Skip to content

Commit e504a25

Browse files
authored
Merge pull request #1031 from AllenInstitute/feature/1031-pressure-sealed-message
Publish seal formation and more pressure entries in TPStorage
2 parents 9f583fb + 7a56177 commit e504a25

10 files changed

+178
-25
lines changed

Packages/MIES/MIES_AcquisitionStateHandling.ipf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ Function AS_GetSweepNumber(string panelTitle)
149149
switch(acqState)
150150
case AS_INACTIVE:
151151
case AS_EARLY_CHECK:
152-
ASSERT(0, "Can not query the sweep number without data acqisition running")
153-
break
152+
// early return as this is not a valid sweep number
153+
return NaN
154154
case AS_PRE_DAQ:
155155
case AS_PRE_SWEEP_CONFIG:
156156
case AS_PRE_SWEEP:

Packages/MIES/MIES_Constants.ipf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ Constant ANALYSISBROWSER_PANEL_VERSION = 1
633633
/// - Changed names of entries
634634
/// - Changed units or meaning of entries
635635
/// - New/Changed layers of entries
636-
Constant LABNOTEBOOK_VERSION = 47
636+
Constant LABNOTEBOOK_VERSION = 48
637637

638638
/// Version of the stimset wave note
639639
Constant STIMSET_NOTE_VERSION = 7
@@ -1566,7 +1566,14 @@ Constant LBN_TEXTUAL_KEYS = 0x4
15661566
Constant LBN_TEXTUAL_VALUES = 0x8
15671567
/// @}
15681568

1569-
StrConstant PRESSURE_FILTER = "pressure:state"
1569+
StrConstant PRESSURE_STATE_FILTER = "pressure:state"
1570+
StrConstant PRESSURE_SEALED_FILTER = "pressure:sealed"
15701571

15711572
/// which is sufficient to represent each sample point time with a distinctive number up to rates of 10 MHz.
15721573
Constant EPOCHTIME_PRECISION = 7
1574+
1575+
/// @name Possible cell state values
1576+
/// @anchor CellStateValues
1577+
/// @{
1578+
Constant TPSTORAGE_SEALED = 0x1
1579+
/// @}

Packages/MIES/MIES_ForeignFunctionInterface.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ End
7676
/// @sa FFI_GetJSONTemplate
7777
Function/WAVE FFI_GetAvailableMessageFilters()
7878

79-
Make/FREE/T wv = {ZeroMQ_HEARTBEAT, IVS_PUB_FILTER, PRESSURE_FILTER}
79+
Make/FREE/T wv = {ZeroMQ_HEARTBEAT, IVS_PUB_FILTER, PRESSURE_STATE_FILTER, PRESSURE_SEALED_FILTER}
8080

8181
Note/K wv "Heartbeat is sent every 5 seconds."
8282

