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
35
src/main.cpp
35
src/main.cpp
|
@ -5,12 +5,20 @@
|
|||
#include "afsk_sinus.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 FRAME_REPEAT 3
|
||||
|
||||
#define PTT 4
|
||||
#define PTT_IND 13
|
||||
|
||||
#define EDITOR_EEPROM_BASE 42
|
||||
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 {
|
||||
uint8_t daddr[7];
|
||||
|
@ -108,7 +116,7 @@ void initFrame() {
|
|||
frame.daddr[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.ctrl = 0x03;
|
||||
frame.proto = 0xf0;
|
||||
|
@ -121,6 +129,10 @@ uint8_t mirrorByte(uint8_t byt) {
|
|||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(PTT, OUTPUT);
|
||||
digitalWrite(PTT, LOW);
|
||||
pinMode(PTT_IND, OUTPUT);
|
||||
digitalWrite(PTT_IND, LOW);
|
||||
initEditor(callsign, 7, EDITOR_EEPROM_BASE, editorPinMap);
|
||||
OUT_DDR = 0x3f;
|
||||
setZero();
|
||||
|
@ -173,11 +185,15 @@ void readNmeaGll() {
|
|||
if (byt == '\n') {
|
||||
state = 2;
|
||||
*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') {
|
||||
if (SEND_INVALID || *(sptr-6) == 'A') {
|
||||
state = 2;
|
||||
} else {
|
||||
state = 0;
|
||||
}
|
||||
} else {
|
||||
state = 0;
|
||||
}
|
||||
Serial.print(str);
|
||||
Serial.flush();
|
||||
}
|
||||
|
@ -186,6 +202,9 @@ void readNmeaGll() {
|
|||
state = 0;
|
||||
}
|
||||
}
|
||||
uint32_t now = millis();
|
||||
if (now - lastBroadcast > MIN_INTERVAL || lastBroadcast == 0) {
|
||||
lastBroadcast = now;
|
||||
// AX.25 3.8 - FCS is sent MSB first
|
||||
uint16_t fcs = 0xffff;
|
||||
for (size_t i = 0; i < sizeof(frame); ++i) {
|
||||
|
@ -196,17 +215,23 @@ void readNmeaGll() {
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
readNmeaGll();
|
||||
delay(10000);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue