9 Commits
1.4.2 ... 1.5.1

Author SHA1 Message Date
f1c41d3081 Perform poll even if init fails
Some checks failed
Test And Build / Lint (push) Failing after 5s
Test And Build / Build (push) Successful in 8s
2025-09-17 13:12:21 +02:00
d78586a815 Updated sinqMotor to 1.5.6
Some checks failed
Test And Build / Lint (push) Failing after 4s
Test And Build / Build (push) Successful in 7s
2025-09-17 12:38:30 +02:00
ebcf99ac56 Updated sinqMotor to 1.5.5 2025-09-17 12:34:47 +02:00
de32298609 Updated sinqMotor to 1.5.4 2025-09-17 12:19:00 +02:00
8f457889c0 Updated sinqMotor to 1.5.3 2025-09-17 11:28:53 +02:00
6f63e521c1 Updated sinqMotor to 1.5.2 2025-09-17 11:25:40 +02:00
670f01fbe3 Updated sinqMotor to 1.5.1 to get a better error message in case of speed problems 2025-09-17 10:54:56 +02:00
25286652d5 Moved version definition in Makefile
Some checks failed
Test And Build / Lint (push) Failing after 3s
Test And Build / Build (push) Successful in 7s
The expected version can now be set in the Makefile via USR_CXXFLAGS.
Additionally, the README.md has received documentation regarding the
version check. Lastly, the version check can now be disabled by omitting
the flags or setting one of them to a negative value.
2025-08-22 13:18:43 +02:00
27f7cc8602 Added version check prototype
Some checks failed
Test And Build / Lint (push) Failing after 4s
Test And Build / Build (push) Successful in 8s
2025-08-22 08:46:30 +02:00
7 changed files with 222 additions and 79 deletions

View File

@@ -29,4 +29,8 @@ TEMPLATES += db/masterMacs.db
DBDS += sinqMotor/src/sinqMotor.dbd
DBDS += src/masterMacs.dbd
USR_CFLAGS += -Wall -Wextra -Weffc++ -Wunused-result -Wextra -Werror
USR_CFLAGS += -Wall -Wextra -Wunused-result -Wextra -Werror
# These flags define the expected firmware version. See README.md, section
# "Firmware version checking" for details.
USR_CXXFLAGS += -DFIRMWARE_MAJOR_VERSION=2 -DFIRMWARE_MINOR_VERSION=2 -Wall -Wextra -Weffc++ -Wunused-result -Wextra

View File

