Skip to content

Commit

Permalink
Merge pull request #43 from uniba-swt/stop-delay-benchmarking
Browse files Browse the repository at this point in the history
Merge Stop delay benchmarking (log time for train occupancy changes)
  • Loading branch information
eyip002 authored Dec 2, 2024
2 parents 5f27c61 + 26710c1 commit 6202a62
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
13 changes: 8 additions & 5 deletions src/state/bidib_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <memory.h>
#include <unistd.h>
#include <stdint.h>
#include <time.h>

#include "bidib_state_intern.h"
#include "bidib_state_getter_intern.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
37 changes: 23 additions & 14 deletions src/state/bidib_state_setter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <stdint.h>
#include <glib.h>
#include <time.h>

#include "bidib_state_setter_intern.h"
#include "bidib_state_getter_intern.h"
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 6202a62

Please sign in to comment.