|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Implementation of the application-level Broadcast Time Protocol module. More...
Macros | |
| #define | BROADCAST_TIME_MS_PER_MINUTE_FIXED_POINT 240000 |
Functions | |
| void | OpenLcbApplicationBroadcastTime_initialize (const interface_openlcb_application_broadcast_time_t *interface) |
| Initialises the broadcast time module and stores the callback interface. | |
| broadcast_clock_state_t * | OpenLcbApplicationBroadcastTime_setup_consumer (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Allocates a clock slot as a consumer and registers event ranges on the node. | |
| broadcast_clock_state_t * | OpenLcbApplicationBroadcastTime_setup_producer (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Allocates a clock slot as a producer and registers event ranges on the node. | |
| void | OpenLcbApplicationBroadcastTime_start (event_id_t clock_id) |
| Marks the given clock as running. | |
| void | OpenLcbApplicationBroadcastTime_stop (event_id_t clock_id) |
| Marks the given clock as stopped. | |
| broadcast_clock_state_t * | OpenLcbApplicationBroadcastTime_get_clock (event_id_t clock_id) |
| Returns the state for a registered clock. | |
| bool | OpenLcbApplicationBroadcastTime_is_consumer (event_id_t clock_id) |
| Returns whether the given clock is registered as a consumer. | |
| bool | OpenLcbApplicationBroadcastTime_is_producer (event_id_t clock_id) |
| Returns whether the given clock is registered as a producer. | |
| void | OpenLcbApplicationBroadcastTime_100ms_time_tick (uint8_t current_tick) |
| Advances all running consumer clocks by one 100 ms step. | |
| bool | OpenLcbApplicationBroadcastTime_send_report_time (openlcb_node_t *openlcb_node, event_id_t clock_id, uint8_t hour, uint8_t minute) |
| Sends a Report Time event (PCER) for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_report_date (openlcb_node_t *openlcb_node, event_id_t clock_id, uint8_t month, uint8_t day) |
| Sends a Report Date event (PCER) for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_report_year (openlcb_node_t *openlcb_node, event_id_t clock_id, uint16_t year) |
| Sends a Report Year event (PCER) for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_report_rate (openlcb_node_t *openlcb_node, event_id_t clock_id, int16_t rate) |
| Sends a Report Rate event (PCER) for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_start (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Sends a Start event (PCER) for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_stop (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Sends a Stop event (PCER) for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_date_rollover (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Sends a Date Rollover event (PCER) for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_query_reply (openlcb_node_t *openlcb_node, event_id_t clock_id, uint8_t next_hour, uint8_t next_minute) |
| Sends the full query reply sequence for a producer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_query (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Sends a Query event (PCER) for a consumer clock. | |
| bool | OpenLcbApplicationBroadcastTime_send_set_time (openlcb_node_t *openlcb_node, event_id_t clock_id, uint8_t hour, uint8_t minute) |
| Sends a Set Time command to a clock generator. | |
| bool | OpenLcbApplicationBroadcastTime_send_set_date (openlcb_node_t *openlcb_node, event_id_t clock_id, uint8_t month, uint8_t day) |
| Sends a Set Date command to a clock generator. | |
| bool | OpenLcbApplicationBroadcastTime_send_set_year (openlcb_node_t *openlcb_node, event_id_t clock_id, uint16_t year) |
| Sends a Set Year command to a clock generator. | |
| bool | OpenLcbApplicationBroadcastTime_send_set_rate (openlcb_node_t *openlcb_node, event_id_t clock_id, int16_t rate) |
| Sends a Set Rate command to a clock generator. | |
| bool | OpenLcbApplicationBroadcastTime_send_command_start (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Sends a Start command to a clock generator. | |
| bool | OpenLcbApplicationBroadcastTime_send_command_stop (openlcb_node_t *openlcb_node, event_id_t clock_id) |
| Sends a Stop command to a clock generator. | |
| void | OpenLcbApplicationBroadcastTime_trigger_query_reply (event_id_t clock_id) |
| Triggers an immediate query reply for a producer clock. | |
| void | OpenLcbApplicationBroadcastTime_trigger_sync_delay (event_id_t clock_id) |
| Starts or resets the 3-second sync delay timer for a producer clock. | |
Implementation of the application-level Broadcast Time Protocol module.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Manages the fixed-size clock array, the fixed-point time accumulator, and all send functions for the OpenLCB Broadcast Time Protocol.
| #define BROADCAST_TIME_MS_PER_MINUTE_FIXED_POINT 240000 |
| void OpenLcbApplicationBroadcastTime_initialize | ( | const interface_openlcb_application_broadcast_time_t * | interface | ) |
Initialises the broadcast time module and stores the callback interface.
Algorithm:
* @param interface Pointer to a interface_openlcb_application_broadcast_time_t * with the desired callbacks (NULL callbacks are safe). *
| broadcast_clock_state_t * OpenLcbApplicationBroadcastTime_setup_consumer | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Allocates a clock slot as a consumer and registers event ranges on the node.
Algorithm:
* @param openlcb_node Pointer to the openlcb_node_t; may be NULL to skip range registration. * @param clock_id 64-bit event_id_t identifying the clock. *
| broadcast_clock_state_t * OpenLcbApplicationBroadcastTime_setup_producer | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Allocates a clock slot as a producer and registers event ranges on the node.
Algorithm:
* @param openlcb_node Pointer to the openlcb_node_t; may be NULL to skip range registration. * @param clock_id 64-bit event_id_t identifying the clock. *
| void OpenLcbApplicationBroadcastTime_start | ( | event_id_t | clock_id | ) |
Marks the given clock as running.
Marks the given clock as running so the 100 ms tick will advance it.
Algorithm:
* @param clock_id 64-bit event_id_t identifying the clock. *
| void OpenLcbApplicationBroadcastTime_stop | ( | event_id_t | clock_id | ) |
Marks the given clock as stopped.
Marks the given clock as stopped so the 100 ms tick will not advance it.
Algorithm:
* @param clock_id 64-bit event_id_t identifying the clock. *
| broadcast_clock_state_t * OpenLcbApplicationBroadcastTime_get_clock | ( | event_id_t | clock_id | ) |
Returns the state for a registered clock.
Algorithm:
* @param clock_id 64-bit event_id_t identifying the clock. *
| bool OpenLcbApplicationBroadcastTime_is_consumer | ( | event_id_t | clock_id | ) |
Returns whether the given clock is registered as a consumer.
Algorithm:
* @param clock_id 64-bit event_id_t identifying the clock. *
| bool OpenLcbApplicationBroadcastTime_is_producer | ( | event_id_t | clock_id | ) |
Returns whether the given clock is registered as a producer.
Algorithm:
* @param clock_id 64-bit event_id_t identifying the clock. *
| void OpenLcbApplicationBroadcastTime_100ms_time_tick | ( | uint8_t | current_tick | ) |
Advances all running consumer clocks by one 100 ms step.
Advances all running consumer clocks based on elapsed ticks.
Algorithm:
The threshold 240,000 equals 4 * 60 * 1000, which at rate=4 (1.0x) yields exactly one fast-minute per real minute. See the accumulator math comment above for details.
* @param current_tick Current value of the global 100ms tick counter. *
| bool OpenLcbApplicationBroadcastTime_send_report_time | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| uint8_t | hour, | ||
| uint8_t | minute ) |
Sends a Report Time event (PCER) for a producer clock.
Sends a Report Time event (Producer Identified Set) for a producer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. * @param hour Hour value to report (0-23). * @param minute Minute value to report (0-59). *
| bool OpenLcbApplicationBroadcastTime_send_report_date | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| uint8_t | month, | ||
| uint8_t | day ) |
Sends a Report Date event (PCER) for a producer clock.
Sends a Report Date event (Producer Identified Set) for a producer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. * @param month Month value to report (1-12). * @param day Day value to report (1-31). *
| bool OpenLcbApplicationBroadcastTime_send_report_year | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| uint16_t | year ) |
Sends a Report Year event (PCER) for a producer clock.
Sends a Report Year event (Producer Identified Set) for a producer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. * @param year Year value to report. *
| bool OpenLcbApplicationBroadcastTime_send_report_rate | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| int16_t | rate ) |
Sends a Report Rate event (PCER) for a producer clock.
Sends a Report Rate event (Producer Identified Set) for a producer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. * @param rate 12-bit signed fixed-point rate (4 = 1.0x real-time). *
| bool OpenLcbApplicationBroadcastTime_send_start | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Sends a Start event (PCER) for a producer clock.
Sends a Start event for a producer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. *
| bool OpenLcbApplicationBroadcastTime_send_stop | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Sends a Stop event (PCER) for a producer clock.
Sends a Stop event for a producer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. *
| bool OpenLcbApplicationBroadcastTime_send_date_rollover | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Sends a Date Rollover event (PCER) for a producer clock.
Sends a Date Rollover event for a producer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. *
| bool OpenLcbApplicationBroadcastTime_send_query_reply | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| uint8_t | next_hour, | ||
| uint8_t | next_minute ) |
Sends the full query reply sequence for a producer clock.
Looks up the clock by clock_id and delegates to the internal state machine. See _send_query_reply_for_clock for the full sequence.
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. * @param next_hour Hour of the next scheduled time event (0-23). * @param next_minute Minute of the next scheduled time event (0-59). *
| bool OpenLcbApplicationBroadcastTime_send_query | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Sends a Query event (PCER) for a consumer clock.
Sends a Query event for a consumer clock.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the clock. *
| bool OpenLcbApplicationBroadcastTime_send_set_time | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| uint8_t | hour, | ||
| uint8_t | minute ) |
Sends a Set Time command to a clock generator.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the target clock. * @param hour Desired hour (0-23). * @param minute Desired minute (0-59). *
| bool OpenLcbApplicationBroadcastTime_send_set_date | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| uint8_t | month, | ||
| uint8_t | day ) |
Sends a Set Date command to a clock generator.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the target clock. * @param month Desired month (1-12). * @param day Desired day (1-31). *
| bool OpenLcbApplicationBroadcastTime_send_set_year | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| uint16_t | year ) |
Sends a Set Year command to a clock generator.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the target clock. * @param year Desired year. *
| bool OpenLcbApplicationBroadcastTime_send_set_rate | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id, | ||
| int16_t | rate ) |
Sends a Set Rate command to a clock generator.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the target clock. * @param rate 12-bit signed fixed-point rate (4 = 1.0x real-time). *
| bool OpenLcbApplicationBroadcastTime_send_command_start | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Sends a Start command to a clock generator.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the target clock. *
| bool OpenLcbApplicationBroadcastTime_send_command_stop | ( | openlcb_node_t * | openlcb_node, |
| event_id_t | clock_id ) |
Sends a Stop command to a clock generator.
Algorithm:
* @param openlcb_node Pointer to the sending openlcb_node_t. * @param clock_id 64-bit event_id_t identifying the target clock. *
| void OpenLcbApplicationBroadcastTime_trigger_query_reply | ( | event_id_t | clock_id | ) |
Triggers an immediate query reply for a producer clock.
Triggers an immediate query reply (6-message sync sequence) for a producer clock.
Sets the query_reply_pending flag and resets the state machine so the 100ms tick will drive the 6-message sync sequence.
* @param clock_id 64-bit event_id_t identifying the clock. *
| void OpenLcbApplicationBroadcastTime_trigger_sync_delay | ( | event_id_t | clock_id | ) |
Starts or resets the 3-second sync delay timer for a producer clock.
Each call resets the timer to 30 ticks (3 seconds at 100ms). When the timer expires, the query reply state machine is triggered automatically, sending the 6-message sync sequence.
* @param clock_id 64-bit event_id_t identifying the clock. *
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License