Skip to content

Commit f5c052c

Browse files
committed
fix storage dumping; send latest location together with ping
1 parent ea1b0e6 commit f5c052c

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

firmware_v5/telelogger/telelogger.ino

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ void processExtInputs(CBuffer* buffer)
173173
}
174174
#endif
175175

176+
CStorageRAM latestLocationStore;
177+
178+
void prepareData(CStorageRAM* store, CBuffer* buffer) {
179+
// here we use CStorageRAM to serialize data correctly
180+
store->purge();
181+
#if SERVER_PROTOCOL == PROTOCOL_UDP
182+
store->header(devid);
183+
#endif
184+
185+
store->timestamp(buffer->timestamp);
186+
buffer->serialize(*store);
187+
store->tailer();
188+
}
189+
176190
/*******************************************************************************
177191
HTTP API
178192
*******************************************************************************/
@@ -804,14 +818,14 @@ void process()
804818
processMEMS(buffer);
805819
#endif
806820

807-
processGPS(buffer);
821+
bool receivedGPS = processGPS(buffer);
808822

809823
float cpuTemp = readChipTemperature();
810824
buffer->add(PID_CPU_TEMP, (int) (cpuTemp * 10));
811825
if (!state.check(STATE_MEMS_READY)) {
812826
deviceTemp = cpuTemp;
813827
}
814-
828+
815829
buffer->timestamp = millis();
816830
buffer->state = BUFFER_STATE_FILLED;
817831

@@ -821,9 +835,10 @@ void process()
821835
lastStatsTime = startTime;
822836
}
823837

838+
prepareData(&latestLocationStore, buffer);
824839
#if STORAGE != STORAGE_NONE
825840
if (state.check(STATE_STORAGE_READY)) {
826-
buffer->serialize(logger);
841+
logger.dispatch(latestLocationStore.buffer(), latestLocationStore.length());
827842
uint16_t sizeKB = (uint16_t)(logger.size() >> 10);
828843
if (sizeKB != lastSizeKB) {
829844
logger.flush();
@@ -1027,6 +1042,7 @@ void telemetry(void* inst)
10271042
if (initNetwork()) {
10281043
Serial.print("Ping...");
10291044
bool success = teleClient.ping();
1045+
bool successData = teleClient.transmit(latestLocationStore.buffer(), latestLocationStore.length());
10301046
Serial.println(success ? "OK" : "NO");
10311047
}
10321048
teleClient.shutdown();
@@ -1056,17 +1072,12 @@ void telemetry(void* inst)
10561072
}
10571073

10581074
buffer->state = BUFFER_STATE_LOCKED;
1059-
#if SERVER_PROTOCOL == PROTOCOL_UDP
1060-
store.header(devid);
1061-
#endif
1062-
store.timestamp(buffer->timestamp);
1063-
buffer->serialize(store);
1075+
prepareData(&store, buffer);
10641076
buffer->purge();
1065-
store.tailer();
1066-
//Serial.println(store.buffer());
10671077

10681078
// start transmission
10691079
if (ledMode == 0) digitalWrite(PIN_LED, HIGH);
1080+
10701081
if (teleClient.transmit(store.buffer(), store.length())) {
10711082
// successfully sent
10721083
connErrors = 0;
@@ -1078,8 +1089,6 @@ void telemetry(void* inst)
10781089
}
10791090
if (ledMode == 0) digitalWrite(PIN_LED, LOW);
10801091

1081-
store.purge();
1082-
10831092
teleClient.inbound();
10841093
if (syncInterval > 10000 && millis() - teleClient.lastSyncTime > syncInterval) {
10851094
Serial.println("Instable connection");
@@ -1353,6 +1362,7 @@ void setup()
13531362
Serial.println("HTTPD:NO");
13541363
}
13551364
#endif
1365+
latestLocationStore.init(SERIALIZE_BUFFER_SIZE);
13561366

13571367
state.set(STATE_WORKING);
13581368
// initialize network and maintain connection

0 commit comments

Comments
 (0)