-
Notifications
You must be signed in to change notification settings - Fork 4
BiDiB State Object
The sending and receiving of BiDiB messages to and from the BiDiB boards are handled by two pthreads that are forked after serial communication has been established with the BiDiB boards:
-
bidib_receiver_thread
: Periodically checks the serial communication for new messages that have been sent from the BiDiB boards. Message types are handled bybidib_handle_received_message(...)
. -
bidib_autoflush_thread
: Periodically flushes the contents of the BiDiB message buffer out to the serial communication, which have been placed in bybidib_buffer_message_with_data(...)
.
All message types are defined in include/definitions/bidib_messages.h.
The BiDiB state is stored in a t_bidib_track_state_intern
data structure. It is sometimes updated after an actuate command is sent to the BiDiB boards, or after a BiDiB feedback message has been received, e.g.:
-
bidib_send_cs_drive_intern(...)
: After a drive command has been sent,bidib_state_cs_drive(...)
is called to update the train state. -
bidib_state_cs_accessory(...)
: Called after the position of a point has been set. -
bidib_handle_received_message(...)
: When BiDiB feedback messages are being handled, the BiDiB state is updated accordingly. For example, when a change in track occupancy has been detected (MSG_BM_ADDRESS
),bidib_state_bm_address(...)
is called to update the states of the track segments, which in turn callsbidib_state_update_train_available(void)
to update the train positions. As another example, when feedback on a point change has been detected (MSG_ACCESSORY_STATE
),bidib_state_accessory_state(...)
is called to update the states of the points.
The state of specific track elements can be retrieved by calling one of the bidib_get_..._state(...)
functions and providing the name of the track element (defined in the Yaml configuration files), e.g.:
bidib_get_point_state(const char *point)
bidib_get_signal_state(const char *signal)
bidib_get_peripheral_state(const char *peripheral)
bidib_get_segment_state(const char *segment)
These functions iterate over the state object until it finds the name of the provided track element. The index of the track element in the state object can be retrieved, so that its state can be accessed directly in constant time.
The entire BiDiB state is retrieved by calling bidib_get_state(void)
from src/highlevel/bidib_highlevel_getter.c, which returns a t_bidib_track_state
data structure. The index of a track element in the state object can be retrieved with one of the following functions: