Closed eyip002 closed 4 years ago
I can confirm, through experimentation on a live system, that this is the way to detect and record the orientation of a train.
Recording the train orientation in bidib_state_cs_drive()
is not the right place; this function is only responsible for sending MSG_CS_DRIVE
commands.
https://github.com/uniba-swt/libbidib/blob/dd0b871d06c15154f4bc571853da12288dc21ce7/src/state/bidib_state_setter.c#L208
Extended struct t_bidib_dcc_address
with type
to store the two MSB of an address that defines the type of address (locomotive or accessory decoder). For locomotives, type
determines whether the train is in the left or right orientation.
Renamed the struct t_bidib_train_direction
and its values in terms of orientation.
Renamed struct variable t_bidib_train_state_data.direction to t_bidib_train_state_data.orientation.
Extended struct t_bidib_train_position_query
with orientation_is_left
for train orientation information.
Extended struct t_bidib_train_state_intern
with orientation.
Updated the following functions to support the updated structs:
bidib_get_state_trains()
bidib_get_train_state()
bidib_get_train_dcc_addr()
bidib_get_train_position_intern()
bidib_get_train_position_intern()
bidib_config_parse_single_dcc_accessory()
bidib_config_parse_single_train()
Extended function bidib_state_update_train_available()
to update the train's current orientation.
Updated function bidib_state_reset()
to support the updated struct.
Implemented a new function bidib_state_get_segment_state()
that returns a deep copy of a given segment's state. Needed to log the trains and their current orientation as they enter and exit a segment.
Removed from function bidib_state_cs_drive()
the updating of train orientation , because this is not the right place; orientation is unknown by the function.
Updated function bidib_state_log_train_detect()
to log orientation information.
Updated function bidib_state_bm_address_log_changes()
to store the orientation of a new train address.
Updated function bidib_state_bm_address()
to extract the orientation of all train addresses, and to log train movements after the train states have been updated. To log train movements with proper orientation information, the previous train states have to be saved temporarily while the current list of trains on each segment is updated.
In Section 4.7.7 of the BiDiB standard, the address format of locomotives is described. An address has a low and high part, called addrl and addrh respectively.
What is interesting is that bits 7 and 6 of addrh (assuming 0 indexing) provides the locomotive's orientation relative to the track.
00
means that the locomotive faces one way, while10
means it faces the other.Could this orientation information be included in the train state? https://github.com/uniba-swt/libbidib/blob/92472ed1faa734e72426929d23b72498eb24d2ce/src/state/bidib_state_intern.h#L49-L58
https://github.com/uniba-swt/libbidib/blob/92472ed1faa734e72426929d23b72498eb24d2ce/include/definitions/bidib_definitions_custom.h#L255-L258
One of the places where locomotive orientation is updated? https://github.com/uniba-swt/libbidib/blob/92472ed1faa734e72426929d23b72498eb24d2ce/src/state/bidib_state_setter.c#L607
https://github.com/uniba-swt/libbidib/blob/dd0b871d06c15154f4bc571853da12288dc21ce7/src/state/bidib_state.c#L610