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
AIDASLCBPMBUFF_SERVER.c File Reference

Buffered BPM Acquisition Native Provider implementation. More...

#include "aida_pva.h"
#include "AIDASLCBPMBUFF_SERVER.h"

Go to the source code of this file.

Functions

Table aidaRequestTable (JNIEnv *env, const char *uri, Arguments arguments)
 Get a table of data Parameters: BPMD: Integer Bpm Measurement Definition number NRPOS: number of pulses. More...
 
REQUEST_STUB_BOOLEAN REQUEST_STUB_BYTE REQUEST_STUB_SHORT REQUEST_STUB_INTEGER REQUEST_STUB_LONG REQUEST_STUB_FLOAT REQUEST_STUB_DOUBLE REQUEST_STUB_STRING 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 SET_STUB_VOID SET_STUB_TABLE void aidaServiceInit (JNIEnv *env)
 Initialise the service. More...
 

Detailed Description

Buffered BPM Acquisition Native Provider implementation.

MEMBER=SLCLIBS:AIDA_PVALIB ATTRIBUTES=JNI,LIBR_NOGLOBAL

Definition in file AIDASLCBPMBUFF_SERVER.c.

Function Documentation

◆ aidaRequestTable()

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

Get a table of data Parameters: BPMD: Integer Bpm Measurement Definition number NRPOS: number of pulses.

Get a table of data.

Default is 1 BPMS: json. List of BPMs to read ["BPMS:LI02:501", "BPMS:DR12:334"] DEVS: json. List of devices to read Note: cannot specify both BPMS and DEVS

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

Definition at line 75 of file AIDASLCBPMBUFF_SERVER.c.

