File Coverage

blib/lib/AnyEvent/OWNet/Constants.pm
Criterion Covered Total %
statement 27 28 96.4
branch n/a
condition n/a
subroutine 8 9 88.8
pod 3 3 100.0
total 38 40 95.0


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