Accelerator Independent Data Access / PVAccess 2.0
AIDA-PVA is the latest version of the AIDA framework. Built on top of EPICS 7 it enables client applications to programmatically access and manage any device or database on the SLAC Network using simple channel names.
Loading...
Searching...
No Matches
AIDASLCUTIL_SERVER.c File Reference

Utility Native Provider implementation. More...

#include <descrip.h>
#include <float.h>
#include "aida_pva.h"
#include "descr.h"
#include "ref.h"
#include "crrcntl_parms.h"
#include "bpmutil_proto.h"
#include "AIDASLCUTIL_SERVER.h"

Go to the source code of this file.

Functions

int aidaRequestBoolean (JNIEnv *env, const char *uri, Arguments arguments)
 Get a Boolean. More...
 
int aidaRequestInteger (JNIEnv *env, const char *uri, Arguments arguments)
 Get an integer. More...
 
long aidaRequestLong (JNIEnv *env, const char *uri, Arguments arguments)
 Get a integer. More...
 
short aidaRequestShort (JNIEnv *env, const char *uri, Arguments arguments)
 Get a short. More...
 
char * aidaRequestString (JNIEnv *env, const char *uri, Arguments arguments)
 Get a string. More...
 
Table aidaRequestTable (JNIEnv *env, const char *uri, Arguments arguments)
 Implement Correlated Plots. More...
 
REQUEST_STUB_BYTE REQUEST_STUB_FLOAT REQUEST_STUB_DOUBLE REQUEST_STUB_BOOLEAN_ARRAY REQUEST_STUB_BYTE_ARRAY REQUEST_STUB_SHORT_ARRAY REQUEST_STUB_INTEGER_ARRAY REQUEST_STUB_LONG_ARRAY REQUEST_STUB_FLOAT_ARRAY REQUEST_STUB_DOUBLE_ARRAY REQUEST_STUB_STRING_ARRAY void aidaServiceInit (JNIEnv *env)
 Initialise the service. More...
 
void aidaSetValue (JNIEnv *env, const char *uri, Arguments arguments, Value value)
 Set a value: BGRP Set Variable or SCP transverse feedback. More...
 
Table aidaSetValueWithResponse (JNIEnv *env, const char *uri, Arguments arguments, Value value)
 Set a value and return a table as a response. More...
 

Detailed Description

Utility Native Provider implementation.

MEMBER=SLCLIBS:AIDA_PVALIB ATTRIBUTES=JNI,LIBR_NOGLOBAL

Definition in file AIDASLCUTIL_SERVER.c.

Function Documentation

◆ aidaRequestBoolean()

int aidaRequestBoolean ( JNIEnv *  env,
const char *  uri,
Arguments  arguments 
)

Get a Boolean.

Get a boolean.

Parameters
urithe uri
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
argumentsthe arguments
Returns
the boolean

Definition at line 100 of file AIDASLCUTIL_SERVER.c.

100 {
101 return getShortFaStatus(env, uri) == 0 ? false : true;
102}

References aidaThrow(), TO_SLC_NAME, and UNABLE_TO_GET_DATA_EXCEPTION.

◆ aidaRequestInteger()

int aidaRequestInteger ( JNIEnv *  env,
const char *  uri,
Arguments  arguments 
)

Get an integer.

Get a integer.

Parameters
urithe uri
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
argumentsthe arguments
Returns
the integer

Definition at line 88 of file AIDASLCUTIL_SERVER.c.

88 {
89 return getShortFaStatus(env, uri);
90}

References aidaThrow(), TO_SLC_NAME, and UNABLE_TO_GET_DATA_EXCEPTION.

◆ aidaRequestLong()

long aidaRequestLong ( JNIEnv *  env,
const char *  uri,
Arguments  arguments 
)

Get a integer.

Get a long.

Parameters
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
urithe uri
argumentsthe arguments
Returns
the integer

Definition at line 112 of file AIDASLCUTIL_SERVER.c.

