File Coverage

blib/lib/AnyEvent/OWNet/Constants.pm
Criterion Covered Total %
statement 26 27 96.3
branch n/a
condition n/a
subroutine 7 8 87.5
pod 3 3 100.0
total 36 38 94.7


line stmt bran cond sub pod time code
1 4     4   18960 use strict;
  4         8  
  4         136  
2 4     4   23 use warnings;
  4         7  
  4         542  
3             package AnyEvent::OWNet::Constants;
4             $AnyEvent::OWNet::Constants::VERSION = '1.163170';
5             # ABSTRACT: Module to export constants for 1-wire File System daemon protocol
6              
7              
8             my %constants =
9             (
10             OWNET_BUS_RET => 0x00000002,
11             OWNET_PERSISTENT => 0x00000004,
12             OWNET_ALIAS => 0x00000008,
13             OWNET_SAFEMODE => 0x00000010,
14             OWNET_NET => 0x00000100,
15              
16             OWNET_CENTIGRADE => 0x00000000,
17             OWNET_FAHRENHEIT => 0x00010000,
18             OWNET_KELVIN => 0x00020000,
19             OWNET_RANKINE => 0x00030000,
20             OWNET_TEMP_MASK => 0x00030000,
21              
22             OWNET_MILLIBAR => 0x00000000,
23             OWNET_ATMOSPHERE => 0x00040000,
24             OWNET_MM_MERCURY => 0x00080000,
25             OWNET_IN_MERCURY => 0x000C0000,
26             OWNET_PSI => 0x00100000,
27             OWNET_PASCAL => 0x00140000,
28             OWNET_PRESSURE_MASK => 0x001C0000,
29              
30             OWNET_DISP_F_I => 0x00000000, # f.i e.g. /10.67C6697351FF
31             OWNET_DISP_FI => 0x01000000, # fi e.g. /1067C6697351FF
32             OWNET_DISP_F_I_C => 0x02000000, # f.i.c e.g. /10.67C6697351FF.8D
33             OWNET_DISP_F_IC => 0x03000000, # f.ic e.g. /10.67C6697351FF8D
34             OWNET_DISP_FI_C => 0x04000000, # fi.c e.g. /10.67C6697351FF8D
35             OWNET_DISP_FIC => 0x05000000, # fic e.g. /1067C6697351FF8D
36             OWNET_DISP_MASK => 0x07000000,
37              
38             OWNET_MSG_NOP => 0x1, # deprecated
39             OWNET_MSG_READ => 0x2,
40             OWNET_MSG_WRITE => 0x3,
41             OWNET_MSG_DIR => 0x4,
42             OWNET_MSG_SIZE => 0x5, # deprecated
43             OWNET_MSG_PRESENT => 0x6,
44             OWNET_MSG_DIRALL => 0x7,
45             OWNET_MSG_GET => 0x8,
46             OWNET_MSG_DIRALLSLASH => 0x9,
47             OWNET_MSG_GETSLASH => 0xa,
48              
49             OWNET_DEFAULT_DATA_SIZE => 0x80e8,
50             );
51              
52             $constants{OWNET_DEFAULT_FLAGS} =
53             $constants{OWNET_NET} | $constants{OWNET_BUS_RET} |
54             $constants{OWNET_ALIAS} | $constants{OWNET_PERSISTENT};
55              
56             sub import {
57 4     4   21 no strict qw/refs/; ## no critic
  4         7  
  4         1210  
58 4     4   15 my $pkg = caller(0);
59 4         27 foreach (keys %constants) {
60 144         135 my $v = $constants{$_};
61 144     0   558 *{$pkg.'::'.$_} = sub () { $v };
  144         567  
  0         0  
62             }
63 4         12 *{$pkg.'::ownet_temperature_units'} = \&ownet_temperature_units;
  4         17  
64 4         8 *{$pkg.'::ownet_pressure_units'} = \&ownet_pressure_units;
  4         14  
65 4         7 *{$pkg.'::ownet_display_format'} = \&ownet_display_format;
  4         96  
66             }
67              
68              
69             sub ownet_temperature_units {
70 4     4 1 11 my $flag = shift;
71 4         30 [qw/C F K R/]->[($flag & $constants{OWNET_TEMP_MASK}) >> 16]
72             }
73              
74              
75             sub ownet_pressure_units {
76 6     6 1 9 my $flag = shift;
77             [qw/mbar atm mmHg
78 6         33 inHg psi Pa/]->[($flag & $constants{OWNET_PRESSURE_MASK}) >> 18]
79             }
80              
81              
82             sub ownet_display_format {
83 6     6 1 13 my $flag = shift;
84             [qw/f.i fi f.i.c
85 6         34 f.ic fi.c fic/]->[($flag & $constants{OWNET_DISP_MASK}) >> 24]
86             }
87              
88             1;
89              
90             __END__