-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlackfinConsoleCommands.cs
977 lines (853 loc) · 27.7 KB
/
BlackfinConsoleCommands.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irisys.BlackfinAPI;
using System.IO;
using IrisysTime;
using Irisys.BlackfinAPI.Interfaces;
using System.Net;
using System.Reflection;
namespace BlackfinAPIConsole
{
/// <summary>
/// This class contains all of the command definitions for the Blackfin API
/// None of the commands should use the console (this is handled by whatever
/// is calling the Command)
/// This demonstrates simple use of API for string based operations
/// </summary>
public class BlackfinConsoleCommands
{
private BlackfinConsoleCommands()
{
}
public class GetDeviceNameCommand : BaseConsoleCommand
{
public GetDeviceNameCommand()
: base("GetDeviceName", "Gets the device name string from the connected unit")
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetDeviceName())
return null;
return bf.DeviceName;
}
}
public class GetDeviceIDCommand : BaseConsoleCommand
{
public GetDeviceIDCommand()
: base("GetDeviceID", "Gets the device ID string from the connected unit")
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetDeviceID())
return null;
return bf.DeviceID;
}
}
public class GetSiteNameCommand : BaseConsoleCommand
{
public GetSiteNameCommand()
: base("GetSiteName", "Gets the Site name string from the connected unit")
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetSiteName())
return null;
return bf.SiteName;
}
}
public class GetSiteIDCommand : BaseConsoleCommand
{
public GetSiteIDCommand()
: base("GetSiteID", "Gets the Site ID string from the connected unit")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetSiteID())
return null;
return bf.SiteID;
}
}
public class GetLocaleStringCommand : BaseConsoleCommand
{
public GetLocaleStringCommand()
: base("GetLocaleString", "Gets the Locale string from the connected unit")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetLocaleString())
return null;
return bf.LocaleString;
}
}
public class GetUserStringCommand : BaseConsoleCommand
{
public GetUserStringCommand()
: base("GetUserString", "Gets the user string from the connected unit")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetUserString())
return null;
return bf.UserString;
}
}
public class GetRegisterLabelsCommand : BaseConsoleCommand
{
public GetRegisterLabelsCommand()
: base("GetRegisterLabels", "Gets the labels associated with each active count register on the device")
{ }
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetRegisterLabels())
return null;
List<string> labels = bf.RegisterLabels;
string result = "\nRegister Labels;\n";
foreach (string label in labels)
result += "\t" + label + "\n";
return result;
}
}
public class GetUnitTimeCommand : BaseConsoleCommand
{
public GetUnitTimeCommand()
: base("GetUnitTime", "Gets the Unit Time from the connected unit")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetUnitTime())
return null;
return bf.UnitTime.ToString();
}
}
public class GetUpTimeCommand : BaseConsoleCommand
{
public GetUpTimeCommand()
: base("GetUpTime", "Get the up time of the connected device, in seconds")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetUpTime())
return null;
return "The device has been running for " + bf.UpTime + " seconds";
}
}
public class SetDeviceNameCommand : BaseConsoleCommand
{
public SetDeviceNameCommand()
: base("SetDeviceName",
"Sets the device name string from the connected unit",
new string[] { "Device Name" })
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.SetDeviceName(args[0]))
return null;
return "Set device name";
}
}
public class SetDeviceIDCommand : BaseConsoleCommand
{
public SetDeviceIDCommand()
: base("SetDeviceID",
"Sets the device ID string from the connected unit",
new string[] { "Device ID" })
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.SetDeviceID(args[0]))
return null;
return "Set device ID";
}
}
public class SetSiteNameCommand : BaseConsoleCommand
{
public SetSiteNameCommand()
: base("SetSiteName",
"Sets the Site name string from the connected unit",
new string[] { "Site Name" })
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.SetSiteName(args[0]))
return null;
return "Set site name";
}
}
public class SetSiteIDCommand : BaseConsoleCommand
{
public SetSiteIDCommand()
: base("SetSiteID",
"Sets the Site ID string from the connected unit",
new string[] { "Site ID" })
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.SetSiteID(args[0]))
return null;
return "Set site id";
}
}
public class SetLocaleStringCommand : BaseConsoleCommand
{
public SetLocaleStringCommand()
: base("SetLocaleString",
"Sets the Locale string from the connected unit",
new string[] { "Locale String" })
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.SetLocaleString(args[0]))
return null;
return "The locale string has been set";
}
}
public class SetUserStringCommand : BaseConsoleCommand
{
public SetUserStringCommand()
: base("SetUserString",
"Sets the user string from the connected unit",
new string[] { "User String" })
{
}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.SetUserString(args[0]))
return null;
return "The user string has been set";
}
}
public class SetUnitTimeCommand : BaseConsoleCommand
{
public SetUnitTimeCommand()
: base("SetUnitTime", "Sets the Unit Time on the connected unit", new string[] { "UnitTime" })
{
}
public override string execute(Blackfin bf, string[] args)
{
try
{
DateTime t = DateTime.Parse(args[0]);
if (!bf.SetUnitTime(t))
return null;
return "Set unit time";
}
catch (FormatException)
{
throw new CommandArgumentException("Incorrect Date Format");
}
}
}
public class GetDNSCommand : BaseConsoleCommand
{
public GetDNSCommand()
: base("GetDNS",
"Gets the DNS address for the specified slot (1-3)",
new string[] { "DNS Slot (1 - 3)" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
switch (int.Parse(args[0]))
{
case 1:
return bf.GetDNS1().ToString();
case 2:
return bf.GetDNS2().ToString();
case 3:
return bf.GetDNS3().ToString();
}
}
catch (FormatException)
{
}
catch (OverflowException)
{
}
throw new CommandArgumentException("Invalid DNS slot value");
}
}
public class SetDNSCommand : BaseConsoleCommand
{
public SetDNSCommand()
: base("SetDNS",
"Sets the DNS address for the specified slot (1-3)",
new string[] { "DNS Slot (1 - 3)", "IP address of DNS" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
int slot = int.Parse(args[0]);
IPAddress ip = IPAddress.Parse(args[1]);
switch (slot)
{
case 1:
bf.SetDNS1(ip); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException ("Set DNS 1");
case 2:
bf.SetDNS2(ip); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException("Set DNS 2");
case 3:
bf.SetDNS3(ip); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException("Set DNS 3");
}
}
catch (OverflowException)
{}
catch (FormatException)
{}
throw new CommandArgumentException("Invalid DNS slot value");
}
}
public class GetDHCPEnabledCommand : BaseConsoleCommand
{
public GetDHCPEnabledCommand()
: base("GetDHCPEnabled",
"Gets a value determining whether or not DHCP is to be used by the device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetDHCPEnabled())
return null;
return bf.DHCPEnabled + "";
}
}
public class GetIPFirmwareVersionCommand : BaseConsoleCommand
{
public GetIPFirmwareVersionCommand()
: base("GetIPFirmwareVersion",
"Gets the firmware version of the IP Board of the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetIPFirmwareVersion())
return null;
return bf.IPFirmwareVersion;
}
}
public class GetMonitorFirmwareVersionCommand : BaseConsoleCommand
{
public GetMonitorFirmwareVersionCommand()
: base("GetMonitorFirmwareVersion",
"Gets the firmware version of the DSP Board of the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetMonitorFirmwareVersion())
return null;
return bf.MonitorFirmwareVersion;
}
}
public class GetMACAddressCommand : BaseConsoleCommand
{
public GetMACAddressCommand()
: base("GetMACAddress",
"Gets the MAC address for the IP board of the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetMACAddress())
return null;
return bf.MACAddress;
}
}
public class GetIPAddressCommand : BaseConsoleCommand
{
public GetIPAddressCommand()
: base("GetIPAddress",
"Gets the static IP Address for the IP board of the connected device (not an assigned DHCP address)")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetIPAddress())
return null;
return bf.IPAddress.ToString();
}
}
public class GetGatewayCommand : BaseConsoleCommand
{
public GetGatewayCommand()
: base("GetGateway",
"Gets the static gateway address for the IP board of the connected device (used when DHCP is disabled)")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetGateway())
return null;
return bf.Gateway.ToString();
}
}
public class GetSubnetMaskCommand : BaseConsoleCommand
{
public GetSubnetMaskCommand()
: base("GetSubnetMask",
"Gets the static subnet mask for the IP board of the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetSubnetMask())
return null;
return bf.SubnetMask.ToString();
}
}
public class GetSerialNumberCommand : BaseConsoleCommand
{
public GetSerialNumberCommand()
: base("GetSerialNumber",
"Gets the serial number for the the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetSerialNumber())
return null;
return SerialNumberConverter.ConvertSerialNumber(bf.SerialNumber);
}
}
public class GetClientConfigEnableCommand : BaseConsoleCommand
{
public GetClientConfigEnableCommand()
: base("GetClientConfigEnable",
"Check whether client connection mode is enabled on the device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetClientConfigEnable())
return null;
return "Client connection mode is " + ((bf.ClientConfigEnable) ? "enabled" : "disabled");
}
}
public class GetClientConfigIPCommand : BaseConsoleCommand
{
public GetClientConfigIPCommand()
: base("GetClientConfigIP",
"Gets the IP address which IP board of the connected device will connect to in client connection mode")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetClientConfigIP())
return null;
return bf.ClientConfigIP.ToString();
}
}
public class GetClientConfigHostnameCommand : BaseConsoleCommand
{
public GetClientConfigHostnameCommand()
: base("GetClientConfigHostname",
"Gets the Hostname which IP board of the connected device will connect to in client connection mode")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetClientConfigHostname())
return null;
return bf.ClientConfigHostname;
}
}
public class GetClientConfigPortCommand : BaseConsoleCommand
{
public GetClientConfigPortCommand()
: base("GetClientConfigPort",
"Gets the port which IP board of the connected device will connect to in client connection mode")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetClientConfigPort())
return null;
return bf.ClientConfigPort + "";
}
}
public class GetClientConfigTimeoutCommand : BaseConsoleCommand
{
public GetClientConfigTimeoutCommand()
: base("GetClientConfigTimeout",
"Gets the period in seconds at which IP board of the connected device will attempt to connect in client connection mode")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetClientConfigTimeout())
return null;
return bf.ClientConfigTimeout + "";
}
}
public class SetClientConfigEnableCommand : BaseConsoleCommand
{
public SetClientConfigEnableCommand()
: base("SetClientConfigEnable",
"Enable or disable the client connection mode on the device",
new string[] { "Enabled? (Y/N)" })
{}
public override string execute(Blackfin bf, string[] args)
{
if (args[0].ToLower().Equals("y") || args[0].ToLower().Equals("n"))
{
bool bEnabled = args[0].ToLower().Equals("y");
bf.SetClientConfigEnable(bEnabled); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException("Client connection mode has been " + ((bEnabled) ? "enabled" : "disabled"));
}
throw new CommandArgumentException("Invalid argument value");
}
}
public class SetClientConfigIPCommand : BaseConsoleCommand
{
public SetClientConfigIPCommand()
: base("SetClientConfigIP",
"Sets the IP address which IP board of the connected device will connect to in client connection mode",
new string[] { "Server IP Address" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
IPAddress ipinet = IPAddress.Parse(args[0]);
bf.SetClientConfigIP(ipinet); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException("Client connection IP has been set");
}
catch (FormatException)
{
throw new CommandArgumentException("Invalid IP Address");
}
}
}
public class SetClientConfigHostnameCommand : BaseConsoleCommand
{
public SetClientConfigHostnameCommand()
: base("SetClientConfigHostname",
"Sets the Hostname which IP board of the connected device will connect to in client connection mode",
new string[] { "Server hostname" })
{}
public override string execute(Blackfin bf, string[] args)
{
bf.SetClientConfigHostname(args[0]); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException("Client connection hostname has been set");
}
}
public class SetClientConfigPortCommand : BaseConsoleCommand
{
public SetClientConfigPortCommand()
: base("SetClientConfigPort",
"Sets the port which IP board of the connected device will connect to in client connection mode",
new string[] { "Server port number" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
bf.SetClientConfigPort(ushort.Parse(args[0])); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException("Client connection port has been set");
}
catch (FormatException)
{
throw new CommandArgumentException("Invalid port value");
}
}
}
public class SetClientConfigTimeoutCommand : BaseConsoleCommand
{
public SetClientConfigTimeoutCommand()
: base("SetClientConfigTimeout",
"Sets the period in seconds at which IP board of the connected device will attempt to connect in client connection mode",
new string[] { "Timeout period (s)" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
bf.SetClientConfigTimeout(uint.Parse(args[0])); // Resets the IP board, always returns false for an IP connection
throw new ConnectionResetException("Client connection timeout has been set");
}
catch (FormatException)
{
throw new CommandArgumentException("Invalid timeout value");
}
}
}
public class GetCountLogPeriod : BaseConsoleCommand
{
public GetCountLogPeriod()
: base("GetCountLogPeriod",
"Gets the count log interval in seconds")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetCountLogPeriod())
return null;
return bf.CountLogPeriod.ToString();
}
}
public class SetCountLogPeriod : BaseConsoleCommand
{
public SetCountLogPeriod()
: base("SetCountLogPeriod",
"Sets the count log interval in seconds",
new string[] { "Log Interval (s)" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
if (!bf.SetCountLogPeriod(int.Parse(args[0])))
return null;
}
catch (FormatException)
{
throw new CommandArgumentException("Invalid interval value");
}
return "Set count log interval";
}
}
public class GetDeviceStatusCommand : BaseConsoleCommand
{
public GetDeviceStatusCommand()
: base("GetDeviceStatus", "Gets the errors and warnings for the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetDeviceStatus())
return null;
DeviceStatus deviceStatus = bf.DeviceStatus;
string output = "\nError: ";
//Errors
foreach (DeviceLogEntry entry in deviceStatus.m_errorList)
{
string tmpstring = entry.timestamp.ToString();
tmpstring += " ";
tmpstring += entry.errorDescription;
output += tmpstring;
}
output += "\nWarning: ";
//Add warnings
foreach (DeviceLogEntry entry in deviceStatus.m_warnList)
{
string tmpstring = entry.timestamp.ToString();
tmpstring += " ";
tmpstring += entry.errorDescription;
output += tmpstring;
}
output += "\nMessages: ";
//Add info
foreach (DeviceLogEntry entry in deviceStatus.m_infoList)
{
string tmpstring = entry.timestamp.ToString();
tmpstring += " ";
tmpstring += entry.errorDescription;
output += tmpstring;
}
return "Device Status:" + output + "\n";
}
}
public class GetLastNCountsCommand : BaseConsoleCommand
{
public GetLastNCountsCommand()
: base("GetLastNCounts",
"Gets the last n counts from the device log in the connected device",
new string[] { "N (Number of counts to retrieve)" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
if (!bf.GetLastNCounts(uint.Parse(args[0])))
return null;
return PrintCountsList(bf.Counts);
}
catch (FormatException)
{
throw new CommandArgumentException("Incorrect n argument");
}
}
}
public class GetCurrentCountCommand : BaseConsoleCommand
{
public GetCurrentCountCommand()
: base("GetCurrentCount", "Gets the current count (not from log) from the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetCurrentCount())
return null;
return PrintCounts(bf.Counts.First());
}
}
public class GetUnitTimeZoneCommand : BaseConsoleCommand
{
public GetUnitTimeZoneCommand()
: base("GetUnitTimeZone", "Gets the current Unit Time Zone from the connected device")
{}
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetUnitTimeZone())
return null;
IrisysTimeZone tz = bf.UnitTimeZone;
return tz.DisplayName;
}
}
public class SetUnitTimeZoneCommand : BaseConsoleCommand
{
public SetUnitTimeZoneCommand()
: base("SetUnitTimeZone", "Sets the current Unit Time Zone from the connected device", new string[]
{
"TimeZone Index (0-" + IrisysTimeZone.TimeZones.Count() + ")",
"Apply DST"
})
{
}
public override string execute(Blackfin bf, string[] args)
{
try
{
short index = short.Parse(args[0]);
bool dst = bool.Parse(args[1]);
if (index >= IrisysTimeZone.TimeZones.Count())
throw new CommandArgumentException("Timezone index out of bounds");
IrisysTimeZone tz = new IrisysTimeZone(IrisysTimeZone.TimeZones.ElementAt(index));
if (tz.SupportsDST)
tz.ApplyDST = dst;
if (!bf.SetUnitTimeZone(tz))
return null;
return "Set Timezone to " + tz.TimeZoneID;
}
catch (FormatException)
{
throw new CommandArgumentException("Timezone index incorrect");
}
}
}
public class GetCountsCommand : BaseConsoleCommand
{
public GetCountsCommand()
: base("GetCounts",
"Get the count log between two specified dates",
new string[] { "Start Time", "End Time" })
{}
public override string execute(Blackfin bf, string[] args)
{
try
{
DateTime startTime = DateTime.Parse(args[0]);
DateTime endTime = DateTime.Parse(args[1]);
if (!(bf.GetCounts(startTime, endTime)))
return null;
return PrintCountsList(bf.Counts);
}
catch (FormatException)
{
throw new IOException("Could not parse start or end dates");
}
}
}
public class ResetCurrentCountCommand : ConfirmConsoleCommand
{
public ResetCurrentCountCommand()
: base("ResetCurrentCount", "Resets the current count in the device")
{}
public override string execute(Blackfin bf)
{
if (!bf.ResetCurrentCount())
return null;
return "Reset current counts";
}
}
public class ResetCountLogsCommand : ConfirmConsoleCommand
{
public ResetCountLogsCommand()
: base("ResetCountLogs", "Resets the count logs in the device")
{}
public override string execute(Blackfin bf)
{
if (!bf.ResetCountLogs())
return null;
return "Reset count logs";
}
}
public class ResetDeviceStatusCommand : ConfirmConsoleCommand
{
public ResetDeviceStatusCommand()
: base("ResetDeviceStatus", "Resets the diagnostics message log")
{}
public override string execute(Blackfin bf)
{
if (!bf.ResetDeviceStatus())
return null;
return "Reset device status";
}
}
public class GetNetworkChecksumCommand : BaseConsoleCommand
{
public GetNetworkChecksumCommand()
: base("GetNetworkChecksum", "Get a checksum of the settings for all devices on the network")
{ }
public override string execute(Blackfin bf, string[] args)
{
if (!bf.GetNetworkChecksum())
return null;
return "Network Checksum: " + bf.NetworkChecksum;
}
}
/// <summary>
/// Convenience method for printing count logs
/// </summary>
/// <param name="counts">The list of counts to display as a string</param>
/// <returns>The generated string</returns>
private static string PrintCountsList(List<Count> counts)
{
StringBuilder o = new StringBuilder();
foreach (Count ct in counts)
{
o.Append(ct.countTime.ToString());
o.Append(" ");
foreach (uint ctline in ct.countLines)
{
o.Append(ctline.ToString());
o.Append(" ");
}
o.Append("\n");
}
return o.ToString();
}
private static string PrintCounts(Count c)
{
string tmpstring = "";
foreach (uint ctline in c.countLines)
{
tmpstring += ctline.ToString() + "\n";
}
// adding the timestamp at the end
tmpstring += c.countTime.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
// c.countTime.Year + "-" + c.countTime.Month + "-" + c.countTime.Day + " " + c.countTime.Hour + ":" + c.countTime.Minute + ":" + c.countTime.Second
return tmpstring;
}
/// <summary>
/// Returns a list of all console commands defined in this file
/// </summary>
/// <returns></returns>
public static List<ConsoleCommand> GetAllConsoleCommands()
{
List<ConsoleCommand> Commands = new List<ConsoleCommand>();
// add all nested classes to list
BlackfinConsoleCommands c = new BlackfinConsoleCommands();
foreach (Type t in c.GetType().GetNestedTypes())
{
if (typeof(ConsoleCommand).IsAssignableFrom(t))
{
ConstructorInfo i = t.GetConstructor(new Type[] { });
if (i != null)
{
ConsoleCommand command = i.Invoke(new object[] { }) as ConsoleCommand;
Commands.Add(command);
}
}
}
return Commands;
}
}
}