32 #define NSEC_PER_SEC 1000000000 37 struct timeval tv, t1,
t2;
45 pthread_cond_t
cond = PTHREAD_COND_INITIALIZER;
46 pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
52 int cnt, i,
j, oloop, iloop;
54 printf(
"Starting Redundant test\n");
59 printf(
"ec_init on %s succeeded.\n",ifname);
74 printf(
"Slave:%d Name:%s Output size:%3dbits Input size:%3dbits State:%2d delay:%d.%d\n",
77 printf(
" Out:%8.8x,%4d In:%8.8x,%4d\n",
85 printf(
"Request operational state for all slaves\n");
92 if ((oloop == 0) && (
ec_slave[0].Obits > 0)) oloop = 1;
93 if (oloop > 8) oloop = 8;
95 if ((iloop == 0) && (
ec_slave[0].Ibits > 0)) iloop = 1;
96 if (iloop > 8) iloop = 8;
99 printf(
"Operational state reached for all slaves.\n");
102 for(i = 1; i <= 5000; i++)
105 for(j = 0 ; j < oloop; j++)
107 printf(
" %2.2x", *(
ec_slave[0].outputs + j));
110 for(j = 0 ; j < iloop; j++)
112 printf(
" %2.2x", *(
ec_slave[0].inputs + j));
121 printf(
"Not all slaves reached operational state.\n");
123 printf(
"Request safe operational state for all slaves\n");
130 printf(
"No slaves found!\n");
132 printf(
"End redundant test, close socket\n");
138 printf(
"No socket connection on %s\nExcecute as root\n",ifname);
165 delta = (reftime - 50000) % cycletime;
166 if(delta> (cycletime / 2)) { delta= delta - cycletime; }
167 if(delta>0){ integral++; }
168 if(delta<0){ integral--; }
169 *offsettime = -(delta / 100) - (integral / 20);
181 rc = pthread_mutex_lock(&
mutex);
185 ts.tv_sec = tp.tv_sec;
186 ht = (tp.tv_usec / 1000) + 1;
187 ts.tv_nsec = ht * 1000000;
188 cycletime = *(
int*)ptr * 1000;
196 rc = pthread_cond_timedwait(&
cond, &
mutex, &ts);
218 int main(
int argc,
char *argv[])
222 struct sched_param param;
223 int policy = SCHED_OTHER;
225 printf(
"SOEM (Simple Open EtherCAT Master)\nRedundancy test\n");
229 schedp.sched_priority = 30;
230 sched_setscheduler(0, SCHED_FIFO, &
schedp);
241 ctime = atoi(argv[3]);
244 memset(¶m, 0,
sizeof(param));
246 param.sched_priority = 40;
247 iret1 = pthread_setschedparam(
thread1, policy, ¶m);
254 printf(
"Usage: red_test ifname1 ifname2 cycletime\nifname = eth0 for example\ncycletime in us\n");
257 schedp.sched_priority = 0;
258 sched_setscheduler(0, SCHED_OTHER, &
schedp);
260 printf(
"End program\n");
void ec_sync(int64 reftime, int64 cycletime, int64 *offsettime)
Headerfile for ethercatdc.c.
int ec_send_processdata(void)
PACKED_END ec_slavet ec_slave[EC_MAXSLAVE]
int ec_init_redundant(char *ifname, char *if2name)
int ec_receive_processdata(int timeout)
General typedefs and defines for EtherCAT.
Headerfile for ethercatcoe.c.
int main(int argc, char *argv[])
struct sched_param schedp
int ec_writestate(uint16 slave)
Headerfile for ethercatbase.c.
int ec_config(uint8 usetable, void *pIOmap)
boolean ec_configdc(void)
Headerfile for ethercatmain.c.
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)
Headerfile for ethercatconfig.c.
void redtest(char *ifname, char *ifname2)