Skip to content

Commit db4582d

Browse files
committed
telemetry EUP beacon update
1 parent 09e06d3 commit db4582d

4 files changed

Lines changed: 56 additions & 52 deletions

File tree

include/telemetry_utils.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* Copyright (C) 2025 Ricardo Guzman - CA2RXU
2-
*
2+
*
33
* This file is part of LoRa APRS iGate.
4-
*
4+
*
55
* LoRa APRS iGate is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
7+
* the Free Software Foundation, either version 3 of the License, or
88
* (at your option) any later version.
9-
*
9+
*
1010
* LoRa APRS iGate is distributed in the hope that it will be useful,
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
* GNU General Public License for more details.
14-
*
14+
*
1515
* You should have received a copy of the GNU General Public License
1616
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
1717
*/
@@ -27,7 +27,8 @@ namespace TELEMETRY_Utils {
2727
void sendEquationsUnitsParameters();
2828
String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType);
2929
String generateEncodedTelemetry();
30-
30+
void checkEUPInterval();
31+
3132
}
3233

3334
#endif

src/station_utils.cpp

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ std::vector<LastHeardStation> lastHeardObjects;
4040
struct OutputPacketBuffer {
4141
String packet;
4242
bool isBeacon;
43+
OutputPacketBuffer(const String& p, bool b) : packet(p), isBeacon(b) {}
4344
};
4445
std::vector<OutputPacketBuffer> outputPacketBuffer;
4546

