]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
*** empty log message ***
authorhades <hades>
Wed, 16 Aug 2000 12:00:03 +0000 (12:00 +0000)
committerhades <hades>
Wed, 16 Aug 2000 12:00:03 +0000 (12:00 +0000)
allParam/ca/caParam.c [new file with mode: 0644]
allParam/ca/caParam.h [new file with mode: 0644]
allParam/tcl/tclParam.c [new file with mode: 0644]
allParam/tcl/tclParam.h [new file with mode: 0644]

diff --git a/allParam/ca/caParam.c b/allParam/ca/caParam.c
new file mode 100644 (file)
index 0000000..65b70d4
--- /dev/null
@@ -0,0 +1,155 @@
+#define _POSIX_C_SOURCE 199509L
+
+#include <unistd.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <hadesstd.h>
+
+#include "param.h"
+
+int conParam(Param *my)
+{
+       return 0;
+}
+
+void desParam(Param *my)
+{
+}
+
+int Param_getInt(const Param *my, const char *n, const char *i, int *v)
+{
+       return Param_getIntArray(my, n, i, 1, v);
+}
+
+int Param_getString(const Param *my, const char *n, const char *i, char *v)
+{
+       int i;
+       int status;
+       chid chan;
+       char *pPVName;
+
+       if((status = ca_task_initialize()) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Cannot initialize channel access.\n");
+               exit (-1);
+       }
+
+       pPVName = Param_returnPVName(name, idx, -1);
+       chan = Param_openChannel(pPVName);
+       if((status = ca_bget(chan, val)) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Do not receive value of %s.\n", pPVName);
+               exit (-1);
+       }
+       Param_closeChannel(chan, pPVName);
+
+       if((status = ca_task_exit()) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Cannot exit channel access.\n");
+               exit (-1);
+       }
+       
+       return num;
+}
+
+int Param_getIntArray(const Param *my, const char *name, const char *idx, int num, int *val)
+{
+       int i;
+       int status;
+       chid chan;
+       char *pPVName;
+
+       if((status = ca_task_initialize()) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Cannot initialize channel access.\n");
+               exit (-1);
+       }
+
+       pPVName = Param_returnPVName(name, idx, -1);
+       chan = Param_openChannel(pPVName);
+       if((status = ca_array_get(DBR_LONG, num, chan, val)) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Do not receive value of %s.\n", pPVName);
+               exit (-1);
+       }
+       Param_closeChannel(chan, pPVName);
+
+       if((status = ca_task_exit()) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Cannot exit channel access.\n");
+               exit (-1);
+       }
+       return num;
+}
+
+int Param_getStringArray(const Param *my, const char *name, const char *idx, int num, char **val)
+{
+       int i;
+       int status;
+       chid chan;
+       char *pPVName;
+
+       if((status = ca_task_initialize()) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Cannot initialize channel access.\n");
+               exit (-1);
+       }
+
+       for (i = 0 ; i < num ; i++) {
+               pPVName = Param_returnPVName(name, idx, i);
+               chan = Param_openChannel(pPVName);
+               if((status = ca_bget(chan, val)) != ECA_NORMAL) {
+                       msglog(LOG_ERR, "Do not receive value of %s.\n", pPVName);
+                       exit (-1);
+               }
+               Param_closeChannel(chan, pPVName);
+       }
+
+       if((status = ca_task_exit()) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Cannot exit channel access.\n");
+               exit (-1);
+       }
+       
+       return num;
+}
+
+char *Param_returnPVName(const char *name, const char *idx, int num)
+{
+       int i;
+       char *pPVName;
+
+       if (num == -1) {
+               pPVName = allocMem((strlen("HAD:PARAM:") + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char));
+               sprintf(pPVName ,"HAD:PARAM:%s:%s", name, idx);
+       } else {
+               pPVName = allocMem((strlen("HAD:PARAM:") + strlen(name) + 1 + strlen(idx) + 1 + 4 + 1) * sizeof(char));
+               sprintf(pPVName ,"HAD:PARAM:%s:%s:%d", name, idx, num);
+       }
+
+       for (i = 0 ; i < strlen(pPVName) ; i++) {
+               pPVName[i] = toupper(pPVName[i]);
+       }
+       return pPVName;
+}
+
+chid Param_openChannel(const char *pPVName)
+{
+       int status;
+       chid chan;
+       if((status = ca_search(pPVName, &chan)) != ECA_NORMAL) {
+               msglog(LOG_ERR, "Cannot open channel to %s: %s\n", pPVName, strerror(errno));
+               exit (-1);
+       }
+       if((status = ca_pend_io(TIMEOUT)) != ECA_NORMAL) {
+               msglog(LOG_WARNING, "Cannot switch to asyncronous mode: %s\n", strerror(errno));
+       }
+       return chan;
+}
+
+int Param_closeChannel(chid chan, char *pPVName)
+{
+       int status;
+       if((status = ca_pend_io(TIMEOUT)) != ECA_NORMAL) {
+               msglog(LOG_WARNING, "Cannot switch to asyncronous mode: %s\n", strerror(errno));
+       }
+       status = ca_clear_channel(chan);
+       freeMem(pPVName);
+       return status;
+}
+
diff --git a/allParam/ca/caParam.h b/allParam/ca/caParam.h
new file mode 100644 (file)
index 0000000..caeb86f
--- /dev/null
@@ -0,0 +1,71 @@
+#ifndef PARAM_H
+#define PARAM_H
+
+/**************************************************************************
+ * Section containing struct Param (different in the different param.h's) *
+ **************************************************************************/
+
+typedef struct ParamS {
+} Param;
+
+#define PARAM_MAX_NVALS 1024
+#define PARAM_MAX_NAME_LEN 128
+
+#define PREFIX HAD:PARAM:
+#define TIMEOUT 1.0
+
+#include <cadef.h>
+
+chid Param_openChannel(const char *);
+int Param_closeChannel(chid, char *);
+char *Param_returnPVName(const char *, const char *);
+
+/******************************************************************
+ * Section containing the API for param (common to all param.h's) *
+ ******************************************************************/
+
+int conParam(Param *);
+void desParam(Param *);
+
+/*
+ * All functions have a status as return value. If the return value is positive,
+ * it contains the number of array members returned (1 in case of
+ * Param_getString and Param_getInt, between 1 and num in case of
+ * Param_getStringArray and Param_getIntArray).
+ *
+ * Memory must be allocated for the result before the function is called.
+ * For example, calling Param_getInt needs
+ *
+ * > int status;
+ * > unsigned long int value;
+ * > if(status = Param_getInt(param, name, idx, value) != 1) {
+ * >     printf("No parameter 'value' found. Exiting.\n");
+ * >     exit(-1);
+ * > }
+ * 
+ * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the
+ * above example expands to
+ *
+ * > int status;
+ * > int num = 32;
+ * > char value[PARAM_MAX_VALUE_LEN][num];
+ * > if(status = Param_getStringArray(param, name, idx, num, value) != num) {
+ * >     printf("Not enough elements of 'value' found. Exiting.\n");
+ * >     exit(-1);
+ * > }
+ * 
+ */
+
+#define PARAM_RV_NO_SUCH_PARAMETER 0
+#define PARAM_RV_FAILED -1
+
+#define PARAM_MAX_VALUE_LEN 128
+
+int Param_getInt(const Param *, const char *, const char *, unsigned long int *);
+int Param_getString(const Param *, const char *, const char *, char *);
+
+int Param_getIntArray(const Param *, const char *, const char *, int, unsigned long int *);
+int Param_getStringArray(const Param *, const char *, const char *, int, char **);
+
+#endif
+
diff --git a/allParam/tcl/tclParam.c b/allParam/tcl/tclParam.c
new file mode 100644 (file)
index 0000000..e3ce3f0
--- /dev/null
@@ -0,0 +1,39 @@
+#define _POSIX_C_SOURCE 199509L
+
+#include "param.h"
+
+int conParam(Param *my)
+{
+       return 0;
+}
+
+void desParam(Param *my)
+{
+}
+
+int Param_getInt(const Param *my, const char *n, const char *i, int *v)
+{
+       return Param_getIntArray(my, n, i, 1, v);
+}
+
+int Param_getString(const Param *my, const char *n, const char *i, char *v)
+{
+       return Param_getStringArray(my, n, i, 1, &v);
+}
+
+int Param_getIntArray(const Param *my, const char *n, const char *i, int num, int *v)
+{
+       for (int i = 0 ; i<num ; i++) {
+               v[i] = 0;
+       }
+       return num;
+}
+
+int Param_getStringArray(const Param *my, const char *n, const char *i, int num, char **v)
+{
+       for (int i = 0 ; i<num ; i++) {
+               v[i] = "Blub";
+       }
+       return num;
+}
+
diff --git a/allParam/tcl/tclParam.h b/allParam/tcl/tclParam.h
new file mode 100644 (file)
index 0000000..ea8515c
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef PARAM_H
+#define PARAM_H
+
+/**************************************************************************
+ * Section containing struct Param (different in the different param.h's) *
+ **************************************************************************/
+
+typedef struct ParamS {
+} Param;
+
+/******************************************************************
+ * Section containing the API for param (common to all param.h's) *
+ ******************************************************************/
+
+int conParam(Param *);
+void desParam(Param *);
+
+/*
+ * All functions have a status as return value. If the return value is positive,
+ * it contains the number of array members returned (1 in case of
+ * Param_getString and Param_getInt, between 1 and num in case of
+ * Param_getStringArray and Param_getIntArray).
+ *
+ * Memory must be allocated for the result before the function is called.
+ * For example, calling Param_getInt needs
+ *
+ * > int status;
+ * > unsigned long int value;
+ * > if(status = Param_getInt(param, name, idx, value) != 1) {
+ * >     printf("No parameter 'value' found. Exiting.\n");
+ * >     exit(-1);
+ * > }
+ * 
+ * For strings char[PARAM_MAX_VALUE_LEN] has to be allocated. Therefore the
+ * above example expands to
+ *
+ * > int status;
+ * > int num = 32;
+ * > char value[PARAM_MAX_VALUE_LEN][num];
+ * > if(status = Param_getStringArray(param, name, idx, num, value) != num) {
+ * >     printf("Not enough elements of 'value' found. Exiting.\n");
+ * >     exit(-1);
+ * > }
+ * 
+ */
+
+#define PARAM_RV_NO_SUCH_PARAMETER 0
+#define PARAM_RV_FAILED -1
+
+#define PARAM_MAX_VALUE_LEN 128
+
+int Param_getInt(const Param *, const char *, const char *, unsigned long int *);
+int Param_getString(const Param *, const char *, const char *, char *);
+
+int Param_getIntArray(const Param *, const char *, const char *, int, unsigned long int *);
+int Param_getStringArray(const Param *, const char *, const char *, int, char **);
+
+#endif
+