76{
78
79 // Get arguments
80 int bpmd = BPMD_ROGUE, nrpos = NRPOS_DEFAULT, nDevices = 0, timeout = 3;
81 unsigned int nBpms = 0, nDevs = 0;
82 char** bpms = NULL, ** devices = NULL;
83 DEVICE_NAME_TS deviceNames[MAX_DGRP_BPMS];
84 TO_DGROUP(dGroupName, uri)
85
86 if (ascanf(env, &arguments, "%d %od %osa %osa %od",
87 "bpmd", &bpmd,
88 "nrpos", &nrpos,
89 "bpms", &bpms, &nBpms,
90 "devs", &devices, &nDevs,
91 "timeout", &timeout
92 )) {
94 }
95 TRACK_MEMORY(bpms)
96 TRACK_MEMORY(devices)
97
98 if (nBpms && nDevs) {
99 // Only one or the other not both
100 aidaThrowNonOsException(env, UNABLE_TO_GET_DATA_EXCEPTION, "Specify either DEVS or BPMS argument but not both");
103 } else if (nBpms) {
104 for (int i = 0; i < nBpms; i++) {
105 if (pmuFromDeviceName(env, bpms[i],
106 deviceNames[i].prim_s._a,
107 deviceNames[i].micr_s._a,
108 &deviceNames[i].unit_s._i)) {
111 }
112 }
113 nDevices += nBpms;
114 bpms = NULL;
115 } else if (nDevs) {
116 for (int i = 0; i < nDevs; i++) {
117 if (pmuFromDeviceName(env, devices[i],
118 deviceNames[i].prim_s._a,
119 deviceNames[i].micr_s._a,
120 &deviceNames[i].unit_s._i)) {
123 }
124 }
125 nDevices += nDevs;
126 devices = NULL;
127 }
129
130 // Check arguments
131 if (checkArguments(env, bpmd, nrpos, nDevices)) {
133 }
134
135 // Acquire Data
136 int rows;
137 if (acquireBuffAcqData(env, &rows, nDevices, &deviceNames[0], dGroupName, bpmd, nrpos, timeout)) {
139 }
140
141 // No rows
142 if (!rows) {
143 aidaThrowNonOsException(env, UNABLE_TO_GET_DATA_EXCEPTION, "No rows were retrieved for your query");
145 }
146
147 if (rows > MAX_DGRP_BPMS * MAX_BUFF_MEAS) {
148 aidaThrowNonOsException(env, UNABLE_TO_GET_DATA_EXCEPTION, "Too many rows returned by this query");
150 }
151
152 // To hold data
153 char* namesData[rows + 1];
154 float xData[rows + 1], yData[rows + 1], tmitData[rows + 1];
155 unsigned long pulseIdData[rows + 1];
156 int2u statsData[rows + 1], goodMeasData[rows + 1];
157
158 // Get Buffered Data
159 if (getBuffAcqData(env, namesData, xData, yData, tmitData, pulseIdData, statsData, goodMeasData)) {
161 }
162
163 // Make and output table
164 Table table = tableCreate(env, rows, 7);
166 tableAddStringColumn(env, &table, namesData);
168 tableAddColumn(env, &table, AIDA_INTEGER_TYPE, pulseIdData, false);
170 tableAddColumn(env, &table, AIDA_FLOAT_TYPE, xData, false);
172 tableAddColumn(env, &table, AIDA_FLOAT_TYPE, yData, false);
174 tableAddColumn(env, &table, AIDA_FLOAT_TYPE, tmitData, false);
176 tableAddColumn(env, &table, AIDA_SHORT_TYPE, statsData, false);
178 tableAddColumn(env, &table, AIDA_SHORT_TYPE, goodMeasData, false);
179
180 endAcquireBuffAcq(env);
181
182 // All read successfully
183 return table;
184}
#define RETURN_NULL_TABLE
Return an empty table response.
Definition: aida_pva_api.h:380
#define ON_EXCEPTION_RETURN_(_r)
Check to see if an exception has been raised, and return the given return value.
#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 TRACK_MEMORY(_ptr)
Register this newly allocated memory so that it will be freed by FREE_MEMORY.
void aidaThrowNonOsException(JNIEnv *env, char *exception, const char *message)
To log any non-OS exceptions and throw back to java.
int pmuFromDeviceName(JNIEnv *env, char *device, char *primary, char *micro, int4u *unit)
Get primary, micro and unit from a device name.
@ AIDA_FLOAT_TYPE
Represents a float.
@ AIDA_INTEGER_TYPE
Represents an integer.
@ AIDA_SHORT_TYPE
Represents a short.
void tableAddStringColumn(JNIEnv *env, Table *table, char **data)
Add a String column to the given Table.
int ascanf(JNIEnv *env, Arguments *arguments, const char *formatString,...)
ascanf(), avscanf()
Table tableCreate(JNIEnv *env, int rows, int columns)
Make a Table for return to client.
void tableAddColumn(JNIEnv *env, Table *table, Type type, void *data, bool ieeeFormat)
Add a column of arbitrary type to a Table.
#define TO_DGROUP(_var, _uri)
Get a display group name from the provided uri and store it in the given variable name.
Definition: aida_pva_uri.h:69
Table structure.

References AIDA_FLOAT_TYPE, AIDA_INTEGER_TYPE, AIDA_SHORT_TYPE, aidaThrowNonOsException(), ascanf(), FREE_MEMORY, ON_EXCEPTION_RETURN_, pmuFromDeviceName(), RETURN_NULL_TABLE, tableAddColumn(), tableAddStringColumn(), tableCreate(), TO_DGROUP, 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 46 of file AIDASLCBPMBUFF_SERVER.c.

47{
48 vmsstat_t status;
49
50 if (!$VMS_STATUS_SUCCESS(status = init("AIDA_SLCBPMBUFF", true))) {
51 aidaThrow(env, status, SERVER_INITIALISATION_EXCEPTION, "while initializing Buffered BPM service");
52 return;
53 }
54
55 DPSLCBUFF_SETMODE();
56
57 printf("AIDA-PVA Buffered BPM Acquisition Provider\n");
58}
#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.