| THM1176InstrumentManager 1.2 Qt Object abstraction for Metrolab THM1176

Loading...
Searching...
No Matches
THM1176IM_Test02_Measure.cpp
Go to the documentation of this file.
1// Copyright (c) 2020 Metrolab Technology S.A., Geneva, Switzerland (www.metrolab.com)
2// See the included file LICENSE.txt for the licensing conditions.
3
7
8#include <thread>
9#include <chrono>
10#include <ctime>
11#include <iostream>
12
13#include <QtTest>
14#include <QSignalSpy>
15
16#include "CTHM1176InstrumentManager.h"
17
18 using namespace MTL;
19
20#define THM1176_PROMPT_TIME 10 // s
21#define THM1176_BOOT_N_SCAN_TIME 15000 // ms
22#define THM1176_CONNECT_TIME 5000 // ms
23#define THM1176_CHANGE_PARM_TIME 1000 // ms
24#define THM1176_RESET_TIME 1000 // ms
25#define THM1176_MEASURE_TIME 20000 // ms
26#define THM1176_CALIBRATE_TIME 10000 // ms
27
28 static const F64 THM1176_IMMEDIATE_TIME_PER_ACQ (1.0281823091218700E+05); // ns
29 static const F64 THM1176_IMMEDIATE_TIME_PER_MEAS (4.4532792007542600E+04); // ns
30
31 static CTHM1176InstrumentManager Manager;
32
33//----------------------------------------------------------------------//
34// Utility functions //
35//----------------------------------------------------------------------//
36 static void PromptAndWait(std::string Prompt)
37{
38 std::string l_Space = ("" == Prompt) ? "" : " ";
39 std::string l_Message = ">>> " + Prompt + l_Space + "(Will continue in " + std::to_string(THM1176_PROMPT_TIME) + " seconds) <<<";
40 QWARN(" ");
41 QWARN(l_Message.c_str());
42 QThread::currentThread()->sleep(THM1176_PROMPT_TIME);
43}
44
45 F64 PeriodOfImmediateTrigger (sAveraging<uParm> Averaging)
46{
47 return 1E-9 * (THM1176_IMMEDIATE_TIME_PER_MEAS + Averaging.NoPoints * THM1176_IMMEDIATE_TIME_PER_ACQ);
48}
49
50//----------------------------------------------------------------------//
51// Test class definition //
52//----------------------------------------------------------------------//
53 class THM1176IM_Test02_Measure: public QObject
54{
55 Q_OBJECT
56
57 public:
58 THM1176IM_Test02_Measure();
59 ~THM1176IM_Test02_Measure();
60
61 private:
62 QList<QVariant> m_Arguments;
63
64 CResourceList m_ResourceList;
65 tResourceName m_THM1176Selected;
66 sIdentifier m_Identification;
67 CFluxList m_RangeList;
68 CTHM1176UnitsList m_UnitsList;
69 CDivisorList m_DivisorList;
70 sAveraging<sBoundedParm> m_AveragingBounds;
71 sInputTrigger<sBoundedParm> m_TriggerBounds;
72 sRange<sBoundedParm> m_RangeBounds;
73
74 sAveraging<uParm> m_AveragingParms;
75 sInputTrigger<uParm> m_Trigger;
76 sArbitraryMeasurements m_OutputSelect;
77 bool m_SleepParm;
78 eTHM1176Units m_Units;
79 sRange<uParm> m_RangeParms;
80 eCommunicationFormat m_CommFormat;
81
82 eTHM1176OperatingMode m_OperatingMode;
83 CMeasurement m_Measurement;
84 CErrorList m_LatestErrors;
85
86 private slots:
87
89 void initTestCase(void);
90
92 void cleanupTestCase(void);
93
95 void TestSetOperatingMode_Immediate(void);
96
98 void TestSetOperatingMode_Triggered(void);
99
101 void TestSetOperatingMode_Timed(void);
102
104 void TestSetOperatingMode_TimedLong(void);
105
107 void TestSetOperatingMode_ImmediateContinuous(void);
108
110 void TestSetOperatingMode_TimedContinuous(void);
111
113 void TestSetOperatingMode_TriggeredContinuous(void);
114
116 void TestSetOperatingMode_CalibrateRestore(void);
117
119 void TestUtilities(void);
120
121};
122
123//----------------------------------------------------------------------//
124// Test case constructor and destructor //
125//----------------------------------------------------------------------//
126 THM1176IM_Test02_Measure::THM1176IM_Test02_Measure()
127{
128
129}
130
131 THM1176IM_Test02_Measure::~THM1176IM_Test02_Measure()
132{
133
134}
135
136//----------------------------------------------------------------------//
137// Test case initialization and cleanup //
138//----------------------------------------------------------------------//
139 void THM1176IM_Test02_Measure::initTestCase(void)
140{
141 QList<QVariant> m_Arguments;
142
143 // Start the Instrument Manager.
144 Manager.Start();
145
146 // Create Signal Spies to retrieve instrument list, instrument info, parameters and possible errors.
147 QSignalSpy l_NotifyInstrumentListSpy(&Manager, SIGNAL(NotifyInstrumentList(CResourceList)));
148 QSignalSpy l_NotifyCurrentInstrumentSpy(&Manager, SIGNAL(NotifyCurrentInstrument(tResourceName)));
149
150 QSignalSpy l_NotifyIdentificationSpy(&Manager, SIGNAL(NotifyIdentification(sIdentifier)));
151 QSignalSpy l_NotifyRangeListSpy(&Manager, SIGNAL(NotifyRangeList(CFluxList)));
152 QSignalSpy l_NotifyUnitsListSpy(&Manager, SIGNAL(NotifyUnitsList(CTHM1176UnitsList)));
153 QSignalSpy l_NotifyDivisorListSpy(&Manager, SIGNAL(NotifyDivisorList(CDivisorList)));
154 QSignalSpy l_NotifyAveragingParmBoundsSpy(&Manager, SIGNAL(NotifyAveragingParmBounds(sAveraging<sBoundedParm>)));
155 QSignalSpy l_NotifyTriggerParmBoundsSpy(&Manager, SIGNAL(NotifyTriggerParmBounds(sInputTrigger<sBoundedParm>)));
156 QSignalSpy l_NotifyRangeParmBoundsSpy(&Manager, SIGNAL(NotifyRangeParmBounds(sRange<sBoundedParm>)));
157
158 QSignalSpy l_NotifyAveragingParmsSpy(&Manager, SIGNAL(NotifyAveragingParms(sAveraging<uParm>)));
159 QSignalSpy l_NotifyTriggerParmsSpy(&Manager, SIGNAL(NotifyTriggerParms(sInputTrigger<uParm>)));
160 QSignalSpy l_NotifyOutputSelectSpy(&Manager, SIGNAL(NotifyOutputSelect(sArbitraryMeasurements)));
161 QSignalSpy l_NotifySleepParmSpy(&Manager, SIGNAL(NotifySleepParm(bool)));
162 QSignalSpy l_NotifyUnitsSpy(&Manager, SIGNAL(NotifyUnits(eTHM1176Units)));
163 QSignalSpy l_NotifyRangeParmsSpy(&Manager, SIGNAL(NotifyRangeParms(sRange<uParm>)));
164 QSignalSpy l_NotifyCommFormatSpy(&Manager, SIGNAL(NotifyCommFormat(eCommunicationFormat)));
165
166 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
167 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
168
169 // Plug in the THM.
170 PromptAndWait("Please plug in a THM");
171 l_NotifyInstrumentListSpy.wait(THM1176_BOOT_N_SCAN_TIME);
172 QCOMPARE(l_NotifyInstrumentListSpy.count(), 1);
173 m_Arguments = l_NotifyInstrumentListSpy.takeFirst();
174 m_ResourceList = qvariant_cast<CResourceList>(m_Arguments.at(0));
175 QCOMPARE(m_ResourceList.size(), 1ul);
176
177 // Select the THM.
178 m_THM1176Selected = m_ResourceList[0];
179 Manager.SetCurrentInstrument(m_THM1176Selected);
180
181 // Wait for it to become Idle.
182 l_NotifyOperatingModeSpy.wait(THM1176_CONNECT_TIME);
183 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
184 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
185 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
186 QCOMPARE(m_OperatingMode, kTHM1176Idle);
187
188 // Retrieve the current instrument.
189 QCOMPARE(l_NotifyCurrentInstrumentSpy.count(), 1);
190 m_Arguments = l_NotifyCurrentInstrumentSpy.takeFirst();
191 m_THM1176Selected = qvariant_cast<tResourceName>(m_Arguments.at(0));
192 QCOMPARE(m_THM1176Selected, m_ResourceList[0]);
193
194 // Retrieve instrument information and parameter bounds for this THM.
195 QCOMPARE(l_NotifyIdentificationSpy.count(), 1);
196 m_Arguments = l_NotifyIdentificationSpy.takeFirst();
197 m_Identification = qvariant_cast<sIdentifier>(m_Arguments.at(0));
198 QVERIFY(!m_Identification.Manufacturer.empty() && !m_Identification.Model.empty() && m_Identification.SerialNumber != 0);
199
200 QCOMPARE(l_NotifyRangeListSpy.count(), 1);
201 m_Arguments = l_NotifyRangeListSpy.takeFirst();
202 m_RangeList = qvariant_cast<CFluxList>(m_Arguments.at(0));
203 QVERIFY(!m_RangeList.empty());
204
205 QCOMPARE(l_NotifyUnitsListSpy.count(), 1);
206 m_Arguments = l_NotifyUnitsListSpy.takeFirst();
207 m_UnitsList = qvariant_cast<CTHM1176UnitsList>(m_Arguments.at(0));
208 QVERIFY(!m_UnitsList.empty());
209
210 QCOMPARE(l_NotifyDivisorListSpy.count(), 1);
211 m_Arguments = l_NotifyDivisorListSpy.takeFirst();
212 m_DivisorList = qvariant_cast<CDivisorList>(m_Arguments.at(0));
213 QVERIFY(!m_DivisorList.empty());
214
215 QCOMPARE(l_NotifyAveragingParmBoundsSpy.count(), 1);
216 m_Arguments = l_NotifyAveragingParmBoundsSpy.takeFirst();
217 m_AveragingBounds = qvariant_cast<sAveraging<sBoundedParm>>(m_Arguments.at(0));
218 QVERIFY(m_AveragingBounds.NoPoints.Val != 0 && m_AveragingBounds.NoPoints.Min != 0 &&
219 m_AveragingBounds.NoPoints.Max != 0 && m_AveragingBounds.NoPoints.Def != 0);
220
221 QCOMPARE(l_NotifyTriggerParmBoundsSpy.count(), 1);
222 m_Arguments = l_NotifyTriggerParmBoundsSpy.takeFirst();
223 m_TriggerBounds = qvariant_cast<sInputTrigger<sBoundedParm>>(m_Arguments.at(0));
224 QVERIFY(m_TriggerBounds.Period_s.Val != 0 && m_TriggerBounds.Period_s.Min != 0 &&
225 m_TriggerBounds.Period_s.Max != 0 && m_TriggerBounds.Period_s.Def != 0 &&
226 m_TriggerBounds.Count.Val != 0 && m_TriggerBounds.Count.Min != 0 &&
227 m_TriggerBounds.Count.Max != 0 && m_TriggerBounds.Count.Def != 0);
228
229 QCOMPARE(l_NotifyRangeParmBoundsSpy.count(), 1);
230 m_Arguments = l_NotifyRangeParmBoundsSpy.takeFirst();
231 m_RangeBounds = qvariant_cast<sRange<sBoundedParm>>(m_Arguments.at(0));
232 QVERIFY(m_RangeBounds.Range.Val != 0 && m_RangeBounds.Range.Min != 0 &&
233 m_RangeBounds.Range.Max != 0 && m_RangeBounds.Range.Def != 0);
234
235 // Retrieve the current parameters for this instrument.
236 QCOMPARE(l_NotifyAveragingParmsSpy.count(), 1);
237 m_Arguments = l_NotifyAveragingParmsSpy.takeFirst();
238 m_AveragingParms = qvariant_cast<sAveraging<uParm>>(m_Arguments.at(0));
239 QVERIFY(m_AveragingParms.NoPoints > 0);
240
241 QCOMPARE(l_NotifyTriggerParmsSpy.count(), 1);
242 m_Arguments = l_NotifyTriggerParmsSpy.takeFirst();
243 m_Trigger = qvariant_cast<sInputTrigger<uParm>>(m_Arguments.at(0));
244 QVERIFY(m_Trigger.Period_s > 0. && m_Trigger.Count > 0);
245
246 QCOMPARE(l_NotifyOutputSelectSpy.count(), 1);
247 m_Arguments = l_NotifyOutputSelectSpy.takeFirst();
248 m_OutputSelect = qvariant_cast<sArbitraryMeasurements>(m_Arguments.at(0));
249
250 QCOMPARE(l_NotifySleepParmSpy.count(), 1);
251 m_Arguments = l_NotifySleepParmSpy.takeFirst();
252 m_SleepParm = qvariant_cast<bool>(m_Arguments.at(0));
253
254 QCOMPARE(l_NotifyUnitsSpy.count(), 1);
255 m_Arguments = l_NotifyUnitsSpy.takeFirst();
256 m_Units = qvariant_cast<eTHM1176Units>(m_Arguments.at(0));
257
258 QCOMPARE(l_NotifyRangeParmsSpy.count(), 1);
259 m_Arguments = l_NotifyRangeParmsSpy.takeFirst();
260 m_RangeParms = qvariant_cast<sRange<uParm>>(m_Arguments.at(0));
261
262 QCOMPARE(l_NotifyCommFormatSpy.count(), 1);
263 m_Arguments = l_NotifyCommFormatSpy.takeFirst();
264 m_CommFormat = qvariant_cast<eCommunicationFormat>(m_Arguments.at(0));
265
266 // We expect no errors.
267 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
268
269 std::cout << "- Connected to " + m_Identification.Model + ", S/N " + std::to_string(m_Identification.SerialNumber) << std::endl;
270
271} // THM1176IM_Test02_Measure::initTestCase
272
273 void THM1176IM_Test02_Measure::cleanupTestCase(void)
274{
275 Manager.Stop();
276}
277
296 void THM1176IM_Test02_Measure::TestSetOperatingMode_Immediate(void)
297{
298 // Create Signal Spies to retrieve measurement result, operating mode, and possible errors.
299 QSignalSpy l_NotifyMeasurementSpy(&Manager, SIGNAL(NotifyMeasurement(CMeasurement)));
300 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
301 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
302
303 // - Emit SetOperatingMode = Reset:
304 // - Should receive NotifyOperatingMode = Reset, Idle
305 Manager.SetOperatingMode(kTHM1176Reset);
306
307 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
308 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
309 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
310 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
311 QCOMPARE(m_OperatingMode, kTHM1176Reset);
312 if (l_NotifyOperatingModeSpy.count() <= 0)
313 {
314 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
315 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
316 }
317 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
318 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
319 QCOMPARE(m_OperatingMode, kTHM1176Idle);
320
321 m_AveragingParms = Manager.GetAveragingParms();
322 m_Trigger = Manager.GetTriggerParms();
323 m_OutputSelect = Manager.GetOutputSelect();
324 m_SleepParm = Manager.GetSleepParm();
325 m_Units = Manager.GetUnits();
326 m_RangeParms = Manager.GetRangeParms();
327 m_CommFormat = Manager.GetCommFormat();
328
329 std::cout << "- Reset " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
330
331 // - Set SetTriggerParms to Immediate,1:
332 // - Should not receive NotifyErrorList
333 m_Trigger.Source = kInputTrigSrcImmediate;
334 m_Trigger.Count = 1;
335 Manager.SetTriggerParms(m_Trigger);
336
337 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
338 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
339
340 // - Emit SetOperatingMode = Measure:
341 // - Should receive NotifyOperatingMode = Measure, Idle
342 // - Should receive NotifyMeasurement length 1
343 // - Should not receive NotifyErrorList
344 Manager.SetOperatingMode(kTHM1176Measure);
345
346 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
347 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
348 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
349 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
350 QCOMPARE(m_OperatingMode, kTHM1176Measure);
351 if (l_NotifyOperatingModeSpy.count() <= 0)
352 {
353 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
354 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
355 }
356 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
357 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
358 QCOMPARE(m_OperatingMode, kTHM1176Idle);
359
360 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
361 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
362 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
363 QCOMPARE(m_Measurement.Bx.size(), 1ul);
364 QCOMPARE(m_Measurement.By.size(), 1ul);
365 QCOMPARE(m_Measurement.Bz.size(), 1ul);
366 QCOMPARE(m_Measurement.Units, MTL::kT);
367 QVERIFY(m_Measurement.Temp != 0);
368 QCOMPARE(m_Measurement.TimestampList.size(), 1ul);
369 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
370 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
371 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
372 QCOMPARE(m_Measurement.TriggerParms.Period_s, PeriodOfImmediateTrigger(m_AveragingParms));
373 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
374 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
375 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
376 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
377 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
378 QCOMPARE(m_Measurement.Warnings.size(), 0ul);
379
380 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
381
382 std::cout << "- Measured Immediate,1: B = (" << m_Measurement.Bx[0] << ", " << m_Measurement.By[0] << ", " << m_Measurement.Bz[0] << ") [T], "
383 "Temp = " << m_Measurement.Temp << ", Timestamp = " << m_Measurement.TimestampList[0] << std::endl;
384
385 // - Set SetTriggerParms to Immediate,10:
386 // - Should not receive NotifyErrorList
387 m_Trigger.Source = kInputTrigSrcImmediate;
388 m_Trigger.Count = 10;
389 Manager.SetTriggerParms(m_Trigger);
390
391 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
392 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
393
394 // - Set SetOutputSelect to Bx, no By, Bz, no T, Time, 10:
395 // - Should not receive NotifyErrorList
396 m_OutputSelect.Bx = true;
397 m_OutputSelect.By = false;
398 m_OutputSelect.Bz = true;
399 m_OutputSelect.Temperature = false;
400 m_OutputSelect.Timestamp = true;
401 m_OutputSelect.NoMeasurements = 10;
402 Manager.SetOutputSelect(m_OutputSelect);
403
404 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
405 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
406
407 // - Emit SetOperatingMode = Measure:
408 // - Should receive NotifyOperatingMode = Measure, Idle
409 // - Should receive NotifyMeasurement as requested
410 // - Should not receive NotifyErrorList
411 Manager.SetOperatingMode(kTHM1176Measure);
412
413 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
414 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
415 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
416 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
417 QCOMPARE(m_OperatingMode, kTHM1176Measure);
418 if (l_NotifyOperatingModeSpy.count() <= 0)
419 {
420 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
421 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
422 }
423 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
424 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
425 QCOMPARE(m_OperatingMode, kTHM1176Idle);
426
427 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
428 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
429 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
430 QCOMPARE(m_Measurement.Bx.size(), 10ul);
431 QCOMPARE(m_Measurement.By.size(), 0ul);
432 QCOMPARE(m_Measurement.Bz.size(), 10ul);
433 QCOMPARE(m_Measurement.Units, MTL::kT);
434 QVERIFY(m_Measurement.Temp == 0);
435 QCOMPARE(m_Measurement.TimestampList.size(), 10ul);
436 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
437 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
438 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
439 QCOMPARE(m_Measurement.TriggerParms.Period_s, PeriodOfImmediateTrigger(m_AveragingParms));
440 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
441 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
442 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
443 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
444 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
445 QCOMPARE(m_Measurement.Warnings.size(), 1ul);
446 QCOMPARE(m_Measurement.Warnings[0].Code, THM1176_NO_ANGLE_CORRECTION_CODE);
447
448 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
449
450 std::cout << "- Measured Immediate,10: B[] = (" << m_Measurement.Bx[0] << "..., N/A , " << m_Measurement.Bz[0] << "...) [T], "
451 "Temp = N/A , Timestamp = " << m_Measurement.TimestampList[0] << std::endl;
452
453} // THM1176IM_Test02_Measure::TestSetOperatingMode_Immediate
454
488 void THM1176IM_Test02_Measure::TestSetOperatingMode_Triggered(void)
489{
490 // Create Signal Spies to retrieve measurement result, operating mode, and possible errors.
491 QSignalSpy l_NotifyMeasurementSpy(&Manager, SIGNAL(NotifyMeasurement(CMeasurement)));
492 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
493 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
494
495 // - Emit SetOperatingMode = Reset:
496 // - Should receive NotifyOperatingMode = Reset, Idle
497 Manager.SetOperatingMode(kTHM1176Reset);
498
499 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
500 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
501 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
502 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
503 QCOMPARE(m_OperatingMode, kTHM1176Reset);
504 if (l_NotifyOperatingModeSpy.count() <= 0)
505 {
506 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
507 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
508 }
509 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
510 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
511 QCOMPARE(m_OperatingMode, kTHM1176Idle);
512
513 m_AveragingParms = Manager.GetAveragingParms();
514 m_Trigger = Manager.GetTriggerParms();
515 m_OutputSelect = Manager.GetOutputSelect();
516 m_SleepParm = Manager.GetSleepParm();
517 m_Units = Manager.GetUnits();
518 m_RangeParms = Manager.GetRangeParms();
519 m_CommFormat = Manager.GetCommFormat();
520
521 std::cout << "- Reset " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
522
523 // - Set SetTriggerParms to Triggered,1:
524 // - Should not receive NotifyErrorList
525 m_Trigger.Source = kInputTrigSrcBus;
526 m_Trigger.Count = 1;
527 Manager.SetTriggerParms(m_Trigger);
528
529 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
530 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
531
532 // - Emit SetOperatingMode = Measure:
533 // - Should receive NotifyOperatingMode = Measure
534 // - Should not receive NotifyErrorList
535 Manager.SetOperatingMode(kTHM1176Measure);
536
537 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
538 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
539 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
540 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
541 QCOMPARE(m_OperatingMode, kTHM1176Measure);
542
543 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
544
545 // - Emit SendTrigger:
546 // - Should receive NotifyOperatingMode = Idle
547 // - Should receive NotifyMeasurement length 1
548 // - Should not receive NotifyErrorList
549 QThread::currentThread()->msleep(100);
550 Manager.SendTrigger();
551
552 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
553 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
554 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
555 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
556 QCOMPARE(m_OperatingMode, kTHM1176Idle);
557
558 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
559 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
560 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
561 QCOMPARE(m_Measurement.Bx.size(), 1ul);
562 QCOMPARE(m_Measurement.By.size(), 1ul);
563 QCOMPARE(m_Measurement.Bz.size(), 1ul);
564 QCOMPARE(m_Measurement.Units, MTL::kT);
565 QVERIFY(m_Measurement.Temp != 0);
566 QCOMPARE(m_Measurement.TimestampList.size(), 1ul);
567 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
568 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
569 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
570 QCOMPARE(m_Measurement.TriggerParms.Period_s, 0.);
571 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
572 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
573 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
574 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
575 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
576 QCOMPARE(m_Measurement.Warnings.size(), 0ul);
577
578 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
579
580 std::cout << "- Measured Triggered,1: B = (" << m_Measurement.Bx[0] << ", " << m_Measurement.By[0] << ", " << m_Measurement.Bz[0] << ") [T], "
581 "Temp = " << m_Measurement.Temp << ", Timestamp = " << m_Measurement.TimestampList[0] << std::endl;
582
583 // - Set SetTriggerParms to Triggered,10:
584 // - Should not receive NotifyErrorList
585 m_Trigger.Source = kInputTrigSrcBus;
586 m_Trigger.Count = 10;
587 Manager.SetTriggerParms(m_Trigger);
588
589 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
590 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
591
592 // - Set SetOutputSelect to Bx, no By, Bz, no T, Time, 10:
593 // - Should not receive NotifyErrorList
594 m_OutputSelect.Bx = true;
595 m_OutputSelect.By = false;
596 m_OutputSelect.Bz = true;
597 m_OutputSelect.Temperature = false;
598 m_OutputSelect.Timestamp = true;
599 m_OutputSelect.NoMeasurements = 10;
600 Manager.SetOutputSelect(m_OutputSelect);
601
602 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
603 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
604
605 // - Emit SetOperatingMode = Measure:
606 // - Should receive NotifyOperatingMode = Measure
607 // - Should not receive NotifyErrorList
608 Manager.SetOperatingMode(kTHM1176Measure);
609
610 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
611 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
612 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
613 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
614 QCOMPARE(m_OperatingMode, kTHM1176Measure);
615
616 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
617
618 // - Emit SendTrigger 10x:
619 // - Should receive NotifyOperatingMode = Idle
620 // - Should receive NotifyMeasurement as requested
621 // - Should not receive NotifyErrorList
622 QThread::currentThread()->msleep(100);
623 for (int i = 0; i < 10; i++)
624 {
625 Manager.SendTrigger();
626 QThread::currentThread()->msleep(100);
627 }
628
629 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
630 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
631 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
632 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
633 QCOMPARE(m_OperatingMode, kTHM1176Idle);
634
635 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
636 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
637 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
638 QCOMPARE(m_Measurement.Bx.size(), 10ul);
639 QCOMPARE(m_Measurement.By.size(), 0ul);
640 QCOMPARE(m_Measurement.Bz.size(), 10ul);
641 QCOMPARE(m_Measurement.Units, MTL::kT);
642 QVERIFY(m_Measurement.Temp == 0);
643 QCOMPARE(m_Measurement.TimestampList.size(), 10ul);
644 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
645 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
646 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
647 QVERIFY(m_Measurement.TriggerParms.Period_s > 80e-3 && m_Measurement.TriggerParms.Period_s < 120e-3);
648 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
649 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
650 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
651 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
652 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
653 QCOMPARE(m_Measurement.Warnings.size(), 1ul);
654 QCOMPARE(m_Measurement.Warnings[0].Code, THM1176_NO_ANGLE_CORRECTION_CODE);
655
656 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
657
658 std::cout << "- Measured Triggered,10: B[] = (" << m_Measurement.Bx[0] << "..., N/A , " << m_Measurement.Bz[0] << "...) [T], "
659 "Temp = N/A , TimestampList = " << m_Measurement.TimestampList[0] << "..." << std::endl;
660
661 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
662 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
663
664 // - Emit SetOperatingMode = Measure:
665 // - Should receive NotifyOperatingMode = Measure
666 // - Should not receive NotifyErrorList
667 Manager.SetOperatingMode(kTHM1176Measure);
668
669 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
670 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
671 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
672 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
673 QCOMPARE(m_OperatingMode, kTHM1176Measure);
674
675 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
676
677 // - Emit SendTrigger 5x, then emit SetOperatingMode = Idle:
678 // - Should receive NotifyOperatingMode = Idle
679 // - Should not receive NotifyMeasurement
680 // - Should not receive NotifyErrorList
681 QThread::currentThread()->msleep(100);
682 for (int i = 0; i < 5; i++)
683 {
684 Manager.SendTrigger();
685 QThread::currentThread()->msleep(100);
686 }
687 Manager.SetOperatingMode(kTHM1176Idle);
688
689 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
690 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
691 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
692 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
693 QCOMPARE(m_OperatingMode, kTHM1176Idle);
694
695 QCOMPARE(l_NotifyMeasurementSpy.count(), 0);
696 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
697
698 std::cout << "- Measured Triggered,10, sent 5 triggers, and aborted" << std::endl;
699
700 // - Emit SendTrigger:
701 // - Should receive NotifyErrorList
702 QThread::currentThread()->msleep(100);
703 Manager.SendTrigger();
704
705 l_NotifyErrorListSpy.wait(THM1176_MEASURE_TIME);
706 QCOMPARE(l_NotifyErrorListSpy.count(), 1);
707 m_Arguments = l_NotifyErrorListSpy.takeFirst();
708 m_LatestErrors = qvariant_cast<CErrorList>(m_Arguments.at(0));
709 QCOMPARE(m_LatestErrors.size(), 1ul);
710
711 std::cout << "- Sending spurious trigger returned error: "
712 << m_LatestErrors[0].Code << ", "
713 << m_LatestErrors[0].Context << ": "
714 << m_LatestErrors[0].Description << std::endl;
715
716} // THM1176IM_Test02_Measure::TestSetOperatingMode_Triggered
717
736 void THM1176IM_Test02_Measure::TestSetOperatingMode_Timed(void)
737{
738 // Create Signal Spies to retrieve measurement result, operating mode, and possible errors.
739 QSignalSpy l_NotifyMeasurementSpy(&Manager, SIGNAL(NotifyMeasurement(CMeasurement)));
740 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
741 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
742
743 // - Emit SetOperatingMode = Reset:
744 // - Should receive NotifyOperatingMode = Reset, Idle
745 Manager.SetOperatingMode(kTHM1176Reset);
746
747 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
748 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
749 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
750 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
751 QCOMPARE(m_OperatingMode, kTHM1176Reset);
752 if (l_NotifyOperatingModeSpy.count() <= 0)
753 {
754 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
755 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
756 }
757 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
758 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
759 QCOMPARE(m_OperatingMode, kTHM1176Idle);
760
761 m_AveragingParms = Manager.GetAveragingParms();
762 m_Trigger = Manager.GetTriggerParms();
763 m_OutputSelect = Manager.GetOutputSelect();
764 m_SleepParm = Manager.GetSleepParm();
765 m_Units = Manager.GetUnits();
766 m_RangeParms = Manager.GetRangeParms();
767 m_CommFormat = Manager.GetCommFormat();
768
769 std::cout << "- Reset " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
770
771 // - Set SetTriggerParms to Timed,0.1,1:
772 // - Should not receive NotifyErrorList
773 m_Trigger.Source = kInputTrigSrcTimer;
774 m_Trigger.Period_s = 0.1;
775 m_Trigger.Count = 1;
776 Manager.SetTriggerParms(m_Trigger);
777
778 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
779 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
780
781 // - Emit SetOperatingMode = Measure:
782 // - Should receive NotifyOperatingMode = Measure, Idle
783 // - Should receive NotifyMeasurement length 1
784 // - Should not receive NotifyErrorList
785 Manager.SetOperatingMode(kTHM1176Measure);
786
787 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
788 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
789 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
790 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
791 QCOMPARE(m_OperatingMode, kTHM1176Measure);
792 if (l_NotifyOperatingModeSpy.count() <= 0)
793 {
794 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
795 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
796 }
797 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
798 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
799 QCOMPARE(m_OperatingMode, kTHM1176Idle);
800
801 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
802 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
803 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
804 QCOMPARE(m_Measurement.Bx.size(), 1ul);
805 QCOMPARE(m_Measurement.By.size(), 1ul);
806 QCOMPARE(m_Measurement.Bz.size(), 1ul);
807 QCOMPARE(m_Measurement.Units, MTL::kT);
808 QVERIFY(m_Measurement.Temp != 0);
809 QCOMPARE(m_Measurement.TimestampList.size(), 1ul);
810 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
811 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
812 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
813 QCOMPARE(m_Measurement.TriggerParms.Period_s, m_Trigger.Period_s);
814 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
815 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
816 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
817 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
818 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
819 QCOMPARE(m_Measurement.Warnings.size(), 0ul);
820
821 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
822
823 std::cout << "- Measured Timed,0.1,1: B = (" << m_Measurement.Bx[0] << ", " << m_Measurement.By[0] << ", " << m_Measurement.Bz[0] << ") [T], "
824 "Temp = " << m_Measurement.Temp << ", Timestamp = " << m_Measurement.TimestampList[0] << std::endl;
825
826 // - Set SetTriggerParms to Timed,0.1,10:
827 // - Should not receive NotifyErrorList
828 m_Trigger.Source = kInputTrigSrcTimer;
829 m_Trigger.Period_s = 0.1;
830 m_Trigger.Count = 10;
831 Manager.SetTriggerParms(m_Trigger);
832
833 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
834 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
835
836 // - Set SetOutputSelect to Bx, no By, Bz, no T, Time, 10:
837 // - Should not receive NotifyErrorList
838 m_OutputSelect.Bx = true;
839 m_OutputSelect.By = false;
840 m_OutputSelect.Bz = true;
841 m_OutputSelect.Temperature = false;
842 m_OutputSelect.Timestamp = true;
843 m_OutputSelect.NoMeasurements = 10;
844 Manager.SetOutputSelect(m_OutputSelect);
845
846 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
847 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
848
849 // - Emit SetOperatingMode = Measure:
850 // - Should receive NotifyOperatingMode = Measure, Idle
851 // - Should receive NotifyMeasurement as requested
852 // - Should not receive NotifyErrorList
853 Manager.SetOperatingMode(kTHM1176Measure);
854
855 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
856 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
857 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
858 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
859 QCOMPARE(m_OperatingMode, kTHM1176Measure);
860 if (l_NotifyOperatingModeSpy.count() <= 0)
861 {
862 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
863 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
864 }
865 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
866 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
867 QCOMPARE(m_OperatingMode, kTHM1176Idle);
868
869 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
870 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
871 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
872 QCOMPARE(m_Measurement.Bx.size(), 10ul);
873 QCOMPARE(m_Measurement.By.size(), 0ul);
874 QCOMPARE(m_Measurement.Bz.size(), 10ul);
875 QCOMPARE(m_Measurement.Units, MTL::kT);
876 QVERIFY(m_Measurement.Temp == 0);
877 QCOMPARE(m_Measurement.TimestampList.size(), 10ul);
878 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
879 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
880 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
881 QCOMPARE(m_Measurement.TriggerParms.Period_s, m_Trigger.Period_s);
882 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
883 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
884 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
885 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
886 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
887 QCOMPARE(m_Measurement.Warnings.size(), 1ul);
888 QCOMPARE(m_Measurement.Warnings[0].Code, THM1176_NO_ANGLE_CORRECTION_CODE);
889
890 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
891
892 std::cout << "- Measured Timed,0.1,10: B[] = (" << m_Measurement.Bx[0] << "..., N/A , " << m_Measurement.Bz[0] << "...) [T], "
893 "Temp = N/A , TimestampList[] = " << m_Measurement.TimestampList[0] << "..." << std::endl;
894
895} // THM1176IM_Test02_Measure::TestSetOperatingMode_Timed
896
912 void THM1176IM_Test02_Measure::TestSetOperatingMode_TimedLong(void)
913{
914 // Create Signal Spies to retrieve measurement result, operating mode, and possible errors.
915 QSignalSpy l_NotifyMeasurementSpy(&Manager, SIGNAL(NotifyMeasurement(CMeasurement)));
916 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
917 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
918
919 // - Emit SetOperatingMode = Reset:
920 // - Should receive NotifyOperatingMode = Reset, Idle
921 Manager.SetOperatingMode(kTHM1176Reset);
922
923 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
924 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
925 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
926 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
927 QCOMPARE(m_OperatingMode, kTHM1176Reset);
928 if (l_NotifyOperatingModeSpy.count() <= 0)
929 {
930 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
931 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
932 }
933 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
934 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
935 QCOMPARE(m_OperatingMode, kTHM1176Idle);
936
937 m_AveragingParms = Manager.GetAveragingParms();
938 m_Trigger = Manager.GetTriggerParms();
939 m_OutputSelect = Manager.GetOutputSelect();
940 m_SleepParm = Manager.GetSleepParm();
941 m_Units = Manager.GetUnits();
942 m_RangeParms = Manager.GetRangeParms();
943 m_CommFormat = Manager.GetCommFormat();
944
945 std::cout << "- Reset " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
946
947 // - Set SetTriggerParms to Timed,0.0005,1:
948 // - Should not receive NotifyErrorList
949 m_Trigger.Source = kInputTrigSrcTimer;
950 m_Trigger.Period_s = 0.0005;
951 m_Trigger.Count = 4000;
952 Manager.SetTriggerParms(m_Trigger);
953
954 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
955 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
956
957 // - Set AveragingParms to 1
958 // - Should not receive NotifyErrorList
959 m_AveragingParms.NoPoints = 1;
960 Manager.SetAveragingParms(m_AveragingParms);
961
962 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
963 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
964
965 // - Set SetOutputSelect to Bx, By, Bz, T, Time, 4000:
966 // - Should not receive NotifyErrorList
967 m_OutputSelect.Bx = true;
968 m_OutputSelect.By = true;
969 m_OutputSelect.Bz = true;
970 m_OutputSelect.Temperature = true;
971 m_OutputSelect.Timestamp = true;
972 m_OutputSelect.NoMeasurements = 4000;
973 Manager.SetOutputSelect(m_OutputSelect);
974
975 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
976 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
977
978 // - Set CommFormat to Binary
979 // - Should not receive NotifyErrorList
980 m_CommFormat = kComFormatInteger;
981 Manager.SetCommFormat(m_CommFormat);
982
983 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
984 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
985
986 // - Emit SetOperatingMode = Measure:
987 // - Should receive NotifyOperatingMode = Measure, Idle
988 // - Should receive NotifyMeasurement as requested
989 // - Should not receive NotifyErrorList
990 // - Should take roughly 2-4 seconds
991 auto l_StartTime = std::chrono::high_resolution_clock::now();
992 Manager.SetOperatingMode(kTHM1176Measure);
993
994 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
995 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
996 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
997 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
998 QCOMPARE(m_OperatingMode, kTHM1176Measure);
999 if (l_NotifyOperatingModeSpy.count() <= 0)
1000 {
1001 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
1002 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1003 }
1004 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1005 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1006 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1007
1008 auto l_StopTime = std::chrono::high_resolution_clock::now();
1009
1010 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
1011 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
1012 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
1013 QCOMPARE(m_Measurement.Bx.size(), 4000ul);
1014 QCOMPARE(m_Measurement.By.size(), 4000ul);
1015 QCOMPARE(m_Measurement.Bz.size(), 4000ul);
1016 QCOMPARE(m_Measurement.Units, MTL::kT);
1017 QVERIFY(m_Measurement.Temp > 0);
1018 QCOMPARE(m_Measurement.TimestampList.size(), 4000ul);
1019 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
1020 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
1021 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
1022 QCOMPARE(m_Measurement.TriggerParms.Period_s, m_Trigger.Period_s);
1023 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
1024 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
1025 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
1026 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
1027 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
1028 QCOMPARE(m_Measurement.Warnings.size(), 0ul);
1029
1030 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1031
1032 auto l_TimeElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(l_StopTime - l_StartTime).count();
1033 QVERIFY(l_TimeElapsed > 2000 && l_TimeElapsed < 4000);
1034
1035 std::cout << "- Measured Timed,0.0005,4000 B[] = (" << m_Measurement.Bx[0] << "..., " << m_Measurement.By[0] << "..., " << m_Measurement.Bz[0] << "...) [T], "
1036 "Temp = " << m_Measurement.Temp << ", TimestampList[] = " << m_Measurement.TimestampList[0] << "..." << std::endl;
1037
1038} // THM1176IM_Test02_Measure::TestSetOperatingMode_TimedLong
1039
1053 void THM1176IM_Test02_Measure::TestSetOperatingMode_ImmediateContinuous(void)
1054{
1055 // Create Signal Spies to retrieve measurement result, operating mode, and possible errors.
1056 QSignalSpy l_NotifyMeasurementSpy(&Manager, SIGNAL(NotifyMeasurement(CMeasurement)));
1057 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
1058 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
1059
1060 // - Emit SetOperatingMode = Reset:
1061 // - Should receive NotifyOperatingMode = Reset, Idle
1062 Manager.SetOperatingMode(kTHM1176Reset);
1063
1064 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
1065 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
1066 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1067 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1068 QCOMPARE(m_OperatingMode, kTHM1176Reset);
1069 if (l_NotifyOperatingModeSpy.count() <= 0)
1070 {
1071 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
1072 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1073 }
1074 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1075 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1076 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1077
1078 m_AveragingParms = Manager.GetAveragingParms();
1079 m_Trigger = Manager.GetTriggerParms();
1080 m_OutputSelect = Manager.GetOutputSelect();
1081 m_SleepParm = Manager.GetSleepParm();
1082 m_Units = Manager.GetUnits();
1083 m_RangeParms = Manager.GetRangeParms();
1084 m_CommFormat = Manager.GetCommFormat();
1085
1086 std::cout << "- Reset " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
1087
1088 // - Set SetTriggerParms to Immediate,1:
1089 // - Should not receive NotifyErrorList
1090 m_Trigger.Source = kInputTrigSrcImmediate;
1091 m_Trigger.Period_s = 0.1;
1092 m_Trigger.Count = 1;
1093 Manager.SetTriggerParms(m_Trigger);
1094
1095 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
1096 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1097
1098 // - Emit SetOperatingMode = Measure,Continuous:
1099 // - Should receive NotifyOperatingMode = Measure,Continuous
1100 // - 10x: Should receive NotifyMeasurement length 1
1101 // - Should not receive NotifyErrorList
1102 Manager.SetOperatingMode(kTHM1176MeasureContinuously);
1103
1104 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
1105 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1106 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1107 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1108 QCOMPARE(m_OperatingMode, kTHM1176MeasureContinuously);
1109
1110 for (int i = 0; i < 10; i++)
1111 {
1112 l_NotifyMeasurementSpy.wait(THM1176_MEASURE_TIME);
1113 QVERIFY(l_NotifyMeasurementSpy.count() > 0);
1114 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
1115 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
1116 QCOMPARE(m_Measurement.Bx.size(), 1ul);
1117 QCOMPARE(m_Measurement.By.size(), 1ul);
1118 QCOMPARE(m_Measurement.Bz.size(), 1ul);
1119 QCOMPARE(m_Measurement.Units, MTL::kT);
1120 QVERIFY(m_Measurement.Temp != 0);
1121 QCOMPARE(m_Measurement.TimestampList.size(), 1ul);
1122 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
1123 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
1124 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
1125 QCOMPARE(m_Measurement.TriggerParms.Period_s, PeriodOfImmediateTrigger(m_AveragingParms));
1126 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
1127 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
1128 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
1129 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
1130 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
1131
1132 std::cout << "- Measured Immediate,1,Continuous: B = (" << m_Measurement.Bx[0] << ", " << m_Measurement.By[0] << ", " << m_Measurement.Bz[0] << ") [T], "
1133 "Temp = " << m_Measurement.Temp << ", Timestamp = " << m_Measurement.TimestampList[0] << ", " <<
1134 m_Measurement.Warnings.size() << " Warnings" << std::endl;
1135 }
1136
1137 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1138
1139 // - Emit SetOperatingMode = Idle:
1140 // - Should receive NotifyOperatingMode = Idle
1141 // - Should not receive NotifyErrorList
1142 Manager.SetOperatingMode(kTHM1176Idle);
1143
1144 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
1145 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1146 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1147 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1148 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1149
1150 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1151
1152} // THM1176IM_Test02_Measure::TestSetOperatingMode_TimedLong
1153
1167 void THM1176IM_Test02_Measure::TestSetOperatingMode_TimedContinuous(void)
1168{
1169 // Create Signal Spies to retrieve measurement result, operating mode, and possible errors.
1170 QSignalSpy l_NotifyMeasurementSpy(&Manager, SIGNAL(NotifyMeasurement(CMeasurement)));
1171 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
1172 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
1173
1174 // - Emit SetOperatingMode = Reset:
1175 // - Should receive NotifyOperatingMode = Reset, Idle
1176 Manager.SetOperatingMode(kTHM1176Reset);
1177
1178 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
1179 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
1180 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1181 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1182 QCOMPARE(m_OperatingMode, kTHM1176Reset);
1183 if (l_NotifyOperatingModeSpy.count() <= 0)
1184 {
1185 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
1186 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1187 }
1188 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1189 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1190 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1191
1192 m_AveragingParms = Manager.GetAveragingParms();
1193 m_Trigger = Manager.GetTriggerParms();
1194 m_OutputSelect = Manager.GetOutputSelect();
1195 m_SleepParm = Manager.GetSleepParm();
1196 m_Units = Manager.GetUnits();
1197 m_RangeParms = Manager.GetRangeParms();
1198 m_CommFormat = Manager.GetCommFormat();
1199
1200 std::cout << "- Reset " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
1201
1202 // - Set SetTriggerParms to Timed,0.1,1:
1203 // - Should not receive NotifyErrorList
1204 m_Trigger.Source = kInputTrigSrcTimer;
1205 m_Trigger.Period_s = 0.1;
1206 m_Trigger.Count = 1;
1207 Manager.SetTriggerParms(m_Trigger);
1208
1209 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
1210 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1211
1212 // - Emit SetOperatingMode = Measure,Continuous:
1213 // - Should receive NotifyOperatingMode = Measure,Continuous
1214 // - 10x: Should receive NotifyMeasurement length 1
1215 // - Should not receive NotifyErrorList
1216 Manager.SetOperatingMode(kTHM1176MeasureContinuously);
1217
1218 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
1219 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1220 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1221 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1222 QCOMPARE(m_OperatingMode, kTHM1176MeasureContinuously);
1223
1224 for (int i = 0; i < 10; i++)
1225 {
1226 l_NotifyMeasurementSpy.wait(THM1176_MEASURE_TIME);
1227 QThread::currentThread()->msleep(100);
1228
1229 QVERIFY(l_NotifyMeasurementSpy.count() > 0);
1230 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
1231 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
1232 QCOMPARE(m_Measurement.Bx.size(), 1ul);
1233 QCOMPARE(m_Measurement.By.size(), 1ul);
1234 QCOMPARE(m_Measurement.Bz.size(), 1ul);
1235 QCOMPARE(m_Measurement.Units, MTL::kT);
1236 QVERIFY(m_Measurement.Temp != 0);
1237 QCOMPARE(m_Measurement.TimestampList.size(), 1ul);
1238 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
1239 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
1240 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
1241 QCOMPARE(m_Measurement.TriggerParms.Period_s, m_Trigger.Period_s);
1242 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
1243 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
1244 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
1245 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
1246 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
1247
1248 std::cout << "- Measured Timed,0.1,1,Continuous: B = (" << m_Measurement.Bx[0] << ", " << m_Measurement.By[0] << ", " << m_Measurement.Bz[0] << ") [T], "
1249 "Temp = " << m_Measurement.Temp << ", Timestamp = " << m_Measurement.TimestampList[0] << ", " <<
1250 m_Measurement.Warnings.size() << " Warnings" << std::endl;
1251 }
1252
1253 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1254
1255 // - Emit SetOperatingMode = Idle:
1256 // - Should receive NotifyOperatingMode = Idle
1257 // - Should not receive NotifyErrorList
1258 Manager.SetOperatingMode(kTHM1176Idle);
1259
1260 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
1261 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1262 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1263 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1264 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1265
1266 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1267
1268} // THM1176IM_Test02_Measure::TestSetOperatingMode_TimedContinuous
1269
1284 void THM1176IM_Test02_Measure::TestSetOperatingMode_TriggeredContinuous(void)
1285{
1286 // Create Signal Spies to retrieve measurement result, operating mode, and possible errors.
1287 QSignalSpy l_NotifyMeasurementSpy(&Manager, SIGNAL(NotifyMeasurement(CMeasurement)));
1288 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
1289 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
1290
1291 // - Emit SetOperatingMode = Reset:
1292 // - Should receive NotifyOperatingMode = Reset, Idle
1293 Manager.SetOperatingMode(kTHM1176Reset);
1294
1295 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
1296 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
1297 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1298 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1299 QCOMPARE(m_OperatingMode, kTHM1176Reset);
1300 if (l_NotifyOperatingModeSpy.count() <= 0)
1301 {
1302 l_NotifyOperatingModeSpy.wait(THM1176_RESET_TIME);
1303 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1304 }
1305 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1306 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1307 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1308
1309 m_AveragingParms = Manager.GetAveragingParms();
1310 m_Trigger = Manager.GetTriggerParms();
1311 m_OutputSelect = Manager.GetOutputSelect();
1312 m_SleepParm = Manager.GetSleepParm();
1313 m_Units = Manager.GetUnits();
1314 m_RangeParms = Manager.GetRangeParms();
1315 m_CommFormat = Manager.GetCommFormat();
1316
1317 std::cout << "- Reset " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
1318
1319 // - Set SetTriggerParms to Bus,1:
1320 // - Should not receive NotifyErrorList
1321 m_Trigger.Source = kInputTrigSrcBus;
1322 m_Trigger.Period_s = 0.1;
1323 m_Trigger.Count = 1;
1324 Manager.SetTriggerParms(m_Trigger);
1325
1326 l_NotifyErrorListSpy.wait(THM1176_CHANGE_PARM_TIME);
1327 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1328
1329 // - Emit SetOperatingMode = Measure,Continuous:
1330 // - Should receive NotifyOperatingMode = Measure,Continuous
1331 Manager.SetOperatingMode(kTHM1176MeasureContinuously);
1332
1333 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
1334 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1335 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1336 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1337 QCOMPARE(m_OperatingMode, kTHM1176MeasureContinuously);
1338
1339 // Send 10 triggers:
1340 // - 10x: Should receive NotifyMeasurement length 1
1341 // - Should not receive NotifyErrorList
1342 QThread::currentThread()->msleep(100);
1343 for (int i = 0; i < 10; i++)
1344 {
1345 Manager.SendTrigger();
1346 QThread::currentThread()->msleep(100);
1347
1348 l_NotifyMeasurementSpy.wait(THM1176_MEASURE_TIME);
1349 QCOMPARE(l_NotifyMeasurementSpy.count(), 1);
1350 m_Arguments = l_NotifyMeasurementSpy.takeFirst();
1351 m_Measurement = qvariant_cast<CMeasurement> (m_Arguments.at(0));
1352 QCOMPARE(m_Measurement.Bx.size(), 1ul);
1353 QCOMPARE(m_Measurement.By.size(), 1ul);
1354 QCOMPARE(m_Measurement.Bz.size(), 1ul);
1355 QCOMPARE(m_Measurement.Units, MTL::kT);
1356 QVERIFY(m_Measurement.Temp != 0);
1357 QCOMPARE(m_Measurement.TimestampList.size(), 1ul);
1358 QVERIFY(m_Measurement.AveragingParms == m_AveragingParms);
1359 QCOMPARE(m_Measurement.TriggerParms.Source, m_Trigger.Source);
1360 QCOMPARE(m_Measurement.TriggerParms.Count, m_Trigger.Count);
1361 QCOMPARE(m_Measurement.TriggerParms.Period_s, 0.);
1362 QVERIFY(m_Measurement.OutputSelect == m_OutputSelect);
1363 QVERIFY(m_Measurement.SleepParm == m_SleepParm);
1364 QVERIFY(m_Measurement.RangeParms.Auto == m_RangeParms.Auto &&
1365 (m_RangeParms.Auto || m_Measurement.RangeParms.Range == m_RangeParms.Range));
1366 QVERIFY(m_Measurement.CommFormat == m_CommFormat);
1367
1368 std::cout << "- Measured Triggered,1,Continuous: B = (" << m_Measurement.Bx[0] << ", " << m_Measurement.By[0] << ", " << m_Measurement.Bz[0] << ") [T], "
1369 "Temp = " << m_Measurement.Temp << ", Timestamp = " << m_Measurement.TimestampList[0] << ", " <<
1370 m_Measurement.Warnings.size() << " Warnings" << std::endl;
1371
1372 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1373 }
1374
1375 // - Emit SetOperatingMode = Idle:
1376 // - Should receive NotifyOperatingMode = Idle
1377 // - Should not receive NotifyErrorList
1378 Manager.SetOperatingMode(kTHM1176Idle);
1379
1380 l_NotifyOperatingModeSpy.wait(THM1176_MEASURE_TIME);
1381 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1382 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1383 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1384 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1385
1386 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1387
1388} // THM1176IM_Test02_Measure::TestSetOperatingMode_TriggeredContinuous
1389
1398 void THM1176IM_Test02_Measure::TestSetOperatingMode_CalibrateRestore(void)
1399{
1400 // Create Signal Spies to retrieve operating mode and possible errors.
1401 QSignalSpy l_NotifyOperatingModeSpy(&Manager, SIGNAL(NotifyOperatingMode(eTHM1176OperatingMode)));
1402 QSignalSpy l_NotifyErrorListSpy(&Manager, SIGNAL(NotifyErrorList(CErrorList)));
1403
1404 // - Emit SetOperatingMode = Calibrate Zero Offset with Override enabled:
1405 // - Should receive NotifyOperatingMode = Calibrate, Idle
1406 Manager.SetCalibrationOverride(true);
1407 Manager.SetOperatingMode(kTHM1176CalibrateZeroOffset);
1408
1409 l_NotifyOperatingModeSpy.wait(THM1176_CALIBRATE_TIME);
1410 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
1411 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1412 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1413 QCOMPARE(m_OperatingMode, kTHM1176CalibrateZeroOffset);
1414 if (l_NotifyOperatingModeSpy.count() <= 0)
1415 {
1416 l_NotifyOperatingModeSpy.wait(THM1176_CALIBRATE_TIME);
1417 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1418 }
1419 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1420 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1421 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1422
1423 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1424
1425 std::cout << "- Performed zero calibration " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
1426
1429 if (Manager.GetIdentification().Model == "TFM1186")
1430 {
1431 Manager.SetCalibrationOverride(false);
1432 Manager.SetOperatingMode(kTHM1176CalibrateZeroOffset);
1433
1434 l_NotifyOperatingModeSpy.wait(THM1176_CALIBRATE_TIME);
1435 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
1436 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1437 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1438 QCOMPARE(m_OperatingMode, kTHM1176CalibrateZeroOffset);
1439 if (l_NotifyOperatingModeSpy.count() <= 0)
1440 {
1441 l_NotifyOperatingModeSpy.wait(THM1176_CALIBRATE_TIME);
1442 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1443 }
1444 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1445 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1446 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1447
1448 QCOMPARE(l_NotifyErrorListSpy.count(), 1);
1449 m_Arguments = l_NotifyErrorListSpy.takeFirst();
1450 m_LatestErrors = qvariant_cast<CErrorList>(m_Arguments.at(0));
1451 QCOMPARE(m_LatestErrors.size(), 1ul);
1452
1453 std::cout << "- Trying to calibrate 'prohibited' model returned error: "
1454 << m_LatestErrors[0].Code << ", "
1455 << m_LatestErrors[0].Context << ": "
1456 << m_LatestErrors[0].Description << std::endl;
1457 }
1458
1459 // - Emit SetOperatingMode = Calibrate Zero Offset:
1460 // - Should receive NotifyOperatingMode = Calibrate, Idle
1461 Manager.SetOperatingMode(kTHM1176RestoreZeroOffset);
1462
1463 l_NotifyOperatingModeSpy.wait(THM1176_CALIBRATE_TIME);
1464 QVERIFY(l_NotifyOperatingModeSpy.count() > 0);
1465 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1466 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1467 QCOMPARE(m_OperatingMode, kTHM1176RestoreZeroOffset);
1468 if (l_NotifyOperatingModeSpy.count() <= 0)
1469 {
1470 l_NotifyOperatingModeSpy.wait(THM1176_CALIBRATE_TIME);
1471 QCOMPARE(l_NotifyOperatingModeSpy.count(), 1);
1472 }
1473 m_Arguments = l_NotifyOperatingModeSpy.takeFirst();
1474 m_OperatingMode = qvariant_cast<eTHM1176OperatingMode>(m_Arguments.at(0));
1475 QCOMPARE(m_OperatingMode, kTHM1176Idle);
1476
1477 QCOMPARE(l_NotifyErrorListSpy.count(), 0);
1478
1479 std::cout << "- Restored zero calibration " << m_Identification.Model << ", S/N " << m_Identification.SerialNumber << std::endl;
1480}
1481
1490 void THM1176IM_Test02_Measure::TestUtilities(void)
1491{
1492 bool l_Result;
1493
1494 // - Call GetImmediateMeasurementPeriod for averaging 1, 2, 3:
1495 // - Should be linear.
1496 sAveraging<uParm> l_Avg;
1497 F64 l_Period1, l_Period2, l_Period3;
1498 l_Avg.NoPoints = 1;
1499 l_Result = Manager.GetImmediateMeasurementPeriod(l_Avg, l_Period1);
1500 Q_ASSERT(true == l_Result);
1501 l_Avg.NoPoints = 2;
1502 l_Result = Manager.GetImmediateMeasurementPeriod(l_Avg, l_Period2);
1503 Q_ASSERT(true == l_Result);
1504 l_Avg.NoPoints = 3;
1505 l_Result = Manager.GetImmediateMeasurementPeriod(l_Avg, l_Period3);
1506 Q_ASSERT(true == l_Result);
1507 QVERIFY(abs((l_Period2 - l_Period1) - (l_Period3 - l_Period2)) < 1E-8);
1508
1509 // - Call ConvertTimestamp for 0:
1510 // - Should get a date within the last 24 hours.
1511 CAbsoluteTimestamp l_Timestamp;
1512 l_Result = Manager.ConvertTimestamp(0ul, l_Timestamp);
1513 Q_ASSERT(true == l_Result);
1514 QVERIFY(l_Timestamp.seconds() > (std::time(NULL) - 24l*60l*60l) &&
1515 l_Timestamp.seconds() < std::time(NULL));
1516
1517 // - Call ReadInformationDates:
1518 // - Should get Manufacturing date since 2008, and calibration date within 3 years.
1519 QDateTime l_MfrDate, l_CalDate;
1520 l_Result = Manager.ReadInformationDates(l_MfrDate, l_CalDate);
1521 Q_ASSERT(true == l_Result);
1522 QVERIFY(2008 < l_MfrDate.date().year());
1523 QVERIFY((QDateTime::currentDateTime().date().year() - 3) < l_CalDate.date().year() &&
1524 QDateTime::currentDateTime().date().year() >= l_CalDate.date().year());
1525}
1526
1527//----------------------------------------------------------------------//
1528// main() //
1529//----------------------------------------------------------------------//
1530QTEST_MAIN(THM1176IM_Test02_Measure)
1531
1532#include "THM1176IM_Test02_Measure.moc"
CTHM1176InstrumentManager.h
Interface definition for Metrolab THM1176/TFM1186 Instrument Manager.
F64
double F64
64-bit floating-point number.
Definition OSDefines.h:34
THM1176_PROMPT_TIME
#define THM1176_PROMPT_TIME
Definition THM1176IM_Test01_Connect.cpp:18
Manager
static CTHM1176InstrumentManager Manager
Definition THM1176IM_Test01_Connect.cpp:26
THM1176_CONNECT_TIME
#define THM1176_CONNECT_TIME
Definition THM1176IM_Test01_Connect.cpp:20
THM1176_BOOT_N_SCAN_TIME
#define THM1176_BOOT_N_SCAN_TIME
Definition THM1176IM_Test01_Connect.cpp:19
THM1176_IMMEDIATE_TIME_PER_MEAS
static const F64 THM1176_IMMEDIATE_TIME_PER_MEAS(4.4532792007542600E+04)
THM1176_CHANGE_PARM_TIME
#define THM1176_CHANGE_PARM_TIME
Definition THM1176IM_Test02_Measure.cpp:23
Manager
static CTHM1176InstrumentManager Manager
Definition THM1176IM_Test02_Measure.cpp:31
THM1176_CALIBRATE_TIME
#define THM1176_CALIBRATE_TIME
Definition THM1176IM_Test02_Measure.cpp:26
THM1176_IMMEDIATE_TIME_PER_ACQ
static const F64 THM1176_IMMEDIATE_TIME_PER_ACQ(1.0281823091218700E+05)
THM1176_MEASURE_TIME
#define THM1176_MEASURE_TIME
Definition THM1176IM_Test02_Measure.cpp:25
THM1176_RESET_TIME
#define THM1176_RESET_TIME
Definition THM1176IM_Test02_Measure.cpp:24
PeriodOfImmediateTrigger
F64 PeriodOfImmediateTrigger(sAveraging< uParm > Averaging)
Definition THM1176IM_Test02_Measure.cpp:45
PromptAndWait
static void PromptAndWait(std::string Prompt)
Definition THM1176IM_Test02_Measure.cpp:36
MTL::CMeasurement
Data returned for one measurement.
Definition THM1176InstrumentManagerTypes.h:51
MTL::CTHM1176InstrumentManager
THM1176 Instrument Manager class: public interface.
Definition CTHM1176InstrumentManager.h:539
MTL::CTHM1176InstrumentManager::SetAveragingParms
void SetAveragingParms(sAveraging< uParm > AveragingParms)
Set the averaging parameters.
Definition CTHM1176InstrumentManager.cpp:1670
MTL::CTHM1176InstrumentManager::GetOutputSelect
sArbitraryMeasurements GetOutputSelect(void)
Get the output selection parameters.
Definition CTHM1176InstrumentManager.cpp:1543
MTL::CTHM1176InstrumentManager::ReadInformationDates
bool ReadInformationDates(QDateTime &rManufacturingDate, QDateTime &rCalibrationDate)
Fetch the intrument's date information.
Definition CTHM1176InstrumentManager.cpp:1596
MTL::CTHM1176InstrumentManager::GetUnits
eTHM1176Units GetUnits(void)
Get the measurement units.
Definition CTHM1176InstrumentManager.cpp:1559
MTL::CTHM1176InstrumentManager::SetOutputSelect
void SetOutputSelect(sArbitraryMeasurements OutputSelect)
Set the output selection parameters.
Definition CTHM1176InstrumentManager.cpp:1725
MTL::CTHM1176InstrumentManager::GetTriggerParms
sInputTrigger< uParm > GetTriggerParms(void)
Get the trigger parameters.
Definition CTHM1176InstrumentManager.cpp:1535
MTL::CTHM1176InstrumentManager::ConvertTimestamp
bool ConvertTimestamp(const U64 RawTimestamp, CAbsoluteTimestamp &rTimestamp)
Convert a raw timestamp to UNIX Epoch time and nanoseconds.
Definition CTHM1176InstrumentManager.h:794
MTL::CTHM1176InstrumentManager::GetCommFormat
eCommunicationFormat GetCommFormat(void)
Get the communication format parameters.
Definition CTHM1176InstrumentManager.cpp:1575
MTL::CTHM1176InstrumentManager::GetAveragingParms
sAveraging< uParm > GetAveragingParms(void)
Get the averaging parameters.
Definition CTHM1176InstrumentManager.cpp:1527
MTL::CTHM1176InstrumentManager::GetImmediateMeasurementPeriod
bool GetImmediateMeasurementPeriod(const sAveraging< uParm > &rAvg, F64 &rPeriod)
Get measurement interval for Immediate Trigger, for a given averaging parameter.
Definition CTHM1176InstrumentManager.cpp:1583
MTL::CTHM1176InstrumentManager::SetCalibrationOverride
void SetCalibrationOverride(bool Override)
Set whether or not to override the check for instruments whose zero offset should not be calibrated.
MTL::CTHM1176InstrumentManager::GetIdentification
sIdentifier GetIdentification(void)
Get the current instrument's identification information.
Definition CTHM1176InstrumentManager.cpp:1469
MTL::CTHM1176InstrumentManager::SendTrigger
void SendTrigger(void)
Send a bus trigger to the instrument (both slot and signal).
MTL::CTHM1176InstrumentManager::GetSleepParm
bool GetSleepParm(void)
Get the sleep parameter.
Definition CTHM1176InstrumentManager.cpp:1551
MTL::CTHM1176InstrumentManager::SetOperatingMode
void SetOperatingMode(eTHM1176OperatingMode OperatingMode)
Set a new operating mode, for example to start measuring.
Definition CTHM1176InstrumentManager.cpp:1650
MTL::CTHM1176InstrumentManager::SetTriggerParms
void SetTriggerParms(sInputTrigger< uParm > TriggerParms)
Set the trigger parameters.
Definition CTHM1176InstrumentManager.cpp:1696
MTL::CTHM1176InstrumentManager::SetCommFormat
void SetCommFormat(eCommunicationFormat CommFormat)
Set the communication format parameters.
Definition CTHM1176InstrumentManager.cpp:1830
MTL::CTHM1176InstrumentManager::Stop
void Stop(void)
Shut down the THM1176 Instrument Manager.
Definition CTHM1176InstrumentManager.cpp:1181
MTL::CTHM1176InstrumentManager::GetRangeParms
sRange< uParm > GetRangeParms(void)
Get the range parameters.
Definition CTHM1176InstrumentManager.cpp:1567
MTL::CTHM1176UnitsList
List of measurement units.
Definition THM1176InstrumentManagerTypes.h:46
MTL::Instrument::CResourceList
List of VISA resource names.
Definition IEEE488InstrumentTypes.h:26
MTL::Instrument::THM1176Types::CAbsoluteTimestamp::seconds
std::time_t seconds(void) const
Fetch the number of seconds.
Definition THM1176Types.cpp:363
MTL::Instrument::THM1176Types::CDivisorList
List of divisors, one per measurement unit.
Definition THM1176Types.h:203
MTL::Instrument::THM1176Types::CErrorList
List of errors returned by the instrument.
Definition THM1176Types.h:232
MTL::Instrument::THM1176Types::CFluxList
List of flux density values.
Definition THM1176Types.h:170
THM1176IM_Test02_Measure
Definition THM1176IM_Test02_Measure.cpp:54
THM1176IM_Test02_Measure::THM1176IM_Test02_Measure
THM1176IM_Test02_Measure()
Definition THM1176IM_Test02_Measure.cpp:126
THM1176IM_Test02_Measure::~THM1176IM_Test02_Measure
~THM1176IM_Test02_Measure()
Definition THM1176IM_Test02_Measure.cpp:131
MTL::Instrument::THM1176Types::eCommunicationFormat
eCommunicationFormat
Enumeration of possible formats for returned data.
Definition THM1176Types.h:466
MTL::Instrument::THM1176Types::kComFormatInteger
@ kComFormatInteger
Binary (32-bit integers).
Definition THM1176Types.h:468
MTL::Instrument::THM1176Types::kInputTrigSrcTimer
@ kInputTrigSrcTimer
Timed trigger: start measurement at regular intervals.
Definition THM1176Types.h:419
MTL::Instrument::THM1176Types::kInputTrigSrcImmediate
@ kInputTrigSrcImmediate
Immediate trigger: start measurement immediately after previous one completes.
Definition THM1176Types.h:418
MTL::Instrument::THM1176Types::kInputTrigSrcBus
@ kInputTrigSrcBus
Bus trigger: start measurement upon USB trigger message.
Definition THM1176Types.h:420
MTL::Instrument::tResourceName
std::string tResourceName
IEEE488 resource name.
Definition IEEE488InstrumentTypes.h:22
MTL::Instrument::THM1176_NO_ANGLE_CORRECTION_CODE
static const I32 THM1176_NO_ANGLE_CORRECTION_CODE
Warning that angle correction was not applied.
Definition THM1176.h:82
MTL
Definition CTHM1176InstrumentManager.h:179
MTL::eTHM1176OperatingMode
eTHM1176OperatingMode
Operating modes used to initiate actions or provide status.
Definition THM1176InstrumentManagerTypes.h:17
MTL::kTHM1176RestoreZeroOffset
@ kTHM1176RestoreZeroOffset
Restore the factory zero-offset setting.
Definition THM1176InstrumentManagerTypes.h:24
MTL::kTHM1176CalibrateZeroOffset
@ kTHM1176CalibrateZeroOffset
Initiate the zero-offset calibration procedure.
Definition THM1176InstrumentManagerTypes.h:23
MTL::kTHM1176Reset
@ kTHM1176Reset
Reset instrument.
Definition THM1176InstrumentManagerTypes.h:19
MTL::kTHM1176Measure
@ kTHM1176Measure
Start a single measurement.
Definition THM1176InstrumentManagerTypes.h:21
MTL::kTHM1176MeasureContinuously
@ kTHM1176MeasureContinuously
Start a continuous measurement.
Definition THM1176InstrumentManagerTypes.h:22
MTL::kTHM1176Idle
@ kTHM1176Idle
Place the instrument in idle mode.
Definition THM1176InstrumentManagerTypes.h:20
MTL::eTHM1176Units
eTHM1176Units
Enumeration of possible measurement units, including "ADC".
Definition THM1176InstrumentManagerTypes.h:29
MTL::kT
@ kT
Tesla.
Definition THM1176InstrumentManagerTypes.h:30
MTL::Instrument::THM1176Types::sArbitraryMeasurements
Specify the measurement data to be returned.
Definition THM1176Types.h:593
MTL::Instrument::THM1176Types::sAveraging
Averaging parameter.
Definition THM1176Types.h:388
MTL::Instrument::THM1176Types::sAveraging::NoPoints
ParmType< U16 > NoPoints
Number of points in block average.
Definition THM1176Types.h:389
MTL::Instrument::THM1176Types::sBoundedParm::Val
DataType Val
Current value.
Definition THM1176Types.h:247
MTL::Instrument::THM1176Types::sBoundedParm::Max
DataType Max
Upper bound.
Definition THM1176Types.h:249
MTL::Instrument::THM1176Types::sBoundedParm::Min
DataType Min
Lower bound.
Definition THM1176Types.h:248
MTL::Instrument::THM1176Types::sBoundedParm::Def
DataType Def
Default value.
Definition THM1176Types.h:250
MTL::Instrument::THM1176Types::sIdentifier
Instrument's identification string - parsed version.
Definition THM1176Types.h:353
MTL::Instrument::THM1176Types::sIdentifier::Manufacturer
std::string Manufacturer
Manufacturer name ("Metrolab Technology SA").
Definition THM1176Types.h:354
MTL::Instrument::THM1176Types::sIdentifier::SerialNumber
U32 SerialNumber
Serial number.
Definition THM1176Types.h:356
MTL::Instrument::THM1176Types::sIdentifier::Model
std::string Model
Model name (e.g. "THM1176-MF").
Definition THM1176Types.h:355
MTL::Instrument::THM1176Types::sInputTrigger
Input trigger parameter.
Definition THM1176Types.h:426
MTL::Instrument::THM1176Types::sInputTrigger::Count
ParmType< U16 > Count
Trigger count: take this many measurements before sending results.
Definition THM1176Types.h:429
MTL::Instrument::THM1176Types::sInputTrigger::Period_s
ParmType< F64 > Period_s
Trigger period, for timed trigger.
Definition THM1176Types.h:428
MTL::Instrument::THM1176Types::sRange
Measurement range parameter.
Definition THM1176Types.h:479
MTL::Instrument::THM1176Types::sRange::Range
ParmType< tFlux > Range
Measurement range, if auto-ranging is not enabled.
Definition THM1176Types.h:481