Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time driver ng #1425

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
24f6c02
Introduce new time posibilities for every device w/o ntp:
MaxineMuster Oct 9, 2024
f5d35be
Merge branch 'openshwprojects:main' into time_driver_ng
MaxineMuster Oct 9, 2024
0aba810
Added files to makefiles
MaxineMuster Oct 9, 2024
dae002d
Fixes
MaxineMuster Oct 9, 2024
b30e72b
Fix clashing defines for "read" and "write"
MaxineMuster Oct 10, 2024
2bf3422
Next try fixing Windows build
MaxineMuster Oct 10, 2024
cfbb3c6
Fix Windows include - take 3
MaxineMuster Oct 10, 2024
93da598
Next try for fix Windows build
MaxineMuster Oct 10, 2024
d3a7112
Try fixing Windows again - simulated NTP time needs extra handling
MaxineMuster Oct 10, 2024
b350830
Fix test/simulation - allow adding events even if clock is not set.
MaxineMuster Oct 10, 2024
cb67b48
Add missing alias ntp_setLatLong for new clock_setLatLong
MaxineMuster Oct 10, 2024
7271898
Adjusting simulated time to new clock
MaxineMuster Oct 10, 2024
8bcbe3f
Add some (temporary) functions to get "device clock" even if ntp is u…
MaxineMuster Oct 10, 2024
f383d84
Merge branch 'openshwprojects:main' into time_driver_ng
MaxineMuster Oct 10, 2024
ba2d04c
fix for merge conflicts 1
MaxineMuster Nov 13, 2024
1382c41
fix2
MaxineMuster Nov 13, 2024
855638f
next try fix src/httpserver/http_fns.c
MaxineMuster Nov 13, 2024
972fc56
remove duplicate line
MaxineMuster Nov 13, 2024
7304be3
Update http_fns.c
MaxineMuster Nov 13, 2024
a74fbc9
Update http_fns.c
MaxineMuster Nov 13, 2024
7e36b9b
temp
MaxineMuster Nov 13, 2024
86b6abf
Update http_fns.c
MaxineMuster Nov 13, 2024
947846c
Delete src/httpserver/http_fns.c
MaxineMuster Nov 13, 2024
0319394
add file again
MaxineMuster Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions openBeken_win32_mvsc2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
<ClCompile Include="src\driver\drv_max72xx_single.c" />
<ClCompile Include="src\driver\drv_mcp9808.c" />
<ClCompile Include="src\driver\drv_ntp.c" />
<ClCompile Include="src\driver\drv_ntp_events.c" />
<ClCompile Include="src\driver\drv_deviceclock.c" />
<ClCompile Include="src\driver\drv_timed_events.c" />
<ClCompile Include="src\driver\drv_pixelAnim.c" />
<ClCompile Include="src\driver\drv_pt6523.c" />
<ClCompile Include="src\driver\drv_pwmToggler.c" />
Expand Down Expand Up @@ -1170,4 +1171,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions openBeken_win32_mvsc2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ClCompile Include="src\driver\drv_max72xx_single.c" />
<ClCompile Include="src\driver\drv_mcp9808.c" />
<ClCompile Include="src\driver\drv_ntp.c" />
<ClCompile Include="src\driver\drv_ntp_events.c" />
<ClCompile Include="src\driver\drv_timed_events.c" />
<ClCompile Include="src\driver\drv_pt6523.c" />
<ClCompile Include="src\driver\drv_pwmToggler.c" />
<ClCompile Include="src\driver\drv_pwrCal.c" />
Expand Down Expand Up @@ -532,4 +532,4 @@
<CustomBuild Include="src\rgb2hsv.h" />
<CustomBuild Include="..\..\platforms\bk7231t\bk7231t_os\application.mk" />
</ItemGroup>
</Project>
</Project>
3 changes: 3 additions & 0 deletions platforms/LN882H/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ set(PROJ_ALL_SRC
app/src/driver/drv_wemo.c
app/src/driver/drv_ds1820_simple.c
app/src/driver/drv_charts.c
app/src/driver/drv_deviceclock.c
app/src/driver/drv_timed_events.c
app/src/httpclient/http_get_header.c
app/src/hal/ln882h/hal_adc_ln882h.c
app/src/hal/ln882h/hal_flashConfig_ln882h.c
app/src/hal/ln882h/hal_flashVars_ln882h.c
Expand Down
2 changes: 2 additions & 0 deletions platforms/W600/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ CSRCS += $(_SHARED_APP)/driver/drv_tasmotaDeviceGroups.c
CSRCS += $(_SHARED_APP)/driver/drv_test_drivers.c
CSRCS += $(_SHARED_APP)/driver/drv_bridge_driver.c
CSRCS += $(_SHARED_APP)/driver/drv_charts.c
CSRCS += $(_SHARED_APP)/driver/drv_deviceclock.c
CSRCS += $(_SHARED_APP)/driver/drv_timed_events.c
CSRCS += $(_SHARED_APP)/hal/w800/hal_adc_w800.c
CSRCS += $(_SHARED_APP)/hal/w800/hal_flashConfig_w800.c
CSRCS += $(_SHARED_APP)/hal/w800/hal_flashVars_w800.c
Expand Down
3 changes: 3 additions & 0 deletions platforms/W800/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ CSRCS += $(_SHARED_APP)/tiny_crc8.c
CSRCS += $(_SHARED_APP)/driver/drv_main.c
CSRCS += $(_SHARED_APP)/driver/drv_ds1820_simple.c
CSRCS += $(_SHARED_APP)/driver/drv_charts.c
CSRCS += $(_SHARED_APP)/driver/drv_deviceclock.c
CSRCS += $(_SHARED_APP)/driver/drv_timed_events.c
CSRCS += $(_SHARED_APP)/httpclient/http_get_header.c
CSRCS += $(_SHARED_APP)/user_main.c
CSRCS += main.c

Expand Down
2 changes: 2 additions & 0 deletions platforms/XR809/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ SRCS += ../shared/src/driver/drv_main
SRCS += ../shared/src/driver/drv_ntp
SRCS += ../shared/src/driver/drv_tuyaMCU
SRCS += ../shared/src/driver/drv_uart
SRCS += ../shared/src/driver/drv_deviceclock
SRCS += ../shared/src/driver/drv_timed_events

SRCS += ../shared/src/i2c/drv_i2c_main
SRCS += ../shared/src/i2c/drv_i2c_mcp23017
Expand Down
23 changes: 12 additions & 11 deletions src/cmnds/cmd_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../driver/drv_public.h"
#include "../driver/drv_battery.h"
#include "../driver/drv_ntp.h"
#include "../driver/drv_deviceclock.h"
#include <ctype.h> // isspace

/*
Expand Down Expand Up @@ -273,34 +274,34 @@ float getUpTime(const char *s) {
return g_secondsElapsed;
}
float getWeekDay(const char *s) {
return NTP_GetWeekDay();
return CLOCK_GetWeekDay();
}
float getMinute(const char *s) {
return NTP_GetMinute();
return CLOCK_GetMinute();
}
float getHour(const char *s) {
return NTP_GetHour();
return CLOCK_GetHour();
}
float getSecond(const char *s) {
return NTP_GetSecond();
return CLOCK_GetSecond();
}
float getYear(const char *s) {
return NTP_GetYear();
return CLOCK_GetYear();
}
float getMonth(const char *s) {
return NTP_GetMonth();
return CLOCK_GetMonth();
}
float getMDay(const char *s) {
return NTP_GetMDay();
return CLOCK_GetMDay();
}

#if ENABLE_NTP_SUNRISE_SUNSET
#if ENABLE_CLOCK_SUNRISE_SUNSET

float getSunrise(const char *s) {
return NTP_GetSunrise();
return CLOCK_GetSunrise();
}
float getSunset(const char *s) {
return NTP_GetSunset();
return CLOCK_GetSunset();
}

#endif
Expand Down Expand Up @@ -465,7 +466,7 @@ const constant_t g_constants[] = {
////cnstdetail:"descr":"",
////cnstdetail:"requires":""}
{ "$today", &getToday },
#if ENABLE_NTP_SUNRISE_SUNSET
#if ENABLE_CLOCK_SUNRISE_SUNSET
////cnstdetail:{"name":"$sunrise",
////cnstdetail:"title":"$sunrise",
////cnstdetail:"descr":"Next sunrise as a TimerSeconds from midnight",
Expand Down
3 changes: 3 additions & 0 deletions src/cmnds/cmd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,9 @@ void CMD_Init_Delayed() {
#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602)
UART_AddCommands();
#endif
#if ENABLE_LOCAL_CLOCK || WINDOWS
CLOCK_Init();
#endif
}


Expand Down
39 changes: 16 additions & 23 deletions src/driver/drv_bl_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../ota/ota.h"
#include "drv_local.h"
#include "drv_ntp.h"
#include "../driver/drv_deviceclock.h"
#include "drv_public.h"
#include "drv_uart.h"
#include "../cmnds/cmd_public.h" //for enum EventCode
Expand Down Expand Up @@ -105,7 +106,7 @@ void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request)
}

for (int i = OBK__FIRST; i <= OBK_CONSUMPTION__DAILY_LAST; i++) {
if (i <= OBK__NUM_MEASUREMENTS || NTP_IsTimeSynced()) {
if (i <= OBK__NUM_MEASUREMENTS || Clock_IsTimeSynced()) {
poststr(request, "<tr><td><b>");
poststr(request, sensors[i].names.name_friendly);
poststr(request, "</b></td><td style='text-align: right;'>");
Expand All @@ -131,10 +132,8 @@ void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request)
}

hprintf255(request, "<br>");
if(DRV_IsRunning("NTP")==false) {
hprintf255(request,"NTP driver is not started, daily energy stats disabled.");
} else if (!NTP_IsTimeSynced()) {
hprintf255(request,"Daily energy stats awaiting NTP driver to sync real time...");
if(Clock_IsTimeSynced()==false) {
hprintf255(request,"Device time not in sync, daily energy stats disabled.");
}
hprintf255(request, "</h5>");

Expand Down Expand Up @@ -223,7 +222,7 @@ commandResult_t BL09XX_ResetEnergyCounter(const void *context, const char *cmd,
sensors[OBK_CONSUMPTION_TOTAL].lastReading = value;
energyCounterStamp = xTaskGetTickCount();
}
ConsumptionResetTime = (time_t)NTP_GetCurrentTime();
ConsumptionResetTime = (time_t)Clock_GetCurrentTime();
#if WINDOWS
#elif PLATFORM_BL602
#elif PLATFORM_W600 || PLATFORM_W800
Expand Down Expand Up @@ -524,8 +523,8 @@ void BL_ProcessUpdate(float voltage, float current, float power,
HAL_FlashVars_SaveTotalConsumption(sensors[OBK_CONSUMPTION_TOTAL].lastReading);
sensors[OBK_CONSUMPTION_TODAY].lastReading += energy;

if (NTP_IsTimeSynced()) {
ntpTime = (time_t)NTP_GetCurrentTime();
if (Clock_IsTimeSynced()) {
ntpTime = (time_t)Clock_GetCurrentTime();
ltm = gmtime(&ntpTime);
if (ConsumptionResetTime == 0)
ConsumptionResetTime = (time_t)ntpTime;
Expand Down Expand Up @@ -581,20 +580,20 @@ void BL_ProcessUpdate(float voltage, float current, float power,
cJSON_AddNumberToObject(root, "consumption_stat_index", energyCounterMinutesIndex);
cJSON_AddNumberToObject(root, "consumption_sample_count", energyCounterSampleCount);
cJSON_AddNumberToObject(root, "consumption_sampling_period", energyCounterSampleInterval);
if(NTP_IsTimeSynced() == true)
if(Clock_IsTimeSynced() == true)
{
cJSON_AddNumberToObject(root, "consumption_today", BL_ChangeEnergyUnitIfNeeded(DRV_GetReading(OBK_CONSUMPTION_TODAY)));
cJSON_AddNumberToObject(root, "consumption_yesterday", BL_ChangeEnergyUnitIfNeeded(DRV_GetReading(OBK_CONSUMPTION_YESTERDAY)));
ltm = gmtime(&ConsumptionResetTime);
if (NTP_GetTimesZoneOfsSeconds()>0)
if (Clock_GetTimesZoneOfsSeconds()>0)
{
snprintf(datetime,sizeof(datetime), "%04i-%02i-%02iT%02i:%02i+%02i:%02i",
ltm->tm_year+1900, ltm->tm_mon+1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min,
NTP_GetTimesZoneOfsSeconds()/3600, (NTP_GetTimesZoneOfsSeconds()/60) % 60);
Clock_GetTimesZoneOfsSeconds()/3600, (Clock_GetTimesZoneOfsSeconds()/60) % 60);
} else {
snprintf(datetime, sizeof(datetime), "%04i-%02i-%02iT%02i:%02i-%02i:%02i",
ltm->tm_year+1900, ltm->tm_mon+1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min,
abs(NTP_GetTimesZoneOfsSeconds()/3600), (abs(NTP_GetTimesZoneOfsSeconds())/60) % 60);
abs(Clock_GetTimesZoneOfsSeconds()/3600), (abs(Clock_GetTimesZoneOfsSeconds())/60) % 60);
}
cJSON_AddStringToObject(root, "consumption_clear_date", datetime);
}
Expand All @@ -613,7 +612,7 @@ void BL_ProcessUpdate(float voltage, float current, float power,
cJSON_AddItemToObject(root, "consumption_samples", stats);
}

if(NTP_IsTimeSynced() == true)
if(Clock_IsTimeSynced() == true)
{
stats = cJSON_CreateArray();
for(i = OBK_CONSUMPTION__DAILY_FIRST; i <= OBK_CONSUMPTION__DAILY_LAST; i++)
Expand Down Expand Up @@ -696,16 +695,10 @@ void BL_ProcessUpdate(float voltage, float current, float power,
sensors[i].lastReading = ConsumptionResetTime; //Only to make the 'nochangeframe' mechanism work here
ltm = gmtime(&ConsumptionResetTime);
/* 2019-09-07T15:50-04:00 */
if (NTP_GetTimesZoneOfsSeconds()>0)
{
snprintf(datetime, sizeof(datetime), "%04i-%02i-%02iT%02i:%02i+%02i:%02i",
ltm->tm_year+1900, ltm->tm_mon+1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min,
NTP_GetTimesZoneOfsSeconds()/3600, (NTP_GetTimesZoneOfsSeconds()/60) % 60);
} else {
snprintf(datetime, sizeof(datetime), "%04i-%02i-%02iT%02i:%02i-%02i:%02i",
ltm->tm_year+1900, ltm->tm_mon+1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min,
abs(NTP_GetTimesZoneOfsSeconds()/3600), (abs(NTP_GetTimesZoneOfsSeconds())/60) % 60);
}
snprintf(datetime, sizeof(datetime), "%04i-%02i-%02iT%02i:%02i%s%02i:%02i",
ltm->tm_year+1900, ltm->tm_mon+1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min,
Clock_GetTimesZoneOfsSeconds()>0 ? "+" : "-",
abs(Clock_GetTimesZoneOfsSeconds()/3600), (abs(Clock_GetTimesZoneOfsSeconds())/60) % 60);
MQTT_PublishMain_StringString(sensors[i].names.name_mqtt, datetime, 0);
} else { //all other sensors
float val = sensors[i].lastReading;
Expand Down
Loading