SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
pvaSDDS.h
Go to the documentation of this file.
1/**
2 * @file pvaSDDS.h
3 * @brief Functions for managing and interacting with Process Variable Array (PVA) structures.
4 *
5 * @details
6 * This file includes a set of functions to allocate, reallocate, free, connect, monitor, and
7 * extract values for Process Variable Arrays (PVA) using EPICS PVAccess and PVData libraries.
8 * It provides utilities for managing PVAs in scenarios where EPICS Channel Access (CA) and
9 * PVAccess (PVA) protocols are used to interact with control system process variables.
10 *
11 * @copyright
12 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
13 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
14 *
15 * @license
16 * This file is distributed under the terms of the Software License Agreement
17 * found in the file LICENSE included with this distribution.
18 *
19 * @authors
20 * R. Soliday,
21 */
22
23#include "pv/pvaClient.h"
24#include "pv/pvaClientMultiChannel.h"
25#include "pv/pvEnumerated.h"
26//#include "../modules/pvAccess/src/ca/caChannel.h"
27
28/* Example Callback Requesters
29
30 To use these you will need to add one or more of the following:
31
32 pva->stateChangeReqPtr = exampleStateChangeRequester::create();
33 pva->getReqPtr = exampleGetRequester::create();
34 pva->monitorReqPtr = exampleMonitorRequester::create();
35 pva->putReqPtr = examplePutRequester::create();
36
37*/
39typedef std::tr1::shared_ptr<exampleStateChangeRequester> exampleStateChangeRequesterPtr;
41typedef std::tr1::shared_ptr<exampleGetRequester> exampleGetRequesterPtr;
43typedef std::tr1::shared_ptr<exampleMonitorRequester> exampleMonitorRequesterPtr;
45typedef std::tr1::shared_ptr<examplePutRequester> examplePutRequesterPtr;
46
47class epicsShareClass exampleStateChangeRequester : public epics::pvaClient::PvaClientChannelStateChangeRequester,
48 public std::tr1::enable_shared_from_this<exampleStateChangeRequester> {
49public:
50 POINTER_DEFINITIONS(exampleStateChangeRequester);
52 }
53
54 static exampleStateChangeRequesterPtr create() {
55 exampleStateChangeRequesterPtr client(exampleStateChangeRequesterPtr(new exampleStateChangeRequester()));
56 return client;
57 }
58
59 virtual void channelStateChange(epics::pvaClient::PvaClientChannelPtr const &channel, bool isConnected) {
60 if (isConnected)
61 fprintf(stdout, "StateChange: %s is connected\n", channel->getChannelName().c_str());
62 else
63 fprintf(stdout, "StateChange: %s is not connected\n", channel->getChannelName().c_str());
64 }
65};
66
67class epicsShareClass exampleGetRequester : public epics::pvaClient::PvaClientGetRequester,
68 public std::tr1::enable_shared_from_this<exampleGetRequester> {
69public:
70 POINTER_DEFINITIONS(exampleGetRequester);
72 }
73
74 static exampleGetRequesterPtr create() {
75 exampleGetRequesterPtr client(exampleGetRequesterPtr(new exampleGetRequester()));
76 return client;
77 }
78
79 virtual void channelGetConnect(const epics::pvData::Status &status,
80 epics::pvaClient::PvaClientGetPtr const &clientGet) {
81 fprintf(stdout, "ChannelGetConnected: status=%s %s\n",
82 epics::pvData::Status::StatusTypeName[status.getType()],
83 clientGet->getPvaClientChannel()->getChannelName().c_str());
84 }
85 virtual void getDone(const epics::pvData::Status &status,
86 epics::pvaClient::PvaClientGetPtr const &clientGet) {
87 fprintf(stdout, "GetDone: status=%s %s\n",
88 epics::pvData::Status::StatusTypeName[status.getType()],
89 clientGet->getPvaClientChannel()->getChannelName().c_str());
90 }
91};
92
93class epicsShareClass exampleMonitorRequester : public epics::pvaClient::PvaClientMonitorRequester,
94 public std::tr1::enable_shared_from_this<exampleMonitorRequester> {
95public:
96 POINTER_DEFINITIONS(exampleMonitorRequester);
98 }
99
100 static exampleMonitorRequesterPtr create() {
101 exampleMonitorRequesterPtr client(exampleMonitorRequesterPtr(new exampleMonitorRequester()));
102 return client;
103 }
104
105 virtual void monitorConnect(const epics::pvData::Status &status,
106 epics::pvaClient::PvaClientMonitorPtr const &monitor,
107 epics::pvData::StructureConstPtr const &structure) {
108 fprintf(stdout, "MonitorConnected: status=%s %s\n",
109 epics::pvData::Status::StatusTypeName[status.getType()],
110 monitor->getPvaClientChannel()->getChannelName().c_str());
111 }
112 virtual void event(epics::pvaClient::PvaClientMonitorPtr const &monitor) {
113 fprintf(stdout, "Event: %s\n", monitor->getPvaClientChannel()->getChannelName().c_str());
114 }
115 virtual void unlisten() {
116 fprintf(stdout, "Unlisten: \n");
117 }
118};
119
120class epicsShareClass examplePutRequester : public epics::pvaClient::PvaClientPutRequester,
121 public std::tr1::enable_shared_from_this<examplePutRequester> {
122public:
123 POINTER_DEFINITIONS(examplePutRequester);
125 }
126
127 static examplePutRequesterPtr create() {
128 examplePutRequesterPtr client(examplePutRequesterPtr(new examplePutRequester()));
129 return client;
130 }
131
132 virtual void channelPutConnect(const epics::pvData::Status &status,
133 epics::pvaClient::PvaClientPutPtr const &clientPut) {
134 fprintf(stdout, "ChannelPutConnected: status=%s %s\n",
135 epics::pvData::Status::StatusTypeName[status.getType()],
136 clientPut->getPvaClientChannel()->getChannelName().c_str());
137 }
138 virtual void getDone(const epics::pvData::Status &status,
139 epics::pvaClient::PvaClientPutPtr const &clientPut) {
140 fprintf(stdout, "GetDone: status=%s %s\n",
141 epics::pvData::Status::StatusTypeName[status.getType()],
142 clientPut->getPvaClientChannel()->getChannelName().c_str());
143 }
144 virtual void putDone(const epics::pvData::Status &status,
145 epics::pvaClient::PvaClientPutPtr const &clientPut) {
146 fprintf(stdout, "PutDone: status=%s %s\n",
147 epics::pvData::Status::StatusTypeName[status.getType()],
148 clientPut->getPvaClientChannel()->getChannelName().c_str());
149 }
150};
151
152typedef struct
153{
154 double *values;
155 char **stringValues;
156} PVA_DATA;
157
158typedef struct
159{
160 long numGetElements;
161 long numPutElements;
162 long numMonitorElements;
163 long numGetReadings;
164 long numMonitorReadings;
165 bool numeric;
166 bool nonnumeric;
167 bool pvEnumeratedStructure;
168 epics::pvData::Type fieldType;
169 epics::pvData::ScalarType scalarType;
170 PVA_DATA *getData;
171 PVA_DATA *putData;
172 PVA_DATA *monitorData;
173 double mean, median, sigma, min, max, spread, stDev, rms, MAD;
174 bool haveGetPtr, havePutPtr, haveMonitorPtr;
175 char *units;
176 int alarmSeverity;
177 int L1Ptr;
178 int L2Ptr;
179 bool skip;
181
182typedef struct
183{
184 epics::pvaClient::PvaClientPtr pvaClientPtr;
185 std::vector<epics::pvaClient::PvaClientMultiChannelPtr> pvaClientMultiChannelPtr;
186 int numMultiChannels;
187 std::vector<epics::pvaClient::PvaClientGetPtr> pvaClientGetPtr;
188 std::vector<epics::pvaClient::PvaClientPutPtr> pvaClientPutPtr;
189 std::vector<epics::pvaClient::PvaClientMonitorPtr> pvaClientMonitorPtr;
190
191 epics::pvData::shared_vector<const std::string> pvaChannelNames;
192 epics::pvData::shared_vector<const std::string> pvaChannelNamesTop;
193 epics::pvData::shared_vector<const std::string> pvaChannelNamesSub;
194 epics::pvData::shared_vector<epics::pvData::boolean> isConnected; //numInternalPVs
195 epics::pvData::shared_vector<epics::pvData::boolean> isInternalConnected; //numInternalPVs
196 epics::pvData::shared_vector<const std::string> pvaProvider;
197 epics::pvaClient::PvaClientChannelStateChangeRequesterPtr stateChangeReqPtr;
198 epics::pvaClient::PvaClientGetRequesterPtr getReqPtr;
199 epics::pvaClient::PvaClientMonitorRequesterPtr monitorReqPtr;
200 epics::pvaClient::PvaClientPutRequesterPtr putReqPtr;
201 bool useStateChangeCallbacks;
202 bool useGetCallbacks;
203 bool useMonitorCallbacks;
204 bool usePutCallbacks;
205 bool includeAlarmSeverity;
206 long numPVs, prevNumPVs, numInternalPVs, prevNumInternalPVs, numNotConnected;
207 PVA_DATA_ALL_READINGS *pvaData;
208 bool limitGetReadings;
210
211void allocPVA(PVA_OVERALL *pva, long PVs);
212void allocPVA(PVA_OVERALL *pva, long PVs, long repeats);
213void reallocPVA(PVA_OVERALL *pva, long PVs);
214void reallocPVA(PVA_OVERALL *pva, long PVs, long repeats);
215void freePVA(PVA_OVERALL *pva);
216void freePVAGetReadings(PVA_OVERALL *pva);
217void freePVAMonitorReadings(PVA_OVERALL *pva);
218void ConnectPVA(PVA_OVERALL *pva, double pendIOTime);
219long GetPVAValues(PVA_OVERALL *pva);
220long GetPVAValues(PVA_OVERALL **pva, long count);
221long PrepPut(PVA_OVERALL *pva, long index, double value);
222long PrepPut(PVA_OVERALL *pva, long index, int64_t value);
223long PrepPut(PVA_OVERALL *pva, long index, char *value);
224long PrepPut(PVA_OVERALL *pva, long index, double *value, long length);
225long PrepPut(PVA_OVERALL *pva, long index, int64_t *value, long length);
226long PrepPut(PVA_OVERALL *pva, long index, char **value, long length);
227long PutPVAValues(PVA_OVERALL *pva);
228long MonitorPVAValues(PVA_OVERALL *pva);
229long PollMonitoredPVA(PVA_OVERALL *pva);
230long PollMonitoredPVA(PVA_OVERALL **pva, long count);
231long WaitEventMonitoredPVA(PVA_OVERALL *pva, long index, double secondsToWait);
232long count_chars(char *string, char c);
233long ExtractPVAUnits(PVA_OVERALL *pva);
234void PausePVAMonitoring(PVA_OVERALL **pva, long count);
235void PausePVAMonitoring(PVA_OVERALL *pva);
236void ResumePVAMonitoring(PVA_OVERALL **pva, long count);
237void ResumePVAMonitoring(PVA_OVERALL *pva);
238
239std::string GetProviderName(PVA_OVERALL *pva, long index);
240std::string GetRemoteAddress(PVA_OVERALL *pva, long index);
241bool HaveReadAccess(PVA_OVERALL *pva, long index);
242bool HaveWriteAccess(PVA_OVERALL *pva, long index);
243std::string GetAlarmSeverity(PVA_OVERALL *pva, long index);
244std::string GetStructureID(PVA_OVERALL *pva, long index);
245std::string GetFieldType(PVA_OVERALL *pva, long index);
246bool IsEnumFieldType(PVA_OVERALL *pva, long index);
247uint32_t GetElementCount(PVA_OVERALL *pva, long index);
248std::string GetNativeDataType(PVA_OVERALL *pva, long index);
249std::string GetUnits(PVA_OVERALL *pva, long index);
250uint32_t GetEnumChoices(PVA_OVERALL *pva, long index, char ***choices);
251
252//Internal Functions
253long ExtractPVAValues(PVA_OVERALL *pva);
254long ExtractNTScalarValue(PVA_OVERALL *pva, long index, epics::pvData::PVStructurePtr pvStructurePtr, bool monitorMode);
255long ExtractNTScalarArrayValue(PVA_OVERALL *pva, long index, epics::pvData::PVStructurePtr pvStructurePtr, bool monitorMode);
256long ExtractNTEnumValue(PVA_OVERALL *pva, long index, epics::pvData::PVStructurePtr pvStructurePtr, bool monitorMode);
257long ExtractScalarValue(PVA_OVERALL *pva, long index, epics::pvData::PVFieldPtr PVFieldPtr, bool monitorMode);
258long ExtractScalarArrayValue(PVA_OVERALL *pva, long index, epics::pvData::PVFieldPtr PVFieldPtr, bool monitorMode);
259long ExtractStructureValue(PVA_OVERALL *pva, long index, epics::pvData::PVFieldPtr PVFieldPtr, bool monitorMode);
260
261long PutNTScalarValue(PVA_OVERALL *pva, long index);
262long PutNTScalarArrayValue(PVA_OVERALL *pva, long index);
263long PutNTEnumValue(PVA_OVERALL *pva, long index);
264long PutScalarValue(PVA_OVERALL *pva, long index, epics::pvData::PVFieldPtr PVFieldPtr);
265long PutScalarArrayValue(PVA_OVERALL *pva, long index, epics::pvData::PVFieldPtr PVFieldPtr);
266long PutStructureValue(PVA_OVERALL *pva, long index, epics::pvData::PVFieldPtr PVFieldPtr);