@@ -66,6 +66,32 @@ dbLoadRecords("$(masterMacs_DB)/asynRecord.db","P=$(INSTR)$(NAME),PORT=$(ASYN_PO
Please see the documentation for the module sinqMotor: https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md.
### Firmware version checking
This driver expects a certain version of the firmware running on the controller itself.
This is checked at IOC startup by reading the version directly from the hardware.
If the firmware version is incompatible to the driver, the IOC will be shut down.
If the firmware version cannot be read (e.g. because the variable used to do so
does not exist yet on old firmware versions), the firmware is assumed to be compatible
to the driver.
The version check is separated into a check of the major and the minor firmware
version against expected values. The firmware is seen as compatible if the following conditions hold:
- Read-out major version == Expected major version
- Read-out read major version >= Expected minor version
The expected versions are defined via compiler flags in `Makefile`:
```
USR_CXXFLAGS += -DFIRMWARE_MAJOR_VERSION=1 -DFIRMWARE_MINOR_VERSION=0
```
Be aware that these flags are only used to compile C++-files (.cpp, .cxx) and not
C-files (.c). For C-files, the Makefile variable `USR_CFLAGS` must be used.
In order to disable the checks, the flags can be set to -1 or just be removed
entirely. If one of the flags is not given, both the major and the minor version
checks are deactivated.
### How to build it
Please see the documentation for the module sinqMotor: https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md.

View File

@@ -85,7 +85,14 @@ void appendErrorMessage(char *fullMessage, size_t capacityFullMessage,
}
masterMacsAxis::masterMacsAxis(masterMacsController *pC, int axisNo)
: sinqAxis(pC, axisNo), pC_(pC) {
: sinqAxis(pC, axisNo), pC_(pC),
pMasterMacsA_(std::make_unique<masterMacsAxisImpl>((masterMacsAxisImpl){
.axisStatus = std::bitset<16>(0),
.axisError = std::bitset<16>(0),
.waitForHandshake = false,
.timeAtHandshake = 0,
.targetReachedUninitialized = true,
})) {
asynStatus status = asynSuccess;
@@ -118,14 +125,6 @@ masterMacsAxis::masterMacsAxis(masterMacsController *pC, int axisNo)
// Collect all axes into this list which will be used in the hook function
axes.push_back(this);
pMasterMacsA_ = std::make_unique<masterMacsAxisImpl>((masterMacsAxisImpl){
.axisStatus = std::bitset<16>(0),
.axisError = std::bitset<16>(0),
.waitForHandshake = false,
.timeAtHandshake = 0,
.targetReachedUninitialized = true,
});
// masterMacs motors can always be disabled
status = pC_->setIntegerParam(axisNo_, pC_->motorCanDisable(), 1);
if (status != asynSuccess) {
@@ -330,10 +329,8 @@ asynStatus masterMacsAxis::doPoll(bool *moving) {
// Does the axis need to be intialized?
if (needInit()) {
rw_status = init();
if (rw_status != asynSuccess) {
return rw_status;
}
// Perform the rest of the poll, but remember if sth. failed in the init.
poll_status = init();
}
// Are we currently waiting for a handshake?
@@ -688,6 +685,11 @@ asynStatus masterMacsAxis::doMove(double position, int relative,
double minVelocity, double maxVelocity,
double acceleration) {
// Suppress unused variable warning
(void)minVelocity;
(void)maxVelocity;
(void)acceleration;
// Status of read-write-operations of ASCII commands to the controller
asynStatus status = asynSuccess;
@@ -790,6 +792,9 @@ asynStatus masterMacsAxis::doMove(double position, int relative,
asynStatus masterMacsAxis::stop(double acceleration) {
// Suppress unused variable warning
(void)acceleration;
asynStatus status = pC_->write(axisNo_, 00, "8");
if (status != asynSuccess) {
setAxisParamChecked(this, motorStatusProblem, true);
@@ -845,13 +850,19 @@ asynStatus masterMacsAxis::nodeReset() {
/*
Home the axis. On absolute encoder systems, this is a no-op
*/
asynStatus masterMacsAxis::doHome(double min_velocity, double max_velocity,
asynStatus masterMacsAxis::doHome(double minVelocity, double maxVelocity,
double acceleration, int forwards) {
char response[pC_->MAXBUF_] = {0};
// =========================================================================
// Suppress unused variable warning
(void)minVelocity;
(void)maxVelocity;
(void)acceleration;
(void)forwards;
getAxisParamChecked(this, encoderType, &response);
// Only send the home command if the axis has an incremental encoder
@@ -1246,8 +1257,9 @@ static const iocshArg CreateAxisArg0 = {"Controller name (e.g. mmacs1)",
static const iocshArg CreateAxisArg1 = {"Axis number", iocshArgInt};
static const iocshArg *const CreateAxisArgs[] = {&CreateAxisArg0,
&CreateAxisArg1};
static const iocshFuncDef configMasterMacsCreateAxis = {"masterMacsAxis", 2,
CreateAxisArgs};
static const iocshFuncDef configMasterMacsCreateAxis = {
"masterMacsAxis", 2, CreateAxisArgs,
"Create a new instance of a MasterMACS axis."};
static void configMasterMacsCreateAxisCallFunc(const iocshArgBuf *args) {
masterMacsCreateAxis(args[0].sval, args[1].ival);
}

View File

@@ -16,6 +16,13 @@ class HIDDEN masterMacsAxis : public sinqAxis {
*/
masterMacsAxis(masterMacsController *pController, int axisNo);
/**
* @brief Delete the copy and copy assignment constructors, because this
* class should not be copied (it is tied to hardware!)
*/
masterMacsAxis(const masterMacsAxis &) = delete;
masterMacsAxis &operator=(const masterMacsAxis &) = delete;
/**
* @brief Destroy the masterMacsAxis
*
@@ -50,13 +57,13 @@ class HIDDEN masterMacsAxis : public sinqAxis {
*
* @param position
* @param relative
* @param min_velocity
* @param max_velocity
* @param minVelocity
* @param maxVelocity
* @param acceleration
* @return asynStatus
*/
asynStatus doMove(double position, int relative, double min_velocity,
double max_velocity, double acceleration);
asynStatus doMove(double position, int relative, double minVelocity,
double maxVelocity, double acceleration);
/**
* @brief Implementation of the `stop` function from asynMotorAxis

View File

@@ -12,6 +12,28 @@
#include <string>
#include <unistd.h>
/*
These functions are used to read out the compiler flags defining the major and
minor versions. See README.md, section "Firmware version checking" for
details. If these flags are not given, a default value of -1 is used, which
disables the version checks (it suffices to have one of these at -1 to disable
both major and minor version check)
*/
constexpr int firmware_major_version() {
#ifdef FIRMWARE_MAJOR_VERSION
return FIRMWARE_MAJOR_VERSION;
#else
return -1;
#endif
}
constexpr int firmware_minor_version() {
#ifdef FIRMWARE_MINOR_VERSION
return FIRMWARE_MINOR_VERSION;
#else
return -1;
#endif
}
struct masterMacsControllerImpl {
double comTimeout;
@@ -59,17 +81,18 @@ masterMacsController::masterMacsController(const char *portName,
: sinqController(portName, ipPortConfigName, numAxes, movingPollPeriod,
idlePollPeriod,
// No additional parameter library entries
0)
0),
pMasterMacsC_(
std::make_unique<masterMacsControllerImpl>((masterMacsControllerImpl){
.comTimeout = comTimeout,
.nodeReset = 0, // Overwritten later
}))
{
// Initialization of local variables
asynStatus status = asynSuccess;
pMasterMacsC_ =
std::make_unique<masterMacsControllerImpl>((masterMacsControllerImpl){
.comTimeout = comTimeout,
});
char response[MAXBUF_] = {0};
// =========================================================================
// Create additional parameter library entries
@@ -116,6 +139,60 @@ masterMacsController::masterMacsController(const char *portName,
pasynOctetSyncIO->disconnect(pasynOctetSyncIOipPort());
exit(-1);
}
// =========================================================================
if (firmware_major_version() >= 0 && firmware_minor_version() >= 0) {
// Check the firmware version according to the conditions outlined in
// README.md
status = read(0, 99, response);
if (status == asynSuccess) {
// Just interpret the version if the variable already exists
double versionRaw = 0.0;
int nvals = sscanf(response, "%lf", &versionRaw);
if (nvals == 1 && versionRaw != 0.0) {
// Discard decimal part
long long versionInt = (long long)versionRaw;
// Extract bugfix (last 3 digits)
// Currently not used, just here for completions sake
// int bugfix = versionInt % 1000;
versionInt /= 1000;
// Extract minor (next 3 digits)
int minor = versionInt % 1000;
versionInt /= 1000;
// Remaining is major
int major = (int)versionInt;
// Compare to target values
if (firmware_major_version() != major ||
firmware_minor_version() > minor) {
asynPrint(this->pasynUser(), ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d\nFATAL ERROR "
"(Incorrect "
"version number of firmware: Expected major "
"version equal "
"to %d, got %d. Expected minor version equal to "
"or larger "
"than %d, got %d).\nTerminating IOC",
portName, __PRETTY_FUNCTION__, __LINE__,
firmware_major_version(), major,
firmware_minor_version(), minor);
exit(-1);
}
}
} else {
asynPrint(
this->pasynUser(), ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d\nCould not read firmware "
"version\n",
portName, __PRETTY_FUNCTION__, __LINE__);
}
}
}
/*
@@ -154,7 +231,7 @@ asynStatus masterMacsController::writeInt32(asynUser *pasynUser,
}
asynStatus masterMacsController::read(int axisNo, int tcpCmd, char *response,
double comTimeout) {
double /*comTimeout*/) {
return writeRead(axisNo, tcpCmd, NULL, response);
}
@@ -199,12 +276,6 @@ asynStatus masterMacsController::writeRead(int axisNo, int tcpCmd,
comTimeout = pMasterMacsC_->comTimeout;
}
masterMacsAxis *axis = getMasterMacsAxis(axisNo);
if (axis == nullptr) {
// We already did the error logging directly in getAxis
return asynError;
}
// Build the full command depending on the inputs to this function
if (isRead) {
snprintf(fullCommand, MAXBUF_ - 1, "%dR%02d\x0D", axisNo, tcpCmd);
@@ -286,32 +357,39 @@ asynStatus masterMacsController::writeRead(int axisNo, int tcpCmd,
}
// Log the overall status (communication successfull or not)
if (status == asynSuccess) {
setAxisParamChecked(axis, motorStatusCommsError, false);
} else {
if (axisNo != 0) {
masterMacsAxis *axis = getMasterMacsAxis(axisNo);
if (axis == nullptr) {
// We already did the error logging directly in getAxis
return asynError;
}
/*
Since the communication failed, there is the possibility that the
controller is not connected at all to the network. In that case, we
cannot be sure that the information read out in the init method of the
axis is still up-to-date the next time we get a connection. Therefore,
an info flag is set which the axis object can use at the start of its
poll method to try to initialize itself.
*/
axis->setNeedInit(true);
/*
Check if the axis already is in an error communication mode. If
it is not, upstream the error. This is done to avoid "flooding"
the user with different error messages if more than one error
ocurred before an error-free communication
*/
getAxisParamChecked(axis, motorStatusProblem, &motorStatusProblem);
if (motorStatusProblem == 0) {
setAxisParamChecked(axis, motorMessageText, drvMessageText);
setAxisParamChecked(axis, motorStatusProblem, true);
if (status == asynSuccess) {
setAxisParamChecked(axis, motorStatusCommsError, false);
} else {
/*
Since the communication failed, there is the possibility that the
controller is not connected at all to the network. In that case, we
cannot be sure that the information read out in the init method of
the axis is still up-to-date the next time we get a connection.
Therefore, an info flag is set which the axis object can use at the
start of its poll method to try to initialize itself.
*/
axis->setNeedInit(true);
/*
Check if the axis already is in an error communication mode. If
it is not, upstream the error. This is done to avoid "flooding"
the user with different error messages if more than one error
ocurred before an error-free communication
*/
getAxisParamChecked(axis, motorStatusProblem, &motorStatusProblem);
if (motorStatusProblem == 0) {
setAxisParamChecked(axis, motorMessageText, drvMessageText);
setAxisParamChecked(axis, motorStatusProblem, true);
setAxisParamChecked(axis, motorStatusCommsError, false);
}
}
}
@@ -334,7 +412,7 @@ asynStatus masterMacsController::parseResponse(
bool responseValid = false;
int responseStart = 0;
asynStatus status = asynSuccess;
int prevConnected = 0;
int prevConnected = 1;
char printableCommand[MAXBUF_] = {0};
char printableResponse[MAXBUF_] = {0};
@@ -342,12 +420,14 @@ asynStatus masterMacsController::parseResponse(
msgPrintControlKey(portName, axisNo, __PRETTY_FUNCTION__, __LINE__);
masterMacsAxis *axis = getMasterMacsAxis(axisNo);
if (axis == nullptr) {
if (axisNo != 0 && axis == nullptr) {
return asynError;
}
// Was the motor previously connected?
getAxisParamChecked(axis, motorConnected, &prevConnected);
if (axis != nullptr) {
getAxisParamChecked(axis, motorConnected, &prevConnected);
}
// We don't use strlen here since the C string terminator 0x00
// occurs in the middle of the char array.
@@ -371,14 +451,17 @@ asynStatus masterMacsController::parseResponse(
"connected.\n",
portName, axisNo, __PRETTY_FUNCTION__, __LINE__);
setAxisParamChecked(axis, motorConnected, true);
status = callParamCallbacks();
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line "
"%d:\nCould not update parameter library\n",
portName, axisNo, __PRETTY_FUNCTION__, __LINE__);
return status;
if (axis != nullptr) {
setAxisParamChecked(axis, motorConnected, true);
status = callParamCallbacks();
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line "
"%d:\nCould not update parameter library\n",
portName, axisNo, __PRETTY_FUNCTION__,
__LINE__);
return status;
}
}
}
@@ -399,14 +482,17 @@ asynStatus masterMacsController::parseResponse(
"disconnected.\n",
portName, axisNo, __PRETTY_FUNCTION__, __LINE__);
setAxisParamChecked(axis, motorConnected, false);
status = callParamCallbacks();
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line "
"%d:\nCould not update parameter library\n",
portName, axisNo, __PRETTY_FUNCTION__, __LINE__);
return status;
if (axis != nullptr) {
setAxisParamChecked(axis, motorConnected, false);
status = callParamCallbacks();
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line "
"%d:\nCould not update parameter library\n",
portName, axisNo, __PRETTY_FUNCTION__,
__LINE__);
return status;
}
}
}
break;
@@ -553,7 +639,8 @@ static const iocshArg *const CreateControllerArgs[] = {
&CreateControllerArg0, &CreateControllerArg1, &CreateControllerArg2,
&CreateControllerArg3, &CreateControllerArg4, &CreateControllerArg5};
static const iocshFuncDef configMasterMacsCreateController = {
"masterMacsController", 6, CreateControllerArgs};
"masterMacsController", 6, CreateControllerArgs,
"Create a new instance of a MasterMACS controller."};
static void configMasterMacsCreateControllerCallFunc(const iocshArgBuf *args) {
masterMacsCreateController(args[0].sval, args[1].sval, args[2].ival,
args[3].dval, args[4].dval, args[5].dval);

View File

@@ -38,6 +38,13 @@ class HIDDEN masterMacsController : public sinqController {
int numAxes, double movingPollPeriod,
double idlePollPeriod, double comTimeout);
/**
* @brief Delete the copy and copy assignment constructors, because this
* class should not be copied (it is tied to hardware!)
*/
masterMacsController(const masterMacsController &) = delete;
masterMacsController &operator=(const masterMacsController &) = delete;
/**
* @brief Overloaded version of the sinqController version
*