Compare commits
2 Commits
bdefc6090d
...
31ff26cb78
| Author | SHA1 | Date | |
|---|---|---|---|
| 31ff26cb78 | |||
| 43df40aaea |
162
src/sinqAxis.cpp
162
src/sinqAxis.cpp
@@ -10,6 +10,8 @@
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define getControllerMethod pController
|
||||
|
||||
struct sinqAxisImpl {
|
||||
// Internal variables used in the movement timeout watchdog
|
||||
time_t expectedArrivalTime;
|
||||
@@ -28,21 +30,23 @@ struct sinqAxisImpl {
|
||||
epicsTimeStamp lastPollTime;
|
||||
};
|
||||
|
||||
template <typename T> struct TypeTag {};
|
||||
|
||||
// Generic fallback - if the compiler tries to compile this function, it fails.
|
||||
template <typename T>
|
||||
asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
static_assert(
|
||||
sizeof(T) == 0,
|
||||
"no specialization of setAxisParam exists for the given type");
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<void>) {
|
||||
static_assert(sizeof(T) == 0, "Unsupported type for setAxisParamImpl");
|
||||
return asynError;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), int writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), int writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<int>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setIntegerParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -52,19 +56,21 @@ asynStatus setAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<bool>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), bool writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
return setAxisParam(axis, indexName, func, static_cast<int>(writeValue),
|
||||
callerFunctionName, lineNumber);
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), bool writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<bool>) {
|
||||
return setAxisParamImpl(axis, controller, indexName, func,
|
||||
static_cast<int>(writeValue), callerFunctionName,
|
||||
lineNumber, TypeTag<int>{});
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus
|
||||
setAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), double writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (sinqController::*func)(), double writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<double>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setDoubleParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -74,11 +80,11 @@ setAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<char *>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), char *writeValue,
|
||||
const char *callerFunctionName,
|
||||
int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), char *writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<char *>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setStringParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -88,12 +94,11 @@ asynStatus setAxisParam<char *>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<const char *>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(),
|
||||
const char *writeValue,
|
||||
const char *callerFunctionName,
|
||||
int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), const char *writeValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<const char *>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setStringParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -103,21 +108,31 @@ asynStatus setAxisParam<const char *>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
return setAxisParamImpl(axis, controller, indexName, func, writeValue,
|
||||
callerFunctionName, lineNumber, TypeTag<T>{});
|
||||
}
|
||||
|
||||
// Generic fallback - if the compiler tries to compile this function, it fails.
|
||||
template <typename T>
|
||||
asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<void>) {
|
||||
static_assert(
|
||||
sizeof(T) == 0,
|
||||
"no specialization of getAxisParam exists for the given type");
|
||||
return asynError;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus getAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), int *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), int *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<int>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->pController()->getIntegerParam(
|
||||
axis->axisNo(), indexValue, readValue);
|
||||
@@ -128,19 +143,20 @@ asynStatus getAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus getAxisParam<bool>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), bool *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
return getAxisParam(axis, indexName, func, (int *)readValue,
|
||||
callerFunctionName, lineNumber);
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), bool *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<bool>) {
|
||||
return getAxisParamImpl(axis, indexName, func, (int *)readValue,
|
||||
callerFunctionName, lineNumber);
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus
|
||||
getAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), double *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), double *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<double>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->pController()->getDoubleParam(
|
||||
axis->axisNo(), indexValue, readValue);
|
||||
@@ -151,10 +167,11 @@ getAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus getAxisParam<char>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), char *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), char *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<char>) {
|
||||
|
||||
int maxChars = 200;
|
||||
|
||||
@@ -168,21 +185,22 @@ asynStatus getAxisParam<char>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), char (&readValue)[N],
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C, size_t N>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), char (&readValue)[N],
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<char>) {
|
||||
// Decay the array to char*
|
||||
return getAxisParam<char>(axis, indexName, func,
|
||||
static_cast<char *>(readValue),
|
||||
callerFunctionName, lineNumber);
|
||||
return getAxisParamImpl(axis, controller, indexName, func,
|
||||
static_cast<char *>(readValue), callerFunctionName,
|
||||
lineNumber);
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus
|
||||
getAxisParam<std::string>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), std::string *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C>
|
||||
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), std::string *readValue,
|
||||
const char *callerFunctionName, int lineNumber,
|
||||
TypeTag<std::string>) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
|
||||
// Convert the pointer to a reference, since getStringParam expects the
|
||||
@@ -198,6 +216,14 @@ getAxisParam<std::string>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), std::string *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
return getAxisParamImpl(axis, controller, indexName, func, readValue,
|
||||
callerFunctionName, lineNumber, TypeTag<T>{});
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
|
||||
|
||||
@@ -365,9 +365,22 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
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
|
||||
@@ -423,9 +436,9 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
|
||||
* @param lineNumber
|
||||
* @return asynStatus
|
||||
*/
|
||||
template <typename T>
|
||||
asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), T writeValue,
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber);
|
||||
|
||||
/**
|
||||
@@ -457,7 +470,7 @@ asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
|
||||
#define setAxisParamChecked(axis, indexGetterFunction, writeValue) \
|
||||
{ \
|
||||
asynStatus setStatus = setAxisParam( \
|
||||
axis, #indexGetterFunction, \
|
||||
axis, axis->pController(), #indexGetterFunction, \
|
||||
&std::remove_pointer< \
|
||||
decltype(axis->pController())>::type::indexGetterFunction, \
|
||||
writeValue, __PRETTY_FUNCTION__, __LINE__); \
|
||||
@@ -488,9 +501,9 @@ asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
|
||||
* to.
|
||||
* @return asynStatus
|
||||
*/
|
||||
template <typename T>
|
||||
asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), T *readValue,
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber);
|
||||
|
||||
/**
|
||||
@@ -498,7 +511,7 @@ asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
*
|
||||
* This macro is a wrapper around `getIntegerParam` / `getDoubleParam` /
|
||||
* `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:
|
||||
* ```
|
||||
@@ -522,7 +535,7 @@ asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
#define getAxisParamChecked(axis, indexGetterFunction, readValue) \
|
||||
{ \
|
||||
asynStatus getStatus = getAxisParam( \
|
||||
axis, #indexGetterFunction, \
|
||||
axis, axis->pController(), #indexGetterFunction, \
|
||||
&std::remove_pointer< \
|
||||
decltype(axis->pController())>::type::indexGetterFunction, \
|
||||
readValue, __PRETTY_FUNCTION__, __LINE__); \
|
||||
|
||||
Reference in New Issue
Block a user