Skip to content

TimeService update/refactor #318

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
956de5a
TimeService: Add connected() method to check connection status
pennam May 24, 2022
398bef8
Check if board is connected before trying to get time from network/NTP
pennam May 24, 2022
4f79884
Add HAS_RTC define in config file for boards with RTC support
pennam May 24, 2022
bd8ec23
Fix includes to make HAS_RTC macro available in TimeService code
pennam May 24, 2022
947c9c6
Add internal interface functions to RTC
pennam May 24, 2022
e837afb
Add getRTC() and configureRTC private methods
pennam May 24, 2022
ccc88de
Use internal RTC interface function to initialize RTC hardware
pennam May 24, 2022
c1d5a85
TimeService::getTime rework to simplify logic
pennam May 24, 2022
1f5722d
Fix isTimeValid() > EPOCH_AT_COMPILE_TIME
pennam May 24, 2022
4b7e17a
Substitute missing build options with HAS_RTC define
pennam May 24, 2022
8afe843
getRemoteTime() and connected() methods are meaningful only if TCP is…
pennam May 24, 2022
52f19f6
TimeService::setTimeZoneData: change timezone prints from DEBUG_DEBUG…
pennam Feb 3, 2022
0f3511a
TimeService::setTimeZoneData: add braces around single statement if
pennam Feb 3, 2022
2597a79
TimeService::setTimeZoneData print timezone updates in one row
pennam May 24, 2022
6c7b163
TimeService: other cosmetics changes
pennam May 24, 2022
5bbec58
Fix debug prints reporting the wrong class name
pennam May 25, 2022
4ea05aa
Make explicit that timezone support is not available for devices with…
pennam May 25, 2022
2d7c0cf
Fix getTime() flow and add comments to describe it
pennam May 25, 2022
e9e0434
Rename TimeService into TimeServiceClass and use a more standard way …
pennam May 25, 2022
5132d2b
Fix build for esp8226
pennam May 25, 2022
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
12 changes: 9 additions & 3 deletions extras/test/src/test_CloudSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@
unsigned long time_now = 1;

/**************************************************************************************
* TimeService Fake CTOR/DTOR
* TimeService Fake CTOR
**************************************************************************************/

TimeService::TimeService() {}
TimeServiceClass::TimeServiceClass() {}

/**************************************************************************************
* TimeService Fake Methods
**************************************************************************************/

unsigned long TimeService::getLocalTime() {return time_now;}
unsigned long TimeServiceClass::getLocalTime() {return time_now;}

/**************************************************************************************
* TimeService Fake local instance
**************************************************************************************/

TimeServiceClass TimeService;

/**************************************************************************************
TEST CODE
Expand Down
5 changes: 0 additions & 5 deletions extras/test/src/util/PropertyTestUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ unsigned long getTime()
{
return 0;
}

TimeService & ArduinoIoTCloudTimeService() {
static TimeService _timeService_instance;
return _timeService_instance;
}
4 changes: 4 additions & 0 deletions src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,25 @@
defined (ARDUINO_NANO_RP2040_CONNECT)
#define BOARD_HAS_ECCX08
#define HAS_TCP
#define HAS_RTC
#endif

#if defined(ARDUINO_NICLA_VISION)
#define BOARD_HAS_SE050
#define HAS_TCP
#define HAS_RTC
#endif

#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || \
defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
#define BOARD_HAS_OFFLOADED_ECCX08
#define HAS_TCP
#define HAS_RTC
#endif

#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
#define HAS_LORA
#define HAS_RTC
#endif

#if defined(ARDUINO_ESP8266_ESP12) || defined(ARDUINO_ARCH_ESP32) || defined(ESP8266) || defined(ESP32)
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ArduinoIoTCloudClass::ArduinoIoTCloudClass()
: _connection{nullptr}
, _last_checked_property_index{0}
, _time_service(ArduinoIoTCloudTimeService())
, _time_service(TimeService)
, _tz_offset{0}
, _tz_dst_until{0}
, _thing_id{""}
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ArduinoIoTCloudClass
PropertyContainer _device_property_container;
PropertyContainer _thing_property_container;
unsigned int _last_checked_property_index;
TimeService & _time_service;
TimeServiceClass & _time_service;
int _tz_offset;
unsigned int _tz_dst_until;
String _thing_id;
Expand Down
3 changes: 1 addition & 2 deletions src/property/types/CloudSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Schedule {

bool isActive() {

ScheduleTimeType now = _schedule_time_service.getLocalTime();
ScheduleTimeType now = TimeService.getLocalTime();

if(checkTimeValid(now)) {
/* We have to wait RTC configuration and Timezone setting from the cloud */
Expand Down Expand Up @@ -201,7 +201,6 @@ class Schedule {
return !(operator==(aSchedule));
}
private:
TimeService & _schedule_time_service = ArduinoIoTCloudTimeService();

ScheduleUnit getScheduleUnit(ScheduleConfigurationType msk) {
return static_cast<ScheduleUnit>((msk & SCHEDULE_UNIT_MASK) >> SCHEDULE_UNIT_SHIFT);
Expand Down
Loading