From 68f955e21f45f04872abdf574161c4cbcbf2920c Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Thu, 24 Nov 2022 13:27:25 +0100 Subject: [PATCH 01/12] Added timestamp logging for delay benchmarking --- src/highlevel/bidib_highlevel_setter.c | 10 ++++++++++ src/lowlevel/bidib_lowlevel_track.c | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/highlevel/bidib_highlevel_setter.c b/src/highlevel/bidib_highlevel_setter.c index 4c1de47..48a264f 100644 --- a/src/highlevel/bidib_highlevel_setter.c +++ b/src/highlevel/bidib_highlevel_setter.c @@ -29,6 +29,7 @@ #include #include +#include #include "../../include/highlevel/bidib_highlevel_setter.h" #include "../../include/highlevel/bidib_highlevel_util.h" @@ -406,6 +407,9 @@ int bidib_set_train_speed_internal(const char *train, int speed, const char *tra } int bidib_set_train_speed(const char *train, int speed, const char *track_output) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + syslog_libbidib(LOG_NOTICE, "Set train speed %d: Start at %d.%.9ld", speed, tv.tv_sec, tv.tv_nsec); int ret = 0; pthread_rwlock_wrlock(&bidib_state_trains_rwlock); ret = bidib_set_train_speed_internal(train, speed, track_output); @@ -414,6 +418,9 @@ int bidib_set_train_speed(const char *train, int speed, const char *track_output } int bidib_set_calibrated_train_speed(const char *train, int speed, const char *track_output) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + syslog_libbidib(LOG_NOTICE, "Set calibrated train speed %d: Start at %d.%.9ld", speed, tv.tv_sec, tv.tv_nsec); if (train == NULL || track_output == NULL) { syslog_libbidib(LOG_ERR, "Set calibrated train speed: parameters must not be NULL"); return 1; @@ -454,6 +461,9 @@ int bidib_set_calibrated_train_speed(const char *train, int speed, const char *t } int bidib_emergency_stop_train(const char *train, const char *track_output) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + syslog_libbidib(LOG_NOTICE, "Emergency stop train: Start at %d.%.9ld", tv.tv_sec, tv.tv_nsec); if (train == NULL || track_output == NULL) { syslog_libbidib(LOG_ERR, "Emergency stop train: parameters must not be NULL"); return 1; diff --git a/src/lowlevel/bidib_lowlevel_track.c b/src/lowlevel/bidib_lowlevel_track.c index f36b95f..8f58795 100644 --- a/src/lowlevel/bidib_lowlevel_track.c +++ b/src/lowlevel/bidib_lowlevel_track.c @@ -81,7 +81,10 @@ void bidib_send_cs_drive_intern(t_bidib_node_address node_address, cs_drive_params.active, cs_drive_params.speed, cs_drive_params.function1, cs_drive_params.function2, cs_drive_params.function3, cs_drive_params.function4}; + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); bidib_buffer_message_with_data(addr_stack, MSG_CS_DRIVE, 9, data, action_id); + syslog_libbidib(LOG_NOTICE, "bidib_send_cs_drive_intern: buffer MSG_CS_DRIVE at %d.%.9ld", tv.tv_sec, tv.tv_nsec); if (lock) { pthread_rwlock_rdlock(&bidib_state_trains_rwlock); bidib_state_cs_drive(cs_drive_params); From a2edf4706e478fb990f9b8bc4358346fb400044a Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Fri, 2 Dec 2022 10:09:44 +0100 Subject: [PATCH 02/12] more time logging and lock type corrections --- src/highlevel/bidib_highlevel_getter.c | 2 +- src/state/bidib_state.c | 16 +++++++++------- src/state/bidib_state_setter.c | 21 +++++++++++++-------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/highlevel/bidib_highlevel_getter.c b/src/highlevel/bidib_highlevel_getter.c index 6d47c3a..dd7609d 100644 --- a/src/highlevel/bidib_highlevel_getter.c +++ b/src/highlevel/bidib_highlevel_getter.c @@ -1241,7 +1241,7 @@ t_bidib_train_position_query bidib_get_train_position_intern(const char *train) t_bidib_train_position_query bidib_get_train_position(const char *train) { pthread_rwlock_rdlock(&bidib_state_trains_rwlock); - pthread_rwlock_wrlock(&bidib_state_track_rwlock); + pthread_rwlock_rdlock(&bidib_state_track_rwlock); t_bidib_train_position_query query = bidib_get_train_position_intern(train); pthread_rwlock_unlock(&bidib_state_track_rwlock); pthread_rwlock_unlock(&bidib_state_trains_rwlock); diff --git a/src/state/bidib_state.c b/src/state/bidib_state.c index 85654d1..fc09095 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" @@ -245,8 +246,7 @@ void bidib_state_query_occupancy(void) { } void bidib_state_set_board_features(void) { - // Acquire bidib_state_boards_rwlock write lock because we need to wait for board features to change. - pthread_rwlock_wrlock(&bidib_state_boards_rwlock); + pthread_rwlock_rdlock(&bidib_state_boards_rwlock); for (size_t i = 0; i < bidib_boards->len; i++) { const t_bidib_board *const board_i = &g_array_index(bidib_boards, t_bidib_board, i); if (board_i->connected) { @@ -662,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); @@ -671,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, logged at %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, logged at %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 712788a..9b52aee 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" @@ -495,31 +496,35 @@ 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); 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, logged at %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, logged at %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, logged at %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, logged at %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); } } } From 6440d5bc167f1fbb8b9ffcc21807fba81f31a05d Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Fri, 2 Dec 2022 14:18:12 +0100 Subject: [PATCH 03/12] log train detection via printf --- src/state/bidib_state_setter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/state/bidib_state_setter.c b/src/state/bidib_state_setter.c index 9b52aee..13e30af 100644 --- a/src/state/bidib_state_setter.c +++ b/src/state/bidib_state_setter.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "bidib_state_setter_intern.h" #include "bidib_state_getter_intern.h" @@ -501,6 +502,7 @@ void bidib_state_log_train_detect(bool detected, const t_bidib_dcc_address *cons const t_bidib_train_state_intern *const train_state = bidib_state_get_train_state_ref_by_dccaddr(*dcc_address); if (detected) { + printf("Segment %s entered by train at %ld.%.9ld\n", segment_state->id->str, tv.tv_sec, tv.tv_nsec); if (train_state == NULL) { syslog_libbidib(LOG_NOTICE, "Segment: %s is being entered by: unknown train (0x%02x%02x) with %s orientation, logged at %d.%.9ld", From 9327ee77aa155de6e340759b983ee8d88bfc3542 Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Fri, 2 Dec 2022 14:21:12 +0100 Subject: [PATCH 04/12] add printf time log for send cs drive intern --- src/lowlevel/bidib_lowlevel_track.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lowlevel/bidib_lowlevel_track.c b/src/lowlevel/bidib_lowlevel_track.c index 8f58795..ddc92d9 100644 --- a/src/lowlevel/bidib_lowlevel_track.c +++ b/src/lowlevel/bidib_lowlevel_track.c @@ -83,6 +83,7 @@ void bidib_send_cs_drive_intern(t_bidib_node_address node_address, cs_drive_params.function3, cs_drive_params.function4}; struct timespec tv; clock_gettime(CLOCK_MONOTONIC, &tv); + printf("bidib_send_cs_drive_intern at %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); bidib_buffer_message_with_data(addr_stack, MSG_CS_DRIVE, 9, data, action_id); syslog_libbidib(LOG_NOTICE, "bidib_send_cs_drive_intern: buffer MSG_CS_DRIVE at %d.%.9ld", tv.tv_sec, tv.tv_nsec); if (lock) { From 9a4d67b1116a7dfea2935a7cca5f97648d9cfff4 Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Fri, 2 Dec 2022 14:36:39 +0100 Subject: [PATCH 05/12] Add flush and extra newline for time logs --- src/lowlevel/bidib_lowlevel_track.c | 4 +++- src/state/bidib_state_setter.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lowlevel/bidib_lowlevel_track.c b/src/lowlevel/bidib_lowlevel_track.c index ddc92d9..768aa13 100644 --- a/src/lowlevel/bidib_lowlevel_track.c +++ b/src/lowlevel/bidib_lowlevel_track.c @@ -28,6 +28,7 @@ */ #include +#include #include "../../include/lowlevel/bidib_lowlevel_track.h" #include "../../include/highlevel/bidib_highlevel_util.h" @@ -83,7 +84,8 @@ void bidib_send_cs_drive_intern(t_bidib_node_address node_address, cs_drive_params.function3, cs_drive_params.function4}; struct timespec tv; clock_gettime(CLOCK_MONOTONIC, &tv); - printf("bidib_send_cs_drive_intern at %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); + printf("\nbidib_send_cs_drive_intern at %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); + fflush(stdout); bidib_buffer_message_with_data(addr_stack, MSG_CS_DRIVE, 9, data, action_id); syslog_libbidib(LOG_NOTICE, "bidib_send_cs_drive_intern: buffer MSG_CS_DRIVE at %d.%.9ld", tv.tv_sec, tv.tv_nsec); if (lock) { diff --git a/src/state/bidib_state_setter.c b/src/state/bidib_state_setter.c index 13e30af..9416beb 100644 --- a/src/state/bidib_state_setter.c +++ b/src/state/bidib_state_setter.c @@ -502,7 +502,8 @@ void bidib_state_log_train_detect(bool detected, const t_bidib_dcc_address *cons const t_bidib_train_state_intern *const train_state = bidib_state_get_train_state_ref_by_dccaddr(*dcc_address); if (detected) { - printf("Segment %s entered by train at %ld.%.9ld\n", segment_state->id->str, tv.tv_sec, tv.tv_nsec); + printf("\nSegment %s entered by train at %ld.%.9ld\n", segment_state->id->str, tv.tv_sec, tv.tv_nsec); + fflush(stdout); if (train_state == NULL) { syslog_libbidib(LOG_NOTICE, "Segment: %s is being entered by: unknown train (0x%02x%02x) with %s orientation, logged at %d.%.9ld", From fb513dd0c8e8d85baa5c2ec9600d418b890038c9 Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Fri, 2 Dec 2022 15:07:23 +0100 Subject: [PATCH 06/12] log timestamps when receiving certain types of messages --- src/highlevel/bidib_highlevel_setter.c | 1 + src/transmission/bidib_transmission_receive.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/highlevel/bidib_highlevel_setter.c b/src/highlevel/bidib_highlevel_setter.c index 48a264f..e574faa 100644 --- a/src/highlevel/bidib_highlevel_setter.c +++ b/src/highlevel/bidib_highlevel_setter.c @@ -409,6 +409,7 @@ int bidib_set_train_speed_internal(const char *train, int speed, const char *tra int bidib_set_train_speed(const char *train, int speed, const char *track_output) { struct timespec tv; clock_gettime(CLOCK_MONOTONIC, &tv); + printf("\nSet train speed %d: Start at %ld.%.9ld\n", speed, tv.tv_sec, tv.tv_nsec); syslog_libbidib(LOG_NOTICE, "Set train speed %d: Start at %d.%.9ld", speed, tv.tv_sec, tv.tv_nsec); int ret = 0; pthread_rwlock_wrlock(&bidib_state_trains_rwlock); diff --git a/src/transmission/bidib_transmission_receive.c b/src/transmission/bidib_transmission_receive.c index 119fe12..08a59d4 100644 --- a/src/transmission/bidib_transmission_receive.c +++ b/src/transmission/bidib_transmission_receive.c @@ -699,6 +699,19 @@ static void bidib_split_packet(const uint8_t *const buffer, size_t buffer_size) } uint8_t type = bidib_extract_msg_type(message); + if (type == MSG_BM_OCC) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + printf("\nMSG_BM_OCC received %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); + } else if (type == MSG_BM_MULTIPLE) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + printf("\nMSG_BM_MULTIPLE received %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); + } else if (type == MSG_BM_ADDRESS) { + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + printf("\nMSG_BM_ADDRESS received %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); + } uint8_t addr_stack[4]; bidib_extract_address(message, addr_stack); uint8_t msg_seqnum = bidib_extract_seq_num(message); From 049847cd119996e331b511c1dbf1cdec17d7922c Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Fri, 2 Dec 2022 15:09:27 +0100 Subject: [PATCH 07/12] fix missing includes --- src/highlevel/bidib_highlevel_setter.c | 1 + src/transmission/bidib_transmission_receive.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/highlevel/bidib_highlevel_setter.c b/src/highlevel/bidib_highlevel_setter.c index e574faa..c094632 100644 --- a/src/highlevel/bidib_highlevel_setter.c +++ b/src/highlevel/bidib_highlevel_setter.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "../../include/highlevel/bidib_highlevel_setter.h" #include "../../include/highlevel/bidib_highlevel_util.h" diff --git a/src/transmission/bidib_transmission_receive.c b/src/transmission/bidib_transmission_receive.c index 08a59d4..c975cf9 100644 --- a/src/transmission/bidib_transmission_receive.c +++ b/src/transmission/bidib_transmission_receive.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "bidib_transmission_intern.h" #include "../../include/highlevel/bidib_highlevel_util.h" From 40f340debd947e47bbc666df87c5040625ceb929 Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Fri, 2 Dec 2022 15:24:56 +0100 Subject: [PATCH 08/12] add timestamped log for exit and log which segments --- src/state/bidib_state_setter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/state/bidib_state_setter.c b/src/state/bidib_state_setter.c index 9416beb..41c96b0 100644 --- a/src/state/bidib_state_setter.c +++ b/src/state/bidib_state_setter.c @@ -517,6 +517,7 @@ void bidib_state_log_train_detect(bool detected, const t_bidib_dcc_address *cons tv.tv_sec, tv.tv_nsec); } } else { + printf("\nSegment %s left by train at %ld.%.9ld\n", segment_state->id->str, tv.tv_sec, tv.tv_nsec); if (train_state == NULL) { syslog_libbidib(LOG_NOTICE, "Segment: %s is being exited by: unknown train (0x%02x%02x) with %s orientation, logged at %d.%.9ld", @@ -538,6 +539,7 @@ void bidib_state_bm_occ(t_bidib_node_address node_address, uint8_t number, bool t_bidib_segment_state_intern *segment_state = bidib_state_get_segment_state_ref_by_nodeaddr(node_address, number); if (segment_state != NULL) { + printf("\bidib_state_bm_occ called for segment %s\n", segment_state->id->str); segment_state->occupied = occ; if (!occ && segment_state->dcc_addresses->len > 0) { for (size_t j = 0; j < segment_state->dcc_addresses->len; j++) { @@ -708,6 +710,7 @@ void bidib_state_bm_address(t_bidib_node_address node_address, uint8_t number, t_bidib_segment_state_intern *segment_state = bidib_state_get_segment_state_ref_by_nodeaddr(node_address, number); if (segment_state != NULL) { + printf("\nbidib_state_bm_address called for segment %s\n", segment_state->id->str); // make a copy of the current decoder addresses for logging purposes t_bidib_segment_state_intern segment_state_intern_query = bidib_state_get_segment_state(segment_state); From 4a006eaa89f27360086f79716a5966c3b072e5e7 Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Tue, 8 Aug 2023 09:23:19 +0200 Subject: [PATCH 09/12] removed time logging from highlevel setter --- src/highlevel/bidib_highlevel_setter.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/highlevel/bidib_highlevel_setter.c b/src/highlevel/bidib_highlevel_setter.c index 71e7d7b..78c3619 100644 --- a/src/highlevel/bidib_highlevel_setter.c +++ b/src/highlevel/bidib_highlevel_setter.c @@ -29,8 +29,6 @@ #include #include -#include -#include #include "../../include/highlevel/bidib_highlevel_setter.h" #include "../../include/highlevel/bidib_highlevel_util.h" @@ -408,10 +406,6 @@ int bidib_set_train_speed_internal(const char *train, int speed, const char *tra } int bidib_set_train_speed(const char *train, int speed, const char *track_output) { - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - printf("\nSet train speed %d: Start at %ld.%.9ld\n", speed, tv.tv_sec, tv.tv_nsec); - syslog_libbidib(LOG_NOTICE, "Set train speed %d: Start at %d.%.9ld", speed, tv.tv_sec, tv.tv_nsec); int ret = 0; pthread_rwlock_wrlock(&bidib_state_trains_rwlock); ret = bidib_set_train_speed_internal(train, speed, track_output); @@ -420,9 +414,6 @@ int bidib_set_train_speed(const char *train, int speed, const char *track_output } int bidib_set_calibrated_train_speed(const char *train, int speed, const char *track_output) { - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - syslog_libbidib(LOG_NOTICE, "Set calibrated train speed %d: Start at %d.%.9ld", speed, tv.tv_sec, tv.tv_nsec); if (train == NULL || track_output == NULL) { syslog_libbidib(LOG_ERR, "Set calibrated train speed: parameters must not be NULL"); return 1; @@ -463,9 +454,6 @@ int bidib_set_calibrated_train_speed(const char *train, int speed, const char *t } int bidib_emergency_stop_train(const char *train, const char *track_output) { - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - syslog_libbidib(LOG_NOTICE, "Emergency stop train: Start at %d.%.9ld", tv.tv_sec, tv.tv_nsec); if (train == NULL || track_output == NULL) { syslog_libbidib(LOG_ERR, "Emergency stop train: parameters must not be NULL"); return 1; From cb708ca36bb3cea0a6315951beb2da6954a6937e Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Tue, 8 Aug 2023 09:26:10 +0200 Subject: [PATCH 10/12] Remove time log from lowlevel track and transmission --- src/lowlevel/bidib_lowlevel_track.c | 6 ------ src/transmission/bidib_transmission_receive.c | 15 --------------- 2 files changed, 21 deletions(-) diff --git a/src/lowlevel/bidib_lowlevel_track.c b/src/lowlevel/bidib_lowlevel_track.c index 7c0a053..b7a824f 100644 --- a/src/lowlevel/bidib_lowlevel_track.c +++ b/src/lowlevel/bidib_lowlevel_track.c @@ -28,7 +28,6 @@ */ #include -#include #include "../../include/lowlevel/bidib_lowlevel_track.h" #include "../../include/highlevel/bidib_highlevel_util.h" @@ -82,12 +81,7 @@ void bidib_send_cs_drive_intern(t_bidib_node_address node_address, cs_drive_params.active, cs_drive_params.speed, cs_drive_params.function1, cs_drive_params.function2, cs_drive_params.function3, cs_drive_params.function4}; - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - printf("\nbidib_send_cs_drive_intern at %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); - fflush(stdout); bidib_buffer_message_with_data(addr_stack, MSG_CS_DRIVE, 9, data, action_id); - syslog_libbidib(LOG_NOTICE, "bidib_send_cs_drive_intern: buffer MSG_CS_DRIVE at %d.%.9ld", tv.tv_sec, tv.tv_nsec); if (lock) { pthread_rwlock_rdlock(&bidib_state_trains_rwlock); bidib_state_cs_drive(cs_drive_params); diff --git a/src/transmission/bidib_transmission_receive.c b/src/transmission/bidib_transmission_receive.c index fb0a5de..7ce7088 100644 --- a/src/transmission/bidib_transmission_receive.c +++ b/src/transmission/bidib_transmission_receive.c @@ -33,8 +33,6 @@ #include #include #include -#include -#include #include "bidib_transmission_intern.h" #include "../../include/highlevel/bidib_highlevel_util.h" @@ -701,19 +699,6 @@ static void bidib_split_packet(const uint8_t *const buffer, size_t buffer_size) } uint8_t type = bidib_extract_msg_type(message); - if (type == MSG_BM_OCC) { - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - printf("\nMSG_BM_OCC received %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); - } else if (type == MSG_BM_MULTIPLE) { - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - printf("\nMSG_BM_MULTIPLE received %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); - } else if (type == MSG_BM_ADDRESS) { - struct timespec tv; - clock_gettime(CLOCK_MONOTONIC, &tv); - printf("\nMSG_BM_ADDRESS received %ld.%.9ld\n", tv.tv_sec, tv.tv_nsec); - } uint8_t addr_stack[4]; bidib_extract_address(message, addr_stack); uint8_t msg_seqnum = bidib_extract_seq_num(message); From a44953b704d08ea0bc238bb470cd735840c850e5 Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Tue, 8 Aug 2023 09:31:06 +0200 Subject: [PATCH 11/12] Adjust log message time integration --- src/state/bidib_state.c | 4 ++-- src/state/bidib_state_setter.c | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/state/bidib_state.c b/src/state/bidib_state.c index fc09095..b14f663 100644 --- a/src/state/bidib_state.c +++ b/src/state/bidib_state.c @@ -673,14 +673,14 @@ 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, logged at %d.%.9ld", + 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, logged at %d.%.9ld", + 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 57ec916..94c2a16 100644 --- a/src/state/bidib_state_setter.c +++ b/src/state/bidib_state_setter.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "bidib_state_setter_intern.h" #include "bidib_state_getter_intern.h" @@ -500,33 +499,34 @@ void bidib_state_log_train_detect(bool detected, const t_bidib_dcc_address *cons const t_bidib_train_state_intern *const train_state = bidib_state_get_train_state_ref_by_dccaddr(*dcc_address); if (detected) { - printf("\nSegment %s entered by train at %ld.%.9ld\n", segment_state->id->str, tv.tv_sec, tv.tv_nsec); - fflush(stdout); if (train_state == NULL) { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being entered by: unknown train (0x%02x%02x) with %s orientation, logged at %d.%.9ld", + "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", tv.tv_sec, tv.tv_nsec); } else { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being entered by: %s with %s orientation, logged at %d.%.9ld", + "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", - tv.tv_sec, tv.tv_nsec); + tv.tv_sec, tv.tv_nsec); } } else { - printf("\nSegment %s left by train at %ld.%.9ld\n", segment_state->id->str, tv.tv_sec, tv.tv_nsec); if (train_state == NULL) { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being exited by: unknown train (0x%02x%02x) with %s orientation, logged at %d.%.9ld", + "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", tv.tv_sec, tv.tv_nsec); } else { syslog_libbidib(LOG_NOTICE, - "Segment: %s is being exited by: %s with %s orientation, logged at %d.%.9ld", + "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", - tv.tv_sec, tv.tv_nsec); + tv.tv_sec, tv.tv_nsec); } } } @@ -537,7 +537,6 @@ void bidib_state_bm_occ(t_bidib_node_address node_address, uint8_t number, bool t_bidib_segment_state_intern *segment_state = bidib_state_get_segment_state_ref_by_nodeaddr(node_address, number); if (segment_state != NULL) { - printf("\bidib_state_bm_occ called for segment %s\n", segment_state->id->str); segment_state->occupied = occ; if (!occ && segment_state->dcc_addresses->len > 0) { for (size_t j = 0; j < segment_state->dcc_addresses->len; j++) { @@ -708,7 +707,6 @@ void bidib_state_bm_address(t_bidib_node_address node_address, uint8_t number, t_bidib_segment_state_intern *segment_state = bidib_state_get_segment_state_ref_by_nodeaddr(node_address, number); if (segment_state != NULL) { - printf("\nbidib_state_bm_address called for segment %s\n", segment_state->id->str); // make a copy of the current decoder addresses for logging purposes t_bidib_segment_state_intern segment_state_intern_query = bidib_state_get_segment_state(segment_state); From b826003659666b43d978b26c10df2f221bd9b498 Mon Sep 17 00:00:00 2001 From: Bernhard Luedtke Date: Tue, 8 Aug 2023 09:36:16 +0200 Subject: [PATCH 12/12] Whitespace consistency in bidib state setter --- src/state/bidib_state_setter.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/state/bidib_state_setter.c b/src/state/bidib_state_setter.c index 94c2a16..6fc3a9c 100644 --- a/src/state/bidib_state_setter.c +++ b/src/state/bidib_state_setter.c @@ -38,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 @@ -145,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", @@ -401,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)) { @@ -472,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)) { @@ -497,7 +497,7 @@ void bidib_state_log_train_detect(bool detected, const t_bidib_dcc_address *cons 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,