Skip to content

Commit 8e4147f

Browse files
committed
add coarse and fine zero interactions
1 parent dd9eba2 commit 8e4147f

File tree

1 file changed

+177
-14
lines changed

1 file changed

+177
-14
lines changed

src/applications/mne_scan/plugins/fieldline/fieldline_acqsystem.cpp

+177-14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ const std::string resourcesPath(QCoreApplication::applicationDirPath().toStdStri
6767
const std::string entryFile(resourcesPath + "main.py");
6868

6969
bool restartFinished = false;
70+
bool coarseZeroFinished = false;
71+
bool fineZeroFinished = false;
7072

7173
void callbackOnFinishedWhileRestart(int chassisId, int sensorId) {
7274
std::cout << "Sensor: (" << chassisId << ", " << sensorId << ") Finished restart.\n";
@@ -95,15 +97,17 @@ void callbackOnErrorWhileFineZero(int chassisId, int sensorId, int errorId) {
9597
void callbackOnCompletionRestart() {
9698
std::cout << "About to change restartFinished\n";
9799
restartFinished = true;
98-
std::cout << "Restart of sensors, finished.\n";
100+
std::cout << "Restarting sensors, finished.\n";
99101
}
100102

101103
void callbackOnCompletionCoarseZero() {
102-
std::cout << "Coarse zero of sensors, finished.\n";
104+
coarseZeroFinished = true;
105+
std::cout << "Coarse zero sensors, finished.\n";
103106
}
104107

105108
void callbackOnCompletionFineZero() {
106-
std::cout << "Fine zero of sensors, finished.\n";
109+
fineZeroFinished = true;
110+
std::cout << "Fine zero sensors, finished.\n";
107111
}
108112

109113
static PyObject* callbackOnFinishedWhileRestart_py(PyObject* self, PyObject* args) {
@@ -361,6 +365,8 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent)
361365

362366
PyObject* loadSensors = PyObject_GetAttrString(fServiceInstance, "load_sensors");
363367
PyObject* sensors = PyObject_CallNoArgs(loadSensors);
368+
// =========================================================================
369+
// =========================================================================
364370
PyObject* restartAllSensors = PyObject_GetAttrString(fServiceInstance, "restart_sensors");
365371

366372
if (restartAllSensors == NULL)
@@ -416,16 +422,179 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent)
416422
printLog("restart call ok!");
417423
}
418424

425+
Py_DECREF(restartAllSensors);
426+
Py_DECREF(callback_on_finished);
427+
Py_DECREF(callback_on_error);
428+
Py_DECREF(callback_on_completion);
429+
Py_DECREF(argsRestart);
430+
Py_DECREF(resultRestart);
431+
419432
PyGILState_Release(gstate);
420-
// while (restartFinished == false) {
421-
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
422-
// printLog("waiting...");
423-
// }
424-
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
433+
434+
while (restartFinished == false) {
435+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
436+
}
437+
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
438+
439+
// =========================================================================
440+
// =========== coarse zero =================================================
441+
// =========================================================================
442+
gstate = PyGILState_Ensure();
443+
444+
445+
PyObject* coarseZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "coarse_zero_sensors");
446+
447+
if (coarseZeroAllSensors == NULL)
448+
{
449+
printLog("coarse zero sensors broken");
450+
} else {
451+
printLog("coarseZeroAllSensors ok!");
452+
}
453+
454+
PyObject* callback_on_finished_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileCoarseZero");
455+
if (callback_on_finished_coarse_zero == NULL)
456+
{
457+
printLog("callback on finished coarse zero broken");
458+
} else {
459+
printLog("callback on finished coarse zero ok!");
460+
}
461+
462+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
463+
464+
PyObject* callback_on_error_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileCoarseZero");
465+
if (callback_on_error_coarse_zero == NULL)
466+
{
467+
printLog("callback on error coarse zero broken");
468+
} else {
469+
printLog("callback coarse zero error ok!");
470+
}
471+
472+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
473+
474+
PyObject* callback_on_completion_coarse_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionCoarseZero");
475+
if (callback_on_completion_coarse_zero == NULL)
476+
{
477+
printLog("callback on completion coarse zero broken");
478+
} else {
479+
printLog("callback coarse zero completion ok!");
480+
}
481+
482+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
483+
484+
PyObject* argsCoarseZero = PyTuple_New(4);
485+
PyTuple_SetItem(argsCoarseZero, 0, sensors);
486+
PyTuple_SetItem(argsCoarseZero, 1, callback_on_finished_coarse_zero);
487+
PyTuple_SetItem(argsCoarseZero, 2, callback_on_error_coarse_zero);
488+
PyTuple_SetItem(argsCoarseZero, 3, callback_on_completion_coarse_zero);
489+
490+
coarseZeroFinished = false;
491+
492+
PyObject* resultCoarseZero = PyObject_CallObject(coarseZeroAllSensors, argsCoarseZero);
493+
if (resultCoarseZero == NULL)
494+
{
495+
printLog("call coarsezero call broken");
496+
} else {
497+
printLog("coarse zero call call ok!");
498+
}
499+
500+
Py_DECREF(coarseZeroAllSensors);
501+
Py_DECREF(callback_on_finished_coarse_zero);
502+
Py_DECREF(callback_on_error_coarse_zero);
503+
Py_DECREF(callback_on_completion_coarse_zero);
504+
Py_DECREF(argsCoarseZero);
505+
Py_DECREF(resultCoarseZero);
506+
507+
PyGILState_Release(gstate);
508+
509+
while (coarseZeroFinished == false) {
510+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
511+
}
512+
// =========================================================================
513+
// =========================================================================
514+
515+
516+
// =========================================================================
517+
// ============ fine zero ==================================================
518+
// =========================================================================
519+
gstate = PyGILState_Ensure();
520+
521+
522+
PyObject* fineZeroAllSensors = PyObject_GetAttrString(fServiceInstance, "fine_zero_sensors");
523+
524+
if (fineZeroAllSensors == NULL)
525+
{
526+
printLog("fine zero sensors broken");
527+
} else {
528+
printLog("fineZeroAllSensors ok!");
529+
}
530+
531+
PyObject* callback_on_finished_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnFinishedWhileFineZero");
532+
if (callback_on_finished_fine_zero == NULL)
533+
{
534+
printLog("callback on finished fine zero broken");
535+
} else {
536+
printLog("callback on finished fine zero ok!");
537+
}
538+
539+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
540+
541+
PyObject* callback_on_error_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnErrorWhileFineZero");
542+
if (callback_on_error_fine_zero == NULL)
543+
{
544+
printLog("callback on error fine zero broken");
545+
} else {
546+
printLog("callback fine zero error ok!");
547+
}
548+
549+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
550+
551+
PyObject* callback_on_completion_fine_zero = PyObject_GetAttrString((PyObject*)m_pCallsModule, "callbackOnCompletionFineZero");
552+
if (callback_on_completion_fine_zero == NULL)
553+
{
554+
printLog("callback on completion fine zero broken");
555+
} else {
556+
printLog("callback fine zero completion ok!");
557+
}
558+
559+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
560+
561+
PyObject* argsFineZero = PyTuple_New(4);
562+
PyTuple_SetItem(argsFineZero, 0, sensors);
563+
PyTuple_SetItem(argsFineZero, 1, callback_on_finished_fine_zero);
564+
PyTuple_SetItem(argsFineZero, 2, callback_on_error_fine_zero);
565+
PyTuple_SetItem(argsFineZero, 3, callback_on_completion_fine_zero);
566+
567+
fineZeroFinished = false;
568+
569+
PyObject* resultFineZero = PyObject_CallObject(fineZeroAllSensors, argsFineZero);
570+
if (resultFineZero == NULL)
571+
{
572+
printLog("call finezero call broken");
573+
} else {
574+
printLog("fine zero call call ok!");
575+
}
576+
577+
Py_DECREF(fineZeroAllSensors);
578+
Py_DECREF(callback_on_finished_fine_zero);
579+
Py_DECREF(callback_on_error_fine_zero);
580+
Py_DECREF(callback_on_completion_fine_zero);
581+
Py_DECREF(argsFineZero);
582+
Py_DECREF(resultFineZero);
583+
584+
PyGILState_Release(gstate);
585+
586+
while (fineZeroFinished == false) {
587+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
588+
}
589+
// =========================================================================
590+
// =========================================================================
591+
592+
//
425593
// PyGILState_STATE gstate;
426594
gstate = PyGILState_Ensure();
427595

428596

597+
429598
PyObject* readDataFcn = PyObject_GetAttrString(fServiceInstance, "read_data");
430599
if (readDataFcn == NULL) {
431600
printLog("problem readDataFcn");
@@ -471,12 +640,6 @@ FieldlineAcqSystem::FieldlineAcqSystem(Fieldline* parent)
471640
Py_DECREF(trueTuple);
472641
Py_DECREF(pResult2);
473642
Py_DECREF(loadSensors);
474-
Py_DECREF(restartAllSensors);
475-
Py_DECREF(callback_on_finished);
476-
Py_DECREF(callback_on_error);
477-
Py_DECREF(callback_on_completion);
478-
Py_DECREF(argsRestart);
479-
Py_DECREF(resultRestart);
480643
Py_DECREF(readDataFcn);
481644
Py_DECREF(parserCallback);
482645
Py_DECREF(argsSetDataParser);

0 commit comments

Comments
 (0)