Moved get/set of current time to platform interface API
This commit is contained in:
parent
498f959798
commit
009930f914
|
|
@ -20,7 +20,7 @@
|
||||||
#ifndef GPS_H
|
#ifndef GPS_H
|
||||||
#define GPS_H
|
#define GPS_H
|
||||||
|
|
||||||
#include <interfaces/rtc.h>
|
#include <datetime.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <datetime.h>
|
||||||
|
#include <hwconfig.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -142,6 +144,20 @@ void platform_beepStart(uint16_t freq);
|
||||||
*/
|
*/
|
||||||
void platform_beepStop();
|
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
|
* This function returns a pointer to a data structure containing all the
|
||||||
* hardware information.
|
* hardware information.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <interfaces/platform.h>
|
||||||
#include <interfaces/gps.h>
|
#include <interfaces/gps.h>
|
||||||
#include <gps.h>
|
#include <gps.h>
|
||||||
#include <minmea.h>
|
#include <minmea.h>
|
||||||
|
|
@ -28,9 +29,11 @@
|
||||||
#define KNOTS2KMH 1.852f
|
#define KNOTS2KMH 1.852f
|
||||||
|
|
||||||
static char sentence[2*MINMEA_MAX_LENGTH];
|
static char sentence[2*MINMEA_MAX_LENGTH];
|
||||||
static bool isRtcSyncronised = false;
|
|
||||||
static bool gpsEnabled = false;
|
static bool gpsEnabled = false;
|
||||||
static bool readNewSentence = true;
|
static bool readNewSentence = true;
|
||||||
|
#ifdef RTC_PRESENT
|
||||||
|
static bool isRtcSyncronised = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
void gps_task()
|
void gps_task()
|
||||||
{
|
{
|
||||||
|
|
@ -188,13 +191,14 @@ void gps_task()
|
||||||
pthread_mutex_unlock(&state_mutex);
|
pthread_mutex_unlock(&state_mutex);
|
||||||
|
|
||||||
// Synchronize RTC with GPS UTC clock, only when fix is done
|
// Synchronize RTC with GPS UTC clock, only when fix is done
|
||||||
|
#ifdef RTC_PRESENT
|
||||||
if(state.gps_set_time)
|
if(state.gps_set_time)
|
||||||
{
|
{
|
||||||
if((sId == MINMEA_SENTENCE_RMC) &&
|
if((sId == MINMEA_SENTENCE_RMC) &&
|
||||||
(gps_data.fix_quality > 0) &&
|
(gps_data.fix_quality > 0) &&
|
||||||
(isRtcSyncronised == false))
|
(isRtcSyncronised == false))
|
||||||
{
|
{
|
||||||
rtc_setTime(gps_data.timestamp);
|
platform_setTime(gps_data.timestamp);
|
||||||
isRtcSyncronised = true;
|
isRtcSyncronised = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -202,6 +206,7 @@ void gps_task()
|
||||||
{
|
{
|
||||||
isRtcSyncronised = false;
|
isRtcSyncronised = false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Finally, trigger the acquisition of a new NMEA sentence
|
// Finally, trigger the acquisition of a new NMEA sentence
|
||||||
readNewSentence = true;
|
readNewSentence = true;
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ void state_init()
|
||||||
* Initialise remaining fields
|
* Initialise remaining fields
|
||||||
*/
|
*/
|
||||||
#ifdef RTC_PRESENT
|
#ifdef RTC_PRESENT
|
||||||
state.time = rtc_getTime();
|
state.time = platform_getCurrentTime();
|
||||||
#endif
|
#endif
|
||||||
state.v_bat = platform_getVbat();
|
state.v_bat = platform_getVbat();
|
||||||
state.charge = battery_getCharge(state.v_bat);
|
state.charge = battery_getCharge(state.v_bat);
|
||||||
|
|
@ -113,7 +113,7 @@ void state_task()
|
||||||
state.rssi = rtx_getRssi();
|
state.rssi = rtx_getRssi();
|
||||||
|
|
||||||
#ifdef RTC_PRESENT
|
#ifdef RTC_PRESENT
|
||||||
state.time = rtc_getTime();
|
state.time = platform_getCurrentTime();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pthread_mutex_unlock(&state_mutex);
|
pthread_mutex_unlock(&state_mutex);
|
||||||
|
|
|
||||||
|
|
@ -1815,7 +1815,7 @@ void ui_updateFSM(bool *sync_rtx)
|
||||||
// NOTE: The user inserted a local time, we must save an UTC time
|
// NOTE: The user inserted a local time, we must save an UTC time
|
||||||
datetime_t utc_time = localTimeToUtc(ui_state.new_timedate,
|
datetime_t utc_time = localTimeToUtc(ui_state.new_timedate,
|
||||||
state.settings.utc_timezone);
|
state.settings.utc_timezone);
|
||||||
rtc_setTime(utc_time);
|
platform_setTime(utc_time);
|
||||||
state.time = utc_time;
|
state.time = utc_time;
|
||||||
vp_announceSettingsTimeDate();
|
vp_announceSettingsTimeDate();
|
||||||
state.ui_screen = SETTINGS_TIMEDATE;
|
state.ui_screen = SETTINGS_TIMEDATE;
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,16 @@ void platform_beepStop()
|
||||||
toneGen_beepOff();
|
toneGen_beepOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datetime_t platform_getCurrentTime()
|
||||||
|
{
|
||||||
|
return rtc_getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
void platform_setTime(datetime_t t)
|
||||||
|
{
|
||||||
|
rtc_setTime(t);
|
||||||
|
}
|
||||||
|
|
||||||
const hwInfo_t *platform_getHwInfo()
|
const hwInfo_t *platform_getHwInfo()
|
||||||
{
|
{
|
||||||
return &hwInfo;
|
return &hwInfo;
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,16 @@ void platform_beepStop()
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datetime_t platform_getCurrentTime()
|
||||||
|
{
|
||||||
|
return rtc_getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
void platform_setTime(datetime_t t)
|
||||||
|
{
|
||||||
|
rtc_setTime(t);
|
||||||
|
}
|
||||||
|
|
||||||
const hwInfo_t *platform_getHwInfo()
|
const hwInfo_t *platform_getHwInfo()
|
||||||
{
|
{
|
||||||
return &hwInfo;
|
return &hwInfo;
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,16 @@ void platform_beepStop()
|
||||||
toneGen_beepOff();
|
toneGen_beepOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datetime_t platform_getCurrentTime()
|
||||||
|
{
|
||||||
|
return rtc_getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
void platform_setTime(datetime_t t)
|
||||||
|
{
|
||||||
|
rtc_setTime(t);
|
||||||
|
}
|
||||||
|
|
||||||
const hwInfo_t *platform_getHwInfo()
|
const hwInfo_t *platform_getHwInfo()
|
||||||
{
|
{
|
||||||
return &hwInfo;
|
return &hwInfo;
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,35 @@ void platform_beepStop()
|
||||||
printf("platform_beepStop()\n");
|
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()
|
const hwInfo_t *platform_getHwInfo()
|
||||||
{
|
{
|
||||||
return &hwInfo;
|
return &hwInfo;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue