diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 5982612..d012ce5 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -227,6 +227,7 @@ void loop() { } STATION_Utils::processOutputPacketBuffer(); + STATION_Utils::clean25SegBuffer(); show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); } \ No newline at end of file diff --git a/src/station_utils.cpp b/src/station_utils.cpp index b10c82f..373a26d 100644 --- a/src/station_utils.cpp +++ b/src/station_utils.cpp @@ -12,6 +12,9 @@ extern uint32_t lastTxTime; extern uint32_t lastRxTime; extern String fourthLine; +std::vector packet25SegBuffer; +std::vector packet25SegTimeBuffer; + namespace STATION_Utils { @@ -63,6 +66,37 @@ namespace STATION_Utils { return false; } + void clean25SegBuffer() { + if (!packet25SegTimeBuffer.empty()) { + if (millis() - packet25SegTimeBuffer[0] > 25 * 1000) { + packet25SegTimeBuffer.erase(packet25SegTimeBuffer.begin()); + packet25SegBuffer.erase(packet25SegBuffer.begin()); + } + } + } + + bool check25SegBuffer(String station, String textMessage) { + if (!packet25SegBuffer.empty()) { + bool shouldBeIgnored = false; + for (int i = 0; i < packet25SegBuffer.size(); i++) { + if (packet25SegBuffer[i].substring(0, packet25SegBuffer[i].indexOf(",")) == station && packet25SegBuffer[i].substring(packet25SegBuffer[i].indexOf(",") + 1) == textMessage) { + shouldBeIgnored = true; + } + } + if (shouldBeIgnored) { + return false; + } else { + packet25SegBuffer.push_back(station + "," + textMessage); + packet25SegTimeBuffer.push_back(millis()); + return true; + } + } else { + packet25SegBuffer.push_back(station + "," + textMessage); + packet25SegTimeBuffer.push_back(millis()); + return true; + } + } + void processOutputPacketBuffer() { int timeToWait = 3 * 1000; // 3 segs between packet Tx and also Rx ??? uint32_t lastRx = millis() - lastRxTime; diff --git a/src/station_utils.h b/src/station_utils.h index c0be3e1..d9423b9 100644 --- a/src/station_utils.h +++ b/src/station_utils.h @@ -9,6 +9,8 @@ namespace STATION_Utils { void deleteNotHeard(); void updateLastHeard(String station); bool wasHeard(String station); + void clean25SegBuffer(); + bool check25SegBuffer(String station, String textMessage); void processOutputPacketBuffer(); void addToOutputPacketBuffer(String packet);