From bdc3c3c93dd995c22ea2c71807e580e0e4e3416b Mon Sep 17 00:00:00 2001 From: Davide Marcato Date: Sat, 16 Oct 2021 16:51:28 +0200 Subject: [PATCH 1/3] Add asynInterposeDummy --- asyn/Makefile | 2 + asyn/miscellaneous/asyn.dbd | 1 + asyn/miscellaneous/asynInterposeDummy.c | 153 ++++++++++++++++++++++++ asyn/miscellaneous/asynInterposeDummy.h | 72 +++++++++++ 4 files changed, 228 insertions(+) create mode 100644 asyn/miscellaneous/asynInterposeDummy.c create mode 100644 asyn/miscellaneous/asynInterposeDummy.h diff --git a/asyn/Makefile b/asyn/Makefile index 889eff333..071379841 100644 --- a/asyn/Makefile +++ b/asyn/Makefile @@ -102,6 +102,7 @@ DBD += asyn.dbd INC += asynShellCommands.h INC += asynInterposeCom.h INC += asynInterposeEos.h +INC += asynInterposeDummy.h INC += asynInterposeFlush.h ifneq ($(EPICS_LIBCOM_ONLY),YES) asyn_SRCS += asynShellCommands.c @@ -111,6 +112,7 @@ asyn_SRCS += asynInterposeEos.c asyn_SRCS += asynInterposeFlush.c asyn_SRCS += asynInterposeDelay.c asyn_SRCS += asynInterposeEcho.c +asyn_SRCS += asynInterposeDummy.c SRC_DIRS += $(ASYN)/asynPortDriver/exceptions INC += ParamListInvalidIndex.h diff --git a/asyn/miscellaneous/asyn.dbd b/asyn/miscellaneous/asyn.dbd index ca23a6723..70d1fdedd 100644 --- a/asyn/miscellaneous/asyn.dbd +++ b/asyn/miscellaneous/asyn.dbd @@ -3,6 +3,7 @@ registrar(asynInterposeFlushRegister) registrar(asynInterposeEosRegister) registrar(asynInterposeDelayRegister) registrar(asynInterposeEchoRegister) +registrar(asynInterposeDummyRegister) # # The following ties this to EPICS records. diff --git a/asyn/miscellaneous/asynInterposeDummy.c b/asyn/miscellaneous/asynInterposeDummy.c new file mode 100644 index 000000000..30800f65e --- /dev/null +++ b/asyn/miscellaneous/asynInterposeDummy.c @@ -0,0 +1,153 @@ +/*asynInterposeDummy.c*/ + +/* + * Example of an asynInterpose implementation + * The dummy implementation does *nothing*, + * simply forwards requests to the lower port. + * + * Use this as as a base example to build your asynInterpose. + * + * Author: davide.marcato@lnl.infn.it + */ + +#include "asynInterposeDummy.h" + +ASYN_API +int asynInterposeDummyConfig(const char *portName) { + interposePvt *pvt; + asynInterface *plowerLevelInterface; + asynStatus status; + asynUser *pasynUser; + int addr = 0; + /* + * Interpose ourselves + */ + pvt = callocMustSucceed(1, sizeof(interposePvt), "asynInterposeEcho"); + pvt->portName = epicsStrDup(portName); + pvt->dummyInterface.interfaceType = asynOctetType; + pvt->dummyInterface.pinterface = &octet; + pvt->dummyInterface.drvPvt = pvt; + pasynUser = pasynManager->createAsynUser(0, 0); + pvt->pasynUser = pasynUser; + pvt->pasynUser->userPvt = pvt; + + // Connect + status = pasynManager->connectDevice(pasynUser, portName, addr); + if (status != asynSuccess) { + printf("%s connectDevice failed\n", portName); + pasynManager->freeAsynUser(pasynUser); + free(pvt); + return -1; + } + + // Add callback + status = pasynManager->exceptionCallbackAdd(pasynUser, ExceptionHandler); + if (status != asynSuccess) { + printf("%s exceptionCallbackAdd failed\n", portName); + pasynManager->freeAsynUser(pasynUser); + free(pvt); + return -1; + } + + // Interpose port + status = + pasynManager->interposeInterface(portName, addr, &pvt->dummyInterface, &plowerLevelInterface); + if (status != asynSuccess) { + printf("%s interposeInterface failed\n", portName); + pasynManager->exceptionCallbackRemove(pasynUser); + pasynManager->freeAsynUser(pasynUser); + free(pvt); + return -1; + } + pvt->poctet = (asynOctet *)plowerLevelInterface->pinterface; + pvt->octetPvt = plowerLevelInterface->drvPvt; + + return (0); +} + +// Catch all exceptions +static void ExceptionHandler(asynUser *pasynUser, asynException exception) { + // On connections/disconnections + // Occurs every streamdevice transaction + if (exception == asynExceptionConnect) { + // Default = do nothing + } +} + +/** + * asynOctet methods + */ + +static asynStatus writeIt(void *ppvt, asynUser *pasynUser, const char *data, size_t numchars, + size_t *nbytesTransfered) { + interposePvt *pvt = (interposePvt *)ppvt; + + // Write on underlying port + return pvt->poctet->write(pvt->octetPvt, pasynUser, data, numchars, nbytesTransfered); +} + +static asynStatus readIt(void *ppvt, asynUser *pasynUser, char *data, size_t maxchars, + size_t *nbytesTransfered, int *eomReason) { + interposePvt *pvt = (interposePvt *)ppvt; + + // Read from underlying port + return pvt->poctet->read(pvt->octetPvt, pasynUser, data, maxchars, nbytesTransfered, eomReason); +} + +static asynStatus flushIt(void *ppvt, asynUser *pasynUser) { + interposePvt *pvt = (interposePvt *)ppvt; + return pvt->poctet->flush(pvt->octetPvt, pasynUser); +} + +static asynStatus registerInterruptUser(void *ppvt, asynUser *pasynUser, + interruptCallbackOctet callback, void *userPvt, + void **registrarPvt) { + interposePvt *pvt = (interposePvt *)ppvt; + return pvt->poctet->registerInterruptUser(pvt->octetPvt, pasynUser, callback, userPvt, + registrarPvt); +} + +static asynStatus cancelInterruptUser(void *ppvt, asynUser *pasynUser, void *registrarPvt) { + interposePvt *pvt = (interposePvt *)ppvt; + return pvt->poctet->cancelInterruptUser(pvt->octetPvt, pasynUser, registrarPvt); +} + +static asynStatus setInputEos(void *ppvt, asynUser *pasynUser, const char *eos, int eoslen) { + interposePvt *pvt = (interposePvt *)ppvt; + return pvt->poctet->setInputEos(pvt->octetPvt, pasynUser, eos, eoslen); +} + +static asynStatus getInputEos(void *ppvt, asynUser *pasynUser, char *eos, int eossize, + int *eoslen) { + interposePvt *pvt = (interposePvt *)ppvt; + return pvt->poctet->getInputEos(pvt->octetPvt, pasynUser, eos, eossize, eoslen); +} + +static asynStatus setOutputEos(void *ppvt, asynUser *pasynUser, const char *eos, int eoslen) { + interposePvt *pvt = (interposePvt *)ppvt; + return pvt->poctet->setOutputEos(pvt->octetPvt, pasynUser, eos, eoslen); +} + +static asynStatus getOutputEos(void *ppvt, asynUser *pasynUser, char *eos, int eossize, + int *eoslen) { + interposePvt *pvt = (interposePvt *)ppvt; + return pvt->poctet->getOutputEos(pvt->octetPvt, pasynUser, eos, eossize, eoslen); +} + +/* register asynInterposeDummyConfig*/ +static const iocshArg asynInterposeDummyConfigArg0 = {"portName", iocshArgString}; +static const iocshArg *asynInterposeDummyConfigArgs[] = {&asynInterposeDummyConfigArg0}; +static const iocshFuncDef asynInterposeDummyConfigFuncDef = {"asynInterposeDummyConfig", 1, + asynInterposeDummyConfigArgs}; +static void asynInterposeDummyConfigCallFunc(const iocshArgBuf *args) { + asynInterposeDummyConfig(args[0].sval); +} + +static void asynInterposeDummyRegister(void) { + static int firstTime = 1; + if (firstTime) { + firstTime = 0; + iocshRegister(&asynInterposeDummyConfigFuncDef, asynInterposeDummyConfigCallFunc); + } +} +epicsExportRegistrar(asynInterposeDummyRegister); diff --git a/asyn/miscellaneous/asynInterposeDummy.h b/asyn/miscellaneous/asynInterposeDummy.h new file mode 100644 index 000000000..9ac755331 --- /dev/null +++ b/asyn/miscellaneous/asynInterposeDummy.h @@ -0,0 +1,72 @@ +/*asynInterposeDummy.h*/ + +/* + * Example of an asynInterpose implementation + * The dummy implementation does *nothing*, + * simply forwards requests to the lower port. + * + * Use this as as a base example to build your asynInterpose. + * + * Author: davide.marcato@lnl.infn.it + */ + +#ifndef asynInterposeDummy_H +#define asynInterposeDummy_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "asynDriver.h" +#include "asynOctet.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +// Dummy private data +typedef struct interposePvt { + char *portName; + asynInterface dummyInterface; /* This asynOctet interface */ + asynOctet *poctet; /* The methods we're overriding */ + void *octetPvt; /* Private data of next lower interface */ + asynUser *pasynUser; /* For connect/disconnect reporting */ + epicsInt8 escape; /* The escape char to deduplicate */ +} interposePvt; + +ASYN_API +int asynInterposeDummyConfig(const char *portName); + +/* Connect/disconnect handling */ +static void ExceptionHandler(asynUser *pasynUser, asynException exception); + +/* asynOctet methods */ +static asynStatus writeIt(void *ppvt, asynUser *pasynUser, const char *data, size_t numchars, + size_t *nbytesTransfered); +static asynStatus readIt(void *ppvt, asynUser *pasynUser, char *data, size_t maxchars, + size_t *nbytesTransfered, int *eomReason); +static asynStatus flushIt(void *ppvt, asynUser *pasynUser); +static asynStatus registerInterruptUser(void *ppvt, asynUser *pasynUser, + interruptCallbackOctet callback, void *userPvt, + void **registrarPvt); +static asynStatus cancelInterruptUser(void *drvPvt, asynUser *pasynUser, void *registrarPvt); +static asynStatus setInputEos(void *ppvt, asynUser *pasynUser, const char *eos, int eoslen); +static asynStatus getInputEos(void *ppvt, asynUser *pasynUser, char *eos, int eossize, int *eoslen); +static asynStatus setOutputEos(void *ppvt, asynUser *pasynUser, const char *eos, int eoslen); +static asynStatus getOutputEos(void *ppvt, asynUser *pasynUser, char *eos, int eossize, + int *eoslen); +static asynOctet octet = { + writeIt, readIt, flushIt, registerInterruptUser, cancelInterruptUser, + setInputEos, getInputEos, setOutputEos, getOutputEos}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* asynInterposeEos_H */ From 87f9a75564a35bf39253196f2730c50160b06a2b Mon Sep 17 00:00:00 2001 From: Davide Marcato Date: Sat, 16 Oct 2021 17:07:09 +0200 Subject: [PATCH 2/3] Fix some typos --- asyn/miscellaneous/asynInterposeDummy.c | 7 +++---- asyn/miscellaneous/asynInterposeDummy.h | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/asyn/miscellaneous/asynInterposeDummy.c b/asyn/miscellaneous/asynInterposeDummy.c index 30800f65e..2a5d6e768 100644 --- a/asyn/miscellaneous/asynInterposeDummy.c +++ b/asyn/miscellaneous/asynInterposeDummy.c @@ -19,10 +19,9 @@ int asynInterposeDummyConfig(const char *portName) { asynStatus status; asynUser *pasynUser; int addr = 0; - /* - * Interpose ourselves - */ - pvt = callocMustSucceed(1, sizeof(interposePvt), "asynInterposeEcho"); + + // Populate private data + pvt = callocMustSucceed(1, sizeof(interposePvt), "asynInterposeDummy"); pvt->portName = epicsStrDup(portName); pvt->dummyInterface.interfaceType = asynOctetType; pvt->dummyInterface.pinterface = &octet; diff --git a/asyn/miscellaneous/asynInterposeDummy.h b/asyn/miscellaneous/asynInterposeDummy.h index 9ac755331..2c8d57963 100644 --- a/asyn/miscellaneous/asynInterposeDummy.h +++ b/asyn/miscellaneous/asynInterposeDummy.h @@ -30,14 +30,13 @@ extern "C" { #endif /* __cplusplus */ -// Dummy private data +// Interpose private data typedef struct interposePvt { char *portName; asynInterface dummyInterface; /* This asynOctet interface */ asynOctet *poctet; /* The methods we're overriding */ void *octetPvt; /* Private data of next lower interface */ asynUser *pasynUser; /* For connect/disconnect reporting */ - epicsInt8 escape; /* The escape char to deduplicate */ } interposePvt; ASYN_API @@ -55,7 +54,7 @@ static asynStatus flushIt(void *ppvt, asynUser *pasynUser); static asynStatus registerInterruptUser(void *ppvt, asynUser *pasynUser, interruptCallbackOctet callback, void *userPvt, void **registrarPvt); -static asynStatus cancelInterruptUser(void *drvPvt, asynUser *pasynUser, void *registrarPvt); +static asynStatus cancelInterruptUser(void *ppvt, asynUser *pasynUser, void *registrarPvt); static asynStatus setInputEos(void *ppvt, asynUser *pasynUser, const char *eos, int eoslen); static asynStatus getInputEos(void *ppvt, asynUser *pasynUser, char *eos, int eossize, int *eoslen); static asynStatus setOutputEos(void *ppvt, asynUser *pasynUser, const char *eos, int eoslen); @@ -69,4 +68,4 @@ static asynOctet octet = { } #endif /* __cplusplus */ -#endif /* asynInterposeEos_H */ +#endif /* asynInterposeDummy_H */ From e49d25cc5167995ac85df3389fca24904ad15882 Mon Sep 17 00:00:00 2001 From: Davide Marcato Date: Mon, 18 Oct 2021 09:43:05 +0200 Subject: [PATCH 3/3] Rename asynInterposeDummy to asynInterposeTemplate --- asyn/Makefile | 4 +- asyn/miscellaneous/asyn.dbd | 2 +- ...terposeDummy.c => asynInterposeTemplate.c} | 42 +++++++++---------- ...terposeDummy.h => asynInterposeTemplate.h} | 20 ++++----- 4 files changed, 34 insertions(+), 34 deletions(-) rename asyn/miscellaneous/{asynInterposeDummy.c => asynInterposeTemplate.c} (77%) rename asyn/miscellaneous/{asynInterposeDummy.h => asynInterposeTemplate.h} (79%) diff --git a/asyn/Makefile b/asyn/Makefile index 071379841..7f565c8bb 100644 --- a/asyn/Makefile +++ b/asyn/Makefile @@ -102,7 +102,7 @@ DBD += asyn.dbd INC += asynShellCommands.h INC += asynInterposeCom.h INC += asynInterposeEos.h -INC += asynInterposeDummy.h +INC += asynInterposeTemplate.h INC += asynInterposeFlush.h ifneq ($(EPICS_LIBCOM_ONLY),YES) asyn_SRCS += asynShellCommands.c @@ -112,7 +112,7 @@ asyn_SRCS += asynInterposeEos.c asyn_SRCS += asynInterposeFlush.c asyn_SRCS += asynInterposeDelay.c asyn_SRCS += asynInterposeEcho.c -asyn_SRCS += asynInterposeDummy.c +asyn_SRCS += asynInterposeTemplate.c SRC_DIRS += $(ASYN)/asynPortDriver/exceptions INC += ParamListInvalidIndex.h diff --git a/asyn/miscellaneous/asyn.dbd b/asyn/miscellaneous/asyn.dbd index 70d1fdedd..3678a73b1 100644 --- a/asyn/miscellaneous/asyn.dbd +++ b/asyn/miscellaneous/asyn.dbd @@ -3,7 +3,7 @@ registrar(asynInterposeFlushRegister) registrar(asynInterposeEosRegister) registrar(asynInterposeDelayRegister) registrar(asynInterposeEchoRegister) -registrar(asynInterposeDummyRegister) +registrar(asynInterposeTemplateRegister) # # The following ties this to EPICS records. diff --git a/asyn/miscellaneous/asynInterposeDummy.c b/asyn/miscellaneous/asynInterposeTemplate.c similarity index 77% rename from asyn/miscellaneous/asynInterposeDummy.c rename to asyn/miscellaneous/asynInterposeTemplate.c index 2a5d6e768..422fca746 100644 --- a/asyn/miscellaneous/asynInterposeDummy.c +++ b/asyn/miscellaneous/asynInterposeTemplate.c @@ -1,8 +1,8 @@ -/*asynInterposeDummy.c*/ +/*asynInterposeTemplate.c*/ /* * Example of an asynInterpose implementation - * The dummy implementation does *nothing*, + * The template implementation does *nothing*, * simply forwards requests to the lower port. * * Use this as as a base example to build your asynInterpose. @@ -10,22 +10,22 @@ * Author: davide.marcato@lnl.infn.it */ -#include "asynInterposeDummy.h" +#include "asynInterposeTemplate.h" ASYN_API -int asynInterposeDummyConfig(const char *portName) { +int asynInterposeTemplateConfig(const char *portName) { interposePvt *pvt; asynInterface *plowerLevelInterface; asynStatus status; asynUser *pasynUser; int addr = 0; - + // Populate private data - pvt = callocMustSucceed(1, sizeof(interposePvt), "asynInterposeDummy"); + pvt = callocMustSucceed(1, sizeof(interposePvt), "asynInterposeTemplate"); pvt->portName = epicsStrDup(portName); - pvt->dummyInterface.interfaceType = asynOctetType; - pvt->dummyInterface.pinterface = &octet; - pvt->dummyInterface.drvPvt = pvt; + pvt->templateInterface.interfaceType = asynOctetType; + pvt->templateInterface.pinterface = &octet; + pvt->templateInterface.drvPvt = pvt; pasynUser = pasynManager->createAsynUser(0, 0); pvt->pasynUser = pasynUser; pvt->pasynUser->userPvt = pvt; @@ -49,8 +49,8 @@ int asynInterposeDummyConfig(const char *portName) { } // Interpose port - status = - pasynManager->interposeInterface(portName, addr, &pvt->dummyInterface, &plowerLevelInterface); + status = pasynManager->interposeInterface(portName, addr, &pvt->templateInterface, + &plowerLevelInterface); if (status != asynSuccess) { printf("%s interposeInterface failed\n", portName); pasynManager->exceptionCallbackRemove(pasynUser); @@ -133,20 +133,20 @@ static asynStatus getOutputEos(void *ppvt, asynUser *pasynUser, char *eos, int e return pvt->poctet->getOutputEos(pvt->octetPvt, pasynUser, eos, eossize, eoslen); } -/* register asynInterposeDummyConfig*/ -static const iocshArg asynInterposeDummyConfigArg0 = {"portName", iocshArgString}; -static const iocshArg *asynInterposeDummyConfigArgs[] = {&asynInterposeDummyConfigArg0}; -static const iocshFuncDef asynInterposeDummyConfigFuncDef = {"asynInterposeDummyConfig", 1, - asynInterposeDummyConfigArgs}; -static void asynInterposeDummyConfigCallFunc(const iocshArgBuf *args) { - asynInterposeDummyConfig(args[0].sval); +/* register asynInterposeTemplateConfig*/ +static const iocshArg asynInterposeTemplateConfigArg0 = {"portName", iocshArgString}; +static const iocshArg *asynInterposeTemplateConfigArgs[] = {&asynInterposeTemplateConfigArg0}; +static const iocshFuncDef asynInterposeTemplateConfigFuncDef = {"asynInterposeTemplateConfig", 1, + asynInterposeTemplateConfigArgs}; +static void asynInterposeTemplateConfigCallFunc(const iocshArgBuf *args) { + asynInterposeTemplateConfig(args[0].sval); } -static void asynInterposeDummyRegister(void) { +static void asynInterposeTemplateRegister(void) { static int firstTime = 1; if (firstTime) { firstTime = 0; - iocshRegister(&asynInterposeDummyConfigFuncDef, asynInterposeDummyConfigCallFunc); + iocshRegister(&asynInterposeTemplateConfigFuncDef, asynInterposeTemplateConfigCallFunc); } } -epicsExportRegistrar(asynInterposeDummyRegister); +epicsExportRegistrar(asynInterposeTemplateRegister); diff --git a/asyn/miscellaneous/asynInterposeDummy.h b/asyn/miscellaneous/asynInterposeTemplate.h similarity index 79% rename from asyn/miscellaneous/asynInterposeDummy.h rename to asyn/miscellaneous/asynInterposeTemplate.h index 2c8d57963..272655d1f 100644 --- a/asyn/miscellaneous/asynInterposeDummy.h +++ b/asyn/miscellaneous/asynInterposeTemplate.h @@ -1,8 +1,8 @@ -/*asynInterposeDummy.h*/ +/*asynInterposeTemplate.h*/ /* * Example of an asynInterpose implementation - * The dummy implementation does *nothing*, + * The template implementation does *nothing*, * simply forwards requests to the lower port. * * Use this as as a base example to build your asynInterpose. @@ -10,8 +10,8 @@ * Author: davide.marcato@lnl.infn.it */ -#ifndef asynInterposeDummy_H -#define asynInterposeDummy_H +#ifndef asynInterposeTemplate_H +#define asynInterposeTemplate_H #include #include @@ -33,14 +33,14 @@ extern "C" { // Interpose private data typedef struct interposePvt { char *portName; - asynInterface dummyInterface; /* This asynOctet interface */ - asynOctet *poctet; /* The methods we're overriding */ - void *octetPvt; /* Private data of next lower interface */ - asynUser *pasynUser; /* For connect/disconnect reporting */ + asynInterface templateInterface; /* This asynOctet interface */ + asynOctet *poctet; /* The methods we're overriding */ + void *octetPvt; /* Private data of next lower interface */ + asynUser *pasynUser; /* For connect/disconnect reporting */ } interposePvt; ASYN_API -int asynInterposeDummyConfig(const char *portName); +int asynInterposeTemplateConfig(const char *portName); /* Connect/disconnect handling */ static void ExceptionHandler(asynUser *pasynUser, asynException exception); @@ -68,4 +68,4 @@ static asynOctet octet = { } #endif /* __cplusplus */ -#endif /* asynInterposeDummy_H */ +#endif /* asynInterposeTemplate_H */