Moose/Instrument/Bluefors_Temp.pm

filter: Statementstmt 31.6% 44 / 139 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 12 / 24 Podpod 100% 10 / 10 totaltotal 32.2% 66 / 205 CC 11 SCAR 20.3
CC
11
Cov
27%
set_heater
20.0
set_channel
20.0
get_T
12.0
CRAP 7.6
« Moose/Instrument/SR830.pm ↑ Summary Moose/Instrument/Log.pm »
1 package Lab::Moose::Instrument::Bluefors_Temp;
2 1 $Lab::Moose::Instrument::Bluefors_Temp::VERSION = '3.931';
3 #ABSTRACT: Bluefors temperature control
4  
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose::Util::TypeConstraints qw/enum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Lab::Moose::Instrument qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
12 validated_getter
13 validated_setter
14 validated_no_param_setter
15 setter_params
16 1 /;
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Time::HiRes qw/time usleep/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # HTTP request JSON stuff
22 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 1 extends 'Lab::Moose::Instrument';
28  
29 1 has default_channel => (
30 is => 'ro',
31 isa => 'Num',
32 default => 1,
33 );
34  
35 1 has default_heater => (
36 is => 'ro',
37 isa => 'Num',
38 default => 1,
39 );
40  
41 1 has default_time => (
42 is => 'ro',
43 isa => 'Num',
44 default => 90,
45 );
46  
47 1 has json => (
48 is => 'ro',
49 isa => 'Any',
50 builder => '_build_json',
51 );
52 0 ▶sub _build_json {
Subroutine _build_json: not called CC=1 SCAR=6.9
53 0 return JSON::PP->new;
54 }
55  
56 0 ▶around default_connection_options => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 my $orig = shift;
58 0 my $self = shift;
59 0 my $options = $self->$orig();
60  
61 0 $options->{HTTP}{port} = 5001;
62 0 return $options;
63 1 };
64  
65  
66 0 ▶sub get_measurement {
Subroutine get_measurement: not called CC=1 SCAR=6.9
Pod documented
67 0 my ( $self, %args ) = validated_hash(
68 \@_,
69 channel_nr => { isa => enum([ (1..12) ]) },
70 time => { isa => 'Lab::Moose::PosNum' },
71 fields => { isa => 'ArrayRef' },
72 );
73 0 my $channel_nr = $args{'channel_nr'};
74 0 my $time = $args{'time'};
75 0 my $fields = $args{'fields'};
76  
77 0 my $time_stop = DateTime->now."Z";
78 0 my $time_start = DateTime->from_epoch(epoch => time()-$time)."Z";
79  
80 0 my %hash_json = ( 'channel_nr' => $channel_nr,
81 'start_time' => $time_start,
82 'stop_time' => $time_stop,
83 'fields' => $fields,
84 );
85 0 my $json = $self->json->encode(\%hash_json);
86  
87 0 my $endpoint = '/channel/historical-data';
88  
89 0 my $response = $self->write( endpoint => $endpoint, body => $json);
90 0 my $hashref = $self->json->decode($response->content);
91  
92 0 return $hashref->{'measurements'};
93 }
94  
95  
96 0 ▶sub get_heater_measurement {
Subroutine get_heater_measurement: not called CC=1 SCAR=6.9
Pod documented
97 0 my ( $self, %args ) = validated_hash(
98 \@_,
99 heater_nr => { isa => enum([ (1..4) ])},
100 time => { isa => 'Lab::Moose::PosNum' },
101 fields => { isa => 'ArrayRef' },
102 );
103 0 my $heater_nr = delete $args{'heater_nr'};
104 0 my $time = delete $args{'time'};
105 0 my $fields = delete $args{'fields'};
106  
107 0 my $time_stop = DateTime->now."Z";
108 0 my $time_start = DateTime->from_epoch(epoch => time()-$time)."Z";
109  
110 0 my %hash_json = ( 'heater_nr' => $heater_nr,
111 'start_time' => $time_start,
112 'stop_time' => $time_stop,
113 'fields' => $fields,
114 );
115 0 my $json = $self->json->encode(\%hash_json);
116  
117 0 my $endpoint = '/heater/historical-data';
118  
119 0 my $response = $self->write( endpoint => $endpoint, body => $json);
120 0 my $hashref = $self->json->decode($response->content);
121  
122 0 return $hashref->{'measurements'};
123 }
124  
125  
126 0 ▶sub set_heater {
Subroutine set_heater: not called CC=4 SCAR=30.0
Pod documented
127 0 my ($self, %args) = validated_hash(
128 \@_,
129 heater_nr => { isa => enum([ (1..4) ]) },
130 active => { isa => enum( [qw/0 1/]), optional => 1 },
131 pid_mode => { isa => enum( [qw/0 1/]), optional => 1 },
132 resistance => { isa => 'Num', optional => 1 },
133 power => { isa => 'Num', optional => 1 },
134 target_temperature => { isa => 'Num', optional => 1 },
135 control_algorithm_settings => { isa => 'HashRef', optional => 1 },
136 setpoint => { isa => 'Num', optional => 1 },
137 );
138 0 ▶ if (exists $args{'active'} and defined $args{'active'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"active"} and defined $args{"active"}) 0 0 0
Condition0%0/3
exists $args{"active"} and defined $args{"active"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"active"} and defined $args{"active"}
exists $args{"active"} defined $args{"active"}
Truth table0%0/3
A and B
A= exists $args{"active"}B= defined $args{"active"}
ABresult
0X0
100
111
139 0 ▶ if ( $args{"active"} eq 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'active'} eq 1) { } 0 0 0
140 0 $args{"active"} = JSON::PP::true;
141 } else {
142 0 $args{"active"} = JSON::PP::false;
143 }
144 }
145 0 my $json = $self->json->encode(\%args);
146  
147 0 my $endpoint = '/heater/update';
148 0 my $response = $self->write( endpoint => $endpoint, body => $json);
149 0 my $hashref = $self->json->decode($response->content);
150  
151 0 return $hashref;
152 }
153  
154  
155 0 ▶sub set_channel {
Subroutine set_channel: not called CC=4 SCAR=30.0
Pod documented
156 0 my ($self, %args) = validated_hash(
157 \@_,
158 channel_nr => { isa => enum([ (1..12) ]) },
159 active => { isa => enum( [qw/0 1/] ), optional => 1 },
160 excitation_mode => { isa => enum( [qw/0 1 2/] ), optional => 1 },
161 excitation_current_range => { isa => enum([ (1..22) ]), optional => 1 },
162 excitation_cmn_range => { isa => enum( [qw/1 2/] ), optional => 1 },
163 excitation_vmax_range => { isa => enum( [qw/1 2/] ), optional => 1 },
164 use_non_default_timeconstants => { isa => enum( [qw/0 1/] ), optional => 1 },
165 wait_time => { isa => 'Num', optional => 1 },
166 meas_time => { isa => 'Num', optional => 1 },
167 );
168 0 ▶ if (exists $args{'active'} and defined $args{'active'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"active"} and defined $args{"active"}) 0 0 0
Condition0%0/3
exists $args{"active"} and defined $args{"active"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"active"} and defined $args{"active"}
exists $args{"active"} defined $args{"active"}
Truth table0%0/3
A and B
A= exists $args{"active"}B= defined $args{"active"}
ABresult
0X0
100
111
169 0 ▶ if ( $args{"active"} eq 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'active'} eq 1) { } 0 0 0
170 0 $args{"active"} = JSON::PP::true;
171 } else {
172 0 $args{"active"} = JSON::PP::false;
173 }
174 }
175 0 my $json = $self->json->encode(\%args);
176  
177 0 my $endpoint = '/channel/update';
178 0 my $response = $self->write( endpoint => $endpoint, body => $json);
179 0 my $hashref = $self->json->decode($response->content);
180  
181 0 return $hashref;
182 }
183  
184  
185 0 ▶sub set_statemachine {
Subroutine set_statemachine: not called CC=1 SCAR=6.9
Pod documented
186 0 my ($self, %args) = validated_hash(
187 \@_,
188 wait_time => { isa => enum([ (1..100) ]) },
189 meas_time => { isa => enum([ (1..100) ]) },
190 );
191  
192 0 my $json = $self->json->encode(\%args);
193  
194 0 my $endpoint = '/statemachine/update';
195 0 my $response = $self->write( endpoint => $endpoint, body => $json);
196 0 my $hashref = $self->json->decode($response->content);
197  
198 0 return $hashref;
199 }
200  
201  
202 0 ▶sub idn {
Subroutine idn: not called CC=1 SCAR=6.9
Pod documented
203 0 my $self = shift;
204  
205 0 my $endpoint = '/system';
206 0 my $response = $self->read( endpoint => $endpoint );
207 0 my $hashref = $self->json->decode($response->content);
208  
209 0 my $ret = '';
210 0 $ret = $ret . $hashref->{api_version} . ":";
211 0 $ret = $ret . $hashref->{type} . ":";
212 0 $ret = $ret . $hashref->{serial} . ":";
213 0 $ret = $ret . $hashref->{label} . ":";
214 0 $ret = $ret . $hashref->{addinfo} . ":";
215 0 $ret = $ret . $hashref->{software_version};
216  
217 0 return $ret;
218 }
219  
220  
221 0 ▶sub set_network_config {
Subroutine set_network_config: not called CC=1 SCAR=6.9
Pod documented
222 0 my ($self, %args) = validated_hash(
223 \@_,
224 ip_configuration => { isa => 'Str' },
225 ip_address => { isa => 'Str', optional => 1 },
226 netmask => { isa => 'Str', optional => 1 },
227 );
228 0 my $json = $self->json->encode(\%args);
229 0 say $json;
230  
231 0 my $endpoint = '/system/network/update';
232 0 my $response = $self->write( endpoint => $endpoint, body => $json);
233 0 my $hashref = $self->json->decode($response->content);
234  
235 0 return $hashref;
236 }
237  
238  
239 0 ▶sub set_channel_heater_relation {
Subroutine set_channel_heater_relation: not called CC=1 SCAR=6.9
Pod documented
240 0 my ($self, %args) = validated_hash(
241 \@_,
242 channel_nr => { isa => enum([ (0..12) ]) },
243 heater_nr => { isa => enum([ (0..4) ]) },
244 );
245 0 my $json = $self->json->encode(\%args);
246  
247 0 my $endpoint = '/channel/heater/update';
248 0 my $response = $self->write( endpoint => $endpoint, body => $json);
249 0 my $hashref = $self->json->decode($response->content);
250  
251 0 return $hashref;
252 }
253  
254  
255 # High level functions for sweeps
256  
257  
258 0 ▶sub get_T {
Subroutine get_T: not called CC=3 SCAR=24.8
Pod documented
259 0 my ($self, %args) = validated_hash(
260 \@_,
261 channel_nr => { isa => enum([ (1..12) ]), optional => 1 },
262 );
263  
264 0 my $channel;
265 0 ▶ if( exists $args{'channel_nr'} and defined $args{'channel_nr'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'channel_nr'} and defined $args{'channel_nr'}) { } 0 0 0
Condition0%0/3
exists $args{"channel_nr"} and defined $args{"channel_nr"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"channel_nr"} and defined $args{"channel_nr"}
exists $args{"channel_nr"} defined $args{"channel_nr"}
Truth table0%0/3
A and B
A= exists $args{"channel_nr"}B= defined $args{"channel_nr"}
ABresult
0X0
100
111
266 0 $channel = delete $args{'channel_nr'};
267 } else {
268 0 $channel = $self->default_channel;
269 }
270  
271 0 my $response = $self->get_measurement( channel_nr => $channel,
272 time => $self->default_time,
273 fields => [ "temperature" ] );
274 0 return $response->{'temperature'}->[-1];
275  
276 }
277  
278  
279 0 ▶sub set_T {
Subroutine set_T: not called CC=3 SCAR=24.8
Pod documented
280 0 my ($self, %args) = validated_hash(
281 \@_,
282 value => { isa => 'Num' },
283 heater_nr => { isa => enum([ (1..4) ]), optional => 1 },
284 );
285  
286 0 my $heater;
287 0 ▶ if( exists $args{'heater_nr'} and defined $args{'heater_nr'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'heater_nr'} and defined $args{'heater_nr'}) { } 0 0 0
Condition0%0/3
exists $args{"heater_nr"} and defined $args{"heater_nr"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"heater_nr"} and defined $args{"heater_nr"}
exists $args{"heater_nr"} defined $args{"heater_nr"}
Truth table0%0/3
A and B
A= exists $args{"heater_nr"}B= defined $args{"heater_nr"}
ABresult
0X0
100
111
288 0 $heater = delete $args{'heater_nr'};
289 } else {
290 0 $heater = $self->default_heater;
291 }
292 0 my $value = delete $args{'value'};
293  
294 0 return $self->set_heater( heater_nr => $heater, active => 1, setpoint => $value );
295 }
296  
297 1 __PACKAGE__->meta->make_immutable;
298  
299 1 1;
300  
301 __END__
« Moose/Instrument/SR830.pm ↑ Summary Moose/Instrument/Log.pm »