Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
authorFlorian Pose <fp@igh-essen.com>
Tue, 17 Oct 2006 14:15:48 +0000
changeset 403 7bb931deccd9
parent 402 03e31ac14047
child 404 7f7f429e13c7
Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
master/fsm.c
master/globals.h
master/module.c
master/slave.c
--- a/master/fsm.c	Tue Oct 17 14:10:29 2006 +0000
+++ b/master/fsm.c	Tue Oct 17 14:15:48 2006 +0000
@@ -475,7 +475,7 @@
     }
 
     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 @@
 {
     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 @@
     // 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 @@
         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",
--- a/master/globals.h	Tue Oct 17 14:10:29 2006 +0000
+++ b/master/globals.h	Tue Oct 17 14:15:48 2006 +0000
@@ -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
  *****************************************************************************/
--- a/master/module.c	Tue Oct 17 14:10:29 2006 +0000
+++ b/master/module.c	Tue Oct 17 14:15:48 2006 +0000
@@ -233,7 +233,8 @@
 */
 
 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 @@
         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;
 }
--- a/master/slave.c	Tue Oct 17 14:10:29 2006 +0000
+++ b/master/slave.c	Tue Oct 17 14:15:48 2006 +0000
@@ -781,7 +781,7 @@
     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"))