diff --git a/src/main.cpp b/src/main.cpp index d66b6eb..bbb975d 100644 --- a/src/main.cpp +++ b/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,8 +185,12 @@ void readNmeaGll() { if (byt == '\n') { state = 2; *sptr = 0; - if (str[3] == 'R' && str[4] == 'M' && str[5] == 'C' && *(sptr-6) == 'A') { - state = 2; + if (str[3] == 'R' && str[4] == 'M' && str[5] == 'C') { + if (SEND_INVALID || *(sptr-6) == 'A') { + state = 2; + } else { + state = 0; + } } else { state = 0; } @@ -186,27 +202,36 @@ void readNmeaGll() { state = 0; } } - // 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])); + 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) { + 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() { readNmeaGll(); - delay(10000); }