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