Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 24, 2019 License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed) More...
#include <cs_SystemTime.h>
Public Member Functions | |
void | init () |
Creates and starts the first tick timer. More... | |
virtual void | handleEvent (event_t &event) |
Handle events. More... | |
virtual | ~SystemTime ()=default |
![]() | |
EventListener () | |
virtual | ~EventListener () |
unregisters the listener. More... | |
virtual void | handleEvent (event_t &event)=0 |
Handle events. More... | |
void | listen () |
Registers this with the EventDispatcher. More... | |
Static Public Member Functions | |
static uint32_t | posix () |
Get the current time as posix timestamp in seconds. More... | |
static Time | now () |
Get the current time as Time object. More... | |
static DayOfWeek | day () |
Get the current weekday. More... | |
static uint32_t | up () |
Uptime in seconds. More... | |
static high_resolution_time_stamp_t | getSynchronizedStamp () |
Get the synchronized timestamp, updated to current time. More... | |
static cs_ret_code_t | setTime (uint32_t time, bool throttled, bool sendToMesh) |
Set the system wide time to given posix timestamp. More... | |
static cs_ret_code_t | setSunTimes (const sun_time_t &sunTimes, bool throttled=true) |
Set the sunrise and sunset times. More... | |
Private Member Functions | |
bool | isOnlyReceiveByThisDevice (cmd_source_with_counter_t counted_source) |
Returns true if the command source is uart or ble through connection. More... | |
Static Private Member Functions | |
static void | scheduleNextTick () |
static void | tick (void *unused) |
Must be called at least once per second to update upTimeSec. More... | |
static constexpr uint32_t | reboot_sync_timeout_ms () |
Timeout period before considering this stone to be root clock. More... | |
static constexpr uint32_t | root_clock_update_period_ms () |
Time between sync messages from the root clock. More... | |
static constexpr uint32_t | root_clock_reelection_timeout_ms () |
If no sync message has been received from the root clock for this time, a new root clock will be selected. More... | |
static constexpr stone_id_t | stone_id_init () |
Stone id to use for initialization. More... | |
static constexpr uint8_t | timestamp_version_lollipop_max () |
The time version is lollipop versioned. More... | |
static constexpr uint8_t | timestamp_version_min_valid () |
Lowest time version at which a valid posix time is set. More... | |
static uint32_t | syncTimeCoroutineAction () |
static uint8_t | timeStampVersion () |
static void | onTimeSyncMessageReceive (time_sync_message_t syncmessage) |
static void | setRootTimeStamp (high_resolution_time_stamp_t stamp, stone_id_t id, uint32_t rtcCount) |
static void | updateRootTimeStamp (uint32_t rtcCount) |
Keep up the root clock time. More... | |
static void | sendTimeSyncMessage (high_resolution_time_stamp_t stamp, stone_id_t id, bool reliable=false) |
Send a sync message for given stamp/id combo to the mesh. More... | |
static bool | meIsRootClock () |
Returns true if the id of this stone can considered to be root clock. More... | |
static bool | isRootClock (stone_id_t candidate) |
Returns true if the candidate can considered to be root clock. More... | |
static bool | reelectionPeriodTimedOut () |
Returns true if onTimeSyncMessageReceive hasn't received any sync messages from a clock authority in the last root_clock_reelection_timeout_ms milliseconds. More... | |
static bool | rebootTimedOut () |
Returns true when reboot period is passed. More... | |
static constexpr uint32_t | debugSyncTimeMessagePeriodMs () |
static void | initDebug () |
Sets up the debug symc time coroutine when DEBUG_SYSTEM_TIME is defined in order to broadcast sync messages to the mesh regardless of being root clock or not. More... | |
static void | publishSyncMessageForTesting () |
static void | pushSyncMessageToTestSuite (time_sync_message_t &syncmessage) |
Static Private Attributes | |
static uint32_t | upTimeSec |
static uint16_t | throttleSetTimeCountdownTicks |
static uint16_t | throttleSetSunTimesCountdownTicks |
static constexpr auto | TICK_TIME_MS = 500 |
static constexpr uint16_t | TIME_UPDATE_PERIOD_MS = (60 * 1000) |
static constexpr uint16_t | THROTTLE_SET_TIME_TICKS = (60 * 1000 / TICK_TIME_MS) |
static constexpr uint16_t | THROTTLE_SET_SUN_TIMES_TICKS = (30 * 60 * 1000 / TICK_TIME_MS) |
static app_timer_t | appTimerData |
static app_timer_id_t | appTimerId |
static uint32_t | rtcCountOfLastSecondIncrement |
RTC count of last time a second had passed. More... | |
static stone_id_t | myId |
Cached ID of this stone. More... | |
static high_resolution_time_stamp_t | rootTime |
Root clock. More... | |
static uint32_t | rtcCountOfLastRootTimeUpdate |
RTC count of last time the root clock was set. More... | |
static uint32_t | uptimeOfLastTimeSyncMessage |
Uptime of last time a sync message was received. More... | |
static stone_id_t | rootClockId |
Stone ID of the root clock. More... | |
static Coroutine | syncTimeCoroutine |
static Coroutine | debugSyncTimeCoroutine |
Friends | |
class | TestAccess< SystemTime > |
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 24, 2019 License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
This class keeps track of the real time in the current time zone. It may obtain its data through the mesh, or some other way and try to keep up to date using on board timing functionality.
This class also synchronizes time with other nodes in the mesh. The node with the lowest ID is considered to be the root clock. Other nodes will update their time on receival of time sync messages from the root clock.
There are some scenarios to consider here:
This is solved by:
For robustness, not only the root clock node, but all nodes will regularly send a time sync message. It's up to the receiving node to device which clock is the root clock. Not sure if this is necessary.
|
virtualdefault |
|
static |
Get the current weekday.
|
staticconstexprprivate |
|
static |
Get the synchronized timestamp, updated to current time.
When version == 0, the timestamp is not posix based.
|
virtual |
Handle events.
This method is overloaded by all classes that derive from EventListener. They can receive an event_t struct and act upon it. These events are dispatched by the EventDispatcher.
Implements EventListener.
void SystemTime::init | ( | ) |
Creates and starts the first tick timer.
|
staticprivate |
Sets up the debug symc time coroutine when DEBUG_SYSTEM_TIME is defined in order to broadcast sync messages to the mesh regardless of being root clock or not.
|
private |
Returns true if the command source is uart or ble through connection.
|
staticprivate |
Returns true if the candidate can considered to be root clock.
|
staticprivate |
Returns true if the id of this stone can considered to be root clock.
|
staticprivate |
|
static |
Get the current time as posix timestamp in seconds.
Returns 0 if no valid posix time is set.
|
staticprivate |
|
staticprivate |
|
staticconstexprprivate |
Timeout period before considering this stone to be root clock.
|
staticprivate |
Returns true when reboot period is passed.
|
staticprivate |
Returns true if onTimeSyncMessageReceive hasn't received any sync messages from a clock authority in the last root_clock_reelection_timeout_ms milliseconds.
|
staticconstexprprivate |
If no sync message has been received from the root clock for this time, a new root clock will be selected.
|
staticconstexprprivate |
Time between sync messages from the root clock.
|
staticprivate |
|
staticprivate |
Send a sync message for given stamp/id combo to the mesh.
|
staticprivate |
|
static |
Set the sunrise and sunset times.
Also sets it to state.
[in] | sunTimes | Sun rise and set times. |
[in] | throttled | When true, a new suntime won't be allowed to be set for a while. Unless it's set with throttled false. |
|
static |
Set the system wide time to given posix timestamp.
Dispatches EVT_TIME_SET. Also sets it to state.
[in] | time | Posix time in seconds. |
[in] | throttled | When true, a new suntime won't be allowed to be set for a while. Unless it's set with throttled false. |
[in] | sendToMesh | Setting this to false will prevent updating other mesh nodes |
|
staticconstexprprivate |
Stone id to use for initialization.
|
staticprivate |
|
staticprivate |
Must be called at least once per second to update upTimeSec.
|
staticconstexprprivate |
The time version is lollipop versioned.
This constant defines its roll over point.
|
staticconstexprprivate |
Lowest time version at which a valid posix time is set.
|
staticprivate |
|
static |
Uptime in seconds.
|
staticprivate |
Keep up the root clock time.
Should be called at least every second. But it currently looses some precision, so don't call it too often.
|
friend |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Cached ID of this stone.
|
staticprivate |
Stone ID of the root clock.
|
staticprivate |
Root clock.
Updated at a low rate, use a function to get an up to date timestamp.
|
staticprivate |
RTC count of last time the root clock was set.
|
staticprivate |
RTC count of last time a second had passed.
|
staticprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticprivate |
|
staticprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticprivate |
Uptime of last time a sync message was received.
|
staticprivate |