This commit is contained in:
2025-06-16 13:32:49 +02:00
parent bdefc6090d
commit 43df40aaea
2 changed files with 85 additions and 63 deletions

View File

@ -10,6 +10,8 @@
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#define getControllerMethod pController
struct sinqAxisImpl { struct sinqAxisImpl {
// Internal variables used in the movement timeout watchdog // Internal variables used in the movement timeout watchdog
time_t expectedArrivalTime; time_t expectedArrivalTime;
@ -29,9 +31,9 @@ struct sinqAxisImpl {
}; };
// Generic fallback - if the compiler tries to compile this function, it fails. // Generic fallback - if the compiler tries to compile this function, it fails.
template <typename T> template <typename A, typename C, typename T>
asynStatus setAxisParam(sinqAxis *axis, const char *indexName, asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
int (sinqController::*func)(), T writeValue, int (C::*func)(), T writeValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
static_assert( static_assert(
sizeof(T) == 0, sizeof(T) == 0,
@ -39,10 +41,11 @@ asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
return asynError; return asynError;
} }
template <> template <typename A, typename C, typename T,
asynStatus setAxisParam<int>(sinqAxis *axis, const char *indexName, std::enable_if_t<std::is_same<T, int>::value, int> = 0>
int (sinqController::*func)(), int writeValue, asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
const char *callerFunctionName, int lineNumber) { int (C::*func)(), T writeValue,
const char *callerFunctionName, int lineNumber) {
int indexValue = (axis->pController()->*func)(); int indexValue = (axis->pController()->*func)();
asynStatus status = axis->setIntegerParam(indexValue, writeValue); asynStatus status = axis->setIntegerParam(indexValue, writeValue);
if (status != asynSuccess) { if (status != asynSuccess) {
@ -52,19 +55,20 @@ asynStatus setAxisParam<int>(sinqAxis *axis, const char *indexName,
return asynSuccess; return asynSuccess;
} }
template <> template <typename A, typename C, typename T,
asynStatus setAxisParam<bool>(sinqAxis *axis, const char *indexName, std::enable_if_t<std::is_same<T, bool>::value, bool> = 0>
int (sinqController::*func)(), bool writeValue, asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
const char *callerFunctionName, int lineNumber) { int (C::*func)(), T writeValue,
const char *callerFunctionName, int lineNumber) {
return setAxisParam(axis, indexName, func, static_cast<int>(writeValue), return setAxisParam(axis, indexName, func, static_cast<int>(writeValue),
callerFunctionName, lineNumber); callerFunctionName, lineNumber);
} }
template <> template <typename A, typename C, typename T,
asynStatus std::enable_if_t<std::is_same<T, double>::value, double> = 0>
setAxisParam<double>(sinqAxis *axis, const char *indexName, asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
int (sinqController::*func)(), double writeValue, int (sinqController::*func)(), T writeValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
int indexValue = (axis->pController()->*func)(); int indexValue = (axis->pController()->*func)();
asynStatus status = axis->setDoubleParam(indexValue, writeValue); asynStatus status = axis->setDoubleParam(indexValue, writeValue);
if (status != asynSuccess) { if (status != asynSuccess) {
@ -74,11 +78,11 @@ setAxisParam<double>(sinqAxis *axis, const char *indexName,
return asynSuccess; return asynSuccess;
} }
template <> template <typename A, typename C, typename T,
asynStatus setAxisParam<char *>(sinqAxis *axis, const char *indexName, std::enable_if_t<std::is_same<T, char *>::value, char *> = 0>
int (sinqController::*func)(), char *writeValue, asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
const char *callerFunctionName, int (C::*func)(), T writeValue,
int lineNumber) { const char *callerFunctionName, int lineNumber) {
int indexValue = (axis->pController()->*func)(); int indexValue = (axis->pController()->*func)();
asynStatus status = axis->setStringParam(indexValue, writeValue); asynStatus status = axis->setStringParam(indexValue, writeValue);
if (status != asynSuccess) { if (status != asynSuccess) {
@ -88,12 +92,12 @@ asynStatus setAxisParam<char *>(sinqAxis *axis, const char *indexName,
return asynSuccess; return asynSuccess;
} }
template <> template <
asynStatus setAxisParam<const char *>(sinqAxis *axis, const char *indexName, typename A, typename C, typename T,
int (sinqController::*func)(), std::enable_if_t<std::is_same<T, const char *>::value, const char *> = 0>
const char *writeValue, asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
const char *callerFunctionName, int (C::*func)(), T writeValue,
int lineNumber) { const char *callerFunctionName, int lineNumber) {
int indexValue = (axis->pController()->*func)(); int indexValue = (axis->pController()->*func)();
asynStatus status = axis->setStringParam(indexValue, writeValue); asynStatus status = axis->setStringParam(indexValue, writeValue);
if (status != asynSuccess) { if (status != asynSuccess) {
@ -104,9 +108,9 @@ asynStatus setAxisParam<const char *>(sinqAxis *axis, const char *indexName,
} }
// Generic fallback - if the compiler tries to compile this function, it fails. // Generic fallback - if the compiler tries to compile this function, it fails.
template <typename T> template <typename A, typename C, typename T>
asynStatus getAxisParam(sinqAxis *axis, const char *indexName, asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
int (sinqController::*func)(), T *readValue, int (C::*func)(), T *readValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
static_assert( static_assert(
sizeof(T) == 0, sizeof(T) == 0,
@ -114,9 +118,10 @@ asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
return asynError; return asynError;
} }
template <> template <typename A, typename C, typename T,
asynStatus getAxisParam<int>(sinqAxis *axis, const char *indexName, std::enable_if_t<std::is_same<T, int>::value, int> = 0>
int (sinqController::*func)(), int *readValue, asynStatus getAxisParam<int>(A *axis, C *controller, const char *indexName,
int (C::*func)(), T *readValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
int indexValue = (axis->pController()->*func)(); int indexValue = (axis->pController()->*func)();
asynStatus status = axis->pController()->getIntegerParam( asynStatus status = axis->pController()->getIntegerParam(
@ -128,19 +133,21 @@ asynStatus getAxisParam<int>(sinqAxis *axis, const char *indexName,
return asynSuccess; return asynSuccess;
} }
template <> template <typename A, typename C, typename T,
asynStatus getAxisParam<bool>(sinqAxis *axis, const char *indexName, std::enable_if_t<std::is_same<T, bool>::value, bool> = 0>
int (sinqController::*func)(), bool *readValue, asynStatus getAxisParam<bool>(A *axis, C *controller, const char *indexName,
int (C::*func)(), T *readValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
return getAxisParam(axis, indexName, func, (int *)readValue, return getAxisParam(axis, indexName, func, (int *)readValue,
callerFunctionName, lineNumber); callerFunctionName, lineNumber);
} }
template <> template <typename A, typename C, typename T,
asynStatus std::enable_if_t<std::is_same<T, double>::value, double> = 0>
getAxisParam<double>(sinqAxis *axis, const char *indexName, asynStatus getAxisParam<double>(A *axis, C *controller, const char *indexName,
int (sinqController::*func)(), double *readValue, int (C::*func)(), T *readValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName,
int lineNumber) {
int indexValue = (axis->pController()->*func)(); int indexValue = (axis->pController()->*func)();
asynStatus status = axis->pController()->getDoubleParam( asynStatus status = axis->pController()->getDoubleParam(
axis->axisNo(), indexValue, readValue); axis->axisNo(), indexValue, readValue);
@ -151,9 +158,10 @@ getAxisParam<double>(sinqAxis *axis, const char *indexName,
return asynSuccess; return asynSuccess;
} }
template <> template <typename A, typename C, typename T,
asynStatus getAxisParam<char>(sinqAxis *axis, const char *indexName, std::enable_if_t<std::is_same<T, char>::value, char> = 0>
int (sinqController::*func)(), char *readValue, asynStatus getAxisParam<char>(A *axis, C *controller, const char *indexName,
int (C::*func)(), T *readValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
int maxChars = 200; int maxChars = 200;
@ -168,20 +176,21 @@ asynStatus getAxisParam<char>(sinqAxis *axis, const char *indexName,
return asynSuccess; return asynSuccess;
} }
template <size_t N> template <typename A, typename C, typename T,
asynStatus getAxisParam(sinqAxis *axis, const char *indexName, std::enable_if_t<std::is_same<T, char>::value, char> = 0, size_t N>
int (sinqController::*func)(), char (&readValue)[N], asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
int (C::*func)(), T (&readValue)[N],
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
// Decay the array to char* // Decay the array to char*
return getAxisParam<char>(axis, indexName, func, return getAxisParam<char>(axis, controller, indexName, func,
static_cast<char *>(readValue), static_cast<char *>(readValue),
callerFunctionName, lineNumber); callerFunctionName, lineNumber);
} }
template <> template <typename A, typename C>
asynStatus asynStatus
getAxisParam<std::string>(sinqAxis *axis, const char *indexName, getAxisParam<std::string>(A *axis, C *controller, const char *indexName,
int (sinqController::*func)(), std::string *readValue, int (C::*func)(), std::string *readValue,
const char *callerFunctionName, int lineNumber) { const char *callerFunctionName, int lineNumber) {
int indexValue = (axis->pController()->*func)(); int indexValue = (axis->pController()->*func)();

View File

@ -365,9 +365,22 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
asynStatus assertConnected(); asynStatus assertConnected();
/** /**
* @brief Return a pointer to the axis controller * @brief Return a pointer to the axis controller.
*
* This function should be overriden in derived classes using the `override`
* keyword so the macros `getAxisParamChecked` and `setAxisParamChecked`
* work correctly:
*
* ```
* class mySpecialAxis : public sinqAxis {
public:
mySpecialController* getControllerMethod() override {
return mySpecialControllerPtr;
}
};
* ```
*/ */
sinqController *pController() { return pC_; }; virtual sinqController *pController() { return pC_; };
/** /**
* @brief Returns true, if the axis was moving in the last poll cycle, and * @brief Returns true, if the axis was moving in the last poll cycle, and
@ -423,9 +436,9 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* @param lineNumber * @param lineNumber
* @return asynStatus * @return asynStatus
*/ */
template <typename T> template <typename A, typename C, typename T>
asynStatus setAxisParam(sinqAxis *axis, const char *indexName, asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
int (sinqController::*func)(), T writeValue, int (C::*func)(), T writeValue,
const char *callerFunctionName, int lineNumber); const char *callerFunctionName, int lineNumber);
/** /**
@ -457,7 +470,7 @@ asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
#define setAxisParamChecked(axis, indexGetterFunction, writeValue) \ #define setAxisParamChecked(axis, indexGetterFunction, writeValue) \
{ \ { \
asynStatus setStatus = setAxisParam( \ asynStatus setStatus = setAxisParam( \
axis, #indexGetterFunction, \ axis, axis->pController(), #indexGetterFunction, \
&std::remove_pointer< \ &std::remove_pointer< \
decltype(axis->pController())>::type::indexGetterFunction, \ decltype(axis->pController())>::type::indexGetterFunction, \
writeValue, __PRETTY_FUNCTION__, __LINE__); \ writeValue, __PRETTY_FUNCTION__, __LINE__); \
@ -488,17 +501,17 @@ asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
* to. * to.
* @return asynStatus * @return asynStatus
*/ */
template <typename T> template <typename A, typename C, typename T>
asynStatus getAxisParam(sinqAxis *axis, const char *indexName, asynStatus getAxisParam(A *axis, const char *indexName, int (C::*func)(),
int (sinqController::*func)(), T *readValue, T *readValue, const char *callerFunctionName,
const char *callerFunctionName, int lineNumber); int lineNumber);
/** /**
* @brief Macro to get an paramLib parameter and error checking the return value * @brief Macro to get an paramLib parameter and error checking the return value
* *
* This macro is a wrapper around `getIntegerParam` / `getDoubleParam` / * This macro is a wrapper around `getIntegerParam` / `getDoubleParam` /
* `getStringParam` which checks if the operation was successfull. If it wasn't, * `getStringParam` which checks if the operation was successfull. If it wasn't,
* it returns by calling the paramLibAccessFailed function. * it returns by calling the paramLibAccessFailed function. In order
* *
* For example, the following input: * For example, the following input:
* ``` * ```
@ -522,7 +535,7 @@ asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
#define getAxisParamChecked(axis, indexGetterFunction, readValue) \ #define getAxisParamChecked(axis, indexGetterFunction, readValue) \
{ \ { \
asynStatus getStatus = getAxisParam( \ asynStatus getStatus = getAxisParam( \
axis, #indexGetterFunction, \ axis, axis->pController(), #indexGetterFunction, \
&std::remove_pointer< \ &std::remove_pointer< \
decltype(axis->pController())>::type::indexGetterFunction, \ decltype(axis->pController())>::type::indexGetterFunction, \
readValue, __PRETTY_FUNCTION__, __LINE__); \ readValue, __PRETTY_FUNCTION__, __LINE__); \