-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathRTADlg.cpp
More file actions
884 lines (754 loc) · 26.4 KB
/
RTADlg.cpp
File metadata and controls
884 lines (754 loc) · 26.4 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
#include "stdafx.h"
#include "ScannerSDKSampleApp.h"
#include "RTADlg.h"
#include "afxdialogex.h"
#include <chrono>
#include <ctime>
#include <sstream>
#include <iomanip>
#include "QuickXmlParser.h"
#include "LogsDlg.h"
#include <vector>
// CRTADlg dialog
IMPLEMENT_DYNAMIC(CRTADlg, CDialogEx)
BOOL inRTAEventStatusView = FALSE;
BOOL inRegisterEventView = FALSE;
CRTADlg::CRTADlg(CWnd* pParent /*=nullptr*/)
: CDialog(IDD_RTA, pParent)
{
}
CRTADlg::~CRTADlg()
{
}
void CRTADlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RTAEventsLog, RtaEventLogGridControl);
DDX_Control(pDX, IDC_LIST3, RtaEventsGrid);
DDX_Check(pDX, IDC_CHECK1, RtaSuspend);
DDX_Text(pDX, IDC_RTA_STATE, RtaState);
DDX_Control(pDX, IDC_BUTTON1, GetSupportedRTAEvents);
DDX_Control(pDX, IDC_BUTTON2, GetRegisteredRTAEvents);
DDX_Control(pDX, IDC_BUTTON3, RegisterRTAEvents);
DDX_Control(pDX, IDC_BUTTON4, SetRTAEventStatus);
DDX_Control(pDX, IDC_BUTTON5, GetRTAEventStatus);
DDX_Control(pDX, IDC_BUTTON6, ClearAll);
DDX_Control(pDX, IDC_BUTTON7, GetRTAState);
DDX_Control(pDX, IDC_BUTTON8, ClearEvents);
DDX_Control(pDX, IDC_CHECK1, RTASuspendCheck);
}
BEGIN_MESSAGE_MAP(CRTADlg, CDialog)
ON_BN_CLICKED(IDC_CHECK1, &CRTADlg::OnCheckedSuspendReportingAlerts)
ON_BN_CLICKED(IDC_BUTTON1, &CRTADlg::OnGetSupportedRTAEvents)
ON_BN_CLICKED(IDC_BUTTON2, &CRTADlg::OnGetRegisteredRTAEvents)
ON_BN_CLICKED(IDC_BUTTON3, &CRTADlg::OnRegisterRTAEvents)
ON_BN_CLICKED(IDC_BUTTON4, &CRTADlg::OnSetRTAEventStatus)
ON_BN_CLICKED(IDC_BUTTON5, &CRTADlg::OnGetRTAEventStatus)
ON_BN_CLICKED(IDC_BUTTON6, &CRTADlg::OnClearAll)
ON_BN_CLICKED(IDC_BUTTON7, &CRTADlg::OnGetRTAState)
ON_BN_CLICKED(IDC_BUTTON8, &CRTADlg::OnClearEventLog)
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
BOOL CRTADlg::OnInitDialog() //Initializing the headers of the RTA Event Log grid
{
CDialog::OnInitDialog();
InitRTAEventsLogAttribList();
RtaEventsGrid.ClearList();
RtaSuspend = FALSE;
return TRUE;
}
void CRTADlg::InitRTAEventsLogAttribList()
{
CRtaListCtrl::tooltips = {
{L"30012", L"9",L"Gifted Batt. Percentage",L"Value below min",L""},
{L"30012", L"7",L"Gifted Batt. Percentage",L"Value above max",L""},
{L"38001", L"7",L"RTA Scanner idle",L"Value above max",L""},
{L"38003", L"13",L"RTA virtual tether alert",L"Alarm",L""},
{L"38004", L"7",L"RTA Scanner out of cradle",L"Value above min",L""},
{L"616", L"2",L"Config file",L"State any",L""}
};
//Setting headers for the RTA Event Log grid
RtaEventLogGridControl.SetHeader(0,_T("Date Time"), 120, TRUE);
RtaEventLogGridControl.SetHeader(1,_T("Model"), 140, TRUE);
RtaEventLogGridControl.SetHeader(2,_T("Serial Number"), 110, TRUE);
RtaEventLogGridControl.SetHeader(3,_T("Event"), 50, TRUE);
RtaEventLogGridControl.SetHeader(4,_T("Stat"), 50, TRUE);
RtaEventLogGridControl.SetHeader(5,_T("Data 1"), 50, TRUE);
RtaEventLogGridControl.SetHeader(6,_T("Data 2"), 50, TRUE);
}
void CRTADlg::InitRTAGetEventsAttribList()
{
inRegisterEventView = FALSE;
inRTAEventStatusView = TRUE;
RtaEventsGrid.ClearList(); // Clear the existing list
CRtaListCtrl::tooltips = {
{L"30012", L"9",L"Gifted Batt. Percentage",L"Value below min",L""},
{L"30012", L"7",L"Gifted Batt. Percentage",L"Value above max",L""},
{L"38001", L"7",L"RTA Scanner idle",L"Value above max",L""},
{L"38003", L"13",L"RTA virtual tether alert",L"Alarm",L""},
{L"38004", L"7",L"RTA Scanner out of cradle",L"Value above min",L""},
{L"616", L"2",L"Config file",L"State any",L""}
};
//Setting headers for the RTA Events grid
RtaEventsGrid.SetHeader(0, _T("No"), 50, TRUE);
RtaEventsGrid.SetHeader(1, _T("Event"), 60, TRUE);
RtaEventsGrid.SetHeader(2, _T("Stat"), 50, TRUE);
RtaEventsGrid.SetHeader(3, _T("Scope"), 50, TRUE);
RtaEventsGrid.SetHeader(4, _T("Registered"), 80, FALSE);
RtaEventsGrid.SetHeader(5, _T("Reported"), 80, FALSE);
RtaEventsGrid.SetHeader(6, _T("Initialized"), 80, TRUE);
RtaEventsGrid.SetHeader(7, _T("Measuring"), 80, TRUE);
}
void CRTADlg::InitRTAGetSupportedList()
{
inRegisterEventView = TRUE;
inRTAEventStatusView = FALSE;
RtaEventsGrid.ClearList(); // Clear the existing list
CRtaListCtrl::tooltips = {
{L"30012", L"9",L"Gifted Batt. Percentage",L"Value below min",L"A value between 5% to 95% can be set",L"A value between 5% to 95% can be set"},
{L"30012", L"7",L"Gifted Batt. Percentage",L"Value above max",L"A value between 5% to 95% can be set",L"A value between 5% to 95% can be set"},
{L"38001", L"7",L"RTA Scanner idle",L"Value above max",L"A value between 5 mins to 600 mins can be set"},
{L"38003", L"13",L"RTA virtual tether alert",L"Alarm"},
{L"38004", L"7",L"RTA Scanner out of cradle",L"Value above min",L"A value between 5 mins to 600 mins can be set"},
{L"616", L"2",L"Config file",L"State any"}
};
//Setting headers for the Supported RTA Events grid
RtaEventsGrid.SetHeader(0, _T("No"), 50, TRUE);
RtaEventsGrid.SetHeader(1, _T("Registered"), 80, FALSE);
RtaEventsGrid.SetHeader(2, _T("Event"), 50, TRUE);
RtaEventsGrid.SetHeader(3, _T("Stat"), 50, TRUE);
RtaEventsGrid.SetHeader(4, _T("On-Limit"), 80, FALSE);
RtaEventsGrid.SetHeader(5, _T("Off-Limit"), 80, FALSE);
}
void CRTADlg::SetScannerID(wstring* pScannerID)
{
m_ScannerID = *pScannerID;
}
void CRTADlg::SetAsync(int* pAsync)
{
}
HBRUSH CRTADlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (!m_brush.m_hObject)
m_brush.CreateSolidBrush(RGB(247, 250, 253));
SetLabelBkg(pDC, pWnd, IDC_STATIC);
return m_brush;
}
string getCurrentDateTime() { //Adding current date and time to the RTA Event Log
auto now = chrono::system_clock::now();
time_t now_time = chrono::system_clock::to_time_t(now);
tm* now_tm = localtime(&now_time);
ostringstream oss;
oss << put_time(now_tm, "%Y-%m-%d %H:%M:%S");
return oss.str();
}
void CRTADlg::UIButtonsState(BOOL State)
{
OnClearAll();
RTASuspendCheck.EnableWindow(State);
GetSupportedRTAEvents.EnableWindow(State);
GetRegisteredRTAEvents.EnableWindow(State);
RegisterRTAEvents.EnableWindow(State);
SetRTAEventStatus.EnableWindow(State);
GetRTAEventStatus.EnableWindow(State);
ClearAll.EnableWindow(State);
GetRTAState.EnableWindow(State);
ClearEvents.EnableWindow(State);
}
void CRTADlg::UpdateRtaEvent(BSTR rtaData)
{
try {
int itemIndex = RtaEventLogGridControl.GetItemCount();
// Convert date string to CString
CString cstr(getCurrentDateTime().c_str());
// Convert CString to LPCTSTR
LPCTSTR time = cstr;
// Insert the main item (this will usually correspond to the first column)
int nIndex = RtaEventLogGridControl.InsertItem(itemIndex, time);
CQuickXmlParser x(rtaData);
CQuickXmlParser::TAGDATA tag[6] = { 0 };
tag[0].Tag.Name = L"modelnumber";
tag[1].Tag.Name = L"serialnumber";
tag[2].Tag.Name = L"id";
tag[3].Tag.Name = L"type";
tag[4].Tag.Name = L"data-1";
tag[5].Tag.Name = L"data-2";
x.Configure(tag, 6);
CQuickXmlParser::xptr p = 0;
p = x.Parse(p);
// Set the subitem texts (for the subsequent columns)
RtaEventLogGridControl.SetItemText(nIndex, 1, x.Translate(tag[0].Value)); // Second column
RtaEventLogGridControl.SetItemText(nIndex, 2, x.Translate(tag[1].Value)); // Third column
RtaEventLogGridControl.SetItemText(nIndex, 3, x.Translate(tag[2].Value)); // Fourth column
RtaEventLogGridControl.SetItemText(nIndex, 4, x.Translate(tag[3].Value)); // Fifth column
RtaEventLogGridControl.SetItemText(nIndex, 5, x.Translate(tag[4].Value)); // Sixth column
RtaEventLogGridControl.SetItemText(nIndex, 6, x.Translate(tag[5].Value)); // Seventh column
x.ClearValues(tag);
//OnGetRTAEventStatus(); //Update the RTAEventsGrid
}
catch (exception ex) {
CString errorMsg;
errorMsg.Format(L"Update RTA Event Error: {%S}", ex.what());
LOGV(-1, errorMsg.GetBuffer());
}
}
void CRTADlg::OnListConfigurationSettings()
{
// TODO: Add your control notification handler code here
}
void CRTADlg::OnListEventLog()
{
// TODO: Add your control notification handler code here
}
void CRTADlg::OnCheckedSuspendReportingAlerts()
{
try {
RtaSuspend = (RtaSuspend == FALSE ? TRUE : FALSE);
long status = -1;
CComBSTR outXml(L"");
CString log;
log.Format(L"RTA Suspend State : %s", RtaSuspend ? L"Enabled" : L"Disabled");
wchar_t* logStr = log.GetBuffer();
SC->cmdSuspendRTAEvent(m_ScannerID, &outXml, &status, RtaSuspend);
if (status != 0) {
GetTabManager().GetTabDlg<CLogsDlg>().DisplayResult(status, L"RTA_SUSPEND_STATE");
}
GetTabManager().GetTabDlg<CLogsDlg>().DisplayResult(0, logStr);
}
catch (exception ex) {
CString errorMsg;
errorMsg.Format(L"RTA_SUSPEND_STATE_UPDATE_ERROR: {%S}", ex.what());
LOGV(-1, errorMsg.GetBuffer());
throw ex;
}
}
void CRTADlg::OnGetSupportedRTAEvents()
{
try
{
InitRTAGetSupportedList();
SeparateSupportedandRegistered(FALSE);
}
catch (exception ex){
throw ex;
}
}
void CRTADlg::OnGetRegisteredRTAEvents()
{
try
{
InitRTAGetSupportedList();
SeparateSupportedandRegistered(TRUE);
}
catch (exception ex) {
throw ex;
}
}
void CRTADlg::SeparateSupportedandRegistered(BOOL registeredOnly)
{
// Retrieve registered RTA events to get their IDs
vector<vector<wstring>> eventDetailsList = GetRTAEventsStatus();
if (eventDetailsList.empty()) return;
GetRTASuspendStatus();
vector<vector<wstring>> supportedRTAEvents = GetSupportedRTA();
vector<vector<wstring>> supportedRTAEventsGrid;
if (!supportedRTAEvents.empty()) {
for (const auto& supportedEvent : supportedRTAEvents) {
bool matchFound = false;
for (const auto& event : eventDetailsList) {
if (event[0] == supportedEvent[0] && event[1] == supportedEvent[1] && event[3] == L"TRUE") {
supportedRTAEventsGrid.push_back({ L"TRUE", supportedEvent[0], supportedEvent[1], supportedEvent[2], supportedEvent[3] });
matchFound = true;
break; // No need to check further once a match is found
}
}
if (!matchFound && !registeredOnly) {
supportedRTAEventsGrid.push_back({ L"FALSE", supportedEvent[0], supportedEvent[1], supportedEvent[2], supportedEvent[3] });
}
}
}
if (supportedRTAEventsGrid.empty()) {
MessageBox(_T("RTA Events are not registered in the selected device."), _T("INFO - Get Registered RTA Events"), MB_OK | MB_ICONINFORMATION);
return;
}
//Update the grid with data
UpdateRTAGrid(supportedRTAEventsGrid);
}
void CRTADlg::OnRegisterRTAEvents()
{
try {
if (RtaEventsGrid.GetItemText(0, 0) != "" && inRegisterEventView == TRUE) {
vector<vector<wstring>> rtaEventsRegister;
long status = -1;
CComBSTR outXml(L"");
for (auto& event : CRtaListCtrl::gridData)
{
if (event[0] == L"TRUE") {
RtaEventDetails details;
details.Event = event[1];
details.Stat = event[2];
details.OnLimit = event[3];
details.OffLimit = event[4];
int onLimitValue = -1, offLimitValue = -1;
// Validate On-Limit and Off-Limit values should not be empty
if (details.OnLimit.empty() || details.OffLimit.empty())
{
AfxMessageBox(L"On-Limit or Off-Limit should not be empty", MB_OK | MB_ICONERROR);
return;
}
// Validate user is registering by not setting (value = "Not set") On-Limit/Off-Limit values
if ((details.OnLimit == RtaLimitNotSet || details.OffLimit == RtaLimitNotSet))
{
CString errorMessage;
errorMessage.Format(L"On-Limit/Off-Limit should be set for Event: %s and Stat: %s",
details.Event.c_str(),
details.Stat.c_str());
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
// Validations for Gifted Battery Percentage range limits
else if (details.Event == GiftedBatteryPercentageAttribute)
{
// Validate On-Limit value
if ((details.OnLimit != RtaLimitNotSet) && (details.OnLimit != RtaLimitNotSupported))
{
int onLimitValue = 0;
if (swscanf_s(details.OnLimit.c_str(), L"%d", &onLimitValue) == 1)
{
if (onLimitValue > RtaRangeMaxLimitGiftedBatt || onLimitValue < RtaRangeMinLimit)
{
CString errorMessage;
errorMessage.Format(L"On-Limit value is out of range for Event: %s and Stat: %d",
GiftedBatteryPercentageAttribute.c_str(),
RtaStatOverMax);
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
else
{
CString errorMessage;
errorMessage.Format(L"Invalid On-Limit value for Event: %s and Stat: %d",
GiftedBatteryPercentageAttribute.c_str(),
RtaStatOverMax);
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
// Validate Off-Limit value
if ((details.OffLimit != RtaLimitNotSet) && (details.OffLimit != RtaLimitNotSupported))
{
int offLimitValue = 0;
if (swscanf_s(details.OffLimit.c_str(), L"%d", &offLimitValue) == 1) // Use swscanf_s for safe conversion
{
if (offLimitValue > RtaRangeMaxLimitGiftedBatt || offLimitValue < RtaRangeMinLimit)
{
CString errorMessage;
errorMessage.Format(L"Off-Limit value is out of range for Event: %s and Stat: %d",
GiftedBatteryPercentageAttribute.c_str(),
RtaStatOverMax);
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
else
{
CString errorMessage;
errorMessage.Format(L"Invalid Off-Limit value for Event: %s and Stat: %d",
GiftedBatteryPercentageAttribute.c_str(),
RtaStatOverMax);
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
int currentStat = -1;
if (swscanf_s(details.Stat.c_str(), L"%d", ¤tStat) == 1)
{
swscanf_s(details.OnLimit.c_str(), L"%d", &onLimitValue);
swscanf_s(details.OffLimit.c_str(), L"%d", &offLimitValue);
if (currentStat == RtaStatOverMax) // Max value Stat
{
if ((offLimitValue > 0) && (onLimitValue > 0) && (offLimitValue >= onLimitValue))
{
CString errorMessage;
errorMessage.Format(L"Off-Limit value should be less than On-Limit for Event: %s and Stat: %d",
GiftedBatteryPercentageAttribute.c_str(),
RtaStatOverMax);
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
else if (currentStat == RtaStatBelowMin) // Min value Stat
{
if ((offLimitValue > 0) && (onLimitValue > 0) && (offLimitValue <= onLimitValue))
{
CString errorMessage;
errorMessage.Format(L"Off-Limit value should be greater than On-Limit for Event: %s and Stat: %d",
GiftedBatteryPercentageAttribute.c_str(),
RtaStatBelowMin);
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
}
}
// Validate Scanner Out Of Cradle and Scanner Idle attributes
if ((details.Event == ScannerOutOfCradleAttribute) || (details.Event == ScannerIdleAttribute))
{
int onLimitValue = -1;
int offLimitValue = -1;
// Validate On-Limit value
if ((details.OnLimit != RtaLimitNotSet) && (details.OnLimit != RtaLimitNotSupported))
{
if (swscanf_s(details.OnLimit.c_str(), L"%d", &onLimitValue) == 1) // Use swscanf_s for safe conversion
{
if (onLimitValue > RtaRangeMaxLimitScannerOutOfCradle || onLimitValue < RtaRangeMinLimit)
{
CString errorMessage;
errorMessage.Format(L"On-Limit value is out of range for Event: %s and Stat: %s",
details.Event.c_str(),
details.Stat.c_str());
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
else
{
CString errorMessage;
errorMessage.Format(L"Invalid On-Limit value for Event: %s and Stat: %s",
details.Event.c_str(),
details.Stat.c_str());
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
// Validate Off-Limit value
if ((details.OffLimit != RtaLimitNotSet) && (details.OffLimit != RtaLimitNotSupported))
{
if (swscanf_s(details.OffLimit.c_str(), L"%d", &offLimitValue) == 1) // Use swscanf_s for safe conversion
{
if (offLimitValue > RtaRangeMaxLimitScannerOutOfCradle || offLimitValue < RtaRangeMinLimit)
{
CString errorMessage;
errorMessage.Format(L"Off-Limit value is out of range for Event: %s and Stat: %s",
details.Event.c_str(),
details.Stat.c_str());
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
else
{
CString errorMessage;
errorMessage.Format(L"Invalid Off-Limit value for Event: %s and Stat: %s",
details.Event.c_str(),
details.Stat.c_str());
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
// Validate if Off-Limit is greater than On-Limit
if ((offLimitValue > 0) && (onLimitValue > 0) && (offLimitValue <= onLimitValue))
{
CString errorMessage;
errorMessage.Format(L"Off-Limit value should be greater than On-Limit for Event: %s and Stat: %s",
details.Event.c_str(),
details.Stat.c_str());
AfxMessageBox(errorMessage, MB_OK | MB_ICONERROR);
return;
}
}
rtaEventsRegister.push_back({ event[1], event[2], event[3], event[4]});
}
}
if (!rtaEventsRegister.empty()) {
SC->cmdRegisterRTAEvents(m_ScannerID, &status, rtaEventsRegister);
LOG(status,"RTA_REGISTER_EVENTS")
}
else {
AfxMessageBox(L"No valid events to register", MB_OK | MB_ICONERROR);
return;
}
}
else {
MessageBox(_T("No data available to register RTA Events. Retrieve Supported/Registered RTA events, select new registrations and then proceed with registering RTA events"), (RegisterRtaErrorTitle), MB_OK | MB_ICONERROR);
return;
}
}
catch (exception ex) {
throw ex;
}
}
void CRTADlg::OnSetRTAEventStatus() {
// Check if the grid has data in the first cell
if (RtaEventsGrid.GetItemText(0, 0) != "" && inRTAEventStatusView == TRUE) {
long status = -1;
CComBSTR outXml(L"");
// Retrieve grid data and event details
vector<vector<wstring>> gridData = CRtaListCtrl::gridData;
vector<vector<wstring>> eventDetailsList = GetRTAEventsStatus();
// Prepare a list of events that need to be updated
vector<vector<wstring>> setRTAEventsList;
vector<vector<wstring>> unregRTAEventsList;
size_t eventCount = min(gridData.size(), eventDetailsList.size());
for (size_t i = 0; i < eventCount; ++i) {
const vector<wstring>& rtaEvent = gridData[i];
const vector<wstring>& eventDetails = eventDetailsList[i];
// Compare specific field (index 4) and prepare events for update
if (rtaEvent[4] != eventDetails[4]) {
vector<wstring> event = {
rtaEvent[0], // Event ID
rtaEvent[1], // Stat
rtaEvent[4] // Status to be updated
};
setRTAEventsList.push_back(event);
}
if (rtaEvent[3] != eventDetails[3] && rtaEvent[3] == L"FALSE") {
vector<wstring> event = {
rtaEvent[0], //Event ID
rtaEvent[1] //Stat
};
unregRTAEventsList.push_back(event);
}
}
// Send the updates to the system
if (!setRTAEventsList.empty()) {
SC->cmdSetRTAEventStatus(m_ScannerID, &outXml, &status, setRTAEventsList);
}
if (!unregRTAEventsList.empty()) {
SC->cmdUnregisterRTAEvent(m_ScannerID, &outXml, &status, unregRTAEventsList);
}
LOG(status, "RTA_SET_EVENT_STATUS");
}
else {
// Display an error message if no data is available
MessageBox(_T("No data available to set RTA Alert Status. Get RTA event status, select new status updates and then proceed with Setting RTA event status."),_T("ERROR - Set RTA Event Status"), MB_OK | MB_ICONERROR);
LOG(-1, "RTA get event status error: No data available. Please press 'Get RTA Event Status'.");
}
}
void CRTADlg::OnGetRTAEventStatus()
{
try {
InitRTAGetEventsAttribList(); // Initialize the attributes list
vector<vector<wstring>> eventDetailsList = GetRTAEventsStatus(); // Retrieve event status and XML
if (eventDetailsList.empty()) return;
GetRTASuspendStatus();
UpdateRTAGrid(eventDetailsList); //Update the grid with data
}
catch (...) {
LOG(-1, "RTA_GET_EVENT_STATUS"); // Catch any other exceptions
}
}
void CRTADlg::OnClearAll()
{
RtaEventsGrid.ClearList(); // Clear the existing list
RtaSuspend = FALSE; //Clear the suspend checkbox state
UpdateData(FALSE); //Updating the UI
}
void CRTADlg::OnGetRTAState()
{
map<int, CString> RtaStates =
{
{0, L"RTA Suspended" },
{ 1, L"RTA Awaiting Registration" },
{ 2, L"RTA Awaiting Context Address" },
{ 3, L"RTA Fully Operational" }
};
long status = -1;
CComBSTR outXml(L"");
try {
// Get the RTA event status
if (!SC->cmdGetRTAState(m_ScannerID, &outXml, &status)) {
if (status != 0) {
LOG(status, "RTA_GET_STATE");
return;
}
// Display XML response
GetTabManager().GetTabDlg<CLogsDlg>().ShowOutXml(outXml);
// Configure XML parser
CQuickXmlParser x(outXml);
CQuickXmlParser::TAGDATA tag[1] = { 0 };
tag[0].Tag.Name = L"state";
x.Configure(tag, 1);
// Parse XML and collect event details
CQuickXmlParser::xptr p = 0;
while (true) {
p = x.Parse(p);
RtaState = RtaStates[_ttoi(x.Translate(tag[0].Value))];
UpdateData(FALSE);
if (p == 0) break;
x.ClearValues(tag);
}
LOG(status, "RTA_GET_STATE");
}
}
catch (exception ex) {
throw ex;
}
return;
}
void CRTADlg::OnClearEventLog()
{
try {
RtaEventLogGridControl.DeleteAllItems(); //Clearing the RTA Event Log
}
catch (exception ex) {
CString errorMsg;
errorMsg.Format(L"RTA_EVENT_LOG_CLEAR ERROR : {%S}", ex.what());
LOGV(-1, errorMsg.GetBuffer());
}
}
vector<vector<wstring>> CRTADlg::GetSupportedRTA() { //Parse the outXML of Supported RTA Events
long status = -1;
CComBSTR outXml(L"");
vector<vector<wstring>> supportedRTAEvents;
// Retrieve supported RTA events
if (!SC->cmdGetSupportedRTAEvents(m_ScannerID, &outXml, &status))
{
if (outXml.Length() == 0 || status != 0) {
MessageBox(_T("Supported RTA events could not be retrieved from the selected device."), _T("ERROR - Get Supported RTA Events"), MB_OK | MB_ICONERROR);
LOG(status, "RTA_GET_SUPPORTED_STATUS");
return supportedRTAEvents;
}
// Update the log tab with the supported events XML
GetTabManager().GetTabDlg<CLogsDlg>().ShowOutXml(outXml);
// Parse the XML and fill in the grid control with the data
CQuickXmlParser x(outXml);
CQuickXmlParser::TAGDATA tag[4] = { 0 };
tag[0].Tag.Name = L"id";
tag[1].Tag.Name = L"stat";
tag[2].Tag.Name = L"onlimit";
tag[3].Tag.Name = L"offlimit";
x.Configure(tag, 4);
CQuickXmlParser::xptr p = 0;
while (1)
{
p = x.Parse(p); // Parse the XML
vector<wstring> event = {
x.Translate(tag[0].Value),
x.Translate(tag[1].Value),
x.Translate(tag[2].Value),
x.Translate(tag[3].Value),
};
supportedRTAEvents.push_back(event);
if (p == 0) break;
x.ClearValues(tag); // Clear tag values for the next iteration
}
}
LOG(status, "GET_SUPPORTED_RTA");
return supportedRTAEvents;
}
vector<vector<wstring>> CRTADlg::GetRTAEventsStatus() { //Parse the outXML of RTA Events Status
long status = -1;
CComBSTR outXml(L"");
vector<vector<wstring>> eventDetailsList;
try {
// Get the RTA event status
if (!SC->cmdGetRTAEventStatus(m_ScannerID, &outXml, &status)) {
// Handle empty response
if (outXml.Length() == 0 || status != 0) {
MessageBox(_T("RTA alert status could not be retrieved from the selected device."),_T("ERROR - Get RTA Event Status"), MB_OK | MB_ICONERROR);
LOG(status, "RTA_GET_EVENT_STATUS");
return eventDetailsList;
}
// Display XML response
GetTabManager().GetTabDlg<CLogsDlg>().ShowOutXml(outXml);
// Configure XML parser
CQuickXmlParser x(outXml);
CQuickXmlParser::TAGDATA tag[7] = { 0 };
tag[0].Tag.Name = L"id";
tag[1].Tag.Name = L"stat";
tag[2].Tag.Name = L"scope";
tag[3].Tag.Name = L"registered";
tag[4].Tag.Name = L"reported";
tag[5].Tag.Name = L"initialized";
tag[6].Tag.Name = L"measuring";
x.Configure(tag, 7);
// Parse XML and collect event details
CQuickXmlParser::xptr p = 0;
while (true) {
p = x.Parse(p);
vector<wstring> event = {
x.Translate(tag[0].Value),
x.Translate(tag[1].Value),
x.Translate(tag[2].Value),
x.Translate(tag[3].Value),
x.Translate(tag[4].Value),
x.Translate(tag[5].Value),
x.Translate(tag[6].Value)
};
eventDetailsList.push_back(event);
if (p == 0) break;
x.ClearValues(tag);
}
// Log successful status retrieval
LOG(status, "RTA_GET_EVENT_STATUS");
}
}
catch (const exception& ex) {
// Handle exceptions
throw ex;
}
return eventDetailsList;
}
BOOL CRTADlg::GetRTASuspendStatus() //Parse the outXML of RTA State
{
long status = -1;
CComBSTR outXml(L"");
CString rtaSuspendState;
try {
if (!SC->cmdGetRTAEventStatus(m_ScannerID, &outXml, &status)) {
// Handle empty response
if (outXml.Length() == 0) {
AfxMessageBox(_T("Setting RTA State failed"));
LOG(-1, "RTA get event status error - Empty response from CS");
return FALSE;
}
// Display XML response
GetTabManager().GetTabDlg<CLogsDlg>().ShowOutXml(outXml);
// Configure XML parser
CQuickXmlParser x(outXml);
CQuickXmlParser::TAGDATA tag[1] = { 0 };
tag[0].Tag.Name = L"suspend";
x.Configure(tag, 1);
// Parse XML and collect event details
CQuickXmlParser::xptr p = 0;
while (true) {
p = x.Parse(p);
rtaSuspendState = x.Translate(tag[0].Value);
if (p == 0) break;
x.ClearValues(tag);
}
RtaSuspend = rtaSuspendState == L"TRUE" ? TRUE : FALSE;
UpdateData(FALSE);
// Log successful status retrieval
//LOG(status, "GET_RTA_SUSPEND");
return RtaSuspend;
}
}
catch (exception ex){
LOG(status, "GET_RTA_SUSPEND_ERROR");
throw ex;
}
return FALSE;
}
void CRTADlg::UpdateRTAGrid(vector<vector<wstring>> eventDetailsList)
{
// Update the static member of CRtaListCtrl
CRtaListCtrl::gridData = eventDetailsList;
if (!eventDetailsList.empty()) {
// Insert and populate grid with event details
for (size_t rowIndex = 0; rowIndex < eventDetailsList.size(); ++rowIndex) {
const auto& event = eventDetailsList[rowIndex];
int itemIndex = RtaEventsGrid.GetItemCount();
int nIndex = RtaEventsGrid.InsertItem(itemIndex, L"");
// Set item number for the first column
RtaEventsGrid.SetItemText(nIndex, 0, to_wstring(nIndex + 1).c_str());
// Set the subitem texts for the subsequent columns
for (size_t colIndex = 0; colIndex < event.size(); ++colIndex) {
RtaEventsGrid.SetItemText(nIndex, static_cast<int>(colIndex + 1), event[colIndex].c_str());
}
}
}
}