diff --git a/openrtx/include/core/gps.h b/openrtx/include/core/gps.h index 114b5dd4..6c610be0 100644 --- a/openrtx/include/core/gps.h +++ b/openrtx/include/core/gps.h @@ -20,7 +20,7 @@ #ifndef GPS_H #define GPS_H -#include +#include #include /** diff --git a/openrtx/include/interfaces/platform.h b/openrtx/include/interfaces/platform.h index 64274f3f..9ef336c4 100644 --- a/openrtx/include/interfaces/platform.h +++ b/openrtx/include/interfaces/platform.h @@ -22,6 +22,8 @@ #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -142,6 +144,20 @@ void platform_beepStart(uint16_t freq); */ void platform_beepStop(); +#ifdef RTC_PRESENT +/** + * Get current UTC date and time. + * @return structure of type datetime_t with current clock and calendar values. + */ +datetime_t platform_getCurrentTime(); + +/** + * Set date and time to a given value. + * @param t: struct of type datetime_t, holding the new time to be set. + */ +void platform_setTime(datetime_t t); +#endif + /** * This function returns a pointer to a data structure containing all the * hardware information. diff --git a/openrtx/src/core/gps.c b/openrtx/src/core/gps.c index ef17c74e..19f9d49b 100644 --- a/openrtx/src/core/gps.c +++ b/openrtx/src/core/gps.c @@ -17,6 +17,7 @@ * along with this program; if not, see * ***************************************************************************/ +#include #include #include #include @@ -28,9 +29,11 @@ #define KNOTS2KMH 1.852f static char sentence[2*MINMEA_MAX_LENGTH]; -static bool isRtcSyncronised = false; static bool gpsEnabled = false; static bool readNewSentence = true; +#ifdef RTC_PRESENT +static bool isRtcSyncronised = false; +#endif void gps_task() { @@ -188,13 +191,14 @@ void gps_task() pthread_mutex_unlock(&state_mutex); // Synchronize RTC with GPS UTC clock, only when fix is done + #ifdef RTC_PRESENT if(state.gps_set_time) { if((sId == MINMEA_SENTENCE_RMC) && (gps_data.fix_quality > 0) && (isRtcSyncronised == false)) { - rtc_setTime(gps_data.timestamp); + platform_setTime(gps_data.timestamp); isRtcSyncronised = true; } } @@ -202,6 +206,7 @@ void gps_task() { isRtcSyncronised = false; } + #endif // Finally, trigger the acquisition of a new NMEA sentence readNewSentence = true; diff --git a/openrtx/src/core/state.c b/openrtx/src/core/state.c index 826f1956..a833e152 100644 --- a/openrtx/src/core/state.c +++ b/openrtx/src/core/state.c @@ -61,7 +61,7 @@ void state_init() * Initialise remaining fields */ #ifdef RTC_PRESENT - state.time = rtc_getTime(); + state.time = platform_getCurrentTime(); #endif state.v_bat = platform_getVbat(); state.charge = battery_getCharge(state.v_bat); @@ -113,7 +113,7 @@ void state_task() state.rssi = rtx_getRssi(); #ifdef RTC_PRESENT - state.time = rtc_getTime(); + state.time = platform_getCurrentTime(); #endif pthread_mutex_unlock(&state_mutex); diff --git a/openrtx/src/ui/default/ui.c b/openrtx/src/ui/default/ui.c index 2fd1d307..e037a434 100644 --- a/openrtx/src/ui/default/ui.c +++ b/openrtx/src/ui/default/ui.c @@ -1815,7 +1815,7 @@ void ui_updateFSM(bool *sync_rtx) // NOTE: The user inserted a local time, we must save an UTC time datetime_t utc_time = localTimeToUtc(ui_state.new_timedate, state.settings.utc_timezone); - rtc_setTime(utc_time); + platform_setTime(utc_time); state.time = utc_time; vp_announceSettingsTimeDate(); state.ui_screen = SETTINGS_TIMEDATE; diff --git a/platform/targets/MD-3x0/platform.c b/platform/targets/MD-3x0/platform.c index 2aa85655..c76160d2 100644 --- a/platform/targets/MD-3x0/platform.c +++ b/platform/targets/MD-3x0/platform.c @@ -193,6 +193,16 @@ void platform_beepStop() toneGen_beepOff(); } +datetime_t platform_getCurrentTime() +{ + return rtc_getTime(); +} + +void platform_setTime(datetime_t t) +{ + rtc_setTime(t); +} + const hwInfo_t *platform_getHwInfo() { return &hwInfo; diff --git a/platform/targets/MD-9600/platform.c b/platform/targets/MD-9600/platform.c index fa1255d4..946091f1 100644 --- a/platform/targets/MD-9600/platform.c +++ b/platform/targets/MD-9600/platform.c @@ -220,6 +220,16 @@ void platform_beepStop() /* TODO */ } +datetime_t platform_getCurrentTime() +{ + return rtc_getTime(); +} + +void platform_setTime(datetime_t t) +{ + rtc_setTime(t); +} + const hwInfo_t *platform_getHwInfo() { return &hwInfo; diff --git a/platform/targets/MD-UV3x0/platform.c b/platform/targets/MD-UV3x0/platform.c index f581202f..472bb09c 100644 --- a/platform/targets/MD-UV3x0/platform.c +++ b/platform/targets/MD-UV3x0/platform.c @@ -186,6 +186,16 @@ void platform_beepStop() toneGen_beepOff(); } +datetime_t platform_getCurrentTime() +{ + return rtc_getTime(); +} + +void platform_setTime(datetime_t t) +{ + rtc_setTime(t); +} + const hwInfo_t *platform_getHwInfo() { return &hwInfo; diff --git a/platform/targets/linux/platform.c b/platform/targets/linux/platform.c index 85258315..d1dc2c2e 100644 --- a/platform/targets/linux/platform.c +++ b/platform/targets/linux/platform.c @@ -115,6 +115,35 @@ void platform_beepStop() printf("platform_beepStop()\n"); } +datetime_t platform_getCurrentTime() +{ + datetime_t t; + + time_t rawtime; + struct tm * timeinfo; + time ( &rawtime ); + // radio expects time to be TZ-less, so use gmtime instead of localtime. + timeinfo = gmtime ( &rawtime ); + + t.hour = timeinfo->tm_hour; + t.minute = timeinfo->tm_min; + t.second = timeinfo->tm_sec; + t.day = timeinfo->tm_wday; + t.date = timeinfo->tm_mday; + t.month = timeinfo->tm_mon + 1; + // Only last two digits of the year are supported in OpenRTX + t.year = (timeinfo->tm_year + 1900) % 100; + + return t; +} + +void platform_setTime(datetime_t t) +{ + (void) t; + + printf("rtc_setTime(t)\n"); +} + const hwInfo_t *platform_getHwInfo() { return &hwInfo;