305 lines
7.9 KiB
C
305 lines
7.9 KiB
C
/********************************************************************\
|
|
|
|
Name: bulk_monitor.c
|
|
Created by: RA36
|
|
|
|
Contents: DD definitions
|
|
Bulk muSR front-end creating mon files
|
|
\********************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include "midas.h"
|
|
|
|
/*#define MIDEBUG // */
|
|
|
|
/*---- globals -----------------------------------------------------*/
|
|
|
|
extern INT verbose;
|
|
|
|
INT n_mon_devices;
|
|
INT n_reg_devices;
|
|
|
|
/*------------------------------------------------------------------*/
|
|
|
|
/* Store any parameters the device driver needs in following
|
|
structure. */
|
|
|
|
/* REMEMBER also to modify slowcont/mon/mon_do.c ! */
|
|
typedef struct {
|
|
char device_list[4*NAME_LENGTH];
|
|
char active_list[4*NAME_LENGTH];
|
|
} BULK_MONITOR_SETTINGS;
|
|
|
|
#define BULK_MONITOR_SETTINGS_STR "\
|
|
Device_list = STRING : [128] NONE\n\
|
|
Active_list = STRING : [128] NONE\n\
|
|
"
|
|
|
|
/* following structure contains private variables to the device
|
|
driver. It is necessary to store it here in case the device
|
|
|
|
would be stored in a global variable, one device could over-
|
|
write the other device's variables. */
|
|
|
|
typedef struct {
|
|
BULK_MONITOR_SETTINGS bulk_monitor_settings;
|
|
INT channels;
|
|
} BULK_MONITOR_INFO;
|
|
|
|
/* device driver support routines ------------------------------------------------- */
|
|
|
|
/*---- device driver routines --------------------------------------*/
|
|
|
|
INT bulk_monitor_exit(BULK_MONITOR_INFO *);
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* the init function creates a ODB record which contains the
|
|
settings and initialized it variables as well as the bus driver */
|
|
|
|
INT bulk_monitor_init(HNDLE hkey, void **pinfo, INT channels, INT(*bd) (INT cmd, ...))
|
|
{
|
|
int status, size, len, i;
|
|
HNDLE hDB, hkeydd;
|
|
BULK_MONITOR_INFO *info;
|
|
|
|
#ifdef MIDEBUG
|
|
cm_msg(MLOG,"","++bulk_monitor_init()");
|
|
#endif
|
|
/* allocate info structure */
|
|
info = calloc(1, sizeof(BULK_MONITOR_INFO));
|
|
info->channels = channels;
|
|
*pinfo = info;
|
|
|
|
cm_get_experiment_database(&hDB, NULL);
|
|
|
|
/* create settings record */
|
|
status = db_create_record(hDB, hkey, "DD", BULK_MONITOR_SETTINGS_STR);
|
|
if (status != DB_SUCCESS) {
|
|
cm_msg(MERROR, "bulk_monitor_init", "Error creating DD Settings record in ODB.");
|
|
return FE_ERR_ODB;
|
|
}
|
|
|
|
status = db_find_key(hDB, hkey, "DD", &hkeydd);
|
|
if (status != DB_SUCCESS) {
|
|
cm_msg(MERROR, "bulk_monitor_init", "Error %d Finding DD key in ODB.",status);
|
|
return FE_ERR_ODB;
|
|
}
|
|
size = sizeof(info->bulk_monitor_settings);
|
|
status = db_get_record(hDB, hkeydd, &info->bulk_monitor_settings, &size, 0);
|
|
if (status != DB_SUCCESS) {
|
|
cm_msg(MERROR, "bulk_monitor_init", "Error %d getting record of DD key in ODB.",
|
|
status);
|
|
return FE_ERR_ODB;
|
|
}
|
|
|
|
/* initialize driver */
|
|
|
|
#ifdef MIDEBUG
|
|
cm_msg(MLOG,"","--bulk_monitor_init()");
|
|
#endif
|
|
return FE_SUCCESS;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
INT bulk_monitor_exit(BULK_MONITOR_INFO * info)
|
|
{
|
|
#ifdef MIDEBUG
|
|
cm_msg(MLOG,"","++bulk_monitor_exit()");
|
|
#endif
|
|
|
|
free(info);
|
|
|
|
#ifdef MIDEBUG
|
|
cm_msg(MLOG,"","--bulk_monitor_exit()");
|
|
#endif
|
|
return FE_SUCCESS;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
INT bulk_monitor_set(BULK_MONITOR_INFO * info, INT channel, float value)
|
|
{
|
|
INT status;
|
|
|
|
#ifdef MIDEBUG
|
|
cm_msg(MLOG,"","--bulk_monitor_set()");
|
|
#endif
|
|
return FE_SUCCESS;
|
|
}
|
|
/*----------------------------------------------------------------------------*/
|
|
INT bulk_monitor_get(BULK_MONITOR_INFO * info, INT channel, float *pvalue)
|
|
{
|
|
|
|
#ifdef MIDEBUG
|
|
cm_msg(MLOG,"","++bulk_monitor_get()");
|
|
#endif
|
|
if ((channel == 0) && pvalue)
|
|
*pvalue = n_mon_devices;
|
|
else if ((channel == 1) && pvalue)
|
|
*pvalue = n_reg_devices;
|
|
|
|
return FE_SUCCESS;
|
|
}
|
|
/*----------------------------------------------------------------------------*/
|
|
INT bulk_monitor_get_demand(BULK_MONITOR_INFO *info, INT channel, float *pvalue)
|
|
{
|
|
|
|
#ifdef MIDEBUG
|
|
cm_msg(MLOG,"","++bulk_monitor_get_demand()");
|
|
#endif
|
|
if (pvalue) *pvalue = 0.f;
|
|
return FE_SUCCESS;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
INT bulk_monitor_get_all(BULK_MONITOR_INFO * info, INT channels, float *pvalue)
|
|
{
|
|
if (channels > 0) {
|
|
int i;
|
|
|
|
for (i = 0; i < MIN(channels, info->channels); i++)
|
|
bulk_monitor_get(info, i, pvalue + i);
|
|
}
|
|
return FE_SUCCESS;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
INT bulk_monitor_get_default_threshold(BULK_MONITOR_INFO * info, INT channel,
|
|
float *pvalue) {
|
|
if (pvalue != NULL) {
|
|
switch (channel) {
|
|
default:
|
|
*pvalue = 0.5;
|
|
}
|
|
}
|
|
return FE_SUCCESS;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
INT bulk_monitor_get_name(BULK_MONITOR_INFO * info, INT channel, char *name)
|
|
{
|
|
if (name != NULL) {
|
|
// return channel name if channel available else NONE
|
|
if ((channel >= 0) && (channel < info->channels)) {
|
|
char tname[64];
|
|
|
|
tname[0] = '\0';
|
|
switch (channel) {
|
|
case 0: strcpy(tname,"Num Monitored Devices");
|
|
break;
|
|
case 1: strcpy(tname,"Num Registered Devices");
|
|
break;
|
|
case -1:
|
|
strcat(tname,"_Error");
|
|
break;
|
|
default:
|
|
sprintf(tname,"Channel_%d",channel);
|
|
}
|
|
strncpy(name,tname,NAME_LENGTH);
|
|
*(name+NAME_LENGTH-1) = '\0';
|
|
} else
|
|
strcpy(name, "NONE");
|
|
|
|
}
|
|
return FE_SUCCESS;
|
|
}
|
|
|
|
/*---- device driver entry point -----------------------------------*/
|
|
|
|
INT bulk_monitor(INT cmd, ...)
|
|
{
|
|
va_list argptr;
|
|
HNDLE hKey;
|
|
INT channel, status;
|
|
DWORD flags;
|
|
float value, *pvalue;
|
|
void *info, *bd;
|
|
char *name;
|
|
|
|
va_start(argptr, cmd);
|
|
status = FE_SUCCESS;
|
|
|
|
switch (cmd) {
|
|
case CMD_INIT:
|
|
hKey = va_arg(argptr, HNDLE);
|
|
info = va_arg(argptr, void *);
|
|
channel = va_arg(argptr, INT);
|
|
flags = va_arg(argptr, DWORD);
|
|
bd = va_arg(argptr, void *);
|
|
status = bulk_monitor_init(hKey, info, channel, bd);
|
|
break;
|
|
|
|
case CMD_EXIT:
|
|
info = va_arg(argptr, void *);
|
|
status = bulk_monitor_exit(info);
|
|
break;
|
|
|
|
case CMD_GET:
|
|
info = va_arg(argptr, void *);
|
|
channel = va_arg(argptr, INT);
|
|
pvalue = va_arg(argptr, float *);
|
|
status = bulk_monitor_get(info, channel, pvalue);
|
|
break;
|
|
|
|
case CMD_GET_DEMAND:
|
|
info = va_arg(argptr, void *);
|
|
channel = va_arg(argptr, INT);
|
|
pvalue = va_arg(argptr, float *);
|
|
status = bulk_monitor_get_demand(info, channel, pvalue);
|
|
break;
|
|
|
|
case CMD_SET:
|
|
info = va_arg(argptr, void *);
|
|
channel = va_arg(argptr, INT);
|
|
value = (float) va_arg(argptr, double);
|
|
status = bulk_monitor_set(info, channel, value);
|
|
break;
|
|
|
|
#ifdef OBSOLETE_2_1
|
|
case CMD_GET_ALL:
|
|
info = va_arg(argptr, void *);
|
|
channel = va_arg(argptr, INT);
|
|
pvalue = va_arg(argptr, float *);
|
|
status = bulk_monitor_get_all(info, channel, pvalue);
|
|
break;
|
|
#endif
|
|
|
|
case CMD_GET_THRESHOLD:
|
|
info = va_arg(argptr, void *);
|
|
channel = va_arg(argptr, INT);
|
|
pvalue = va_arg(argptr, float *);
|
|
status = bulk_monitor_get_default_threshold(info, channel, pvalue);
|
|
break;
|
|
|
|
case CMD_GET_LABEL:
|
|
info = va_arg(argptr, void *);
|
|
channel = va_arg(argptr, INT);
|
|
name = va_arg(argptr, char *);
|
|
status = bulk_monitor_get_name(info, channel, name);
|
|
break;
|
|
|
|
case CMD_SET_LABEL:
|
|
#ifdef OBSOLETE_2_1
|
|
case CMD_SET_ALL:
|
|
#endif
|
|
/* NOT USED not necessary to implement */ ;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
va_end(argptr);
|
|
|
|
return status;
|
|
}
|
|
|
|
/*------------------------------------------------------------------*/
|