Minor cleanup in the test applications

This commit is contained in:
Mikael Heden 2015-07-09 17:58:54 +02:00
parent 77da52b89d
commit d6dd3411d7
5 changed files with 39 additions and 35 deletions

View File

@ -1,6 +0,0 @@
<?xml version="1.0"?>
<gtodo>
<category title="Personal" place="0"/>
<category title="Business" place="1"/>
<category title="Unfiled" place="2"/>
</gtodo>

View File

@ -42,7 +42,7 @@ typedef double float64;
typedef struct typedef struct
{ {
uint32 sec; /*< Seconds elapsed since the Epoch (Jan 1, 1970) */ uint32 sec; /*< Seconds elapsed since the Epoch (Jan 1, 1970) */
int32 usec; /*< Microseconds elapsed since last second boundary */ uint32 usec; /*< Microseconds elapsed since last second boundary */
} ec_timet; } ec_timet;
typedef struct osal_timer typedef struct osal_timer

View File

@ -17,9 +17,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#include "ethercattype.h" #include "ethercattype.h"
#include "nicdrv.h" #include "nicdrv.h"
@ -51,7 +48,7 @@ uint16 ow;
int os; int os;
int slave; int slave;
int alias; int alias;
struct timeval tstart,tend, tdif; ec_timet tstart,tend, tdif;
int wkc; int wkc;
int mode; int mode;
char sline[MAXSLENGTH]; char sline[MAXSLENGTH];
@ -341,7 +338,7 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)
{ {
if ((mode == MODE_INFO) || (mode == MODE_READBIN) || (mode == MODE_READINTEL)) if ((mode == MODE_INFO) || (mode == MODE_READBIN) || (mode == MODE_READINTEL))
{ {
rc = gettimeofday(&tstart, NULL); tstart = osal_current_time();
eeprom_read(slave, 0x0000, MINBUF); // read first 128 bytes eeprom_read(slave, 0x0000, MINBUF); // read first 128 bytes
wbuf = (uint16 *)&ebuf[0]; wbuf = (uint16 *)&ebuf[0];
@ -366,12 +363,12 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)
if (esize > MINBUF) if (esize > MINBUF)
eeprom_read(slave, MINBUF, esize - MINBUF); // read reminder eeprom_read(slave, MINBUF, esize - MINBUF); // read reminder
rc = gettimeofday(&tend, NULL); tend = osal_current_time();
timersub(&tend, &tstart, &tdif); osal_time_diff(&tstart, &tend, &tdif);
if (mode == MODE_READINTEL) output_intelhex(fname, esize); if (mode == MODE_READINTEL) output_intelhex(fname, esize);
if (mode == MODE_READBIN) output_bin(fname, esize); if (mode == MODE_READBIN) output_bin(fname, esize);
printf("\nTotal EEPROM read time :%ldms\n", (tdif.tv_usec+(tdif.tv_sec*1000000L)) / 1000); printf("\nTotal EEPROM read time :%ldms\n", (tdif.usec+(tdif.sec*1000000L)) / 1000);
} }
if ((mode == MODE_WRITEBIN) || (mode == MODE_WRITEINTEL)) if ((mode == MODE_WRITEBIN) || (mode == MODE_WRITEINTEL))
{ {
@ -390,12 +387,12 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)
printf("Busy"); printf("Busy");
fflush(stdout); fflush(stdout);
rc = gettimeofday(&tstart, NULL); tstart = osal_current_time();
eeprom_write(slave, estart, esize); eeprom_write(slave, estart, esize);
rc = gettimeofday(&tend, NULL); tend = osal_current_time();
timersub(&tend, &tstart, &tdif); osal_time_diff(&tstart, &tend, &tdif);
printf("\nTotal EEPROM write time :%ldms\n", (tdif.tv_usec+(tdif.tv_sec*1000000L)) / 1000); printf("\nTotal EEPROM write time :%ldms\n", (tdif.usec+(tdif.sec*1000000L)) / 1000);
} }
else else
printf("Error reading file, abort.\n"); printf("Error reading file, abort.\n");

View File

@ -11,9 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
#include "ethercattype.h" #include "ethercattype.h"
#include "nicdrv.h" #include "nicdrv.h"
@ -116,7 +113,7 @@ void simpletest(char *ifname)
printf(" T:%lld\r",ec_DCtime); printf(" T:%lld\r",ec_DCtime);
needlf = TRUE; needlf = TRUE;
} }
usleep(5000); osal_usleep(5000);
} }
inOP = FALSE; inOP = FALSE;
@ -225,7 +222,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr )
if(!ec_group[currentgroup].docheckstate) if(!ec_group[currentgroup].docheckstate)
printf("OK : all slaves resumed OPERATIONAL.\n"); printf("OK : all slaves resumed OPERATIONAL.\n");
} }
usleep(10000); osal_usleep(10000);
} }
} }

View File

@ -420,12 +420,16 @@ int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset)
PDO->BitSize[PDO->nPDO] += bitlen; PDO->BitSize[PDO->nPDO] += bitlen;
a += 2; a += 2;
/* skip entry if filler (0x0000:0x00) */
if(obj_idx || obj_subidx)
{
str_name[0] = 0; str_name[0] = 0;
if(obj_name) if(obj_name)
ec_siistring(str_name, slave, obj_name); ec_siistring(str_name, slave, obj_name);
printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen); printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen);
printf(" %-12s %s\n", dtype2string(obj_datatype), str_name); printf(" %-12s %s\n", dtype2string(obj_datatype), str_name);
}
bitoffset += bitlen; bitoffset += bitlen;
totalsize += bitlen; totalsize += bitlen;
} }
@ -619,8 +623,11 @@ void slaveinfo(char *ifname)
} }
} }
char ifbuf[1024];
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n"); printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n");
if (argc > 1) if (argc > 1)
@ -628,11 +635,20 @@ int main(int argc, char *argv[])
if ((argc > 2) && (strncmp(argv[2], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE; if ((argc > 2) && (strncmp(argv[2], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE;
if ((argc > 2) && (strncmp(argv[2], "-map", sizeof("-map")) == 0)) printMAP = TRUE; if ((argc > 2) && (strncmp(argv[2], "-map", sizeof("-map")) == 0)) printMAP = TRUE;
/* start slaveinfo */ /* start slaveinfo */
slaveinfo(argv[1]); strcpy(ifbuf, argv[1]);
slaveinfo(ifbuf);
} }
else else
{ {
printf("Usage: slaveinfo ifname [options]\nifname = eth0 for example\nOptions :\n -sdo : print SDO info\n -map : print mapping\n"); printf("Usage: slaveinfo ifname [options]\nifname = eth0 for example\nOptions :\n -sdo : print SDO info\n -map : print mapping\n");
printf ("Available adapters\n");
adapter = ec_find_adapters ();
while (adapter != NULL)
{
printf ("Description : %s, Device to use for wpcap: %s\n", adapter->desc,adapter->name);
adapter = adapter->next;
}
} }
printf("End program\n"); printf("End program\n");