diff --git a/src/state/bidib_state.c b/src/state/bidib_state.c index 3ce0b90..db33d33 100644 --- a/src/state/bidib_state.c +++ b/src/state/bidib_state.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "bidib_state_intern.h" #include "bidib_state_getter_intern.h" @@ -661,6 +662,8 @@ void bidib_state_add_initial_train_value(t_bidib_state_train_initial_value value void bidib_state_update_train_available(void) { t_bidib_train_state_intern *train_state; t_bidib_train_position_query query; + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); for (size_t i = 0; i < bidib_track_state.trains->len; i++) { train_state = &g_array_index( bidib_track_state.trains, t_bidib_train_state_intern, i); @@ -670,15 +673,15 @@ void bidib_state_update_train_available(void) { (query.orientation_is_left ? BIDIB_TRAIN_ORIENTATION_LEFT : BIDIB_TRAIN_ORIENTATION_RIGHT); if (train_state->on_track == false) { - syslog_libbidib(LOG_NOTICE, "Train %s detected, orientated %s", - train_state->id->str, - query.orientation_is_left ? "left" : "right"); + syslog_libbidib(LOG_NOTICE, "Train %s detected, orientated %s, at time %d.%.9ld", + train_state->id->str, query.orientation_is_left ? "left" : "right", + tv.tv_sec, tv.tv_nsec); } train_state->on_track = true; } else { if (train_state->on_track == true) { - syslog_libbidib(LOG_WARNING, "Train %s lost", - train_state->id->str); + syslog_libbidib(LOG_WARNING, "Train %s lost, at time %d.%.9ld", + train_state->id->str, tv.tv_sec, tv.tv_nsec); } train_state->on_track = false; } diff --git a/src/state/bidib_state_setter.c b/src/state/bidib_state_setter.c index 2baf7fb..6fc3a9c 100644 --- a/src/state/bidib_state_setter.c +++ b/src/state/bidib_state_setter.c @@ -29,6 +29,7 @@ #include #include +#include #include "bidib_state_setter_intern.h" #include "bidib_state_getter_intern.h" @@ -37,13 +38,13 @@ void bidib_state_vendor(t_bidib_node_address node_address, uint8_t length, - const uint8_t *const value_list, unsigned int action_id) { + const uint8_t *const value_list, unsigned int action_id) { pthread_rwlock_wrlock(&bidib_state_track_rwlock); pthread_rwlock_rdlock(&bidib_state_boards_rwlock); uint8_t name_len = value_list[0]; char *name = strndup((const char *)&value_list[1], name_len); - uint8_t value_len = value_list[name_len + 1]; + uint8_t value_len = value_list[name_len + 1]; char *value = strndup((const char *)&value_list[length - value_len], value_len); // check whether the name corresponds to the CV of a reverser @@ -144,7 +145,7 @@ void bidib_state_accessory_state(t_bidib_node_address node_address, uint8_t numb : (wait & 0x80) ? (wait & 0x3f) : ((float) (wait & 0x3f)) * 0.1; syslog_libbidib(LOG_INFO, "Feedback for action id %d: %s accessory: %s execution: %s%s reached%s " - "verified with wait time: %.1fs", + "verified with wait time: %.1fs", action_id, (point) ? "Point" : "Signal", accessory_mapping->id->str, aspect_mapping->id->str, (target_state_reached) ? "" : " not", @@ -400,7 +401,7 @@ void bidib_state_cs_accessory(t_bidib_node_address node_address, t_bidib_dcc_accessory_state *accessory_state; if (accessory_mapping != NULL && (accessory_state = bidib_state_get_dcc_accessory_state_ref(accessory_mapping->id->str, - point)) != NULL) { + point)) != NULL) { accessory_state->data.state_id = NULL; accessory_state->data.state_value = (uint8_t) (params.data & 0x1F); if (params.data & (1 << 5)) { @@ -471,7 +472,7 @@ void bidib_state_lc_wait(t_bidib_node_address node_address, t_bidib_peripheral_p pthread_rwlock_wrlock(&bidib_state_track_rwlock); pthread_rwlock_rdlock(&bidib_state_boards_rwlock); const t_bidib_peripheral_mapping *const peripheral_mapping = - bidib_state_get_peripheral_mapping_ref_by_port(node_address, port); + bidib_state_get_peripheral_mapping_ref_by_port(node_address, port); if (peripheral_mapping != NULL && (peripheral_state = bidib_state_get_peripheral_state_ref(peripheral_mapping->id->str)) != NULL) { if (time & (1 << 7)) { @@ -493,31 +494,39 @@ void bidib_state_lc_wait(t_bidib_node_address node_address, t_bidib_peripheral_p void bidib_state_log_train_detect(bool detected, const t_bidib_dcc_address *const dcc_address, const t_bidib_segment_state_intern *const segment_state) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); const t_bidib_train_state_intern *const train_state = - bidib_state_get_train_state_ref_by_dccaddr(*dcc_address); + bidib_state_get_train_state_ref_by_dccaddr(*dcc_address); if (detected) { if (train_state == NULL) { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being entered by: unknown train (0x%02x%02x) with %s orientation", + "Segment: %s is being entered by: unknown train (0x%02x%02x) " + "with %s orientation, at time %d.%.9ld", segment_state->id->str, dcc_address->addrh, dcc_address->addrl, - dcc_address->type == 0 ? "left" : "right"); + dcc_address->type == 0 ? "left" : "right", tv.tv_sec, tv.tv_nsec); } else { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being entered by: %s with %s orientation", + "Segment: %s is being entered by: %s with %s " + "orientation, at time %d.%.9ld", segment_state->id->str, train_state->id->str, - train_state->orientation == BIDIB_TRAIN_ORIENTATION_LEFT ? "left" : "right"); + train_state->orientation == BIDIB_TRAIN_ORIENTATION_LEFT ? "left" : "right", + tv.tv_sec, tv.tv_nsec); } } else { if (train_state == NULL) { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being exited by: unknown train (0x%02x%02x) with %s orientation", + "Segment: %s is being exited by: unknown train (0x%02x%02x) " + "with %s orientation, at time %d.%.9ld", segment_state->id->str, dcc_address->addrh, dcc_address->addrl, - dcc_address->type == 0 ? "left" : "right"); + dcc_address->type == 0 ? "left" : "right", tv.tv_sec, tv.tv_nsec); } else { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being exited by: %s with %s orientation", + "Segment: %s is being exited by: %s with %s " + "orientation, at time %d.%.9ld", segment_state->id->str, train_state->id->str, - train_state->orientation == BIDIB_TRAIN_ORIENTATION_LEFT ? "left" : "right"); + train_state->orientation == BIDIB_TRAIN_ORIENTATION_LEFT ? "left" : "right", + tv.tv_sec, tv.tv_nsec); } } }