Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 37 additions & 31 deletions LibAPRS/AFSK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern bool LibAPRS_open_squelch;

bool hw_afsk_dac_isr = false;
bool hw_5v_ref = false;
bool fullBfrErr=false;
Afsk *AFSK_modem;


Expand All @@ -25,36 +26,39 @@ void AFSK_hw_refDetect(void) {
}
}

void AFSK_hw_init(void) {
// Set up ADC

AFSK_hw_refDetect();

TCCR1A = 0;
TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
ICR1 = (((CPU_FREQ+FREQUENCY_CORRECTION)) / 9600) - 1;

if (hw_5v_ref) {
ADMUX = _BV(REFS0) | 0;
} else {
ADMUX = 0;
}

ADC_DDR &= ~_BV(0);
ADC_PORT &= ~_BV(0);
DIDR0 |= _BV(0);
ADCSRB = _BV(ADTS2) |
_BV(ADTS1) |
_BV(ADTS0);
ADCSRA = _BV(ADEN) |
_BV(ADSC) |
_BV(ADATE)|
_BV(ADIE) |
_BV(ADPS2);

AFSK_DAC_INIT();
LED_TX_INIT();
LED_RX_INIT();
namespace AFSKADCINIT{

void AFSK_hw_init(void) {
// Set up ADC

AFSK_hw_refDetect();

TCCR1A = 0;
TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
ICR1 = (((CPU_FREQ+FREQUENCY_CORRECTION)) / 9600) - 1;

if (hw_5v_ref) {
ADMUX = _BV(REFS0) | 0;
} else {
ADMUX = 0;
}

ADC_DDR &= ~_BV(0);
ADC_PORT &= ~_BV(0);
DIDR0 |= _BV(0);
ADCSRB = _BV(ADTS2) |
_BV(ADTS1) |
_BV(ADTS0);
ADCSRA = _BV(ADEN) |
_BV(ADSC) |
_BV(ADATE)|
_BV(ADIE) |
_BV(ADPS2);

AFSK_DAC_INIT();
LED_TX_INIT();
LED_RX_INIT();
}
}

void AFSK_init(Afsk *afsk) {
Expand All @@ -73,7 +77,7 @@ void AFSK_init(Afsk *afsk) {
fifo_push(&afsk->delayFifo, 0);
}

AFSK_hw_init();
AFSKADCINIT::AFSK_hw_init();

}

Expand Down Expand Up @@ -211,6 +215,8 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
ret = false;
hdlc->receiving = false;
LED_RX_OFF();
fullBfrErr=true;

}

// Everytime we receive a HDLC_FLAG, we reset the
Expand Down
3 changes: 3 additions & 0 deletions LibAPRS/AFSK.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "HDLC.h"

#define SIN_LEN 512
namespace AFSKADCINIT {
void AFSK_hw_init(void);
};
static const uint8_t sin_table[] PROGMEM =
{
128, 129, 131, 132, 134, 135, 137, 138, 140, 142, 143, 145, 146, 148, 149, 151,
Expand Down
3 changes: 3 additions & 0 deletions LibAPRS/AX25.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

extern int LibAPRS_vref;
extern bool LibAPRS_open_squelch;
bool CRC_Err=false;

void ax25_init(AX25Ctx *ctx, ax25_callback_t hook) {
memset(ctx, 0, sizeof(*ctx));
Expand Down Expand Up @@ -70,6 +71,8 @@ void ax25_poll(AX25Ctx *ctx) {
LED_RX_ON();
}
ax25_decode(ctx);
}else{
CRC_Err=true;
}
}
ctx->sync = true;
Expand Down
9 changes: 7 additions & 2 deletions LibAPRS/LibAPRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

Afsk modem;
AX25Ctx AX25;
extern void aprs_msg_callback(struct AX25Msg *msg);
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;
char dataID_Flag; // '!' no messaging; '=' messaging va7ta update

AX25Call src;
AX25Call dst;
Expand Down Expand Up @@ -121,6 +122,10 @@ void APRS_setTail(unsigned long tail) {
custom_tail = tail;
}

void APRS_setDataTypeID(uint8_t flag) {//va7ta update
dataID_Flag = flag;//va7ta update
}//va7ta update

void APRS_useAlternateSymbolTable(bool use) {
if (use) {
symbolTable = '\\';
Expand Down Expand Up @@ -228,7 +233,7 @@ void APRS_sendLoc(void *_buffer, size_t length) {
}
uint8_t *packet = (uint8_t*)malloc(payloadLength);
uint8_t *ptr = packet;
packet[0] = '=';
packet[0] = dataID_Flag; //'!'or'='//va7ta update
packet[9] = symbolTable;
packet[19] = symbol;
ptr++;
Expand Down
4 changes: 3 additions & 1 deletion LibAPRS/LibAPRS.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ void APRS_setPath2(char *call, int ssid);

void APRS_setPreamble(unsigned long pre);
void APRS_setTail(unsigned long tail);
void APRS_useAlternateSymbolTable(bool use);
void APRS_useAlternateSymbolTable(bool use);
void APRS_setDataTypeID(uint8_t flag);

void APRS_setSymbol(char sym);

void APRS_setLat(char *lat);
Expand Down
31 changes: 30 additions & 1 deletion LibAPRS/examples/Basic_usage/Basic_usage.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
// OR
//#define ADC_REFERENCE REF_5V

// '!'(33) for no messaging; '='(61)if APRS messaging available
#define APRS_DATA_TYPE_FLAG '='

// Note some squelch delays are too short for catching APRS packets.
// You can also define whether your modem will be
// running with an open squelch radio:
#define OPEN_SQUELCH false
Expand All @@ -29,8 +33,13 @@
// from your main loop, like this:

boolean gotPacket = false;
extern boolean fullBfrErr;//used for flagging data errors
extern boolean CRC_Err;//used for flagging data errors
AX25Msg incomingPacket;
uint8_t *packetData;

using namespace AFSKADCINIT;//provides access for re-initializing ADC for AFSK decoding

void aprs_msg_callback(struct AX25Msg *msg) {
// If we already have a packet waiting to be
// processed, we must drop the new one.
Expand Down Expand Up @@ -109,6 +118,8 @@ void locationUpdateExample() {
APRS_setHeight(4);
APRS_setGain(7);
APRS_setDirectivity(0);
APRS_setDataTypeID(APRS_DATA_TYPE_FLAG);//flags if APRS messaging is available


// We'll define a comment string
char *comment = "LibAPRS location update";
Expand Down Expand Up @@ -164,6 +175,14 @@ void processPacket() {
boolean whichExample = false;
void loop() {

/*
* insert this statement immediately after using the ADC for
* other possible functions such as measuring a voltage from
* a sensor. This is needed to re-configure the ADC for AFSK
* decoding.
*/
// AFSKADCINIT::AFSK_hw_init();// re-initialize AFSK operation

delay(1000);
if (whichExample) {
locationUpdateExample();
Expand All @@ -174,4 +193,14 @@ void loop() {

delay(500);
processPacket();
}
// monitor packet data errors - Note: cannot be used with open squelch
if(CRC_Err==true){
Serial.println(F("CRC_Error"));
CRC_Err=false;
}
// Flag any buffer overrun errors
if(fullBfrErr==true){
Serial.println(F("FullBufferError"));
fullBfrErr=false;
}
}