From d7a4d057aa8bd0d1f2865b2379ce74aa1f4ef5c4 Mon Sep 17 00:00:00 2001 From: Edward Wall Date: Tue, 18 Nov 2025 07:58:02 +0100 Subject: [PATCH] makes detector channel the last channel --- db/daq_common.db | 51 +++++++++++++++---------------- scripts/st.cmd | 14 ++++----- src/asynStreamGeneratorDriver.cpp | 25 ++++++++------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/db/daq_common.db b/db/daq_common.db index 22ad9a1..3f3af55 100644 --- a/db/daq_common.db +++ b/db/daq_common.db @@ -15,6 +15,11 @@ record(longout, "$(INSTR)$(NAME):FULL-RESET") ################################################################################ # Status Variables +record(stringin, "$(INSTR)$(NAME):MsgTxt") +{ + field(DESC, "Unexpected received response") +} + # We separate the RAW-STATUS and the STATUS PV so that the state can be updated # in a sequence, that guarantees that we included the most recent time and # counts before the status switches back to Idle. @@ -48,11 +53,11 @@ record(fanout, "$(INSTR)$(NAME):READALL") { field(SELM, "All") field(LNK0, "$(INSTR)$(NAME):ELAPSED-TIME PP") - field(LNK1, "$(INSTR)$(NAME):M0") - field(LNK2, "$(INSTR)$(NAME):M1") - field(LNK3, "$(INSTR)$(NAME):M2") - field(LNK4, "$(INSTR)$(NAME):M3") - field(LNK5, "$(INSTR)$(NAME):M4") + field(LNK1, "$(INSTR)$(NAME):M1") + field(LNK2, "$(INSTR)$(NAME):M2") + field(LNK3, "$(INSTR)$(NAME):M3") + field(LNK4, "$(INSTR)$(NAME):M4") + field(LNK5, "$(INSTR)$(NAME):M5") # Doesn't seemt o be a problem to have more in here :D # field(LNK6, "$(INSTR)$(NAME):M5") # field(LNK7, "$(INSTR)$(NAME):M6") @@ -116,42 +121,34 @@ record(bi, "$(INSTR)$(NAME):ETS") ################################################################################ # Count Commands -record(ao,"$(INSTR)$(NAME):PRESET-COUNT") +record(longout,"$(INSTR)$(NAME):PRESET-COUNT") { field(DESC, "Count until preset reached") field(DTYP, "asynInt32") field(OUT, "@asyn($(PORT),0,$(TIMEOUT=1)) P_CNT") field(VAL, 0) - field(PREC, 2) } -record(ao,"$(INSTR)$(NAME):PRESET-TIME") +record(longout,"$(INSTR)$(NAME):PRESET-TIME") { field(DESC, "Count for specified time") field(EGU, "seconds") field(DTYP, "asynInt32") field(OUT, "@asyn($(PORT),0,$(TIMEOUT=1)) P_TIME") field(VAL, 0) - field(PREC, 2) } -# record(bo,"$(INSTR)$(NAME):PAUSE") -# { -# field(DESC, "Pause the current count") -# field(DTYP, "stream") -# field(OUT, "@... pauseCount($(INSTR)$(NAME):) $(PORT)") -# field(VAL, "0") -# field(FLNK, "$(INSTR)$(NAME):RAW-STATUS") -# } -# -# record(bo,"$(INSTR)$(NAME):CONTINUE") -# { -# field(DESC, "Continue with a count that was paused") -# field(DTYP, "stream") -# field(OUT, "@... continueCount($(INSTR)$(NAME):) $(PORT)") -# field(VAL, "0") -# field(FLNK, "$(INSTR)$(NAME):RAW-STATUS") -# } +record(bo,"$(INSTR)$(NAME):PAUSE") +{ + field(DESC, "Pause the current count") + field(VAL, "0") +} + +record(bo,"$(INSTR)$(NAME):CONTINUE") +{ + field(DESC, "Continue with a count that was paused") + field(VAL, "0") +} record(longout, "$(INSTR)$(NAME):STOP") { @@ -165,7 +162,7 @@ record(longout, "$(INSTR)$(NAME):MONITOR-CHANNEL") field(DESC, "PRESET-COUNT Monitors this channel") field(DTYP, "asynInt32") field(OUT, "@asyn($(PORT),0,$(TIMEOUT=1)) MONITOR") - field(DRVL, "0") # Smallest Monitor Channel + field(DRVL, "1") # Smallest Monitor Channel field(DRVH, "$(CHANNELS)") # Largest Monitor Channel } diff --git a/scripts/st.cmd b/scripts/st.cmd index 06a696e..4f5d5d7 100755 --- a/scripts/st.cmd +++ b/scripts/st.cmd @@ -5,14 +5,14 @@ on error break require StreamGenerator, test -epicsEnvSet("INSTR", "SQ:TEST:") -epicsEnvSet("NAME", "SG") +epicsEnvSet("INSTR", "SQ:DMC-DAQ:") +epicsEnvSet("NAME", "DAQ") # Local UDP Generator Test Config -# drvAsynIPPortConfigure("ASYN_IP_PORT", "127.0.0.1:9071:54321 UDP", 0, 0, 1) +drvAsynIPPortConfigure("ASYN_IP_PORT", "127.0.0.1:9071:54321 UDP", 0, 0, 1) # Correlation Unit Config -drvAsynIPPortConfigure("ASYN_IP_PORT", "172.28.69.20:54321:54321 UDP", 0, 0, 1) +# drvAsynIPPortConfigure("ASYN_IP_PORT", "172.28.69.20:54321:54321 UDP", 0, 0, 1) # With a udpQueue and sortQueue size of 10'000 packets, we can hold in memory # 10'000 * 243 = 2.43e6 events @@ -26,13 +26,13 @@ asynStreamGenerator("ASYN_SG", "ASYN_IP_PORT", 4, 10000, "", "", "", 0, 0) dbLoadRecords("$(StreamGenerator_DB)daq_common.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNELS=5") -# Detector Count Channel -dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=0") - # Monitor Channels dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=1") dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=2") dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=3") dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=4") +# Detector Count Channel +dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=5") + iocInit() diff --git a/src/asynStreamGeneratorDriver.cpp b/src/asynStreamGeneratorDriver.cpp index bb9f7cd..add7410 100644 --- a/src/asynStreamGeneratorDriver.cpp +++ b/src/asynStreamGeneratorDriver.cpp @@ -169,8 +169,8 @@ asynStreamGeneratorDriver::asynStreamGeneratorDriver( status = createFloat64Param(status, P_ElapsedTimeString, &P_ElapsedTime); status = createInt32Param(status, P_ClearElapsedTimeString, &P_ClearElapsedTime); - status = - createInt32Param(status, P_MonitorChannelString, &P_MonitorChannel); + status = createInt32Param(status, P_MonitorChannelString, &P_MonitorChannel, + this->num_channels); status = createInt32Param(status, P_ThresholdString, &P_Threshold, 1); status = createInt32Param(status, P_ThresholdChannelString, &P_ThresholdChannel, 1); @@ -182,15 +182,15 @@ asynStreamGeneratorDriver::asynStreamGeneratorDriver( P_ClearCounts = new int[this->num_channels]; for (std::size_t i = 0; i < this->num_channels; ++i) { memset(pv_name_buffer, 0, 100); - epicsSnprintf(pv_name_buffer, 100, P_CountsString, i); + epicsSnprintf(pv_name_buffer, 100, P_CountsString, i + 1); status = createInt64Param(status, pv_name_buffer, P_Counts + i); memset(pv_name_buffer, 0, 100); - epicsSnprintf(pv_name_buffer, 100, P_RateString, i); + epicsSnprintf(pv_name_buffer, 100, P_RateString, i + 1); status = createInt32Param(status, pv_name_buffer, P_Rates + i); memset(pv_name_buffer, 0, 100); - epicsSnprintf(pv_name_buffer, 100, P_ClearCountsString, i); + epicsSnprintf(pv_name_buffer, 100, P_ClearCountsString, i + 1); status = createInt32Param(status, pv_name_buffer, P_ClearCounts + i); } @@ -409,15 +409,13 @@ asynStatus asynStreamGeneratorDriver::writeInt32(asynUser *pasynUser, } } else if (function == P_ClearElapsedTime) { if (!currentStatus) { - setIntegerParam(P_ElapsedTime, 0); - status = (asynStatus)callParamCallbacks(); + setDoubleParam(P_ElapsedTime, 0); } else { return asynError; } } else if (isClearCount) { if (!currentStatus) { setInteger64Param(P_Counts[channelToClear], 0); - status = (asynStatus)callParamCallbacks(); } else { return asynError; } @@ -726,6 +724,9 @@ void asynStreamGeneratorDriver::processEvents() { getIntegerParam(this->P_TimePreset, &timePreset); getIntegerParam(this->P_MonitorChannel, &presetChannel); + // Parameter is base 1, here we need base 0 + --presetChannel; + // reset status variables startTimestamp = eventsA[0].timestamp; elapsedSeconds = 0; @@ -741,15 +742,17 @@ void asynStreamGeneratorDriver::processEvents() { // try and make sure the data we send to kafka is correct, while // the measurement time also appears intuitive. for (std::size_t i = 0; i < toProcess; ++i) { - counts[eventsA[i].source == 0 ? eventsA[i].pixelId + 1 : 0] += - 1; + counts[eventsA[i].source == 0 ? eventsA[i].pixelId + : this->num_channels - 1] += 1; elapsedSeconds = (eventsA[i].timestamp - startTimestamp) / 1e9; // TODO should really check there an no more events with the // same final timestamp if ((countPreset && counts[presetChannel] >= countPreset) || - (timePreset && elapsedSeconds > (double)timePreset)) + (timePreset && elapsedSeconds > (double)timePreset)) { + elapsedSeconds = timePreset; break; + } // TODO also batchwise? this->queueForKafka(eventsA[i]);