More work on soft proton counter

This commit is contained in:
2026-02-06 10:29:24 +01:00
committed by soederqvist_a
parent 94814b2140
commit bec218ad86
2 changed files with 255 additions and 59 deletions
+118
View File
@@ -0,0 +1,118 @@
#include <stdio.h>
#include <dbDefs.h>
#include <errlog.h>
#include <aSubRecord.h>
#include <epicsTypes.h>
#include <registryFunction.h>
#include <epicsExport.h>
/* Sample rate */
static const epicsFloat64 soft_proton_sample_rate = 0.1;
/* To allow setting debug pring from iocsh */
static int softProtonDebug=0;
epicsExportAddress(int, softProtonDebug);
/*
* This function is called a IOC init
*/
static long initEmulatedCounter(struct subRecord *psub)
{
if (softProtonDebug) printf("initEmulatedCounter was called\n");
return 0;
}
/*
* This functioni is called everytime the record processes.
* Even though this record can process arrays, we only use it with scalars,
* hence all the [0]'s.
*/
static long processEmulatedCounter(struct aSubRecord *psub)
{
enum commands {
NONE = 0,
COUNT_PRESET = 1,
TIME_PRESET = 2,
PAUSE = 3,
CONTINUE = 4
STOP = 5,
FULL_RESET = 6
};
enum status {
IDLE = 0,
COUNTING = 1,
LOW_RATE = 2,
PAUSED = 3,
INVALID = 4
};
const char[] funcstr = "processEmulatedCounter";
if (softProtonDebug) printf("%s was called\n", funcstr);
/* We copy input values to the stack,
but take the pointer to output values.
This to increase readability. */
/* First all inputs that have a matching output */
/* Status input and output pointer */
epicsUInt32 status = psub->a[0];
epicsUInt32* status_out = psub->vala;
/* Monitor count input and output pointer */
epicsInt64 monitor_count = psub->b[0];
epicsInt64* monitor_count_out = psub->valb;
/* Elapsed time input and output pointer */
epicsFloat64 elapsed_time = psub->c[0];
epicsFloat64* elaped_time_out = psub->valc;
/* Command trigger input and output pointer */
epicsUInt32* command_trig = psub->d[0];
epicsUInt32* command_trig_out = psub->vald;
/* Remaining only inputs */
epicsUInt32 preset_count = psub->f[0];
epicsInt64 preset_count = psub->g[0];
epicsFloat64 preset_time = psub->h[0];
epicsFloat64 proton_rate = psub->l[0];
if (status >= INVALID || command_trig > FULL_RESET) {
/* This shouldn't happen, but let's handle it just in case */
errlogPrintf("%s: Status and/or command triggers are invalid \n"
"Status has value %d, \n Command trigger has value %d\n",
funcstr, status, command_trig);
return -1;
}
if (command_trig == FULL_RESET) {
*status_out = IDLE;
*monitor_count_out = 0;
*elapsed_time_out = 0.0;
*command_trig_out = NONE;
if (softProtonDebug) printf("%s: Full reset done!\n", funcstr);
return 0;
}
/* Determine if we are idle and have not received a command */
if (status == 0 && command_trig == 0) {
/* Just return as quickly as possible if there is nothing going on */
return 0;
}
/* Determine if we are idle but received a count command */
if (status == 0 && (command_trig == 1 || command_trig == 2)) {
if (softProtonDebug) printf("%s: Starting Count!\n", funcstr);
/* Check that count type is properly stored */
if ( command_trig != count_type ) {
}
}
/* Placeholder output setting */
*status_out = status;
*monitor_count_out = monitor_count;
if ( first
*elapsed_time_out = elapsed_time + soft_proton_sample_rate;
return 0;
}
epicsRegisterFunction(initEmulatedCounter);
epicsRegisterFunction(processEmulatedCounter);