From d2981dd29fc857d6981e446ba0bbba273ab8d1dc Mon Sep 17 00:00:00 2001 From: soederqvist_a Date: Fri, 6 Mar 2026 10:54:33 +0100 Subject: [PATCH] clang-format, change to don't allow single line enum --- .clang-format | 2 +- src/daq_soft_proton.c | 176 ++++++++++++++++++++++-------------------- 2 files changed, 92 insertions(+), 86 deletions(-) diff --git a/.clang-format b/.clang-format index 67fb9e0..2dec313 100644 --- a/.clang-format +++ b/.clang-format @@ -42,7 +42,7 @@ AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false -AllowShortEnumsOnASingleLine: true +AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All diff --git a/src/daq_soft_proton.c b/src/daq_soft_proton.c index 3f50ed4..e366ca4 100644 --- a/src/daq_soft_proton.c +++ b/src/daq_soft_proton.c @@ -7,31 +7,31 @@ */ #include -#include -#include #include -#include -#include -#include +#include #include +#include +#include +#include +#include /* Sample rate */ #define SOFT_PROTON_SAMPLE_RATE 0.1 /* To allow setting debug pring from iocsh */ -static int softProtonDebug=0; +static int softProtonDebug = 0; epicsExportAddress(int, softProtonDebug); struct spc_internal { - epicsUInt32 status; - epicsInt64 monitor_count; + epicsUInt32 status; + epicsInt64 monitor_count; epicsFloat64 elapsed_time; - epicsUInt32 command_trig; - epicsInt32 threshold_ch; + epicsUInt32 command_trig; + epicsInt32 threshold_ch; epicsFloat64 threshold; epicsFloat64 proton_rate; epicsFloat64 prev_proton_rate; - epicsUInt32 count_type; + epicsUInt32 count_type; epicsFloat64 preset_count; epicsFloat64 preset_time; epicsFloat64 average_rate; @@ -49,7 +49,7 @@ enum commands { FULL_RESET = 6 }; -/* Enum with the possible statuses/states +/* Enum with the possible statuses/states * this has to match the what's in the mbbi in the database*/ enum status { IDLE = 0, @@ -59,10 +59,9 @@ enum status { INVALID = 4 }; - -int handleNoop(struct spc_internal* spc, epicsOldString* msg_text) { - const char* funcstr = "handleNoop"; - //if (softProtonDebug) printf("%s was called\n", funcstr); +int handleNoop(struct spc_internal *spc, epicsOldString *msg_text) { + const char *funcstr = "handleNoop"; + // if (softProtonDebug) printf("%s was called\n", funcstr); /* This shouldn't happen, but let's handle it just in case */ if (spc->status >= INVALID || spc->command_trig > FULL_RESET) { strcpy(*msg_text, "INVALID STATE!"); @@ -75,33 +74,33 @@ int handleNoop(struct spc_internal* spc, epicsOldString* msg_text) { /* Determine if we are idle and have received a noop command */ if (spc->status == IDLE) { switch (spc->command_trig) { - case PAUSE: - case CONTINUE: - case STOP: - strcpy(*msg_text, "Can not PAUSE/CONTINUE/STOP during IDLE."); - printf("%s: %s\n" - "Status has value %d, \n" - "Command trigger has value %d\n", *msg_text, - funcstr, spc->status, spc->command_trig); - return 1; + case PAUSE: + case CONTINUE: + case STOP: + strcpy(*msg_text, "Can not PAUSE/CONTINUE/STOP during IDLE."); + printf("%s: %s\n" + "Status has value %d, \n" + "Command trigger has value %d\n", + *msg_text, funcstr, spc->status, spc->command_trig); + return 1; } } /* Determine if we are counting, low_rate or paused; * and have received a noop command */ if (spc->status == COUNTING || spc->status == LOW_RATE || - spc->status == PAUSED) { + spc->status == PAUSED) { switch (spc->command_trig) { - case COUNT_PRESET: - case TIME_PRESET: - strcpy(*msg_text, "Already counting"); - printf("%s: Already counting can not start a new count\n" - "Status has value %d, \n" - "Command trigger has value %d\n", - funcstr, spc->status, spc->command_trig); - /* This case could be seen as OK. - * Nothing is keeping us from continuing, so let's do that. */ - return 0; + case COUNT_PRESET: + case TIME_PRESET: + strcpy(*msg_text, "Already counting"); + printf("%s: Already counting can not start a new count\n" + "Status has value %d, \n" + "Command trigger has value %d\n", + funcstr, spc->status, spc->command_trig); + /* This case could be seen as OK. + * Nothing is keeping us from continuing, so let's do that. */ + return 0; } } @@ -121,37 +120,36 @@ int handleNoop(struct spc_internal* spc, epicsOldString* msg_text) { * This function is called everytime the record processes. * Even though this record can process arrays, we only use it with scalars. */ -static long processEmulatedCounter(struct aSubRecord *psub) -{ - const char* funcstr = "processEmulatedCounter"; - //if (softProtonDebug) printf("%s was called\n", funcstr); +static long processEmulatedCounter(struct aSubRecord *psub) { + const char *funcstr = "processEmulatedCounter"; + // if (softProtonDebug) printf("%s was called\n", funcstr); /* Declare internal variable */ struct spc_internal spc_int; - struct spc_internal* spc = &spc_int; + struct spc_internal *spc = &spc_int; - /* Copy input values to a struct on the stack + /* Copy input values to a struct on the stack * to simplify creation of functions */ - spc->status = *(epicsUInt32*)psub->a; - spc->monitor_count = *(epicsInt64*)psub->b; - spc->elapsed_time = *(epicsFloat64*)psub->c; - spc->command_trig = *(epicsUInt32*)psub->d; - spc->threshold_ch = *(epicsInt32*)psub->e; - spc->threshold = *(epicsFloat64*)psub->f; - spc->count_type = *(epicsUInt32*)psub->g; - spc->preset_count = *(epicsFloat64*)psub->h; - spc->preset_time = *(epicsFloat64*)psub->i; - spc->prev_proton_rate = *(epicsFloat64*)psub->j; - spc->proton_rate = *(epicsFloat64*)psub->l; + spc->status = *(epicsUInt32 *)psub->a; + spc->monitor_count = *(epicsInt64 *)psub->b; + spc->elapsed_time = *(epicsFloat64 *)psub->c; + spc->command_trig = *(epicsUInt32 *)psub->d; + spc->threshold_ch = *(epicsInt32 *)psub->e; + spc->threshold = *(epicsFloat64 *)psub->f; + spc->count_type = *(epicsUInt32 *)psub->g; + spc->preset_count = *(epicsFloat64 *)psub->h; + spc->preset_time = *(epicsFloat64 *)psub->i; + spc->prev_proton_rate = *(epicsFloat64 *)psub->j; + spc->proton_rate = *(epicsFloat64 *)psub->l; /* Get the pointer to output values only to increase readability. */ - epicsUInt32* status_out = (epicsUInt32*)psub->vala; - epicsInt64* monitor_count_out = (epicsInt64*)psub->valb; - epicsFloat64* elapsed_time_out = (epicsFloat64*)psub->valc; - epicsUInt32* command_trig_out = (epicsUInt32*)psub->vald; - epicsFloat64* prev_proton_rate_out = (epicsFloat64*)psub->vale; - epicsUInt32* is_low_rate_out = (epicsUInt32*)psub->valf; - epicsOldString* msg_txt_out = (epicsOldString*)psub->valg; + epicsUInt32 *status_out = (epicsUInt32 *)psub->vala; + epicsInt64 *monitor_count_out = (epicsInt64 *)psub->valb; + epicsFloat64 *elapsed_time_out = (epicsFloat64 *)psub->valc; + epicsUInt32 *command_trig_out = (epicsUInt32 *)psub->vald; + epicsFloat64 *prev_proton_rate_out = (epicsFloat64 *)psub->vale; + epicsUInt32 *is_low_rate_out = (epicsUInt32 *)psub->valf; + epicsOldString *msg_txt_out = (epicsOldString *)psub->valg; /* Always update the whole string */ psub->nevg = psub->novg = 40; @@ -163,7 +161,7 @@ static long processEmulatedCounter(struct aSubRecord *psub) *prev_proton_rate_out = spc->proton_rate; if (spc->average_rate < spc->threshold && - spc->threshold_ch >= 1) { /* Channel 0 is interpreted as disabled */ + spc->threshold_ch >= 1) { /* Channel 0 is interpreted as disabled */ *is_low_rate_out = 1; } else { *is_low_rate_out = 0; @@ -181,7 +179,6 @@ static long processEmulatedCounter(struct aSubRecord *psub) /* We have state that prohibits further processing */ return 0; - /* Commands with priority always yielding IDLE status first */ if (spc->command_trig == FULL_RESET) { strcpy(*msg_txt_out, "Full reset!"); @@ -190,21 +187,24 @@ static long processEmulatedCounter(struct aSubRecord *psub) *monitor_count_out = 0; *elapsed_time_out = 0.0; *command_trig_out = NONE; - if (softProtonDebug) printf("%s: Full reset done!\n", funcstr); + if (softProtonDebug) + printf("%s: Full reset done!\n", funcstr); return 0; } else if (spc->command_trig == STOP || (spc->status == IDLE && spc->command_trig == NONE)) { /* Stop is always valid, retains everything except status goes to idle. - * This happens to be the same case as when IDLE and no command received */ + * This happens to be the same case as when IDLE and no command received + */ *status_out = IDLE; *command_trig_out = NONE; *monitor_count_out = spc->monitor_count; *elapsed_time_out = spc->elapsed_time; - if (softProtonDebug) printf("%s: Case STOP or IDLE!\n", funcstr); + if (softProtonDebug) + printf("%s: Case STOP or IDLE!\n", funcstr); return 0; - } else if (((spc->status == COUNTING || spc->status == LOW_RATE) - && spc->command_trig == PAUSE) || - (spc->status == PAUSED && spc->command_trig == NONE)) { + } else if (((spc->status == COUNTING || spc->status == LOW_RATE) && + spc->command_trig == PAUSE) || + (spc->status == PAUSED && spc->command_trig == NONE)) { strcpy(*msg_txt_out, "Paused!"); /* We are counting or at low rate and received pause. * Also we are paused but have received no command, this @@ -213,15 +213,18 @@ static long processEmulatedCounter(struct aSubRecord *psub) *command_trig_out = NONE; *monitor_count_out = spc->monitor_count; *elapsed_time_out = spc->elapsed_time; - if (softProtonDebug) printf("%s: Case PAUSE!\n", funcstr); + if (softProtonDebug) + printf("%s: Case PAUSE!\n", funcstr); return 0; - } else if (spc->status == IDLE && - (spc->command_trig == COUNT_PRESET || spc->command_trig == TIME_PRESET)) { + } else if (spc->status == IDLE && (spc->command_trig == COUNT_PRESET || + spc->command_trig == TIME_PRESET)) { /* Determine if we are idle but received a count command */ - if (softProtonDebug) printf("%s: Starting Count!\n", funcstr); - /* Sanity check that count type is properly stored */ + if (softProtonDebug) + printf("%s: Starting Count!\n", funcstr); + /* Sanity check that count type is properly stored */ if (spc->command_trig != spc->count_type) { - if (softProtonDebug) printf("%s: Count type not stored!\n", funcstr); + if (softProtonDebug) + printf("%s: Count type not stored!\n", funcstr); return -1; } /* Starting a new count @@ -234,22 +237,25 @@ static long processEmulatedCounter(struct aSubRecord *psub) } else { *status_out = COUNTING; } - if (softProtonDebug) printf("%s: Case received COUNT command!\n", funcstr); + if (softProtonDebug) + printf("%s: Case received COUNT command!\n", funcstr); return 0; } else if ((((spc->status == LOW_RATE && spc->command_trig == NONE) || - (spc->status == LOW_RATE && spc->command_trig == CONTINUE))) - && *is_low_rate_out == 1) { + (spc->status == LOW_RATE && spc->command_trig == CONTINUE))) && + *is_low_rate_out == 1) { *status_out = LOW_RATE; /* LOW_RATE or resuming from PAUSE */ *command_trig_out = NONE; /* Maintain same counter and time*/ *monitor_count_out = spc->monitor_count; *elapsed_time_out = spc->elapsed_time; - if (softProtonDebug) printf("%s: Case LOW_RATE!\n", funcstr); + if (softProtonDebug) + printf("%s: Case LOW_RATE!\n", funcstr); return 0; } - if (softProtonDebug) printf("%s: Case COUNT incremental cycle!\n", funcstr); + if (softProtonDebug) + printf("%s: Case COUNT incremental cycle!\n", funcstr); /* Ending up here means: * 1. status == COUNTING && command_trig == NONE * 2. status == COUNTING && command_trig == CONTINUE @@ -264,8 +270,8 @@ static long processEmulatedCounter(struct aSubRecord *psub) *status_out = COUNTING; /* Increament counter and time */ - *monitor_count_out = spc->monitor_count + - spc->average_rate * SOFT_PROTON_SAMPLE_RATE; + *monitor_count_out = + spc->monitor_count + spc->average_rate * SOFT_PROTON_SAMPLE_RATE; *elapsed_time_out = spc->elapsed_time + SOFT_PROTON_SAMPLE_RATE; /* Check if we are below threshold */ @@ -278,11 +284,11 @@ static long processEmulatedCounter(struct aSubRecord *psub) /* Check if count is finished normally. * Higher priority than low rate */ if (/* Time based count finished */ - (*elapsed_time_out >= spc->preset_time && - spc->count_type == TIME_PRESET) || + (*elapsed_time_out >= spc->preset_time && + spc->count_type == TIME_PRESET) || /* Monitor based count finished */ - (*monitor_count_out >= spc->preset_count && - spc->count_type == COUNT_PRESET)) { + (*monitor_count_out >= spc->preset_count && + spc->count_type == COUNT_PRESET)) { *status_out = IDLE; }