This commit is contained in:
richonguzman 2024-05-13 20:29:08 -04:00
parent bee09386e1
commit 2e4ee4792e
3 changed files with 37 additions and 0 deletions

View file

@ -227,6 +227,7 @@ void loop() {
}
STATION_Utils::processOutputPacketBuffer();
STATION_Utils::clean25SegBuffer();
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
}

View file

@ -12,6 +12,9 @@ extern uint32_t lastTxTime;
extern uint32_t lastRxTime;
extern String fourthLine;
std::vector<String> packet25SegBuffer;
std::vector<uint32_t> 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;

View file

@ -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);