From 67e974c4e464bd0c8f87fb886fc5f0d41264a96f Mon Sep 17 00:00:00 2001 From: s3lph Date: Mon, 8 May 2023 01:24:37 +0200 Subject: [PATCH] feat: add option to configure position ambiguity for privacy reasons --- src/main.cpp | 118 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 86 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e1909d3..95cfcae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,10 @@ #include "afsk_sinus.hpp" +#ifndef SEND_INVALID #define SEND_INVALID 0 +#endif + #define DESTINATION "WIDE1 \x01" #define TXDELAY 32 #define FRAME_REPEAT 3 @@ -198,6 +201,7 @@ struct __attribute__((packed)) EepromConfig { uint16_t interval; uint8_t commentLen; uint8_t comment[32]; + uint8_t positionAmbiguity; }; struct EepromConfig config; @@ -227,6 +231,7 @@ uint32_t lastPressed = 0; bool off = true; bool editingConfig = false; bool editingComment = false; +bool editingAmbiguity = false; uint8_t configEditState = 0; uint8_t commentEditState = 0; @@ -254,13 +259,14 @@ uint8_t mirrorByte(uint8_t byt) { void createDefaultConfig() { - config.flag = 1; + config.flag = 2; memset(&config.srcCallsign, ' ', 6); config.srcSsid = 0; config.marker = 'b'; config.interval = 300; config.commentLen = 0; memset(&config.comment, ' ', 32); + config.positionAmbiguity = 4; } void writeEepromConfig() { @@ -503,10 +509,33 @@ void editComment() { } } lcd.print((char) config.comment[commentEditState]); - lcd.setCursor(commentEditState%16, commentEditState/16); + lcd.setCursor(commentEditState%16, commentEditState/16); } }; +void editAmbiguity() { + if (abcPressed) { + abcPressed = false; + config.positionAmbiguity = (config.positionAmbiguity + 1) % 5; + } + if (setPressed) { + setPressed = false; + writeEepromConfig(); + editingAmbiguity = false; + return; + } + lcd.setCursor(0, 0); + lcd.print("Pos. Ambiguity"); + lcd.setCursor(0, 1); + lcd.print(" 47\xdf "); + lcd.print(config.positionAmbiguity > 0 ? '1' : '_'); + lcd.print(config.positionAmbiguity > 1 ? '2' : '_'); + lcd.print('.'); + lcd.print(config.positionAmbiguity > 2 ? '3' : '_'); + lcd.print(config.positionAmbiguity > 3 ? '4' : '_'); + lcd.print('\''); +}; + uint8_t nmeaState = 0; char nmeaStr[256]; // NMEA-0183 messages should only be 82 characters, but the NEO-6M sends much longer messages @@ -624,10 +653,24 @@ void readNmeaRmc() { rmc.lonDeg, rmc.lonMin, rmc.lonDir, config.marker, rmc.course, rmc.speed); } else { - snprintf(aprs, 256, "/012058z4700.00N/00700.00Eb000/000"); + snprintf(aprs, 256, "/012058z4712.34N/00712.34Eb000/000"); + } + // Insert position ambiguity + if (config.positionAmbiguity < 1) { + aprs[10] = aprs[20] = ' '; + } + if (config.positionAmbiguity < 2) { + aprs[11] = aprs[21] = ' '; + } + if (config.positionAmbiguity < 3) { + aprs[13] = aprs[23] = ' '; + } + if (config.positionAmbiguity < 4) { + aprs[14] = aprs[24] = ' '; } memcpy(aprs+34, config.comment, config.commentLen); aprs[34+config.commentLen] = 0; + Serial.println(aprs); // AX.25 3.8 - FCS is sent MSB first uint16_t fcs = 0xffff; for (size_t i = 0; i < sizeof(frame); ++i) { @@ -702,39 +745,50 @@ void setup() { void loop() { readNmeaRmc(); - if (editingConfig) { - editConfig(); - return; + if (editingConfig) { + editConfig(); + return; + } + if (editingComment) { + editComment(); + return; + } + if (editingAmbiguity) { + editAmbiguity(); + return; + } + if (abcPressed) { + abcPressed = false; + page = (page + 1) % 4; + lcd.clear(); + } + if (page == 0) { + printConfig(); + if (setPressed) { + setPressed = false; + editingConfig = true; + lcd.blink(); } - if (editingComment) { - editComment(); - return; - } - if (abcPressed) { - abcPressed = false; - page = (page + 1) % 4; + } else if (page == 1) { + printComment(); + if (setPressed) { + setPressed = false; + editingComment = true; lcd.clear(); - } - if (page == 0) { - printConfig(); - if (setPressed) { - setPressed = false; - editingConfig = true; - lcd.blink(); - } - } else if (page == 1) { printComment(); - if (setPressed) { - setPressed = false; - editingComment = true; - lcd.clear(); - lcd.blink(); - } - } else if (page == 2) { - printLocation(); - } else if (page == 3) { - printDateTime(); + lcd.blink(); } + } else if (page == 2) { + printLocation(); + if (setPressed) { + setPressed = false; + editingAmbiguity = true; + lcd.clear(); + editAmbiguity(); + } + } else if (page == 3) { + printDateTime(); + } LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); if (!abcPressed && !setPressed) { off = true;