112 {
113 if (startsWith(uri, "FBCK")) {
114 return (long)faStatus(env, uri, 0, TRUE_B);
115 } else {
116 return (long)getTrigStatus(env, uri, arguments);
117 }
118}
int startsWith(const char *str, char *prefix)
Check if a string starts with another string.

References aidaThrow(), startsWith(), TO_SLC_NAME, and UNABLE_TO_GET_DATA_EXCEPTION.

◆ aidaRequestShort()

short aidaRequestShort ( JNIEnv *  env,
const char *  uri,
Arguments  arguments 
)

Get a short.

Parameters
urithe uri
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
argumentsthe arguments
Returns
the short

Definition at line 72 of file AIDASLCUTIL_SERVER.c.

72 {
73 if (startsWith(uri, "FBCK")) {
74 return getShortFaStatus(env, uri);
75 } else {
76 return getTrigStatus(env, uri, arguments);
77 }
78}

References aidaThrow(), startsWith(), TO_SLC_NAME, and UNABLE_TO_GET_DATA_EXCEPTION.

◆ aidaRequestString()

char * aidaRequestString ( JNIEnv *  env,
const char *  uri,
Arguments  arguments 
)

Get a string.

Allocate memory for string and it will be freed for you by framework

Parameters
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
urithe uri
argumentsthe arguments
Returns
the string

Definition at line 128 of file AIDASLCUTIL_SERVER.c.

128 {
129 if (startsWith(uri, "FBCK")) {
130 return GetStringFaStatus(env, uri);
131 } else {
132 // Read the status
133 short trig_status = getTrigStatus(env, uri, arguments);
135
136 if (trig_status) {
137 return ALLOCATE_STRING(env, "activated", "string");
138 } else {
139 return ALLOCATE_STRING(env, "deactivated", "string");
140 }
141 }
142}
#define ON_EXCEPTION_RETURN_(_r)
Check to see if an exception has been raised, and return the given return value.
#define ALLOCATE_STRING(_env, _string, _purpose)
Allocate memory for a string and copy the given string into this allocated space.

References aidaThrow(), ALLOCATE_STRING, ON_EXCEPTION_RETURN_, startsWith(), TO_SLC_NAME, and UNABLE_TO_GET_DATA_EXCEPTION.

◆ aidaRequestTable()

Table aidaRequestTable ( JNIEnv *  env,
const char *  uri,
Arguments  arguments 
)

Implement Correlated Plots.

Get a table of data.

Parameters
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
urithe uri
argumentsthe arguments
Returns
the table

The FILE contains the name of the button file and is used The PRIMSTV contains a structure with configuration for the primary step variable The SECNSTV optionally contains a structure with configuration for the secondary step variable

First the button file is loaded and then it is executed. A table with the following fields is returned: primary FLOAT_ARRAY value of primary step variable for this data set secondary FLOAT_ARRAY value of secondary step variable for this data set. Omitted if no secondary step variable specified samp{n} FLOAT_ARRAY For each sample variable found in the given FILE a column is returned. {n} is the sample var number

The labels for each column are set to the device name

Definition at line 164 of file AIDASLCUTIL_SERVER.c.

