From 28927aab87d70dc428dd8a6121bc6de3af568c3a Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 18 Oct 2016 00:35:54 +0200 Subject: [PATCH] minor_improvement/ ecx_statecheck() improved ecx_statecheck() when called with the first argument set to 0 automatically updates the state of all the slaves in the slavelist structure when possible, --- soem/ethercatmain.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/soem/ethercatmain.c b/soem/ethercatmain.c index f270dba..5d81c36 100644 --- a/soem/ethercatmain.c +++ b/soem/ethercatmain.c @@ -849,9 +849,39 @@ uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int { if (slave < 1) { + uint16 bitWiseState; + uint16 slaveIndex; + rval = 0; ecx_BRD(context->port, 0, ECT_REG_ALSTAT, sizeof(rval), &rval , EC_TIMEOUTRET); rval = etohs(rval); + bitWiseState = (rval & 0x0f); + + if((rval & 0xf0) == 0) + { + /* No slave has toggled the error flag so the alstatuscode (even if different from 0) should be ignored */ + for(slaveIndex = 0; slaveIndex < *(context->slavecount); slaveIndex++) + { + ec_slave[slaveIndex].ALstatuscode = 0x0000; + } + } + + switch(bitWiseState) + { + case EC_STATE_INIT: + case EC_STATE_PRE_OP: + case EC_STATE_BOOT: + case EC_STATE_SAFE_OP: + case EC_STATE_OPERATIONAL: + /* All the slaves have reached the same state so we can update the state of every slave */ + for(slaveIndex = 0; slaveIndex < *(context->slavecount); slaveIndex++) + { + ec_slave[slaveIndex].state = bitWiseState; + } + break; + default: + break; + } } else {