-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombinedAPISampleDlg.cpp
More file actions
1750 lines (1483 loc) · 54.1 KB
/
Copy pathCombinedAPISampleDlg.cpp
File metadata and controls
1750 lines (1483 loc) · 54.1 KB
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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************
Name: CombinedAPISampleDlg.cpp
Description: This is the main dialog.
All Northern Digital Inc. ("NDI") Media and/or Sample Code and/or
Sample Code Documentation (collectively referred to as "Sample Code")
is licensed and provided "as is" without warranty of any kind. The
licensee, by use of the Sample Code, warrants to NDI that the Sample
Code is fit for the use and purpose for which the licensee intends to
use the Sample Code. NDI makes no warranties, express or implied, that
the functions contained in the Sample Code will meet the licensee’s
requirements or that the operation of the programs contained therein
will be error free. This warranty as expressed herein is exclusive
and NDI expressly disclaims any and all express and/or implied, in fact
or in law, warranties, representations, and conditions of every kind
pertaining in any way to the Sample Code licensed and provided by NDI
hereunder, including without limitation, each warranty and/or condition
of quality, merchantability, description, operation, adequacy,
suitability, fitness for particular purpose, title, interference with
use or enjoyment, and/or non infringement, whether express or implied
by statute, common law, usage of trade, course of dealing, custom, or
otherwise. No NDI dealer, distributor, agent or employee is authorized
to make any modification or addition to this warranty.
In no event shall NDI nor any of its employees be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages,
sundry damages or any damages whatsoever, including, but not limited to,
procurement of substitute goods or services, loss of use, data or profits,
or business interruption, however caused. In no event shall NDI’s
liability to the licensee exceed the amount paid by the licensee for the S
ample Code or any NDI products that accompany the Sample Code. The said
imitations and exclusions of liability shall apply whether or not any
such damages are construed as arising from a breach of a representation,
warranty, guarantee, covenant, obligation, condition or fundamental term
or on any theory of liability, whether in contract, strict liability, or
tort (including negligence or otherwise) arising in any way out of the
use of the Sample Code even if advised of the possibility of such damage.
In no event shall NDI be liable for any claims, losses, damages, judgments,
costs, awards, expenses or liabilities of any kind whatsoever arising
directly or indirectly from any injury to person or property, arising
from the Sample Code or any use thereof.
Copyright (C) 2002, 2003, Northern Digital Inc. All rights reserved.
*****************************************************************/
/*****************************************************************
C Library Files Included
*****************************************************************/
/* None. */
/*****************************************************************
Project Files Included
*****************************************************************/
#include "stdafx.h"
#include "CombinedAPISample.h"
#include "CombinedAPISampleDlg.h"
#include "COMPortSettings.h"
#include "ROMFileDlg.h"
#include "SystemFeaturesDlg.h"
#include "IlluminatorFiringRate.h"
#include "ProgramOptions.h"
#include "NewAlertFlagsDlg.h"
#include "INIFileRW.h"
#include "Conversions.h"
/*****************************************************************
Defines
*****************************************************************/
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/*****************************************************************
Global Variables
*****************************************************************/
bool
m_bStopTracking, /* flag that tells the thread to stop tracking */
m_bIsTracking; /* flag that specifies if we are tracking */
UINT FillTrackingTable(LPVOID pParam); /* FillTrackingTable thread declaration */
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCombinedAPISampleDlg dialog
CCombinedAPISampleDlg::CCombinedAPISampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCombinedAPISampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCombinedAPISampleDlg)
m_szFrameNumber = _T("");
m_bInterference = FALSE;
m_szSystemMode = _T("");
m_bUse0x0800Option = FALSE;
m_bUseEulerAngles = FALSE;
m_nTrackingMode = 0;
m_szManufID = _T("");
m_bPortEnabled = FALSE;
m_bPortInitialized = FALSE;
m_szSerialNo = _T("");
m_szToolRev = _T("");
m_szToolType = _T("");
m_szPartNumber = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCombinedAPISampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCombinedAPISampleDlg)
DDX_Control(pDX, IDC_FRAME_NO, m_ctlFrameNo);
DDX_Control(pDX, IDC_PORT_HANDLES, m_ctlPortHandleCB);
DDX_Control(pDX, IDC_REFERENCE_HANDLE_CMB, m_ctlRefHandleCB);
DDX_Control(pDX, IDC_TRACKING_LIST, m_ctlTrackingList);
DDX_Text(pDX, IDC_FRAME_NO, m_szFrameNumber);
DDX_Text(pDX, IDC_SYSTEMMODE, m_szSystemMode);
DDX_Check(pDX, IDC_TRACKING_REPORT_OOV, m_bUse0x0800Option);
DDX_Check(pDX, IDC_EULER_ANGLES, m_bUseEulerAngles);
DDX_Radio(pDX, IDC_TRACKING_TX, m_nTrackingMode);
DDX_Text(pDX, IDC_MANUF_ID, m_szManufID);
DDX_Check(pDX, IDC_PORT_ENABLED, m_bPortEnabled);
DDX_Check(pDX, IDC_PORT_INIT, m_bPortInitialized);
DDX_Text(pDX, IDC_SERIAL_NO, m_szSerialNo);
DDX_Text(pDX, IDC_TOOL_REV, m_szToolRev);
DDX_Text(pDX, IDC_TOOL_TYPE, m_szToolType);
DDX_Text(pDX, IDC_PARTNUMBER, m_szPartNumber);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCombinedAPISampleDlg, CDialog)
//{{AFX_MSG_MAP(CCombinedAPISampleDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RESET_SYSTEM, OnResetSystem)
ON_BN_CLICKED(IDC_INITIALIZE_SYSTEM, OnInitializeSystem)
ON_BN_CLICKED(IDC_ACTIVATE_PORTS, OnActivatePorts)
ON_BN_CLICKED(IDC_TRACKING_BUT, OnTrackingBut)
ON_MESSAGE(WM_FILL_LIST, nGetSystemTransformData)
ON_MESSAGE(WM_COM_PORT_TO, nComPortTimeout)
ON_COMMAND(ID_FILE_EXIT, OnFileExit)
ON_COMMAND(ID_SETTINGS_COMPORTSETTINGS, OnSettingsComportsettings)
ON_COMMAND(ID_SETTINGS_ROMFILESETTINGS, OnSettingsRomfilesettings)
ON_COMMAND(ID_SYSTEM_ACTIVATEPORTS, OnSystemActivateports)
ON_COMMAND(ID_SYSTEM_INITIALIZESYSTEM, OnSystemInitializesystem)
ON_COMMAND(ID_SYSTEM_STARTTRACKING, OnSystemStarttracking)
ON_COMMAND(ID_SYSTEM_STOPTRACKING, OnSystemStoptracking)
ON_COMMAND(ID_VIEW_SYSTEMPROPERTIES, OnViewSystemproperties)
ON_COMMAND(ID_VIEW_DIAGNOSTICALERTS, OnViewAlertFlags)
ON_CBN_SELCHANGE(IDC_PORT_HANDLES, OnSelchangePortHandles)
ON_CBN_SELCHANGE(IDC_REFERENCE_HANDLE_CMB, OnSelchangeRefPortHandle)
ON_COMMAND(ID_OPTIONS_ILLUMINATORFIRINGRATE, OnOptionsIlluminatorfiringrate)
ON_COMMAND(ID_OPTIONS_PROGRAMOPTIONS, OnOptionsProgramoptions)
ON_COMMAND(ID_HELP_ABOUTCOMBINEDAPISAMPLE, OnHelpAboutcombinedapisample)
ON_BN_CLICKED(IDC_PORT_ENABLED, OnPortEnabled)
ON_BN_CLICKED(IDC_DIAGNOSTICS_PENDING, OnDiagnosticsPending)
ON_BN_CLICKED(IDC_EULER_ANGLES, OnEulerAngles)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCombinedAPISampleDlg message handlers
/*****************************************************************
OnInitDialog
VISUAL C++ FUNCTION CALL
*****************************************************************/
BOOL CCombinedAPISampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
/*
* declare pCommandHandling and load the accelerators
*/
pCommandHandling = new CCommandHandling;
m_hAccel = LoadAccelerators(NULL,
MAKEINTRESOURCE(IDR_MAIN_MENU));
/*
* setup the table headings
*/
m_ctlTrackingList.InsertColumn( 0, "Handle", LVCFMT_LEFT, 49, -1 );
m_ctlTrackingList.InsertColumn( 1, "Port", LVCFMT_LEFT, 0, -1 );
m_ctlTrackingList.InsertColumn( 2, "Tx", LVCFMT_LEFT, 65, -1 );
m_ctlTrackingList.InsertColumn( 3, "Ty", LVCFMT_LEFT, 65, -1 );
m_ctlTrackingList.InsertColumn( 4, "Tz", LVCFMT_LEFT, 65, -1 );
m_ctlTrackingList.InsertColumn( 5, "Qo", LVCFMT_LEFT, 65, -1 );
m_ctlTrackingList.InsertColumn( 6, "Qx", LVCFMT_LEFT, 65, -1 );
m_ctlTrackingList.InsertColumn( 7, "Qy", LVCFMT_LEFT, 65, -1 );
m_ctlTrackingList.InsertColumn( 8, "Qz", LVCFMT_LEFT, 65, -1 );
m_ctlTrackingList.InsertColumn( 9, "Error", LVCFMT_LEFT, 60, -1 );
m_ctlTrackingList.InsertColumn( 10, "Status", LVCFMT_LEFT, 42, -1 );
m_ctlTrackingList.SetExtendedStyle(LVS_EX_FULLROWSELECT );
/*
* set initial dialog mode
*/
m_szSystemMode = "Setup Mode";
SetMode( MODE_PRE_INIT );
UpdateData(false);
/* variable initialization */
m_bStopTracking = FALSE;
m_bIsTracking = FALSE;
m_bResetHardware = FALSE;
m_bWireless = FALSE;
m_bSystemInitialized = FALSE;
m_bPortsActivated = FALSE;
m_nCOMPort = 0;
return TRUE; // return TRUE unless you set the focus to a control
}/* OnInitDialog */
/*****************************************************************
OnSysCommand
VISUAL C++ FUNCTION CALL
*****************************************************************/
void CCombinedAPISampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
/*****************************************************************
OnPaint
VISUAL C++ FUNCTION CALL
*****************************************************************/
void CCombinedAPISampleDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
/*****************************************************************
OnQueryDragIcon
VISUAL C++ FUNCTION CALL
*****************************************************************/
HCURSOR CCombinedAPISampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/*****************************************************************
DestroyWindow
VISUAL C++ FUNCTION CALL
*****************************************************************/
BOOL CCombinedAPISampleDlg::DestroyWindow()
{
/*
* if we are tracking, stop. Then close com port and do clean up
*/
if ( m_bIsTracking )
nStopTracking();
pCommandHandling->nCloseComPorts();
if ( pCommandHandling )
delete ( pCommandHandling );
return CDialog::DestroyWindow();
}
/*****************************************************************
PreTranslateMessage
VISUAL C++ FUNCTION CALL
*****************************************************************/
BOOL CCombinedAPISampleDlg::PreTranslateMessage(MSG* pMsg)
{
if (m_hAccel && TranslateAccelerator(GetSafeHwnd(), m_hAccel, pMsg))
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
/*****************************************************************
Name: OnResetSystem
Inputs:
None.
Return Value:
None.
Description: This routine handles what happens when the user
presses the Reset System button. It resets the
system they are connected to.
*****************************************************************/
void CCombinedAPISampleDlg::OnResetSystem()
{
CWaitCursor
wait;
int
nRet = 0;
/*
* read the reset variable from the ini file, this tells us
* if you want to reset the system.
*/
/*
* This feature is useful for debugging only
*/
ReadINIParm( "Communication", "Reset Hardware", "0", &m_bResetHardware );
ReadINIParm( "Communication", "COM Port", "0", &m_nCOMPort );
ReadINIParm( "Communication", "Wireless", "0", &m_bWireless );
pCommandHandling->nCloseComPorts();
if (!pCommandHandling->nOpenComPort( m_nCOMPort ))
{
MessageBox( "COM Port could not be opened. "
"Check your COM Port settings and\n"
"make sure you system is turned on.",
"COM ERROR", MB_ICONERROR|MB_SYSTEMMODAL|MB_SETFOREGROUND );
return;
} /* if */
if ( m_bResetHardware )
{
if( !pCommandHandling->nHardWareReset(m_bWireless) )
return;
if ( !pCommandHandling->nSetSystemComParms( 0, 0, 0, 0, 0))
return;
} /* if */
/*
* set the new mode
*/
m_szSystemMode = "Setup Mode";
SetMode( MODE_PRE_INIT );
MessageBox( "System reset successful", "Reset", MB_ICONINFORMATION|MB_SYSTEMMODAL|MB_SETFOREGROUND );
UpdateData(false);
} /* OnResetSystem */
/*****************************************************************
Name: OnInitializeSystem
Inputs:
None.
Return Value:
None.
Description: This routine handles what happen when the user
presses the Intialize System button. We initialize
the System.
*****************************************************************/
void CCombinedAPISampleDlg::OnInitializeSystem()
{
int
nBaudRate = 0,
nStopBits = 0,
nParity = 0,
nDataBits = 0,
nHardware = 0,
nWireless = 0;
CWaitCursor
wait;
/*
* read the COM port parameters from the ini file
*/
ReadINIParm( "Communication", "Baud Rate", "0", &nBaudRate );
ReadINIParm( "Communication", "Stop Bits", "0", &nStopBits );
ReadINIParm( "Communication", "Parity", "0", &nParity );
ReadINIParm( "Communication", "Data Bits", "0", &nDataBits );
ReadINIParm( "Communication", "Hardware", "0", &nHardware );
ReadINIParm( "Communication", "COM Port", "0", &m_nCOMPort );
ReadINIParm( "Communication", "Wireless", "0", &m_bWireless );
/*
* This feature is useful for debugging only, m_bResetHardware is set to
* TRUE to disable it.
*/
ReadINIParm( "Communication", "Reset Hardware", "0", &m_bResetHardware );
/*
* close, then open the port
*/
pCommandHandling->nCloseComPorts();
if (!pCommandHandling->nOpenComPort( m_nCOMPort ))
{
MessageBox( "COM Port could not be opened. "
"Check your COM Port settings and\n"
"make sure you system is turned on.",
"COM ERROR", MB_ICONERROR|MB_SYSTEMMODAL|MB_SETFOREGROUND );
return;
} /* if */
/*
* if we are supposed to reset, call the reset now
*/
if ( m_bResetHardware )
{
if (!pCommandHandling->nHardWareReset(m_bWireless))
return;
}/* if */
/*
* get the timeout values for the commands
* this will return an error with all other systems, other than Vicra
*/
pCommandHandling->CreateTimeoutTable();
/*
* set the System COM Port parameters, then the computers COM Port parameters.
* if that is successful, initialize the system
*/
if(pCommandHandling->nSetSystemComParms( nBaudRate, nDataBits, nParity, nStopBits, nHardware ))
{
if(pCommandHandling->nSetCompCommParms( nBaudRate, nDataBits, nParity, nStopBits, nHardware ))
{
if(pCommandHandling->nInitializeSystem())
{
/*
* get the system information
*/
if (!pCommandHandling->nGetSystemInfo())
{
/*
* Check system type: Polaris, Polaris Accedo, and Aurora
*/
MessageBox( "Could not determine type of system\n"
"(Polaris, Polaris Accedo, Polaris Vicra or Aurora)",
"INIT ERROR", MB_ICONERROR|MB_SYSTEMMODAL|MB_SETFOREGROUND );
return;
} /* if */
/*
* Set firing rate if system type is Polaris or Polaris Accedo.
*/
if( pCommandHandling->m_dtSystemInformation.nTypeofSystem != AURORA_SYSTEM )
{
pCommandHandling->nSetFiringRate();
}/* if */
m_szSystemMode = "System Initialized";
SetMode( MODE_INIT );
UpdateData(false);
m_bSystemInitialized = TRUE;
MessageBox( "System successfully intialized", "Initialization", MB_ICONINFORMATION|MB_SYSTEMMODAL|MB_SETFOREGROUND );
return;
} /* if */
else
{
MessageBox( "System could not be initialized. "
"Check your COM Port settings, make sure your\n"
"system is turned on and the system components are compatible.",
"INIT ERROR", MB_ICONERROR|MB_SYSTEMMODAL|MB_SETFOREGROUND );
}/* else */
}/* if */
}/* if */
} /* OnInitializeSystem */
/*****************************************************************
Name: OnActivePorts
Inputs:
None.
Return Value:
None.
Description: This routine handles what happens when the user presses
the active ports button.
*****************************************************************/
void CCombinedAPISampleDlg::OnActivatePorts()
{
nActivatePorts();
} /* OnActivatePorts */
/*****************************************************************
Name: OnTrackingBut
Inputs:
None.
Return Value:
None.
Description: This routine handles what happens when the user
presses the Tracking Button.
*****************************************************************/
void CCombinedAPISampleDlg::OnTrackingBut()
{
CWaitCursor
wait;
CString
szButtonText;
GetDlgItem( IDC_TRACKING_BUT )->GetWindowText( szButtonText );
/* if the text read Start, then we start, else we stop tracking */
if ( szButtonText == "&Start Tracking" )
nStartTracking();
else
nStopTracking();
} /* OnTrackingBut */
/*****************************************************************
Name: nActivePorts
Inputs:
None.
Return Value:
int - 1 if successful, 0 otherwise
Description: This routine actives the ports plugged into the system
*****************************************************************/
int CCombinedAPISampleDlg::nActivatePorts()
{
CWaitCursor
wait;
char
pszPortID[9];
int
i = 0;
/*
* if we can active the ports, we then fill the port information
* on the main dialog
*/
if (pCommandHandling->nActivateAllPorts())
{
m_bPortsActivated = TRUE;
m_ctlPortHandleCB.ResetContent();
m_ctlRefHandleCB.ResetContent();
m_ctlTrackingList.DeleteAllItems();
m_szManufID = _T("");
m_bPortEnabled = FALSE;
m_bPortInitialized = FALSE;
m_szSerialNo = _T("");
m_szToolRev = _T("");
m_szToolType = _T("");
m_szPartNumber = _T("");
UpdateData(false);
for ( int i = NO_HANDLES; i > 0; i-- )
{
if ( pCommandHandling->m_dtHandleInformation[i].HandleInfo.bInitialized == 1 )
{
sprintf( pszPortID, "%02X", i );
if( pCommandHandling->m_dtHandleInformation[i].szToolType[1] != '8' )
{
m_ctlTrackingList.InsertItem( 0, NULL );
m_ctlTrackingList.SetItemText( 0, 1,
pCommandHandling->m_dtHandleInformation[i].szPhysicalPort );
m_ctlTrackingList.SetItemText( 0, 0, pszPortID );
}/* if */
m_ctlPortHandleCB.AddString( pszPortID );
m_ctlRefHandleCB.AddString( pszPortID );
} /* if */
} /* for */
m_ctlRefHandleCB.InsertString( 0, "None" );
GetDlgItem( IDC_PORT_HANDLES )->EnableWindow( TRUE );
GetDlgItem( IDC_REFERENCE_HANDLE_CMB )->EnableWindow( TRUE );
m_ctlRefHandleCB.SetCurSel(0);
SetMode( MODE_ACTIVATED );
if (!m_bIsTracking)
MessageBox( "Ports successfully activated", "Port Activation",
MB_ICONINFORMATION|MB_SYSTEMMODAL|MB_SETFOREGROUND );
return 1;
} /* if */
m_bPortsActivated = FALSE;
MessageBox( "Ports could not be activated.\n"
"Check your SROM image file settings and\n"
"make sure your system is turned on and initialized.",
"PORT ACTIVATION ERROR", MB_ICONERROR|MB_SYSTEMMODAL|MB_SETFOREGROUND );
SetMode( MODE_PRE_INIT );
return 0;
} /* nActivatePorts */
/*****************************************************************
Name: nStartTracking
Inputs:
None.
Return Value:
int - 1 if successful, 0 otherwise
Description: This routine starts the System tracking
*****************************************************************/
int CCombinedAPISampleDlg::nStartTracking()
{
if ( pCommandHandling->nStartTracking() )
{
/*
* if we can start tracking, set the appropriate window text,
* start the tracking thread and set the mode.
*/
m_bIsTracking = TRUE;
m_bStopTracking = FALSE;
m_szSystemMode = "System Tracking";
GetDlgItem( IDC_TRACKING_BUT )->SetWindowText("S&top Tracking");
GetDlgItem( IDC_PORT_ENABLED )->EnableWindow( FALSE );
SetMode( MODE_TRACKING );
/* EC-03-0071 */
if (m_ctlPortHandleCB.GetCount() > 0)
{
m_ctlPortHandleCB.SetCurSel( 0 );
OnSelchangePortHandles();
}
UpdateData(false);
AfxBeginThread( FillTrackingTable,
m_hWnd,
THREAD_PRIORITY_NORMAL,
0,
0 );
return 1;
} /* if */
return 0;
} /* nStartTracking */
/*****************************************************************
Name: nStopTracking
Inputs:
None.
Return Value:
int - 1 if successful, 0 otherwise
Description:
This routine stops the tracking procedure.
*****************************************************************/
int CCombinedAPISampleDlg::nStopTracking()
{
if ( pCommandHandling->nStopTracking() )
{
/*
* set the variable that will stop the thread.
* set the text on the dialog and put program in proper mode.
*/
m_bIsTracking = FALSE;
m_bStopTracking = TRUE;
GetDlgItem( IDC_TRACKING_BUT )->SetWindowText("&Start Tracking");
m_szSystemMode = "System Initialized";
SetMode( MODE_ACTIVATED );
GetDlgItem( IDC_TRACKING_BUT )->SetWindowText("&Start Tracking");
if ( m_ctlPortHandleCB.GetCurSel() > -1 )
GetDlgItem( IDC_PORT_ENABLED )->EnableWindow( TRUE );
UpdateData(false);
return 1;
} /* if */
return 0;
} /* nStopTracking */
/*****************************************************************
Name: FillTrackingTable
Inputs:
input LPVOID pParam - normal thread input
Return Value:
UINT - normal thread return
Description:
This is the thread call that controls the collection of data
This thread allows the user to perform other tasks
within the program while data is being collected
*****************************************************************/
UINT FillTrackingTable( LPVOID pParam)
{
HWND hWnd = (HWND)pParam;
while ( !m_bStopTracking )
{
/*
* while tracking, post messages to fill the list
*/
if ( m_bIsTracking )
::SendMessage( hWnd, WM_FILL_LIST, 0, 0 );
else
m_bStopTracking = TRUE;
}/* while */
/* when tracking stopped, kill the thread */
m_bStopTracking = FALSE;
AfxEndThread( 0, TRUE );
return 0;
} /* FillTrackingTable */
/*****************************************************************
Name: nGetSystemTransformData
Inputs:
UNIT wParam and LONG lParam are normal message handling inputs
Return Value:
LONG is the normal return for a message handling routine
Description:
This routine is the message handler for a WM_FILL_LIST posting.
This routine gets the next set of transformation data and displays
it in the main dialog.
*****************************************************************/
//Andrew Global
FILE * pFile;
SYSTEMTIME st;
int counter = 0;
LONG CCombinedAPISampleDlg::nGetSystemTransformData( UINT wParam, LONG lParam )
{
//ANDREW'S CSV RECORD FILE
/* fprintf example */
if (counter == 0) {
//Done only at the very start:
GetSystemTime(&st);
pFile = fopen("NDIdata_snakeravenTest_2_2_21.csv", "w"); //write new file
fprintf(pFile, "Test Date: \n"); //Write today's date and time
fprintf(pFile, "day, month, year, hour, minute, second, milliseconds\n");
fprintf(pFile, "%d, %d, %d, %d, %d , %d , %d \n", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
//Start recording data:
counter++;
//Old way
//fprintf(pFile, "\nSample:, %d,\n",counter);
//fprintf(pFile, "Hour, Minutes, Seconds, ms \n");
//fprintf(pFile, "%d, %d , %d , %d \n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
//fprintf(pFile, "sensor, X, Y, Z, qo, qx, qy, qz\n");
//New way 2020: for all 4 sensors
fprintf(pFile, "\nSample:,Hour,Minutes,Seconds,ms,Xa,Ya,Za,qoa,qxa,qya,qza,Xb,Yb,Zb,qob,qxb,qyb,qzb,Xc,Yc,Zc,qoc,qxc,qyc,qzc,Xd,Yd,Zd,qod,qxd,qyd,qzd\n");
fprintf(pFile, "%d, %d , %d , %d, %d,", counter, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
//finish start
}
else {
//Every other loop:
GetSystemTime(&st);
//continue recording data:
counter++;
//fprintf(pFile, "\nSample:, %d,\n", counter);
//fprintf(pFile, "Hour, Minutes, Seconds, ms \n");
//fprintf(pFile, "%d, %d , %d , %d \n", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
//fprintf(pFile, "sensor, X, Y, Z, qo, qx, qy, qz\n");
//New way 2020
fprintf(pFile, "%d, %d , %d , %d, %d,", counter, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
}
//
char
pszTemp[256];
CString
szCBHandle,
szPortNo;
int
nRow = -1;
Rotation
dtEulerRot;
if (!m_bIsTracking)
return 0;
UpdateData(true);
/*
* if tracking mode is 0, we are asking for TX data, else we are
* asking for BX data.
*/
if ( m_nTrackingMode == 0 )
{
if ( !pCommandHandling->nGetTXTransforms( m_bUse0x0800Option ? true : false ) )
return 0;
} /* if */
else if ( m_nTrackingMode == 1 )
{
if ( !pCommandHandling->nGetBXTransforms( m_bUse0x0800Option ? true : false ) )
return 0;
} /* else if */
/* check for system flags */
GetDlgItem(IDC_TEMPERATURE_NOTE)->SetWindowText(pCommandHandling->m_dtSystemInformation.bTemperatureOutOfRange ?
"Temperature out of range" : "Temperature within range" );
GetDlgItem(IDC_DIAGNOSTICS_PENDING)->EnableWindow(pCommandHandling->m_dtSystemInformation.bDiagnosticsPending);
UpdateData(false);
/*
* if a new port has become occupied we do the following:
* 1) Stop tracking
* 2) Activate Ports
* 3) Start Tracking
*/
if ( pCommandHandling->m_dtSystemInformation.bPortOccupied )
{
if ( pCommandHandling->nStopTracking() &&
nActivatePorts() &&
pCommandHandling->nStartTracking() )
{
return 1;
}/* if */
/*
* We don't want the tracking thread to track if
* activating the ports failed!
*/
m_bStopTracking = true;
m_bIsTracking = FALSE;
return 0;
} /* if */
//FOR LOOP ABOUT EACH SENSOR
for ( int i = 0; i < NO_HANDLES; i ++ )
{
if ( pCommandHandling->m_dtHandleInformation[i].HandleInfo.bInitialized > 0 &&
pCommandHandling->m_dtHandleInformation[i].szToolType[1] != '8' )
{
/* only update the frame if the handle isn't disabled*/
if ( pCommandHandling->m_dtHandleInformation[i].Xfrms.ulFlags == TRANSFORM_VALID ||
pCommandHandling->m_dtHandleInformation[i].Xfrms.ulFlags == TRANSFORM_MISSING )
{
m_szFrameNumber.Format( "%d",
pCommandHandling->m_dtHandleInformation[i].Xfrms.ulFrameNumber );
UpdateData(false);
m_ctlFrameNo.RedrawWindow();
}/* if */
if( i == pCommandHandling->m_nRefHandle )
sprintf( pszTemp, "R%02X", i );
else
sprintf( pszTemp, "%02X", i );
for ( int j = nRow+1; j < m_ctlTrackingList.GetItemCount(); j++ )
{
szPortNo = m_ctlTrackingList.GetItemText( j, 1 );
if ( pCommandHandling->m_dtHandleInformation[i].szPhysicalPort == szPortNo )
{
nRow = j;
break;
} /* if */
//nRow = -1;
} /* for */
/* fill the table */
m_ctlTrackingList.SetItemText( nRow, 0, pszTemp );
if ( pCommandHandling->m_dtHandleInformation[i].Xfrms.ulFlags == TRANSFORM_VALID )
{
sprintf( pszTemp, "%.2f",
pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.x );
m_ctlTrackingList.SetItemText( nRow, 2, pszTemp );
sprintf( pszTemp, "%.2f",
pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.y );
m_ctlTrackingList.SetItemText( nRow, 3, pszTemp );
sprintf( pszTemp, "%.2f",
pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.z );
m_ctlTrackingList.SetItemText( nRow, 4, pszTemp );
//Andrew's Data recording: position
//fprintf(pFile, " %x , %.4f , %.4f , %.4f, ", i , pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.x, pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.y, pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.z);
//new way 2020
fprintf(pFile, "%.4f , %.4f , %.4f, ", pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.x, pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.y, pCommandHandling->m_dtHandleInformation[i].Xfrms.translation.z);
////
if( !m_bUseEulerAngles )
{
sprintf( pszTemp, "%.4f",
pCommandHandling->m_dtHandleInformation[i].Xfrms.rotation.q0 );
m_ctlTrackingList.SetItemText( nRow, 5, pszTemp );
sprintf( pszTemp, "%.4f",
pCommandHandling->m_dtHandleInformation[i].Xfrms.rotation.qx );
m_ctlTrackingList.SetItemText( nRow, 6, pszTemp );
sprintf( pszTemp, "%.4f",
pCommandHandling->m_dtHandleInformation[i].Xfrms.rotation.qy );
m_ctlTrackingList.SetItemText( nRow, 7, pszTemp );
sprintf( pszTemp, "%.4f",
pCommandHandling->m_dtHandleInformation[i].Xfrms.rotation.qz );