diff --git a/src/cap5/camonitor.pl b/src/cap5/camonitor.pl index a1e30685f..56c609141 100644 --- a/src/cap5/camonitor.pl +++ b/src/cap5/camonitor.pl @@ -8,13 +8,14 @@ use lib "$Bin/../../lib/perl"; use Getopt::Std; use CA; -our ($opt_0, $opt_C, $opt_e, $opt_f, $opt_g, $opt_h, $opt_n, $opt_s); +our ($opt_0, $opt_c, $opt_e, $opt_f, $opt_g, $opt_h, $opt_n, $opt_s, $opt_S); +our $opt_F = ' '; our $opt_w = 1; our $opt_m = 'va'; $Getopt::Std::OUTPUT_HELP_VERSION = 1; -HELP_MESSAGE() unless getopts('0:C:e:f:g:hm:nsw:'); +HELP_MESSAGE() unless getopts('0:c:e:f:F:g:hm:nsSw:'); HELP_MESSAGE() if $opt_h; die "No pv name specified. ('camonitor -h' gives help.)\n" @@ -23,9 +24,11 @@ die "No pv name specified. ('camonitor -h' gives help.)\n" my %monitors; my @chans = map { CA->new($_, \&conn_callback); } @ARGV; +my $fmt = ($opt_F eq ' ') ? "%-30s %s\n" : "%s$opt_F%s\n"; + CA->pend_event($opt_w); map { - printf "%-30s %s\n", $_->name, '*** Not connected (PV not found)' + printf $fmt, $_->name, '*** Not connected (PV not found)' unless $monitors{$_}; } @chans; CA->pend_event(0); @@ -36,13 +39,14 @@ sub conn_callback { if ($up && ! $monitors{$chan}) { my $type = $chan->field_type; $type = 'DBR_STRING' - if $opt_s && $type =~ m/ DBR_DOUBLE | DBR_FLOAT /x; + if $opt_s && $type =~ m/ ^ DBR_ ( DOUBLE | FLOAT ) $ /x; $type = 'DBR_LONG' - if $opt_n && $type eq 'DBR_ENUM'; + if ($opt_n && $type eq 'DBR_ENUM') + || (!$opt_S && $type eq 'DBR_CHAR'); $type =~ s/^DBR_/DBR_TIME_/; my $count = $chan->element_count; - $count = +$opt_C if $opt_C && $opt_C <= $count; + $count = +$opt_c if $opt_c && $opt_c <= $count; $monitors{$chan} = $chan->create_subscription($opt_m, \&mon_callback, $type, $count); @@ -52,7 +56,7 @@ sub conn_callback { sub mon_callback { my ($chan, $status, $data) = @_; if ($status) { - printf "%-30s %s\n", $chan->name, $status; + printf $fmt, $chan->name, $status; } else { display($chan, $data); } @@ -85,7 +89,7 @@ sub display { my $type = $data->{TYPE}; my $value = $data->{value}; if (ref $value eq 'ARRAY') { - $value = join(' ', $data->{COUNT}, + $value = join($opt_F, $data->{COUNT}, map { format_number($_, $type); } @{$value}); } else { $value = format_number($value, $type); @@ -98,8 +102,8 @@ sub display { $t[0] += $data->{stamp_fraction}; $stamp = sprintf "%4d-%02d-%02d %02d:%02d:%09.6f", reverse @t; } - printf "%-30s %s %s %s %s\n", $chan->name, - $stamp, $value, $data->{status}, $data->{severity}; + printf $fmt, $chan->name, join($opt_F, + $stamp, $value, $data->{status}, $data->{severity}); } sub HELP_MESSAGE { @@ -109,7 +113,8 @@ sub HELP_MESSAGE { "Channel Access options:\n", " -w : Wait time, specifies longer CA timeout, default is $opt_w second\n", " -m : Specify CA event mask to use, with being any combination of\n", - " 'v' (value), 'a' (alarm), 'l' (log). Default: '$opt_m'\n", + " 'v' (value), 'a' (alarm), 'l' (log/archive), 'p' (property)", + " Default: '$opt_m'\n", # "Timestamps:\n", # " Default: Print absolute timestamps (as reported by CA)\n", # " -r: Relative timestamps (time elapsed since start of program)\n", @@ -119,7 +124,8 @@ sub HELP_MESSAGE { " -n: Print DBF_ENUM values as number (default are enum string values)\n", "Arrays: Value format: print number of values, then list of values\n", " Default: Print all values\n", - " -C : Print first elements of an array\n", + " -c : Print first elements of an array\n", + " -S: Print array of char as a string (long string)\n", "Floating point type format:\n", " Default: Use %g format\n", " -e : Use %e format, with a precision of digits\n", @@ -131,10 +137,11 @@ sub HELP_MESSAGE { " -0x: Print as hex number\n", " -0o: Print as octal number\n", " -0b: Print as binary number\n", + "Alternate output field separator:\n", + " -F : Use to separate fields on output\n", "\n", "Example: camonitor -f8 my_channel another_channel\n", " (doubles are printed as %f with 8 decimal digits)\n", "\n"; exit 1; } -