Skip to content

Commit 9fd48f0

Browse files
committed
v3.1.0 - update getSystemTime for new epoch
1 parent 79d89b1 commit 9fd48f0

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=IridiumSBDi2c
2-
version=3.0.8
2+
version=3.1.0
33
author=Mikal Hart and Paul Clark (PaulZC)
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=This library supports satellite data transmissions from anywhere on earth using the RockBLOCK family of Iridium 9602 and 9603 modems.

src/IridiumSBD.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,33 @@ int IridiumSBD::getSystemTime(struct tm &tm)
266266
if (!isxdigit(msstmResponseBuf[0]))
267267
return ISBD_NO_NETWORK;
268268

269-
// Latest epoch began at May 11, 2014, at 14:23:55 UTC.
270-
struct tm epoch_start;
271-
epoch_start.tm_year = 2014 - 1900;
272-
epoch_start.tm_mon = 5 - 1;
273-
epoch_start.tm_mday = 11;
274-
epoch_start.tm_hour = 14;
275-
epoch_start.tm_min = 23;
276-
epoch_start.tm_sec = 55;
277-
epoch_start.tm_isdst = 0; // Resolves #16
269+
// From the AT Command Reference:
270+
// The system time as received through the Iridium Air
271+
// Interface, is a 32 bit integer count of the number of 90 millisecond
272+
// intervals that have elapsed since the epoch. The return value is
273+
// formatted as an ASCII hexadecimal number. The counter will rollover
274+
// approximately every 12 years or be changed to prevent a rollover and
275+
// as a result should not be used as a time source for user applications
276+
277+
// Current epoch: May 11, 2014, at 14:23:55 UTC.
278+
struct tm epoch_start_current;
279+
epoch_start_current.tm_year = 2014 - 1900;
280+
epoch_start_current.tm_mon = 5 - 1;
281+
epoch_start_current.tm_mday = 11;
282+
epoch_start_current.tm_hour = 14;
283+
epoch_start_current.tm_min = 23;
284+
epoch_start_current.tm_sec = 55;
285+
epoch_start_current.tm_isdst = 0; // Resolves #16
286+
287+
// Future epoch: February 14, 2025, at 18:14:17 UTC.
288+
struct tm epoch_start_future;
289+
epoch_start_future.tm_year = 2025 - 1900;
290+
epoch_start_future.tm_mon = 2 - 1;
291+
epoch_start_future.tm_mday = 14;
292+
epoch_start_future.tm_hour = 18;
293+
epoch_start_future.tm_min = 14;
294+
epoch_start_future.tm_sec = 17;
295+
epoch_start_future.tm_isdst = 0; // Resolves #16
278296

279297
unsigned long ticks_since_epoch = strtoul(msstmResponseBuf, NULL, 16);
280298

@@ -288,9 +306,23 @@ int IridiumSBD::getSystemTime(struct tm &tm)
288306
unsigned long small_ticks = ticks_since_epoch - (secs_since_epoch / 90) * 1000;
289307
secs_since_epoch += small_ticks * 90 / 1000;
290308

291-
time_t epoch_time = mktime(&epoch_start);
309+
time_t epoch_time = mktime(&epoch_start_current); // Try current epoch first
292310
time_t now = epoch_time + secs_since_epoch;
311+
struct tm * local_now = localtime(&now);
312+
313+
// Extract the current year from __DATE__
314+
int build_year = (((int)(__DATE__[7] - 0x30) * 1000) + ((int)(__DATE__[8] - 0x30) * 100)
315+
+ ((int)(__DATE__[9] - 0x30) * 10) + ((int)(__DATE__[10] - 0x30) * 1));
316+
317+
// Check if year is within bounds
318+
if ((local_now->tm_year + 1900) < build_year)
319+
{
320+
epoch_time = mktime(&epoch_start_future); // Use future epoch
321+
now = epoch_time + secs_since_epoch;
322+
}
323+
293324
memcpy(&tm, localtime(&now), sizeof tm);
325+
294326
return ISBD_SUCCESS;
295327
}
296328

0 commit comments

Comments
 (0)