Skip to content

Commit

Permalink
Merge pull request #22 from anderssandstrom/master
Browse files Browse the repository at this point in the history
Strings as plc func args, new plugin if
  • Loading branch information
anderssandstrom authored May 27, 2020
2 parents 9660dda + a12ab86 commit ba7dd3f
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 60 deletions.
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Release Notes
===
# ECMC 6.2.1
* Add exprtk support for plc functions with stings as args (need ess-exprtk 1.2.1)
* Add possabilty ti use plc-functions with strings a sarguments in plugins
* Expose ecmc epics ioc state to plugins
* Add plugin for pvAccess in ecmc plc:s: https://github.com/anderssandstrom/e3-ecmcPlugin_Utils

# ECMC 6.2

### Add plugin support
Expand Down
78 changes: 49 additions & 29 deletions devEcmcSup/plc/ecmcPLCTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,9 @@ bool ecmcPLCTask::findPluginFunction(ecmcPluginLib* plugin, const char *exprStr)
int argCount = plugin->findArgCount(data->funcs[i]);
if(!data->funcs[i].funcName ||
strlen(data->funcs[i].funcName) == 0 ||
argCount < 0 ||
argCount > ECMC_PLUGIN_MAX_PLC_ARG_COUNT ){
((argCount < 0 ||
argCount > ECMC_PLUGIN_MAX_PLC_ARG_COUNT) &&
data->funcs[i].funcGenericObj==NULL)){
break;
}

Expand Down Expand Up @@ -644,39 +645,58 @@ int ecmcPLCTask::loadPluginLib(ecmcPluginLib* plugin){
}

for(int i = 0; i < ECMC_PLUGIN_MAX_PLC_FUNC_COUNT; ++i){

int argCount = plugin->findArgCount(data->funcs[i]);
if(!data->funcs[i].funcName ||
strlen(data->funcs[i].funcName) == 0 ||
argCount < 0 ||
argCount > ECMC_PLUGIN_MAX_PLC_ARG_COUNT ){
((argCount < 0 ||
argCount > ECMC_PLUGIN_MAX_PLC_ARG_COUNT) &&
data->funcs[i].funcGenericObj==NULL)){
break;
}
switch(argCount) {
case 0:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg0);
break;
case 1:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg1);
break;
case 2:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg2);
break;
case 3:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg3);
break;
case 4:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg4);
break;
case 5:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg5);
break;
case 6:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg6);
break;
default:
break;

if(data->funcs[i].funcGenericObj && strlen(data->funcs[i].funcName) > 0) {
// load generic_function_t generic func object (allow strings)
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcGenericObj);
}
else {
switch(argCount) {
case 0:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg0);
break;
case 1:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg1);
break;
case 2:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg2);
break;
case 3:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg3);
break;
case 4:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg4);
break;
case 5:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg5);
break;
case 6:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg6);
break;
case 7:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg7);
break;
case 8:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg8);
break;
case 9:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg9);
break;
case 10:
ecmcPLCTaskAddFunction(data->funcs[i].funcName,data->funcs[i].funcArg10);
break;
default:
break;
}
}
}

// Load constants
Expand Down
8 changes: 8 additions & 0 deletions devEcmcSup/plugin/ecmcPluginClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ double getEcmcSampleTimeMS() {
//mcuPeriod is in nano seconds
return mcuPeriod/1000;
}

int getEcmcEpicsIOCState() {
if(!asynPort) {
return -1;
}
return asynPort->getEpicsState();
}

8 changes: 8 additions & 0 deletions devEcmcSup/plugin/ecmcPluginClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ double getEcmcSampleRate();
*/
double getEcmcSampleTimeMS();

/** \brief Get ecmc IOC state (hook)
*
* \return IOC state as int \n
*
* \note There's no ascii command in ecmcCmdParser.c for this method.\n
*/
int getEcmcEpicsIOCState();

