fix: tons of minor issues; first successful point on aprs.fi
This commit is contained in:
parent
e198d32b7f
commit
45d29a8391
1 changed files with 47 additions and 22 deletions
69
src/main.cpp
69
src/main.cpp
|
@ -5,12 +5,20 @@
|
||||||
#include "afsk_sinus.hpp"
|
#include "afsk_sinus.hpp"
|
||||||
#include "eepromedit.hpp"
|
#include "eepromedit.hpp"
|
||||||
|
|
||||||
#define DESTINATION "GPS "
|
#define MIN_INTERVAL 300000 // 5 min
|
||||||
|
#define SEND_INVALID 0
|
||||||
|
#define DESTINATION "WIDE1 \x01"
|
||||||
#define TXDELAY 32
|
#define TXDELAY 32
|
||||||
|
#define FRAME_REPEAT 3
|
||||||
|
|
||||||
|
#define PTT 4
|
||||||
|
#define PTT_IND 13
|
||||||
|
|
||||||
#define EDITOR_EEPROM_BASE 42
|
#define EDITOR_EEPROM_BASE 42
|
||||||
char callsign[7] = { ' ', ' ', ' ', ' ', ' ', ' ', '\0' };
|
char callsign[7] = { ' ', ' ', ' ', ' ', ' ', ' ', '\0' };
|
||||||
uint8_t editorPinMap[8] = { 10, 11, 4, 6, 7, 8, 9, 5 };
|
uint8_t editorPinMap[8] = { 10, 9, 12, 8, 5, 7, 6, 11 };
|
||||||
|
|
||||||
|
uint32_t lastBroadcast = 0;
|
||||||
|
|
||||||
struct ax25 {
|
struct ax25 {
|
||||||
uint8_t daddr[7];
|
uint8_t daddr[7];
|
||||||
|
@ -108,7 +116,7 @@ void initFrame() {
|
||||||
frame.daddr[i] <<=1;
|
frame.daddr[i] <<=1;
|
||||||
frame.saddr[i] <<=1;
|
frame.saddr[i] <<=1;
|
||||||
}
|
}
|
||||||
frame.daddr[6] = (NONE << 1) | 0xe0; // command bit + reserved bits (AX.25 3.12.2)
|
frame.daddr[6] = (DESTINATION[6] << 1) | 0xe0; // command bit + reserved bits (AX.25 3.12.2)
|
||||||
frame.saddr[6] = (callsign[6] << 1) | 0xe1; // command bit + reserved bits + end bit
|
frame.saddr[6] = (callsign[6] << 1) | 0xe1; // command bit + reserved bits + end bit
|
||||||
frame.ctrl = 0x03;
|
frame.ctrl = 0x03;
|
||||||
frame.proto = 0xf0;
|
frame.proto = 0xf0;
|
||||||
|
@ -121,6 +129,10 @@ uint8_t mirrorByte(uint8_t byt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
pinMode(PTT, OUTPUT);
|
||||||
|
digitalWrite(PTT, LOW);
|
||||||
|
pinMode(PTT_IND, OUTPUT);
|
||||||
|
digitalWrite(PTT_IND, LOW);
|
||||||
initEditor(callsign, 7, EDITOR_EEPROM_BASE, editorPinMap);
|
initEditor(callsign, 7, EDITOR_EEPROM_BASE, editorPinMap);
|
||||||
OUT_DDR = 0x3f;
|
OUT_DDR = 0x3f;
|
||||||
setZero();
|
setZero();
|
||||||
|
@ -173,8 +185,12 @@ void readNmeaGll() {
|
||||||
if (byt == '\n') {
|
if (byt == '\n') {
|
||||||
state = 2;
|
state = 2;
|
||||||
*sptr = 0;
|
*sptr = 0;
|
||||||
if (str[3] == 'R' && str[4] == 'M' && str[5] == 'C' && *(sptr-6) == 'A') {
|
if (str[3] == 'R' && str[4] == 'M' && str[5] == 'C') {
|
||||||
state = 2;
|
if (SEND_INVALID || *(sptr-6) == 'A') {
|
||||||
|
state = 2;
|
||||||
|
} else {
|
||||||
|
state = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
|
@ -186,27 +202,36 @@ void readNmeaGll() {
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// AX.25 3.8 - FCS is sent MSB first
|
uint32_t now = millis();
|
||||||
uint16_t fcs = 0xffff;
|
if (now - lastBroadcast > MIN_INTERVAL || lastBroadcast == 0) {
|
||||||
for (size_t i = 0; i < sizeof(frame); ++i) {
|
lastBroadcast = now;
|
||||||
fcs = _crc_xmodem_update(fcs, mirrorByte(((uint8_t*) &frame)[i]));
|
// AX.25 3.8 - FCS is sent MSB first
|
||||||
|
uint16_t fcs = 0xffff;
|
||||||
|
for (size_t i = 0; i < sizeof(frame); ++i) {
|
||||||
|
fcs = _crc_xmodem_update(fcs, mirrorByte(((uint8_t*) &frame)[i]));
|
||||||
|
}
|
||||||
|
for (char *c = str; c < sptr; ++c) {
|
||||||
|
fcs = _crc_xmodem_update(fcs, mirrorByte(*c));
|
||||||
|
}
|
||||||
|
fcs ^= 0xffff;
|
||||||
|
fcs = (mirrorByte(fcs & 0xff) << 8) | mirrorByte(fcs >> 8);
|
||||||
|
digitalWrite(PTT, HIGH);
|
||||||
|
digitalWrite(PTT_IND, HIGH);
|
||||||
|
sendFlag(true, TXDELAY+1);
|
||||||
|
for (uint8_t i = i; i < FRAME_REPEAT; ++i) {
|
||||||
|
sendBell202buf((uint8_t*) &frame, sizeof(frame), false);
|
||||||
|
sendBell202buf((uint8_t*) str, sptr-str, false);
|
||||||
|
sendBell202buf((uint8_t*) &fcs, 2, false);
|
||||||
|
sendFlag(false, 1);
|
||||||
|
}
|
||||||
|
setZero();
|
||||||
|
nrzi = true;
|
||||||
|
digitalWrite(PTT, LOW);
|
||||||
|
digitalWrite(PTT_IND, LOW);
|
||||||
}
|
}
|
||||||
for (char *c = str; c < sptr; ++c) {
|
|
||||||
fcs = _crc_xmodem_update(fcs, mirrorByte(*c));
|
|
||||||
}
|
|
||||||
fcs ^= 0xffff;
|
|
||||||
fcs = (mirrorByte(fcs & 0xff) << 8) | mirrorByte(fcs >> 8);
|
|
||||||
sendFlag(true, TXDELAY+1);
|
|
||||||
sendBell202buf((uint8_t*) &frame, sizeof(frame), false);
|
|
||||||
sendBell202buf((uint8_t*) str, sptr-str, false);
|
|
||||||
sendBell202buf((uint8_t*) &fcs, 2, false);
|
|
||||||
sendFlag(false, 1);
|
|
||||||
setZero();
|
|
||||||
nrzi = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
readNmeaGll();
|
readNmeaGll();
|
||||||
delay(10000);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue