26 #define NSEC_PER_SEC 1000000000 58 #define MAXSTREAM 200000 61 #define SYNC0TIME 8000 66 struct timeval tv,t1,
t2;
75 pthread_cond_t
cond = PTHREAD_COND_INITIALIZER;
76 pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
93 fp = fopen(fname,
"w");
96 for (i = 0; i <
length; i++)
109 printf(
"Starting E/BOX test\n");
114 printf(
"ec_init on %s succeeded.\n",ifname);
144 (strcmp(
ec_slave[1].name,
"E/BOX") == 0)
147 printf(
"E/BOX found.\n");
157 printf(
"Slave:%d Name:%s Output size:%3dbits Input size:%3dbits State:%2d delay:%d.%d\n",
161 printf(
"Request operational state for all slaves\n");
174 printf(
"Operational state reached for all slaves.\n");
182 for(i = 1; i <= 200; i++)
187 printf(
"PD cycle %5d DCtime %12lld Cnt:%3d Data: %6d %6d %6d %6d %6d %6d %6d %6d \n",
198 printf(
"Not all slaves reached operational state.\n");
203 printf(
"E/BOX not found in slave configuration.\n");
206 printf(
"Request safe operational state for all slaves\n");
218 (strcmp(
ec_slave[1].name,
"E/BOX") == 0))
232 printf(
"No slaves found!\n");
234 printf(
"End E/BOX, close socket\n");
240 printf(
"No socket connection on %s\nExcecute as root\n",ifname);
266 delta = (reftime - 50000) % cycletime;
267 if(delta> (cycletime /2)) { delta= delta - cycletime; }
270 *offsettime = -(delta / 100) - (
integral /20);
284 rc = pthread_mutex_lock(&
mutex);
288 ts.tv_sec = tp.tv_sec;
289 ht = (tp.tv_usec / 1000) + 1;
290 ts.tv_nsec = ht * 1000000;
291 cycletime = *(
int*)ptr * 1000;
299 rc = pthread_cond_timedwait(&
cond, &
mutex, &ts);
315 if(in_EBOX->
counter > (pcounter + 1))
317 for(i = 0 ; i < 50 ; i++)
325 for(i = 0 ; i < 50 ; i++)
340 int main(
int argc,
char *argv[])
344 struct sched_param param;
345 int policy = SCHED_OTHER;
347 printf(
"SOEM (Simple Open EtherCAT Master)\nE/BOX test\n");
351 schedp.sched_priority = 30;
352 sched_setscheduler(0, SCHED_FIFO, &
schedp);
364 ctime = atoi(argv[2]);
369 memset(¶m, 0,
sizeof(param));
371 param.sched_priority = 40;
372 iret1 = pthread_setschedparam(
thread1, policy, ¶m);
379 printf(
"Usage: ebox ifname [cycletime]\nifname = eth0 for example\ncycletime in us\n");
382 schedp.sched_priority = 0;
383 sched_setscheduler(0, SCHED_OTHER, &
schedp);
385 printf(
"End program\n");
int ec_send_processdata(void)
void ec_dcsync0(uint16 slave, boolean act, uint32 CyclTime, int32 CyclShift)
void ecatthread(void *ptr)
Headerfile for all ethercat headers.
int ec_receive_processdata(int timeout)
int ec_init(const char *ifname)
int ec_config_map(void *pIOmap)
void ec_sync(int64 reftime, int64 cycletime, int64 *offsettime)
void eboxtest(char *ifname)
struct PACKED in_EBOX_streamt
struct sched_param schedp
in_EBOX_streamt * in_EBOX
int output_cvs(char *fname, int length)
struct PACKED out_EBOX_streamt
int ec_writestate(uint16 slave)
boolean ec_configdc(void)
int main(int argc, char *argv[])
out_EBOX_streamt * out_EBOX
int gettimeofday(struct timeval *tp, void *tzp)
void add_timespec(struct timespec *ts, int64 addtime)
char name[EC_SOE_MAXNAME]
uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)
int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout)
int ec_config_init(uint8 usetable)