# ifdef __cplusplus
}
# endif // ifdef __cplusplus
Expand Down
5 changes: 3 additions & 2 deletions devEcmcSup/plugin/ecmcPluginDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#define ECMC_PLUGIN_MAX_PLC_FUNC_COUNT 64
#define ECMC_PLUGIN_MAX_PLC_CONST_COUNT 64
#define ECMC_PLUGIN_MAX_PLC_ARG_COUNT 10
#define ECMC_PLUG_VER_MAJOR 0
#define ECMC_PLUG_VER_MINOR 2
#define ECMC_PLUG_VER_MAJOR 1
#define ECMC_PLUG_VER_MINOR 0
#define ECMC_PLUG_VER_PATCH 0
#define ECMC_PLUG_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
#define ECMC_PLUG_VERSION_MAGIC ECMC_PLUG_VERSION(ECMC_PLUG_VER_MAJOR, ECMC_PLUG_VER_MINOR, ECMC_PLUG_VER_PATCH)
Expand All @@ -42,6 +42,7 @@ struct ecmcOnePlcFunc {
double (*funcArg8)(double,double,double,double,double,double,double,double);
double (*funcArg9)(double,double,double,double,double,double,double,double,double);
double (*funcArg10)(double,double,double,double,double,double,double,double,double,double);
void* funcGenericObj; // generic_function_t generic Func object (allow strings)
};

// Structure for defining one custom plc constant
Expand Down
74 changes: 46 additions & 28 deletions devEcmcSup/plugin/ecmcPluginLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int ecmcPluginLib::load(const char* libFilenameWP, const char* libConfigStr) {

// Ensure that file exist
if(access( libFilenameWP, 0 )!= 0){
LOGERR("%s/%s:%d: Error: PllibFilenameWP_gin %s: File not found (0x%x) .\n",
LOGERR("%s/%s:%d: Error: Plugin %s: File not found (0x%x) .\n",
__FILE__, __FUNCTION__, __LINE__,
libFilenameWP,ERROR_PLUGIN_FLIE_NOT_FOUND);
return setErrorID(ERROR_PLUGIN_FLIE_NOT_FOUND);
Expand Down Expand Up @@ -175,8 +175,8 @@ void ecmcPluginLib::report() {
int argCount = findArgCount(data_->funcs[i]);
if(!data_->funcs[i].funcName ||
strlen(data_->funcs[i].funcName) == 0 ||
argCount > ECMC_PLUGIN_MAX_PLC_ARG_COUNT ||
argCount < 0){
((argCount > ECMC_PLUGIN_MAX_PLC_ARG_COUNT ||
argCount < 0) && data_->funcs[i].funcGenericObj==NULL)){
break;
}

Expand All @@ -198,31 +198,49 @@ void ecmcPluginLib::report() {
data_->funcs[i].funcName,
protoBuffer);
printf(" Desc = %s\n",data_->funcs[i].funcDesc);
printf(" Arg count = %d\n",argCount);
switch(argCount) {
case 0:
printf(" func = @%p\n",data_->funcs[i].funcArg0);
break;
case 1:
printf(" func = @%p\n",data_->funcs[i].funcArg1);
break;
case 2:
printf(" func = @%p\n",data_->funcs[i].funcArg2);
break;
case 3:
printf(" func = @%p\n",data_->funcs[i].funcArg3);
break;
case 4:
printf(" func = @%p\n",data_->funcs[i].funcArg4);
break;
case 5:
printf(" func = @%p\n",data_->funcs[i].funcArg5);
break;
case 6:
printf(" func = @%p\n",data_->funcs[i].funcArg6);
break;
default:
break;
// generic_function_t generic func object (allow strings)
if(data_->funcs[i].funcGenericObj) {
printf(" func = @%p\n",data_->funcs[i].funcGenericObj);
}
else {
printf(" Arg count = %d\n",argCount);
switch(argCount) {
case 0:
printf(" func = @%p\n",data_->funcs[i].funcArg0);
break;
case 1:
printf(" func = @%p\n",data_->funcs[i].funcArg1);
break;
case 2:
printf(" func = @%p\n",data_->funcs[i].funcArg2);
break;
case 3:
printf(" func = @%p\n",data_->funcs[i].funcArg3);
break;
case 4:
printf(" func = @%p\n",data_->funcs[i].funcArg4);
break;
case 5:
printf(" func = @%p\n",data_->funcs[i].funcArg5);
break;
case 6:
printf(" func = @%p\n",data_->funcs[i].funcArg6);
break;
case 7:
printf(" func = @%p\n",data_->funcs[i].funcArg7);
break;
case 8:
printf(" func = @%p\n",data_->funcs[i].funcArg8);
break;
case 9:
printf(" func = @%p\n",data_->funcs[i].funcArg9);
break;
case 10:
printf(" func = @%p\n",data_->funcs[i].funcArg10);
break;
default:
break;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion exprtkSupport

0 comments on commit ba7dd3f

Please sign in to comment.