diff --git a/src/msgPrintControl.cpp b/src/msgPrintControl.cpp index caa7bfd..615a7a5 100644 --- a/src/msgPrintControl.cpp +++ b/src/msgPrintControl.cpp @@ -2,11 +2,13 @@ #include msgPrintControlKey::msgPrintControlKey(char *controller, int axisNo, - const char *functionName, int line) { + const char *functionName, int line, + size_t maxRepetitions) { controller_ = controller; axisNo_ = axisNo; line_ = line; functionName_ = functionName; + maxRepetitions_ = maxRepetitions; } void msgPrintControlKey::format(char *buffer, size_t bufferSize) { @@ -16,10 +18,6 @@ void msgPrintControlKey::format(char *buffer, size_t bufferSize) { // ============================================================================= -msgPrintControl::msgPrintControl(size_t maxRepetitions) { - maxRepetitions_ = maxRepetitions; -} - bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint, asynUser *pasynUser) { @@ -34,12 +32,12 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint, */ if (map_.find(key) != map_.end()) { size_t repetitions = map_[key]; - if (repetitions < maxRepetitions_) { + if (repetitions < key.maxRepetitions_) { // Number of allowed repetitions not exceeded -> Printing the // message is ok. map_[key] = repetitions + 1; return true; - } else if (repetitions == maxRepetitions_) { + } else if (repetitions == key.maxRepetitions_) { // Reached number of allowed repetitions -> Printing the message // is ok, but further trys are rejected. char formattedKey[100] = {0}; @@ -88,7 +86,8 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint, bool msgPrintControl::shouldBePrinted(char *portName, int axisNo, const char *functionName, int line, - bool wantToPrint, asynUser *pasynUser) { + bool wantToPrint, asynUser *pasynUser, + size_t maxRepetitions) { msgPrintControlKey key = msgPrintControlKey(portName, axisNo, functionName, __LINE__); return shouldBePrinted(key, wantToPrint, pasynUser); diff --git a/src/msgPrintControl.h b/src/msgPrintControl.h index fce360e..96b491e 100644 --- a/src/msgPrintControl.h +++ b/src/msgPrintControl.h @@ -1,6 +1,8 @@ #ifndef msgPrintControl_H #define msgPrintControl_H +#define DefaultMaxRepetitions 4 + #include #include #include @@ -21,8 +23,15 @@ class msgPrintControlKey { const char *functionName_; int line_; + /** + * @brief Maximum number of times a message is printed before it is + * suppressed. This number is not used as part of the hash. + * + */ + size_t maxRepetitions_; + msgPrintControlKey(char *controller_, int axisNo, const char *fileName, - int line); + int line, size_t maxRepetitions = DefaultMaxRepetitions); bool operator==(const msgPrintControlKey &other) const { return axisNo_ == other.axisNo_ && line_ == other.line_ && @@ -73,8 +82,6 @@ template <> struct hash { */ class msgPrintControl { public: - msgPrintControl(size_t maxRepetitions); - /** * @brief Checks if the error message associated with "key" has been printed * more than `this->maxRepetitions_` times in a row. If yes, returns false, @@ -115,7 +122,8 @@ class msgPrintControl { * @param pasynUser */ bool shouldBePrinted(char *controller, int axisNo, const char *functionName, - int line, bool wantToPrint, asynUser *pasynUser); + int line, bool wantToPrint, asynUser *pasynUser, + size_t maxRepetitions = DefaultMaxRepetitions); /** * @brief Reset the error message count incremented in `shouldBePrinted` for @@ -129,13 +137,6 @@ class msgPrintControl { */ void resetCount(msgPrintControlKey &key, asynUser *pasynUser); - /** - * @brief Maximum number of times a message is printed before it is - * suppressed. - * - */ - size_t maxRepetitions_; - char *getSuffix(); private: diff --git a/src/sinqAxis.cpp b/src/sinqAxis.cpp index 1aeb54f..e9ea07c 100644 --- a/src/sinqAxis.cpp +++ b/src/sinqAxis.cpp @@ -296,6 +296,11 @@ asynStatus sinqAxis::move(double position, int relative, double minVelocity, return status; } + status = assertConnected(); + if (status != asynSuccess) { + return status; + } + // Since the move command was successfull, we assume that the motor has // started its movement. status = setIntegerParam(pC_->motorStatusHomed(), 0); @@ -363,6 +368,11 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity, __LINE__); } + status = assertConnected(); + if (status != asynSuccess) { + return status; + } + // Update the motor record return callParamCallbacks(); @@ -376,11 +386,16 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity, __LINE__); } + status = assertConnected(); + if (status != asynSuccess) { + return status; + } + // Update the motor record return callParamCallbacks(); } else { // Bubble up all other problems - return status; + return assertConnected(); } } @@ -391,6 +406,7 @@ asynStatus sinqAxis::doHome(double minVelocity, double maxVelocity, asynStatus sinqAxis::reset() { asynStatus status = doReset(); + if (status == asynSuccess) { // Perform some fast polls pC_->lock(); @@ -403,6 +419,12 @@ asynStatus sinqAxis::reset() { } pC_->unlock(); } + + asynStatus pl_status = assertConnected(); + if (pl_status != asynSuccess) { + return pl_status; + } + return status; } @@ -456,6 +478,25 @@ asynStatus sinqAxis::setMotorPosition(double motorPosition) { return status; } +asynStatus sinqAxis::assertConnected() { + asynStatus status = asynSuccess; + int connected = 0; + + status = pC_->getIntegerParam(axisNo(), pC_->motorConnected(), &connected); + if (status != asynSuccess) { + return pC_->paramLibAccessFailed(status, "motorConnected", axisNo(), + __PRETTY_FUNCTION__, __LINE__); + } + + if (connected == 0) { + asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR, + "Controller \"%s\", axis %d => %s, line " + "%d:\nAxis is not connected, all commands are ignored.\n", + pC_->portName, axisNo(), __PRETTY_FUNCTION__, __LINE__); + } + return asynSuccess; +} + asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) { asynStatus status = asynSuccess; int variableSpeed = 0; diff --git a/src/sinqAxis.h b/src/sinqAxis.h index 8842a8d..44d0a41 100644 --- a/src/sinqAxis.h +++ b/src/sinqAxis.h @@ -348,6 +348,16 @@ class epicsShareClass sinqAxis : public asynMotorAxis { */ asynStatus setMotorPosition(double motorPosition); + /** + * @brief Check if the axis is not connected and print a corresponding error + * message + * + * This method is meant to be used at the end of "interactive" function + * calls such as move, home, stop etc which can be manually triggered from + * the IOC shell or from the channel access protocol. + */ + asynStatus assertConnected(); + protected: // Internal variables used in the movement timeout watchdog time_t expectedArrivalTime_; diff --git a/src/sinqController.cpp b/src/sinqController.cpp index 767ed3c..7236ea9 100644 --- a/src/sinqController.cpp +++ b/src/sinqController.cpp @@ -48,7 +48,7 @@ sinqController::sinqController(const char *portName, ASYN_CANBLOCK | ASYN_MULTIDEVICE, 1, // autoconnect 0, 0), // Default priority and stack size - msgPrintControl_(4) { + msgPrintControl_() { asynStatus status = asynSuccess;