From e47f203a5648786cd782d921880a77a395570059 Mon Sep 17 00:00:00 2001 From: batt Date: Fri, 16 Apr 2010 22:48:41 +0000 Subject: [PATCH] AX25:add new print function compatible with TNC-2 format. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3444 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/net/afsk_test.c | 6 +++++- bertos/net/ax25.c | 33 ++++++++++++++++++++++++++++++++- bertos/net/ax25.h | 2 ++ bertos/net/ax25_test.c | 8 ++++++-- test/run_tests.sh | 1 + 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/bertos/net/afsk_test.c b/bertos/net/afsk_test.c index 9aa50830..cd434084 100644 --- a/bertos/net/afsk_test.c +++ b/bertos/net/afsk_test.c @@ -51,6 +51,7 @@ #include #include +#include #include @@ -63,11 +64,13 @@ uint32_t data_size; uint32_t data_written; Afsk afsk_fd; AX25Ctx ax25; +KFileDebug dbg; int msg_cnt; -static void message_hook(UNUSED_ARG(struct AX25Msg *, msg)) +static void message_hook(struct AX25Msg *msg) { msg_cnt++; + ax25_print(&dbg.fd, msg); } static FILE *afsk_fileOpen(const char *name) @@ -126,6 +129,7 @@ static FILE *afsk_fileOpen(const char *name) int afsk_testSetup(void) { kdbg_init(); + kfiledebug_init(&dbg); fp_adc = afsk_fileOpen("test/afsk_test.au"); #if CPU_AVR #warning TODO: open the file? diff --git a/bertos/net/ax25.c b/bertos/net/ax25.c index 68a6ae56..a4059505 100644 --- a/bertos/net/ax25.c +++ b/bertos/net/ax25.c @@ -54,7 +54,8 @@ #define DECODE_CALL(buf, addr) \ for (unsigned i = 0; i < sizeof((addr)); i++) \ { \ - (addr)[i] = *(buf)++ >> 1; \ + char c = (*(buf)++ >> 1); \ + (addr)[i] = (c == ' ') ? '\x0' : c; \ } static void ax25_decode(AX25Ctx *ctx) @@ -258,6 +259,36 @@ void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const voi kfile_putc(HDLC_FLAG, ctx->ch); } +static void print_call(KFile *ch, const AX25Call *call) +{ + kfile_printf(ch, "%.6s", call->call); + if (call->ssid) + kfile_printf(ch, "-%d", call->ssid); +} + +/** + * Print a AX25 message in TNC-2 packet monitor format. + * \param ch a kfile channel where the message will be printed. + * \param msg the message to be printed. + */ +void ax25_print(KFile *ch, const AX25Msg *msg) +{ + print_call(ch, &msg->src); + kfile_putc('>', ch); + print_call(ch, &msg->dst); + + #if CONFIG_AX25_RPT_LST + for (int i = 0; i < msg->rpt_cnt; i++) + { + kfile_putc(',', ch); + print_call(ch, &msg->rpt_lst[i]); + // TODO: add * to the trasmitting digi + } + #endif + + kfile_printf(ch, ":%.*s\n", msg->len, msg->info); +} + /** * Init the AX25 protocol decoder. diff --git a/bertos/net/ax25.h b/bertos/net/ax25.h index ad11e466..0e609136 100644 --- a/bertos/net/ax25.h +++ b/bertos/net/ax25.h @@ -179,6 +179,8 @@ void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const voi #define ax25_send(ctx, dst, src, buf, len) ax25_sendVia(ctx, ({static AX25Call __path[]={dst, src}; __path;}), 2, buf, len) void ax25_init(AX25Ctx *ctx, KFile *channel, ax25_callback_t hook); +void ax25_print(KFile *ch, const AX25Msg *msg); + int ax25_testSetup(void); int ax25_testTearDown(void); int ax25_testRun(void); diff --git a/bertos/net/ax25_test.c b/bertos/net/ax25_test.c index 2016eadb..fc3736cc 100644 --- a/bertos/net/ax25_test.c +++ b/bertos/net/ax25_test.c @@ -41,12 +41,14 @@ #include #include +#include #include #include //strncmp static AX25Ctx ax25; static KFileMem mem; +static KFileDebug dbg; #define APRS_MSG \ 0x3D, 0x34, 0x36, 0x30, 0x33, 0x2E, 0x36, 0x33, \ @@ -73,8 +75,9 @@ 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); @@ -86,6 +89,7 @@ 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); diff --git a/test/run_tests.sh b/test/run_tests.sh index 7150a5cb..71a25d31 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -61,6 +61,7 @@ SRC_LIST=" bertos/net/afsk.c bertos/net/nmeap/src/nmeap01.c bertos/net/nmea.c + bertos/cfg/kfile_debug.c " buildout='/dev/null' -- 2.25.1