From 828e9bc59ce852517b6c522dc6b0b2c1bbf43c4e Mon Sep 17 00:00:00 2001 From: smathis Date: Wed, 19 Mar 2025 15:01:20 +0100 Subject: [PATCH] Fixed a bug in msgPrintControl --- src/msgPrintControl.h | 2 +- src/sinqAxis.cpp | 17 +++++++++++++++-- src/sinqController.cpp | 12 +++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/msgPrintControl.h b/src/msgPrintControl.h index fd80969..9214afa 100644 --- a/src/msgPrintControl.h +++ b/src/msgPrintControl.h @@ -139,7 +139,7 @@ class msgPrintControl { private: std::unordered_map map_; - char suffix_[200] = {0}; + char suffix_[300] = {0}; }; #endif \ No newline at end of file diff --git a/src/sinqAxis.cpp b/src/sinqAxis.cpp index 1cf7544..efc5f7d 100644 --- a/src/sinqAxis.cpp +++ b/src/sinqAxis.cpp @@ -15,6 +15,19 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo) offsetMovTimeout_ = 30; targetPosition_ = 0.0; + // This check is also done in asynMotorAxis, but there the IOC continues + // running even though the configuration is incorrect. When failing this + // check, the IOC is stopped, since this is definitely a configuration + // problem. + if ((axisNo < 0) || (axisNo >= pC->numAxes())) { + asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR, + "Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR " + "(axis index %d is not in range 0 to %d)\n. Terminating IOC", + pC->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, axisNo, + pC->numAxes() - 1); + exit(-1); + } + // Motor is assumed to be enabled status = setIntegerParam(pC_->motorEnableRBV(), 1); if (status != asynSuccess) { @@ -699,9 +712,9 @@ asynStatus setScaleMovTimeout(const char *portName, int axisNo, sinqAxis *axis = dynamic_cast(asynAxis); if (axis == nullptr) { errlogPrintf("Controller \"%s\" => %s, line %d:\nAxis %d does not " - "exist or is not an " - "instance of sinqAxis.", + "exist or is not an instance of sinqAxis.", portName, __PRETTY_FUNCTION__, __LINE__, axisNo); + return asynError; } return axis->setScaleMovTimeout(scaleMovTimeout); diff --git a/src/sinqController.cpp b/src/sinqController.cpp index a5e9361..786c41d 100644 --- a/src/sinqController.cpp +++ b/src/sinqController.cpp @@ -274,9 +274,15 @@ sinqController::sinqController(const char *portName, } sinqController::~sinqController(void) { - /* - Cleanup of the memory allocated in the asynMotorController constructor - */ + + // Free all axes + for (int axisNo = 0; axisNo < numAxes_; axisNo++) { + if (pAxes_[axisNo] != nullptr) { + delete pAxes_[axisNo]; + } + } + + // Cleanup of the array allocated in the asynMotorController constructor free(this->pAxes_); }