areaDetector 3-14
EPICS areaDetector framework
specsAnalyser.h
Go to the documentation of this file.
1// Standard includes
2#include <vector>
3#include <sys/stat.h>
4#include <iostream>
5#include <sstream>
6#include <string>
7#include <string.h>
8#include <stdlib.h>
9#include <stdio.h>
10#include <math.h>
11#include <errno.h>
12#include <locale>
13#include <map>
14#include <algorithm>
15
16// EPICS includes
17#include <epicsThread.h>
18#include <epicsEvent.h>
19#include <epicsString.h>
20#include <iocsh.h>
21#include <drvSup.h>
22#include <epicsExport.h>
23
24// areaDetector includes
25#include <ADDriver.h>
26
27// Asyn driver includes
28#include "asynOctetSyncIO.h"
29
30// String length
31#define SPECS_MAX_STRING 4096
32// Asyn timeout
33#define SPECS_TIMEOUT 10
34// SPECS Update rate
35#define SPECS_UPDATE_RATE 0.1
36// SPECS Response OK/ERROR
37#define SPECS_OK_STRING "OK"
38#define SPECS_ERROR_STRING "ERROR"
39
40// SPECS Run Modes
41#define SPECS_RUN_FAT 0
42#define SPECS_RUN_SFAT 1
43#define SPECS_RUN_FRR 2
44#define SPECS_RUN_FE 3
45
46// SPECS Types
47#define SPECS_TYPE_DOUBLE "double"
48#define SPECS_TYPE_INTEGER "integer"
49#define SPECS_TYPE_STRING "string"
50#define SPECS_TYPE_BOOL "bool"
51
52// SPECS Command Strings
53#define SPECS_CMD_CONNECT "Connect"
54#define SPECS_CMD_DISCONNECT "Disconnect"
55#define SPECS_CMD_DEFINE_FAT "DefineSpectrumFAT"
56#define SPECS_CMD_DEFINE_SFAT "DefineSpectrumSFAT"
57#define SPECS_CMD_DEFINE_FRR "DefineSpectrumFRR"
58#define SPECS_CMD_DEFINE_FE "DefineSpectrumFE"
59#define SPECS_CMD_VALIDATE "ValidateSpectrum"
60#define SPECS_CMD_START "Start"
61#define SPECS_CMD_PAUSE "Pause"
62#define SPECS_CMD_RESUME "Resume"
63#define SPECS_CMD_ABORT "Abort"
64#define SPECS_CMD_GET_STATUS "GetAcquisitionStatus"
65#define SPECS_CMD_GET_DATA "GetAcquisitionData"
66#define SPECS_CMD_CLEAR "ClearSpectrum"
67#define SPECS_CMD_GET_NAMES "GetAllAnalyzerParameterNames"
68#define SPECS_CMD_GET_INFO "GetAnalyzerParameterInfo"
69#define SPECS_CMD_GET_VISNAME "GetAnalyzerVisibleName"
70#define SPECS_CMD_GET_VALUE "GetAnalyzerParameterValue"
71#define SPECS_CMD_SET_VALUE "SetAnalyzerParameterValue"
72#define SPECS_CMD_GET_SPECTRUM "GetSpectrumParameterInfo"
73#define SPECS_CMD_GET_DATA_INFO "GetSpectrumDataInfo"
74#define SPECS_CMD_SET_SAFE_STATE "SetSafeState"
75
76// Pre-defined EPICS Parameter Names
77#define SPECSConnectString "SPECS_CONNECT"
78#define SPECSConnectedString "SPECS_CONNECTED"
79#define SPECSPauseAcqString "SPECS_PAUSE_ACQ"
80#define SPECSMsgCounterString "SPECS_MSG_COUNTER"
81#define SPECSServerNameString "SPECS_SERVER_NAME"
82#define SPECSProtocolVersionString "SPECS_PROTOCOL_VERSION"
83#define SPECSProtocolVersionMinorString "SPECS_PROTOCOL_VER_MINOR"
84#define SPECSProtocolVersionMajorString "SPECS_PROTOCOL_VER_MAJOR"
85#define SPECSStartEnergyString "SPECS_START_ENERGY"
86#define SPECSEndEnergyString "SPECS_END_ENERGY"
87#define SPECSRetardingRatioString "SPECS_RETARDING_RATIO"
88#define SPECSKineticEnergyString "SPECS_KINETIC_ENERGY"
89#define SPECSStepWidthString "SPECS_STEP_WIDTH"
90#define SPECSSamplesString "SPECS_SAMPLES"
91#define SPECSSamplesIterationString "SPECS_SAMPLES_ITERATION"
92#define SPECSSnapshotValuesString "SPECS_SNAPSHOT_VALUES"
93#define SPECSPassEnergyString "SPECS_PASS_ENERGY"
94#define SPECSLensModeString "SPECS_LENS_MODE"
95#define SPECSScanRangeString "SPECS_SCAN_RANGE"
96#define SPECSCurrentSampleString "SPECS_CURRENT_SAMPLE"
97#define SPECSPercentCompleteString "SPECS_PERCENT_COMPLETE"
98#define SPECSRemainingTimeString "SPECS_REMAINING_TIME"
99#define SPECSCurrentSampleIterationString "SPECS_CRT_SAMPLE_ITER"
100#define SPECSPercentCompleteIterationString "SPECS_PCT_COMPLETE_ITER"
101#define SPECSRemainingTimeIterationString "SPECS_RMG_TIME_ITER"
102#define SPECSAcqSpectrumString "SPECS_ACQ_SPECTRUM"
103#define SPECSAcqImageString "SPECS_ACQ_IMAGE"
104
105#define SPECSRunModeString "SPECS_RUN_MODE"
106#define SPECSDefineString "SPECS_DEFINE"
107#define SPECSValidateString "SPECS_VALIDATE"
108
109#define SPECSNonEnergyChannelsString "SPECS_NON_ENERGY_CHANNELS"
110#define SPECSNonEnergyUnitsString "SPECS_NON_ENERGY_UNITS"
111#define SPECSNonEnergyMinString "SPECS_NON_ENERGY_MIN"
112#define SPECSNonEnergyMaxString "SPECS_NON_ENERGY_MAX"
113#define SPECSSafeStateString "SPECS_SAFE_STATE"
114#define SPECSDataDelayMaxString "SPECS_DATA_DELAY_MAX"
115
123
128
130{
131 public:
132 SpecsAnalyser(const char *portName, const char *driverPort, int maxBuffers, size_t maxMemory, int priority, int stackSize);
133 virtual ~SpecsAnalyser();
134 void specsAnalyserTask();
135 asynStatus makeConnection();
136 asynStatus connect();
137 asynStatus disconnect();
138 asynStatus readEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements, size_t *nIn);
139 asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
140 asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
141 asynStatus validateSpectrum();
142 asynStatus defineSpectrumFAT();
143 asynStatus defineSpectrumSFAT();
144 asynStatus defineSpectrumFRR();
145 asynStatus defineSpectrumFE();
146 asynStatus readAcquisitionData(int startIndex, int endIndex, std::vector<double> &values);
147 asynStatus sendStartCommand(bool safeAfter);
148 asynStatus sendSimpleCommand(const std::string& command, std::map<std::string, std::string> *data = NULL);
149 asynStatus readDeviceVisibleName();
150 asynStatus setupEPICSParameters();
151 asynStatus getAnalyserParameterType(const std::string& name, SPECSValueType_t &value);
152 asynStatus getAnalyserParameter(const std::string& name, int &value);
153 asynStatus getAnalyserParameter(const std::string& name, double &value);
154 asynStatus getAnalyserParameter(const std::string& name, std::string &value);
155 asynStatus getAnalyserParameter(const std::string& name, bool &value);
156 asynStatus setAnalyserParameter(const std::string& name, int value);
157 asynStatus setAnalyserParameter(const std::string& name, double value);
158 asynStatus setAnalyserParameter(const std::string& name, std::string value);
159 asynStatus readIntegerData(std::map<std::string, std::string> data, const std::string& name, int &value);
160 asynStatus readDoubleData(std::map<std::string, std::string> data, const std::string& name, double &value);
161 asynStatus readSpectrumParameter(int param);
162 asynStatus readRunModes();
164 asynStatus asynPortConnect(const char *port, int addr, asynUser **ppasynUser, const char *inputEos, const char *outputEos);
165 asynStatus asynPortDisconnect(asynUser *pasynUser);
166 asynStatus commandResponse(const std::string &command, std::string &response, std::map<std::string, std::string> &data);
167 asynStatus asynWriteRead(const char *command, char *response);
168
169 // String cleanup routines
170 asynStatus cleanString(std::string &str, const std::string &search = ": \n", int where = 0);
171
172 // Debugging routines
173 asynStatus initDebugger(int initDebug);
174 asynStatus debugLevel(const std::string& method, int onOff);
175 asynStatus debug(const std::string& method, const std::string& msg);
176 asynStatus debug(const std::string& method, const std::string& msg, int value);
177 asynStatus debug(const std::string& method, const std::string& msg, double value);
178 asynStatus debug(const std::string& method, const std::string& msg, const std::string& value);
179 asynStatus debug(const std::string& method, const std::string& msg, std::map<std::string, std::string> value);
180 asynStatus debug(const std::string& method, const std::string& msg, std::map<int, std::string> value);
181
182 protected:
184 #define FIRST_SPECS_PARAM SPECSConnect_
211
215
222 #define LAST_SPECS_PARAM SPECSDataDelayMax_
223
224 private:
225 asynUser *portUser_;
226 char driverPort_[SPECS_MAX_STRING];
227 std::map<std::string, int> debugMap_;
228 epicsEventId startEventId_;
229 epicsEventId stopEventId_;
230 std::vector<std::string> lensModes_;
231 std::vector<std::string> scanRanges_;
232 std::vector<std::string> runModes_;
233 std::map<std::string, std::string> paramMap_;
234 std::map<int, std::string> paramIndexes_;
235 bool firstConnect_;
236};
237
238// Number of asyn parameters (asyn commands) this driver supports
239// Currently hardcoding 100 additional device specific parameters
240#define NUM_SPECS_PARAMS ((int)(&LAST_SPECS_PARAM - &FIRST_SPECS_PARAM + 100))
241
242
Class from which areaDetector drivers are directly derived.
Definition ADDriver.h:132
Definition specsAnalyser.h:130
asynStatus getAnalyserParameter(const std::string &name, int &value)
Definition specsAnalyser.cpp:1518
int SPECSStartEnergy_
Definition specsAnalyser.h:192
asynStatus makeConnection()
Definition specsAnalyser.cpp:180
asynStatus readRunModes()
Definition specsAnalyser.cpp:1740
int SPECSConnected_
Definition specsAnalyser.h:185
int SPECSLensMode_
Definition specsAnalyser.h:201
asynStatus readDeviceVisibleName()
This method queries the analyser for its device name to populate the ADModel parameter.
Definition specsAnalyser.cpp:1345
int SPECSCurrentSample_
Definition specsAnalyser.h:203
int SPECSEndEnergy_
Definition specsAnalyser.h:193
int SPECSScanRange_
Definition specsAnalyser.h:202
asynStatus defineSpectrumFE()
Definition specsAnalyser.cpp:1231
int SPECSNonEnergyMin_
Definition specsAnalyser.h:218
asynStatus debug(const std::string &method, const std::string &msg)
Definition specsAnalyser.cpp:2204
asynStatus readEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements, size_t *nIn)
Called when asyn clients call pasynEnum->read().
Definition specsAnalyser.cpp:716
asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value)
Called when asyn clients call pasynInt32->write().
Definition specsAnalyser.cpp:770
asynStatus asynPortDisconnect(asynUser *pasynUser)
Definition specsAnalyser.cpp:1873
int SPECSNonEnergyMax_
Definition specsAnalyser.h:219
int SPECSMsgCounter_
Definition specsAnalyser.h:187
asynStatus disconnect()
Definition specsAnalyser.cpp:243
int SPECSRetardingRatio_
Definition specsAnalyser.h:194
asynStatus setAnalyserParameter(const std::string &name, int value)
Definition specsAnalyser.cpp:1592
int SPECSPauseAcq_
Definition specsAnalyser.h:186
int SPECSProtocolVersionMinor_
Definition specsAnalyser.h:190
asynStatus readSpectrumParameter(int param)
Definition specsAnalyser.cpp:1663
asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
Called when asyn clients call pasynFloat64->write().
Definition specsAnalyser.cpp:927
asynStatus asynPortConnect(const char *port, int addr, asynUser **ppasynUser, const char *inputEos, const char *outputEos)
Connect to the underlying low level Asyn port that is used for comms.
Definition specsAnalyser.cpp:1831
int SPECSProtocolVersionMajor_
Definition specsAnalyser.h:191
int SPECSNonEnergyChannels_
Definition specsAnalyser.h:216
int SPECSSamplesIteration_
Definition specsAnalyser.h:198
asynStatus asynWriteRead(const char *command, char *response)
Wrapper for asynOctetSyncIO write/read functions.
Definition specsAnalyser.cpp:2042
asynStatus setupEPICSParameters()
This method sets up the analyser parameters that are not known prior to connecting to the device.
Definition specsAnalyser.cpp:1367
asynStatus readAcquisitionData(int startIndex, int endIndex, std::vector< double > &values)
Definition specsAnalyser.cpp:1269
int SPECSValidate_
Definition specsAnalyser.h:214
void specsAnalyserTask()
Task to listen to the SPECS prodigy application and update the higher level software.
Definition specsAnalyser.cpp:268
asynStatus debugLevel(const std::string &method, int onOff)
Definition specsAnalyser.cpp:2172
int SPECSSnapshotValues_
Definition specsAnalyser.h:199
int SPECSConnect_
Definition specsAnalyser.h:183
int SPECSRunMode_
Definition specsAnalyser.h:212
asynStatus readSpectrumDataInfo(SPECSDataInfoParam_t param)
Send the GetSpectrumDataInfo method to query the spectrum metadata.
Definition specsAnalyser.cpp:1764
int SPECSDefine_
Definition specsAnalyser.h:213
asynStatus getAnalyserParameterType(const std::string &name, SPECSValueType_t &value)
Definition specsAnalyser.cpp:1495
asynStatus validateSpectrum()
Validate the currently defined spectrum.
Definition specsAnalyser.cpp:979
int SPECSSafeState_
Definition specsAnalyser.h:220
int SPECSPercentComplete_
Definition specsAnalyser.h:204
int SPECSPercentCompleteIteration_
Definition specsAnalyser.h:207
asynStatus sendSimpleCommand(const std::string &command, std::map< std::string, std::string > *data=NULL)
Method for sending a simple command (no parameters) that will check the error status and do the right...
Definition specsAnalyser.cpp:1313
asynStatus readIntegerData(std::map< std::string, std::string > data, const std::string &name, int &value)
Definition specsAnalyser.cpp:1635
asynStatus cleanString(std::string &str, const std::string &search=": \n", int where=0)
Utility function, returns strings with unwanted characters stripped.
Definition specsAnalyser.cpp:2126
asynStatus sendStartCommand(bool safeAfter)
Send the start command to the analyser.
Definition specsAnalyser.cpp:1078
int SPECSNonEnergyUnits_
Definition specsAnalyser.h:217
int SPECSCurrentSampleIteration_
Definition specsAnalyser.h:206
asynStatus defineSpectrumFAT()
Define a Fixed Analyser Transmission spectrum.
Definition specsAnalyser.cpp:1106
asynStatus defineSpectrumSFAT()
Define a Snapshot Fixed Analyser Transmission spectrum.
Definition specsAnalyser.cpp:1152
asynStatus defineSpectrumFRR()
Definition specsAnalyser.cpp:1190
virtual ~SpecsAnalyser()
specsAnalyser destructor
Definition specsAnalyser.cpp:40
int SPECSServerName_
Definition specsAnalyser.h:188
asynStatus connect()
Definition specsAnalyser.cpp:220
int SPECSStepWidth_
Definition specsAnalyser.h:196
asynStatus readDoubleData(std::map< std::string, std::string > data, const std::string &name, double &value)
Definition specsAnalyser.cpp:1649
int SPECSKineticEnergy_
Definition specsAnalyser.h:195
int SPECSProtocolVersion_
Definition specsAnalyser.h:189
int SPECSPassEnergy_
Definition specsAnalyser.h:200
int SPECSRemainingTimeIteration_
Definition specsAnalyser.h:208
int SPECSRemainingTime_
Definition specsAnalyser.h:205
int SPECSAcqImage_
Definition specsAnalyser.h:210
int SPECSDataDelayMax_
Definition specsAnalyser.h:221
asynStatus commandResponse(const std::string &command, std::string &response, std::map< std::string, std::string > &data)
This sends a command to the device and parses the response.
Definition specsAnalyser.cpp:1897
int SPECSAcqSpectrum_
Definition specsAnalyser.h:209
asynStatus initDebugger(int initDebug)
Definition specsAnalyser.cpp:2143
int SPECSSamples_
Definition specsAnalyser.h:197
SPECSValueType_t
Definition specsAnalyser.h:117
@ SPECSTypeString
Definition specsAnalyser.h:120
@ SPECSTypeInteger
Definition specsAnalyser.h:119
@ SPECSTypeDouble
Definition specsAnalyser.h:118
@ SPECSTypeBool
Definition specsAnalyser.h:121
#define SPECS_MAX_STRING
Definition specsAnalyser.h:31
SPECSDataInfoParam_t
Definition specsAnalyser.h:125
@ SPECSOrdinateRange
Definition specsAnalyser.h:126
Definition restApi.cpp:92