@@ -57,19 +58,18 @@ namespace STATION_Utils {
5758

5859
std::vector<String> loadCallsignList(const String& list) {
5960
std::vector<String> loadedList;
61+
int start = 0;
62+
int listLength = list.length();
6063

61-
String callsigns = list;
62-
callsigns.trim();
64+
while (start < listLength) {
65+
while (start < listLength && list[start] == ' ') start++; // avoid blank spaces
66+
if (start >= listLength) break;
6367

64-
while (callsigns.length() > 0) { // != ""
65-
int spaceIndex = callsigns.indexOf(" ");
66-
if (spaceIndex == -1) { // No more spaces, add the last part
67-
loadedList.push_back(callsigns);
68-
break;
69-
}
70-
loadedList.push_back(callsigns.substring(0, spaceIndex));
71-
callsigns = callsigns.substring(spaceIndex + 1);
72-
callsigns.trim(); // Trim in case of multiple spaces
68+
int end = start;
69+
while (end < listLength && list[end] != ' ') end++; // find another blank space or reach listLength
70+
71+
loadedList.emplace_back(list.substring(start, end));
72+
start = end + 1; // keep on searching if listLength not reached
7373
}
7474
return loadedList;
7575
}
@@ -126,36 +126,33 @@ namespace STATION_Utils {
126126
}
127127

128128
void deleteNotHeard() {
129-
std::vector<LastHeardStation> lastHeardStation_temp;
130-
for (int i = 0; i < lastHeardStations.size(); i++) {
131-
if (millis() - lastHeardStations[i].lastHeardTime < Config.rememberStationTime * 60 * 1000) {
132-
lastHeardStation_temp.push_back(lastHeardStations[i]);
129+
uint32_t currentTime = millis();
130+
uint32_t timeout = Config.rememberStationTime * 60UL * 1000UL;
131+
132+
for (int i = lastHeardStations.size() - 1; i >= 0; i--) {
133+
if (currentTime - lastHeardStations[i].lastHeardTime >= timeout) {
134+
lastHeardStations.erase(lastHeardStations.begin() + i);
133135
}
134136
}
135-
lastHeardStations.clear();
136-
for (int j = 0; j < lastHeardStation_temp.size(); j++) {
137-
lastHeardStations.push_back(lastHeardStation_temp[j]);
138-
}
139-
lastHeardStation_temp.clear();
140137
}
141138

142139
void updateLastHeard(const String& station) {
143140
deleteNotHeard();
144-
bool stationHeard = false;
145-
for (int i = 0; i < lastHeardStations.size(); i++) {
141+
uint32_t currentTime = millis();
142+
for (size_t i = 0; i < lastHeardStations.size(); i++) {
146143
if (lastHeardStations[i].station == station) {
147-
lastHeardStations[i].lastHeardTime = millis();
148-
stationHeard = true;
149-
break;
144+
lastHeardStations[i].lastHeardTime = currentTime;
145+
Utils::showActiveStations();
146+
return;
150147
}
151148
}
152-
if (!stationHeard) lastHeardStations.emplace_back(LastHeardStation{millis(), station});
149+
lastHeardStations.emplace_back(LastHeardStation{currentTime, station});
153150
Utils::showActiveStations();
154151
}
155152

156153
bool wasHeard(const String& station) {
157154
deleteNotHeard();
158-
for (int i = 0; i < lastHeardStations.size(); i++) {
155+
for (size_t i = 0; i < lastHeardStations.size(); i++) {
159156
if (lastHeardStations[i].station == station) {
160157
Utils::println(" ---> Listened Station");
161158
return true;
@@ -184,9 +181,9 @@ namespace STATION_Utils {
184181
}
185182

186183
bool isIn25SegHashBuffer(const String& station, const String& textMessage) {
187-
uint32_t newHash = makeHash(station, textMessage);
188-
uint32_t currentTime = millis();
189184
clean25SegHashBuffer();
185+
uint32_t newHash = makeHash(station, textMessage);
186+
uint32_t currentTime = millis();
190187
for (int i = 0; i < packet25SegBuffer.size(); i++) {
191188
if (packet25SegBuffer[i].hash == newHash) return true;
192189
}
@@ -243,11 +240,7 @@ namespace STATION_Utils {
243240
}
244241

245242
void addToOutputPacketBuffer(const String& packet, bool flag) {
246-
OutputPacketBuffer entry;
247-
entry.packet = packet;
248-
entry.isBeacon = flag;
249-
250-
outputPacketBuffer.push_back(entry);
243+
outputPacketBuffer.emplace_back(OutputPacketBuffer{packet, flag});
251244
}
252245

253246
}

src/telemetry_utils.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* Copyright (C) 2025 Ricardo Guzman - CA2RXU
2-
*
2+
*
33
* This file is part of LoRa APRS iGate.
4-
*
4+
*
55
* LoRa APRS iGate is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
7+
* the Free Software Foundation, either version 3 of the License, or
88
* (at your option) any later version.
9-
*
9+
*
1010
* LoRa APRS iGate is distributed in the hope that it will be useful,
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
* GNU General Public License for more details.
14-
*
14+
*
1515
* You should have received a copy of the GNU General Public License
1616
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
1717
*/
@@ -29,10 +29,11 @@
2929
#include "display.h"
3030

3131

32-
extern Configuration Config;
33-
extern bool sendStartTelemetry;
32+
extern Configuration Config;
3433

35-
int telemetryCounter = random(1,999);
34+
int telemetryCounter = random(1,999);
35+
uint32_t telemetryEUPTime = 0;
36+
bool sendEUP = false; // Equations Units Parameters
3637

3738

3839
namespace TELEMETRY_Utils {
@@ -89,7 +90,7 @@ namespace TELEMETRY_Utils {
8990
sendBaseTelemetryPacket("EQNS.", getEquationCoefficients());
9091
sendBaseTelemetryPacket("UNIT.", getUnitLabels());
9192
sendBaseTelemetryPacket("PARM.", getParameterNames());
92-
sendStartTelemetry = false;
93+
sendEUP = false;
9394
}
9495

9596
String generateEncodedTelemetryBytes(float value, bool counterBytes, byte telemetryType) {
@@ -106,7 +107,7 @@ namespace TELEMETRY_Utils {
106107
case 3: tempValue = (value * 8); break; // Pressure
107108
default: tempValue = value; break;
108109
}
109-
}
110+
}
110111

111112
int firstByte = tempValue / 91;
112113
tempValue -= firstByte * 91;
@@ -127,4 +128,11 @@ namespace TELEMETRY_Utils {
127128
return telemetry;
128129
}
129130

131+
void checkEUPInterval() {
132+
if (telemetryEUPTime == 0 || millis() - telemetryEUPTime > 24UL * 60UL * 60UL * 1000UL) {
133+
sendEUP = true;
134+
telemetryEUPTime = millis();
135+
}
136+
}
137+
130138
}

src/utils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ extern bool backupDigiMode;
5858
extern bool shouldSleepLowVoltage;
5959
extern bool transmitFlag;
6060
extern bool passcodeValid;
61+
extern bool sendEUP; // Equations Units Parameters
6162

6263
extern std::vector<LastHeardStation> lastHeardStations;
6364

6465
bool statusAfterBoot = true;
65-
bool sendStartTelemetry = true;
66+
6667
bool beaconUpdate = false;
6768
uint32_t lastBeaconTx = 0;
6869
uint32_t lastScreenOn = millis();
@@ -157,7 +158,8 @@ namespace Utils {
157158
if (beaconUpdate) {
158159
if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true);
159160

160-
if (sendStartTelemetry &&
161+
TELEMETRY_Utils::checkEUPInterval();
162+
if (sendEUP &&
161163
Config.battery.sendVoltageAsTelemetry &&
162164
!Config.wxsensor.active &&
163165
(Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage) &&

0 commit comments

Comments
 (0)