|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
// Needed to use strcpy_s from string.h
|
|
|
|
|
#define __STDC_WANT_LIB_EXT1__ 1
|
|
|
|
|
|
|
|
|
|
#include "pmacv3Controller.h"
|
|
|
|
|
#include "asynMotorController.h"
|
|
|
|
@ -11,6 +13,24 @@
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Copy src into dst and replace all carriage returns with spaces
|
|
|
|
|
*
|
|
|
|
|
* @param dst Buffer for the modified string
|
|
|
|
|
* @param src Original string
|
|
|
|
|
*/
|
|
|
|
|
void adjustResponseForPrint(char *dst, const char *src) {
|
|
|
|
|
// Needed to use strcpy_s from string.h
|
|
|
|
|
#ifdef __STDC_LIB_EXT1__
|
|
|
|
|
strcpy_s(dst, src);
|
|
|
|
|
for (size_t i = 0; i < strlen(dst); i++) {
|
|
|
|
|
if (dst[i] == '\r') {
|
|
|
|
|
dst[i] = '_';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Construct a new pmacv3Controller::pmacv3Controller object
|
|
|
|
|
*
|
|
|
|
@ -192,8 +212,9 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
// Definition of local variables.
|
|
|
|
|
asynStatus status = asynSuccess;
|
|
|
|
|
asynStatus pl_status = asynSuccess;
|
|
|
|
|
char full_command[MAXBUF_] = {0};
|
|
|
|
|
char user_message[MAXBUF_] = {0};
|
|
|
|
|
char fullCommand[MAXBUF_] = {0};
|
|
|
|
|
char drvMessageText[MAXBUF_] = {0};
|
|
|
|
|
char modResponse[MAXBUF_] = {0};
|
|
|
|
|
int motorStatusProblem = 0;
|
|
|
|
|
int numReceivedResponses = 0;
|
|
|
|
|
|
|
|
|
@ -232,7 +253,7 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
this protocol encodes the message length at the beginning. See Turbo PMAC
|
|
|
|
|
User Manual, page 418 in VR_PMAC_GETRESPONSE
|
|
|
|
|
|
|
|
|
|
The message has to be build manually into the buffer full_command, since it
|
|
|
|
|
The message has to be build manually into the buffer fullCommand, since it
|
|
|
|
|
contains NULL terminators in its middle, therefore the string manipulation
|
|
|
|
|
methods of C don't work.
|
|
|
|
|
*/
|
|
|
|
@ -242,20 +263,20 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
strlen(command) + 1; // +1 because of the appended /r
|
|
|
|
|
const int offset = 8;
|
|
|
|
|
|
|
|
|
|
// Positions 2 to 6 must have the value 0. Since full_command is initialized
|
|
|
|
|
// Positions 2 to 6 must have the value 0. Since fullCommand is initialized
|
|
|
|
|
// as an array of zeros, we don't need to set these bits manually.
|
|
|
|
|
full_command[0] = '\x40';
|
|
|
|
|
full_command[1] = '\xBF';
|
|
|
|
|
full_command[7] = commandLength;
|
|
|
|
|
fullCommand[0] = '\x40';
|
|
|
|
|
fullCommand[1] = '\xBF';
|
|
|
|
|
fullCommand[7] = commandLength;
|
|
|
|
|
|
|
|
|
|
snprintf((char *)full_command + offset, MAXBUF_ - offset, "%s\r", command);
|
|
|
|
|
snprintf((char *)fullCommand + offset, MAXBUF_ - offset, "%s\r", command);
|
|
|
|
|
asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,
|
|
|
|
|
"%s => line %d:\nSending command %s", __PRETTY_FUNCTION__,
|
|
|
|
|
__LINE__, full_command);
|
|
|
|
|
__LINE__, fullCommand);
|
|
|
|
|
|
|
|
|
|
// Perform the actual writeRead
|
|
|
|
|
status = pasynOctetSyncIO->writeRead(
|
|
|
|
|
lowLevelPortUser_, full_command, commandLength + offset, response,
|
|
|
|
|
lowLevelPortUser_, fullCommand, commandLength + offset, response,
|
|
|
|
|
MAXBUF_, comTimeout_, &nbytesOut, &nbytesIn, &eomReason);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -291,7 +312,7 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
if (status == asynSuccess) {
|
|
|
|
|
// If flushing the MCU succeded, try to send the command again
|
|
|
|
|
status = pasynOctetSyncIO->writeRead(
|
|
|
|
|
lowLevelPortUser_, full_command, commandLength + offset,
|
|
|
|
|
lowLevelPortUser_, fullCommand, commandLength + offset,
|
|
|
|
|
response, MAXBUF_, comTimeout_, &nbytesOut, &nbytesIn,
|
|
|
|
|
&eomReason);
|
|
|
|
|
|
|
|
|
@ -306,15 +327,18 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
|
|
|
|
|
// Second check: If this fails, give up and propagate the error.
|
|
|
|
|
if (numExpectedResponses != numReceivedResponses) {
|
|
|
|
|
asynPrint(
|
|
|
|
|
this->pasynUserSelf, ASYN_TRACE_ERROR,
|
|
|
|
|
"%s => line %d:\nUnexpected response %s for command %s\n",
|
|
|
|
|
__PRETTY_FUNCTION__, __LINE__, response, command);
|
|
|
|
|
snprintf(user_message, sizeof(user_message),
|
|
|
|
|
"Received unexpected response %s for command %s. "
|
|
|
|
|
|
|
|
|
|
adjustResponseForPrint(modResponse, response);
|
|
|
|
|
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
|
|
|
|
|
"%s => line %d:\nUnexpected response %s (_ are "
|
|
|
|
|
"carriage returns) for command %s\n",
|
|
|
|
|
__PRETTY_FUNCTION__, __LINE__, modResponse, command);
|
|
|
|
|
snprintf(drvMessageText, sizeof(drvMessageText),
|
|
|
|
|
"Received unexpected response %s (_ are "
|
|
|
|
|
"carriage returns) for command %s. "
|
|
|
|
|
"Please call the support",
|
|
|
|
|
response, command);
|
|
|
|
|
pl_status = setStringParam(motorMessageText_, user_message);
|
|
|
|
|
modResponse, command);
|
|
|
|
|
pl_status = setStringParam(motorMessageText_, drvMessageText);
|
|
|
|
|
if (pl_status != asynSuccess) {
|
|
|
|
|
return paramLibAccessFailed(pl_status, "motorMessageText_",
|
|
|
|
|
__PRETTY_FUNCTION__, __LINE__);
|
|
|
|
@ -330,23 +354,24 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create custom error messages for different failure modes
|
|
|
|
|
if (strlen(user_message) == 0) {
|
|
|
|
|
if (strlen(drvMessageText) == 0) {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case asynSuccess:
|
|
|
|
|
break; // Communicate nothing
|
|
|
|
|
case asynTimeout:
|
|
|
|
|
snprintf(user_message, sizeof(user_message),
|
|
|
|
|
snprintf(drvMessageText, sizeof(drvMessageText),
|
|
|
|
|
"connection timeout for axis %d", axisNo);
|
|
|
|
|
break;
|
|
|
|
|
case asynDisconnected:
|
|
|
|
|
snprintf(user_message, sizeof(user_message),
|
|
|
|
|
snprintf(drvMessageText, sizeof(drvMessageText),
|
|
|
|
|
"axis is not connected");
|
|
|
|
|
break;
|
|
|
|
|
case asynDisabled:
|
|
|
|
|
snprintf(user_message, sizeof(user_message), "axis is disabled");
|
|
|
|
|
snprintf(drvMessageText, sizeof(drvMessageText),
|
|
|
|
|
"axis is disabled");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
snprintf(user_message, sizeof(user_message),
|
|
|
|
|
snprintf(drvMessageText, sizeof(drvMessageText),
|
|
|
|
|
"Communication failed (%s)", stringifyAsynStatus(status));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -367,7 +392,7 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
|
|
|
|
|
if (motorStatusProblem == 0) {
|
|
|
|
|
pl_status =
|
|
|
|
|
axis->setStringParam(this->motorMessageText_, user_message);
|
|
|
|
|
axis->setStringParam(this->motorMessageText_, drvMessageText);
|
|
|
|
|
if (pl_status != asynSuccess) {
|
|
|
|
|
return paramLibAccessFailed(pl_status, "motorMessageText_",
|
|
|
|
|
__PRETTY_FUNCTION__, __LINE__);
|
|
|
|
@ -377,16 +402,18 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
|
|
|
|
|
|
|
|
|
|
// Log the overall status (communication successfull or not)
|
|
|
|
|
if (status == asynSuccess) {
|
|
|
|
|
|
|
|
|
|
asynPrint(lowLevelPortUser_, ASYN_TRACEIO_DRIVER,
|
|
|
|
|
"%s => line %d:\nDevice response: %s\n", __PRETTY_FUNCTION__,
|
|
|
|
|
__LINE__, response);
|
|
|
|
|
"%s => line %d:\nDevice response: %s (_ are "
|
|
|
|
|
"carriage returns)\n",
|
|
|
|
|
__PRETTY_FUNCTION__, __LINE__, modResponse);
|
|
|
|
|
pl_status = axis->setIntegerParam(this->motorStatusCommsError_, 0);
|
|
|
|
|
} else {
|
|
|
|
|
if (status == asynSuccess) {
|
|
|
|
|
asynPrint(
|
|
|
|
|
lowLevelPortUser_, ASYN_TRACE_ERROR,
|
|
|
|
|
"%s => line %d:\nCommunication failed for command %s (%s)\n",
|
|
|
|
|
__PRETTY_FUNCTION__, __LINE__, full_command,
|
|
|
|
|
__PRETTY_FUNCTION__, __LINE__, fullCommand,
|
|
|
|
|
stringifyAsynStatus(status));
|
|
|
|
|
pl_status = axis->setIntegerParam(this->motorStatusCommsError_, 1);
|
|
|
|
|
}
|
|
|
|
@ -420,6 +447,15 @@ asynStatus pmacv3Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
asynStatus pmacv3Controller::errMsgCouldNotParseResponse(
|
|
|
|
|
const char *command, const char *response, int axisNo,
|
|
|
|
|
const char *functionName, int lineNumber) {
|
|
|
|
|
char modifiedResponse[MAXBUF_] = {0};
|
|
|
|
|
adjustResponseForPrint(modifiedResponse, response);
|
|
|
|
|
return sinqController::errMsgCouldNotParseResponse(
|
|
|
|
|
command, modifiedResponse, axisNo, functionName, lineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*************************************************************************************/
|
|
|
|
|
/** The following functions are C-wrappers, and can be called directly from
|
|
|
|
|
* iocsh */
|
|
|
|
@ -533,9 +569,9 @@ types and then providing "factory" functions
|
|
|
|
|
(configCreateControllerCallFunc). These factory functions are used to
|
|
|
|
|
register the constructors during compilation.
|
|
|
|
|
*/
|
|
|
|
|
static const iocshArg CreateControllerArg0 = {"Controller port name",
|
|
|
|
|
static const iocshArg CreateControllerArg0 = {"Controller name (e.g. mcu1)",
|
|
|
|
|
iocshArgString};
|
|
|
|
|
static const iocshArg CreateControllerArg1 = {"Low level port name",
|
|
|
|
|
static const iocshArg CreateControllerArg1 = {"Asyn IP port name (e.g. pmcu1)",
|
|
|
|
|
iocshArgString};
|
|
|
|
|
static const iocshArg CreateControllerArg2 = {"Number of axes", iocshArgInt};
|
|
|
|
|
static const iocshArg CreateControllerArg3 = {"Moving poll rate (s)",
|
|
|
|
@ -558,7 +594,8 @@ static void configPmacV3CreateControllerCallFunc(const iocshArgBuf *args) {
|
|
|
|
|
Same procedure as for the CreateController function, but for the axis
|
|
|
|
|
itself.
|
|
|
|
|
*/
|
|
|
|
|
static const iocshArg CreateAxisArg0 = {"Controller port name", iocshArgString};
|
|
|
|
|
static const iocshArg CreateAxisArg0 = {"Controller name (e.g. mcu1)",
|
|
|
|
|
iocshArgString};
|
|
|
|
|
static const iocshArg CreateAxisArg1 = {"Axis number", iocshArgInt};
|
|
|
|
|
static const iocshArg *const CreateAxisArgs[] = {&CreateAxisArg0,
|
|
|
|
|
&CreateAxisArg1};
|
|
|
|
|