171 lines
6.1 KiB
C++
171 lines
6.1 KiB
C++
/********************************************
|
|
* masterMacsController.h
|
|
*
|
|
* PMAC V3 controller driver based on the asynMotorController class
|
|
*
|
|
* Stefan Mathis, September 2024
|
|
********************************************/
|
|
|
|
#ifndef masterMacsController_H
|
|
#define masterMacsController_H
|
|
#include "sinqAxis.h"
|
|
#include "sinqController.h"
|
|
#include <memory>
|
|
|
|
// Forward declaration of the controller class to resolve the cyclic dependency
|
|
// between the controller and the axis .h-file. See
|
|
// https://en.cppreference.com/w/cpp/language/class.
|
|
class HIDDEN masterMacsAxis;
|
|
|
|
struct HIDDEN masterMacsControllerImpl;
|
|
|
|
class HIDDEN masterMacsController : public sinqController {
|
|
|
|
public:
|
|
/**
|
|
* @brief Construct a new masterMacsController object
|
|
*
|
|
* @param portName See sinqController constructor
|
|
* @param ipPortConfigName See sinqController constructor
|
|
* @param numAxes See sinqController constructor
|
|
* @param movingPollPeriod See sinqController constructor
|
|
* @param idlePollPeriod See sinqController constructor
|
|
* @param comTimeout When trying to communicate with the device,
|
|
the underlying asynOctetSyncIO interface waits for a response until this
|
|
time (in seconds) has passed, then it declares a timeout.
|
|
*/
|
|
masterMacsController(const char *portName, const char *ipPortConfigName,
|
|
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
|
|
*
|
|
* @param pasynUser
|
|
* @param value
|
|
* @return asynStatus
|
|
*/
|
|
asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value);
|
|
|
|
/**
|
|
* @brief Get the axis object
|
|
*
|
|
* @param pasynUser Specify the axis via the asynUser
|
|
* @return masterMacsAxis* If no axis could be found, this is a
|
|
* nullptr
|
|
*/
|
|
masterMacsAxis *getMasterMacsAxis(asynUser *pasynUser);
|
|
|
|
/**
|
|
* @brief Get the axis object
|
|
*
|
|
* @param axisNo Specify the axis via its index
|
|
* @return masterMacsAxis* If no axis could be found, this is a
|
|
* nullptr
|
|
*/
|
|
masterMacsAxis *getMasterMacsAxis(int axisNo);
|
|
|
|
/**
|
|
* @brief Overloaded function of sinqController
|
|
*
|
|
* The function is overloaded to allow resetting the node and changing the
|
|
* operation mode.
|
|
*
|
|
* @param pasynUser Specify the axis via the asynUser
|
|
* @param value New value
|
|
* @return asynStatus
|
|
*/
|
|
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
|
|
|
|
/**
|
|
* @brief Send a command to the hardware (S mode)
|
|
*
|
|
* @param axisNo Axis to which the command should be send
|
|
* @param tcpCmd TCP command key
|
|
* @param payload Value send to MasterMACS.
|
|
* @return asynStatus
|
|
*/
|
|
asynStatus write(int axisNo, int tcpCmd, const char *payload,
|
|
double comTimeout = -1.0);
|
|
|
|
/**
|
|
* @brief Send a command to the hardware and receive a response (R mode)
|
|
*
|
|
* @param axisNo Axis to which the command should be send
|
|
* @param tcpCmd TCP command key
|
|
* @param response Buffer for the response. This buffer is
|
|
* expected to have the size MAXBUF_.
|
|
* @return asynStatus
|
|
*/
|
|
asynStatus read(int axisNo, int tcpCmd, char *response,
|
|
double comTimeout = -1.0);
|
|
|
|
/**
|
|
* @brief Send a command to the hardware (R or S mode) and receive a
|
|
* response in the former case.
|
|
*
|
|
* This function is the internal implementation of the write and read
|
|
* methods.
|
|
*
|
|
* @param axisNo Axis to which the command should be send
|
|
* @param tcpCmd TCP command key
|
|
* @param payload Value send to MasterMACS.
|
|
* @param response Buffer for the response. This buffer is
|
|
* expected to have the size MAXBUF_.
|
|
* @return asynStatus
|
|
*/
|
|
asynStatus writeRead(int axisNo, int tcpCmd, const char *payload,
|
|
char *response, double comTimeout = -1.0);
|
|
|
|
/**
|
|
* @brief Parse "fullResponse" received upon sending "fullCommand".
|
|
*
|
|
* Returns asynSuccess if the response is valid and asynError otherwise.
|
|
* This is an internal function used in writeRead.
|
|
*
|
|
* @param fullCommand Command which was send to the controller
|
|
* @param fullResponse Response which was received
|
|
* @param drvMessageText Buffer for messages send to the user
|
|
* @param valueStart If a payload was included in fullResponse,
|
|
* return the index where it starts.
|
|
* @param valueStop If a payload was included in fullResponse,
|
|
* return the index where it stops.
|
|
* @param axisNo Axis to which the command should be send
|
|
* @param tcpCmd TCP command key
|
|
* @param isRead true, if a payload is expect as part of the
|
|
* answer
|
|
* @return asynStatus
|
|
*/
|
|
asynStatus parseResponse(const char *fullCommand, const char *fullResponse,
|
|
char *drvMessageText, int *valueStart,
|
|
int *valueStop, int axisNo, int tcpCmd,
|
|
bool isRead);
|
|
|
|
// Set the maximum buffer size. This is an empirical value which must be
|
|
// large enough to avoid overflows for all commands to the device /
|
|
// responses from it.
|
|
static const uint32_t MAXBUF_ = 200;
|
|
|
|
/**
|
|
* @brief Get the communication timeout used in the writeRead command
|
|
*
|
|
* @return double Timeout in seconds
|
|
*/
|
|
double comTimeout();
|
|
|
|
// Accessors for additional PVs
|
|
int nodeReset();
|
|
|
|
private:
|
|
std::unique_ptr<masterMacsControllerImpl> pMasterMacsC_;
|
|
};
|
|
|
|
#endif /* masterMacsController_H */
|