AX25:add new print function compatible with TNC-2 format.
[bertos.git] / bertos / net / ax25_test.c
index 31a7ed36722af351548100c432344d12e65ed620..fc3736ccfbce757bb00b676406ef35a08c030e22 100644 (file)
 #include <struct/kfile_mem.h>
 
 #include <cfg/debug.h>
+#include <cfg/kfile_debug.h>
 #include <cfg/test.h>
 
 #include <string.h> //strncmp
 
 static AX25Ctx ax25;
 static KFileMem mem;
+static KFileDebug dbg;
+
+#define APRS_MSG \
+       0x3D, 0x34, 0x36, 0x30, 0x33, 0x2E, 0x36, 0x33, \
+       0x4E, 0x2F, 0x30, 0x31, 0x34, 0x33, 0x31, 0x2E, \
+       0x32, 0x36, 0x45, 0x2D, 0x4F, 0x70, 0x2E, 0x20, \
+       0x41, 0x6E, 0x64, 0x72, 0x65, 0x6A
 
 uint8_t aprs_packet[] =
 {
        HDLC_FLAG,
-       0x82, 0xA0, 0xA4, 0xA6, 0x40, 0x40, 0xE0, 0xA6, 0x6A, 0x6E, 0x98, 0x9C, 0x40, 0x61, 0x03, 0xF0,
-       0x3D, 0x34, 0x36, 0x30, 0x33, 0x2E, 0x36, 0x33, 0x4E, 0x2F, 0x30, 0x31, 0x34, 0x33, 0x31, 0x2E,
-       0x32, 0x36, 0x45, 0x2D, 0x4F, 0x70, 0x2E, 0x20, 0x41, 0x6E, 0x64, 0x72, 0x65, 0x6A, 0x40, 0x65,
+       0x82, 0xA0, 0xA4, 0xA6, 0x40, 0x40, 0xE0, /* dst */
+       0xA6, 0x6A, 0x6E, 0x98, 0x9C, 0x40, 0x61, /* src */
+       0x03, /* ctrl */
+       0xF0, /* pid */
+       APRS_MSG, /* payload */
+       0x40, 0x65, /* CRC */
        HDLC_FLAG,
 };
 
+uint8_t buf[] = { APRS_MSG };
+KFileMem mem1;
+uint8_t aprs_packet_check[256];
+
+
 static void msg_callback(AX25Msg *msg)
 {
-       ASSERT(strncmp(msg->dst.call, "APRS  ", 6) == 0);
-       ASSERT(strncmp(msg->src.call, "S57LN ", 6) == 0);
+       ax25_print(&dbg.fd, msg);
+       ASSERT(strncmp(msg->dst.call, "APRS\x0\x0", 6) == 0);
+       ASSERT(strncmp(msg->src.call, "S57LN\x0", 6) == 0);
        ASSERT(msg->src.ssid == 0);
        ASSERT(msg->dst.ssid == 0);
        ASSERT(msg->ctrl == AX25_CTRL_UI);
@@ -72,7 +89,9 @@ static void msg_callback(AX25Msg *msg)
 int ax25_testSetup(void)
 {
        kdbg_init();
+       kfiledebug_init(&dbg);
        kfilemem_init(&mem, aprs_packet, sizeof(aprs_packet));
+       kfilemem_init(&mem1, aprs_packet_check, sizeof(aprs_packet_check));
        ax25_init(&ax25, &mem.fd, msg_callback);
        return 0;
 }
@@ -85,6 +104,9 @@ int ax25_testTearDown(void)
 int ax25_testRun(void)
 {
        ax25_poll(&ax25);
+       ax25_init(&ax25, &mem1.fd, NULL);
+       ax25_send(&ax25, AX25_CALL("aprs", 0x70), AX25_CALL("s57ln", 0x30), buf, sizeof(buf));
+       ASSERT(memcmp(aprs_packet, aprs_packet_check, sizeof(aprs_packet)) == 0);
        return  0;
 }