From 6c37e949e042bd4be8d3c4c00511e980715753c5 Mon Sep 17 00:00:00 2001 From: Albert Hofkamp Date: Thu, 9 Feb 2017 08:51:34 +0100 Subject: [PATCH] Improve tutorial and documentation --- doc/tutorial.txt | 12 +++++++----- soem/ethercatmain.h | 2 +- soem/ethercattype.h | 4 +++- test/linux/red_test/red_test.c | 6 +++--- test/linux/simple_test/simple_test.c | 6 +++--- test/win32/simple_test/simple_test.c | 6 +++--- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/doc/tutorial.txt b/doc/tutorial.txt index 1c7ce15d..2eae8172 100644 --- a/doc/tutorial.txt +++ b/doc/tutorial.txt @@ -38,7 +38,7 @@ have a dedicated NIC selected in the nicdrv.c. It returns >0 if succeeded. \code /* initialise SOEM, bind socket to ifname */ - if (ec_init(ifname)) + if (ec_init(ifname) > 0) \endcode @@ -120,8 +120,10 @@ That is the primary key to detect errors. \code char IOmap[128]; +int usedmem; ... - ec_config_map(&IOmap); + usedmem = ec_config_map(&IOmap); + if (usedmem <= sizeof(IOmap)) ... \endcode @@ -258,7 +260,7 @@ if( inOP && ((wkc < expectedWKC) || ec_group[currentgroup].docheckstate)) ec_slave[slave].state = EC_STATE_OPERATIONAL; ec_writestate(slave); } - else if(ec_slave[slave].state > 0) + else if(ec_slave[slave].state > EC_STATE_NONE) { if (ec_reconfig_slave(slave, EC_TIMEOUTMON)) { @@ -270,7 +272,7 @@ if( inOP && ((wkc < expectedWKC) || ec_group[currentgroup].docheckstate)) { /* re-check state */ ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); - if (!ec_slave[slave].state) + if (ec_slave[slave].state == EC_STATE_NONE) { ec_slave[slave].islost = TRUE; printf("ERROR : slave %d lost\n",slave); @@ -279,7 +281,7 @@ if( inOP && ((wkc < expectedWKC) || ec_group[currentgroup].docheckstate)) } if (ec_slave[slave].islost) { - if(!ec_slave[slave].state) + if(ec_slave[slave].state == EC_STATE_NONE) { if (ec_recover_slave(slave, EC_TIMEOUTMON)) { diff --git a/soem/ethercatmain.h b/soem/ethercatmain.h index 4bb4633c..ad175888 100644 --- a/soem/ethercatmain.h +++ b/soem/ethercatmain.h @@ -259,7 +259,7 @@ typedef struct uint8 group; /** first unused FMMU */ uint8 FMMUunused; - /** TRUE is slave is not responding at all */ + /** Boolean for tracking whether the slave is (not) responding, not used/set by the SOEM library */ boolean islost; /** registered configuration function PO->SO */ int (*PO2SOconfig)(uint16 slave); diff --git a/soem/ethercattype.h b/soem/ethercattype.h index 62037157..a3dee0c6 100644 --- a/soem/ethercattype.h +++ b/soem/ethercattype.h @@ -179,12 +179,14 @@ typedef enum /** Possible EtherCAT slave states */ typedef enum { + /** No valid state. */ + EC_STATE_NONE = 0x00, /** Init state*/ EC_STATE_INIT = 0x01, /** Pre-operational. */ EC_STATE_PRE_OP = 0x02, /** Boot state*/ - EC_STATE_BOOT = 0x03, + EC_STATE_BOOT = 0x03, /** Safe-operational. */ EC_STATE_SAFE_OP = 0x04, /** Operational */ diff --git a/test/linux/red_test/red_test.c b/test/linux/red_test/red_test.c index e5d4bd14..d42e20f3 100644 --- a/test/linux/red_test/red_test.c +++ b/test/linux/red_test/red_test.c @@ -257,7 +257,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr ) ec_slave[slave].state = EC_STATE_OPERATIONAL; ec_writestate(slave); } - else if(ec_slave[slave].state > 0) + else if(ec_slave[slave].state > EC_STATE_NONE) { if (ec_reconfig_slave(slave, EC_TIMEOUTMON)) { @@ -269,7 +269,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr ) { /* re-check state */ ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); - if (!ec_slave[slave].state) + if (ec_slave[slave].state == EC_STATE_NONE) { ec_slave[slave].islost = TRUE; printf("ERROR : slave %d lost\n",slave); @@ -278,7 +278,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr ) } if (ec_slave[slave].islost) { - if(!ec_slave[slave].state) + if(ec_slave[slave].state == EC_STATE_NONE) { if (ec_recover_slave(slave, EC_TIMEOUTMON)) { diff --git a/test/linux/simple_test/simple_test.c b/test/linux/simple_test/simple_test.c index 48216a4b..4cd9c7c4 100644 --- a/test/linux/simple_test/simple_test.c +++ b/test/linux/simple_test/simple_test.c @@ -176,7 +176,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr ) ec_slave[slave].state = EC_STATE_OPERATIONAL; ec_writestate(slave); } - else if(ec_slave[slave].state > 0) + else if(ec_slave[slave].state > EC_STATE_NONE) { if (ec_reconfig_slave(slave, EC_TIMEOUTMON)) { @@ -188,7 +188,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr ) { /* re-check state */ ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); - if (!ec_slave[slave].state) + if (ec_slave[slave].state == EC_STATE_NONE) { ec_slave[slave].islost = TRUE; printf("ERROR : slave %d lost\n",slave); @@ -197,7 +197,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr ) } if (ec_slave[slave].islost) { - if(!ec_slave[slave].state) + if(ec_slave[slave].state == EC_STATE_NONE) { if (ec_recover_slave(slave, EC_TIMEOUTMON)) { diff --git a/test/win32/simple_test/simple_test.c b/test/win32/simple_test/simple_test.c index b23e4742..2e93c683 100644 --- a/test/win32/simple_test/simple_test.c +++ b/test/win32/simple_test/simple_test.c @@ -295,7 +295,7 @@ OSAL_THREAD_FUNC ecatcheck(void *lpParam) ec_slave[slave].state = EC_STATE_OPERATIONAL; ec_writestate(slave); } - else if(ec_slave[slave].state > 0) + else if(ec_slave[slave].state > EC_STATE_NONE) { if (ec_reconfig_slave(slave, EC_TIMEOUTMON)) { @@ -307,7 +307,7 @@ OSAL_THREAD_FUNC ecatcheck(void *lpParam) { /* re-check state */ ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET); - if (!ec_slave[slave].state) + if (ec_slave[slave].state == EC_STATE_NONE) { ec_slave[slave].islost = TRUE; printf("ERROR : slave %d lost\n",slave); @@ -316,7 +316,7 @@ OSAL_THREAD_FUNC ecatcheck(void *lpParam) } if (ec_slave[slave].islost) { - if(!ec_slave[slave].state) + if(ec_slave[slave].state == EC_STATE_NONE) { if (ec_recover_slave(slave, EC_TIMEOUTMON)) {