Packages/MIES/MIES_PressureControl.ipf

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ static Function P_FindLastSetEntry(WAVE wv, variable row, variable col, string n
196196
return NaN
197197
End
198198

199+
static Function P_AddSealedEntryToTPStorage(string panelTitle, variable headstage)
200+
variable count
201+
202+
if(!P_ValidatePressureSetHeadstage(panelTitle, headstage) || !P_IsHSActiveAndInVClamp(panelTitle, headstage))
203+
return NaN
204+
endif
205+
206+
WAVE TPStorage = GetTPStorage(panelTitle)
207+
208+
count = GetNumberFromWaveNote(TPStorage, NOTE_INDEX)
209+
210+
TPStorage[count][headstage][%CellState] = TPSTORAGE_SEALED
211+
212+
SetNumberInWaveNote(TPStorage, NOTE_INDEX, ++count)
213+
End
214+
199215
static Function P_PublishPressureMethodChange(string panelTitle, variable headstage, variable oldMethod, variable newMethod)
200216

201217
variable jsonID, err
@@ -216,7 +232,7 @@ static Function P_PublishPressureMethodChange(string panelTitle, variable headst
216232
try
217233
ClearRTError()
218234
#if exists("zeromq_pub_send")
219-
zeromq_pub_send(PRESSURE_FILTER, payload); AbortOnRTE
235+
zeromq_pub_send(PRESSURE_STATE_FILTER, payload); AbortOnRTE
220236
#else
221237
ASSERT(0, "ZeroMQ XOP not present")
222238
#endif
@@ -226,6 +242,29 @@ static Function P_PublishPressureMethodChange(string panelTitle, variable headst
226242
endtry
227243
End
228244

245+
static Function P_PublishSealedState(string panelTitle, variable headstage)
246+
variable jsonID, err
247+
string payload
248+
249+
jsonID = FFI_GetJSONTemplate(panelTitle, headstage)
250+
JSON_AddBoolean(jsonID, "/sealed", 1)
251+
252+
payload = JSON_Dump(jsonID)
253+
JSON_Release(jsonID)
254+
255+
try
256+
ClearRTError()
257+
#if exists("zeromq_pub_send")
258+
zeromq_pub_send(PRESSURE_SEALED_FILTER, payload); AbortOnRTE
259+
#else
260+
ASSERT(0, "ZeroMQ XOP not present")
261+
#endif
262+
catch
263+
err = ClearRTError()
264+
BUG("Could not publish pressure seal state " + num2str(err))
265+
endtry
266+
End
267+
229268
/// @brief Sets the pressure to atmospheric
230269
static Function P_MethodAtmospheric(panelTitle, headstage)
231270
string panelTitle
@@ -306,6 +345,8 @@ static Function P_MethodSeal(panelTitle, headStage)
306345
// apply holding potential of SEAL_POTENTIAL
307346
P_UpdateVcom(panelTitle, SEAL_POTENTIAL, headStage)
308347
print "Seal on head stage:", headstage
348+
P_PublishSealedState(panelTitle, headstage)
349+
P_AddSealedEntryToTPStorage(panelTitle, headstage)
309350
else // no seal, start, hold, or increment negative pressure
310351
// if there is no neg pressure, apply starting pressure.
311352
access = P_GetUserAccess(panelTitle, headStage, PRESSURE_METHOD_SEAL)

Packages/MIES/MIES_Utilities.ipf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ threadsafe Function/DF createDFWithAllParents(dataFolder)
699699
string dataFolder
700700

701701
variable i, numItems
702-
string partialPath
702+
string partialPath, component
703703
DFREF dfr = $dataFolder
704704

705705
if(DataFolderRefStatus(dfr))
@@ -711,8 +711,10 @@ threadsafe Function/DF createDFWithAllParents(dataFolder)
711711
// i=1 because we want to skip root, as this exists always
712712
numItems = ItemsInList(dataFolder,":")
713713
for(i=1; i < numItems ; i+=1)
714-
partialPath += ":"
715-
partialPath += StringFromList(i,dataFolder,":")
714+
component = StringFromList(i,dataFolder,":")
715+
ASSERT_TS(IsValidObjectName(component), "dataFolder must follow strict object naming rules.")
716+
717+
partialPath += ":" + component
716718
if(!DataFolderExists(partialPath))
717719
NewDataFolder $partialPath
718720
endif

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,18 +2295,19 @@ End
22952295
/// - 21: UserPressureTimeStampUTC timestamp since Igor Pro epoch in UTC where
22962296
/// the user pressure was acquired
22972297
/// - 22: TPMarker unique number identifying this set of TPs
2298+
/// - 23: Cell state: Pressure control values defining the cell state, one of @ref CellStateValues
22982299
Function/Wave GetTPStorage(panelTitle)
22992300
string panelTitle
23002301

23012302
dfref dfr = GetDeviceTestPulse(panelTitle)
2302-
variable versionOfNewWave = 12
2303+
variable versionOfNewWave = 13
23032304

23042305
WAVE/Z/SDFR=dfr/D wv = TPStorage
23052306

23062307
if(ExistsWithCorrectLayoutVersion(wv, versionOfNewWave))
23072308
return wv
23082309
elseif(WaveExists(wv))
2309-
Redimension/N=(-1, NUM_HEADSTAGES, 23)/D wv
2310+
Redimension/N=(-1, NUM_HEADSTAGES, 24)/D wv
23102311

23112312
if(WaveVersionIsSmaller(wv, 10))
23122313
wv[][][17] = NaN
@@ -2315,8 +2316,11 @@ Function/Wave GetTPStorage(panelTitle)
23152316
if(WaveVersionIsSmaller(wv, 11))
23162317
wv[][][22] = NaN
23172318
endif
2319+
if(WaveVersionIsSmaller(wv, 13))
2320+
wv[][][23] = NaN
2321+
endif
23182322
else
2319-
Make/N=(MINIMUM_WAVE_SIZE_LARGE, NUM_HEADSTAGES, 23)/D dfr:TPStorage/Wave=wv
2323+
Make/N=(MINIMUM_WAVE_SIZE_LARGE, NUM_HEADSTAGES, 24)/D dfr:TPStorage/Wave=wv
23202324

23212325
wv = NaN
23222326

@@ -2348,6 +2352,7 @@ Function/Wave GetTPStorage(panelTitle)
23482352
SetDimLabel LAYERS, 20, UserPressureType , wv
23492353
SetDimLabel LAYERS, 21, UserPressureTimeStampUTC , wv
23502354
SetDimLabel LAYERS, 22, TPMarker , wv
2355+
SetDimLabel LAYERS, 23, CellState , wv
23512356

23522357
SetNumberInWaveNote(wv, AUTOBIAS_LAST_INVOCATION_KEY, 0)
23532358
SetNumberInWaveNote(wv, DIMENSION_SCALING_LAST_INVOC, 0)

Packages/Testing-MIES/UTF_HelperFunctions.ipf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,21 @@ Function AdditionalExperimentCleanup()
5656
NVAR bugCount = $GetBugCount()
5757
KillVariables bugCount
5858
End
59+
60+
Function WaitForPubSubHeartbeat()
61+
variable i, foundHeart
62+
string msg, filter
63+
64+
// wait until we get the first heartbeat
65+
for(i = 0; i < 200; i += 1)
66+
msg = zeromq_sub_recv(filter)
67+
if(!cmpstr(filter, ZEROMQ_HEARTBEAT))
68+
PASS()
69+
return NaN
70+
endif
71+
72+
Sleep/S 0.1
73+
endfor
74+
75+
FAIL()
76+
End

Packages/Testing-MIES/UTF_IVSCC.ipf

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,12 @@ End
2121

2222
Function CheckThatPublishingWorks()
2323
string msg, filter, expected, actual
24-
variable found, i, jsonID, foundHeart
24+
variable found, i, jsonID
2525

2626
zeromq_sub_add_filter("")
2727
zeromq_sub_connect("tcp://127.0.0.1:" + num2str(ZEROMQ_BIND_PUB_PORT))
2828

29-
// wait until we get the first heartbeat
30-
for(i = 0; i < 200; i += 1)
31-
msg = zeromq_sub_recv(filter)
32-
if(!cmpstr(filter, ZeroMQ_HEARTBEAT))
33-
foundHeart += 1
34-
break
35-
endif
36-
37-
Sleep/S 0.1
38-
endfor
39-
40-
CHECK(foundHeart > 0)
29+
WaitForPubSubHeartbeat()
4130

4231
MIES_IVSCC#IVS_PublishQCState(123, "some text")
4332

Packages/Testing-MIES/UTF_Main.ipf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "UTF_WaveBuilder"
2424
#include "UTF_WaveBuilderRegression"
2525
#include "UTF_WaveVersioning"
26+
#include "UTF_Pressure"
2627

2728
// include examples here so that these are compile tested as well
2829
#include "example-stimulus-set-api"
@@ -62,6 +63,7 @@ Function RunWithOpts([string testcase, string testsuite, variable allowdebug])
6263
list = AddListItem("UTF_Labnotebook.ipf", list, ";", inf)
6364
list = AddListItem("UTF_Macros.ipf", list, ";", inf)
6465
list = AddListItem("UTF_PGCSetAndActivateControl.ipf", list, ";", inf)
66+
list = AddListItem("UTF_Pressure.ipf", list, ";", inf)
6567
list = AddListItem("UTF_StimsetAPI.ipf", list, ";", inf)
6668
list = AddListItem("UTF_SweepFormula.ipf", list, ";", inf)
6769
list = AddListItem("UTF_TraceUserData.ipf", list, ";", inf)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#pragma TextEncoding = "UTF-8"
2+
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
3+
#pragma rtFunctionErrors=1
4+
#pragma ModuleName=PressureTests
5+
6+
static Function TEST_CASE_BEGIN_OVERRIDE(string testname)
7+
8+
StartZeroMQSockets(forceRestart = 1)
9+
10+
zeromq_sub_add_filter("")
11+
zeromq_sub_connect("tcp://127.0.0.1:" + num2str(ZEROMQ_BIND_PUB_PORT))
12+
End
13+
14+
static Function TEST_CASE_END_OVERRIDE(string testname)
15+
16+
StartZeroMQSockets(forceRestart = 1)
17+
zeromq_sub_add_filter("")
18+
End
19+
20+
static Function CheckPressureStatePublishing()
21+
string device, msg, filter, expected, actual
22+
variable headstage, i, jsonID
23+
24+
WaitForPubSubHeartbeat()
25+
26+
device = "my_device"
27+
headstage = 0
28+
29+
MIES_P#P_PublishPressureMethodChange(device, headstage, PRESSURE_METHOD_ATM, PRESSURE_METHOD_APPROACH)
30+
31+
for(i = 0; i < 100; i += 1)
32+
msg = zeromq_sub_recv(filter)
33+
34+
if(!cmpstr(filter, PRESSURE_STATE_FILTER))
35+
break
36+
endif
37+
38+
Sleep/S 0.1
39+
endfor
40+
41+
expected = PRESSURE_STATE_FILTER
42+
actual = filter
43+
CHECK_EQUAL_STR(actual, expected)
44+
45+
jsonID = JSON_Parse(msg)
46+
47+
expected = MIES_P#P_PressureMethodToString(PRESSURE_METHOD_ATM)
48+
actual = JSON_GetString(jsonID, "/pressure method/old")
49+
CHECK_EQUAL_STR(actual, expected)
50+
51+
expected = MIES_P#P_PressureMethodToString(PRESSURE_METHOD_APPROACH)
52+
actual = JSON_GetString(jsonID, "/pressure method/new")
53+
CHECK_EQUAL_STR(actual, expected)
54+
55+
JSON_Release(jsonID)
56+
End
57+
58+
static Function CheckPressureSealPublishing()
59+
string device, msg, filter, expected, actual
60+
variable headstage, i, jsonID, value
61+
62+
WaitForPubSubHeartbeat()
63+
64+
device = "my_device"
65+
headstage = 0
66+
67+
MIES_P#P_PublishSealedState(device, headstage)
68+
69+
for(i = 0; i < 100; i += 1)
70+
msg = zeromq_sub_recv(filter)
71+
72+
if(!cmpstr(filter, PRESSURE_SEALED_FILTER))
73+
break
74+
endif
75+
76+
Sleep/S 0.1
77+
endfor
78+
79+
expected = PRESSURE_SEALED_FILTER
80+
actual = filter
81+
CHECK_EQUAL_STR(actual, expected)
82+
83+
jsonID = JSON_Parse(msg)
84+
85+
value = JSON_GetVariable(jsonID, "/sealed")
86+
CHECK_EQUAL_VAR(value, 1)
87+
88+
JSON_Release(jsonID)
89+
End

0 commit comments

Comments
 (0)