9#include "AIDASLCMAGNET_SERVER.h"
11static int getBaseMagnetArguments(JNIEnv* env,
const char* uri,
Arguments arguments,
Value value,
12 int* count,
char** prim_list,
13 char** micr_list,
int** unit_list, int4u* secn,
float** set_values,
char** name_validity);
14static int getMagnetArguments(JNIEnv* env,
const char* uri,
Arguments arguments,
Value value,
15 int* count,
char** prim_list,
16 char** micr_list,
int** unit_list, int4u* secn,
float** set_values,
char** magFunc,
char** limitCheck,
17 char** name_validity);
18static bool isAllValid(
int count,
const char* name_validity);
19static void getInvalidNames(
char* dst,
int count,
char* names[],
const char* name_validity);
48 if (!$VMS_STATUS_SUCCESS(status =
init(
"AIDA_SLCMAGNET",
false))) {
51 printf(
"AIDA-PVA Magnet Provider\n");
68 char* micrPattern = NULL, * unitPattern = NULL;
69 if (
ascanf(env, &arguments,
"%os %os",
70 "micros", &micrPattern,
81 vmsstat_t status = DPSLCMAGNET_GET((
char*)legacyName, (micrPattern ? micrPattern :
"ALL*"),
82 (unitPattern ? unitPattern :
"ALL*"),
85 if (!SUCCESS(status)) {
87 DPSLCMAGNET_GETCLEANUP();
92 char namesData[(numMagnetPvs * MAX_PMU_STRING_LEN) + 1];
93 float secondaryValues[numMagnetPvs];
96 DPSLCMAGNET_GETNAMES(namesData);
99 DPSLCMAGNET_GETSECNVALUES(secondaryValues);
102 DPSLCMAGNET_GETCLEANUP();
134 if (!DPSLCMAGNET_ACCESSENABLED()) {
136 "Aida magnet set operations are not currently enabled");
144 char* primaryList = NULL, * microList = NULL, * name_validity = NULL;
145 int* unitList = NULL;
148 float* setValues = NULL;
150 if (getBaseMagnetArguments(env, uri,
151 arguments, value, &count, &primaryList, µList, &unitList, &secn, &setValues, &name_validity)) {
165 status = DPSLCMAGNET_SETCONFIG(count, primaryList, microList, unitList, secn, setValues);
169 DPSLCMAGNET_SETCLEANUP();
170 if (!SUCCESS(status)) {
212 if (!DPSLCMAGNET_ACCESSENABLED()) {
214 "Aida magnet set operations are not currently enabled");
221 char* primaryList, * microList, * magnetFunction, * limitCheck, * name_validity;
224 int limitCheckAll =
true;
225 if (getMagnetArguments(env, uri, arguments, value, &count,
226 &primaryList, µList, &unitList, &secn, &setValues,
227 &magnetFunction, &limitCheck,
239 if (strcasecmp(magnetFunction,
"TRIM") != 0 && strcasecmp(magnetFunction,
"PTRB") != 0
240 && strcasecmp(magnetFunction,
"NOFUNC") != 0) {
246 if (limitCheck && strcasecmp(limitCheck,
"ALL") != 0 && strcasecmp(limitCheck,
"SOME") != 0) {
253 limitCheckAll =
false;
257 bool withinLimits[count], allSetValuesWithinLimits =
true;
258 int numPairsWithinLimits = 0;
259 float magnetLimits[count * 2];
260 DPSLCMAGNET_RET_MAGLIMITS(count, &magnetLimits[0]);
262 for (
int i = 0; i < count; i++) {
263 float lowerLimit = magnetLimits[i * 2];
264 float upperLimit = magnetLimits[i * 2 + 1];
265 if ((setValues[i] < lowerLimit) || (setValues[i] > upperLimit)) {
266 withinLimits[i] =
false;
267 allSetValuesWithinLimits =
false;
269 withinLimits[i] =
true;
270 numPairsWithinLimits++;
273 if (!allSetValuesWithinLimits && limitCheckAll || !numPairsWithinLimits) {
275 "Some or all of the set values are outside of the limits");
281 char limitedPrimList[(numPairsWithinLimits *
PRIM_LEN) + 1];
282 char limitedMicrList[(numPairsWithinLimits *
MICRO_LEN) + 1];
283 int limitedUnitList[numPairsWithinLimits];
284 float limitedValuesList[numPairsWithinLimits];
286 int limitedCounter = 0;
287 for (
int i = 0; i < count; i++) {
288 if (withinLimits[i]) {
291 limitedUnitList[limitedCounter] = unitList[i];
292 limitedValuesList[limitedCounter] = setValues[i];
296 limitedPrimList[(numPairsWithinLimits *
PRIM_LEN)] = 0x0;
297 limitedMicrList[(numPairsWithinLimits *
PRIM_LEN)] = 0x0;
304 status = DPSLCMAGNET_SET(numPairsWithinLimits, limitedPrimList, limitedMicrList, limitedUnitList, secn,
305 limitedValuesList, magnetFunction);
307 if (!SUCCESS(status)) {
313 int rows = DPSLCMAGNET_RET_SETNUMPVS();
314 char namesData[(rows * MAX_STATE_NAME_LEN) + 1];
315 float bactData[rows];
318 DPSLCMAGNET_RET_STATENAMES(namesData);
319 DPSLCMAGNET_RET_BACTVALUES(bactData);
322 DPSLCMAGNET_SETCLEANUP();
348getBaseMagnetArguments(JNIEnv* env,
const char* uri,
Arguments arguments,
Value value,
int* count,
char** prim_list,
349 char** micr_list,
int** unit_list, int4u* secn,
float** set_values,
char** name_validity)
356 *name_validity = NULL;
358 unsigned int nNames, nValues;
363 if (
avscanf(env, &arguments, &value,
"%sa %fa",
364 "value.names", &names, &nNames,
365 "value.values", set_values, &nValues
373 *count = (int)nNames;
374 if (nNames != nValues) {
384 unsigned long longUnitList[*count];
385 for (
int i = 0; i < nNames; i++) {
392 ((
int*)*unit_list)[i] = (int)longUnitList[i];
400 DPSLCMAGNET_SETNAMESVALIDATE(*count, *prim_list, *micr_list, *unit_list, *secn, *name_validity);
403 if (!isAllValid(*count, *name_validity)) {
405 getInvalidNames(invalidNames, *count, names, *name_validity);
435getMagnetArguments(JNIEnv* env,
const char* uri,
Arguments arguments,
Value value,
int* count,
char** prim_list,
436 char** micr_list,
int** unit_list, int4u* secn,
float** set_values,
char** magFunc,
char** limitCheck,
437 char** name_validity)
443 if (getBaseMagnetArguments(env, uri, arguments, value, count, prim_list, micr_list, unit_list, secn, set_values,
453 if (
ascanf(env, &arguments,
"%s %os",
455 "limitcheck", limitCheck
471bool isAllValid(
int count,
const char* name_validity)
473 if (!name_validity) {
477 for (
int i = 0; i < count; i++) {
478 if (strncasecmp(name_validity + (i * MAX_VALIDITY_STRING_LEN),
"Success",
sizeof(
"Success") - 1) != 0) {
493static void getInvalidNames(
char* dst,
int count,
char* names[],
const char* name_validity)
495 if (!name_validity || !names) {
500 for (
int i = 0; i < count; i++) {
501 if (strncasecmp(name_validity + (i * MAX_VALIDITY_STRING_LEN),
"Success",
sizeof(
"Success") - 1) != 0) {
502 strcat(dst, names[i]);
503 if (i != count - 1) {
Table aidaSetValueWithResponse(JNIEnv *env, const char *uri, Arguments arguments, Value value)
Sets specified BDES or VDES secondary values for specified array of magnet names to an array of corre...
void aidaSetValue(JNIEnv *env, const char *uri, Arguments arguments, Value value)
Sets specified BCON secondary values for specified array of magnet names to an array of corresponding...
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 void aidaServiceInit(JNIEnv *env)
Initialise the service.
Table aidaRequestTable(JNIEnv *env, const char *uri, Arguments arguments)
Get a table of data.
The Header File for the AIDA-PVA Module functions.
#define REQUEST_STUB_BYTE
aidaRequestByte API Stub
#define VERSION(_version)
Use this macro to define the version of the provider.
#define REQUEST_STUB_INTEGER
aidaRequestInteger API Stub
#define REQUEST_STUB_LONG_ARRAY
aidaRequestLongArray API Stub
#define REQUEST_STUB_SHORT
aidaRequestShort API Stub
#define REQUEST_STUB_INTEGER_ARRAY
aidaRequestIntegerArray API Stub
#define REQUEST_STUB_LONG
aidaRequestLong API Stub
#define REQUEST_STUB_STRING
aidaRequestString API Stub
#define REQUEST_STUB_DOUBLE
aidaRequestDouble API Stub
#define REQUEST_STUB_SHORT_ARRAY
aidaRequestShortArray API Stub
#define REQUEST_STUB_BYTE_ARRAY
aidaRequestByteArray API Stub
#define RETURN_NULL_TABLE
Return an empty table response.
#define REQUEST_STUB_BOOLEAN
aidaRequestBoolean API Stub
#define REQUEST_STUB_FLOAT_ARRAY
aidaRequestFloatArray API Stub
#define REQUEST_STUB_DOUBLE_ARRAY
aidaRequestDoubleArray API Stub
#define REQUEST_STUB_BOOLEAN_ARRAY
aidaRequestBooleanArray API Stub
#define REQUEST_STUB_FLOAT
aidaRequestFloat API Stub
#define REQUEST_STUB_STRING_ARRAY
aidaRequestStringArray API stub
#define CONVERT_FROM_VMS_FLOAT(_float, _count)
Convert in-place, floating point numbers from VMS to ieee format.
#define CONVERT_TO_VMS_FLOAT(_float, _count)
Convert in-place, floating point numbers from ieee to VMS format.
#define SERVER_INITIALISATION_EXCEPTION
Use this string to signal Server Initialisation Exceptions in aidaThrow()
#define UNABLE_TO_SET_DATA_EXCEPTION
Use this string to signal Exceptions when trying to Set Data in aidaThrow()
#define ON_EXCEPTION_RETURN_(_r)
Check to see if an exception has been raised, and return the given return value.
#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 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 FREE_TRACKED_MEMORY(_ptr)
Free a single tracked memory allocation and remove from list.
#define TRACK_MEMORY(_ptr)
Register this newly allocated memory so that it will be freed by FREE_MEMORY.
void secnFromUri(const char *uri, int4u *secn)
Get secondary from pseudo secondary (containing a colon) number from URI e.g.
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()
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.
void tableAddFixedWidthStringColumn(JNIEnv *env, Table *table, char *data, int width)
This reads data from an allocated space that is rows * width with each string occupying width charact...
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.
int avscanf(JNIEnv *env, Arguments *arguments, Value *value, const char *formatString,...)
ascanf(), avscanf()
#define TO_LEGACY_NAME(_uri, _var)
Get a legacy AIDA name from the provided uri and store it in the given variable name.
#define PRIM_LEN
The length of the primary part of a PMU string.
#define MAX_URI_LEN
The maximum length of a URI.
#define MICRO_LEN
The length of the micro part of a PMU string.
An Arguments structure stores all of the arguments passed from the request to the Native Channel Prov...
This special type represents a Value.