Simplified paramLib access and show error messages for one poll cycle

Simplified getting and setting paramLib entries via a macro and created
a mechanism within poll() which makes sure that error messages are shown
for at least one poll cycle. Also moved MAXBUF_ to the SinqController
level.
This commit is contained in:
2025-05-14 15:59:48 +02:00
parent 9792697d03
commit 9bc90cff61
5 changed files with 48 additions and 70 deletions
+34 -20
View File
@@ -100,7 +100,7 @@ asynStatus getAxisParam<char>(sinqAxis *axis, const char *indexName,
int (sinqController::*func)(), char *readValue,
const char *callerFunctionName, int lineNumber) {
int maxChars = 190;
int maxChars = 200;
int indexValue = (axis->pController()->*func)();
asynStatus status = axis->pController()->getStringParam(
@@ -259,6 +259,8 @@ asynStatus sinqAxis::poll(bool *moving) {
asynStatus poll_status = asynSuccess;
int homing = 0;
int adaptivePolling = 0;
char waitingMessage[pC_->MAXBUF_] = {0};
char newMessage[pC_->MAXBUF_] = {0};
/*
If adaptive polling is enabled:
@@ -300,35 +302,42 @@ asynStatus sinqAxis::poll(bool *moving) {
lastPollTime_ = ts;
/*
At the beginning of the poll, it is assumed that the axis has no status
problems and therefore all error indicators are reset. This does not affect
the PVs until callParamCallbacks has been called!
The motorStatusProblem_ field changes the motor record fields SEVR and STAT.
If the "motorMessageText" record currently contains an error message, it
should be shown for at least one poll period. To assure this, it is read out
here from the paramLib into "waitingMessage". If no new error message was
added to the parameter library at the end of the poll cycle, the
"waitingMessage" is briefly put into the paramLib again, then the PVs are
updated and then the message text is cleared again.
*/
setAxisParamChecked(this, motorStatusCommsError, false);
setAxisParamChecked(this, motorMessageText, "");
getAxisParamChecked(this, motorMessageText, &waitingMessage);
// The poll function is just a wrapper around doPoll and
// handles mainly the callParamCallbacks() function. This wrapper is used
// to make sure callParamCallbacks() is called in case of a premature
// return.
// Clear the communication
setAxisParamChecked(this, motorStatusCommsError, false);
/*
The poll function is just a wrapper around doPoll and handles mainly the
callParamCallbacks() function. This wrapper is used to make sure
callParamCallbacks() is called in case of a premature return.
*/
poll_status = doPoll(moving);
// If the poll did not succeed, something went wrong and the motor has a
// status problem.
if (poll_status == asynSuccess) {
setAxisParamChecked(this, motorStatusProblem, false);
} else {
/*
If the poll did not succeed OR if an error message is waiting, something
went wrong and the motor has a status problem. Otherwise, delete the error
message entry which is currently in the paramLib.
*/
if (poll_status != asynSuccess || waitingMessage[0] != '\0') {
setAxisParamChecked(this, motorStatusProblem, true);
} else {
setAxisParamChecked(this, motorMessageText, "");
setAxisParamChecked(this, motorStatusProblem, false);
}
getAxisParamChecked(this, motorStatusHome, &homing);
/*
Motor is in homing mode, was moving, but is not moving anymore -> It can be
assumed that the homing procedure is done.
*/
getAxisParamChecked(this, motorStatusHome, &homing);
if (homing == 1 && !(*moving) && wasMoving_) {
setAxisParamChecked(this, motorStatusHome, false);
setAxisParamChecked(this, motorStatusHomed, true);
@@ -363,6 +372,12 @@ asynStatus sinqAxis::poll(bool *moving) {
poll_status = pl_status;
}
/*
Delete the error message AFTER updating the PVs so it is not there anymore
during the next poll.
*/
setAxisParamChecked(this, motorMessageText, "");
return poll_status;
}
@@ -416,7 +431,6 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity,
if (status == asynSuccess) {
setAxisParamChecked(this, motorMessageText, "Reference drive");
setAxisParamChecked(this, motorStatusHome, true);
setAxisParamChecked(this, motorStatusHomed, false);
setAxisParamChecked(this, motorStatusAtHome, false);