From b87d4d5775c50d363a440f74c084ac3f4c11c9da Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 5 Jan 2015 22:36:35 +0100 Subject: [PATCH] Fixed library init not adhering to OPEN_SQUELCH and ADC_REFERENCE settings. Added examples on how to get SRC and DST callsign and SSIDs. --- LibAPRS/AFSK.cpp | 12 +++++++----- LibAPRS/AX25.cpp | 11 ++++++++--- LibAPRS/AX25.h | 2 +- LibAPRS/LibAPRS.cpp | 8 +++++++- LibAPRS/LibAPRS.h | 2 +- LibAPRS/device.h | 11 ----------- LibAPRS/examples/Basic_usage/Basic_usage.ino | 20 +++++++++++++++----- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/LibAPRS/AFSK.cpp b/LibAPRS/AFSK.cpp index 5f07619..47a7e7c 100644 --- a/LibAPRS/AFSK.cpp +++ b/LibAPRS/AFSK.cpp @@ -4,6 +4,8 @@ extern unsigned long custom_preamble; extern unsigned long custom_tail; +extern int LibAPRS_vref; +extern bool LibAPRS_open_squelch; bool hw_afsk_dac_isr = false; bool hw_5v_ref = false; @@ -16,11 +18,11 @@ void afsk_putchar(char c); void AFSK_hw_refDetect(void) { // This is manual for now - #if ADC_REFERENCE == REF_5V + if (LibAPRS_vref == REF_5V) { hw_5v_ref = true; - #else + } else { hw_5v_ref = false; - #endif + } } void AFSK_hw_init(void) { @@ -198,9 +200,9 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) { // on the RX LED. fifo_push(fifo, HDLC_FLAG); hdlc->receiving = true; - #if OPEN_SQUELCH == false + if(!LibAPRS_open_squelch) { LED_RX_ON(); - #endif + } } else { // If the buffer is full, we have a problem // and abort by setting the return value to diff --git a/LibAPRS/AX25.cpp b/LibAPRS/AX25.cpp index a1bff8a..98825b4 100644 --- a/LibAPRS/AX25.cpp +++ b/LibAPRS/AX25.cpp @@ -10,9 +10,12 @@ #define countof(a) sizeof(a)/sizeof(a[0]) #define MIN(a,b) ({ typeof(a) _a = (a); typeof(b) _b = (b); ((typeof(_a))((_a < _b) ? _a : _b)); }) -#define DECODE_CALL(buf, addr) for (unsigned i = 0; i < sizeof((addr)); i++) { char c = (*(buf)++ >> 1); (addr)[i] = (c == ' ') ? '\x0' : c; } +#define DECODE_CALL(buf, addr) for (unsigned i = 0; i < sizeof((addr))-1; i++) { char c = (*(buf)++ >> 1); (addr)[i] = (c == ' ') ? '\x0' : c; } #define AX25_SET_REPEATED(msg, idx, val) do { if (val) { (msg)->rpt_flags |= _BV(idx); } else { (msg)->rpt_flags &= ~_BV(idx) ; } } while(0) +extern int LibAPRS_vref; +extern bool LibAPRS_open_squelch; + void ax25_init(AX25Ctx *ctx, ax25_callback_t hook) { memset(ctx, 0, sizeof(*ctx)); ctx->hook = hook; @@ -25,9 +28,11 @@ static void ax25_decode(AX25Ctx *ctx) { DECODE_CALL(buf, msg.dst.call); msg.dst.ssid = (*buf++ >> 1) & 0x0F; + msg.dst.call[6] = 0; DECODE_CALL(buf, msg.src.call); msg.src.ssid = (*buf >> 1) & 0x0F; + msg.src.call[6] = 0; for (msg.rpt_count = 0; !(*buf++ & 0x01) && (msg.rpt_count < countof(msg.rpt_list)); msg.rpt_count++) { DECODE_CALL(buf, msg.rpt_list[msg.rpt_count].call); @@ -55,9 +60,9 @@ void ax25_poll(AX25Ctx *ctx) { if (!ctx->escape && c == HDLC_FLAG) { if (ctx->frame_len >= AX25_MIN_FRAME_LEN) { if (ctx->crc_in == AX25_CRC_CORRECT) { - #if OPEN_SQUELCH == true + if(LibAPRS_open_squelch) { LED_RX_ON(); - #endif + } ax25_decode(ctx); } } diff --git a/LibAPRS/AX25.h b/LibAPRS/AX25.h index 4a453d8..ce622ef 100644 --- a/LibAPRS/AX25.h +++ b/LibAPRS/AX25.h @@ -39,7 +39,7 @@ typedef struct AX25Ctx { #define AX25_REPEATED(msg, n) ((msg)->rpt_flags & BV(n)) typedef struct AX25Call { - char call[6]; + char call[7]; uint8_t ssid; } AX25Call; diff --git a/LibAPRS/LibAPRS.cpp b/LibAPRS/LibAPRS.cpp index ae29a41..eaf72b8 100644 --- a/LibAPRS/LibAPRS.cpp +++ b/LibAPRS/LibAPRS.cpp @@ -7,6 +7,9 @@ AX25Ctx AX25; extern void aprs_msg_callback(struct AX25Msg *msg); #define countof(a) sizeof(a)/sizeof(a[0]) +int LibAPRS_vref = REF_3V3; +bool LibAPRS_open_squelch = false; + unsigned long custom_preamble = 350UL; unsigned long custom_tail = 50UL; @@ -48,7 +51,10 @@ size_t lastMessageLen; bool message_autoAck = false; ///////////////////////// -void APRS_init(void) { +void APRS_init(int reference, bool open_squelch) { + LibAPRS_vref = reference; + LibAPRS_open_squelch = open_squelch; + AFSK_init(&modem); ax25_init(&AX25, aprs_msg_callback); } diff --git a/LibAPRS/LibAPRS.h b/LibAPRS/LibAPRS.h index 69a9c11..78e725a 100644 --- a/LibAPRS/LibAPRS.h +++ b/LibAPRS/LibAPRS.h @@ -8,7 +8,7 @@ #include "AFSK.h" #include "AX25.h" -void APRS_init(void); +void APRS_init(int reference, bool open_squelch); void APRS_poll(void); void APRS_setCallsign(char *call, int ssid); diff --git a/LibAPRS/device.h b/LibAPRS/device.h index 8a518f8..0e35eec 100644 --- a/LibAPRS/device.h +++ b/LibAPRS/device.h @@ -16,17 +16,6 @@ #define FREQUENCY_CORRECTION 0 #endif -// ADC settings -#ifndef OPEN_SQUELCH - #define OPEN_SQUELCH false -#endif - -#ifndef ADC_REFERENCE - #define ADC_REFERENCE REF_3V3 - // OR - //#define ADC_REFERENCE REF_5V -#endif - // Sampling & timer setup #define CONFIG_AFSK_DAC_SAMPLERATE 9600 diff --git a/LibAPRS/examples/Basic_usage/Basic_usage.ino b/LibAPRS/examples/Basic_usage/Basic_usage.ino index 3be3303..dc2bbcc 100644 --- a/LibAPRS/examples/Basic_usage/Basic_usage.ino +++ b/LibAPRS/examples/Basic_usage/Basic_usage.ino @@ -1,3 +1,6 @@ +// Include LibAPRS +#include + // You must define what reference voltage the ADC // of your device is running at. If you bought a // MicroModem from unsigned.io, it will be running @@ -12,9 +15,6 @@ // running with an open squelch radio: #define OPEN_SQUELCH false -// Include LibAPRS -#include - // You always need to include this function. It will // get called by the library every time a packet is // received, so you can process incoming packets. @@ -60,7 +60,7 @@ void setup() { Serial.begin(115200); // Initialise APRS library - This starts the modem - APRS_init(); + APRS_init(ADC_REFERENCE, OPEN_SQUELCH); // You must at a minimum configure your callsign and SSID APRS_setCallsign("NOCALL", 1); @@ -132,7 +132,17 @@ void messageExample() { void processPacket() { if (gotPacket) { gotPacket = false; - Serial.print(F("Received APRS packet. Data: ")); + + Serial.print(F("Received APRS packet. SRC: ")); + Serial.print(incomingPacket.src.call); + Serial.print(F("-")); + Serial.print(incomingPacket.src.ssid); + Serial.print(F(". DST: ")); + Serial.print(incomingPacket.dst.call); + Serial.print(F("-")); + Serial.print(incomingPacket.dst.ssid); + Serial.print(F(". Data: ")); + for (int i = 0; i < incomingPacket.len; i++) { Serial.write(incomingPacket.info[i]); }