From 8a0be319efcec130daecb09bac95a592e43cef8f Mon Sep 17 00:00:00 2001 From: Edward Wall Date: Mon, 15 Sep 2025 09:17:32 +0200 Subject: [PATCH] Driver from Andrea Raselli as of 12.01.2024 --- device/bulk_monitor.c | 304 ++++++++++++++++++++++++++++++++++++++++++ device/bulk_monitor.h | 14 ++ 2 files changed, 318 insertions(+) create mode 100644 device/bulk_monitor.c create mode 100644 device/bulk_monitor.h diff --git a/device/bulk_monitor.c b/device/bulk_monitor.c new file mode 100644 index 0000000..ed2999b --- /dev/null +++ b/device/bulk_monitor.c @@ -0,0 +1,304 @@ +/********************************************************************\ + + Name: bulk_monitor.c + Created by: RA36 + + Contents: DD definitions + Bulk muSR front-end creating mon files +\********************************************************************/ + +#include +#include +#include +#include +#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; +} + +/*------------------------------------------------------------------*/ diff --git a/device/bulk_monitor.h b/device/bulk_monitor.h new file mode 100644 index 0000000..97723c0 --- /dev/null +++ b/device/bulk_monitor.h @@ -0,0 +1,14 @@ +/********************************************************************\ + + Name: bulk_monitor.h + Created by: RA36 + + Contents: Device driver function declarations for + Bulk muSR front-end creating mon files + +\********************************************************************/ + +extern INT n_mon_devices; +extern INT n_reg_devices; + +INT bulk_monitor(INT cmd, ...);