aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilien Cuony <maximilien@theglu.org>2016-06-05 16:05:43 +0200
committerMaximilien Cuony <maximilien@theglu.org>2016-06-05 16:05:43 +0200
commit54b86809942e247648511bab04ea793bcfda2f2c (patch)
treeac3ee881b3d6fc76cc820075724c26be478ae1d9 /src
parent9d5ff73c98c9c2da27791813b18721e366d61912 (diff)
downloadglutte-o-matic-54b86809942e247648511bab04ea793bcfda2f2c.tar.gz
glutte-o-matic-54b86809942e247648511bab04ea793bcfda2f2c.tar.bz2
glutte-o-matic-54b86809942e247648511bab04ea793bcfda2f2c.zip
Fix timestamp and fsm date
Diffstat (limited to 'src')
-rw-r--r--src/common/src/Core/common.c23
-rw-r--r--src/simulator/src/Core/fsm.c2
2 files changed, 20 insertions, 5 deletions
diff --git a/src/common/src/Core/common.c b/src/common/src/Core/common.c
index 2077a16..d04987a 100644
--- a/src/common/src/Core/common.c
+++ b/src/common/src/Core/common.c
@@ -26,9 +26,10 @@
#include "GPIO/usart.h"
#include "FreeRTOS.h"
#include "timers.h"
-/* #include "Core/gps.h" */
+#include "GPS/gps.h"
#include <time.h>
+
static uint64_t common_timestamp = 0; // milliseconds since startup
static TimerHandle_t common_timer;
@@ -38,6 +39,11 @@ static uint16_t lfsr;
static void common_increase_timestamp(TimerHandle_t t);
+
+#ifdef SIMULATOR
+long timestamp_delta = 0;
+#endif
+
int find_last_sunday(const struct tm* time) {
struct tm t = *time;
@@ -157,11 +163,20 @@ void common_init(void)
static void common_increase_timestamp(TimerHandle_t t)
{
- common_timestamp++;
#ifdef SIMULATOR
- //Simulator rate is 100ticks/s
- common_timestamp += 9;
+ struct timespec ctime;
+
+ clock_gettime(CLOCK_REALTIME, &ctime);
+ common_timestamp = ctime.tv_sec * 1000 + ctime.tv_nsec / 1.0e6 - timestamp_delta;
+
+ if (timestamp_delta == 0) {
+ timestamp_delta = common_timestamp;
+ common_timestamp = 0;
+ }
+
+#else
+ common_timestamp++;
#endif
}
diff --git a/src/simulator/src/Core/fsm.c b/src/simulator/src/Core/fsm.c
index ec17e56..6f771c2 100644
--- a/src/simulator/src/Core/fsm.c
+++ b/src/simulator/src/Core/fsm.c
@@ -17,7 +17,7 @@ void fsm_state_switched(char * new_state) {
time_t now = time(NULL);
- struct tm *t = gmtime(&now);
+ struct tm *t = localtime(&now);
gui_last_fsm_states[0] = new_state;
gui_last_fsm_states_timestamps[0] = t->tm_hour * 10000 + t->tm_min * 100 + t->tm_sec;