Skip to content

Commit

Permalink
Merge pull request #40 from uniba-swt/39-flush-in-batch
Browse files Browse the repository at this point in the history
Merge flush-in-batch capability
  • Loading branch information
eyip002 authored Dec 4, 2024
2 parents ae9b762 + c097281 commit 1959bd1
Show file tree
Hide file tree
Showing 39 changed files with 1,600 additions and 906 deletions.
52 changes: 23 additions & 29 deletions example/src/bidib_system_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,30 @@ void print_board_accessory_state_query(t_bidib_unified_accessory_state_query que
}

void print_points(void) {
GString *points = g_string_new("");
t_bidib_id_list_query query = bidib_get_connected_points();
for (size_t i = 0; i < query.length; i++) {
t_bidib_unified_accessory_state_query point_state =
bidib_get_point_state(query.ids[i]);

GString *execution_state = g_string_new("");
if (point_state.type == BIDIB_ACCESSORY_BOARD) {
g_string_printf(execution_state, "(target state%s reached)",
point_state.board_accessory_state.execution_state ?
" not" : "");
}
char execution_state_str[execution_state->len + 1];
strcpy(execution_state_str, execution_state->str);
g_string_free(execution_state, true);

g_string_append_printf(points, "%s%s - state: %s %s",
i != 0 ? "\n" : "", query.ids[i],
point_state.type == BIDIB_ACCESSORY_BOARD ?
point_state.board_accessory_state.state_id :
point_state.dcc_accessory_state.state_id,
execution_state_str);
bidib_free_unified_accessory_state_query(point_state);
GString *points = g_string_new("");
t_bidib_id_list_query query = bidib_get_connected_points();
for (size_t i = 0; i < query.length; i++) {
t_bidib_unified_accessory_state_query point_state = bidib_get_point_state(query.ids[i]);

GString *execution_state = g_string_new("");
if (point_state.type == BIDIB_ACCESSORY_BOARD) {
g_string_printf(execution_state, "(target state%s reached)",
point_state.board_accessory_state.execution_state ?
" not" : "");
}
bidib_free_id_list_query(query);
char response[points->len + 1];
strcpy(response, points->str);
g_string_free(points, true);

printf("%s\n", response);

g_string_append_printf(points, "%s%s - state: %s %s",
i != 0 ? "\n" : "", query.ids[i],
point_state.type == BIDIB_ACCESSORY_BOARD ?
point_state.board_accessory_state.state_id :
point_state.dcc_accessory_state.state_id,
execution_state->str);
g_string_free(execution_state, true);
bidib_free_unified_accessory_state_query(point_state);
}
bidib_free_id_list_query(query);
printf("%s\n", points->str);
g_string_free(points, true);
}

void print_segment_state_query(t_bidib_segment_state_query seg_state_query) {
Expand Down
4 changes: 2 additions & 2 deletions include/highlevel/bidib_highlevel_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
*
* @param read a pointer to a function, which reads a byte from the connected
* BiDiB interface. This function must not be blocking.
* @param write a pointer to a function, which sends a byte to the connected
* @param write_n a pointer to a function, which sends n bytes to the connected
* BiDiB interface.
* @param config_dir the directory in which the config files are stored, use
* NULL if no configs should be used.
* @param flush_interval the interval for automatic flushing in ms. If 0,
* automatic flushing is disabled.
* @return 0 if configs are valid, otherwise 1.
*/
int bidib_start_pointer(uint8_t (*read)(int *), void (*write)(uint8_t),
int bidib_start_pointer(uint8_t (*read)(int *), void (*write_n)(uint8_t*, int32_t),
const char *config_dir, unsigned int flush_interval);

/**
Expand Down
28 changes: 16 additions & 12 deletions src/highlevel/bidib_highlevel_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ int bidib_ping(const char *board, uint8_t ping_byte) {
syslog_libbidib(LOG_ERR, "Ping: parameters must not be NULL");
return 1;
}
pthread_rwlock_rdlock(&bidib_state_boards_rwlock);
// For bidib_state_get_board_ref
pthread_rwlock_rdlock(&bidib_boards_rwlock);
const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board);
if (tmp_board != NULL && tmp_board->connected) {
unsigned int action_id = bidib_get_and_incr_action_id();
Expand All @@ -51,11 +52,11 @@ int bidib_ping(const char *board, uint8_t ping_byte) {
tmp_board->node_addr.top, tmp_board->node_addr.sub,
tmp_board->node_addr.subsub, action_id);
t_bidib_node_address tmp_addr = tmp_board->node_addr;
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
bidib_send_sys_ping(tmp_addr, ping_byte, action_id);
return 0;
}
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
return 1;
}

Expand All @@ -64,7 +65,8 @@ int bidib_identify(const char *board, uint8_t state) {
syslog_libbidib(LOG_ERR, "Identify: parameters must not be NULL");
return 1;
}
pthread_rwlock_rdlock(&bidib_state_boards_rwlock);
// For bidib_state_get_board_ref
pthread_rwlock_rdlock(&bidib_boards_rwlock);
const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board);
if (tmp_board != NULL && tmp_board->connected) {
unsigned int action_id = bidib_get_and_incr_action_id();
Expand All @@ -74,11 +76,11 @@ int bidib_identify(const char *board, uint8_t state) {
tmp_board->node_addr.top, tmp_board->node_addr.sub,
tmp_board->node_addr.subsub, action_id);
t_bidib_node_address tmp_addr = tmp_board->node_addr;
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
bidib_send_sys_identify(tmp_addr, state, action_id);
return 0;
}
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
return 1;
}

Expand All @@ -87,7 +89,8 @@ int bidib_get_protocol_version(const char *board) {
syslog_libbidib(LOG_ERR, "Get protocol version: parameters must not be NULL");
return 1;
}
pthread_rwlock_rdlock(&bidib_state_boards_rwlock);
// For bidib_state_get_board_ref
pthread_rwlock_rdlock(&bidib_boards_rwlock);
const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board);
if (tmp_board != NULL && tmp_board->connected) {
unsigned int action_id = bidib_get_and_incr_action_id();
Expand All @@ -97,11 +100,11 @@ int bidib_get_protocol_version(const char *board) {
tmp_board->node_addr.top, tmp_board->node_addr.sub,
tmp_board->node_addr.subsub, action_id);
t_bidib_node_address tmp_addr = tmp_board->node_addr;
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
bidib_send_sys_get_p_version(tmp_addr, action_id);
return 0;
}
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
return 1;
}

Expand All @@ -110,7 +113,8 @@ int bidib_get_software_version(const char *board) {
syslog_libbidib(LOG_ERR, "Get software version: parameters must not be NULL");
return 1;
}
pthread_rwlock_rdlock(&bidib_state_boards_rwlock);
// For bidib_state_get_board_ref
pthread_rwlock_rdlock(&bidib_boards_rwlock);
const t_bidib_board *const tmp_board = bidib_state_get_board_ref(board);
if (tmp_board != NULL && tmp_board->connected) {
unsigned int action_id = bidib_get_and_incr_action_id();
Expand All @@ -120,10 +124,10 @@ int bidib_get_software_version(const char *board) {
tmp_board->node_addr.top, tmp_board->node_addr.sub,
tmp_board->node_addr.subsub, action_id);
t_bidib_node_address tmp_addr = tmp_board->node_addr;
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
bidib_send_sys_get_sw_version(tmp_addr, action_id);
return 0;
}
pthread_rwlock_unlock(&bidib_state_boards_rwlock);
pthread_rwlock_unlock(&bidib_boards_rwlock);
return 1;
}
Loading

0 comments on commit 1959bd1

Please sign in to comment.