kopia lustrzana https://github.com/markqvist/LibAPRS
Merge 23b912827b
into a36acdd460
commit
1c9a9e9507
|
@ -30,7 +30,7 @@ void AFSK_hw_init(void) {
|
|||
|
||||
AFSK_hw_refDetect();
|
||||
|
||||
TCCR1A = 0;
|
||||
TCCR1A = 0;
|
||||
TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
|
||||
ICR1 = (((CPU_FREQ+FREQUENCY_CORRECTION)) / 9600) - 1;
|
||||
|
||||
|
@ -45,7 +45,7 @@ void AFSK_hw_init(void) {
|
|||
DIDR0 |= _BV(0);
|
||||
ADCSRB = _BV(ADTS2) |
|
||||
_BV(ADTS1) |
|
||||
_BV(ADTS0);
|
||||
_BV(ADTS0);
|
||||
ADCSRA = _BV(ADEN) |
|
||||
_BV(ADSC) |
|
||||
_BV(ADATE)|
|
||||
|
@ -62,33 +62,37 @@ void AFSK_init(Afsk *afsk) {
|
|||
memset(afsk, 0, sizeof(*afsk));
|
||||
AFSK_modem = afsk;
|
||||
// Set phase increment
|
||||
afsk->phaseInc = MARK_INC;
|
||||
afsk->dataRate = 1200;
|
||||
afsk->phaseInc = MARK_INC_1200;
|
||||
// Initialise FIFO buffers
|
||||
fifo_init(&afsk->delayFifo, (uint8_t *)afsk->delayBuf, sizeof(afsk->delayBuf));
|
||||
fifo_init(&afsk->rxFifo, afsk->rxBuf, sizeof(afsk->rxBuf));
|
||||
fifo_init(&afsk->txFifo, afsk->txBuf, sizeof(afsk->txBuf));
|
||||
|
||||
// Fill delay FIFO with zeroes
|
||||
for (int i = 0; i<SAMPLESPERBIT / 2; i++) {
|
||||
for (int i = 0; i<SAMPLESPERBIT_300 / 2; i++) {
|
||||
fifo_push(&afsk->delayFifo, 0);
|
||||
}
|
||||
|
||||
AFSK_hw_init();
|
||||
}
|
||||
|
||||
void AFSK_setDataRate(Afsk *afsk, uint16_t dataRate) {
|
||||
afsk->dataRate = dataRate;
|
||||
}
|
||||
|
||||
static void AFSK_txStart(Afsk *afsk) {
|
||||
if (!afsk->sending) {
|
||||
afsk->phaseInc = MARK_INC;
|
||||
afsk->phaseInc = afsk->dataRate == 1200 ? MARK_INC_1200 : MARK_INC_300;
|
||||
afsk->phaseAcc = 0;
|
||||
afsk->bitstuffCount = 0;
|
||||
afsk->sending = true;
|
||||
LED_TX_ON();
|
||||
afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);
|
||||
afsk->preambleLength = DIV_ROUND(custom_preamble * afsk->dataRate, 8000);
|
||||
AFSK_DAC_IRQ_START();
|
||||
}
|
||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||
afsk->tailLength = DIV_ROUND(custom_tail * BITRATE, 8000);
|
||||
afsk->tailLength = DIV_ROUND(custom_tail * afsk->dataRate, 8000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,18 +158,18 @@ uint8_t AFSK_dac_isr(Afsk *afsk) {
|
|||
|
||||
if (afsk->bitStuff && afsk->bitstuffCount >= BIT_STUFF_LEN) {
|
||||
afsk->bitstuffCount = 0;
|
||||
afsk->phaseInc = SWITCH_TONE(afsk->phaseInc);
|
||||
afsk->phaseInc = (afsk->dataRate == 1200) ? SWITCH_TONE_1200(afsk->phaseInc) : SWITCH_TONE_300(afsk->phaseInc);
|
||||
} else {
|
||||
if (afsk->currentOutputByte & afsk->txBit) {
|
||||
afsk->bitstuffCount++;
|
||||
} else {
|
||||
afsk->bitstuffCount = 0;
|
||||
afsk->phaseInc = SWITCH_TONE(afsk->phaseInc);
|
||||
afsk->phaseInc = (afsk->dataRate == 1200) ? SWITCH_TONE_1200(afsk->phaseInc) : SWITCH_TONE_300(afsk->phaseInc);
|
||||
}
|
||||
afsk->txBit <<= 1;
|
||||
}
|
||||
|
||||
afsk->sampleIndex = SAMPLESPERBIT;
|
||||
afsk->sampleIndex = (afsk->dataRate == 1200) ? SAMPLESPERBIT_1200 : SAMPLESPERBIT_300;
|
||||
}
|
||||
|
||||
afsk->phaseAcc += afsk->phaseInc;
|
||||
|
@ -184,7 +188,7 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
|||
// the left by one bit, to make room for the
|
||||
// next incoming bit
|
||||
hdlc->demodulatedBits <<= 1;
|
||||
// And then put the newest bit from the
|
||||
// And then put the newest bit from the
|
||||
// demodulator into the byte.
|
||||
hdlc->demodulatedBits |= bit ? 1 : 0;
|
||||
|
||||
|
@ -205,9 +209,9 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
|||
}
|
||||
} else {
|
||||
// If the buffer is full, we have a problem
|
||||
// and abort by setting the return value to
|
||||
// and abort by setting the return value to
|
||||
// false and stopping the here.
|
||||
|
||||
|
||||
ret = false;
|
||||
hdlc->receiving = false;
|
||||
LED_RX_OFF();
|
||||
|
@ -255,7 +259,7 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
|||
// a control character. Therefore, if we detect such a
|
||||
// "stuffed bit", we simply ignore it and wait for the
|
||||
// next bit to come in.
|
||||
//
|
||||
//
|
||||
// We do the detection by applying an AND bit-mask to the
|
||||
// stream of demodulated bits. This mask is 00111111 (0x3f)
|
||||
// if the result of the operation is 00111110 (0x3e), we
|
||||
|
@ -333,7 +337,7 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
|
|||
afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) >> 2;
|
||||
|
||||
afsk->iirY[0] = afsk->iirY[1];
|
||||
|
||||
|
||||
afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] >> 1); // Chebyshev filter
|
||||
|
||||
|
||||
|
@ -347,7 +351,7 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
|
|||
fifo_push(&afsk->delayFifo, currentSample);
|
||||
|
||||
// We need to check whether there is a signal transition.
|
||||
// If there is, we can recalibrate the phase of our
|
||||
// If there is, we can recalibrate the phase of our
|
||||
// sampler to stay in sync with the transmitter. A bit of
|
||||
// explanation is required to understand how this works.
|
||||
// Since we have PHASE_MAX/PHASE_BITS = 8 samples per bit,
|
||||
|
@ -363,13 +367,13 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
|
|||
// Past Future
|
||||
// 0000000011111111000000001111111100000000
|
||||
// |________|
|
||||
// ||
|
||||
// ||
|
||||
// Window
|
||||
//
|
||||
// Every time we detect a signal transition, we adjust
|
||||
// where this window is positioned little. How much we
|
||||
// adjust it is defined by PHASE_INC. If our current phase
|
||||
// phase counter value is less than half of PHASE_MAX (ie,
|
||||
// phase counter value is less than half of PHASE_MAX (ie,
|
||||
// the window size) when a signal transition is detected,
|
||||
// add PHASE_INC to our phase counter, effectively moving
|
||||
// the window a little bit backward (to the left in the
|
||||
|
@ -380,7 +384,7 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
|
|||
// our timing to the transmitter, even if it's timing is
|
||||
// a little off compared to our own.
|
||||
if (SIGNAL_TRANSITIONED(afsk->sampledBits)) {
|
||||
if (afsk->currentPhase < PHASE_THRESHOLD) {
|
||||
if (afsk->currentPhase < PHASE_THRESHOLD_1200) {
|
||||
afsk->currentPhase += PHASE_INC;
|
||||
} else {
|
||||
afsk->currentPhase -= PHASE_INC;
|
||||
|
@ -392,10 +396,10 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
|
|||
|
||||
// Check if we have reached the end of
|
||||
// our sampling window.
|
||||
if (afsk->currentPhase >= PHASE_MAX) {
|
||||
if (afsk->currentPhase >= PHASE_MAX_1200) {
|
||||
// If we have, wrap around our phase
|
||||
// counter by modulus
|
||||
afsk->currentPhase %= PHASE_MAX;
|
||||
afsk->currentPhase %= PHASE_MAX_1200;
|
||||
|
||||
// Bitshift to make room for the next
|
||||
// bit in our stream of demodulated bits
|
||||
|
@ -462,7 +466,7 @@ ISR(ADC_vect) {
|
|||
TIFR1 = _BV(ICF1);
|
||||
AFSK_adc_isr(AFSK_modem, ((int16_t)((ADC) >> 2) - 128));
|
||||
if (hw_afsk_dac_isr) {
|
||||
DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | _BV(3);
|
||||
DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | _BV(3);
|
||||
} else {
|
||||
DAC_PORT = 128;
|
||||
}
|
||||
|
@ -472,4 +476,4 @@ ISR(ADC_vect) {
|
|||
poll_timer = 0;
|
||||
APRS_poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,9 @@ inline static uint8_t sinSample(uint16_t i) {
|
|||
return (i >= (SIN_LEN/2)) ? (255 - sine) : sine;
|
||||
}
|
||||
|
||||
|
||||
#define SWITCH_TONE(inc) (((inc) == MARK_INC) ? SPACE_INC : MARK_INC)
|
||||
#define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor))
|
||||
#define SWITCH_TONE_300(inc) (((inc) == MARK_INC_300) ? SPACE_INC_300 : MARK_INC_300)
|
||||
#define SWITCH_TONE_1200(inc) (((inc) == MARK_INC_1200) ? SPACE_INC_1200 : MARK_INC_1200)
|
||||
#define BITS_DIFFER(bits1, bits2) (((bits1)^(bits2)) & 0x01)
|
||||
#define DUAL_XOR(bits1, bits2) ((((bits1)^(bits2)) & 0x03) == 0x03)
|
||||
#define SIGNAL_TRANSITIONED(bits) DUAL_XOR((bits), (bits) >> 2)
|
||||
|
@ -44,15 +45,23 @@ inline static uint8_t sinSample(uint16_t i) {
|
|||
#define CONFIG_AFSK_PREAMBLE_LEN 150UL
|
||||
#define CONFIG_AFSK_TRAILER_LEN 50UL
|
||||
#define SAMPLERATE 9600
|
||||
#define BITRATE 1200
|
||||
#define SAMPLESPERBIT (SAMPLERATE / BITRATE)
|
||||
#define SAMPLESPERBIT_1200 (SAMPLERATE / 1200)
|
||||
#define SAMPLESPERBIT_300 (SAMPLERATE / 300)
|
||||
#define BIT_STUFF_LEN 5
|
||||
#define MARK_FREQ 1200
|
||||
#define SPACE_FREQ 2200
|
||||
#define MARK_FREQ_300 1600
|
||||
#define SPACE_FREQ_300 1800
|
||||
#define MARK_FREQ_1200 1200
|
||||
#define SPACE_FREQ_1200 2200
|
||||
#define PHASE_BITS 8 // How much to increment phase counter each sample
|
||||
#define PHASE_INC 1 // Nudge by an eigth of a sample each adjustment
|
||||
#define PHASE_MAX (SAMPLESPERBIT * PHASE_BITS) // Resolution of our phase counter = 64
|
||||
#define PHASE_THRESHOLD (PHASE_MAX / 2) // Target transition point of our phase window
|
||||
#define PHASE_MAX_300 (SAMPLESPERBIT_300 * PHASE_BITS) // Resolution of our phase counter = 64
|
||||
#define PHASE_MAX_1200 (SAMPLESPERBIT_1200 * PHASE_BITS) // Resolution of our phase counter = 64
|
||||
#define PHASE_THRESHOLD_300 (PHASE_MAX_300 / 2) // Target transition point of our phase window
|
||||
#define PHASE_THRESHOLD_1200 (PHASE_MAX_1200 / 2) // Target transition point of our phase window
|
||||
#define MARK_INC_300 (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)MARK_FREQ_300, CONFIG_AFSK_DAC_SAMPLERATE))
|
||||
#define SPACE_INC_300 (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)SPACE_FREQ_300, CONFIG_AFSK_DAC_SAMPLERATE))
|
||||
#define MARK_INC_1200 (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)MARK_FREQ_1200, CONFIG_AFSK_DAC_SAMPLERATE))
|
||||
#define SPACE_INC_1200 (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)SPACE_FREQ_1200, CONFIG_AFSK_DAC_SAMPLERATE))
|
||||
|
||||
|
||||
typedef struct Hdlc
|
||||
|
@ -85,13 +94,13 @@ typedef struct Afsk
|
|||
uint16_t phaseInc; // Phase increment per sample
|
||||
|
||||
FIFOBuffer txFifo; // FIFO for transmit data
|
||||
uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN]; // Actial data storage for said FIFO
|
||||
uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN]; // Actual data storage for said FIFO
|
||||
|
||||
volatile bool sending; // Set when modem is sending
|
||||
|
||||
// Demodulation values
|
||||
FIFOBuffer delayFifo; // Delayed FIFO for frequency discrimination
|
||||
int8_t delayBuf[SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO
|
||||
int8_t delayBuf[SAMPLESPERBIT_300 / 2 + 1]; // Actual data storage for said FIFO
|
||||
|
||||
FIFOBuffer rxFifo; // FIFO for received data
|
||||
uint8_t rxBuf[CONFIG_AFSK_RX_BUFLEN]; // Actual data storage for said FIFO
|
||||
|
@ -100,16 +109,13 @@ typedef struct Afsk
|
|||
int16_t iirY[2]; // IIR Filter Y cells
|
||||
|
||||
uint8_t sampledBits; // Bits sampled by the demodulator (at ADC speed)
|
||||
int8_t currentPhase; // Current phase of the demodulator
|
||||
int16_t currentPhase; // Current phase of the demodulator
|
||||
uint8_t actualBits; // Actual found bits at correct bitrate
|
||||
|
||||
volatile int status; // Status of the modem, 0 means OK
|
||||
|
||||
uint16_t dataRate; // Data rate for the modem
|
||||
} Afsk;
|
||||
|
||||
#define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor))
|
||||
#define MARK_INC (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)MARK_FREQ, CONFIG_AFSK_DAC_SAMPLERATE))
|
||||
#define SPACE_INC (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)SPACE_FREQ, CONFIG_AFSK_DAC_SAMPLERATE))
|
||||
|
||||
#define AFSK_DAC_IRQ_START() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = true; } while (0)
|
||||
#define AFSK_DAC_IRQ_STOP() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = false; } while (0)
|
||||
|
@ -131,6 +137,7 @@ typedef struct Afsk
|
|||
void AFSK_init(Afsk *afsk);
|
||||
void AFSK_transmit(char *buffer, size_t size);
|
||||
void AFSK_poll(Afsk *afsk);
|
||||
void AFSK_setDataRate(Afsk *afsk, uint16_t rate);
|
||||
|
||||
void afsk_putchar(char c);
|
||||
int afsk_getchar(void);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
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;
|
||||
|
|
|
@ -18,14 +18,17 @@ AX25Call dst;
|
|||
AX25Call path1;
|
||||
AX25Call path2;
|
||||
|
||||
char CALL[7] = "NOCALL";
|
||||
#define MAX_CALL_LENGTH 7
|
||||
char CALL[MAX_CALL_LENGTH] = "NOCALL";
|
||||
int CALL_SSID = 0;
|
||||
char DST[7] = "APZMDM";
|
||||
char DST[MAX_CALL_LENGTH] = "APZMDM";
|
||||
int DST_SSID = 0;
|
||||
char PATH1[7] = "WIDE1";
|
||||
char PATH1[MAX_CALL_LENGTH] = "WIDE1";
|
||||
int PATH1_SSID = 1;
|
||||
char PATH2[7] = "WIDE2";
|
||||
char PATH2[MAX_CALL_LENGTH] = "WIDE2";
|
||||
int PATH2_SSID = 2;
|
||||
uint8_t MICE_MSG;
|
||||
uint8_t MICE_SSID;
|
||||
|
||||
AX25Call path[4];
|
||||
|
||||
|
@ -39,6 +42,8 @@ uint8_t power = 10;
|
|||
uint8_t height = 10;
|
||||
uint8_t gain = 10;
|
||||
uint8_t directivity = 10;
|
||||
uint16_t speed;
|
||||
uint16_t course;
|
||||
/////////////////////////
|
||||
|
||||
// Message packet assembly fields
|
||||
|
@ -63,8 +68,16 @@ void APRS_poll(void) {
|
|||
ax25_poll(&AX25);
|
||||
}
|
||||
|
||||
void APRS_setDataRate300() {
|
||||
AFSK_setDataRate(&modem, 300);
|
||||
}
|
||||
|
||||
void APRS_setDataRate1200() {
|
||||
AFSK_setDataRate(&modem, 1200);
|
||||
}
|
||||
|
||||
void APRS_setCallsign(char *call, int ssid) {
|
||||
memset(CALL, 0, 7);
|
||||
memset(CALL, 0, MAX_CALL_LENGTH);
|
||||
int i = 0;
|
||||
while (i < 6 && call[i] != 0) {
|
||||
CALL[i] = call[i];
|
||||
|
@ -74,7 +87,7 @@ void APRS_setCallsign(char *call, int ssid) {
|
|||
}
|
||||
|
||||
void APRS_setDestination(char *call, int ssid) {
|
||||
memset(DST, 0, 7);
|
||||
memset(DST, 0, MAX_CALL_LENGTH);
|
||||
int i = 0;
|
||||
while (i < 6 && call[i] != 0) {
|
||||
DST[i] = call[i];
|
||||
|
@ -84,7 +97,7 @@ void APRS_setDestination(char *call, int ssid) {
|
|||
}
|
||||
|
||||
void APRS_setPath1(char *call, int ssid) {
|
||||
memset(PATH1, 0, 7);
|
||||
memset(PATH1, 0, MAX_CALL_LENGTH);
|
||||
int i = 0;
|
||||
while (i < 6 && call[i] != 0) {
|
||||
PATH1[i] = call[i];
|
||||
|
@ -94,7 +107,7 @@ void APRS_setPath1(char *call, int ssid) {
|
|||
}
|
||||
|
||||
void APRS_setPath2(char *call, int ssid) {
|
||||
memset(PATH2, 0, 7);
|
||||
memset(PATH2, 0, MAX_CALL_LENGTH);
|
||||
int i = 0;
|
||||
while (i < 6 && call[i] != 0) {
|
||||
PATH2[i] = call[i];
|
||||
|
@ -104,7 +117,7 @@ void APRS_setPath2(char *call, int ssid) {
|
|||
}
|
||||
|
||||
void APRS_setMessageDestination(char *call, int ssid) {
|
||||
memset(message_recip, 0, 7);
|
||||
memset(message_recip, 0, 6);
|
||||
int i = 0;
|
||||
while (i < 6 && call[i] != 0) {
|
||||
message_recip[i] = call[i];
|
||||
|
@ -129,6 +142,10 @@ void APRS_useAlternateSymbolTable(bool use) {
|
|||
}
|
||||
}
|
||||
|
||||
void APRS_setSymbolTable(char table) {
|
||||
symbolTable = table;
|
||||
}
|
||||
|
||||
void APRS_setSymbol(char sym) {
|
||||
symbol = sym;
|
||||
}
|
||||
|
@ -175,6 +192,24 @@ void APRS_setDirectivity(int s) {
|
|||
}
|
||||
}
|
||||
|
||||
// Set the speed in knots. Valid speeds are 0-799 knots
|
||||
void APRS_setSpeed(int s) {
|
||||
if (s >= 0 && s < 800) {
|
||||
speed = s;
|
||||
} else {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the course, valid courses are 0-360 where 0 is unknown and 360 is due north
|
||||
void APRS_setCourse(int c) {
|
||||
if (c >= 0 && c <= 360) {
|
||||
course = c;
|
||||
} else {
|
||||
course = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void APRS_printSettings() {
|
||||
Serial.println(F("LibAPRS Settings:"));
|
||||
Serial.print(F("Callsign: ")); Serial.print(CALL); Serial.print(F("-")); Serial.println(CALL_SSID);
|
||||
|
@ -218,6 +253,154 @@ void APRS_sendPkt(void *_buffer, size_t length) {
|
|||
ax25_sendVia(&AX25, path, countof(path), buffer, length);
|
||||
}
|
||||
|
||||
// 3 bits of MIC-E message. Bit A is the most significant bit.
|
||||
// If custom is set then we use the custom message bits when encoding
|
||||
// Standard messages Custom Messages
|
||||
// 0x07: M0: Off Duty C0: Custom-0
|
||||
// 0x06: M1: En route C1: Custom-1
|
||||
// 0x05: M2: In service C2: Custom-2
|
||||
// 0x04: M3: Returning C3: Custom-3
|
||||
// 0x03: M4: Committed C4: Custom-4
|
||||
// 0x02: M5: Special C5: Custom-5
|
||||
// 0x01: M6: Priority C6: Custom-6
|
||||
// 0x00: Emergency Emergency
|
||||
void APRS_set_mice_msg(uint8_t msg, bool custom) {
|
||||
MICE_MSG = msg & 0x07;
|
||||
// If custom message bits, store the custom flag in bit 7 of the MICE_MSG
|
||||
if (custom) {
|
||||
MICE_MSG |= 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
void APRS_set_mice_ssid(uint8_t ssid) {
|
||||
MICE_SSID = ssid & 0x0F;
|
||||
}
|
||||
|
||||
uint8_t APRS_sendLoc_mice(void *_buffer, size_t length) {
|
||||
uint8_t path_len;
|
||||
uint8_t payloadLength = 9 + length;
|
||||
uint8_t *packet = (uint8_t*)malloc(payloadLength);
|
||||
// Sanity check the latitude and longtitude
|
||||
if (latitude[7] != 'N' && latitude[7] != 'S') {
|
||||
return 1;
|
||||
}
|
||||
if (longtitude[8] != 'E' && longtitude[8] != 'W') {
|
||||
return 1;
|
||||
}
|
||||
// Build the Destination callsign with the latitude information
|
||||
DST[0] = (latitude[0] & 0x0F) | 0x30;
|
||||
if (MICE_MSG & 0x04) {
|
||||
if (MICE_MSG & 0x80) {
|
||||
DST[0] += 0x17; // Custom message bit
|
||||
} else {
|
||||
DST[0] += 0x20; // Standard message bit
|
||||
}
|
||||
}
|
||||
DST[1] = (latitude[1] & 0x0F) | 0x30;
|
||||
if (MICE_MSG & 0x02) {
|
||||
if (MICE_MSG & 0x80) {
|
||||
DST[1] += 0x17; // Custom message bit
|
||||
} else {
|
||||
DST[1] += 0x20; // Standard message bit
|
||||
}
|
||||
}
|
||||
DST[2] = (latitude[2] & 0x0F) | 0x30;
|
||||
if (MICE_MSG & 0x01) {
|
||||
if (MICE_MSG & 0x80) {
|
||||
DST[2] += 0x17; // Custom message bit
|
||||
} else {
|
||||
DST[2] += 0x20; // Standard message bit
|
||||
}
|
||||
}
|
||||
DST[3] = (latitude[3] & 0x0F) | 0x30;
|
||||
if (latitude[7] == 'N') { // North/South Latitude Indicator
|
||||
DST[3] += 0x20;
|
||||
}
|
||||
DST[4] = (latitude[5] & 0x0F) | 0x30; // Use latitude[5] becuase latitude[4] is a .
|
||||
// if (longtitude[0] == '1') { // If the longtitude is > 100, set this bit
|
||||
// DST[4] += 0x20;
|
||||
// }
|
||||
DST[5] = (latitude[6] & 0x0F) | 0x30;
|
||||
if (longtitude[8] == 'W') { // If the longtitude is > 100, set this bit
|
||||
DST[4] += 0x20;
|
||||
}
|
||||
|
||||
packet[0] = 0x60; // The ` character indicating valid GPS data
|
||||
// Degrees. If longtitude > 100 the +100 longtitude bit is set in the Destination field, but only in
|
||||
// certain circumstances, see http://www.aprs.org/doc/APRS101.PDF page 47
|
||||
uint8_t lon_deg = ((longtitude[0] & 0x0F) * 100 + (longtitude[1] & 0x0F) * 10 + (longtitude[2] & 0x0F));
|
||||
if (lon_deg < 10) {
|
||||
packet[1] = 118 + lon_deg;
|
||||
DST[4] += 0x20;
|
||||
} else if (lon_deg < 100) {
|
||||
packet[1] = 38 + lon_deg - 10;
|
||||
} else if (lon_deg < 110) {
|
||||
packet[1] = 108 + (lon_deg - 100);
|
||||
DST[4] += 0x20;
|
||||
} else {
|
||||
packet[1] = 38 + (lon_deg - 110);
|
||||
DST[4] += 0x20;
|
||||
}
|
||||
|
||||
uint8_t lon_min = ((longtitude[3] & 0x0F) * 10) + (longtitude[4] & 0x0F);
|
||||
if (lon_min < 10) {
|
||||
packet[2] = 88 + lon_min;
|
||||
} else {
|
||||
packet[2] = 38 + lon_min - 10;
|
||||
}
|
||||
packet[3] = ((longtitude[6] & 0x0F) * 10) + (longtitude[7] & 0x0F) + 28;
|
||||
|
||||
// bytes 4, 5 and 6 encode the speed and course
|
||||
// Page 50 of the APRS spec
|
||||
packet[4] = (speed / 10) + 28; // 100's an 10's of knots
|
||||
packet[5] = (speed % 10) * 10 + 32; // 1's of knots
|
||||
if (course > 299) {
|
||||
packet[5] += 3;
|
||||
} else if (course > 199) {
|
||||
packet[5] += 2;
|
||||
} else if (course > 99) {
|
||||
packet[5] += 1;
|
||||
}
|
||||
packet[6] = (course % 100) + 28;
|
||||
packet[7] = (uint8_t)symbol;
|
||||
packet[8] = (uint8_t)symbolTable;
|
||||
|
||||
if (MICE_SSID != 0) {
|
||||
path_len = 0;
|
||||
} else {
|
||||
path_len = 4;
|
||||
}
|
||||
|
||||
memcpy(dst.call, DST, 6);
|
||||
dst.ssid = DST_SSID;
|
||||
|
||||
memcpy(src.call, CALL, 6);
|
||||
src.ssid = CALL_SSID;
|
||||
|
||||
memcpy(path1.call, PATH1, 6);
|
||||
path1.ssid = PATH1_SSID;
|
||||
|
||||
memcpy(path2.call, PATH2, 6);
|
||||
path2.ssid = PATH2_SSID;
|
||||
|
||||
for (int i=0; i<6; i++) {
|
||||
Serial.print((char)DST[i]);
|
||||
}
|
||||
|
||||
|
||||
path[0] = dst;
|
||||
path[1] = src;
|
||||
path[2] = path1;
|
||||
path[3] = path2;
|
||||
if (length > 0) {
|
||||
uint8_t *buffer = (uint8_t *)_buffer;
|
||||
memcpy(&packet[9], buffer, length);
|
||||
}
|
||||
ax25_sendVia(&AX25, path, path_len, packet, payloadLength);
|
||||
free(packet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Dynamic RAM usage of this function is 30 bytes
|
||||
void APRS_sendLoc(void *_buffer, size_t length) {
|
||||
size_t payloadLength = 20+length;
|
||||
|
@ -303,7 +486,7 @@ void APRS_sendMsg(void *_buffer, size_t length) {
|
|||
packet[12+length] = h+48;
|
||||
packet[13+length] = d+48;
|
||||
packet[14+length] = n+48;
|
||||
|
||||
|
||||
APRS_sendPkt(packet, payloadLength);
|
||||
free(packet);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,15 @@
|
|||
#include "AFSK.h"
|
||||
#include "AX25.h"
|
||||
|
||||
#define MICE_STD_MSG_OFF_DUTY 0x07
|
||||
#define MICE_STD_MSG_EN_ROUTE 0x06
|
||||
#define MICE_STD_MSG_IN_SERVICE 0x05
|
||||
#define MICE_STD_MSG_RETURNING 0x04
|
||||
#define MICE_STD_MSG_COMMITTED 0x03
|
||||
#define MICE_STD_MSG_SPECIAL 0x02
|
||||
#define MICE_STD_MSG_PRIORITY 0x01
|
||||
#define MICE_STD_MSG_EMERGENCY 0x00
|
||||
|
||||
void APRS_init(int reference, bool open_squelch);
|
||||
void APRS_poll(void);
|
||||
|
||||
|
@ -21,6 +30,7 @@ void APRS_setPreamble(unsigned long pre);
|
|||
void APRS_setTail(unsigned long tail);
|
||||
void APRS_useAlternateSymbolTable(bool use);
|
||||
void APRS_setSymbol(char sym);
|
||||
void APRS_setSymbolTable(char table);
|
||||
|
||||
void APRS_setLat(char *lat);
|
||||
void APRS_setLon(char *lon);
|
||||
|
@ -28,11 +38,19 @@ void APRS_setPower(int s);
|
|||
void APRS_setHeight(int s);
|
||||
void APRS_setGain(int s);
|
||||
void APRS_setDirectivity(int s);
|
||||
void APRS_setSpeed(int s);
|
||||
void APRS_setCourse(int c);
|
||||
void APRS_setDataRate300();
|
||||
void APRS_setDataRate1200();
|
||||
|
||||
void APRS_sendPkt(void *_buffer, size_t length);
|
||||
void APRS_sendLoc(void *_buffer, size_t length);
|
||||
void APRS_sendMsg(void *_buffer, size_t length);
|
||||
void APRS_msgRetry();
|
||||
uint8_t APRS_sendLoc_mice(void *_buffer, size_t length);
|
||||
void APRS_set_mice_ssid(uint8_t ssid);
|
||||
void APRS_set_mice_msg(uint8_t msg, bool custom);
|
||||
|
||||
|
||||
void APRS_printSettings();
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue