26 #define NSEC_PER_SEC 1000000000 27 #define EC_TIMEOUTMON 500 32 struct timeval tv, t1,
t2;
50 int cnt, i,
j, oloop, iloop;
52 printf(
"Starting Redundant test\n");
58 printf(
"ec_init on %s succeeded.\n",ifname);
73 printf(
"Slave:%d Name:%s Output size:%3dbits Input size:%3dbits State:%2d delay:%d.%d\n",
76 printf(
" Out:%8.8x,%4d In:%8.8x,%4d\n",
87 printf(
"Request operational state for all slaves\n");
96 if ((oloop == 0) && (
ec_slave[0].Obits > 0)) oloop = 1;
97 if (oloop > 8) oloop = 8;
99 if ((iloop == 0) && (
ec_slave[0].Ibits > 0)) iloop = 1;
100 if (iloop > 8) iloop = 8;
103 printf(
"Operational state reached for all slaves.\n");
106 for(i = 1; i <= 5000; i++)
108 printf(
"Processdata cycle %5d , Wck %3d, DCtime %12lld, dt %12lld, O:",
110 for(j = 0 ; j < oloop; j++)
112 printf(
" %2.2x", *(
ec_slave[0].outputs + j));
115 for(j = 0 ; j < iloop; j++)
117 printf(
" %2.2x", *(
ec_slave[0].inputs + j));
128 printf(
"Not all slaves reached operational state.\n");
134 printf(
"Slave %d State=0x%2.2x StatusCode=0x%4.4x : %s\n",
139 printf(
"Request safe operational state for all slaves\n");
146 printf(
"No slaves found!\n");
148 printf(
"End redundant test, close socket\n");
154 printf(
"No socket connection on %s\nExcecute as root\n",ifname);
181 delta = (reftime - 50000) % cycletime;
182 if(delta> (cycletime / 2)) { delta= delta - cycletime; }
183 if(delta>0){ integral++; }
184 if(delta<0){ integral--; }
185 *offsettime = -(delta / 100) - (integral / 20);
192 struct timespec ts, tleft;
196 clock_gettime(CLOCK_MONOTONIC, &ts);
197 ht = (ts.tv_nsec / 1000000) + 1;
198 ts.tv_nsec = ht * 1000000;
199 cycletime = *(
int*)ptr * 1000;
208 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, &tleft);
250 printf(
"ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slave);
256 printf(
"WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slave);
265 printf(
"MESSAGE : slave %d reconfigured\n",slave);
275 printf(
"ERROR : slave %d lost\n",slave);
286 printf(
"MESSAGE : slave %d recovered\n",slave);
292 printf(
"MESSAGE : slave %d found\n",slave);
297 printf(
"OK : all slaves resumed OPERATIONAL.\n");
303 #define stack64k (64 * 1024) 305 int main(
int argc,
char *argv[])
309 printf(
"SOEM (Simple Open EtherCAT Master)\nRedundancy test\n");
314 ctime = atoi(argv[3]);
327 printf(
"Usage: red_test ifname1 ifname2 cycletime\nifname = eth0 for example\ncycletime in us\n");
330 printf(
"End program\n");
int ec_reconfig_slave(uint16 slave, int timeout)
char * ec_ALstatuscode2string(uint16 ALstatuscode)
int ec_send_processdata(void)
OSAL_THREAD_FUNC_RT ecatthread(void *ptr)
void redtest(char *ifname, char *ifname2)
int ec_recover_slave(uint16 slave, int timeout)
Headerfile for all ethercat headers.
int ec_receive_processdata(int timeout)
int ec_init(const char *ifname)
OSAL_THREAD_FUNC ecatcheck(void *ptr)
int osal_usleep(uint32 usec)
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
struct sched_param schedp
void ec_sync(int64 reftime, int64 cycletime, int64 *offsettime)
int main(int argc, char *argv[])
void add_timespec(struct timespec *ts, int64 addtime)
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
int ec_writestate(uint16 slave)
int ec_config(uint8 usetable, void *pIOmap)
boolean ec_configdc(void)
#define OSAL_THREAD_FUNC_RT
uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)