32 #define NSEC_PER_SEC 1000000000 64 #define MAXSTREAM 200000 67 #define SYNC0TIME 8000 72 struct timeval tv,t1,
t2;
81 pthread_cond_t
cond = PTHREAD_COND_INITIALIZER;
82 pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
99 fp = fopen(fname,
"w");
102 for (i = 0; i <
length; i++)
115 printf(
"Starting E/BOX test\n");
120 printf(
"ec_init on %s succeeded.\n",ifname);
150 (strcmp(
ec_slave[1].name,
"E/BOX") == 0)
153 printf(
"E/BOX found.\n");
163 printf(
"Slave:%d Name:%s Output size:%3dbits Input size:%3dbits State:%2d delay:%d.%d\n",
167 printf(
"Request operational state for all slaves\n");
180 printf(
"Operational state reached for all slaves.\n");
188 for(i = 1; i <= 200; i++)
193 printf(
"PD cycle %5d DCtime %12lld Cnt:%3d Data: %6d %6d %6d %6d %6d %6d %6d %6d \n",
204 printf(
"Not all slaves reached operational state.\n");
209 printf(
"E/BOX not found in slave configuration.\n");
212 printf(
"Request safe operational state for all slaves\n");
224 (strcmp(
ec_slave[1].name,
"E/BOX") == 0))
238 printf(
"No slaves found!\n");
240 printf(
"End E/BOX, close socket\n");
246 printf(
"No socket connection on %s\nExcecute as root\n",ifname);
272 delta = (reftime - 50000) % cycletime;
273 if(delta> (cycletime /2)) { delta= delta - cycletime; }
276 *offsettime = -(delta / 100) - (
integral /20);
290 rc = pthread_mutex_lock(&
mutex);
294 ts.tv_sec = tp.tv_sec;
295 ht = (tp.tv_usec / 1000) + 1;
296 ts.tv_nsec = ht * 1000000;
297 cycletime = *(
int*)ptr * 1000;
305 rc = pthread_cond_timedwait(&
cond, &
mutex, &ts);
321 if(in_EBOX->
counter > (pcounter + 1))
323 for(i = 0 ; i < 50 ; i++)
331 for(i = 0 ; i < 50 ; i++)
346 int main(
int argc,
char *argv[])
350 struct sched_param param;
351 int policy = SCHED_OTHER;
353 printf(
"SOEM (Simple Open EtherCAT Master)\nE/BOX test\n");
357 schedp.sched_priority = 30;
358 sched_setscheduler(0, SCHED_FIFO, &
schedp);
370 ctime = atoi(argv[2]);
375 memset(¶m, 0,
sizeof(param));
377 param.sched_priority = 40;
378 iret1 = pthread_setschedparam(
thread1, policy, ¶m);
385 printf(
"Usage: ebox ifname [cycletime]\nifname = eth0 for example\ncycletime in us\n");
388 schedp.sched_priority = 0;
389 sched_setscheduler(0, SCHED_OTHER, &
schedp);
391 printf(
"End program\n");
Headerfile for ethercatdc.c.
int ec_send_processdata(void)
PACKED_END ec_slavet ec_slave[EC_MAXSLAVE]
void ecatthread(void *ptr)
int ec_receive_processdata(int timeout)
General typedefs and defines for EtherCAT.
Headerfile for ethercatcoe.c.
int ec_config_map(void *pIOmap)
void ec_sync(int64 reftime, int64 cycletime, int64 *offsettime)
void eboxtest(char *ifname)
int ec_init(char *ifname)
void ec_dcsync0(uint16 slave, boolean act, uint32 CyclTime, uint32 CyclShift)
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)
Headerfile for ethercatbase.c.
boolean ec_configdc(void)
int main(int argc, char *argv[])
Headerfile for ethercatmain.c.
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)
Headerfile for ethercatconfig.c.
int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout)
int ec_config_init(uint8 usetable)