From 9e4f24dd9f14b614ac25f6abbdaae35f937c3ee4 Mon Sep 17 00:00:00 2001 From: Edward Wall Date: Fri, 20 Sep 2024 14:27:40 +0200 Subject: [PATCH] Playing around with the initHooks.h trying to discover when different things are available and what order things are started --- Makefile.RHEL8 | 3 +- sinqEPICSApp/src/pmacAxis.cpp | 5 ++ sinqEPICSApp/src/pmacController.cpp | 30 ++++++++- sinqEPICSApp/src/pmacController.h | 1 - sinqEPICSApp/src/pollerRegister.cpp | 96 +++++++++++++++++++++++++++++ sinqEPICSApp/src/pollerRegister.h | 8 +++ 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 sinqEPICSApp/src/pollerRegister.cpp create mode 100644 sinqEPICSApp/src/pollerRegister.h diff --git a/Makefile.RHEL8 b/Makefile.RHEL8 index e3d02c2..a58d39c 100644 --- a/Makefile.RHEL8 +++ b/Makefile.RHEL8 @@ -13,7 +13,7 @@ REQUIRED+=scaler REQUIRED+=asynMotor # Release version -LIBVERSION=2024-v2 +LIBVERSION=2024-ed-dev2 # DB files to include in the release TEMPLATES += sinqEPICSApp/Db/dimetix.db @@ -36,6 +36,7 @@ SOURCES += sinqEPICSApp/src/pmacAsynIPPort.c SOURCES += sinqEPICSApp/src/pmacAxis.cpp SOURCES += sinqEPICSApp/src/pmacController.cpp SOURCES += sinqEPICSApp/src/MasterMACSDriver.cpp +SOURCES += sinqEPICSApp/src/pollerRegister.cpp USR_CFLAGS += -Wall -Wextra # -Werror diff --git a/sinqEPICSApp/src/pmacAxis.cpp b/sinqEPICSApp/src/pmacAxis.cpp index 39bb41b..5771a02 100644 --- a/sinqEPICSApp/src/pmacAxis.cpp +++ b/sinqEPICSApp/src/pmacAxis.cpp @@ -916,6 +916,7 @@ asynStatus pmacV3Axis::poll(bool *moving) { sprintf(message, "%s: Polling axis: %d", functionName, this->axisNo_); pC_->debugFlow(message); + // Now poll axis status if ((status = this->getAxisStatus(moving)) != asynSuccess) { asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, @@ -924,6 +925,10 @@ asynStatus pmacV3Axis::poll(bool *moving) { functionName, pC_->portName, axisNo_); } + double motorRecResolution_ = 0.; + pC_->getDoubleParam(this->axisNo_, pC_->motorRecResolution_, &motorRecResolution_); + asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "%s: Polling %f\n", functionName, motorRecResolution_); + callParamCallbacks(); return status; diff --git a/sinqEPICSApp/src/pmacController.cpp b/sinqEPICSApp/src/pmacController.cpp index 0f7fd79..066a113 100644 --- a/sinqEPICSApp/src/pmacController.cpp +++ b/sinqEPICSApp/src/pmacController.cpp @@ -45,6 +45,7 @@ using std::endl; #include "pmacController.h" #include "pmacAxis.h" +#include "pollerRegister.h" #define MULT 1000. @@ -142,6 +143,7 @@ asynStatus pmacCreateAxis(const char *pmacName, int numAxis); } + pmacController::pmacController(const char *portName, const char *lowLevelPortName, int lowLevelPortAddress, int numAxes, double movingPollPeriod, double idlePollPeriod, const int& extraParams) : SINQController(portName, lowLevelPortName, numAxes+1, extraParams) @@ -166,7 +168,31 @@ setIntegerParam(PMAC_C_CommsError_, 1); * NOTE: at this point the axis objects don't yet exist, but the poller tolerates this */ setIntegerParam(PMAC_C_CommsError_, 0); } -startPoller(movingPollPeriod, idlePollPeriod, 10); + +registerFunction( + [this](){ + //startPoller(movingPollPeriod, idlePollPeriod, 0); + // + + asynPrint( + this->pasynUserSelf, + ASYN_TRACE_ERROR, + "\n\n\n%s: status %d %d %d %d %d %d\n\n\n", + functionName, + asynSuccess,asynTimeout,asynOverflow,asynError,asynDisconnected,asynDisabled); + + double motorRecResolution_ = 0.; + asynStatus status = this->getDoubleParam(1, this->motorRecResolution_, &motorRecResolution_); + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "\n\n\n%s: Polling %f, status %d\n\n\n", functionName, motorRecResolution_, status); + + usleep(50000); // slow down communication somewhat + + status = this->getDoubleParam(1, this->motorRecResolution_, &motorRecResolution_); + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "\n\n\n%s: Polling %f, status %d\n\n\n", functionName, motorRecResolution_, status); + } +); + +startPoller(movingPollPeriod, idlePollPeriod, 0); callParamCallbacks(); @@ -502,6 +528,8 @@ asynStatus pmacController::poll() debugFlow(functionName); + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s: Polling\n", functionName); + if (!lowLevelPortUser_) { setIntegerParam(this->motorStatusCommsError_, 1); return asynError; diff --git a/sinqEPICSApp/src/pmacController.h b/sinqEPICSApp/src/pmacController.h index ac84749..e0342a7 100644 --- a/sinqEPICSApp/src/pmacController.h +++ b/sinqEPICSApp/src/pmacController.h @@ -41,7 +41,6 @@ class pmacController : public SINQController { pmacAxis* getAxis(int axisNo); asynStatus poll(); - protected: pmacAxis **pAxes_; /**< Array of pointers to axis objects */ diff --git a/sinqEPICSApp/src/pollerRegister.cpp b/sinqEPICSApp/src/pollerRegister.cpp new file mode 100644 index 0000000..b416960 --- /dev/null +++ b/sinqEPICSApp/src/pollerRegister.cpp @@ -0,0 +1,96 @@ +#include "pollerRegister.h" + +#include +#include + +#include "libComAPI.h" +#include "initHooks.h" + +static std::vector> registeredFunctions; + +static void startPollingHook(initHookState state) { + switch (state) { + case initHookAtIocBuild: + printf("\n\n\ninitHookAtIocBuild\n\n\n"); + break; + + case initHookAtBeginning: + printf("\n\n\ninitHookAtBeginning\n\n\n"); + break; + + case initHookAfterCallbackInit: + printf("\n\n\ninitHookAfterCallbackInit\n\n\n"); + break; + + case initHookAfterCaLinkInit: + printf("\n\n\ninitHookAfterCaLinkInit\n\n\n"); + break; + + case initHookAfterInitDrvSup: + printf("\n\n\ninitHookAfterInitDrvSup\n\n\n"); + break; + + case initHookAfterInitRecSup: + printf("\n\n\ninitHookAfterInitRecSup\n\n\n"); + break; + + case initHookAfterInitDevSup: + printf("\n\n\ninitHookAfterInitDevSup\n\n\n"); + break; + + case initHookAfterInitDatabase: + printf("\n\n\ninitHookAfterInitDatabase\n\n\n"); + break; + + case initHookAfterFinishDevSup: + printf("\n\n\ninitHookAfterFinishDevSup\n\n\n"); + break; + + case initHookAfterScanInit: + printf("\n\n\ninitHookAfterScanInit\n\n\n"); + break; + + case initHookAfterInitialProcess: + printf("\n\n\ninitHookAfterInitialProcess\n\n\n"); + break; + + case initHookAfterCaServerInit: + printf("\n\n\ninitHookAfterCaServerInit\n\n\n"); + break; + + case initHookAfterIocBuilt: + printf("\n\n\ninitHookAfterIocBuilt\n\n\n"); + break; + + case initHookAtIocRun: + printf("\n\n\ninitHookAtIocRun\n\n\n"); + break; + + case initHookAfterDatabaseRunning: + printf("\n\n\ninitHookAfterDatabaseRunning\n\n\n"); + break; + + case initHookAtEnd: + printf("\n\n\ninitHookAtEnd\n\n\n"); + break; + + case initHookAfterCaServerRunning: + printf("\n\n\ninitHookAfterCaServerRunning\n\n\n"); + break; + + case initHookAfterIocRunning: + printf("\n\n\ninitHookAfterIocRunning\n\n\n"); + for(auto&& fn : registeredFunctions) + fn(); + break; + + default: + break; + } +} + +static int myHookStatus = initHookRegister(startPollingHook); + +void registerFunction(std::function func) { + registeredFunctions.push_back(func); +} diff --git a/sinqEPICSApp/src/pollerRegister.h b/sinqEPICSApp/src/pollerRegister.h new file mode 100644 index 0000000..45a5fbf --- /dev/null +++ b/sinqEPICSApp/src/pollerRegister.h @@ -0,0 +1,8 @@ +#ifndef POLLERREGISTER +#define POLLERREGISTER + +#include + +void registerFunction(std::function func); + +#endif