1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
|
//Author: Timothy Pearson <kb9vqf@pearsoncomputing.net>, (C) 2012
//Copyright: See COPYING file that comes with this distribution
#include "define.h"
#include "part.h"
#include <kaboutdata.h> //::createAboutData()
#include <kaction.h>
#include <klocale.h>
#include <kmessagebox.h> //::start()
#include <kparts/genericfactory.h>
#include <kstatusbar.h>
#include <kstdaction.h>
#include <tqfile.h> //encodeName()
#include <tqtimer.h>
#include <tqvbox.h>
#include <tqsocket.h>
#include <tqmutex.h>
#include <tqpushbutton.h>
#include <tqeventloop.h>
#include <tqapplication.h>
#include <unistd.h> //access()
#include <stdint.h>
#include <cmath>
#include "tracewidget.h"
#include "floatspinbox.h"
#include "layout.h"
#define NETWORK_COMM_TIMEOUT_MS 15000
/* exception handling */
struct exit_exception {
int c;
exit_exception(int c):c(c) { }
};
namespace RemoteLab {
typedef KParts::GenericFactory<RemoteLab::ScopePart> Factory;
#define CLIENT_LIBRARY "libremotelab_scope"
K_EXPORT_COMPONENT_FACTORY( libremotelab_scope, RemoteLab::Factory )
ScopePart::ScopePart( TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList& )
: RemoteInstrumentPart( parent, name ), m_traceWidget(0), m_commHandlerState(-1), m_commHandlerMode(0), m_commHandlerCommandState(0), m_connectionActiveAndValid(false),
m_base(0), stopTraceUpdate(false)
{
// Initialize important base class variables
m_clientLibraryName = CLIENT_LIBRARY;
// Initialize mutex
m_instrumentMutex = new TQMutex(false);
// Initialize kpart
setInstance(Factory::instance());
setWidget(new TQVBox(parentWidget, widgetName));
// Create timers
m_forcedUpdateTimer = new TQTimer(this);
connect(m_forcedUpdateTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
m_updateTimeoutTimer = new TQTimer(this);
connect(m_updateTimeoutTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
// Create widgets
m_base = new ScopeBase(widget());
m_traceWidget = m_base->traceWidget;
m_traceWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding));
m_traceWidget->setNumberOfCursors(4);
m_traceWidget->setCursorOrientation(0, TQt::Horizontal);
m_traceWidget->setCursorOrientation(1, TQt::Horizontal);
m_traceWidget->setCursorOrientation(2, TQt::Vertical);
m_traceWidget->setCursorOrientation(3, TQt::Vertical);
m_traceWidget->setCursorEnabled(0, true);
m_traceWidget->setCursorEnabled(1, true);
m_traceWidget->setCursorEnabled(2, true);
m_traceWidget->setCursorEnabled(3, true);
m_traceWidget->setCursorName(0, "Cursor H1");
m_traceWidget->setCursorName(1, "Cursor H2");
m_traceWidget->setCursorName(2, "Cursor V1");
m_traceWidget->setCursorName(3, "Cursor V2");
m_traceWidget->setCursorPosition(0, 25);
m_traceWidget->setCursorPosition(1, 75);
m_traceWidget->setCursorPosition(2, 25);
m_traceWidget->setCursorPosition(3, 75);
m_traceWidget->setZoomBoxEnabled(true);
m_base->traceZoomWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding));
connect(m_traceWidget, SIGNAL(zoomBoxChanged(const TQRectF&)), this, SLOT(updateZoomWidgetLimits(const TQRectF&)));
connect(m_traceWidget, SIGNAL(offsetChanged(uint, double)), m_base->traceZoomWidget, SLOT(setTraceOffset(uint, double)));
m_base->saRefLevel->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed));
m_base->saRefLevel->setFloatMin(-128);
m_base->saRefLevel->setFloatMax(128);
m_base->saRefLevel->setLineStep(1);
connect(m_base->acqStart, SIGNAL(clicked()), this, SLOT(startDAQ()));
connect(m_base->acqStop, SIGNAL(clicked()), this, SLOT(stopDAQ()));
connect(m_base->saRefLevel, SIGNAL(floatValueChanged(double)), this, SLOT(saRefLevelChanged(double)));
TQTimer::singleShot(0, this, TQT_SLOT(postInit()));
}
ScopePart::~ScopePart() {
if (m_instrumentMutex->locked()) {
printf("[WARNING] Exiting when data transfer still in progress!\n\r"); fflush(stdout);
}
disconnectFromServer();
delete m_instrumentMutex;
}
void ScopePart::postInit() {
setUsingFixedSize(false);
}
bool ScopePart::openURL(const KURL &url) {
int ret;
m_connectionActiveAndValid = false;
ret = connectToServer(url.url());
processLockouts();
return (ret != 0);
}
bool ScopePart::closeURL() {
disconnectFromServer();
m_url = KURL();
return true;
}
void ScopePart::processLockouts() {
if (m_connectionActiveAndValid) {
if ((m_commHandlerMode < 2) && (m_commHandlerState < 50)) {
m_base->setEnabled(false);
}
else {
m_base->setEnabled(true);
}
}
else {
m_base->setEnabled(false);
}
}
void ScopePart::disconnectFromServerCallback() {
m_forcedUpdateTimer->stop();
m_updateTimeoutTimer->stop();
m_connectionActiveAndValid = false;
}
void ScopePart::connectionFinishedCallback() {
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop()));
m_tickerState = 0;
m_commHandlerState = 0;
m_commHandlerMode = 0;
m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS);
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
processLockouts();
mainEventLoop();
return;
}
void ScopePart::connectionStatusChangedCallback() {
processLockouts();
}
void ScopePart::setTickerMessage(TQString message) {
m_connectionActiveAndValid = true;
TQString tickerChar;
switch (m_tickerState) {
case 0:
tickerChar = "-";
break;
case 1:
tickerChar = "\\";
break;
case 2:
tickerChar = "|";
break;
case 3:
tickerChar = "/";
break;
}
setStatusMessage(message + TQString("... %1").arg(tickerChar));
m_tickerState++;
if (m_tickerState > 3) {
m_tickerState = 0;
}
}
#define UPDATEDISPLAY_TIMEOUT m_connectionActiveAndValid = false; \
m_tickerState = 0; \
m_commHandlerState = 2; \
m_commHandlerMode = 0; \
m_socket->clearIncomingData(); \
setStatusMessage(i18n("Server ping timeout. Please verify the status of your network connection.")); \
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \
m_instrumentMutex->unlock(); \
return;
#define COMMUNICATIONS_FAILED m_connectionActiveAndValid = false; \
m_tickerState = 0; \
m_commHandlerState = 2; \
m_commHandlerMode = 0; \
m_socket->clearIncomingData(); \
setStatusMessage(i18n("Instrument communication failure. Please verify the status of your network connection.")); \
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \
m_instrumentMutex->unlock(); \
return;
#define SET_WATCHDOG_TIMER if (!m_updateTimeoutTimer->isActive()) m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
#define PAT_WATCHDOG_TIMER m_updateTimeoutTimer->stop(); m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \
setTickerMessage(i18n("Connected"));
#define SET_NEXT_STATE(x) if (m_commHandlerMode == 0) { \
m_commHandlerState = x; \
} \
else { \
m_commHandlerState = 255; \
} \
if (m_commHandlerState < 50) { \
setTickerMessage(i18n("Loading")); \
}
#define EXEC_NEXT_STATE_IMMEDIATELY m_forcedUpdateTimer->start(0, TRUE);
int getNextActiveChannel(int current, bool* activity, int maxtracenumber) {
int ret = -1;
for (int i=current+1; i<=maxtracenumber; i++) {
if (activity[i]) {
ret = i;
break;
}
}
return ret;
}
void ScopePart::mainEventLoop() {
TQDataStream ds(m_socket);
ds.setPrintableData(true);
if (!m_instrumentMutex->tryLock()) {
EXEC_NEXT_STATE_IMMEDIATELY
return;
}
if (m_socket) {
if ((m_commHandlerMode == 0) || (m_commHandlerMode == 1)) {
if (m_commHandlerState == 0) {
// Request scope access
ds << TQString("OSCILLOSCOPE");
m_socket->writeEndOfFrame();
m_commHandlerState = 1;
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 1) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get command status
TQString result;
ds >> result;
m_socket->clearFrameTail();
if (result == "ACK") {
SET_NEXT_STATE(2)
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 2) {
// Reset scope
ds << TQString("RESET");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(3)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 3) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get command status
TQString result;
ds >> result;
m_socket->clearFrameTail();
if (result == "ACK") {
SET_NEXT_STATE(4)
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 4) {
// Get number of horizontal divisions, step 1
ds << TQString("GETHORIZONTALDIVCOUNT");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(5)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 5) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get number of horizontal divisions, step 2
TQString result;
ds >> result;
if (result == "ACK") {
ds >> m_hdivs;
}
m_socket->clearFrameTail();
if (result == "ACK") {
SET_NEXT_STATE(6)
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 6) {
// Get number of vertical divisions, step 1
ds << TQString("GETVERTICALDIVCOUNT");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(7)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 7) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get number of vertical divisions, step 2
TQString result;
ds >> result;
if (result == "ACK") {
ds >> m_vdivs;
}
m_socket->clearFrameTail();
if (result == "ACK") {
SET_NEXT_STATE(8)
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 8) {
// Get number of channels, step 1
ds << TQString("GETNUMBEROFCHANNELS");
m_socket->writeEndOfFrame();
SET_NEXT_STATE(9)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 9) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get number of channels, step 2
TQString result;
ds >> result;
if (result == "ACK") {
ds >> m_maxNumberOfTraces;
if (m_maxNumberOfTraces > MAXTRACES) {
m_maxNumberOfTraces = MAXTRACES;
}
}
m_socket->clearFrameTail();
if (result == "ACK") {
m_currentOpChannel = 1;
SET_NEXT_STATE(10)
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 10) {
// Get channel status, step 1
ds << TQString("GETCHANNELACTIVE");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(11)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 11) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get channel status, step 2
TQString result;
ds >> result;
if (result == "ACK") {
TQ_INT16 active;
ds >> active;
m_channelActive[m_currentOpChannel] = (active != 0);
}
m_socket->clearFrameTail();
if (result == "ACK") {
if (m_currentOpChannel < m_maxNumberOfTraces) {
m_currentOpChannel++;
SET_NEXT_STATE(10)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(12)
}
else {
m_currentOpChannel = 1;
SET_NEXT_STATE(8)
}
}
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 12) {
// Get number of samples in trace, step 1
ds << TQString("GETTRACESAMPLECOUNT");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(13)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 13) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get number of samples in trace, step 2
TQString result;
ds >> result;
if (result == "ACK") {
ds >> m_samplesInTrace[m_currentOpChannel];
}
m_socket->clearFrameTail();
if (result == "ACK") {
m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(12)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(14)
}
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 14) {
// Get volts per division, step 1
ds << TQString("GETVOLTSDIV");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(15)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 15) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get volts per division, step 2
TQString result;
ds >> result;
if (result == "ACK") {
ds >> m_voltsDiv[m_currentOpChannel];
}
m_socket->clearFrameTail();
if (result == "ACK") {
m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(14)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(16)
}
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 16) {
// Get seconds per division, step 1
ds << TQString("GETSECONDSSDIV");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(17)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 17) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get seconds per division, step 2
TQString result;
ds >> result;
if (result == "ACK") {
ds >> m_secsDiv[m_currentOpChannel];
}
m_socket->clearFrameTail();
if (result == "ACK") {
// Update display widget(s)
updateGraticule();
// HACK
// Force resize of parent frame
emit(usingFixedSizeChanged(false));
}
if (result == "ACK") {
m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(16)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(50)
}
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 50) {
// Get trace, step 1
ds << TQString("GETCHANNELTRACE");
ds << m_currentOpChannel;
m_socket->writeEndOfFrame();
SET_NEXT_STATE(51)
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerState == 51) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Get trace, step 2
TQDoubleArray trace;
TQDoubleArray positions;
TQString result;
ds >> result;
if (result == "ACK") {
ds >> trace;
ds >> positions;
}
m_socket->clearFrameTail();
if (result == "ACK") {
// Update display widget(s)
m_traceWidget->setSamples(m_currentOpChannel-1, trace);
m_traceWidget->setPositions(m_currentOpChannel-1, positions);
m_base->traceZoomWidget->setSamples(m_currentOpChannel-1, trace);
m_base->traceZoomWidget->setPositions(m_currentOpChannel-1, positions);
postProcessTrace();
m_traceWidget->repaint(true);
m_base->traceZoomWidget->repaint(true);
}
if (result == "ACK") {
m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces);
if (m_currentOpChannel > 0) {
SET_NEXT_STATE(50)
}
else {
m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces);
SET_NEXT_STATE(50)
}
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerState == 255) {
// Execute pending command
m_commHandlerMode = 2;
m_socket->clearIncomingData();
EXEC_NEXT_STATE_IMMEDIATELY
}
SET_WATCHDOG_TIMER
}
else if (m_commHandlerMode == 2) {
if (m_commHandlerCommandState == 0) {
m_commHandlerMode = 0;
m_commHandlerState = 10;
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerCommandState == 1) {
// Set channel active
ds << TQString("SETCHANNELACTIVE");
ds << m_nextOpChannel;
ds << m_nextOpParameter16;
m_socket->writeEndOfFrame();
m_commHandlerCommandState = 2;
EXEC_NEXT_STATE_IMMEDIATELY
}
else if (m_commHandlerCommandState == 2) {
// Get response data
if (m_socket->canReadFrame()) {
PAT_WATCHDOG_TIMER
// Set channel active, step 2
TQString result;
ds >> result;
m_socket->clearFrameTail();
if (result == "ACK") {
m_commHandlerCommandState = 0;
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
COMMUNICATIONS_FAILED
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT
}
}
}
else if (m_commHandlerCommandState == 3) {
if (stopTraceUpdate == false) {
m_commHandlerCommandState = 0;
EXEC_NEXT_STATE_IMMEDIATELY
}
else {
setTickerMessage(i18n("Data acquisition stopped"));
}
}
}
}
else {
m_commHandlerState = 0;
m_commHandlerCommandState = 0;
}
processLockouts();
m_instrumentMutex->unlock();
}
void ScopePart::postProcessTrace() {
return;
}
void ScopePart::startDAQ() {
// RAJA FIXME
// Also process lockouts...
}
void ScopePart::stopDAQ() {
// RAJA FIXME
// Also process lockouts...
if (m_commHandlerMode < 2) {
stopTraceUpdate = true;
m_commHandlerMode = 1;
m_commHandlerCommandState = 3;
mainEventLoop();
}
}
void ScopePart::updateZoomWidgetLimits(const TQRectF& zoomRect) {
for (int traceno=0; traceno<m_maxNumberOfTraces; traceno++) {
TQRectF fullZoomRect = m_traceWidget->displayLimits(traceno);
double widthSpan = fullZoomRect.width()-fullZoomRect.x();
double heightSpan = fullZoomRect.height()-fullZoomRect.y();
TQRectF zoomLimitsRect((fullZoomRect.x()+(widthSpan*(zoomRect.x()/100.0))), (fullZoomRect.y()+(heightSpan*(zoomRect.y()/100.0))), (fullZoomRect.x()+(widthSpan*((zoomRect.x()/100.0)+(zoomRect.width()/100.0)))), (fullZoomRect.y()+(heightSpan*((zoomRect.y()/100.0)+(zoomRect.height()/100.0)))));
m_base->traceZoomWidget->setDisplayLimits(traceno, zoomLimitsRect);
}
}
void ScopePart::updateGraticule() {
m_traceWidget->setNumberOfHorizontalDivisions(m_hdivs);
m_traceWidget->setNumberOfVerticalDivisions(m_vdivs);
m_base->traceZoomWidget->setNumberOfHorizontalDivisions(m_hdivs);
m_base->traceZoomWidget->setNumberOfVerticalDivisions(m_vdivs);
m_traceWidget->setTraceColor(0, TQColor(255, 255, 255));
m_traceWidget->setTraceColor(1, TQColor(128, 255, 128));
m_traceWidget->setTraceColor(2, TQColor(255, 255, 128));
m_traceWidget->setTraceColor(3, TQColor(128, 128, 255));
m_base->traceZoomWidget->setTraceColor(0, TQColor(255, 255, 255));
m_base->traceZoomWidget->setTraceColor(1, TQColor(128, 255, 128));
m_base->traceZoomWidget->setTraceColor(2, TQColor(255, 255, 128));
m_base->traceZoomWidget->setTraceColor(3, TQColor(128, 128, 255));
for (int traceno=1; traceno<=m_maxNumberOfTraces; traceno++) {
m_traceWidget->setTraceEnabled(traceno-1, m_channelActive[traceno]);
m_traceWidget->setTraceName(traceno-1, TQString("Channel %1").arg(traceno));
m_traceWidget->setTraceHorizontalUnits(traceno-1, "s");
m_traceWidget->setTraceVerticalUnits(traceno-1, "V");
m_base->traceZoomWidget->setTraceEnabled(traceno-1, m_channelActive[traceno], false);
m_base->traceZoomWidget->setTraceName(traceno-1, TQString("Channel %1").arg(traceno));
m_base->traceZoomWidget->setTraceHorizontalUnits(traceno-1, "s");
m_base->traceZoomWidget->setTraceVerticalUnits(traceno-1, "V");
m_traceWidget->setNumberOfSamples(traceno-1, m_samplesInTrace[traceno]);
m_base->traceZoomWidget->setNumberOfSamples(traceno-1, m_samplesInTrace[traceno]);
m_traceWidget->setDisplayLimits(traceno-1, TQRectF(0.0, (m_voltsDiv[traceno]*m_vdivs)/2.0, (m_secsDiv[traceno]*m_hdivs), (m_voltsDiv[traceno]*m_vdivs)/-2.0));
printf("[RAJA DEBUG 700.0] m_voltsDiv[%d]: %f m_vdivs: %d m_secsDiv[%d]: %f m_hdivs: %d\n\r", traceno, m_voltsDiv[traceno], m_vdivs, traceno, m_secsDiv[traceno], m_hdivs); fflush(stdout);
}
updateZoomWidgetLimits(m_traceWidget->zoomBox());
// // Also update controls
// m_base->saRefLevel->blockSignals(true);
// m_base->saRefLevel->setFloatValue(m_voltsDiv);
// m_base->saRefLevel->blockSignals(false);
}
void ScopePart::saRefLevelChanged(double newval) {
// if (m_commHandlerMode < 2) {
// m_voltsDiv = newval;
// m_commHandlerMode = 1;
// m_commHandlerCommandState = 1;
// mainEventLoop();
// }
}
KAboutData* ScopePart::createAboutData() {
return new KAboutData( APP_NAME, I18N_NOOP( APP_PRETTYNAME ), APP_VERSION );
}
} //namespace RemoteLab
#include "part.moc"
|