Skip to content

Commit

Permalink
Minor cleanup in the test applications
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Heden committed Jul 9, 2015
1 parent 77da52b commit d6dd341
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
6 changes: 0 additions & 6 deletions TODO.tasks

This file was deleted.

2 changes: 1 addition & 1 deletion osal/osal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef double float64;
typedef struct
{
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;

typedef struct osal_timer
Expand Down
21 changes: 9 additions & 12 deletions test/linux/eepromtool/eepromtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>

#include "ethercattype.h"
#include "nicdrv.h"
Expand Down Expand Up @@ -51,7 +48,7 @@ uint16 ow;
int os;
int slave;
int alias;
struct timeval tstart,tend, tdif;
ec_timet tstart,tend, tdif;
int wkc;
int mode;
char sline[MAXSLENGTH];
Expand Down Expand Up @@ -341,7 +338,7 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)
{
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

wbuf = (uint16 *)&ebuf[0];
Expand All @@ -366,12 +363,12 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)
if (esize > MINBUF)
eeprom_read(slave, MINBUF, esize - MINBUF); // read reminder

rc = gettimeofday(&tend, NULL);
timersub(&tend, &tstart, &tdif);
tend = osal_current_time();
osal_time_diff(&tstart, &tend, &tdif);
if (mode == MODE_READINTEL) output_intelhex(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))
{
Expand All @@ -390,12 +387,12 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)

printf("Busy");
fflush(stdout);
rc = gettimeofday(&tstart, NULL);
tstart = osal_current_time();
eeprom_write(slave, estart, esize);
rc = gettimeofday(&tend, NULL);
timersub(&tend, &tstart, &tdif);
tend = osal_current_time();
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
printf("Error reading file, abort.\n");
Expand Down
7 changes: 2 additions & 5 deletions test/linux/simple_test/simple_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>

#include "ethercattype.h"
#include "nicdrv.h"
Expand Down Expand Up @@ -116,7 +113,7 @@ void simpletest(char *ifname)
printf(" T:%lld\r",ec_DCtime);
needlf = TRUE;
}
usleep(5000);
osal_usleep(5000);

}
inOP = FALSE;
Expand Down Expand Up @@ -225,7 +222,7 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr )
if(!ec_group[currentgroup].docheckstate)
printf("OK : all slaves resumed OPERATIONAL.\n");
}
usleep(10000);
osal_usleep(10000);
}
}

Expand Down
38 changes: 27 additions & 11 deletions test/linux/slaveinfo/slaveinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,16 @@ int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset)
PDO->BitSize[PDO->nPDO] += bitlen;
a += 2;

str_name[0] = 0;
if(obj_name)
ec_siistring(str_name, slave, obj_name);
/* skip entry if filler (0x0000:0x00) */
if(obj_idx || obj_subidx)
{
str_name[0] = 0;
if(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(" %-12s %s\n", dtype2string(obj_datatype), str_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(" %-12s %s\n", dtype2string(obj_datatype), str_name);
}
bitoffset += bitlen;
totalsize += bitlen;
}
Expand Down Expand Up @@ -619,22 +623,34 @@ void slaveinfo(char *ifname)
}
}

char ifbuf[1024];

int main(int argc, char *argv[])
{
ec_adaptert * adapter = NULL;
printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n");

if (argc > 1)
{
{
if ((argc > 2) && (strncmp(argv[2], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE;
if ((argc > 2) && (strncmp(argv[2], "-map", sizeof("-map")) == 0)) printMAP = TRUE;
/* start slaveinfo */
slaveinfo(argv[1]);
strcpy(ifbuf, argv[1]);
slaveinfo(ifbuf);
}
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");
return (0);
}

0 comments on commit d6dd341

Please sign in to comment.