164 {
165 REF_DECLARE;
166 DESCR_DECLARE;
167
169
170 // Blank table
171 Table table;
172 table.columnCount = 0;
173
174 // Get button file name
175 char* buttonFileName;
176 char* primaryStepVariable, * secondaryStepVariable, * magnetFunction;
177 float primaryLow, primaryHigh, primarySettleTime, primaryExtraSettleTime, secondaryLow, secondaryHigh, secondarySettleTime, secondaryExtraSettleTime, settle;
178 int primarySteps, secondarySteps;
179 long nrpos = NRPOS_DEFAULT, dtizavg;
180 short bpmd = BPMD_ROGUE;
181
182 bool secondaryStepVariableProvided = getAcqParameters(env, arguments, &buttonFileName, &primaryStepVariable,
183 &primaryLow, &primaryHigh, &primarySteps,
184 &primaryExtraSettleTime, &primarySettleTime, &secondaryStepVariable, &secondaryLow, &secondaryHigh,
185 &secondarySteps,
186 &secondarySettleTime, &secondaryExtraSettleTime, &bpmd, &nrpos, &dtizavg, &magnetFunction);
188 TRACK_MEMORY(buttonFileName)
189 TRACK_MEMORY(primaryStepVariable)
190 TRACK_MEMORY(secondaryStepVariable)
191
192 vmsstat_t status;
193
194 // Initialize correlation plot context
195 status = CRR_RESET_ALL();
196 if (!SUCCESS(status)) {
198 "error resetting correlation plots: %s", buttonFileName, table)
199 }
200
201 // Local constant for fortran parameter
202 float wire_size = 0.0f;
203 float inc = (primaryHigh - primaryLow) / (float)(primarySteps - 1);
204
205 // Set up primary step variable
206 status = CRR_SET_VAR_NAME_FREEFORM(REFINT4_1(DEFINE_STEP), REFINT4_2(1), DESCRN1(primaryStepVariable),
207 REFINT4_3(0));
208 if (!SUCCESS(status)) {
210 "error setting primary step variable name: %s", primaryStepVariable, table)
211 }
212 status = CRR_SET_STEP(REFINT4_1(1), &primaryLow, &inc, &primarySteps, &primarySettleTime);
213 if (!SUCCESS(status)) {
215 "error setting primary step variable: %s", primaryStepVariable, table)
216 }
217
218 // Set secondary step variable
219 if (secondaryStepVariableProvided) {
220 status = CRR_SET_VAR_NAME_FREEFORM(REFINT4_1(DEFINE_STEP), REFINT4_2(-1), DESCRN1(secondaryStepVariable),
221 REFINT4_3(0));
222 if (!SUCCESS(status)) {
224 "error setting secondary step variable name: %s", secondaryStepVariable, table)
225 }
226
227 inc = (secondaryHigh - secondaryLow) / (float)(secondarySteps - 1);
228 status = CRR_SET_STEP(REFINT4_1(-1), &secondaryLow, &inc, &secondarySteps, &secondarySettleTime);
229 if (!SUCCESS(status)) {
231 "error setting secondary step variable: %s", secondaryStepVariable, table)
232 }
233 }
234
235 // Make absolute file name
236 char fullyQualifiedButtonFileName[strlen(buttonFileName) + strlen(SLC_BUTTON_DIR) + 1];
237 sprintf(fullyQualifiedButtonFileName, "%s%s", SLC_BUTTON_DIR, buttonFileName);
238
239 // Load button file
240 status = CRR_RESTORE_BUTTON_FILE(DESCRN1(fullyQualifiedButtonFileName));
241 if (!SUCCESS(status)) {
243 "error loading scan parameters from button file: %s", fullyQualifiedButtonFileName, table)
244 }
245
246 // Set BPM Measurement Definition if it has been specified
247 if (bpmd != BPMD_ROGUE) {
248 status = BPMD_SELECT_UTIL(&bpmd, NULL, NULL, NULL, NULL, NULL);
249 if (!SUCCESS(status)) {
250 fprintf(stderr, "Failed to set Measurement Definition: %hd", bpmd);
252 "error initializing correlation plot acquisition: %s", buttonFileName, table)
253 }
254 }
255
256 long magfunc;
257 memcpy(&magfunc, magnetFunction, 4);
258 float settleExtra[2];
259 settleExtra[0] = primaryExtraSettleTime;
260 settleExtra[1] = secondaryExtraSettleTime;
261
262 status = CRR_SET_SAMP_PARMS(&nrpos, &dtizavg, NULL, &magfunc, NULL, NULL, NULL, &settleExtra[0]);
263 if (!SUCCESS(status)) {
264 fprintf(stderr,
265 "Failed to set sample params. nrpos: %ld, dtizavg: %ld, magfunc: %ld, primSettleExtra: %f, secnSettleExtra: %f",
266 nrpos, dtizavg, magfunc, settleExtra[0], settleExtra[1]);
268 "error initializing correlation plot acquisition: %s", buttonFileName, table)
269 }
270
271 status = CRR_DATA_ACQ_INIT();
272 if (!SUCCESS(status)) {
274 "error initializing correlation plot acquisition: %s", buttonFileName, table)
275 }
276
277 // Run Correlation plot
278 status = CRR_DATA_ACQ(DESCRN1("*"));
279 if (!SUCCESS(status)) {
280 CRR_DATA_ACQ_DONE();
282 "executing correlation plot: %s", buttonFileName, table)
283 }
284 printf("Scan Complete");
285
286 // Number of Samples
287 long nSampleVariables;
288 if (countSampleVariables(env, &nSampleVariables)) {
289 CRR_DATA_ACQ_DONE();
290 return table;
291 }
292
293 // Get step count.
294 int nSteps = CRR_SAMPLES();
295 if (!SUCCESS(status)) {
296 CRR_DATA_ACQ_DONE();
298 "error getting number of steps: %s", buttonFileName, table)
299 }
300
301 // Get total number of samples
302 long totalSampleVariables = nSampleVariables + ((secondaryStepVariableProvided) ? 2 : 1);
303 if (!totalSampleVariables || !nSampleVariables) {
304 CRR_DATA_ACQ_DONE();
305 fprintf(stderr, "Invalid number of sample variables. totalSampleVariables: %ld, nSampleVariables: %ld",
306 totalSampleVariables, nSampleVariables);
308 "No sample variables have been specified in the given file: %s", buttonFileName, table)
309 }
310
311 // Query results variables
312 if (!nSteps) {
313 CRR_DATA_ACQ_DONE();
315 "Total number of steps derived from specified step variables is: %s", "0", table)
316 }
317
318 // Space for samples. Organised as sets of values for all sample variables
319 float* samples;
320 long* samplesOk;
321
322 printf("Tabulating Scan Results: %d x %ld\n", nSteps, totalSampleVariables);
323 ALLOCATE_AND_TRACK_MEMORY_AND_ON_ERROR_RETURN_(env, samples, nSteps * totalSampleVariables * sizeof(float) * 2,
324 "store acquired data", table)
325 ALLOCATE_AND_TRACK_MEMORY_AND_ON_ERROR_RETURN_(env, samplesOk, nSteps * totalSampleVariables * sizeof(long),
326 "store acquired data ok", table)
327
328 // Clean up correlation plot context
329 status = CRR_DATA_ACQ_DONE();
330 if (!SUCCESS(status)) {
332 "cleaning up after correlation plot: %s", buttonFileName, table)
333 }
334
335 // Allocate a dynamic table of with as many columns as samples and step variables
336 table = tableCreateDynamic(env, nSteps, (int)totalSampleVariables * 3);
338
339 // Create the correlation plot table
340 createCorrelationPlotTable(env, &table, ((int)totalSampleVariables), nSteps,
341 primaryStepVariable,
342 secondaryStepVariableProvided, secondaryStepVariable,
343 samples, samplesOk);
344
345 // Free all allocated memory
347
348 return table;
349}
#define SPRINTF_ERROR_STATUS_FREE_MEMORY_AND_RETURN_(_status, _exception, _errorText, _ref, _r)
Format an error message, throw it in an exception, free any allocated memory and return the error cod...
#define SPRINTF_ERROR_FREE_MEMORY_AND_RETURN_(_exception, _errorText, _ref, _r)
Format an error message, throw it in an exception, free any allocated memory and return the error cod...
#define ON_EXCEPTION_FREE_MEMORY_AND_RETURN_(_r)
Check to see if an exception has been raised, then free tracked memory, and return the given return v...
#define UNABLE_TO_GET_DATA_EXCEPTION
Use this string to signal Exceptions when trying to Get Data in aidaThrow()
#define TRACK_ALLOCATED_MEMORY
Create tracking variables so that memory can be freed with FREE_MEMORY macro.
#define FREE_MEMORY
Free any allocated memory.
#define ALLOCATE_AND_TRACK_MEMORY_AND_ON_ERROR_RETURN_(_env, _var, _size, _purpose, _r)
Allocate memory and add it to the tracked memory list so that it can be freed automatically later.
#define TRACK_MEMORY(_ptr)
Register this newly allocated memory so that it will be freed by FREE_MEMORY.
Table tableCreateDynamic(JNIEnv *env, int rows, int columns)
Make a Dynamic Table for return to client.
Table structure.
int columnCount
number of columns in table

