diff --git a/master/fsm.c b/master/fsm.c index 1b6da74c73c23d3b68f0793be93921961de70077..94d8c8b344e6eaaed3c777c72cb2095371cfa01f 100644 --- a/master/fsm.c +++ b/master/fsm.c @@ -475,7 +475,7 @@ void ec_fsm_master_broadcast(ec_fsm_t *fsm /**< finite state machine */) } if (states_change) { - char states[25]; + char states[EC_STATE_STRING_SIZE]; ec_state_string(fsm->master_slave_states, states); EC_INFO("Slave states: %s.\n", states); } @@ -555,7 +555,7 @@ void ec_fsm_master_action_process_states(ec_fsm_t *fsm { ec_master_t *master = fsm->master; ec_slave_t *slave; - char old_state[25], new_state[25]; + char old_state[EC_STATE_STRING_SIZE], new_state[EC_STATE_STRING_SIZE]; // check if any slaves are not in the state, they're supposed to be list_for_each_entry(slave, &master->slaves, list) { @@ -690,7 +690,7 @@ void ec_fsm_master_read_states(ec_fsm_t *fsm /**< finite state machine */) // slave responded new_state = EC_READ_U8(datagram->data); if (!slave->online) { // slave was offline before - char cur_state[25]; + char cur_state[EC_STATE_STRING_SIZE]; slave->online = 1; slave->error_flag = 0; // clear error flag slave->current_state = new_state; @@ -698,7 +698,7 @@ void ec_fsm_master_read_states(ec_fsm_t *fsm /**< finite state machine */) EC_INFO("Slave %i: online (%s).\n", slave->ring_position, cur_state); } else if (new_state != slave->current_state) { - char old_state[25], cur_state[25]; + char old_state[EC_STATE_STRING_SIZE], cur_state[EC_STATE_STRING_SIZE]; ec_state_string(slave->current_state, old_state); ec_state_string(new_state, cur_state); EC_INFO("Slave %i: %s -> %s.\n", diff --git a/master/globals.h b/master/globals.h index 7d67899118f946ff93d1035f800808a6f406e57e..ede1445f90df27625ae4fd59451fec4169ba4a75 100644 --- a/master/globals.h +++ b/master/globals.h @@ -77,6 +77,9 @@ /** datagram timeout in microseconds */ #define EC_IO_TIMEOUT 500 +/** minimum size of a buffer used with ec_state_string() */ +#define EC_STATE_STRING_SIZE 30 + /****************************************************************************** * EtherCAT protocol *****************************************************************************/ diff --git a/master/module.c b/master/module.c index 1e7d4132df11c17985a90eb2d3df2da1a50028fc..b8d306435840387a99fa8aeb1a9a9d22c256f614 100644 --- a/master/module.c +++ b/master/module.c @@ -233,7 +233,8 @@ void ec_print_data_diff(const uint8_t *d1, /**< first data */ */ size_t ec_state_string(uint8_t states, /**< slave states */ - char *buffer /**< target buffer (min. 25 bytes) */ + char *buffer /**< target buffer + (min. EC_STATE_STRING_SIZE bytes) */ ) { off_t off = 0; @@ -262,6 +263,10 @@ size_t ec_state_string(uint8_t states, /**< slave states */ if (!first) off += sprintf(buffer + off, ", "); off += sprintf(buffer + off, "OP"); } + if (states & EC_SLAVE_STATE_ACK_ERR) { + if (!first) off += sprintf(buffer + off, ", "); + off += sprintf(buffer + off, "ERR"); + } return off; } diff --git a/master/slave.c b/master/slave.c index 4e0ced66471eec69028b38a008ade68e86d9125c..af31a0fa61ce5c9921fd1d2d0496ffc4a60841c5 100644 --- a/master/slave.c +++ b/master/slave.c @@ -781,7 +781,7 @@ ssize_t ec_store_slave_attribute(struct kobject *kobj, /**< slave's kobject */ ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj); if (attr == &attr_state) { - char state[25]; + char state[EC_STATE_STRING_SIZE]; if (!strcmp(buffer, "INIT\n")) slave->requested_state = EC_SLAVE_STATE_INIT; else if (!strcmp(buffer, "PREOP\n"))