mirror of https://github.com/ARMmbed/mbed-os.git
Exposing GPS/UTC time APIs
Provides hooks for the internal APIs handling GPS time base for device synchronization. In addition to that 'set_system_time_utc(...)' API is added which have no roots in the stack. Its just a helper for the application developer to acquire UTC time base given the difference between TAI and UTC time bases.feature-lorawan-1-1
parent
ef6bc1d0a4
commit
6654a595d6
|
@ -190,3 +190,40 @@ lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_
|
||||||
Lock lock(*this);
|
Lock lock(*this);
|
||||||
return _lw_stack.set_device_class(device_class);
|
return _lw_stack.set_device_class(device_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lorawan_time_t LoRaWANInterface::get_current_gps_time()
|
||||||
|
{
|
||||||
|
Lock lock(*this);
|
||||||
|
return _lw_stack.get_current_gps_time();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRaWANInterface::set_current_gps_time(lorawan_time_t gps_time)
|
||||||
|
{
|
||||||
|
Lock lock(*this);
|
||||||
|
_lw_stack.set_current_gps_time(gps_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
lorawan_status_t LoRaWANInterface::set_system_time_utc(unsigned int tai_utc_diff)
|
||||||
|
{
|
||||||
|
// do not lock here
|
||||||
|
|
||||||
|
// Adjust epoch for 1970 to 1980 (time for Unix epoch to GPS epoch)
|
||||||
|
lorawan_time_t u_time = time(NULL) + UNIX_GPS_EPOCH_DIFF;
|
||||||
|
// Adjust for leap seconds since 1980. TAI is always ahead of GPS by 19 seconds
|
||||||
|
u_time += (tai_utc_diff - 19);
|
||||||
|
lorawan_time_t cur_gps_time = get_current_gps_time();
|
||||||
|
|
||||||
|
if (cur_gps_time == 0) {
|
||||||
|
// GPS time is not set. Application needs to request a clock sync.
|
||||||
|
return LORAWAN_STATUS_SERVICE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
u_time += cur_gps_time;
|
||||||
|
|
||||||
|
set_time(u_time);
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
tr_info("System Clock set - (UTC) = %s", ctime(&now));
|
||||||
|
|
||||||
|
return LORAWAN_STATUS_OK;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue