26 #define NSEC_PER_SEC 1000000000 31 struct timeval tv, t1,
t2;
39 pthread_cond_t
cond = PTHREAD_COND_INITIALIZER;
40 pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
46 int cnt, i,
j, oloop, iloop;
48 printf(
"Starting Redundant test\n");
53 printf(
"ec_init on %s succeeded.\n",ifname);
68 printf(
"Slave:%d Name:%s Output size:%3dbits Input size:%3dbits State:%2d delay:%d.%d\n",
71 printf(
" Out:%8.8x,%4d In:%8.8x,%4d\n",
79 printf(
"Request operational state for all slaves\n");
86 if ((oloop == 0) && (
ec_slave[0].Obits > 0)) oloop = 1;
87 if (oloop > 8) oloop = 8;
89 if ((iloop == 0) && (
ec_slave[0].Ibits > 0)) iloop = 1;
90 if (iloop > 8) iloop = 8;
93 printf(
"Operational state reached for all slaves.\n");
96 for(i = 1; i <= 5000; i++)
99 for(j = 0 ; j < oloop; j++)
101 printf(
" %2.2x", *(
ec_slave[0].outputs + j));
104 for(j = 0 ; j < iloop; j++)
106 printf(
" %2.2x", *(
ec_slave[0].inputs + j));
115 printf(
"Not all slaves reached operational state.\n");
117 printf(
"Request safe operational state for all slaves\n");
124 printf(
"No slaves found!\n");
126 printf(
"End redundant test, close socket\n");
132 printf(
"No socket connection on %s\nExcecute as root\n",ifname);
159 delta = (reftime - 50000) % cycletime;
160 if(delta> (cycletime / 2)) { delta= delta - cycletime; }
161 if(delta>0){ integral++; }
162 if(delta<0){ integral--; }
163 *offsettime = -(delta / 100) - (integral / 20);
175 rc = pthread_mutex_lock(&
mutex);
179 ts.tv_sec = tp.tv_sec;
180 ht = (tp.tv_usec / 1000) + 1;
181 ts.tv_nsec = ht * 1000000;
182 cycletime = *(
int*)ptr * 1000;
190 rc = pthread_cond_timedwait(&
cond, &
mutex, &ts);
212 int main(
int argc,
char *argv[])
216 struct sched_param param;
217 int policy = SCHED_OTHER;
219 printf(
"SOEM (Simple Open EtherCAT Master)\nRedundancy test\n");
223 schedp.sched_priority = 30;
224 sched_setscheduler(0, SCHED_FIFO, &
schedp);
235 ctime = atoi(argv[3]);
238 memset(¶m, 0,
sizeof(param));
240 param.sched_priority = 40;
241 iret1 = pthread_setschedparam(
thread1, policy, ¶m);
248 printf(
"Usage: red_test ifname1 ifname2 cycletime\nifname = eth0 for example\ncycletime in us\n");
251 schedp.sched_priority = 0;
252 sched_setscheduler(0, SCHED_OTHER, &
schedp);
254 printf(
"End program\n");
void ec_sync(int64 reftime, int64 cycletime, int64 *offsettime)
int ec_send_processdata(void)
Headerfile for all ethercat headers.
int ec_receive_processdata(int timeout)
int main(int argc, char *argv[])
int ec_init_redundant(const char *ifname, char *if2name)
struct sched_param schedp
int ec_writestate(uint16 slave)
int ec_config(uint8 usetable, void *pIOmap)
boolean ec_configdc(void)
void add_timespec(struct timespec *ts, int64 addtime)
void ecatthread(void *ptr)
int gettimeofday(struct timeval *tp, void *tzp)
uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)
void redtest(char *ifname, char *ifname2)