Skip to content

Commit

Permalink
add day/year/month access for scripts so we can script a date display
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Oct 30, 2023
1 parent a787c58 commit 5d617ca
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/cmnds/cmd_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ float getHour(const char *s) {
float getSecond(const char *s) {
return NTP_GetSecond();
}
float getYear(const char *s) {
return NTP_GetYear();
}
float getMonth(const char *s) {
return NTP_GetMonth();
}
float getMDay(const char *s) {
return NTP_GetMDay();
}

const constant_t g_constants[] = {
//cnstdetail:{"name":"MQTTOn",
Expand Down Expand Up @@ -375,11 +384,21 @@ const constant_t g_constants[] = {
//cnstdetail:"descr":"Current second from NTP",
//cnstdetail:"requires":""}
{ "$second", &getSecond },
////cnstdetail:{"name":"$mday",
////cnstdetail:"title":"$mday",
////cnstdetail:"descr":"Current mday from NTP",
////cnstdetail:"requires":""}
{ "$mday", &getMDay },
////cnstdetail:{"name":"$month",
////cnstdetail:"title":"$month",
////cnstdetail:"descr":"Current month from NTP",
////cnstdetail:"requires":""}
//{ "$month", &getMonth },
{ "$month", &getMonth },
////cnstdetail:{"name":"$year",
////cnstdetail:"title":"$year",
////cnstdetail:"descr":"Current Year from NTP",
////cnstdetail:"requires":""}
{ "$year", &getYear },
//cnstdetail:{"name":"$NTPOn",
//cnstdetail:"title":"$NTPOn",
//cnstdetail:"descr":"Returns 1 if NTP is on and already synced (so device has correct time), otherwise 0.",
Expand Down
36 changes: 36 additions & 0 deletions src/driver/drv_ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,42 @@ int NTP_GetSecond() {

return ltm->tm_sec;
}
int NTP_GetMDay() {
struct tm *ltm;

// NOTE: on windows, you need _USE_32BIT_TIME_T
ltm = localtime((time_t*)&g_ntpTime);

if (ltm == 0) {
return 0;
}

return ltm->tm_mday;
}
int NTP_GetMonth() {
struct tm *ltm;

// NOTE: on windows, you need _USE_32BIT_TIME_T
ltm = localtime((time_t*)&g_ntpTime);

if (ltm == 0) {
return 0;
}

return ltm->tm_mon+1;
}
int NTP_GetYear() {
struct tm *ltm;

// NOTE: on windows, you need _USE_32BIT_TIME_T
ltm = localtime((time_t*)&g_ntpTime);

if (ltm == 0) {
return 0;
}

return ltm->tm_year+1900;
}
#if WINDOWS
bool b_ntp_simulatedTime = false;
void NTP_SetSimulatedTime(unsigned int timeNow) {
Expand Down
3 changes: 3 additions & 0 deletions src/driver/drv_ntp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ int NTP_GetWeekDay();
int NTP_GetHour();
int NTP_GetMinute();
int NTP_GetSecond();
int NTP_GetMDay();
int NTP_GetMonth();
int NTP_GetYear();
// for Simulator only, on Windows, for unit testing
void NTP_SetSimulatedTime(unsigned int timeNow);
// drv_ntp_events.c
Expand Down

0 comments on commit 5d617ca

Please sign in to comment.