-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ts swap to GPS once fix acquired.
- Loading branch information
1 parent
16429d7
commit 5d35261
Showing
10 changed files
with
106 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
zephyr_include_directories(.) | ||
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/time_handler.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <zephyr.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <modem_info.h> | ||
#include <time.h> | ||
|
||
#include "ruuvinode.h" | ||
#include "time_handler.h" | ||
|
||
time_t epoch; | ||
u32_t epoch_tk; | ||
|
||
int update_ts_modem(void){ | ||
int err; | ||
static char ts_buf[MODEM_TIME_LEN + 1]; | ||
struct tm t; | ||
int tz; | ||
char *pch; | ||
err = modem_info_string_get(MODEM_INFO_DATE_TIME, ts_buf); | ||
if (err != MODEM_TIME_LEN) { | ||
printk("modem_info_string_get(MODEM time), error: %d", err); | ||
return -1; | ||
} | ||
epoch_tk = k_uptime_get_32(); | ||
|
||
char *msg = strdup(ts_buf); | ||
|
||
pch = strtok(msg, "/,:+"); | ||
t.tm_year = atoi(pch); | ||
t.tm_year = t.tm_year + 2000 -1900; | ||
pch = strtok(NULL, "/,:+"); | ||
t.tm_mon = atoi(pch); | ||
t.tm_mon = t.tm_mon -1; | ||
pch = strtok(NULL, "/,:+"); | ||
t.tm_mday = atoi(pch); | ||
pch = strtok(NULL, "/,:+"); | ||
t.tm_hour = atoi(pch); | ||
pch = strtok(NULL, "/,:+"); | ||
t.tm_min = atoi(pch); | ||
pch = strtok(NULL, "/,:+"); | ||
t.tm_sec = atoi(pch); | ||
pch = strtok(NULL, "/,:+"); | ||
tz = atoi(pch); | ||
t.tm_isdst = -1; | ||
epoch = mktime(&t); | ||
memset(ts_buf, 0, MODEM_TIME_LEN + 1); | ||
free(msg); | ||
free(pch); | ||
printk("TS updated by Modem\n"); | ||
return 0; | ||
} | ||
|
||
void update_ts_gps(struct tm *g){ | ||
epoch_tk = k_uptime_get_32(); | ||
epoch = mktime(g); | ||
printk("GPS epoch: %lld\n", epoch); | ||
printk("TS updated by GPS\n"); | ||
return; | ||
|
||
} | ||
|
||
time_t get_ts(void){ | ||
time_t ts; | ||
u32_t now; | ||
now = k_uptime_get_32(); | ||
now = now - epoch_tk; | ||
now = now / 1000; | ||
ts = epoch + now; | ||
return ts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <zephyr.h> | ||
#include <time.h> | ||
|
||
int update_ts_modem(void); | ||
|
||
void update_ts_gps(struct tm *g); | ||
|
||
time_t get_ts(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters