-
-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy patharvtool.c
895 lines (773 loc) · 40.1 KB
/
arvtool.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
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
/* Aravis - Digital camera library
*
* Copyright © 2009-2022 Emmanuel Pacaud
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author: Emmanuel Pacaud <[email protected]>
*/
#include <arvdebugprivate.h>
#include <arvmiscprivate.h>
#include <arv.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static char *arv_option_device_selection = NULL;
static char *arv_option_device_address = NULL;
static char *arv_option_debug_domains = NULL;
static char *arv_option_register_cache = NULL;
static char *arv_option_range_check = NULL;
static char *arv_option_access_check = NULL;
static gboolean arv_option_gv_allow_broadcast_discovery_ack = FALSE;
static gboolean arv_option_show_time = FALSE;
static gboolean arv_option_show_version = FALSE;
static char *arv_option_gv_port_range = NULL;
static char *arv_option_gv_discovery_interface = NULL;
static const GOptionEntry arv_option_entries[] =
{
{
"name", 'n', 0, G_OPTION_ARG_STRING,
&arv_option_device_selection, NULL,
"<pattern>"
},
{
"address", 'a', 0, G_OPTION_ARG_STRING,
&arv_option_device_address, NULL,
"<device_address>"
},
{
"register-cache", '\0', 0, G_OPTION_ARG_STRING,
&arv_option_register_cache, "Register cache policy",
"{disable|enable|debug}"
},
{
"range-check", '\0', 0, G_OPTION_ARG_STRING,
&arv_option_range_check, "Range check policy",
"{disable|enable|debug}"
},
{
"access-check", '\0', 0, G_OPTION_ARG_STRING,
&arv_option_access_check, "Feature access check policy",
"{disable|enable}"
},
{
"gv-allow-broadcast-discovery-ack",
'\0', 0, G_OPTION_ARG_NONE,
&arv_option_gv_allow_broadcast_discovery_ack,
"Allow broadcast discovery ack",
NULL
},
{
"time", 't', 0, G_OPTION_ARG_NONE,
&arv_option_show_time, "Show execution time",
NULL
},
{
"gv-port-range", '\0', 0, G_OPTION_ARG_STRING,
&arv_option_gv_port_range, "GV port range",
"<min>-<max>"
},
{
"gv-discovery-interface", '\0', 0, G_OPTION_ARG_STRING,
&arv_option_gv_discovery_interface, "Discovery using the interface",
"<interface>"
},
{
"debug", 'd', 0, G_OPTION_ARG_STRING,
&arv_option_debug_domains, NULL,
"{<category>[:<level>][,...]|help}"
},
{
"version", 'v', 0, G_OPTION_ARG_NONE,
&arv_option_show_version, "Show version",
NULL
},
{ NULL }
};
static const char
description_content[] =
"Command may be one of the following possibilities:\n"
"\n"
" genicam: dump the content of the Genicam xml data\n"
" features: list all features\n"
" values: list all available feature values\n"
" description [<feature>] ...: show the full feature description\n"
" control <feature>[=<value>] ...: read/write device features\n"
" network <setting>[=<value>]...: read/write network settings\n"
"\n"
"If no command is given, this utility will list all the available devices.\n"
"For the control command, direct access to device registers is provided using a R[address] syntax"
" in place of a feature name.\n"
"\n"
"Examples:\n"
"\n"
"arv-tool-" ARAVIS_API_VERSION " control Width=128 Height=128 Gain R[0x10000]=0x10\n"
"arv-tool-" ARAVIS_API_VERSION " features\n"
"arv-tool-" ARAVIS_API_VERSION " description Width Height\n"
"arv-tool-" ARAVIS_API_VERSION " network mode=PersistentIP\n"
"arv-tool-" ARAVIS_API_VERSION " network ip=192.168.0.1 mask=255.255.255.0 gateway=192.168.0.254\n"
"arv-tool-" ARAVIS_API_VERSION " -n Basler-210ab4 genicam";
typedef enum {
ARV_TOOL_LIST_MODE_FEATURES,
ARV_TOOL_LIST_MODE_DESCRIPTIONS,
ARV_TOOL_LIST_MODE_VALUES
} ArvToolListMode;
static void
arv_tool_show_feature (ArvGcFeatureNode *node, ArvToolListMode list_mode, int level)
{
if (ARV_IS_GC_CATEGORY (node)) {
printf ("%*s%-12s: '%s'\n", 4 * level, "",
arv_dom_node_get_node_name (ARV_DOM_NODE (node)),
arv_gc_feature_node_get_name (node));
} else {
if (arv_gc_feature_node_is_available (node, NULL)) {
char *value = NULL;
GError *error = NULL;
gboolean is_selector;
const char *access_mode;
access_mode = arv_gc_access_mode_to_string (arv_gc_feature_node_get_actual_access_mode (node));
if (list_mode == ARV_TOOL_LIST_MODE_VALUES) {
const char *unit;
if (ARV_IS_GC_STRING (node) ||
ARV_IS_GC_ENUMERATION (node)) {
value = g_strdup_printf ("'%s'", arv_gc_string_get_value (ARV_GC_STRING (node),
&error));
} else if (ARV_IS_GC_INTEGER (node)) {
if (ARV_IS_GC_ENUMERATION (node)) {
value = g_strdup_printf ("'%s'",
arv_gc_string_get_value (ARV_GC_STRING (node),
&error));
} else {
unit = arv_gc_integer_get_unit (ARV_GC_INTEGER (node));
value = g_strdup_printf ("%" G_GINT64_FORMAT "%s%s",
arv_gc_integer_get_value (ARV_GC_INTEGER (node),
&error),
unit != NULL ? " " : "",
unit != NULL ? unit : "");
}
} else if (ARV_IS_GC_FLOAT (node)) {
unit = arv_gc_float_get_unit (ARV_GC_FLOAT (node));
value = g_strdup_printf ("%g%s%s",
arv_gc_float_get_value (ARV_GC_FLOAT (node),
&error),
unit != NULL ? " " : "",
unit != NULL ? unit : "");
} else if (ARV_IS_GC_BOOLEAN (node)) {
value = g_strdup_printf ("%s",
arv_gc_boolean_get_value (ARV_GC_BOOLEAN (node),
&error) ? "true" : "false");
} else if (ARV_IS_GC_REGISTER (node)) {
guint64 length;
length = arv_gc_register_get_length(ARV_GC_REGISTER (node), &error);
value = g_strdup_printf ("%" G_GUINT64_FORMAT, length);
}
}
is_selector = ARV_IS_GC_SELECTOR (node) && arv_gc_selector_is_selector (ARV_GC_SELECTOR (node));
if (error != NULL) {
g_clear_error (&error);
} else {
if (value != NULL && value[0] != '\0')
printf ("%*s%-13s: [%s] '%s' = %s\n", 4 * level, "",
arv_dom_node_get_node_name (ARV_DOM_NODE (node)),
access_mode, arv_gc_feature_node_get_name (node), value);
else
printf ("%*s%-13s: [%s] '%s'\n", 4 * level, "",
arv_dom_node_get_node_name (ARV_DOM_NODE (node)),
access_mode, arv_gc_feature_node_get_name (node));
if (is_selector) {
const GSList *iter;
for (iter = arv_gc_selector_get_selected_features (ARV_GC_SELECTOR (node));
iter != NULL;
iter = iter->next) {
printf (" %*s * %s\n", 4 * level, " ",
arv_gc_feature_node_get_name (iter->data));
}
}
}
g_clear_pointer (&value, g_free);
} else {
if (list_mode == ARV_TOOL_LIST_MODE_FEATURES)
printf ("%*s%-12s: '%s' (Not available)\n", 4 * level, "",
arv_dom_node_get_node_name (ARV_DOM_NODE (node)),
arv_gc_feature_node_get_name (node));
}
}
if (list_mode == ARV_TOOL_LIST_MODE_DESCRIPTIONS) {
const char *description;
description = arv_gc_feature_node_get_description (node);
if (description)
printf ("%s\n", description);
}
if (ARV_IS_GC_ENUMERATION (node) && list_mode == ARV_TOOL_LIST_MODE_FEATURES) {
const GSList *childs;
const GSList *iter;
childs = arv_gc_enumeration_get_entries (ARV_GC_ENUMERATION (node));
for (iter = childs; iter != NULL; iter = iter->next) {
if (arv_gc_feature_node_is_implemented (iter->data, NULL)) {
printf ("%*s%-12s: '%s'%s\n", 4 * (level + 1), "",
arv_dom_node_get_node_name (iter->data),
arv_gc_feature_node_get_name (iter->data),
arv_gc_feature_node_is_available (iter->data, NULL) ? "" : " (Not available)");
}
}
}
}
static void
arv_tool_list_features (ArvGc *genicam, const char *feature, ArvToolListMode list_mode, GRegex *regex, int level)
{
ArvGcNode *node;
node = arv_gc_get_node (genicam, feature);
if (ARV_IS_GC_FEATURE_NODE (node) &&
arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (node), NULL)) {
gboolean match;
match = regex == NULL || g_regex_match (regex,
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (node)),
0, NULL);
if (match)
arv_tool_show_feature (ARV_GC_FEATURE_NODE (node), list_mode, level);
if (ARV_IS_GC_CATEGORY (node)) {
const GSList *features;
const GSList *iter;
features = arv_gc_category_get_features (ARV_GC_CATEGORY (node));
for (iter = features; iter != NULL; iter = iter->next)
arv_tool_list_features (genicam, iter->data, list_mode, match ? NULL : regex, level + 1);
}
}
}
static void
arv_tool_control (int argc, char **argv, ArvDevice *device)
{
int i;
for (i = 2; i < argc; i++) {
ArvGcNode *feature;
char **tokens;
tokens = g_strsplit (argv[i], "=", 2);
feature = arv_device_get_feature (device, tokens[0]);
if (ARV_IS_GC_FEATURE_NODE (feature)) {
if (ARV_IS_GC_COMMAND (feature)) {
GError *error = NULL;
arv_gc_command_execute (ARV_GC_COMMAND (feature), &error);
if (error != NULL) {
printf ("%s execute error: %s\n",
tokens[0],
error->message);
g_clear_error (&error);
} else
printf ("%s executed\n", tokens[0]);
} else {
const char *unit;
GError *error = NULL;
if (tokens[1] != NULL)
arv_gc_feature_node_set_value_from_string (ARV_GC_FEATURE_NODE (feature),
tokens[1], &error);
if (error == NULL) {
if (ARV_IS_GC_STRING (feature) ||
ARV_IS_GC_ENUMERATION (feature)) {
const char *value = arv_gc_string_get_value (ARV_GC_STRING (feature),
&error);
if (error == NULL)
printf ("%s = %s\n", tokens[0], value);
} else if (ARV_IS_GC_INTEGER (feature)) {
gint64 max_int64, min_int64, inc_int64;
gint64 value;
min_int64 = arv_gc_integer_get_min (ARV_GC_INTEGER (feature), NULL);
max_int64 = arv_gc_integer_get_max (ARV_GC_INTEGER (feature), NULL);
inc_int64 = arv_gc_integer_get_inc (ARV_GC_INTEGER (feature), NULL);
unit = arv_gc_integer_get_unit (ARV_GC_INTEGER (feature));
value = arv_gc_integer_get_value (ARV_GC_INTEGER (feature), &error);
if (error == NULL) {
GString *string = g_string_new ("");
g_string_append_printf (string, "%s = %" G_GINT64_FORMAT,
tokens[0], value);
if (unit != NULL)
g_string_append_printf (string, " %s", unit);
if (min_int64 != G_MININT64)
g_string_append_printf (string, " min:%" G_GINT64_FORMAT,
min_int64);
if (max_int64 != G_MAXINT64)
g_string_append_printf (string, " max:%" G_GINT64_FORMAT,
max_int64);
if (inc_int64 != 1)
g_string_append_printf (string, " inc:%" G_GINT64_FORMAT,
inc_int64);
printf ("%s\n", string->str);
g_string_free (string, TRUE);
}
} else if (ARV_IS_GC_FLOAT (feature)) {
double max_double, min_double, inc_double;
GString *string = g_string_new ("");
double value;
min_double = arv_gc_float_get_min (ARV_GC_FLOAT (feature), NULL);
max_double = arv_gc_float_get_max (ARV_GC_FLOAT (feature), NULL);
inc_double = arv_gc_float_get_inc (ARV_GC_FLOAT (feature), NULL);
unit = arv_gc_float_get_unit (ARV_GC_FLOAT (feature));
value = arv_gc_float_get_value (ARV_GC_FLOAT (feature), &error);
if (error == NULL) {
g_string_append_printf (string, "%s = %g", tokens[0], value);
if (unit != NULL)
g_string_append_printf (string, " %s", unit);
if (min_double != -G_MAXDOUBLE)
g_string_append_printf (string, " min:%g", min_double);
if (max_double != G_MAXDOUBLE)
g_string_append_printf (string, " max:%g", max_double);
if (inc_double != G_MINDOUBLE)
g_string_append_printf (string, " inc:%g", inc_double);
printf ("%s\n", string->str);
g_string_free (string, TRUE);
}
} else if (ARV_IS_GC_BOOLEAN (feature)) {
gboolean value = arv_gc_boolean_get_value (ARV_GC_BOOLEAN (feature),
&error);
if (error == NULL)
printf ("%s = %s\n", tokens[0], value ? "true" : "false");
} else if (ARV_IS_GC_REGISTER (feature)) {
unsigned char *buffer;
guint64 length;
buffer = arv_gc_register_dup (ARV_GC_REGISTER (feature), &length,
&error);
if (error == NULL && buffer != NULL) {
GString *dump;
dump = g_string_new("");
printf ("%s = %" G_GUINT64_FORMAT " byte(s)@0x%08"
G_GINT64_MODIFIER "x\n",
tokens[0], length,
arv_gc_register_get_address (ARV_GC_REGISTER(feature),
NULL));
arv_g_string_append_hex_dump(dump, buffer, length);
printf ("%s\n", dump->str);
g_string_free (dump, TRUE);
}
g_free(buffer);
}else {
const char *value = arv_gc_feature_node_get_value_as_string
(ARV_GC_FEATURE_NODE (feature), &error);
if (error == NULL)
printf ("%s = %s\n", tokens[0], value);
}
}
if (error != NULL) {
printf ("%s %s error: %s\n",
tokens[0],
tokens[1] != NULL ? "write" : "read",
error->message);
g_clear_error (&error);
}
}
} else {
if (g_strrstr (tokens[0], "R[") == tokens[0]) {
guint32 value;
guint32 address;
GError *error = NULL;
address = g_ascii_strtoll(&tokens[0][2], NULL, 0);
if (tokens[1] != NULL) {
arv_device_write_register (device,
address,
g_ascii_strtoll (tokens[1],
NULL, 0), &error);
if (error != NULL)
printf ("R[0x%08x] write error: %s\n", address, error->message);
}
if (error == NULL) {
arv_device_read_register (device, address, &value, &error);
if (error == NULL) {
printf ("R[0x%08x] = 0x%08x\n",
address, value);
} else {
printf ("R[0x%08x] read error: %s\n", address, error->message);
}
}
g_clear_error(&error);
} else
printf ("Feature '%s' not found\n", tokens[0]);
}
g_strfreev (tokens);
}
}
static void
arv_tool_show_network_mode (ArvGvDevice* gv_device, GError** error)
{
GError *local_error = NULL;
ArvGvIpConfigurationMode mode;
mode = arv_gv_device_get_ip_configuration_mode (gv_device, &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return;
}
switch (mode) {
case ARV_GV_IP_CONFIGURATION_MODE_NONE:
printf ("Mode: None\n");
break;
case ARV_GV_IP_CONFIGURATION_MODE_PERSISTENT_IP:
printf ("Mode: PersistentIP\n");
break;
case ARV_GV_IP_CONFIGURATION_MODE_DHCP:
printf ("Mode: DHCP\n");
break;
case ARV_GV_IP_CONFIGURATION_MODE_LLA:
printf ("Mode: LLA\n");
break;
case ARV_GV_IP_CONFIGURATION_MODE_FORCE_IP:
printf ("Mode: ForceIP\n");
break;
}
}
static void
arv_tool_show_current_ip (ArvGvDevice* gv_device, GError** error)
{
GError *local_error = NULL;
GInetAddress* ip;
GInetAddressMask* mask;
GInetAddress* gateway;
gchar* ip_str;
gchar* mask_str;
gchar* gateway_str;
arv_gv_device_get_current_ip (gv_device, &ip, &mask, &gateway, &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return;
}
ip_str = g_inet_address_to_string (ip);
mask_str = g_inet_address_mask_to_string (mask);
gateway_str = g_inet_address_to_string (gateway);
g_object_unref(ip);
g_object_unref(mask);
g_object_unref(gateway);
printf ("Current IP: %s\nCurrent Mask: %s\nCurrent Gateway: %s\n", ip_str, mask_str, gateway_str);
g_free (ip_str);
g_free (mask_str);
g_free (gateway_str);
}
static void
arv_tool_show_persistent_ip (ArvGvDevice* gv_device, gboolean show_ip, gboolean show_mask, gboolean show_gateway, GError** error)
{
GError *local_error = NULL;
GInetAddress* ip;
GInetAddressMask* mask;
GInetAddress* gateway;
gchar* ip_str;
gchar* mask_str;
gchar* gateway_str;
arv_gv_device_get_persistent_ip (gv_device, &ip, &mask, &gateway, &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
return;
}
ip_str = g_inet_address_to_string (ip);
mask_str = g_inet_address_mask_to_string (mask);
gateway_str = g_inet_address_to_string (gateway);
g_object_unref(ip);
g_object_unref(mask);
g_object_unref(gateway);
if (show_ip)
printf ("Persistent IP: %s\n", ip_str);
if (show_mask)
printf ("Persistent Mask: %s\n", mask_str);
if (show_gateway)
printf ("Persistent Gateway: %s\n", gateway_str);
g_free (ip_str);
g_free (mask_str);
g_free (gateway_str);
}
static void
arv_tool_network (int argc, char **argv, ArvDevice *device)
{
ArvGvDevice* gv_device = NULL;
if (!ARV_IS_GV_DEVICE (device)) {
printf ("This is not a GV device\n");
return;
}
gv_device = ARV_GV_DEVICE (device);
if (argv[2] == NULL) {
GError *error = NULL;
arv_tool_show_network_mode (gv_device, &error);
if (error == NULL) {
arv_tool_show_current_ip (gv_device, &error);
}
if (error == NULL) {
arv_tool_show_persistent_ip (gv_device, TRUE, TRUE, TRUE, &error);
}
if (error != NULL) {
printf ("%s error: %s\n", argv[2], error->message);
g_clear_error (&error);
}
} else {
int i;
for (i = 2; i < argc; i++) {
GError *error = NULL;
char **tokens;
tokens = g_strsplit (argv[i], "=", 2);
if (g_strcmp0 (tokens[0], "mode") == 0) {
if (tokens[1] != NULL) {
ArvGvIpConfigurationMode mode;
if (g_ascii_strcasecmp (tokens[1], "PersistentIP") == 0)
mode = ARV_GV_IP_CONFIGURATION_MODE_PERSISTENT_IP;
else if (g_ascii_strcasecmp (tokens[1], "DHCP") == 0)
mode = ARV_GV_IP_CONFIGURATION_MODE_DHCP;
else if (g_ascii_strcasecmp (tokens[1], "LLA") == 0)
mode = ARV_GV_IP_CONFIGURATION_MODE_LLA;
else {
printf ("Unknown mode \"%s\". Avalaible modes: PersistentIP, DHCP and LLA\n",
tokens[1]);
return;
}
arv_gv_device_set_ip_configuration_mode (gv_device, mode, &error);
} else {
arv_tool_show_network_mode (gv_device, &error);
}
} else if (g_strcmp0 (tokens[0], "ip") == 0) {
if (tokens[1] != NULL) {
arv_gv_device_set_persistent_ip_from_string (gv_device, tokens[1], NULL, NULL, &error);
} else {
arv_tool_show_persistent_ip (gv_device, TRUE, FALSE, FALSE, &error);
}
} else if (g_strcmp0 (tokens[0], "mask") == 0) {
if (tokens[1] != NULL) {
arv_gv_device_set_persistent_ip_from_string (gv_device, NULL, tokens[1], NULL, &error);
} else {
arv_tool_show_persistent_ip (gv_device, FALSE, TRUE, FALSE, &error);
}
} else if (g_strcmp0 (tokens[0], "gateway") == 0) {
if (tokens[1] != NULL) {
arv_gv_device_set_persistent_ip_from_string (gv_device, NULL, NULL, tokens[1], &error);
} else {
arv_tool_show_persistent_ip (gv_device, FALSE, FALSE, TRUE, &error);
}
}
if (error != NULL) {
printf ("%s error: %s\n", argv[i], error->message);
g_clear_error (&error);
return;
}
g_strfreev (tokens);
}
}
}
static void
arv_tool_execute_command (int argc, char **argv, ArvDevice *device,
ArvRegisterCachePolicy register_cache_policy,
ArvRangeCheckPolicy range_check_policy,
ArvAccessCheckPolicy access_check_policy)
{
ArvGc *genicam;
const char *command = argv[1];
gint64 start;
if (device == NULL || argc < 2)
return;
arv_device_set_register_cache_policy (device, register_cache_policy);
arv_device_set_range_check_policy (device, range_check_policy);
arv_device_set_access_check_policy (device, access_check_policy);
genicam = arv_device_get_genicam (device);
start = g_get_monotonic_time ();
if (g_strcmp0 (command, "genicam") == 0) {
const char *xml;
size_t size;
xml = arv_device_get_genicam_xml (device, &size);
if (xml != NULL)
printf ("%*s\n", (int) size, xml);
} else if (g_strcmp0 (command, "features") == 0) {
if (argc > 3)
printf ("features command takes at most one feature selection parameter\n");
else {
GRegex *regex;
regex = arv_regex_new_from_glob_pattern (argc == 3 ? argv[2] : "*", TRUE);
arv_tool_list_features (genicam, "Root", ARV_TOOL_LIST_MODE_FEATURES, regex, 0);
g_regex_unref (regex);
}
} else if (g_strcmp0 (command, "values") == 0) {
if (argc > 3)
printf ("features command takes at most one feature selection parameter\n");
else {
GRegex *regex;
regex = arv_regex_new_from_glob_pattern (argc == 3 ? argv[2] : "*", TRUE);
arv_tool_list_features (genicam, "Root", ARV_TOOL_LIST_MODE_VALUES, regex, 0);
g_regex_unref (regex);
}
} else if (g_strcmp0 (command, "description") == 0) {
if (argc > 3)
printf ("features command takes at most one feature selection parameter\n");
else {
GRegex *regex;
regex = arv_regex_new_from_glob_pattern (argc == 3 ? argv[2] : "*", TRUE);
arv_tool_list_features (genicam, "Root", ARV_TOOL_LIST_MODE_DESCRIPTIONS, regex, 0);
g_regex_unref (regex);
}
} else if (g_strcmp0 (command, "control") == 0) {
arv_tool_control (argc, argv, device);
} else if (g_strcmp0 (command, "network") == 0) {
arv_tool_network (argc, argv, device);
} else {
printf ("Unknown command\n");
}
if (arv_option_show_time)
printf ("Executed in %g s\n", (g_get_monotonic_time () - start) / 1000000.0);
}
int
main (int argc, char **argv)
{
ArvDevice *device;
ArvRegisterCachePolicy register_cache_policy;
ArvRangeCheckPolicy range_check_policy;
ArvAccessCheckPolicy access_check_policy;
GRegex *regex;
const char *device_id;
GOptionContext *context;
GError *error = NULL;
unsigned int n_devices;
unsigned int n_found_devices = 0;
unsigned int i;
gboolean is_glob_pattern = FALSE;
context = g_option_context_new (" command <parameters>");
g_option_context_set_summary (context, "Small utility for basic control of a Genicam device.");
g_option_context_set_description (context, description_content);
g_option_context_add_main_entries (context, arv_option_entries, NULL);
if (!g_option_context_parse (context, &argc, &argv, &error)) {
g_option_context_free (context);
g_print ("Option parsing failed: %s\n", error->message);
g_error_free (error);
return EXIT_FAILURE;
}
g_option_context_free (context);
if (arv_option_show_version) {
printf ("%u.%u.%u\n",
arv_get_major_version (),
arv_get_minor_version (),
arv_get_micro_version ());
return EXIT_SUCCESS;
}
if (arv_option_register_cache == NULL)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_DEFAULT;
else if (g_strcmp0 (arv_option_register_cache, "disable") == 0)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_DISABLE;
else if (g_strcmp0 (arv_option_register_cache, "enable") == 0)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_ENABLE;
else if (g_strcmp0 (arv_option_register_cache, "debug") == 0)
register_cache_policy = ARV_REGISTER_CACHE_POLICY_DEBUG;
else {
printf ("Invalid register cache policy\n");
return EXIT_FAILURE;
}
if (arv_option_range_check == NULL)
range_check_policy = ARV_RANGE_CHECK_POLICY_DEFAULT;
else if (g_strcmp0 (arv_option_range_check, "disable") == 0)
range_check_policy = ARV_RANGE_CHECK_POLICY_DISABLE;
else if (g_strcmp0 (arv_option_range_check, "enable") == 0)
range_check_policy = ARV_RANGE_CHECK_POLICY_ENABLE;
else if (g_strcmp0 (arv_option_range_check, "debug") == 0)
range_check_policy = ARV_RANGE_CHECK_POLICY_DEBUG;
else {
printf ("Invalid range check policy\n");
return EXIT_FAILURE;
}
if (arv_option_access_check == NULL)
access_check_policy = ARV_ACCESS_CHECK_POLICY_DEFAULT;
else if (g_strcmp0 (arv_option_access_check, "disable") == 0)
access_check_policy = ARV_ACCESS_CHECK_POLICY_DISABLE;
else if (g_strcmp0 (arv_option_access_check, "enable") == 0)
access_check_policy = ARV_ACCESS_CHECK_POLICY_ENABLE;
else {
printf ("Invalid access check policy\n");
return EXIT_FAILURE;
}
if (arv_option_gv_port_range != NULL) {
gboolean success;
success = arv_set_gv_port_range_from_string (arv_option_gv_port_range);
if (!success) {
printf ("Invalid GV port range (%s)\n", arv_option_gv_port_range);
return EXIT_FAILURE;
}
}
if (!arv_debug_enable (arv_option_debug_domains)) {
if (g_strcmp0 (arv_option_debug_domains, "help") != 0)
printf ("Invalid debug selection\n");
else
arv_debug_print_infos ();
return EXIT_FAILURE;
}
for (i = 0; arv_option_device_selection != NULL && arv_option_device_selection[i] != '\0'; i++)
if (arv_option_device_selection[i] == '*' ||
arv_option_device_selection[i] == '?' ||
arv_option_device_selection[i] == '|')
is_glob_pattern = TRUE;
if (arv_option_gv_allow_broadcast_discovery_ack)
arv_set_interface_flags ("GigEVision", ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK);
if (arv_option_gv_discovery_interface)
arv_gv_interface_set_discovery_interface_name (arv_option_gv_discovery_interface);
device_id = arv_option_device_address != NULL ?
arv_option_device_address :
(is_glob_pattern ? NULL : arv_option_device_selection);
if (device_id != NULL) {
GError *error = NULL;
device = arv_open_device (device_id, &error);
if (ARV_IS_DEVICE (device)) {
if (argc < 2) {
printf ("%s\n", device_id);
} else {
arv_tool_execute_command (argc, argv, device,
register_cache_policy,
range_check_policy,
access_check_policy);
}
g_object_unref (device);
} else {
if (error != NULL) {
fprintf (stderr, "%s\n", error->message);
g_clear_error (&error);
} else {
fprintf (stderr, "Device '%s' not found", device_id);
}
}
arv_shutdown ();
return EXIT_SUCCESS;
}
arv_update_device_list ();
n_devices = arv_get_n_devices ();
regex = arv_regex_new_from_glob_pattern (arv_option_device_selection != NULL ?
arv_option_device_selection : "*", TRUE);
if (n_devices > 0) {
for (i = 0; i < n_devices; i++) {
GError *error = NULL;
device_id = arv_get_device_id (i);
if (g_regex_match (regex, device_id, 0, NULL)) {
n_found_devices++;
printf ("%s (%s)\n", device_id, arv_get_device_address (i));
if (argc >= 2) {
device = arv_open_device (device_id, &error);
if (ARV_IS_DEVICE (device)) {
arv_tool_execute_command (argc, argv, device,
register_cache_policy,
range_check_policy,
access_check_policy);
g_object_unref (device);
} else {
fprintf (stderr, "Failed to open device '%s'%s%s\n", device_id,
error != NULL ? ": " : "",
error != NULL ? error->message : "");
g_clear_error (&error);
}
}
}
}
}
if (n_found_devices < 1) {
if (n_devices > 0)
fprintf (stderr, "No matching device found (%d filtered out)\n", n_devices);
else
fprintf (stderr, "No device found\n");
}
g_regex_unref (regex);
arv_shutdown ();
return EXIT_SUCCESS;
}