References AIDA_FLOAT_TYPE, AIDA_INTEGER_TYPE, aidaThrowNonOsException(), ALLOCATE_AND_TRACK_MEMORY_AND_ON_ERROR_RETURN_, ascanf(), Table::columnCount, FREE_MEMORY, ON_EXCEPTION_FREE_MEMORY_AND_RETURN_, ON_EXCEPTION_RETURN_, RETURN_NULL_TABLE, SPRINTF_ERROR_FREE_MEMORY_AND_RETURN_, SPRINTF_ERROR_STATUS_FREE_MEMORY_AND_RETURN_, tableAddColumn(), tableAddFixedWidthStringColumn(), tableCreate(), tableCreateDynamic(), TRACK_ALLOCATED_MEMORY, TRACK_MEMORY, and UNABLE_TO_GET_DATA_EXCEPTION.

◆ aidaServiceInit()

Initialise the service.

Initialise the aida service.

Parameters
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
Exceptions
ServerInitialisationExceptionif the service fails to initialise

Definition at line 55 of file AIDASLCUTIL_SERVER.c.

55 {
56 vmsstat_t status;
57 if (!$VMS_STATUS_SUCCESS(status = init("AIDA_SLCUTIL", false))) {
58 aidaThrow(env, status, SERVER_INITIALISATION_EXCEPTION, "initialising Utility Service");
59 } else {
60 printf("AIDA-PVA Utility Provider\n");
61 }
62}
#define SERVER_INITIALISATION_EXCEPTION
Use this string to signal Server Initialisation Exceptions in aidaThrow()
void aidaThrow(JNIEnv *env, vmsstat_t status, char *exception, const char *message)
To log any exceptions and throw back to java.
vmsstat_t init(const char *processName, bool initMessageServices)
Call standalone_init()

