Skip to content

Commit 9e74213

Browse files
committed
Correctly print key date and duration
1 parent 78ca62c commit 9e74213

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Firmware/RTK_Surveyor/menuPP.ino

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,28 +189,27 @@ char *printDateFromGPSEpoch(long long gpsEpoch)
189189
// https://www.epochconverter.com/programming/c
190190
char *printDateFromUnixEpoch(long long unixEpoch)
191191
{
192-
char *buf = (char *)malloc(strlen("01/01/1010"));
193-
time_t rawtime = unixEpoch;
192+
char *buf = (char *)malloc(strlen("01/01/2023") + 1); //Make room for terminator
193+
time_t rawtime = unixEpoch;
194194

195-
struct tm ts;
196-
ts = *localtime(&rawtime);
195+
struct tm ts;
196+
ts = *localtime(&rawtime);
197197

198-
// Format time, "dd/mm/yyyy"
199-
strftime(buf, strlen("01/01/1010"), "%d/%m/%Y", &ts);
200-
return (buf);
198+
// Format time, "dd/mm/yyyy"
199+
strftime(buf, strlen("01/01/2023") + 1, "%d/%m/%Y", &ts);
200+
return (buf);
201201
}
202202

203203
// Given a duration in ms, print days
204204
char *printDaysFromDuration(long long duration)
205205
{
206-
duration /= (1000L * 60L * 60 * 24); //Convert ms to days
206+
float days = duration / (1000.0 * 60 * 60 * 24); //Convert ms to days
207207

208-
char *response = (char *)malloc(strlen("34.9"));
209-
sprintf(response, "%0.2f", duration);
210-
return (response);
208+
char *response = (char *)malloc(strlen("34.9") + 1); //Make room for terminator
209+
sprintf(response, "%0.2f", days);
210+
return (response);
211211
}
212212

213-
214213
// Connect to 'home' WiFi and then ThingStream API. This will attach this unique device to the ThingStream network.
215214
bool pointperfectProvisionDevice()
216215
{
@@ -375,10 +374,10 @@ bool pointperfectProvisionDevice()
375374
if (settings.debugLBand == true)
376375
{
377376
systemPrintf(" pointPerfectCurrentKey: %s\r\n", settings.pointPerfectCurrentKey);
378-
systemPrintf(" pointPerfectCurrentKeyStart: %lld - %s\r\n", settings.pointPerfectCurrentKeyStart, printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart));
377+
systemPrintf(" pointPerfectCurrentKeyStart: %lld - %s\r\n", settings.pointPerfectCurrentKeyStart, printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart / 1000)); //printDateFromUnixEpoch expects seconds
379378
systemPrintf(" pointPerfectCurrentKeyDuration: %lld - %s\r\n", settings.pointPerfectCurrentKeyDuration, printDaysFromDuration(settings.pointPerfectCurrentKeyDuration));
380379
systemPrintf(" pointPerfectNextKey: %s\r\n", settings.pointPerfectNextKey);
381-
systemPrintf(" pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, printDateFromUnixEpoch(settings.pointPerfectNextKeyStart));
380+
systemPrintf(" pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, printDateFromUnixEpoch(settings.pointPerfectNextKeyStart / 1000));
382381
systemPrintf(" pointPerfectNextKeyDuration: %lld - %s\r\n", settings.pointPerfectNextKeyDuration, printDaysFromDuration(settings.pointPerfectNextKeyDuration));
383382
}
384383
}
@@ -717,8 +716,7 @@ void mqttCallback(char *topic, byte *message, unsigned int length)
717716
settings.pointPerfectNextKeyStart - settings.pointPerfectCurrentKeyStart - 1;
718717
// settings.pointPerfectNextKeyDuration =
719718
// settings.pointPerfectCurrentKeyDuration; // We assume next key duration is the same as current key
720-
// duration
721-
// // because we have to
719+
// duration because we have to
722720

723721
settings.pointPerfectNextKeyDuration = (1000LL * 60 * 60 * 24 * 28) - 1; // Assume next key duration is 28 days
724722

0 commit comments

Comments
 (0)