master/module.c
branch1.4-foe
changeset 1709 63e4bc918640
parent 1685 399ef727bf62
equal deleted inserted replaced
1708:fae3a1759126 1709:63e4bc918640
   355 /*****************************************************************************/
   355 /*****************************************************************************/
   356 
   356 
   357 /** Prints slave states in clear text.
   357 /** Prints slave states in clear text.
   358  */
   358  */
   359 size_t ec_state_string(uint8_t states, /**< slave states */
   359 size_t ec_state_string(uint8_t states, /**< slave states */
   360                        char *buffer /**< target buffer
   360                        char *buffer, /**< target buffer
   361                                        (min. EC_STATE_STRING_SIZE bytes) */
   361                                        (min. EC_STATE_STRING_SIZE bytes) */
       
   362                        uint8_t multi /**< Show multi-state mask. */
   362                        )
   363                        )
   363 {
   364 {
   364     off_t off = 0;
   365     off_t off = 0;
   365     unsigned int first = 1;
   366     unsigned int first = 1;
   366 
   367 
   367     if (!states) {
   368     if (!states) {
   368         off += sprintf(buffer + off, "(unknown)");
   369         off += sprintf(buffer + off, "(unknown)");
   369         return off;
   370         return off;
   370     }
   371     }
   371 
   372 
   372     if (states & EC_SLAVE_STATE_INIT) {
   373     if (multi) { // multiple slaves
   373         off += sprintf(buffer + off, "INIT");
   374         if (states & EC_SLAVE_STATE_INIT) {
       
   375             off += sprintf(buffer + off, "INIT");
       
   376             first = 0;
       
   377         }
       
   378         if (states & EC_SLAVE_STATE_PREOP) {
       
   379             if (!first) off += sprintf(buffer + off, ", ");
       
   380             off += sprintf(buffer + off, "PREOP");
       
   381             first = 0;
       
   382         }
       
   383         if (states & EC_SLAVE_STATE_SAFEOP) {
       
   384             if (!first) off += sprintf(buffer + off, ", ");
       
   385             off += sprintf(buffer + off, "SAFEOP");
       
   386             first = 0;
       
   387         }
       
   388         if (states & EC_SLAVE_STATE_OP) {
       
   389             if (!first) off += sprintf(buffer + off, ", ");
       
   390             off += sprintf(buffer + off, "OP");
       
   391         }
       
   392     } else { // single slave
       
   393         if ((states & EC_SLAVE_STATE_MASK) == EC_SLAVE_STATE_INIT) {
       
   394             off += sprintf(buffer + off, "INIT");
       
   395         } else if ((states & EC_SLAVE_STATE_MASK) == EC_SLAVE_STATE_PREOP) {
       
   396             off += sprintf(buffer + off, "PREOP");
       
   397         } else if ((states & EC_SLAVE_STATE_MASK) == EC_SLAVE_STATE_BOOT) {
       
   398             off += sprintf(buffer + off, "BOOT");
       
   399         } else if ((states & EC_SLAVE_STATE_MASK) == EC_SLAVE_STATE_SAFEOP) {
       
   400             off += sprintf(buffer + off, "SAFEOP");
       
   401         } else if ((states & EC_SLAVE_STATE_MASK) == EC_SLAVE_STATE_OP) {
       
   402             off += sprintf(buffer + off, "OP");
       
   403         } else {
       
   404             off += sprintf(buffer + off, "(invalid)");
       
   405         }
   374         first = 0;
   406         first = 0;
   375     }
   407     }
   376     if (states & EC_SLAVE_STATE_PREOP) {
   408 
   377         if (!first) off += sprintf(buffer + off, ", ");
       
   378         off += sprintf(buffer + off, "PREOP");
       
   379         first = 0;
       
   380     }
       
   381     if (states & EC_SLAVE_STATE_SAFEOP) {
       
   382         if (!first) off += sprintf(buffer + off, ", ");
       
   383         off += sprintf(buffer + off, "SAFEOP");
       
   384         first = 0;
       
   385     }
       
   386     if (states & EC_SLAVE_STATE_OP) {
       
   387         if (!first) off += sprintf(buffer + off, ", ");
       
   388         off += sprintf(buffer + off, "OP");
       
   389     }
       
   390     if (states & EC_SLAVE_STATE_ACK_ERR) {
   409     if (states & EC_SLAVE_STATE_ACK_ERR) {
   391         if (!first) off += sprintf(buffer + off, " + ");
   410         if (!first) off += sprintf(buffer + off, " + ");
   392         off += sprintf(buffer + off, "ERROR");
   411         off += sprintf(buffer + off, "ERROR");
   393     }
   412     }
   394 
   413