Start to add iocsh cmds..
This commit is contained in:
@@ -56,6 +56,8 @@ SOURCES += $(APPSRC)/ecmcCANOpenPDO.cpp
|
||||
SOURCES += $(APPSRC)/ecmcCANOpenDevice.cpp
|
||||
SOURCES += $(APPSRC)/ecmcCANOpenMaster.cpp
|
||||
|
||||
DBDS += $(APPSRC)/ecmcSocketCAN.dbd
|
||||
|
||||
db:
|
||||
|
||||
.PHONY: db
|
||||
|
||||
@@ -56,6 +56,8 @@ SOURCES += $(APPSRC)/ecmcCANOpenPDO.cpp
|
||||
SOURCES += $(APPSRC)/ecmcCANOpenDevice.cpp
|
||||
SOURCES += $(APPSRC)/ecmcCANOpenMaster.cpp
|
||||
|
||||
DBDS += $(APPSRC)/ecmcSocketCAN.dbd
|
||||
|
||||
db:
|
||||
|
||||
.PHONY: db
|
||||
|
||||
@@ -32,7 +32,7 @@ ecmcCANOpenDevice::ecmcCANOpenDevice(ecmcSocketCANWriteBuffer* writeBuffer,
|
||||
errorCode_ = 0;
|
||||
dbgMode_ = dbgMode;
|
||||
name_ = strdup(name);
|
||||
|
||||
isMaster_ = false;
|
||||
pdoCounter_ = 0;
|
||||
sdoCounter_ = 0;
|
||||
|
||||
@@ -77,7 +77,8 @@ void ecmcCANOpenDevice::execute() {
|
||||
// new rx frame recived!
|
||||
void ecmcCANOpenDevice::newRxFrame(can_frame *frame) {
|
||||
|
||||
if (!validateFrame(frame)) {
|
||||
// only validate if not master
|
||||
if (!validateFrame(frame) && !isMaster_) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ class ecmcCANOpenDevice {
|
||||
char* name_;
|
||||
ecmcCANOpenPDO *pdos_[ECMC_CAN_DEVICE_PDO_MAX_COUNT];
|
||||
ecmcCANOpenSDO *sdos_[ECMC_CAN_DEVICE_SDO_MAX_COUNT];
|
||||
bool isMaster_;
|
||||
};
|
||||
|
||||
#endif /* ECMC_CANOPEN_DEVICE_H_ */
|
||||
|
||||
@@ -32,8 +32,10 @@ ecmcCANOpenMaster::ecmcCANOpenMaster(ecmcSocketCANWriteBuffer* writeBuffer,
|
||||
lssPdo_ = NULL;
|
||||
syncPdo_ = NULL;
|
||||
heartPdo_ = NULL;
|
||||
int errorCode = 0;
|
||||
isMaster_ = true;
|
||||
|
||||
int errorCode = 0;
|
||||
|
||||
// lssPdo_ = new ecmcCANOpenPDO( writeBuffer_, 0x7E5,DIR_WRITE,0,0,1000,exeSampleTimeMs_,"lss", cfgDbgMode_);
|
||||
errorCode = addPDO(0x7E5, // uint32_t cobId,
|
||||
DIR_WRITE, // ecmc_can_direction rw,
|
||||
|
||||
@@ -39,7 +39,7 @@ class ecmcCANOpenMaster : public ecmcCANOpenDevice {
|
||||
private:
|
||||
ecmcCANOpenPDO *lssPdo_;
|
||||
ecmcCANOpenPDO *syncPdo_;
|
||||
ecmcCANOpenPDO *heartPdo_;
|
||||
ecmcCANOpenPDO *heartPdo_;
|
||||
};
|
||||
|
||||
#endif /* ECMC_CANOPEN_MASTER_H_ */
|
||||
|
||||
@@ -613,4 +613,4 @@ std::string ecmcSocketCAN::to_string(int value) {
|
||||
// return asynError;*/
|
||||
// return asynSuccess;
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
registrar("ecmcCANPluginDriverRegister")
|
||||
@@ -19,6 +19,17 @@
|
||||
#include "ecmcSocketCANWrap.h"
|
||||
#include "ecmcSocketCAN.h"
|
||||
#include "ecmcSocketCANDefs.h"
|
||||
#include <epicsTypes.h>
|
||||
#include <epicsTime.h>
|
||||
#include <epicsThread.h>
|
||||
#include <epicsString.h>
|
||||
#include <epicsTimer.h>
|
||||
#include <epicsMutex.h>
|
||||
#include <epicsExport.h>
|
||||
#include <epicsEvent.h>
|
||||
|
||||
#include <iocsh.h>
|
||||
|
||||
|
||||
#define ECMC_PLUGIN_MAX_PORTNAME_CHARS 64
|
||||
#define ECMC_PLUGIN_PORTNAME_PREFIX "PLUGIN.CAN"
|
||||
@@ -133,3 +144,184 @@ void deleteSocketCAN() {
|
||||
delete (can);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* EPICS iocsh shell command: ecmcCANOpenAddMaster
|
||||
*/
|
||||
|
||||
void ecmcCANOpenAddMasterPrintHelp() {
|
||||
printf("\n");
|
||||
printf(" Use \"ecmcCANOpenAddMaster(<name>, <node id>\n");
|
||||
printf(" <name> : Name of master device.\n");
|
||||
printf(" <node id> : CANOpen node id of master.\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int ecmcCANOpenAddMaster(const char* name, int nodeId) {
|
||||
if(!name) {
|
||||
printf("Error: name.\n");
|
||||
ecmcCANOpenAddMasterPrintHelp();
|
||||
return asynError;
|
||||
}
|
||||
|
||||
if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
|
||||
ecmcCANOpenAddMasterPrintHelp();
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
/* CODE HERE*/
|
||||
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
static const iocshArg initArg0_0 =
|
||||
{ "Name", iocshArgString };
|
||||
static const iocshArg initArg1_0 =
|
||||
{ "Node Id", iocshArgInt };
|
||||
|
||||
static const iocshArg *const initArgs_0[] = { &initArg0_0,
|
||||
&initArg1_0};
|
||||
|
||||
static const iocshFuncDef initFuncDef_0 = { "ecmcCANOpenAddMaster", 2, initArgs_0 };
|
||||
static void initCallFunc_0(const iocshArgBuf *args) {
|
||||
ecmcCANOpenAddMaster(args[0].sval, args[1].ival);
|
||||
}
|
||||
|
||||
/**
|
||||
* EPICS iocsh shell command: ecmcCANOpenAddDevice
|
||||
*/
|
||||
|
||||
void ecmcCANOpenAddDevicePrintHelp() {
|
||||
printf("\n");
|
||||
printf(" Use \"ecmcCANOpenAddDevice(<name>, <node id>\n");
|
||||
printf(" <name> : Name of device.\n");
|
||||
printf(" <node id> : CANOpen node id of master.\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int ecmcCANOpenAddDevice(const char* name, int nodeId) {
|
||||
if(!name) {
|
||||
printf("Error: name.\n");
|
||||
ecmcCANOpenAddDevicePrintHelp();
|
||||
return asynError;
|
||||
}
|
||||
|
||||
if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
|
||||
ecmcCANOpenAddDevicePrintHelp();
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
/* CODE HERE*/
|
||||
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
static const iocshArg initArg0_1 =
|
||||
{ "Name", iocshArgString };
|
||||
static const iocshArg initArg1_1 =
|
||||
{ "Node Id", iocshArgInt };
|
||||
|
||||
static const iocshArg *const initArgs_1[] = { &initArg0_1,
|
||||
&initArg1_1};
|
||||
|
||||
static const iocshFuncDef initFuncDef_1 = { "ecmcCANOpenAddDevice", 2, initArgs_1 };
|
||||
static void initCallFunc_1(const iocshArgBuf *args) {
|
||||
ecmcCANOpenAddDevice(args[0].sval, args[1].ival);
|
||||
}
|
||||
|
||||
/**
|
||||
* EPICS iocsh shell command: ecmcCANOpenAddSDO
|
||||
*/
|
||||
|
||||
void ecmcCANOpenAddSDOPrintHelp() {
|
||||
printf("\n");
|
||||
printf(" Use \"ecmcCANOpenAddSDO(<name>, <node id>\n");
|
||||
printf(" <name> : Name of master device.\n");
|
||||
printf(" <node id> : CANOpen node id of master.\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int ecmcCANOpenAddSDO(const char* name, int nodeId) {
|
||||
if(!name) {
|
||||
printf("Error: name.\n");
|
||||
ecmcCANOpenAddSDOPrintHelp();
|
||||
return asynError;
|
||||
}
|
||||
|
||||
if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
|
||||
ecmcCANOpenAddSDOPrintHelp();
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
/* CODE HERE*/
|
||||
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
static const iocshArg initArg0_2 =
|
||||
{ "Name", iocshArgString };
|
||||
static const iocshArg initArg1_2 =
|
||||
{ "Node Id", iocshArgInt };
|
||||
|
||||
static const iocshArg *const initArgs_2[] = { &initArg0_2,
|
||||
&initArg1_2};
|
||||
|
||||
static const iocshFuncDef initFuncDef_2 = { "ecmcCANOpenAddSDO", 2, initArgs_2 };
|
||||
static void initCallFunc_2(const iocshArgBuf *args) {
|
||||
ecmcCANOpenAddSDO(args[0].sval, args[1].ival);
|
||||
}
|
||||
|
||||
/**
|
||||
* EPICS iocsh shell command: ecmcCANOpenAddPDO
|
||||
*/
|
||||
|
||||
void ecmcCANOpenAddPDOPrintHelp() {
|
||||
printf("\n");
|
||||
printf(" Use \"ecmcCANOpenAddPDO(<name>, <node id>\n");
|
||||
printf(" <name> : Name of master device.\n");
|
||||
printf(" <node id> : CANOpen node id of master.\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int ecmcCANOpenAddPDO(const char* name, int nodeId) {
|
||||
if(!name) {
|
||||
printf("Error: name.\n");
|
||||
ecmcCANOpenAddPDOPrintHelp();
|
||||
return asynError;
|
||||
}
|
||||
|
||||
if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
|
||||
ecmcCANOpenAddPDOPrintHelp();
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
/* CODE HERE*/
|
||||
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
static const iocshArg initArg0_3 =
|
||||
{ "Name", iocshArgString };
|
||||
static const iocshArg initArg1_3 =
|
||||
{ "Node Id", iocshArgInt };
|
||||
|
||||
static const iocshArg *const initArgs_3[] = { &initArg0_3,
|
||||
&initArg1_3};
|
||||
|
||||
static const iocshFuncDef initFuncDef_3 = { "ecmcCANOpenAddPDO", 2, initArgs_3 };
|
||||
static void initCallFunc_3(const iocshArgBuf *args) {
|
||||
ecmcCANOpenAddPDO(args[0].sval, args[1].ival);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all functions
|
||||
*/
|
||||
void ecmcCANPluginDriverRegister(void) {
|
||||
iocshRegister(&initFuncDef_0, initCallFunc_0); // ecmcCANOpenAddMaster
|
||||
iocshRegister(&initFuncDef_1, initCallFunc_1); // ecmcCANOpenAddDevice
|
||||
iocshRegister(&initFuncDef_2, initCallFunc_2); // ecmcCANOpenAddSDO
|
||||
iocshRegister(&initFuncDef_3, initCallFunc_3); // ecmcCANOpenAddPDO
|
||||
}
|
||||
|
||||
epicsExportRegistrar(ecmcCANPluginDriverRegister);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
IOC_TEST:PLC-0-enable
|
||||
REQMOD:mcag-trgt-muts--11838:MODULES
|
||||
REQMOD:mcag-trgt-muts--11838:VERSIONS
|
||||
REQMOD:mcag-trgt-muts--11838:MOD_VER
|
||||
REQMOD:mcag-trgt-muts--11838:exit
|
||||
REQMOD:mcag-trgt-muts--11838:BaseVersion
|
||||
REQMOD:mcag-trgt-muts--11838:require_VER
|
||||
REQMOD:mcag-trgt-muts--11838:ecmccfg_VER
|
||||
REQMOD:mcag-trgt-muts--11838:asyn_VER
|
||||
REQMOD:mcag-trgt-muts--11838:exprtk_VER
|
||||
REQMOD:mcag-trgt-muts--11838:motor_VER
|
||||
REQMOD:mcag-trgt-muts--11838:ecmc_VER
|
||||
REQMOD:mcag-trgt-muts--16738:MODULES
|
||||
REQMOD:mcag-trgt-muts--16738:VERSIONS
|
||||
REQMOD:mcag-trgt-muts--16738:MOD_VER
|
||||
REQMOD:mcag-trgt-muts--16738:exit
|
||||
REQMOD:mcag-trgt-muts--16738:BaseVersion
|
||||
REQMOD:mcag-trgt-muts--16738:require_VER
|
||||
REQMOD:mcag-trgt-muts--16738:ecmccfg_VER
|
||||
REQMOD:mcag-trgt-muts--16738:asyn_VER
|
||||
REQMOD:mcag-trgt-muts--16738:exprtk_VER
|
||||
REQMOD:mcag-trgt-muts--16738:motor_VER
|
||||
REQMOD:mcag-trgt-muts--16738:ecmc_VER
|
||||
REQMOD:mcag-trgt-muts--16738:ecmc_plugin_socketcan_VER
|
||||
IOC_TEST:PLC-0-scantime
|
||||
IOC_TEST:PLC-0-error
|
||||
|
||||
@@ -21,7 +21,7 @@ $(ECMCCFG_INIT)$(SCRIPTEXEC) ${ecmccfg_DIR}startup.cmd, "IOC=$(IOC),ECMC_VER=6.3
|
||||
|
||||
##############################################################################
|
||||
## Load plugin:
|
||||
#require ecmc_plugin_advanced master # do not require then loaded twice..
|
||||
require ecmc_plugin_socketcan master # do not require then loaded twice..
|
||||
|
||||
epicsEnvSet(ECMC_PLUGIN_FILNAME,"/home/dev/epics/base-7.0.4/require/${E3_REQUIRE_VERSION}/siteMods/ecmc_plugin_socketcan/master/lib/${EPICS_HOST_ARCH=linux-x86_64}/libecmc_plugin_socketcan.so")
|
||||
epicsEnvSet(ECMC_PLUGIN_CONFIG,"IF=can0;DBG_PRINT=1;") # Only one option implemented in this plugin
|
||||
|
||||
Reference in New Issue
Block a user