33 #define NSEC_PER_SEC 1000000000 34 #define EC_TIMEOUTMON 500 39 struct timeval tv, t1,
t2;
47 pthread_cond_t
cond = PTHREAD_COND_INITIALIZER;
48 pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
59 int cnt, i,
j, oloop, iloop;
61 printf(
"Starting Redundant test\n");
66 printf(
"ec_init on %s succeeded.\n",ifname);
81 printf(
"Slave:%d Name:%s Output size:%3dbits Input size:%3dbits State:%2d delay:%d.%d\n",
84 printf(
" Out:%8.8x,%4d In:%8.8x,%4d\n",
95 printf(
"Request operational state for all slaves\n");
104 if ((oloop == 0) && (
ec_slave[0].Obits > 0)) oloop = 1;
105 if (oloop > 8) oloop = 8;
107 if ((iloop == 0) && (
ec_slave[0].Ibits > 0)) iloop = 1;
108 if (iloop > 8) iloop = 8;
111 printf(
"Operational state reached for all slaves.\n");
114 for(i = 1; i <= 5000; i++)
116 printf(
"Processdata cycle %5d , Wck %3d, DCtime %12lld, dt %12lld, O:",
118 for(j = 0 ; j < oloop; j++)
120 printf(
" %2.2x", *(
ec_slave[0].outputs + j));
123 for(j = 0 ; j < iloop; j++)
125 printf(
" %2.2x", *(
ec_slave[0].inputs + j));
136 printf(
"Not all slaves reached operational state.\n");
142 printf(
"Slave %d State=0x%2.2x StatusCode=0x%4.4x : %s\n",
147 printf(
"Request safe operational state for all slaves\n");
154 printf(
"No slaves found!\n");
156 printf(
"End redundant test, close socket\n");
162 printf(
"No socket connection on %s\nExcecute as root\n",ifname);
189 delta = (reftime - 50000) % cycletime;
190 if(delta> (cycletime / 2)) { delta= delta - cycletime; }
191 if(delta>0){ integral++; }
192 if(delta<0){ integral--; }
193 *offsettime = -(delta / 100) - (integral / 20);
200 struct timespec ts, tleft;
206 rc = pthread_mutex_lock(&
mutex);
207 rc = clock_gettime(CLOCK_MONOTONIC, &ts);
208 ht = (ts.tv_nsec / 1000000) + 1;
209 ts.tv_nsec = ht * 1000000;
210 cycletime = *(
int*)ptr * 1000;
219 rc = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, &tleft);
261 printf(
"ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slave);
267 printf(
"WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slave);
276 printf(
"MESSAGE : slave %d reconfigured\n",slave);
286 printf(
"ERROR : slave %d lost\n",slave);
297 printf(
"MESSAGE : slave %d recovered\n",slave);
303 printf(
"MESSAGE : slave %d found\n",slave);
308 printf(
"OK : all slaves resumed OPERATIONAL.\n");
314 int main(
int argc,
char *argv[])
318 struct sched_param param;
319 int policy = SCHED_OTHER;
321 printf(
"SOEM (Simple Open EtherCAT Master)\nRedundancy test\n");
325 schedp.sched_priority = 30;
326 sched_setscheduler(0, SCHED_FIFO, &
schedp);
331 ctime = atoi(argv[3]);
335 memset(¶m, 0,
sizeof(param));
337 param.sched_priority = 40;
338 iret1 = pthread_setschedparam(
thread1, policy, ¶m);
341 iret2 = pthread_create( &
thread2, NULL, (
void *) &
ecatcheck, (
void*) &ctime);
348 printf(
"Usage: red_test ifname1 ifname2 cycletime\nifname = eth0 for example\ncycletime in us\n");
351 schedp.sched_priority = 0;
352 sched_setscheduler(0, SCHED_OTHER, &
schedp);
354 printf(
"End program\n");
ec_groupt ec_group[EC_MAXGROUP]
int ec_reconfig_slave(uint16 slave, int timeout)
char * ec_ALstatuscode2string(uint16 ALstatuscode)
Headerfile for ethercatdc.c.
int ec_send_processdata(void)
PACKED_END ec_slavet ec_slave[EC_MAXSLAVE]
void redtest(char *ifname, char *ifname2)
int ec_init_redundant(char *ifname, char *if2name)
int ec_recover_slave(uint16 slave, int timeout)
int ec_receive_processdata(int timeout)
void ecatcheck(void *ptr)
void ecatthread(void *ptr)
General typedefs and defines for EtherCAT.
Headerfile for ethercatcoe.c.
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 ec_writestate(uint16 slave)
Headerfile for ethercatbase.c.
int ec_config(uint8 usetable, void *pIOmap)
boolean ec_configdc(void)
Headerfile for ethercatmain.c.
int osal_usleep(uint32 usec)
uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)
Headerfile for ethercatconfig.c.
Headerfile for ethercatprint.c.