-
Notifications
You must be signed in to change notification settings - Fork 0
/
nirtconfig.c
708 lines (538 loc) · 22.9 KB
/
nirtconfig.c
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
#include <iostream>
#include <cstring>
#include <string>
#include <unistd.h>
#include <nisyscfg/nisyscfg.h>
#include "nirtconfig.h"
static const struct
{
const char* const name;
int (*fpointer)(int argc, char** argv);
} nirtFunctions[] = {
{ "find", nirtconfig_find },
{ "setimage", nirtconfig_setImage },
{ "getimage", nirtconfig_getImage },
{ "selftest", nirtconfig_selfTest },
{ "sethostname", nirtconfig_setHostname },
{ "setip", nirtconfig_setIpAddress },
{ "restart", nirtconfig_restartTarget },
{ "updatefirmware", nirtconfig_updateFirmware },
{ "findsn", nirtconfig_ipFromSerialNumber },
{ "setmode", nirtconfig_setModuleMode },
{ "listhw", nirtconfig_listHardware },
{ "format", nirtconfig_format },
{ "setalias", nirtconfig_setAlias },
{ NULL, NULL }
};
int main(int argc, char** argv)
{
int status = 0;
if (argc > 1) //Command passed as argument
{
int i = 0;
while (nirtFunctions[i].name != NULL) //Iterate through function lookup table
{
if (strcmp(nirtFunctions[i].name, argv[1]) == 0) //Check if command matches function in table
{
status = (*nirtFunctions[i].fpointer)(argc, argv);
break;
}
i++;
}
if (nirtFunctions[i].name == NULL)
printf("Invalid Command: %s\n", argv[1]);
}
else //No arguments passed
{
printf("No Function Passed\n");
status = 1;
}
if (status != 0)
nirtconfig_printStatusInfo(status);
return status;
}
void nirtconfig_printStatusInfo(int status)
{
char* detailedResults = NULL;
NISysCfgGetStatusDescription(NULL, (NISysCfgStatus)status, &detailedResults);
printf("Error: %d\n", status);
if (strcmp(detailedResults, "") != 0)
printf("%s\n", detailedResults);
NISysCfgFreeDetailedString(detailedResults);
}
int nirtconfig_find(int argc, char** argv)
{
int status = 0;
if (argc > 2) //IP address passed as argument, find specific target
{
status = nirtconfig_findSingleTarget(argv[2]);
}
else //no arguments passed, find all available targets
{
status = nirtconfig_findAllTargets();
}
return status;
}
int nirtconfig_findSingleTarget(char* targetName)
{
int status = 0;
NISysCfgSessionHandle session = NULL;
status = NISysCfgInitializeSession(targetName, NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
printf("%-35s%-20s%-15s%s\n", "HOSTNAME", "IP ADDR", "MODEL", "SERIAL NUMBER");
nirtconfig_printSystemInfo(session);
status = NISysCfgCloseHandle(session);
return status;
}
int nirtconfig_findAllTargets()
{
NISysCfgEnumSystemHandle enumSystemHandle = NULL;
NISysCfgSessionHandle session = NULL;
char systemName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
int status = 0;
printf("Finding Available Targets...\n");
status = NISysCfgFindSystems(NULL, NULL, NISysCfgBoolTrue,
NISysCfgIncludeCachedResultsOnlyIfOnline, NISysCfgSystemNameFormatHostname,
10000, NISysCfgBoolTrue, &enumSystemHandle);
printf("%-35s%-20s%-15s%s\n", "HOSTNAME", "IP ADDR", "MODEL", "SERIAL NUMBER");
while (NISysCfgNextSystemInfo(enumSystemHandle, systemName) == NISysCfg_OK) //Iterate through systems found
{
NISysCfgInitializeSession(systemName, NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
nirtconfig_printSystemInfo(session);
NISysCfgCloseHandle(session);
}
NISysCfgCloseHandle(enumSystemHandle);
return status;
}
void nirtconfig_printSystemInfo(NISysCfgSessionHandle session)
{
char hostname[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char ipaddr[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char model[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char serialNumber[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
NISysCfgGetSystemProperty(session, NISysCfgSystemPropertyHostname, hostname);
NISysCfgGetSystemProperty(session, NISysCfgSystemPropertyIpAddress, ipaddr);
NISysCfgGetSystemProperty(session, NISysCfgSystemPropertyProductName, model);
NISysCfgGetSystemProperty(session, NISysCfgSystemPropertySerialNumber, serialNumber);
printf("%-35s%-20s%-15s%s\n", hostname, ipaddr, model, serialNumber);
}
int nirtconfig_getImage(int argc, char** argv)
{
if (argc != 3) //Check for correct number of arguments
{
printf("Error Expecting Arguments: getimage <TARGETNAME>\n");
return 0;
}
int status = 0;
NISysCfgSessionHandle session = NULL;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
char destination[256] = "";
nirtconfig_buildOutputDir(session, destination);
printf("Getting Image: %s\nSaving To: \"%s\"\n", argv[2], destination);
status = NISysCfgGetSystemImageAsFolder2(session, NISysCfgBoolTrue, destination,
NULL, 0, NULL, NISysCfgBoolTrue, NISysCfgBoolFalse);
return status;
}
void nirtconfig_buildOutputDir(NISysCfgSessionHandle session, char* pathBuffer)
{
char hostname[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
getcwd(pathBuffer, 256);
strcat(pathBuffer, "/");
NISysCfgGetSystemProperty(session, NISysCfgSystemPropertyHostname, hostname);
strcat(pathBuffer, hostname);
}
int nirtconfig_setImage(int argc, char** argv)
{
if (argc != 4) //Check for correct number of arguments
{
printf("Error Expecting Arguments: setimage <TARGETNAME> <IMAGEPATH>\n");
return 0;
}
int status = 0;
NISysCfgSessionHandle session = NULL;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
printf("Imaging Target: %s\nImage Used: %s\n", argv[2], argv[3]);
status = NISysCfgSetSystemImageFromFolder2(session, NISysCfgBoolTrue, argv[3], "", 0, NULL,
NISysCfgBoolFalse, NISysCfgPreservePrimaryResetOthers);
NISysCfgCloseHandle(session);
return status;
}
int nirtconfig_selfTest(int argc, char** argv)
{
if (argc != 3) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: selftest <TARGETNAME>");
return 0;
}
NISysCfgSessionHandle session = NULL;
int status = 0;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
NISysCfgEnumResourceHandle resourceHandle = NULL;
NISysCfgResourceHandle resource = NULL;
NISysCfgFilterHandle filter = NULL;
NISysCfgCreateFilter(session, &filter);
NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertySlotNumber, 0);
status = NISysCfgFindHardware(session, NISysCfgFilterModeAllPropertiesExist, filter, NULL, &resourceHandle);
printf("Running Self Tests...\n");
printf("%-40s%-20s%-15s%s\n", "RESOURCE NAME", "PRODUCT NAME", "PASS/FAIL", "DETAILED RESULTS");
while (NISysCfgNextResource(session, resourceHandle, &resource) == NISysCfg_OK) //Iterate through all hardware resources
{
nirtconfig_printSelfTestResults(resource);
NISysCfgCloseHandle(resource);
}
NISysCfgCloseHandle(resourceHandle);
NISysCfgCloseHandle(session);
return status;
}
void nirtconfig_printSelfTestResults(NISysCfgResourceHandle resource)
{
char productName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char resourceName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char alias[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char passFail[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char* detailedResults = NULL;
int status = 0;
NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertyProductName, productName);
NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyExpertResourceName, 0, resourceName);
NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyExpertUserAlias, 0, alias);
status = NISysCfgSelfTestHardware(resource, 0, &detailedResults);
switch (status) //populate pass/fail string
{
case NISysCfg_OK:
strcpy(passFail, "Pass");
break;
case NISysCfg_NotImplemented:
strcpy(passFail, "Not Supported");
break;
default:
sprintf(passFail, "Error: %d", status);
}
//print results using resource's alias if available, resource name if not
if (strlen(alias))
printf("%-40s%-20s%-15s%s\n", alias, productName, passFail, detailedResults);
else
printf("%-40s%-20s%-15s%s\n", resourceName, productName, passFail, detailedResults);
NISysCfgFreeDetailedString(detailedResults);
}
int nirtconfig_setHostname(int argc, char** argv)
{
if (argc != 4) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: sethostname <TARGETNAME> <NEW_TARGETNAME>\n");
return 0;
}
NISysCfgSessionHandle session = NULL;
int status = 0;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
printf("Updating Hostname of %s to %s\n", argv[2], argv[3]);
status = NISysCfgSetSystemProperty(session, NISysCfgSystemPropertyHostname, argv[3]);
NISysCfgBool restartRequired;
char* detailedResults = NULL;
NISysCfgSaveSystemChanges(session, &restartRequired, &detailedResults);
NISysCfgFreeDetailedString(detailedResults);
NISysCfgCloseHandle(session);
return status;
}
int nirtconfig_setIpAddress(int argc, char** argv)
{
if (argc < 4) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: sethostname <TARGETNAME> <NEW_IP>\n");
return 0;
}
NISysCfgSessionHandle session = NULL;
int status = 0;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
printf("Updating IP Address of %s to %s\n", argv[2], argv[3]);
status = NISysCfgSetSystemProperty(session, NISysCfgSystemPropertyIpAddress, argv[3]);
status = NISysCfgSetSystemProperty(session, NISysCfgSystemPropertyIpAddressMode, NISysCfgIpAddressModeStatic);
NISysCfgBool restartRequired;
char* detailedResults = NULL;
status = NISysCfgSaveSystemChanges(session, &restartRequired, &detailedResults);
NISysCfgFreeDetailedString(detailedResults);
NISysCfgCloseHandle(session);
return status;
}
int nirtconfig_restartTarget(int argc, char** argv)
{
if (argc != 3) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: restart <TARGETNAME>\n");
return 0;
}
NISysCfgSessionHandle session = NULL;
int status = 0;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
char ipAddr[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
printf("Restarting...\n");
status = NISysCfgRestart(session, NISysCfgBoolTrue, NISysCfgBoolFalse, NISysCfgBoolFalse, 120000, ipAddr);
if (status == 0)
printf("Restarted With IP Address: %s\n", ipAddr);
NISysCfgCloseHandle(session);
return status;
}
int nirtconfig_updateFirmware(int argc, char** argv)
{
if (argc < 4) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: updatefirmware <TARGETNAME> <FIRMWARE_PATH>\n");
return 0;
}
NISysCfgSessionHandle session = NULL;
char username[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char password[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
int status = 0;
nirtconfig_getCredentials(argc, argv, username, password);
status = NISysCfgInitializeSession(argv[argc - 2], username, password, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
NISysCfgResourceHandle resource = NULL;
NISysCfgFirmwareStatus firmwareStatus;
char* detailedResults = NULL;
if (nirtconfig_findFirmwareResource(session, &resource) == NISysCfg_OK) //Get hardware resource and set firmware
{
printf("Updating Firmware...\nTarget: %s\nFirmware: %s\n", argv[argc - 2], argv[argc - 1]);
status = NISysCfgUpgradeFirmwareFromFile(resource, argv[argc - 1], NISysCfgBoolTrue, NISysCfgBoolTrue,
NISysCfgBoolTrue, &firmwareStatus, &detailedResults);
printf("Firmware Status: %d\nDetailed Results: %s\n", firmwareStatus, detailedResults);
}
NISysCfgFreeDetailedString(detailedResults);
NISysCfgCloseHandle(resource);
NISysCfgCloseHandle(session);
return status;
}
void nirtconfig_getCredentials(int argc, char** argv, char* username, char* password)
{
int flag;
while ((flag = getopt(argc, argv, "u:p:")) != -1) //search through incoming arguments
{
switch (flag)
{
case 'u':
strcpy(username, optarg);
break;
case 'p':
strcpy(password, optarg);
break;
default:
break;
}
}
}
int nirtconfig_findFirmwareResource(NISysCfgSessionHandle session, NISysCfgResourceHandle* resource)
{
int status = 0;
NISysCfgEnumResourceHandle resourceHandle = NULL;
NISysCfgFilterHandle filter = NULL;
NISysCfgCreateFilter(session, &filter);
NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertySupportsFirmwareUpdate, NISysCfgBoolTrue);
NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertyResourceName, "system");
NISysCfgFindHardware(session, NISysCfgFilterModeMatchValuesAll, filter, NULL, &resourceHandle);
status = NISysCfgNextResource(session, resourceHandle, resource);
NISysCfgCloseHandle(resourceHandle);
return status;
}
int nirtconfig_ipFromSerialNumber(int argc, char** argv)
{
if (argc < 3) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: findsn <SERIAL_NUMBER> \n");
return 0;
}
NISysCfgEnumSystemHandle enumSystemHandle = NULL;
NISysCfgSessionHandle session = NULL;
char systemIP[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char serialNumber[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
int status = 0;
status = NISysCfgFindSystems(NULL, NULL, NISysCfgBoolTrue,
NISysCfgIncludeCachedResultsOnlyIfOnline, NISysCfgSystemNameFormatIp,
10000, NISysCfgBoolTrue, &enumSystemHandle);
while (NISysCfgNextSystemInfo(enumSystemHandle, systemIP) == NISysCfg_OK) //Iterate through systems found
{
NISysCfgInitializeSession(systemIP, NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
NISysCfgGetSystemProperty(session, NISysCfgSystemPropertySerialNumber, serialNumber);
NISysCfgCloseHandle(session);
if ((strcmp(argv[2], serialNumber)) == 0) //Found correct target
{
NISysCfgCloseHandle(enumSystemHandle);
printf("%s\n", systemIP);
return 0;
}
}
printf("Target With SN %s Not Found\n", argv[2]);
NISysCfgCloseHandle(enumSystemHandle);
return status;
}
int nirtconfig_setModuleMode(int argc, char** argv)
{
if (argc < 4) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: setmode <TARGETNAME> <scan|fpga|daq>\n");
return 0;
}
//Get module programming mode from input
NISysCfgModuleProgramMode moduleMode = NISysCfgModuleProgramModeNone;
if (strcmp(argv[3], "scan") == 0)
moduleMode = NISysCfgModuleProgramModeRealtimeScan;
else if (strcmp(argv[3], "fpga") == 0)
moduleMode = NISysCfgModuleProgramModeLabVIEWFpga;
else if (strcmp(argv[3], "daq") == 0)
moduleMode = NISysCfgModuleProgramModeRealtimeCpu;
else
{
printf("Programming mode \"%s\" invalid. Choose from programming modes scan, fpga, or daq.\n", argv[3]);
return 0;
}
NISysCfgSessionHandle session = NULL;
int status = 0;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializing session
nirtconfig_setAllModuleModes(session, moduleMode);
NISysCfgCloseHandle(session);
return status;
}
void nirtconfig_setAllModuleModes(NISysCfgSessionHandle session, NISysCfgModuleProgramMode moduleMode)
{
NISysCfgEnumResourceHandle resourceHandle = NULL;
NISysCfgFilterHandle filter = NULL;
NISysCfgResourceHandle resource = NULL;
char alias[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char productName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
NISysCfgBool changesRequired;
char* detailedResults;
int status = 0;
NISysCfgCreateFilter(session, &filter);
NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertyConnectsToBusType, NISysCfgBusTypeCompactRio);
NISysCfgFindHardware(session, NISysCfgFilterModeMatchValuesAll, filter, NULL, &resourceHandle);
while ((NISysCfgNextResource(session, resourceHandle, &resource)) == NISysCfg_OK) //Iterate through all modules
{
NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyExpertUserAlias, 0, alias);
NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertyProductName, productName);
printf("Setting Module Mode: %s (%s)\n", alias, productName);
NISysCfgSetResourceProperty(resource, NISysCfgResourcePropertyModuleProgramMode, moduleMode);
NISysCfgSaveResourceChanges(resource, &changesRequired, &detailedResults);
NISysCfgCloseHandle(resource);
}
NISysCfgFreeDetailedString(detailedResults);
NISysCfgCloseHandle(resourceHandle);
}
int nirtconfig_listHardware(int argc, char** argv)
{
if (argc != 3) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: listhw <TARGETNAME>\n");
return 0;
}
NISysCfgSessionHandle session = NULL;
int status = 0;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializing session
NISysCfgEnumResourceHandle resourceHandle = NULL;
NISysCfgResourceHandle resource = NULL;
NISysCfgFilterHandle filter = NULL;
NISysCfgCreateFilter(session, &filter);
NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertySlotNumber, 0);
status = NISysCfgFindHardware(session, NISysCfgFilterModeAllPropertiesExist, filter, NULL, &resourceHandle);
printf("%-10s%-15s%s\n", "SLOT", "MODULE", "ALIAS");
while (NISysCfgNextResource(session, resourceHandle, &resource) == NISysCfg_OK) //Iterate through all hardware resources
{
nirtconfig_printHardwareList(resource);
NISysCfgCloseHandle(resource);
}
NISysCfgCloseHandle(resourceHandle);
NISysCfgCloseHandle(session);
return status;
}
void nirtconfig_printHardwareList(NISysCfgResourceHandle resource)
{
char productName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char alias[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char serialNumber[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
int slotNumber = 0;
int status = 0;
NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertyProductName, productName);
NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertySlotNumber, &slotNumber);
NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyExpertUserAlias, 0, alias);
NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertySerialNumber, serialNumber);
// Filter out resources without a SN
// PXIe controllers will list GPIB ports as a unique resource in slot 1
if (strcmp(serialNumber, "") != 0)
printf("%-10d%-15s%s\n", slotNumber, productName, alias);
}
int nirtconfig_format(int argc, char** argv)
{
if (argc < 3) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: format <TARGETNAME>\n");
return 0;
}
NISysCfgSessionHandle session = NULL;
char username[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
char password[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
int status = 0;
nirtconfig_getCredentials(argc, argv, username, password);
status = NISysCfgInitializeSession(argv[argc - 1], username, password, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
printf("Formatting...\n");
status = NISysCfgFormat(session, NISysCfgBoolTrue, NISysCfgBoolTrue,
NISysCfgFileSystemDefault, NISysCfgPreservePrimaryResetOthers, 120000);
return status;
}
int nirtconfig_setAlias(int argc, char** argv)
{
if (argc != 5) //Check for correct number of incoming arguments
{
printf("Error Expecting Arguments: setalias <TARGETNAME> <SLOT> <NEW_ALIAS>\n");
return 0;
}
NISysCfgSessionHandle session = NULL;
int status = 0;
status = NISysCfgInitializeSession(argv[2], NULL, NULL, NISysCfgLocaleDefault,
NISysCfgBoolFalse, 10000, NULL, &session);
if (status != 0)
return status; //Error initializeing session
NISysCfgEnumResourceHandle resourceHandle = NULL;
NISysCfgResourceHandle resource = NULL;
NISysCfgFilterHandle filter = NULL;
NISysCfgBool nameExisted;
NISysCfgResourceHandle overwrittenResource = NULL;
int slotNumber = 0;
sscanf(argv[3], "%d", &slotNumber); //convert char argument to int
NISysCfgCreateFilter(session, &filter);
NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertySlotNumber, slotNumber);
NISysCfgFindHardware(session, NISysCfgFilterModeMatchValuesAll, filter, NULL, &resourceHandle);
NISysCfgNextResource(session, resourceHandle, &resource);
status = NISysCfgRenameResource(resource, argv[4], NISysCfgBoolFalse, NISysCfgBoolTrue, &nameExisted, &overwrittenResource);
NISysCfgCloseHandle(resourceHandle);
NISysCfgCloseHandle(session);
return status;
}