From b350d3cd8cc6fe636ecc7d3ddd82b4b5530d01e6 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 4 Apr 2014 11:40:43 +0200 Subject: [PATCH] MP1 Transmit. Basic iplementation done. --- Modem/Modem_user.mk | 2 -- Modem/main.c | 28 +++------------------------- Modem/protocol/mp1.c | 28 ++++++++++++++++++++++++++++ buildrev.h | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Modem/Modem_user.mk b/Modem/Modem_user.mk index bf15fbe..2b3a404 100644 --- a/Modem/Modem_user.mk +++ b/Modem/Modem_user.mk @@ -13,8 +13,6 @@ Modem_USER_CSRC = \ $(Modem_HW_PATH)/hardware.c \ $(Modem_HW_PATH)/afsk.c \ $(Modem_HW_PATH)/protocol/mp1.c \ - bertos/net/ax25.c \ - bertos/algo/crc_ccitt.c \ # # Files included by the user. diff --git a/Modem/main.c b/Modem/main.c index c9fd9ca..39fb162 100644 --- a/Modem/main.c +++ b/Modem/main.c @@ -18,22 +18,7 @@ static MP1 mp1; #define ADC_CH 0 - -///////////////////////// AX25 for testing //// -#include -static AX25Ctx ax25; -static AX25Call path[] = AX25_PATH(AX25_CALL("apzbrt", 0), AX25_CALL("nocall", 0), AX25_CALL("wide1", 1), AX25_CALL("wide2", 2)); -#define APRS_MSG ">Test BeRTOS APRS http://www.bertos.org" -static void message_callback(struct AX25Msg *msg) -{ - kfile_printf(&ser.fd, "\n\nSRC[%.6s-%d], DST[%.6s-%d]\r\n", msg->src.call, msg->src.ssid, msg->dst.call, msg->dst.ssid); - - for (int i = 0; i < msg->rpt_cnt; i++) - kfile_printf(&ser.fd, "via: [%.6s-%d]\r\n", msg->rpt_lst[i].call, msg->rpt_lst[i].ssid); - - kfile_printf(&ser.fd, "DATA: %.*s\r\n", msg->len, msg->info); -} -/////////////////////////////////////////////// +#define TEST_PACKET "Test MP1 AFSK Packet!" static void mp1Callback(struct MP1Packet *packet) { kfile_printf(&ser.fd, "\nMP1 Packet Received:\n"); @@ -47,7 +32,6 @@ static void init(void) timer_init(); afsk_init(&afsk, ADC_CH, 0); - ax25_init(&ax25, &afsk.fd, message_callback); mp1Init(&mp1, &afsk.fd, mp1Callback); @@ -62,20 +46,14 @@ int main(void) while (1) { - // Raw read, no protocol - // if (!fifo_isempty(&afsk.rxFifo)) { - // char c = fifo_pop(&afsk.rxFifo); - // kprintf("%c", c); - // } - mp1Poll(&mp1); - // Use AX.25 to send test data + // Periodically send test data if (timer_clock() - start > ms_to_ticks(4000L)) { kputs("Test TX\n"); start = timer_clock(); - ax25_sendVia(&ax25, path, countof(path), APRS_MSG, sizeof(APRS_MSG)); + mp1Send(&mp1, TEST_PACKET, sizeof(TEST_PACKET)); } } return 0; diff --git a/Modem/protocol/mp1.c b/Modem/protocol/mp1.c index 59d4dd9..0cdb3d7 100644 --- a/Modem/protocol/mp1.c +++ b/Modem/protocol/mp1.c @@ -79,6 +79,34 @@ void mp1Poll(MP1 *mp1) { } } +static void mp1Putbyte(MP1 *mp1, uint8_t byte) { + // If we are sending something that looks + // like an HDLC special byte, send an escape + // character first + if (byte == HDLC_FLAG || + byte == HDLC_RESET || + byte == AX25_ESC) { + kfile_putc(AX25_ESC, mp1->modem); + } + kfile_putc(byte, mp1->modem); +} + +void mp1Send(MP1 *mp1, const void *_buffer, size_t length) { + // Get the transmit data buffer + const uint8_t *buffer = (const uint8_t *)_buffer; + + // Transmit the HDLC_FLAG to signify start of TX + kfile_putc(HDLC_FLAG, mp1->modem); + + // Continously increment the pointer address + // of the buffer while passing it to the byte + // output function + while (length--) mp1Putbyte(mp1, *buffer++); + + // Transmit a HDLC_FLAG to signify end of TX + kfile_putc(HDLC_FLAG, mp1->modem); +} + void mp1Init(MP1 *mp1, KFile *modem, mp1_callback_t callback) { // Allocate memory for our protocol "object" memset(mp1, 0, sizeof(*mp1)); diff --git a/buildrev.h b/buildrev.h index 733e150..d7fa7e9 100644 --- a/buildrev.h +++ b/buildrev.h @@ -1,2 +1,2 @@ -#define VERS_BUILD 136 +#define VERS_BUILD 148 #define VERS_HOST "vixen"