line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lab::Generic; |
2
|
|
|
|
|
|
|
$Lab::Generic::VERSION = '3.880'; |
3
|
|
|
|
|
|
|
#ABSTRACT: General function library for the L::M classes |
4
|
|
|
|
|
|
|
|
5
|
9
|
|
|
9
|
|
112
|
use v5.20; |
|
9
|
|
|
|
|
35
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
6355
|
use Lab::Generic::CLOptions; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
322
|
|
8
|
|
|
|
|
|
|
|
9
|
9
|
|
|
9
|
|
73
|
use strict; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
194
|
|
10
|
9
|
|
|
9
|
|
4529
|
use Term::ReadKey; |
|
9
|
|
|
|
|
18602
|
|
|
9
|
|
|
|
|
12667
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @OBJECTS = (); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
21
|
|
|
21
|
0
|
61
|
my $proto = shift; |
16
|
21
|
|
33
|
|
|
95
|
my $class = ref($proto) || $proto; |
17
|
|
|
|
|
|
|
|
18
|
21
|
|
|
|
|
53
|
my $self = {}; |
19
|
21
|
|
|
|
|
62
|
push( @OBJECTS, $self ); |
20
|
|
|
|
|
|
|
|
21
|
21
|
|
|
|
|
43
|
bless( $self, $class ); |
22
|
21
|
|
|
|
|
60
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub set_name { |
26
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
27
|
0
|
|
|
|
|
|
my ($name) = $self->_check_args( \@_, ['name'] ); |
28
|
0
|
|
|
|
|
|
$self->{name} = $name; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_name { |
32
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
return $self->{name}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
13
|
0
|
|
sub abort { } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub print { |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
my @data = @_; |
41
|
0
|
|
|
|
|
|
my ( $package, $filename, $line, $subroutine ) = caller(1); |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ( ref( @data[0] ) eq 'HASH' ) { |
|
|
0
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
while ( my ( $k, $v ) = each %{ @data[0] } ) { |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $line = "$k => "; |
46
|
0
|
|
|
|
|
|
$line .= $self->print($v); |
47
|
0
|
0
|
|
|
|
|
if ( $subroutine =~ /print/ ) { |
48
|
0
|
|
|
|
|
|
return $line; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
0
|
|
|
|
|
|
print $line. "\n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif ( ref( @data[0] ) eq 'ARRAY' ) { |
56
|
0
|
|
|
|
|
|
my $line = "["; |
57
|
0
|
|
|
|
|
|
foreach ( @{ @data[0] } ) { |
|
0
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$line .= $self->print($_); |
59
|
0
|
|
|
|
|
|
$line .= ", "; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
chop($line); |
62
|
0
|
|
|
|
|
|
chop($line); |
63
|
0
|
|
|
|
|
|
$line .= "]"; |
64
|
0
|
0
|
|
|
|
|
if ( $subroutine =~ /print/ ) { |
65
|
0
|
|
|
|
|
|
return $line; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
0
|
|
|
|
|
|
print $line. "\n"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
0
|
|
|
|
|
if ( $subroutine =~ /print/ ) { |
73
|
0
|
|
|
|
|
|
return @data[0]; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else { |
76
|
0
|
|
|
|
|
|
print @data[0] . "\n"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _check_args { |
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my $args = shift; |
85
|
0
|
|
|
|
|
|
my $params = shift; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $arguments = {}; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $i = 0; |
90
|
0
|
|
|
|
|
|
foreach my $arg ( @{$args} ) { |
|
0
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ( ref($arg) ne "HASH" ) { |
92
|
0
|
0
|
|
|
|
|
if ( defined @{$params}[$i] ) { |
|
0
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$arguments->{ @{$params}[$i] } = $arg; |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
$i++; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
|
%{$arguments} = ( %{$arguments}, %{$arg} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$i++; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my @return_args = (); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
foreach my $param ( @{$params} ) { |
|
0
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if ( exists $arguments->{$param} ) { |
107
|
0
|
|
|
|
|
|
push( @return_args, $arguments->{$param} ); |
108
|
0
|
|
|
|
|
|
delete $arguments->{$param}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
0
|
|
|
|
|
|
push( @return_args, undef ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
foreach my $param ( 'from_device', 'from_cache' |
116
|
|
|
|
|
|
|
) # Delete Standard option parameters from $arguments hash if not defined in device driver function |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
0
|
|
|
|
|
if ( exists $arguments->{$param} ) { |
119
|
0
|
|
|
|
|
|
delete $arguments->{$param}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
push( @return_args, $arguments ); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# if (scalar(keys %{$arguments}) > 0) |
126
|
|
|
|
|
|
|
# { |
127
|
|
|
|
|
|
|
# my $errmess = "Unknown parameter given in $self :"; |
128
|
|
|
|
|
|
|
# while ( my ($k,$v) = each %{$arguments} ) |
129
|
|
|
|
|
|
|
# { |
130
|
|
|
|
|
|
|
# $errmess .= $k." => ".$v."\t"; |
131
|
|
|
|
|
|
|
# } |
132
|
|
|
|
|
|
|
# print Lab::Exception::Warning->new( error => $errmess); |
133
|
|
|
|
|
|
|
# } |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
return @return_args; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub my_sleep { |
139
|
0
|
|
|
0
|
0
|
|
my $sleeptime = shift; |
140
|
0
|
|
|
|
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my $user_command = shift; |
142
|
0
|
0
|
|
|
|
|
if ( $sleeptime >= 5 ) { |
143
|
0
|
|
|
|
|
|
countdown( $sleeptime * 1e6, $self, $user_command ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else { |
146
|
0
|
|
|
|
|
|
usleep( $sleeptime * 1e6 ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub my_usleep { |
151
|
0
|
|
|
0
|
0
|
|
my $sleeptime = shift; |
152
|
0
|
|
|
|
|
|
my $self = shift; |
153
|
0
|
|
|
|
|
|
my $user_command = shift; |
154
|
0
|
0
|
|
|
|
|
if ( $sleeptime >= 5 ) { |
155
|
0
|
|
|
|
|
|
countdown( $sleeptime, $self, $user_command ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else { |
158
|
0
|
|
|
|
|
|
usleep($sleeptime); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub countdown { |
163
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
164
|
0
|
|
|
|
|
|
my $duration = shift; |
165
|
0
|
|
|
|
|
|
my $user_command = shift; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
ReadMode('cbreak'); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$duration /= 1e6; |
170
|
0
|
|
|
|
|
|
my $hours = int( $duration / 3600 ); |
171
|
0
|
|
|
|
|
|
my $minutes = int( ( $duration - $hours * 3600 ) / 60 ); |
172
|
0
|
|
|
|
|
|
my $seconds = $duration - $hours * 3600 - $minutes * 60; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
my $t_0 = time(); |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
local $| = 1; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my $message = "Waiting for "; |
179
|
|
|
|
|
|
|
|
180
|
0
|
0
|
|
|
|
|
if ( $hours > 1 ) { $message .= "$hours hours "; } |
|
0
|
0
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
elsif ( $hours == 1 ) { $message .= "one hour "; } |
182
|
0
|
0
|
|
|
|
|
if ( $minutes > 1 ) { $message .= "$minutes minutes "; } |
|
0
|
0
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
elsif ( $minutes == 1 ) { $message .= "one minute "; } |
184
|
0
|
0
|
|
|
|
|
if ( $seconds > 1 ) { $message .= "$seconds seconds "; } |
|
0
|
0
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
elsif ( $seconds == 1 ) { $message .= "one second "; } |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$message .= "\n"; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
print $message; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
while ( ( $t_0 + $duration - time() ) > 0 ) { |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
my $char = ReadKey(1); |
194
|
|
|
|
|
|
|
|
195
|
0
|
0
|
0
|
|
|
|
if ( defined($char) && $char eq 'c' ) { |
|
|
0
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
last; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
elsif ( defined($char) ) { |
199
|
0
|
0
|
|
|
|
|
if ( defined $user_command ) { |
200
|
0
|
|
|
|
|
|
$user_command->( $self, $char ); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
else { |
203
|
0
|
|
|
|
|
|
user_command($char); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $left = ( $t_0 + $duration - time() ); |
208
|
0
|
|
|
|
|
|
my $hours = int( $left / 3600 ); |
209
|
0
|
|
|
|
|
|
my $minutes = int( ( $left - $hours * 3600 ) / 60 ); |
210
|
0
|
|
|
|
|
|
my $seconds = $left - $hours * 3600 - $minutes * 60; |
211
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
print sprintf( "%02d:%02d:%02d", $hours, $minutes, $seconds ); |
213
|
0
|
|
|
|
|
|
print "\r"; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
#sleep(1); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
} |
218
|
0
|
|
|
|
|
|
ReadMode('normal'); |
219
|
0
|
|
|
|
|
|
$| = 0; |
220
|
0
|
|
|
|
|
|
print "\n\nGO!\n"; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub timestamp { |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
my ( |
227
|
0
|
|
|
0
|
0
|
|
$Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, |
228
|
|
|
|
|
|
|
$Jahr, $Wochentag, $Jahrestag, $Sommerzeit |
229
|
|
|
|
|
|
|
) = localtime(time); |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
$Monat += 1; |
232
|
0
|
|
|
|
|
|
$Jahrestag += 1; |
233
|
0
|
0
|
|
|
|
|
$Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat; |
234
|
0
|
0
|
|
|
|
|
$Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag; |
235
|
0
|
0
|
|
|
|
|
$Stunden = $Stunden < 10 ? $Stunden = "0" . $Stunden : $Stunden; |
236
|
0
|
0
|
|
|
|
|
$Minuten = $Minuten < 10 ? $Minuten = "0" . $Minuten : $Minuten; |
237
|
0
|
0
|
|
|
|
|
$Sekunden = $Sekunden < 10 ? $Sekunden = "0" . $Sekunden : $Sekunden; |
238
|
0
|
|
|
|
|
|
$Jahr += 1900; |
239
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
return "$Monatstag.$Monat.$Jahr", "$Stunden:$Minuten:$Sekunden"; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub seconds2time { |
245
|
0
|
|
|
0
|
0
|
|
my $duration = shift; |
246
|
|
|
|
|
|
|
|
247
|
0
|
|
|
|
|
|
my $hours = int( $duration / 3600 ); |
248
|
0
|
|
|
|
|
|
my $minutes = int( ( $duration - $hours * 3600 ) / 60 ); |
249
|
0
|
|
|
|
|
|
my $seconds = $duration - $hours * 3600 - $minutes * 60; |
250
|
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
|
my $formated = $hours . "h " . $minutes . "m " . $seconds . "s "; |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
|
return $formated; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
9
|
|
|
9
|
|
4319
|
use Lab::GenericSignals; |
|
9
|
|
|
|
|
32
|
|
|
9
|
|
|
|
|
365
|
|
257
|
|
|
|
|
|
|
1; |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
__END__ |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=pod |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=encoding UTF-8 |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 NAME |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Lab::Generic - General function library for the L::M classes |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 VERSION |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
version 3.880 |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Copyright 2013 Andreas K. Huettel, Christian Butschkow, Stefan Geissler |
278
|
|
|
|
|
|
|
2014 Alexei Iankilevitch, Andreas K. Huettel, Christian Butschkow |
279
|
|
|
|
|
|
|
2015 Alois Dirnaichner, Christian Butschkow |
280
|
|
|
|
|
|
|
2016 Simon Reinhardt |
281
|
|
|
|
|
|
|
2017 Andreas K. Huettel |
282
|
|
|
|
|
|
|
2019 Simon Reinhardt |
283
|
|
|
|
|
|
|
2020 Andreas K. Huettel |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
287
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=cut |