Move commonly used programs to utilities folder
The slaveinfo, simple_test and eepromtool programs are commonly used for debugging and provisioning. This patch moves them to an OS-independent subdirectory and builds them as part of the soem library. The patch also introduces the OSAL_MAIN define to allow platforms to provide their own implementation of main. Finally it adds the programs as shell commands for rt-kernel.pull/343/head
parent
89f3b3c593
commit
080e399ae1
|
@ -11,8 +11,8 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|||
CACHE PATH "Default install path" FORCE)
|
||||
endif()
|
||||
|
||||
# Let platforms disable test programs
|
||||
set(BUILD_TESTS TRUE)
|
||||
# Let platforms disable building of executables
|
||||
set(BUILD_EXECUTABLES TRUE)
|
||||
|
||||
# Always use standard .o suffix
|
||||
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
|
||||
|
@ -40,12 +40,22 @@ add_library(soem
|
|||
soem/ethercatsoe.c
|
||||
soem/ethercatsoe.h
|
||||
soem/ethercattype.h
|
||||
util/slaveinfo/slaveinfo.c
|
||||
util/slaveinfo/slaveinfo.h
|
||||
util/simple_test/simple_test.c
|
||||
util/simple_test/simple_test.h
|
||||
util/eepromtool/eepromtool.c
|
||||
util/eepromtool/eepromtool.h
|
||||
)
|
||||
|
||||
target_include_directories(soem PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/soem>
|
||||
$<INSTALL_INTERFACE:include/soem>
|
||||
)
|
||||
target_include_directories(soem PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/util>
|
||||
$<INSTALL_INTERFACE:include/soem>
|
||||
)
|
||||
target_include_directories(soem PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/osal>
|
||||
$<INSTALL_INTERFACE:include/soem>
|
||||
|
@ -77,12 +87,15 @@ install(FILES
|
|||
soem/ethercatprint.h
|
||||
soem/ethercatsoe.h
|
||||
soem/ethercattype.h
|
||||
util/slaveinfo/slaveinfo.h
|
||||
util/simple_test/simple_test.h
|
||||
util/eepromtool/eepromtool.h
|
||||
osal/osal.h
|
||||
DESTINATION include/soem
|
||||
)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(test/linux/slaveinfo)
|
||||
add_subdirectory(test/linux/eepromtool)
|
||||
add_subdirectory(test/linux/simple_test)
|
||||
if(BUILD_EXECUTABLES)
|
||||
add_subdirectory(util/slaveinfo)
|
||||
add_subdirectory(util/eepromtool)
|
||||
add_subdirectory(util/simple_test)
|
||||
endif()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
target_sources(soem PRIVATE
|
||||
osal/rtk/osal.c
|
||||
osal/rtk/osal_defs.h
|
||||
osal/rtk/soem_cmds.c
|
||||
oshw/rtk/oshw.c
|
||||
oshw/rtk/oshw.h
|
||||
oshw/rtk/nicdrv.c
|
||||
|
@ -35,5 +36,6 @@ add_definitions(
|
|||
|
||||
install(FILES
|
||||
osal/rtk/osal_defs.h
|
||||
osal/rtk/soem_cmds.h
|
||||
DESTINATION include/soem
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Licensed under the GNU General Public License version 2 with exceptions. See
|
||||
# LICENSE file in the project root for full license information
|
||||
|
||||
set(BUILD_TESTS FALSE)
|
||||
set(BUILD_EXECUTABLES FALSE)
|
||||
|
||||
target_sources(soem PRIVATE
|
||||
osal/rtems/osal.c
|
||||
|
|
|
@ -52,6 +52,10 @@ void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff);
|
|||
int osal_thread_create(void *thandle, int stacksize, void *func, void *param);
|
||||
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param);
|
||||
|
||||
#ifndef OSAL_MAIN
|
||||
#define OSAL_MAIN main
|
||||
#endif /* OSAL_MAIN */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Licensed under the GNU General Public License version 2 with exceptions. See
|
||||
* LICENSE file in the project root for full license information
|
||||
*/
|
||||
|
||||
#include "slaveinfo/slaveinfo.h"
|
||||
#include "simple_test/simple_test.h"
|
||||
#include "eepromtool/eepromtool.h"
|
||||
|
||||
#include "soem_cmds.h"
|
||||
|
||||
static int _cmd_slaveinfo (int argc, char * argv[])
|
||||
{
|
||||
return slaveinfo (argc, argv);
|
||||
}
|
||||
|
||||
static int _cmd_simple_test (int argc, char * argv[])
|
||||
{
|
||||
return simple_test (argc, argv);
|
||||
}
|
||||
|
||||
static int _cmd_eepromtool (int argc, char * argv[])
|
||||
{
|
||||
return eepromtool (argc, argv);
|
||||
}
|
||||
|
||||
const shell_cmd_t cmd_slaveinfo =
|
||||
{
|
||||
.cmd = _cmd_slaveinfo,
|
||||
.name = "slaveinfo",
|
||||
.help_short = "show EtherCAT slave info",
|
||||
.help_long =
|
||||
"Usage: slaveinfo ifname [options]\n"
|
||||
"\n"
|
||||
"Find all EtherCAT slaves and show slave configuration.\n"
|
||||
"ifname will be ignored but must be given.\n"
|
||||
"Options :\n"
|
||||
" -sdo : print SDO info\n"
|
||||
" -map : print mapping\n"
|
||||
};
|
||||
|
||||
const shell_cmd_t cmd_simple_test =
|
||||
{
|
||||
.cmd = _cmd_simple_test,
|
||||
.name = "simple_test",
|
||||
.help_short = "EtherCAT process data test",
|
||||
.help_long =
|
||||
"Usage: simple_test ifname\n"
|
||||
"\n"
|
||||
"Send and receive (dummy) processdata on EtherCAT bus.\n"
|
||||
"ifname will be ignored but must be given.\n"
|
||||
};
|
||||
|
||||
const shell_cmd_t cmd_eepromtool =
|
||||
{
|
||||
.cmd = _cmd_eepromtool,
|
||||
.name = "eepromtool",
|
||||
.help_short = "program eeprom of EtherCAT slave",
|
||||
.help_long =
|
||||
"Usage: eepromtool ifname slave [options] fname|alias\n"
|
||||
"\n"
|
||||
"Program the EEPROM of an EtherCAT slave.\n"
|
||||
"ifname will be ignored but must be given.\n"
|
||||
"slave = slave number in EtherCAT order 1..n\n"
|
||||
" -i display EEPROM information\n"
|
||||
" -walias write slave alias\n"
|
||||
" -r read EEPROM, output binary format\n"
|
||||
" -ri read EEPROM, output Intel Hex format\n"
|
||||
" -w write EEPROM, input binary format\n"
|
||||
" -wi write EEPROM, input Intel Hex format\n"
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Licensed under the GNU General Public License version 2 with exceptions. See
|
||||
* LICENSE file in the project root for full license information
|
||||
*/
|
||||
|
||||
#ifndef _SOEM_CMDS_H
|
||||
#define _SOEM_CMDS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <shell.h>
|
||||
|
||||
extern const shell_cmd_t cmd_slaveinfo;
|
||||
extern const shell_cmd_t cmd_simple_test;
|
||||
extern const shell_cmd_t cmd_eepromtool;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SOEM_CMDS_H */
|
|
@ -1,388 +0,0 @@
|
|||
/** \file
|
||||
* \brief EEprom tool for Simple Open EtherCAT master
|
||||
*
|
||||
* Usage : eepromtool ifname slave OPTION fname
|
||||
* ifname is NIC interface, f.e. eth0
|
||||
* slave = slave number in EtherCAT order 1..n
|
||||
* -r read EEPROM, output binary format
|
||||
* -ri read EEPROM, output Intel Hex format
|
||||
* -w write EEPROM, input binary format
|
||||
* -wi write EEPROM, input Intel Hex format
|
||||
*
|
||||
* (c)Arthur Ketels 2010
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ethercat.h"
|
||||
|
||||
#define MAXBUF 32768
|
||||
#define STDBUF 2048
|
||||
#define MINBUF 128
|
||||
|
||||
#define MODE_NONE 0
|
||||
#define MODE_READBIN 1
|
||||
#define MODE_READINTEL 2
|
||||
#define MODE_WRITEBIN 3
|
||||
#define MODE_WRITEINTEL 4
|
||||
|
||||
#define MAXSLENGTH 256
|
||||
|
||||
uint8 ebuf[MAXBUF];
|
||||
uint8 ob;
|
||||
uint16 ow;
|
||||
int os;
|
||||
int slave;
|
||||
ec_timet tstart,tend, tdif;
|
||||
int wkc;
|
||||
int mode;
|
||||
char sline[MAXSLENGTH];
|
||||
|
||||
#define IHEXLENGTH 0x20
|
||||
|
||||
int input_bin(char *fname, int *length)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
int cc = 0, c;
|
||||
|
||||
fp = fopen(fname, "rb");
|
||||
if(fp == NULL)
|
||||
return 0;
|
||||
while (((c = fgetc(fp)) != EOF) && (cc < MAXBUF))
|
||||
ebuf[cc++] = (uint8)c;
|
||||
*length = cc;
|
||||
fclose(fp);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int input_intelhex(char *fname, int *start, int *length)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
int c, sc, retval = 1;
|
||||
int ll, ladr, lt, sn, i, lval;
|
||||
int hstart, hlength, sum;
|
||||
|
||||
fp = fopen(fname, "r");
|
||||
if(fp == NULL)
|
||||
return 0;
|
||||
hstart = MAXBUF;
|
||||
hlength = 0;
|
||||
sum = 0;
|
||||
do
|
||||
{
|
||||
memset(sline, 0x00, MAXSLENGTH);
|
||||
sc = 0;
|
||||
while (((c = fgetc(fp)) != EOF) && (c != 0x0A) && (sc < (MAXSLENGTH -1)))
|
||||
sline[sc++] = (uint8)c;
|
||||
if ((c != EOF) && ((sc < 11) || (sline[0] != ':')))
|
||||
{
|
||||
c = EOF;
|
||||
retval = 0;
|
||||
printf("Invalid Intel Hex format.\n");
|
||||
}
|
||||
if (c != EOF)
|
||||
{
|
||||
sn = sscanf(sline , ":%2x%4x%2x", &ll, &ladr, <);
|
||||
if ((sn == 3) && ((ladr + ll) <= MAXBUF) && (lt == 0))
|
||||
{
|
||||
sum = ll + (ladr >> 8) + (ladr & 0xff) + lt;
|
||||
if(ladr < hstart) hstart = ladr;
|
||||
for(i = 0; i < ll ; i++)
|
||||
{
|
||||
sn = sscanf(&sline[9 + (i << 1)], "%2x", &lval);
|
||||
ebuf[ladr + i] = (uint8)lval;
|
||||
sum += (uint8)lval;
|
||||
}
|
||||
if(((ladr + ll) - hstart) > hlength)
|
||||
hlength = (ladr + ll) - hstart;
|
||||
sum = (0x100 - sum) & 0xff;
|
||||
sn = sscanf(&sline[9 + (i << 1)], "%2x", &lval);
|
||||
if (!sn || ((sum - lval) != 0))
|
||||
{
|
||||
c = EOF;
|
||||
retval = 0;
|
||||
printf("Invalid checksum.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (c != EOF);
|
||||
if (retval)
|
||||
{
|
||||
*length = hlength;
|
||||
*start = hstart;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int output_bin(char *fname, int length)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
int cc;
|
||||
|
||||
fp = fopen(fname, "wb");
|
||||
if(fp == NULL)
|
||||
return 0;
|
||||
for (cc = 0 ; cc < length ; cc++)
|
||||
fputc( ebuf[cc], fp);
|
||||
fclose(fp);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int output_intelhex(char *fname, int length)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
int cc = 0, ll, sum, i;
|
||||
|
||||
fp = fopen(fname, "w");
|
||||
if(fp == NULL)
|
||||
return 0;
|
||||
while (cc < length)
|
||||
{
|
||||
ll = length - cc;
|
||||
if (ll > IHEXLENGTH) ll = IHEXLENGTH;
|
||||
sum = ll + (cc >> 8) + (cc & 0xff);
|
||||
fprintf(fp, ":%2.2X%4.4X00", ll, cc);
|
||||
for (i = 0; i < ll; i++)
|
||||
{
|
||||
fprintf(fp, "%2.2X", ebuf[cc + i]);
|
||||
sum += ebuf[cc + i];
|
||||
}
|
||||
fprintf(fp, "%2.2X\n", (0x100 - sum) & 0xff);
|
||||
cc += ll;
|
||||
}
|
||||
fprintf(fp, ":00000001FF\n");
|
||||
fclose(fp);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int eeprom_read(int slave, int start, int length)
|
||||
{
|
||||
int i, wkc, ainc = 4;
|
||||
uint16 estat, aiadr;
|
||||
uint32 b4;
|
||||
uint64 b8;
|
||||
uint8 eepctl;
|
||||
|
||||
if((ec_slavecount >= slave) && (slave > 0) && ((start + length) <= MAXBUF))
|
||||
{
|
||||
aiadr = 1 - slave;
|
||||
eepctl = 2;
|
||||
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* force Eeprom from PDI */
|
||||
eepctl = 0;
|
||||
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* set Eeprom to master */
|
||||
|
||||
estat = 0x0000;
|
||||
aiadr = 1 - slave;
|
||||
wkc=ec_APRD(aiadr, ECT_REG_EEPSTAT, sizeof(estat), &estat, EC_TIMEOUTRET3); /* read eeprom status */
|
||||
estat = etohs(estat);
|
||||
if (estat & EC_ESTAT_R64)
|
||||
{
|
||||
ainc = 8;
|
||||
for (i = start ; i < (start + length) ; i+=ainc)
|
||||
{
|
||||
b8 = ec_readeepromAP(aiadr, i >> 1 , EC_TIMEOUTEEP);
|
||||
ebuf[i] = (uint8) b8;
|
||||
ebuf[i+1] = (uint8) (b8 >> 8);
|
||||
ebuf[i+2] = (uint8) (b8 >> 16);
|
||||
ebuf[i+3] = (uint8) (b8 >> 24);
|
||||
ebuf[i+4] = (uint8) (b8 >> 32);
|
||||
ebuf[i+5] = (uint8) (b8 >> 40);
|
||||
ebuf[i+6] = (uint8) (b8 >> 48);
|
||||
ebuf[i+7] = (uint8) (b8 >> 56);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = start ; i < (start + length) ; i+=ainc)
|
||||
{
|
||||
b4 = (uint32)ec_readeepromAP(aiadr, i >> 1 , EC_TIMEOUTEEP);
|
||||
ebuf[i] = (uint8) b4;
|
||||
ebuf[i+1] = (uint8) (b4 >> 8);
|
||||
ebuf[i+2] = (uint8) (b4 >> 16);
|
||||
ebuf[i+3] = (uint8) (b4 >> 24);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eeprom_write(int slave, int start, int length)
|
||||
{
|
||||
int i, wkc, dc = 0;
|
||||
uint16 aiadr, *wbuf;
|
||||
uint8 eepctl;
|
||||
int ret;
|
||||
|
||||
if((ec_slavecount >= slave) && (slave > 0) && ((start + length) <= MAXBUF))
|
||||
{
|
||||
aiadr = 1 - slave;
|
||||
eepctl = 2;
|
||||
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* force Eeprom from PDI */
|
||||
eepctl = 0;
|
||||
wkc = ec_APWR(aiadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET3); /* set Eeprom to master */
|
||||
|
||||
aiadr = 1 - slave;
|
||||
wbuf = (uint16 *)&ebuf[0];
|
||||
for (i = start ; i < (start + length) ; i+=2)
|
||||
{
|
||||
ret = ec_writeeepromAP(aiadr, i >> 1 , *(wbuf + (i >> 1)), EC_TIMEOUTEEP);
|
||||
if (++dc >= 100)
|
||||
{
|
||||
dc = 0;
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void eepromtool(char *ifname, int slave, int mode, char *fname)
|
||||
{
|
||||
int w, rc = 0, estart, esize;
|
||||
uint16 *wbuf;
|
||||
|
||||
/* initialise SOEM, bind socket to ifname */
|
||||
if (ec_init(ifname))
|
||||
{
|
||||
printf("ec_init on %s succeeded.\n",ifname);
|
||||
|
||||
w = 0x0000;
|
||||
wkc = ec_BRD(0x0000, ECT_REG_TYPE, sizeof(w), &w, EC_TIMEOUTSAFE); /* detect number of slaves */
|
||||
if (wkc > 0)
|
||||
{
|
||||
ec_slavecount = wkc;
|
||||
|
||||
printf("%d slaves found.\n",ec_slavecount);
|
||||
if((ec_slavecount >= slave) && (slave > 0))
|
||||
{
|
||||
if ((mode == MODE_READBIN) || (mode == MODE_READINTEL))
|
||||
{
|
||||
tstart = osal_current_time();
|
||||
eeprom_read(slave, 0x0000, MINBUF); // read first 128 bytes
|
||||
|
||||
wbuf = (uint16 *)&ebuf[0];
|
||||
printf("Slave %d data\n", slave);
|
||||
printf(" PDI Control : %4.4X\n",*(wbuf + 0x00));
|
||||
printf(" PDI Config : %4.4X\n",*(wbuf + 0x01));
|
||||
printf(" Config Alias : %4.4X\n",*(wbuf + 0x04));
|
||||
printf(" Checksum : %4.4X\n",*(wbuf + 0x07));
|
||||
printf(" Vendor ID : %8.8X\n",*(uint32 *)(wbuf + 0x08));
|
||||
printf(" Product Code : %8.8X\n",*(uint32 *)(wbuf + 0x0A));
|
||||
printf(" Revision Number : %8.8X\n",*(uint32 *)(wbuf + 0x0C));
|
||||
printf(" Serial Number : %8.8X\n",*(uint32 *)(wbuf + 0x0E));
|
||||
printf(" Mailbox Protocol : %4.4X\n",*(wbuf + 0x1C));
|
||||
esize = (*(wbuf + 0x3E) + 1) * 128;
|
||||
if (esize > MAXBUF) esize = MAXBUF;
|
||||
printf(" Size : %4.4X = %d bytes\n",*(wbuf + 0x3E), esize);
|
||||
printf(" Version : %4.4X\n",*(wbuf + 0x3F));
|
||||
|
||||
if (esize > MINBUF)
|
||||
eeprom_read(slave, MINBUF, esize - MINBUF); // read reminder
|
||||
|
||||
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.usec+(tdif.sec*1000000L)) / 1000);
|
||||
}
|
||||
if ((mode == MODE_WRITEBIN) || (mode == MODE_WRITEINTEL))
|
||||
{
|
||||
estart = 0;
|
||||
if (mode == MODE_WRITEINTEL) rc = input_intelhex(fname, &estart, &esize);
|
||||
if (mode == MODE_WRITEBIN) rc = input_bin(fname, &esize);
|
||||
|
||||
if (rc > 0)
|
||||
{
|
||||
wbuf = (uint16 *)&ebuf[0];
|
||||
printf("Slave %d\n", slave);
|
||||
printf(" Vendor ID : %8.8X\n",*(uint32 *)(wbuf + 0x08));
|
||||
printf(" Product Code : %8.8X\n",*(uint32 *)(wbuf + 0x0A));
|
||||
printf(" Revision Number : %8.8X\n",*(uint32 *)(wbuf + 0x0C));
|
||||
printf(" Serial Number : %8.8X\n",*(uint32 *)(wbuf + 0x0E));
|
||||
|
||||
printf("Busy");
|
||||
fflush(stdout);
|
||||
tstart = osal_current_time();
|
||||
eeprom_write(slave, estart, esize);
|
||||
tend = osal_current_time();
|
||||
osal_time_diff(&tstart, &tend, &tdif);
|
||||
|
||||
printf("\nTotal EEPROM write time :%ldms\n", (tdif.usec+(tdif.sec*1000000L)) / 1000);
|
||||
}
|
||||
else
|
||||
printf("Error reading file, abort.\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("Slave number outside range.\n");
|
||||
}
|
||||
else
|
||||
printf("No slaves found!\n");
|
||||
printf("End, close socket\n");
|
||||
/* stop SOEM, close socket */
|
||||
ec_close();
|
||||
}
|
||||
else
|
||||
printf("No socket connection on %s\nExcecute as root\n",ifname);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ec_adaptert * adapter = NULL;
|
||||
printf("SOEM (Simple Open EtherCAT Master)\nEEPROM tool\n");
|
||||
|
||||
if (argc > 4)
|
||||
{
|
||||
slave = atoi(argv[2]);
|
||||
mode = MODE_NONE;
|
||||
if ((strncmp(argv[3], "-r", sizeof("-r")) == 0)) mode = MODE_READBIN;
|
||||
if ((strncmp(argv[3], "-ri", sizeof("-ri")) == 0)) mode = MODE_READINTEL;
|
||||
if ((strncmp(argv[3], "-w", sizeof("-w")) == 0)) mode = MODE_WRITEBIN;
|
||||
if ((strncmp(argv[3], "-wi", sizeof("-wi")) == 0)) mode = MODE_WRITEINTEL;
|
||||
|
||||
/* start tool */
|
||||
eepromtool(argv[1],slave,mode,argv[4]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Usage: eepromtool ifname slave OPTION fname\n");
|
||||
printf("ifname = adapter name\n");
|
||||
printf("slave = slave number in EtherCAT order 1..n\n");
|
||||
printf(" -r read EEPROM, output binary format\n");
|
||||
printf(" -ri read EEPROM, output Intel Hex format\n");
|
||||
printf(" -w write EEPROM, input binary format\n");
|
||||
printf(" -wi write EEPROM, input Intel Hex format\n");
|
||||
/* Print the list */
|
||||
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);
|
||||
}
|
|
@ -1,373 +0,0 @@
|
|||
/** \file
|
||||
* \brief Example code for Simple Open EtherCAT master
|
||||
*
|
||||
* Usage : simple_test [ifname1]
|
||||
* ifname is NIC interface, f.e. eth0
|
||||
*
|
||||
* This is a minimal test.
|
||||
*
|
||||
* (c)Arthur Ketels 2010 - 2011
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
//#include <Mmsystem.h>
|
||||
|
||||
#include "osal.h"
|
||||
#include "ethercat.h"
|
||||
|
||||
#define EC_TIMEOUTMON 500
|
||||
|
||||
char IOmap[4096];
|
||||
OSAL_THREAD_HANDLE thread1;
|
||||
int expectedWKC;
|
||||
boolean needlf;
|
||||
volatile int wkc;
|
||||
volatile int rtcnt;
|
||||
boolean inOP;
|
||||
uint8 currentgroup = 0;
|
||||
|
||||
/* most basic RT thread for process data, just does IO transfer */
|
||||
void CALLBACK RTthread(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
|
||||
{
|
||||
IOmap[0]++;
|
||||
|
||||
ec_send_processdata();
|
||||
wkc = ec_receive_processdata(EC_TIMEOUTRET);
|
||||
rtcnt++;
|
||||
/* do RT control stuff here */
|
||||
}
|
||||
|
||||
int EL7031setup(uint16 slave)
|
||||
{
|
||||
int retval;
|
||||
uint16 u16val;
|
||||
|
||||
// map velocity
|
||||
uint16 map_1c12[4] = {0x0003, 0x1601, 0x1602, 0x1604};
|
||||
uint16 map_1c13[3] = {0x0002, 0x1a01, 0x1a03};
|
||||
|
||||
retval = 0;
|
||||
|
||||
// Set PDO mapping using Complete Access
|
||||
// Strange, writing CA works, reading CA doesn't
|
||||
// This is a protocol error of the slave.
|
||||
retval += ec_SDOwrite(slave, 0x1c12, 0x00, TRUE, sizeof(map_1c12), &map_1c12, EC_TIMEOUTSAFE);
|
||||
retval += ec_SDOwrite(slave, 0x1c13, 0x00, TRUE, sizeof(map_1c13), &map_1c13, EC_TIMEOUTSAFE);
|
||||
|
||||
// bug in EL7031 old firmware, CompleteAccess for reading is not supported even if the slave says it is.
|
||||
ec_slave[slave].CoEdetails &= ~ECT_COEDET_SDOCA;
|
||||
|
||||
// set some motor parameters, just as example
|
||||
u16val = 1200; // max motor current in mA
|
||||
// retval += ec_SDOwrite(slave, 0x8010, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
|
||||
u16val = 150; // motor coil resistance in 0.01ohm
|
||||
// retval += ec_SDOwrite(slave, 0x8010, 0x04, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
|
||||
|
||||
// set other nescessary parameters as needed
|
||||
// .....
|
||||
|
||||
while(EcatError) printf("%s", ec_elist2string());
|
||||
|
||||
printf("EL7031 slave %d set, retval = %d\n", slave, retval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int AEPsetup(uint16 slave)
|
||||
{
|
||||
int retval;
|
||||
uint8 u8val;
|
||||
uint16 u16val;
|
||||
|
||||
retval = 0;
|
||||
|
||||
u8val = 0;
|
||||
retval += ec_SDOwrite(slave, 0x1c12, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
|
||||
u16val = 0x1603;
|
||||
retval += ec_SDOwrite(slave, 0x1c12, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTRXM);
|
||||
u8val = 1;
|
||||
retval += ec_SDOwrite(slave, 0x1c12, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
|
||||
|
||||
u8val = 0;
|
||||
retval += ec_SDOwrite(slave, 0x1c13, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
|
||||
u16val = 0x1a03;
|
||||
retval += ec_SDOwrite(slave, 0x1c13, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTRXM);
|
||||
u8val = 1;
|
||||
retval += ec_SDOwrite(slave, 0x1c13, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
|
||||
|
||||
u8val = 8;
|
||||
retval += ec_SDOwrite(slave, 0x6060, 0x00, FALSE, sizeof(u8val), &u8val, EC_TIMEOUTRXM);
|
||||
|
||||
// set some motor parameters, just as example
|
||||
u16val = 1200; // max motor current in mA
|
||||
// retval += ec_SDOwrite(slave, 0x8010, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
|
||||
u16val = 150; // motor coil resistance in 0.01ohm
|
||||
// retval += ec_SDOwrite(slave, 0x8010, 0x04, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE);
|
||||
|
||||
// set other nescessary parameters as needed
|
||||
// .....
|
||||
|
||||
while(EcatError) printf("%s", ec_elist2string());
|
||||
|
||||
printf("AEP slave %d set, retval = %d\n", slave, retval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void simpletest(char *ifname)
|
||||
{
|
||||
int i, j, oloop, iloop, wkc_count, chk, slc;
|
||||
UINT mmResult;
|
||||
|
||||
needlf = FALSE;
|
||||
inOP = FALSE;
|
||||
|
||||
printf("Starting simple test\n");
|
||||
|
||||
/* initialise SOEM, bind socket to ifname */
|
||||
if (ec_init(ifname))
|
||||
{
|
||||
printf("ec_init on %s succeeded.\n",ifname);
|
||||
/* find and auto-config slaves */
|
||||
|
||||
|
||||
if ( ec_config_init(FALSE) > 0 )
|
||||
{
|
||||
printf("%d slaves found and configured.\n",ec_slavecount);
|
||||
|
||||
if((ec_slavecount > 1))
|
||||
{
|
||||
for(slc = 1; slc <= ec_slavecount; slc++)
|
||||
{
|
||||
// beckhoff EL7031, using ec_slave[].name is not very reliable
|
||||
if((ec_slave[slc].eep_man == 0x00000002) && (ec_slave[slc].eep_id == 0x1b773052))
|
||||
{
|
||||
printf("Found %s at position %d\n", ec_slave[slc].name, slc);
|
||||
// link slave specific setup to preop->safeop hook
|
||||
ec_slave[slc].PO2SOconfig = &EL7031setup;
|
||||
}
|
||||
// Copley Controls EAP, using ec_slave[].name is not very reliable
|
||||
if((ec_slave[slc].eep_man == 0x000000ab) && (ec_slave[slc].eep_id == 0x00000380))
|
||||
{
|
||||
printf("Found %s at position %d\n", ec_slave[slc].name, slc);
|
||||
// link slave specific setup to preop->safeop hook
|
||||
ec_slave[slc].PO2SOconfig = &AEPsetup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ec_config_map(&IOmap);
|
||||
|
||||
ec_configdc();
|
||||
|
||||
printf("Slaves mapped, state to SAFE_OP.\n");
|
||||
/* wait for all slaves to reach SAFE_OP state */
|
||||
ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 4);
|
||||
|
||||
oloop = ec_slave[0].Obytes;
|
||||
if ((oloop == 0) && (ec_slave[0].Obits > 0)) oloop = 1;
|
||||
if (oloop > 8) oloop = 8;
|
||||
iloop = ec_slave[0].Ibytes;
|
||||
if ((iloop == 0) && (ec_slave[0].Ibits > 0)) iloop = 1;
|
||||
if (iloop > 8) iloop = 8;
|
||||
|
||||
printf("segments : %d : %d %d %d %d\n",ec_group[0].nsegments ,ec_group[0].IOsegment[0],ec_group[0].IOsegment[1],ec_group[0].IOsegment[2],ec_group[0].IOsegment[3]);
|
||||
|
||||
printf("Request operational state for all slaves\n");
|
||||
expectedWKC = (ec_group[0].outputsWKC * 2) + ec_group[0].inputsWKC;
|
||||
printf("Calculated workcounter %d\n", expectedWKC);
|
||||
ec_slave[0].state = EC_STATE_OPERATIONAL;
|
||||
/* send one valid process data to make outputs in slaves happy*/
|
||||
ec_send_processdata();
|
||||
ec_receive_processdata(EC_TIMEOUTRET);
|
||||
|
||||
/* start RT thread as periodic MM timer */
|
||||
mmResult = timeSetEvent(1, 0, RTthread, 0, TIME_PERIODIC);
|
||||
|
||||
/* request OP state for all slaves */
|
||||
ec_writestate(0);
|
||||
chk = 200;
|
||||
/* wait for all slaves to reach OP state */
|
||||
do
|
||||
{
|
||||
ec_statecheck(0, EC_STATE_OPERATIONAL, 50000);
|
||||
}
|
||||
while (chk-- && (ec_slave[0].state != EC_STATE_OPERATIONAL));
|
||||
if (ec_slave[0].state == EC_STATE_OPERATIONAL )
|
||||
{
|
||||
printf("Operational state reached for all slaves.\n");
|
||||
wkc_count = 0;
|
||||
inOP = TRUE;
|
||||
|
||||
|
||||
/* cyclic loop, reads data from RT thread */
|
||||
for(i = 1; i <= 500; i++)
|
||||
{
|
||||
if(wkc >= expectedWKC)
|
||||
{
|
||||
printf("Processdata cycle %4d, WKC %d , O:", rtcnt, wkc);
|
||||
|
||||
for(j = 0 ; j < oloop; j++)
|
||||
{
|
||||
printf(" %2.2x", *(ec_slave[0].outputs + j));
|
||||
}
|
||||
|
||||
printf(" I:");
|
||||
for(j = 0 ; j < iloop; j++)
|
||||
{
|
||||
printf(" %2.2x", *(ec_slave[0].inputs + j));
|
||||
}
|
||||
printf(" T:%lld\r",ec_DCtime);
|
||||
needlf = TRUE;
|
||||
}
|
||||
osal_usleep(50000);
|
||||
|
||||
}
|
||||
inOP = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Not all slaves reached operational state.\n");
|
||||
ec_readstate();
|
||||
for(i = 1; i<=ec_slavecount ; i++)
|
||||
{
|
||||
if(ec_slave[i].state != EC_STATE_OPERATIONAL)
|
||||
{
|
||||
printf("Slave %d State=0x%2.2x StatusCode=0x%4.4x : %s\n",
|
||||
i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* stop RT thread */
|
||||
timeKillEvent(mmResult);
|
||||
|
||||
printf("\nRequest init state for all slaves\n");
|
||||
ec_slave[0].state = EC_STATE_INIT;
|
||||
/* request INIT state for all slaves */
|
||||
ec_writestate(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No slaves found!\n");
|
||||
}
|
||||
printf("End simple test, close socket\n");
|
||||
/* stop SOEM, close socket */
|
||||
ec_close();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No socket connection on %s\nExcecute as root\n",ifname);
|
||||
}
|
||||
}
|
||||
|
||||
//DWORD WINAPI ecatcheck( LPVOID lpParam )
|
||||
OSAL_THREAD_FUNC ecatcheck(void *lpParam)
|
||||
{
|
||||
int slave;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if( inOP && ((wkc < expectedWKC) || ec_group[currentgroup].docheckstate))
|
||||
{
|
||||
if (needlf)
|
||||
{
|
||||
needlf = FALSE;
|
||||
printf("\n");
|
||||
}
|
||||
/* one ore more slaves are not responding */
|
||||
ec_group[currentgroup].docheckstate = FALSE;
|
||||
ec_readstate();
|
||||
for (slave = 1; slave <= ec_slavecount; slave++)
|
||||
{
|
||||
if ((ec_slave[slave].group == currentgroup) && (ec_slave[slave].state != EC_STATE_OPERATIONAL))
|
||||
{
|
||||
ec_group[currentgroup].docheckstate = TRUE;
|
||||
if (ec_slave[slave].state == (EC_STATE_SAFE_OP + EC_STATE_ERROR))
|
||||
{
|
||||
printf("ERROR : slave %d is in SAFE_OP + ERROR, attempting ack.\n", slave);
|
||||
ec_slave[slave].state = (EC_STATE_SAFE_OP + EC_STATE_ACK);
|
||||
ec_writestate(slave);
|
||||
}
|
||||
else if(ec_slave[slave].state == EC_STATE_SAFE_OP)
|
||||
{
|
||||
printf("WARNING : slave %d is in SAFE_OP, change to OPERATIONAL.\n", slave);
|
||||
ec_slave[slave].state = EC_STATE_OPERATIONAL;
|
||||
ec_writestate(slave);
|
||||
}
|
||||
else if(ec_slave[slave].state > EC_STATE_NONE)
|
||||
{
|
||||
if (ec_reconfig_slave(slave, EC_TIMEOUTMON))
|
||||
{
|
||||
ec_slave[slave].islost = FALSE;
|
||||
printf("MESSAGE : slave %d reconfigured\n",slave);
|
||||
}
|
||||
}
|
||||
else if(!ec_slave[slave].islost)
|
||||
{
|
||||
/* re-check state */
|
||||
ec_statecheck(slave, EC_STATE_OPERATIONAL, EC_TIMEOUTRET);
|
||||
if (ec_slave[slave].state == EC_STATE_NONE)
|
||||
{
|
||||
ec_slave[slave].islost = TRUE;
|
||||
printf("ERROR : slave %d lost\n",slave);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ec_slave[slave].islost)
|
||||
{
|
||||
if(ec_slave[slave].state == EC_STATE_NONE)
|
||||
{
|
||||
if (ec_recover_slave(slave, EC_TIMEOUTMON))
|
||||
{
|
||||
ec_slave[slave].islost = FALSE;
|
||||
printf("MESSAGE : slave %d recovered\n",slave);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ec_slave[slave].islost = FALSE;
|
||||
printf("MESSAGE : slave %d found\n",slave);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!ec_group[currentgroup].docheckstate)
|
||||
printf("OK : all slaves resumed OPERATIONAL.\n");
|
||||
}
|
||||
osal_usleep(10000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char ifbuf[1024];
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ec_adaptert * adapter = NULL;
|
||||
printf("SOEM (Simple Open EtherCAT Master)\nSimple test\n");
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
/* create thread to handle slave error handling in OP */
|
||||
osal_thread_create(&thread1, 128000, &ecatcheck, (void*) &ctime);
|
||||
strcpy(ifbuf, argv[1]);
|
||||
/* start cyclic part */
|
||||
simpletest(ifbuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Usage: simple_test ifname1\n");
|
||||
/* Print the list */
|
||||
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);
|
||||
}
|
|
@ -1,646 +0,0 @@
|
|||
/** \file
|
||||
* \brief Example code for Simple Open EtherCAT master
|
||||
*
|
||||
* Usage : slaveinfo [ifname] [-sdo] [-map]
|
||||
* Ifname is NIC interface, f.e. eth0.
|
||||
* Optional -sdo to display CoE object dictionary.
|
||||
* Optional -map to display slave PDO mapping
|
||||
*
|
||||
* This shows the configured slave data.
|
||||
*
|
||||
* (c)Arthur Ketels 2010 - 2011
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "ethercat.h"
|
||||
|
||||
char IOmap[4096];
|
||||
ec_ODlistt ODlist;
|
||||
ec_OElistt OElist;
|
||||
boolean printSDO = FALSE;
|
||||
boolean printMAP = FALSE;
|
||||
char usdo[128];
|
||||
char hstr[1024];
|
||||
|
||||
char* dtype2string(uint16 dtype)
|
||||
{
|
||||
switch(dtype)
|
||||
{
|
||||
case ECT_BOOLEAN:
|
||||
sprintf(hstr, "BOOLEAN");
|
||||
break;
|
||||
case ECT_INTEGER8:
|
||||
sprintf(hstr, "INTEGER8");
|
||||
break;
|
||||
case ECT_INTEGER16:
|
||||
sprintf(hstr, "INTEGER16");
|
||||
break;
|
||||
case ECT_INTEGER32:
|
||||
sprintf(hstr, "INTEGER32");
|
||||
break;
|
||||
case ECT_INTEGER24:
|
||||
sprintf(hstr, "INTEGER24");
|
||||
break;
|
||||
case ECT_INTEGER64:
|
||||
sprintf(hstr, "INTEGER64");
|
||||
break;
|
||||
case ECT_UNSIGNED8:
|
||||
sprintf(hstr, "UNSIGNED8");
|
||||
break;
|
||||
case ECT_UNSIGNED16:
|
||||
sprintf(hstr, "UNSIGNED16");
|
||||
break;
|
||||
case ECT_UNSIGNED32:
|
||||
sprintf(hstr, "UNSIGNED32");
|
||||
break;
|
||||
case ECT_UNSIGNED24:
|
||||
sprintf(hstr, "UNSIGNED24");
|
||||
break;
|
||||
case ECT_UNSIGNED64:
|
||||
sprintf(hstr, "UNSIGNED64");
|
||||
break;
|
||||
case ECT_REAL32:
|
||||
sprintf(hstr, "REAL32");
|
||||
break;
|
||||
case ECT_REAL64:
|
||||
sprintf(hstr, "REAL64");
|
||||
break;
|
||||
case ECT_BIT1:
|
||||
sprintf(hstr, "BIT1");
|
||||
break;
|
||||
case ECT_BIT2:
|
||||
sprintf(hstr, "BIT2");
|
||||
break;
|
||||
case ECT_BIT3:
|
||||
sprintf(hstr, "BIT3");
|
||||
break;
|
||||
case ECT_BIT4:
|
||||
sprintf(hstr, "BIT4");
|
||||
break;
|
||||
case ECT_BIT5:
|
||||
sprintf(hstr, "BIT5");
|
||||
break;
|
||||
case ECT_BIT6:
|
||||
sprintf(hstr, "BIT6");
|
||||
break;
|
||||
case ECT_BIT7:
|
||||
sprintf(hstr, "BIT7");
|
||||
break;
|
||||
case ECT_BIT8:
|
||||
sprintf(hstr, "BIT8");
|
||||
break;
|
||||
case ECT_VISIBLE_STRING:
|
||||
sprintf(hstr, "VISIBLE_STRING");
|
||||
break;
|
||||
case ECT_OCTET_STRING:
|
||||
sprintf(hstr, "OCTET_STRING");
|
||||
break;
|
||||
default:
|
||||
sprintf(hstr, "Type 0x%4.4X", dtype);
|
||||
}
|
||||
return hstr;
|
||||
}
|
||||
|
||||
char* SDO2string(uint16 slave, uint16 index, uint8 subidx, uint16 dtype)
|
||||
{
|
||||
int l = sizeof(usdo) - 1, i;
|
||||
uint8 *u8;
|
||||
int8 *i8;
|
||||
uint16 *u16;
|
||||
int16 *i16;
|
||||
uint32 *u32;
|
||||
int32 *i32;
|
||||
uint64 *u64;
|
||||
int64 *i64;
|
||||
float *sr;
|
||||
double *dr;
|
||||
char es[32];
|
||||
|
||||
memset(&usdo, 0, 128);
|
||||
ec_SDOread(slave, index, subidx, FALSE, &l, &usdo, EC_TIMEOUTRXM);
|
||||
if (EcatError)
|
||||
{
|
||||
return ec_elist2string();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(dtype)
|
||||
{
|
||||
case ECT_BOOLEAN:
|
||||
u8 = (uint8*) &usdo[0];
|
||||
if (*u8) sprintf(hstr, "TRUE");
|
||||
else sprintf(hstr, "FALSE");
|
||||
break;
|
||||
case ECT_INTEGER8:
|
||||
i8 = (int8*) &usdo[0];
|
||||
sprintf(hstr, "0x%2.2x %d", *i8, *i8);
|
||||
break;
|
||||
case ECT_INTEGER16:
|
||||
i16 = (int16*) &usdo[0];
|
||||
sprintf(hstr, "0x%4.4x %d", *i16, *i16);
|
||||
break;
|
||||
case ECT_INTEGER32:
|
||||
case ECT_INTEGER24:
|
||||
i32 = (int32*) &usdo[0];
|
||||
sprintf(hstr, "0x%8.8x %d", *i32, *i32);
|
||||
break;
|
||||
case ECT_INTEGER64:
|
||||
i64 = (int64*) &usdo[0];
|
||||
sprintf(hstr, "0x%16.16"PRIx64" %"PRId64, *i64, *i64);
|
||||
break;
|
||||
case ECT_UNSIGNED8:
|
||||
u8 = (uint8*) &usdo[0];
|
||||
sprintf(hstr, "0x%2.2x %u", *u8, *u8);
|
||||
break;
|
||||
case ECT_UNSIGNED16:
|
||||
u16 = (uint16*) &usdo[0];
|
||||
sprintf(hstr, "0x%4.4x %u", *u16, *u16);
|
||||
break;
|
||||
case ECT_UNSIGNED32:
|
||||
case ECT_UNSIGNED24:
|
||||
u32 = (uint32*) &usdo[0];
|
||||
sprintf(hstr, "0x%8.8x %u", *u32, *u32);
|
||||
break;
|
||||
case ECT_UNSIGNED64:
|
||||
u64 = (uint64*) &usdo[0];
|
||||
sprintf(hstr, "0x%16.16"PRIx64" %"PRIu64, *u64, *u64);
|
||||
break;
|
||||
case ECT_REAL32:
|
||||
sr = (float*) &usdo[0];
|
||||
sprintf(hstr, "%f", *sr);
|
||||
break;
|
||||
case ECT_REAL64:
|
||||
dr = (double*) &usdo[0];
|
||||
sprintf(hstr, "%f", *dr);
|
||||
break;
|
||||
case ECT_BIT1:
|
||||
case ECT_BIT2:
|
||||
case ECT_BIT3:
|
||||
case ECT_BIT4:
|
||||
case ECT_BIT5:
|
||||
case ECT_BIT6:
|
||||
case ECT_BIT7:
|
||||
case ECT_BIT8:
|
||||
u8 = (uint8*) &usdo[0];
|
||||
sprintf(hstr, "0x%x", *u8);
|
||||
break;
|
||||
case ECT_VISIBLE_STRING:
|
||||
strcpy(hstr, usdo);
|
||||
break;
|
||||
case ECT_OCTET_STRING:
|
||||
hstr[0] = 0x00;
|
||||
for (i = 0 ; i < l ; i++)
|
||||
{
|
||||
sprintf(es, "0x%2.2x ", usdo[i]);
|
||||
strcat( hstr, es);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sprintf(hstr, "Unknown type");
|
||||
}
|
||||
return hstr;
|
||||
}
|
||||
}
|
||||
|
||||
/** Read PDO assign structure */
|
||||
int si_PDOassign(uint16 slave, uint16 PDOassign, int mapoffset, int bitoffset)
|
||||
{
|
||||
uint16 idxloop, nidx, subidxloop, rdat, idx, subidx;
|
||||
uint8 subcnt;
|
||||
int wkc, bsize = 0, rdl;
|
||||
int32 rdat2;
|
||||
uint8 bitlen, obj_subidx;
|
||||
uint16 obj_idx;
|
||||
int abs_offset, abs_bit;
|
||||
|
||||
rdl = sizeof(rdat); rdat = 0;
|
||||
/* read PDO assign subindex 0 ( = number of PDO's) */
|
||||
wkc = ec_SDOread(slave, PDOassign, 0x00, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
|
||||
rdat = etohs(rdat);
|
||||
/* positive result from slave ? */
|
||||
if ((wkc > 0) && (rdat > 0))
|
||||
{
|
||||
/* number of available sub indexes */
|
||||
nidx = rdat;
|
||||
bsize = 0;
|
||||
/* read all PDO's */
|
||||
for (idxloop = 1; idxloop <= nidx; idxloop++)
|
||||
{
|
||||
rdl = sizeof(rdat); rdat = 0;
|
||||
/* read PDO assign */
|
||||
wkc = ec_SDOread(slave, PDOassign, (uint8)idxloop, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
|
||||
/* result is index of PDO */
|
||||
idx = etohl(rdat);
|
||||
if (idx > 0)
|
||||
{
|
||||
rdl = sizeof(subcnt); subcnt = 0;
|
||||
/* read number of subindexes of PDO */
|
||||
wkc = ec_SDOread(slave,idx, 0x00, FALSE, &rdl, &subcnt, EC_TIMEOUTRXM);
|
||||
subidx = subcnt;
|
||||
/* for each subindex */
|
||||
for (subidxloop = 1; subidxloop <= subidx; subidxloop++)
|
||||
{
|
||||
rdl = sizeof(rdat2); rdat2 = 0;
|
||||
/* read SDO that is mapped in PDO */
|
||||
wkc = ec_SDOread(slave, idx, (uint8)subidxloop, FALSE, &rdl, &rdat2, EC_TIMEOUTRXM);
|
||||
rdat2 = etohl(rdat2);
|
||||
/* extract bitlength of SDO */
|
||||
bitlen = LO_BYTE(rdat2);
|
||||
bsize += bitlen;
|
||||
obj_idx = (uint16)(rdat2 >> 16);
|
||||
obj_subidx = (uint8)((rdat2 >> 8) & 0x000000ff);
|
||||
abs_offset = mapoffset + (bitoffset / 8);
|
||||
abs_bit = bitoffset % 8;
|
||||
ODlist.Slave = slave;
|
||||
ODlist.Index[0] = obj_idx;
|
||||
OElist.Entries = 0;
|
||||
wkc = 0;
|
||||
/* read object entry from dictionary if not a filler (0x0000:0x00) */
|
||||
if(obj_idx || obj_subidx)
|
||||
wkc = ec_readOEsingle(0, obj_subidx, &ODlist, &OElist);
|
||||
printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen);
|
||||
if((wkc > 0) && OElist.Entries)
|
||||
{
|
||||
printf(" %-12s %s\n", dtype2string(OElist.DataType[obj_subidx]), OElist.Name[obj_subidx]);
|
||||
}
|
||||
else
|
||||
printf("\n");
|
||||
bitoffset += bitlen;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/* return total found bitlength (PDO) */
|
||||
return bsize;
|
||||
}
|
||||
|
||||
int si_map_sdo(int slave)
|
||||
{
|
||||
int wkc, rdl;
|
||||
int retVal = 0;
|
||||
uint8 nSM, iSM, tSM;
|
||||
int Tsize, outputs_bo, inputs_bo;
|
||||
uint8 SMt_bug_add;
|
||||
|
||||
printf("PDO mapping according to CoE :\n");
|
||||
SMt_bug_add = 0;
|
||||
outputs_bo = 0;
|
||||
inputs_bo = 0;
|
||||
rdl = sizeof(nSM); nSM = 0;
|
||||
/* read SyncManager Communication Type object count */
|
||||
wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, 0x00, FALSE, &rdl, &nSM, EC_TIMEOUTRXM);
|
||||
/* positive result from slave ? */
|
||||
if ((wkc > 0) && (nSM > 2))
|
||||
{
|
||||
/* make nSM equal to number of defined SM */
|
||||
nSM--;
|
||||
/* limit to maximum number of SM defined, if true the slave can't be configured */
|
||||
if (nSM > EC_MAXSM)
|
||||
nSM = EC_MAXSM;
|
||||
/* iterate for every SM type defined */
|
||||
for (iSM = 2 ; iSM <= nSM ; iSM++)
|
||||
{
|
||||
rdl = sizeof(tSM); tSM = 0;
|
||||
/* read SyncManager Communication Type */
|
||||
wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, iSM + 1, FALSE, &rdl, &tSM, EC_TIMEOUTRXM);
|
||||
if (wkc > 0)
|
||||
{
|
||||
if((iSM == 2) && (tSM == 2)) // SM2 has type 2 == mailbox out, this is a bug in the slave!
|
||||
{
|
||||
SMt_bug_add = 1; // try to correct, this works if the types are 0 1 2 3 and should be 1 2 3 4
|
||||
printf("Activated SM type workaround, possible incorrect mapping.\n");
|
||||
}
|
||||
if(tSM)
|
||||
tSM += SMt_bug_add; // only add if SMt > 0
|
||||
|
||||
if (tSM == 3) // outputs
|
||||
{
|
||||
/* read the assign RXPDO */
|
||||
printf(" SM%1d outputs\n addr b index: sub bitl data_type name\n", iSM);
|
||||
Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].outputs - (uint8 *)&IOmap[0]), outputs_bo );
|
||||
outputs_bo += Tsize;
|
||||
}
|
||||
if (tSM == 4) // inputs
|
||||
{
|
||||
/* read the assign TXPDO */
|
||||
printf(" SM%1d inputs\n addr b index: sub bitl data_type name\n", iSM);
|
||||
Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].inputs - (uint8 *)&IOmap[0]), inputs_bo );
|
||||
inputs_bo += Tsize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* found some I/O bits ? */
|
||||
if ((outputs_bo > 0) || (inputs_bo > 0))
|
||||
retVal = 1;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset)
|
||||
{
|
||||
uint16 a , w, c, e, er, Size;
|
||||
uint8 eectl;
|
||||
uint16 obj_idx;
|
||||
uint8 obj_subidx;
|
||||
uint8 obj_name;
|
||||
uint8 obj_datatype;
|
||||
uint8 bitlen;
|
||||
int totalsize;
|
||||
ec_eepromPDOt eepPDO;
|
||||
ec_eepromPDOt *PDO;
|
||||
int abs_offset, abs_bit;
|
||||
char str_name[EC_MAXNAME + 1];
|
||||
|
||||
eectl = ec_slave[slave].eep_pdi;
|
||||
Size = 0;
|
||||
totalsize = 0;
|
||||
PDO = &eepPDO;
|
||||
PDO->nPDO = 0;
|
||||
PDO->Length = 0;
|
||||
PDO->Index[1] = 0;
|
||||
for (c = 0 ; c < EC_MAXSM ; c++) PDO->SMbitsize[c] = 0;
|
||||
if (t > 1)
|
||||
t = 1;
|
||||
PDO->Startpos = ec_siifind(slave, ECT_SII_PDO + t);
|
||||
if (PDO->Startpos > 0)
|
||||
{
|
||||
a = PDO->Startpos;
|
||||
w = ec_siigetbyte(slave, a++);
|
||||
w += (ec_siigetbyte(slave, a++) << 8);
|
||||
PDO->Length = w;
|
||||
c = 1;
|
||||
/* traverse through all PDOs */
|
||||
do
|
||||
{
|
||||
PDO->nPDO++;
|
||||
PDO->Index[PDO->nPDO] = ec_siigetbyte(slave, a++);
|
||||
PDO->Index[PDO->nPDO] += (ec_siigetbyte(slave, a++) << 8);
|
||||
PDO->BitSize[PDO->nPDO] = 0;
|
||||
c++;
|
||||
/* number of entries in PDO */
|
||||
e = ec_siigetbyte(slave, a++);
|
||||
PDO->SyncM[PDO->nPDO] = ec_siigetbyte(slave, a++);
|
||||
a++;
|
||||
obj_name = ec_siigetbyte(slave, a++);
|
||||
a += 2;
|
||||
c += 2;
|
||||
if (PDO->SyncM[PDO->nPDO] < EC_MAXSM) /* active and in range SM? */
|
||||
{
|
||||
str_name[0] = 0;
|
||||
if(obj_name)
|
||||
ec_siistring(str_name, slave, obj_name);
|
||||
if (t)
|
||||
printf(" SM%1d RXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name);
|
||||
else
|
||||
printf(" SM%1d TXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name);
|
||||
printf(" addr b index: sub bitl data_type name\n");
|
||||
/* read all entries defined in PDO */
|
||||
for (er = 1; er <= e; er++)
|
||||
{
|
||||
c += 4;
|
||||
obj_idx = ec_siigetbyte(slave, a++);
|
||||
obj_idx += (ec_siigetbyte(slave, a++) << 8);
|
||||
obj_subidx = ec_siigetbyte(slave, a++);
|
||||
obj_name = ec_siigetbyte(slave, a++);
|
||||
obj_datatype = ec_siigetbyte(slave, a++);
|
||||
bitlen = ec_siigetbyte(slave, a++);
|
||||
abs_offset = mapoffset + (bitoffset / 8);
|
||||
abs_bit = bitoffset % 8;
|
||||
|
||||
PDO->BitSize[PDO->nPDO] += bitlen;
|
||||
a += 2;
|
||||
|
||||
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);
|
||||
bitoffset += bitlen;
|
||||
totalsize += bitlen;
|
||||
}
|
||||
PDO->SMbitsize[ PDO->SyncM[PDO->nPDO] ] += PDO->BitSize[PDO->nPDO];
|
||||
Size += PDO->BitSize[PDO->nPDO];
|
||||
c++;
|
||||
}
|
||||
else /* PDO deactivated because SM is 0xff or > EC_MAXSM */
|
||||
{
|
||||
c += 4 * e;
|
||||
a += 8 * e;
|
||||
c++;
|
||||
}
|
||||
if (PDO->nPDO >= (EC_MAXEEPDO - 1)) c = PDO->Length; /* limit number of PDO entries in buffer */
|
||||
}
|
||||
while (c < PDO->Length);
|
||||
}
|
||||
if (eectl) ec_eeprom2pdi(slave); /* if eeprom control was previously pdi then restore */
|
||||
return totalsize;
|
||||
}
|
||||
|
||||
|
||||
int si_map_sii(int slave)
|
||||
{
|
||||
int retVal = 0;
|
||||
int Tsize, outputs_bo, inputs_bo;
|
||||
|
||||
printf("PDO mapping according to SII :\n");
|
||||
|
||||
outputs_bo = 0;
|
||||
inputs_bo = 0;
|
||||
/* read the assign RXPDOs */
|
||||
Tsize = si_siiPDO(slave, 1, (int)(ec_slave[slave].outputs - (uint8*)&IOmap), outputs_bo );
|
||||
outputs_bo += Tsize;
|
||||
/* read the assign TXPDOs */
|
||||
Tsize = si_siiPDO(slave, 0, (int)(ec_slave[slave].inputs - (uint8*)&IOmap), inputs_bo );
|
||||
inputs_bo += Tsize;
|
||||
/* found some I/O bits ? */
|
||||
if ((outputs_bo > 0) || (inputs_bo > 0))
|
||||
retVal = 1;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void si_sdo(int cnt)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
ODlist.Entries = 0;
|
||||
memset(&ODlist, 0, sizeof(ODlist));
|
||||
if( ec_readODlist(cnt, &ODlist))
|
||||
{
|
||||
printf(" CoE Object Description found, %d entries.\n",ODlist.Entries);
|
||||
for( i = 0 ; i < ODlist.Entries ; i++)
|
||||
{
|
||||
ec_readODdescription(i, &ODlist);
|
||||
while(EcatError) printf("%s", ec_elist2string());
|
||||
printf(" Index: %4.4x Datatype: %4.4x Objectcode: %2.2x Name: %s\n",
|
||||
ODlist.Index[i], ODlist.DataType[i], ODlist.ObjectCode[i], ODlist.Name[i]);
|
||||
memset(&OElist, 0, sizeof(OElist));
|
||||
ec_readOE(i, &ODlist, &OElist);
|
||||
while(EcatError) printf("%s", ec_elist2string());
|
||||
for( j = 0 ; j < ODlist.MaxSub[i]+1 ; j++)
|
||||
{
|
||||
if ((OElist.DataType[j] > 0) && (OElist.BitLength[j] > 0))
|
||||
{
|
||||
printf(" Sub: %2.2x Datatype: %4.4x Bitlength: %4.4x Obj.access: %4.4x Name: %s\n",
|
||||
j, OElist.DataType[j], OElist.BitLength[j], OElist.ObjAccess[j], OElist.Name[j]);
|
||||
if ((OElist.ObjAccess[j] & 0x0007))
|
||||
{
|
||||
printf(" Value :%s\n", SDO2string(cnt, ODlist.Index[i], j, OElist.DataType[j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(EcatError) printf("%s", ec_elist2string());
|
||||
}
|
||||
}
|
||||
|
||||
void slaveinfo(char *ifname)
|
||||
{
|
||||
int cnt, i, j, nSM;
|
||||
uint16 ssigen;
|
||||
int expectedWKC;
|
||||
|
||||
printf("Starting slaveinfo\n");
|
||||
|
||||
/* initialise SOEM, bind socket to ifname */
|
||||
if (ec_init(ifname))
|
||||
{
|
||||
printf("ec_init on %s succeeded.\n",ifname);
|
||||
/* find and auto-config slaves */
|
||||
if ( ec_config(FALSE, &IOmap) > 0 )
|
||||
{
|
||||
ec_configdc();
|
||||
while(EcatError) printf("%s", ec_elist2string());
|
||||
printf("%d slaves found and configured.\n",ec_slavecount);
|
||||
expectedWKC = (ec_group[0].outputsWKC * 2) + ec_group[0].inputsWKC;
|
||||
printf("Calculated workcounter %d\n", expectedWKC);
|
||||
/* wait for all slaves to reach SAFE_OP state */
|
||||
ec_statecheck(0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 3);
|
||||
if (ec_slave[0].state != EC_STATE_SAFE_OP )
|
||||
{
|
||||
printf("Not all slaves reached safe operational state.\n");
|
||||
ec_readstate();
|
||||
for(i = 1; i<=ec_slavecount ; i++)
|
||||
{
|
||||
if(ec_slave[i].state != EC_STATE_SAFE_OP)
|
||||
{
|
||||
printf("Slave %d State=%2x StatusCode=%4x : %s\n",
|
||||
i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ec_readstate();
|
||||
for( cnt = 1 ; cnt <= ec_slavecount ; cnt++)
|
||||
{
|
||||
printf("\nSlave:%d\n Name:%s\n Output size: %dbits\n Input size: %dbits\n State: %d\n Delay: %d[ns]\n Has DC: %d\n",
|
||||
cnt, ec_slave[cnt].name, ec_slave[cnt].Obits, ec_slave[cnt].Ibits,
|
||||
ec_slave[cnt].state, ec_slave[cnt].pdelay, ec_slave[cnt].hasdc);
|
||||
if (ec_slave[cnt].hasdc) printf(" DCParentport:%d\n", ec_slave[cnt].parentport);
|
||||
printf(" Activeports:%d.%d.%d.%d\n", (ec_slave[cnt].activeports & 0x01) > 0 ,
|
||||
(ec_slave[cnt].activeports & 0x02) > 0 ,
|
||||
(ec_slave[cnt].activeports & 0x04) > 0 ,
|
||||
(ec_slave[cnt].activeports & 0x08) > 0 );
|
||||
printf(" Configured address: %4.4x\n", ec_slave[cnt].configadr);
|
||||
printf(" Man: %8.8x ID: %8.8x Rev: %8.8x\n", (int)ec_slave[cnt].eep_man, (int)ec_slave[cnt].eep_id, (int)ec_slave[cnt].eep_rev);
|
||||
for(nSM = 0 ; nSM < EC_MAXSM ; nSM++)
|
||||
{
|
||||
if(ec_slave[cnt].SM[nSM].StartAddr > 0)
|
||||
printf(" SM%1d A:%4.4x L:%4d F:%8.8x Type:%d\n",nSM, ec_slave[cnt].SM[nSM].StartAddr, ec_slave[cnt].SM[nSM].SMlength,
|
||||
(int)ec_slave[cnt].SM[nSM].SMflags, ec_slave[cnt].SMtype[nSM]);
|
||||
}
|
||||
for(j = 0 ; j < ec_slave[cnt].FMMUunused ; j++)
|
||||
{
|
||||
printf(" FMMU%1d Ls:%8.8x Ll:%4d Lsb:%d Leb:%d Ps:%4.4x Psb:%d Ty:%2.2x Act:%2.2x\n", j,
|
||||
(int)ec_slave[cnt].FMMU[j].LogStart, ec_slave[cnt].FMMU[j].LogLength, ec_slave[cnt].FMMU[j].LogStartbit,
|
||||
ec_slave[cnt].FMMU[j].LogEndbit, ec_slave[cnt].FMMU[j].PhysStart, ec_slave[cnt].FMMU[j].PhysStartBit,
|
||||
ec_slave[cnt].FMMU[j].FMMUtype, ec_slave[cnt].FMMU[j].FMMUactive);
|
||||
}
|
||||
printf(" FMMUfunc 0:%d 1:%d 2:%d 3:%d\n",
|
||||
ec_slave[cnt].FMMU0func, ec_slave[cnt].FMMU1func, ec_slave[cnt].FMMU2func, ec_slave[cnt].FMMU3func);
|
||||
printf(" MBX length wr: %d rd: %d MBX protocols : %2.2x\n", ec_slave[cnt].mbx_l, ec_slave[cnt].mbx_rl, ec_slave[cnt].mbx_proto);
|
||||
ssigen = ec_siifind(cnt, ECT_SII_GENERAL);
|
||||
/* SII general section */
|
||||
if (ssigen)
|
||||
{
|
||||
ec_slave[cnt].CoEdetails = ec_siigetbyte(cnt, ssigen + 0x07);
|
||||
ec_slave[cnt].FoEdetails = ec_siigetbyte(cnt, ssigen + 0x08);
|
||||
ec_slave[cnt].EoEdetails = ec_siigetbyte(cnt, ssigen + 0x09);
|
||||
ec_slave[cnt].SoEdetails = ec_siigetbyte(cnt, ssigen + 0x0a);
|
||||
if((ec_siigetbyte(cnt, ssigen + 0x0d) & 0x02) > 0)
|
||||
{
|
||||
ec_slave[cnt].blockLRW = 1;
|
||||
ec_slave[0].blockLRW++;
|
||||
}
|
||||
ec_slave[cnt].Ebuscurrent = ec_siigetbyte(cnt, ssigen + 0x0e);
|
||||
ec_slave[cnt].Ebuscurrent += ec_siigetbyte(cnt, ssigen + 0x0f) << 8;
|
||||
ec_slave[0].Ebuscurrent += ec_slave[cnt].Ebuscurrent;
|
||||
}
|
||||
printf(" CoE details: %2.2x FoE details: %2.2x EoE details: %2.2x SoE details: %2.2x\n",
|
||||
ec_slave[cnt].CoEdetails, ec_slave[cnt].FoEdetails, ec_slave[cnt].EoEdetails, ec_slave[cnt].SoEdetails);
|
||||
printf(" Ebus current: %d[mA]\n only LRD/LWR:%d\n",
|
||||
ec_slave[cnt].Ebuscurrent, ec_slave[cnt].blockLRW);
|
||||
if ((ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE) && printSDO)
|
||||
si_sdo(cnt);
|
||||
if(printMAP)
|
||||
{
|
||||
if (ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE)
|
||||
si_map_sdo(cnt);
|
||||
else
|
||||
si_map_sii(cnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No slaves found!\n");
|
||||
}
|
||||
printf("End slaveinfo, close socket\n");
|
||||
/* stop SOEM, close socket */
|
||||
ec_close();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No socket connection on %s\nExcecute as root\n",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 */
|
||||
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");
|
||||
/* Print the list */
|
||||
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);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
set(SOURCES eepromtool.c)
|
||||
add_executable(eepromtool ${SOURCES})
|
||||
add_executable(eepromtool main.c)
|
||||
target_link_libraries(eepromtool soem)
|
||||
install(TARGETS eepromtool DESTINATION bin)
|
|
@ -310,7 +310,7 @@ int eeprom_writealias(int slave, int alias, uint16 crc)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void eepromtool(char *ifname, int slave, int mode, char *fname)
|
||||
void do_eepromtool(char *ifname, int slave, int mode, char *fname)
|
||||
{
|
||||
int w, rc = 0, estart, esize;
|
||||
uint16 *wbuf;
|
||||
|
@ -430,8 +430,9 @@ void eepromtool(char *ifname, int slave, int mode, char *fname)
|
|||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int eepromtool(int argc, char *argv[])
|
||||
{
|
||||
ec_adaptert * adapter = NULL;
|
||||
printf("SOEM (Simple Open EtherCAT Master)\nEEPROM tool\n");
|
||||
|
||||
mode = MODE_NONE;
|
||||
|
@ -452,7 +453,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
/* start tool */
|
||||
eepromtool(argv[1],slave,mode,argv[4]);
|
||||
do_eepromtool(argv[1],slave,mode,argv[4]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -465,6 +466,14 @@ int main(int argc, char *argv[])
|
|||
printf(" -ri read EEPROM, output Intel Hex format\n");
|
||||
printf(" -w write EEPROM, input binary format\n");
|
||||
printf(" -wi write EEPROM, input Intel Hex format\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");
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Licensed under the GNU General Public License version 2 with exceptions. See
|
||||
* LICENSE file in the project root for full license information
|
||||
*/
|
||||
|
||||
#ifndef _EEPROMTOOL_H
|
||||
#define _EEPROMTOOL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int eepromtool(int argc, char *argv[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _EEPROMTOOL_H */
|
|
@ -0,0 +1,7 @@
|
|||
#include "eepromtool.h"
|
||||
#include "osal.h"
|
||||
|
||||
int OSAL_MAIN (int argc, char * argv[])
|
||||
{
|
||||
return eepromtool (argc, argv);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
set(SOURCES simple_test.c)
|
||||
add_executable(simple_test ${SOURCES})
|
||||
add_executable(simple_test main.c)
|
||||
target_link_libraries(simple_test soem)
|
||||
install(TARGETS simple_test DESTINATION bin)
|
|
@ -0,0 +1,7 @@
|
|||
#include "simple_test.h"
|
||||
#include "osal.h"
|
||||
|
||||
int OSAL_MAIN (int argc, char * argv[])
|
||||
{
|
||||
return simple_test (argc, argv);
|
||||
}
|
|
@ -25,7 +25,7 @@ volatile int wkc;
|
|||
boolean inOP;
|
||||
uint8 currentgroup = 0;
|
||||
|
||||
void simpletest(char *ifname)
|
||||
void do_simpletest(char *ifname)
|
||||
{
|
||||
int i, j, oloop, iloop, chk;
|
||||
needlf = FALSE;
|
||||
|
@ -220,21 +220,29 @@ OSAL_THREAD_FUNC ecatcheck( void *ptr )
|
|||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int simple_test(int argc, char *argv[])
|
||||
{
|
||||
ec_adaptert * adapter = NULL;
|
||||
printf("SOEM (Simple Open EtherCAT Master)\nSimple test\n");
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
/* create thread to handle slave error handling in OP */
|
||||
// pthread_create( &thread1, NULL, (void *) &ecatcheck, (void*) &ctime);
|
||||
osal_thread_create(&thread1, 128000, &ecatcheck, (void*) &ctime);
|
||||
osal_thread_create(&thread1, 128000, &ecatcheck, NULL);
|
||||
/* start cyclic part */
|
||||
simpletest(argv[1]);
|
||||
do_simpletest(argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Usage: simple_test ifname1\nifname = eth0 for example\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");
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Licensed under the GNU General Public License version 2 with exceptions. See
|
||||
* LICENSE file in the project root for full license information
|
||||
*/
|
||||
|
||||
#ifndef _SIMPLE_TEST_H
|
||||
#define _SIMPLE_TEST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int simple_test(int argc, char *argv[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SIMPLE_TEST_H */
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
set(SOURCES slaveinfo.c)
|
||||
add_executable(slaveinfo ${SOURCES})
|
||||
add_executable(slaveinfo main.c)
|
||||
target_link_libraries(slaveinfo soem)
|
||||
install(TARGETS slaveinfo DESTINATION bin)
|
|
@ -0,0 +1,7 @@
|
|||
#include "slaveinfo.h"
|
||||
#include "osal.h"
|
||||
|
||||
int OSAL_MAIN (int argc, char * argv[])
|
||||
{
|
||||
return slaveinfo (argc, argv);
|
||||
}
|
|
@ -1,3 +1,8 @@
|
|||
/*
|
||||
* Licensed under the GNU General Public License version 2 with exceptions. See
|
||||
* LICENSE file in the project root for full license information
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Example code for Simple Open EtherCAT master
|
||||
*
|
||||
|
@ -7,10 +12,10 @@
|
|||
* Optional -map to display slave PDO mapping
|
||||
*
|
||||
* This shows the configured slave data.
|
||||
*
|
||||
* (c)Arthur Ketels 2010 - 2011
|
||||
*/
|
||||
|
||||
#include "slaveinfo.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -505,7 +510,7 @@ void si_sdo(int cnt)
|
|||
}
|
||||
}
|
||||
|
||||
void slaveinfo(char *ifname)
|
||||
void do_slaveinfo(char *ifname)
|
||||
{
|
||||
int cnt, i, j, nSM;
|
||||
uint16 ssigen;
|
||||
|
@ -617,9 +622,7 @@ void slaveinfo(char *ifname)
|
|||
}
|
||||
}
|
||||
|
||||
char ifbuf[1024];
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int slaveinfo(int argc, char *argv[])
|
||||
{
|
||||
ec_adaptert * adapter = NULL;
|
||||
printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n");
|
||||
|
@ -629,8 +632,7 @@ int main(int argc, char *argv[])
|
|||
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 */
|
||||
strcpy(ifbuf, argv[1]);
|
||||
slaveinfo(ifbuf);
|
||||
do_slaveinfo(argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Licensed under the GNU General Public License version 2 with exceptions. See
|
||||
* LICENSE file in the project root for full license information
|
||||
*/
|
||||
|
||||
#ifndef _SLAVEINFO_H
|
||||
#define _SLAVEINFO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int slaveinfo(int argc, char *argv[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SLAVEINFO_H */
|
Loading…
Reference in New Issue