@@ -106,45 +106,87 @@ Function TP_StoreTP(device, TPWave, tpMarker, hsList)
106
106
SetNumberInWaveNote ( storedTP, NOTE_INDEX, index)
107
107
End
108
108
109
- /// @brief Return a number of consecutive test pulses ending with the TP
110
- /// identified by tpMarker.
111
- ///
112
- /// The wave reference wave will have as many columns as active headstages were used.
113
- Function /WAVE TP_GetConsecutiveTPsUptoMarker ( string device, variable tpMarker, variable number)
109
+ static Function TP_GetStoredTPIndex ( string device, variable tpMarker)
114
110
115
111
variable numEntries
116
112
117
113
WAVE /WAVE storedTP = GetStoredTestPulseWave ( device)
118
114
numEntries = GetNumberFromWaveNote ( storedTP, NOTE_INDEX)
119
-
120
115
if ( numEntries == 0 )
121
- return $ ""
116
+ return NaN
122
117
endif
123
118
124
119
Make / FREE/ N= ( numEntries) matches
125
-
126
120
Multithread matches[ 0, numEntries - 1 ] = GetNumberFromWaveNote ( storedTP[ p] , "TPMarker" ) == tpMarker
127
-
128
121
FindValue / V=1 matches
129
-
130
122
if ( V_row == -1 )
123
+ return NaN
124
+ endif
125
+
126
+ return V_row
127
+ End
128
+
129
+ Function /WAVE TP_GetStoredTP ( string device, variable tpMarker, variable includeDAC)
130
+
131
+ variable tpIndex, numEntries, dimMarker
132
+
133
+ includeDAC = !! includeDAC
134
+
135
+ tpIndex = TP_GetStoredTPIndex ( device, tpMarker)
136
+ if ( IsNaN ( tpIndex))
131
137
return $ ""
132
138
endif
133
139
134
- Make / FREE/ N= ( number) / WAVE result
140
+ WAVE /WAVE tpStored = GetStoredTestPulseWave ( device)
141
+ WAVE tpADC = tpStored[ tpIndex]
135
142
136
- if ( number > V_row + 1 )
143
+ WAVE tpStorage = GetTPStorage ( device)
144
+ numEntries = GetNumberFromWaveNote ( tpStorage, NOTE_INDEX)
145
+ dimMarker = FindDimLabel ( tpStorage, LAYERS, "TPMarker" )
146
+ FindValue / RMD= [][ 0 ][ dimMarker] / V= ( tpMarker) tpStorage
147
+ ASSERT ( V_row >= 0, "Inconsistent TP data" )
148
+ Duplicate / FREE/ RMD= [ V_row][][] tpStorage, tpResults
149
+
150
+ if ( includeDAC)
151
+ Make / FREE/ D/ N=0 tpDAC
152
+ // TP_CreateTestPulseWaveImpl(tpDAC, variable totalLength, variable pulseStart, variable pulseLength)
153
+ else
154
+ WAVE /Z tpDAC = $ ""
155
+ endif
156
+
157
+ Make / FREE/ WAVE tpAll = { tpADC, tpDAC, tpResults}
158
+
159
+ return tpAll
160
+ End
161
+
162
+ /// @brief Return a number of consecutive test pulses ending with the TP
163
+ /// identified by tpMarker.
164
+ ///
165
+ /// The wave reference wave will have as many columns as active headstages were used.
166
+ Function /WAVE TP_GetConsecutiveTPsUptoMarker ( string device, variable tpMarker, variable number)
167
+
168
+ variable tpIndex, tpCycleId
169
+
170
+ tpIndex = TP_GetStoredTPIndex ( device, tpMarker)
171
+ if ( IsNaN ( tpIndex))
172
+ return $ ""
173
+ endif
174
+
175
+ if ( number > tpIndex + 1 )
137
176
// too few TPs available
138
177
return $ ""
139
178
endif
140
179
141
- result [] = storedTP [ V_row - number + 1 + p ]
180
+ Make / FREE / N = ( number) / WAVE result
142
181
143
- // check that they all belong to the same TP cycle
144
- Redimension / N= ( number) matches
145
- matches[] = GetNumberFromWaveNote ( result[ 0 ] , "TPCycleID" ) == GetNumberFromWaveNote ( result[ p] , "TPCycleID" )
182
+ WAVE /WAVE storedTP = GetStoredTestPulseWave ( device)
183
+ result[] = storedTP[ tpIndex - number + 1 + p]
146
184
147
- if ( Sum ( matches) < number)
185
+ // check that they all belong to the same TP cycle
186
+ Make / FREE/ N= ( number) matches
187
+ tpCycleId = GetNumberFromWaveNote ( result[ 0 ] , "TPCycleID" )
188
+ matches[] = tpCycleId == GetNumberFromWaveNote ( result[ p] , "TPCycleID" )
189
+ if ( sum ( matches) < number)
148
190
return $ ""
149
191
endif
150
192
@@ -888,9 +930,11 @@ threadsafe Function/DF TP_TSAnalysis(dfrInp)
888
930
variable evalRange, refTime, refPoint, tpStartPoint
889
931
variable sampleInt, jsonId
890
932
variable avgBaselineSS, avgTPSS, instVal, evalOffsetPointsCorrected, instPoint
933
+ STRUCT TPZMQData tpzmq
891
934
892
935
DFREF dfrOut = NewFreeDataFolder ()
893
936
937
+ // see TP_PrepareAnalysisDF for order
894
938
WAVE data = dfrInp: param0
895
939
NVAR /SDFR= dfrInp clampAmp = param1
896
940
NVAR /SDFR= dfrInp clampMode = param2
@@ -904,6 +948,7 @@ threadsafe Function/DF TP_TSAnalysis(dfrInp)
904
948
NVAR /SDFR= dfrInp activeADCs = param10
905
949
NVAR /SDFR= dfrInp timeStamp = param11
906
950
NVAR /SDFR= dfrInp timeStampUTC = param12
951
+ NVAR /SDFR= dfrInp cycleId = param13
907
952
908
953
#if defined ( TP_ANALYSIS_DEBUGGING)
909
954
DEBUGPRINT_TS ( "Marker: " , var = marker)
@@ -1007,68 +1052,32 @@ threadsafe Function/DF TP_TSAnalysis(dfrInp)
1007
1052
variable /G dfrOut: timeStamp = timeStamp
1008
1053
variable /G dfrOut: timeStampUTC = timeStampUTC
1009
1054
1010
- // ZMQ publishing
1011
- jsonId = JSON_New ()
1012
- JSON_AddTreeObject ( jsonID, "properties" )
1013
- JSON_AddVariable ( jsonID, "properties/unique tp marker" , marker)
1014
- JSON_AddString ( jsonID, "properties/device" , device)
1015
- JSON_AddVariable ( jsonID, "properties/headstage" , hsIndex)
1016
- JSON_AddVariable ( jsonID, "properties/time of tp acquisition" , now)
1017
- JSON_AddVariable ( jsonID, "properties/clamp mode" , clampMode)
1018
- JSON_AddVariable ( jsonID, "properties/clamp amplitude" , clampAmp)
1019
- JSON_AddVariable ( jsonID, "properties/pulse duration in points" , duration)
1020
- JSON_AddVariable ( jsonID, "properties/baseline fraction" , baselineFrac)
1021
- JSON_AddVariable ( jsonID, "properties/length of tp in sample points" , lengthTPInPoints)
1022
- JSON_AddVariable ( jsonID, "properties/sample interval" , sampleInt)
1023
- JSON_AddVariable ( jsonID, "properties/timeStamp" , timeStamp)
1024
- JSON_AddVariable ( jsonID, "properties/timeStampUTC" , timeStampUTC)
1025
- JSON_AddTreeObject ( jsonID, "results" )
1026
- JSON_AddVariable ( jsonID, "results/average baseline steady state" , avgBaselineSS)
1027
- JSON_AddVariable ( jsonID, "results/average tp steady state" , avgTPSS)
1028
- JSON_AddVariable ( jsonID, "results/instantaneous" , instVal)
1029
- JSON_AddVariable ( jsonID, "results/steady state resistance" , outData[ 1 ])
1030
- JSON_AddVariable ( jsonID, "results/instantaneous resistance" , outData[ 2 ])
1031
-
1032
- PUB_Publish ( jsonID, ZMQ_FILTER_TPRESULT_NOW, releaseJSON = 0 )
1033
- if ( TP_CheckPublishingTime ( ZMQ_FILTER_TPRESULT_1 S, 1 ))
1034
- PUB_Publish ( jsonID, ZMQ_FILTER_TPRESULT_1 S, releaseJSON = 0 )
1035
- endif
1036
- if ( TP_CheckPublishingTime ( ZMQ_FILTER_TPRESULT_5 S, 5 ))
1037
- PUB_Publish ( jsonID, ZMQ_FILTER_TPRESULT_5 S, releaseJSON = 0 )
1038
- endif
1039
- if ( TP_CheckPublishingTime ( ZMQ_FILTER_TPRESULT_10 S, 10 ))
1040
- PUB_Publish ( jsonID, ZMQ_FILTER_TPRESULT_10 S, releaseJSON = 0 )
1041
- endif
1042
- JSON_Release ( jsonID)
1055
+ // Serialize for ZMQ publishing
1056
+ tpzmq. marker = marker
1057
+ tpzmq. device = device
1058
+ tpzmq. headstage = hsIndex
1059
+ tpzmq. now = now
1060
+ tpzmq. clampMode = clampMode
1061
+ tpzmq. clampAmp = clampAmp
1062
+ tpzmq. duration = duration
1063
+ tpzmq. baselineFrac = baselineFrac
1064
+ tpzmq. lengthTPInPoints = lengthTPInPoints
1065
+ tpzmq. sampleIntADC = sampleInt
1066
+ tpzmq. timeStamp = timeStamp
1067
+ tpzmq. timeStampUTC = timeStampUTC
1068
+ tpzmq. cycleId = cycleId
1069
+
1070
+ tpzmq. avgBaselineSS = avgBaselineSS
1071
+ tpzmq. avgTPSS = avgTPSS
1072
+ tpzmq. instVal = instVal
1073
+ tpzmq. resistanceSS = outData[ 1 ]
1074
+ tpzmq. resistanceInst = outData[ 2 ]
1075
+
1076
+ PUB_TPResult ( tpzmq)
1043
1077
1044
1078
return dfrOut
1045
1079
End
1046
1080
1047
- /// @brief Updates the publishing timestamp in the TUFXOP storage and returns 1 if an update is due (0 otherwise)
1048
- threadsafe static Function TP_CheckPublishingTime ( string pubFilter, variable period)
1049
-
1050
- variable curTime
1051
-
1052
- TUFXOP_AcquireLock / N= ( pubFilter)
1053
- TUFXOP_GetStorage / Z/ Q/ N= ( pubFilter) lastUpdated
1054
- if ( V_flag)
1055
- TUFXOP_Init / N= ( pubFilter)
1056
- TUFXOP_GetStorage / Z/ N= ( pubFilter) lastUpdated
1057
- Make / FREE/ D dTime = { DateTime }
1058
- lastUpdated[ 0 ] = dTime
1059
- endif
1060
- curTime = DateTime
1061
- WAVE lastTime = lastUpdated[ 0 ]
1062
- if ( lastTime[ 0 ] + period > curTime)
1063
- lastTime[ 0 ] = curTime + period
1064
- TUFXOP_ReleaseLock / N= ( pubFilter)
1065
- return 1
1066
- endif
1067
- TUFXOP_ReleaseLock / N= ( pubFilter)
1068
-
1069
- return 0
1070
- End
1071
-
1072
1081
/// @brief Calculates running average [box average] for all entries and all headstages
1073
1082
static Function TP_CalculateAverage ( WAVE TPResultsBuffer, WAVE TPResults)
1074
1083
variable numEntries, numLayers
@@ -1597,6 +1606,7 @@ Function/DF TP_PrepareAnalysisDF(string device, STRUCT TPAnalysisInput &tpInput)
1597
1606
ASYNC_AddParam ( threadDF, var = tpInput. activeADCs)
1598
1607
ASYNC_AddParam ( threadDF, var = tpInput. timeStamp)
1599
1608
ASYNC_AddParam ( threadDF, var = tpInput. timeStampUTC)
1609
+ ASYNC_AddParam ( threadDF, var = tpInput. cycleId)
1600
1610
1601
1611
return threadDF
1602
1612
End
0 commit comments