56 :
public CallableFlow<BroadcastTimeServerDateRolloverFinishInput>
63 server->node()->iface())
125 int year = tm->tm_year + 1900;
383 int year = tm->tm_year + 1900;
444 expires += 60 - tm->tm_sec;
451 expires -= tm->tm_sec ? (tm->tm_sec + 2) : 2;
454 long long real_expires = 0;
481 uint8_t shutdown_ : 1;
510 server->node()->iface())
543 bool start_or_stop =
false;
547 time_t new_seconds = 0;
549 uint16_t suffix =
message()->data()->suffix_;
556 start_or_stop =
true;
560 start_or_stop =
true;
658 server->node(), server,
660 std::placeholders::_1))
676 if (hour <= 23 && hour >= 0 && min <= 59 && min >= 0)
723 int hour = tm->tm_hour;
724 int min = tm->tm_min;
732 seconds += 60 - tm->tm_sec;
736 seconds -= tm->tm_sec + 1;
752 while ((hour != tm->tm_hour || min != tm->tm_min) &&
753 --rate_min_per_4_real_min > 0);
805 , secondsRequested_(0)
806 , updateRequested_(false)
832void BroadcastTimeServer::shutdown()
839bool BroadcastTimeServer::is_shutdown()
841 return is_terminated() && alarm_->is_shutdown() && sync_->is_shutdown();
859 if (hour != -1 && min != -1)
int bind(int socket, const struct sockaddr *address, socklen_t address_len)
Bind a name to a socket.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
See OSMutexLock in os/OS.hxx.
This class sends a notification in its destructor.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
void notify() override
Implementation of the barrier semantics.
Action return_ok()
Terminates the flow and returns the request buffer to the caller with an error code of OK (zero).
Action wait_and_return_ok()
Waits to be notified before moving onto the next state for termination.
static long long get_monotonic()
Get the monotonic time since the system started.
static EventRegistry * instance()
Return type for a state flow callback.
Use this timer class to deliver the timeout notification to a stateflow.
Action exit()
Terminate current StateFlow activity.
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
static void invoke_subflow_and_ignore_result(FlowInterface< Buffer< T > > *target_flow, Args &&... args)
Calls a helper flow to perform some actions.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
Action sleep_and_call(::Timer *timer, long long timeout_nsec, Callback c)
Suspends execution of this control flow for a specified time.
struct tm * gmtime_r(struct tm *result)
Get the time as a standard struct tm.
uint16_t started_
true if clock is started
time_t seconds_
Clock time at the last time update.
bool is_started()
Test of the clock is started (rate could still be 0).
int16_t get_rate_quarters()
Report the clock rate as a 12-bit fixed point number (-512.00 to 511.75).
bool is_running()
Test of the clock is running.
long long timestamp_
OS time at the last time update.
bool real_nsec_until_fast_time_abs(time_t fast_sec, long long *real_nsec)
Convert a fast time to absolute nsec until it will occur.
time_t time()
Get the time as a value of seconds relative to the system epoch.
int16_t rate_
effective clock rate
void ensure_triggered()
Triggers the timer if it is not expired yet.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Basic alarm type that all other alarms are based off of.
void set(time_t time)
Start the alarm to expire at the given fast time.
BroadcastTime * clock_
clock that our alarm is based off of
virtual Action entry()
Entry point to state flow.
virtual void update_notify()
Called by the clock when time, rate, or running state has changed.
Specialization of the BroacastTimeAlarm to expire on the necessary clock minutes that must be produce...
uint64_t activeMinutes_[24]
active minutes to produce events on
BroadcastTimeServerAlarm(BroadcastTimeServer *server)
Constructor.
bool next_minute(int *hour, int *min)
Advance to the next hour/min based on rate setting.
void update_notify() override
Called when the clock time has changed.
time_t next_active_minute(time_t seconds, const struct tm *tm)
Get the next active minute that we will produce a time event on.
void expired_callback(BarrierNotifiable *done)
callback for when the alarm expires.
BroadcastTimeServer * server_
reference to our parent
Action entry() override
Entry point of the state machine.
void subscribe(int hour, int min)
Add a time event subscriber.
~BroadcastTimeServerAlarm()
Destructor.
State machine for sending the date rollover finish (year and date events) sequence.
BroadcastTimeServer * server_
reference to our parent
StateFlowTimer timer_
timer helper
uint8_t abortCnt_
request that the current processing be aborted
Action send_date_report()
Send the Event Report message appropriate for the date event ID.
BroadcastTimeServerDateRolloverFinish(BroadcastTimeServer *server)
Constuctor.
WriteHelper writer_
helper for sending event messages
~BroadcastTimeServerDateRolloverFinish()
Destructor.
void request_finish()
Request a date rollover finish.
Action entry() override
Wait the obligatory 3 seconds before sending the year/date report.
Action send_year_report()
Send the Event Report message appropriate for the year event ID.
State machine for sending the clock set sequence.
Action send_sync()
Request the sync sequence if timer has not been triggered early.
Action entry() override
Set a clock attribute and send the appropriate event report.
Action write_done()
The previous event write has completed.
BroadcastTimeServerSet(BroadcastTimeServer *server)
Constuctor.
WriteHelper writer_
helper for sending event messages
StateFlowTimer timer_
timer helper
~BroadcastTimeServerSet()
Destructor.
uint8_t requestCount_
counter to know when there are no more requests
void request_set(uint16_t suffix)
Request a time parameter set.
BroadcastTimeServer * server_
reference to our parent
State machine for sending the clock sync sequence.
Action send_rate_report()
Send the Producer Identified message appropriate for the rate event ID.
WriteHelper writer_
helper for sending event messages
BroadcastTimeServerSync(BroadcastTimeServer *server)
Constuctor.
StateFlowTimer timer_
timer helper
Action entry() override
Send the Producer Identified message appropriate for the start/stop event ID.
Action send_time_report_next()
Send the Event Report message appropriate for the time event ID.
~BroadcastTimeServerSync()
Destructor.
BroadcastTimeServer * server_
reference to our parent
Action send_time_report_done()
If clock is running, sleep until next time report.
uint8_t syncRequired_
flag to keep track of multiple sync requests
Action send_year_report()
Send the Producer Identified message appropriate for the year event ID.
void request_sync()
Request a sync.
Action send_date_report()
Send the Producer Identified message appropriate for the date event ID.
Action send_time_report()
Send the Producer Identified message appropriate for the time event ID.
State machine for sending the clock time events.
Action entry() override
Send the date rollover event if appropriate.
~BroadcastTimeServerTime()
Destructor.
BroadcastTimeServerDateRolloverFinish finish_
finsh the date rollover
BroadcastTimeServer * server_
reference to our parent
uint8_t timeRequired_
flag to keep track of multiple tme requests
BroadcastTimeServerTime(BroadcastTimeServer *server)
Constuctor.
Action send_time_report()
Send the appropriate time report event.
uint8_t dateRollover_
processing a date rollover
void request_time()
Request a time event.
WriteHelper writer_
helper for sending event messages
Implementation of a Broadcast Time Protocol server.
BroadcastTimeServer(Node *node, NodeID clock_id)
Constructor.
~BroadcastTimeServer()
Destructor.
void handle_consumer_range_identified(const EventRegistryEntry ®istry_entry, EventReport *event, BarrierNotifiable *done) override
Called on another node sending ConsumerRangeIdentified.
void handle_event_report(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming event report.
void handle_consumer_identified(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming consumer identified.
Action query_response()
Respond to a query by scheduling a sync.
Action entry()
Entry to state machine.
virtual void set_shortcut(uint64_t event) override
Try the possible set event shortcut.
Implementation of Broadcast Time Protocol.
const struct tm * gmtime_get()
Get the last calculated reprentation of time.
void service_callbacks(time_t old, time_t current)
Service all of the attached update subscribers.
Node * node()
Accessor method to get the Node reference.
EventId event_base()
Access method to get the (64-bit) Event ID base.
const struct tm * gmtime_recalculate()
Recalculate the struct tm representation of time.
EventId eventBase_
48-bit unique identifier for the clock instance
Structure used in registering event handlers.
Base class for NMRAnet nodes conforming to the asynchronous interface.
A statically allocated buffer for sending one message to the OpenLCB bus.
void WriteAsync(Node *node, Defs::MTI mti, NodeHandle dst, const payload_type &buffer, Notifiable *done)
Originates an NMRAnet message from a particular node.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
uint64_t NodeID
48-bit NMRAnet Node ID type
Payload eventid_to_buffer(uint64_t eventid)
Converts an Event ID to a Payload suitable to be sent as an event report.
#define SEC_TO_NSEC(_sec)
Convert a second value to a nanosecond value.
All callable flow request objects have to derive from this struct.
static uint64_t time_to_event(uint64_t event_base, int hours, int minutes)
Build an event from hours and minutes.
static int event_to_day(uint64_t event)
Get the day from the event.
static int event_to_month(uint64_t event)
Get the month from the event.
static uint64_t year_to_event(uint64_t event_base, int year)
Build an event from year.
static int event_to_min(uint64_t event)
Get the minutes from the event.
static EventType get_event_type(uint16_t suffix)
Get the EventTuype from the event suffix number.
static uint64_t rate_to_event(uint64_t event_base, int16_t rate)
Build an event from rate.
static int16_t event_to_rate(uint64_t event)
Get the rate from the event.
static uint64_t date_to_event(uint64_t event_base, int month, int day)
Build an event from month and day.
static int event_to_year(uint64_t event)
Get the year from the event.
@ REPORT_TIME
report time event
static int event_to_hour(uint64_t event)
Get the hour from the event.
@ START_EVENT_SUFFIX
start clock event suffix value
@ DATE_ROLLOVER_EVENT_SUFFIX
rollover the date suffix value
@ STOP_EVENT_SUFFIX
stop clock event suffix value
@ MTI_PRODUCER_IDENTIFIED_VALID
producer broadcast, valid state
Shared notification structure that is assembled for each incoming event-related message,...
EventId mask
Specifies the mask in case the request is for an event range.
EventId event
The event ID from the incoming message.