References aidaThrow(), init(), and SERVER_INITIALISATION_EXCEPTION.

◆ aidaSetValue()

void aidaSetValue ( JNIEnv *  env,
const char *  uri,
Arguments  arguments,
Value  value 
)

Set a value: BGRP Set Variable or SCP transverse feedback.

Set a value.

Parameters
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
urithe uri
argumentsthe arguments
valueto set

Definition at line 600 of file AIDASLCUTIL_SERVER.c.

600 {
601 if (startsWith(uri, "FBCK")) {
602 setFeedback(env, uri, arguments, value);
603 } else {
604 setBGrp(env, arguments, value);
605 }
606}

References aidaThrow(), aidaThrowNonOsException(), ascanf(), avscanf(), CONVERT_TO_VMS_FLOAT, FREE_MEMORY, startsWith(), TO_SLC_NAME, TRACK_ALLOCATED_MEMORY, TRACK_MEMORY, UNABLE_TO_GET_DATA_EXCEPTION, and UNABLE_TO_SET_DATA_EXCEPTION.

◆ aidaSetValueWithResponse()

Table aidaSetValueWithResponse ( JNIEnv *  env,
const char *  uri,
Arguments  arguments,
Value  value 
)

Set a value and return a table as a response.

Parameters
envto be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
urithe uri
argumentsthe arguments
valueto set
Returns
a table

Definition at line 617 of file AIDASLCUTIL_SERVER.c.

617 {
618 if (strcasecmp(uri, "MKB:VAL") == 0) {
619 // set Multi Knob value
620 return setMkbValue(env, uri, arguments, value);
621 } else {
622 // set TRIGGER value
623 return setTriggerValue(env, uri, arguments, value);
624 }
625}

References aidaThrowNonOsException(), endsWith(), PMU_STRING_FROM_URI, RETURN_NULL_TABLE, UNABLE_TO_SET_DATA_EXCEPTION, and UNSUPPORTED_CHANNEL_EXCEPTION.