line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
### |
2
|
|
|
|
|
|
|
# $Revision: 1.3 $ |
3
|
|
|
|
|
|
|
# $Date: 2002/02/16 15:27:32 $ |
4
|
|
|
|
|
|
|
# $Author: ruediger $ |
5
|
|
|
|
|
|
|
### |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Device::Conrad::RelaisCard; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Device::SerialPort qw(:PARAM :STAT 0.07); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
288
|
|
10
|
1
|
|
|
1
|
|
6
|
use Device::Conrad::Frame; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
11
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
12
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#use vars qw ($VERSION); |
15
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $VERBOSE = 0; |
18
|
1
|
|
|
1
|
|
5
|
use constant NUMRELAIS => 8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use constant CMD_NOP => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
21
|
1
|
|
|
1
|
|
4
|
use constant CMD_SETUP => 1; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
37
|
|
22
|
1
|
|
|
1
|
|
5
|
use constant CMD_GET_PORT => 2; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
48
|
|
23
|
1
|
|
|
1
|
|
5
|
use constant CMD_SET_PORT => 3; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
24
|
1
|
|
|
1
|
|
5
|
use constant CMD_GET_OPT => 4; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
25
|
1
|
|
|
1
|
|
5
|
use constant CMD_SET_OPT => 5; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1103
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
30
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
31
|
0
|
|
|
|
|
|
my $self = {}; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$self->{'_addr'} = shift; |
34
|
0
|
|
|
|
|
|
$self->{'_ctrl'} = shift; |
35
|
0
|
|
|
|
|
|
$self->{'_bcast_exec'} = 0; |
36
|
0
|
|
|
|
|
|
$self->{'_bcast_block'} = 0; |
37
|
0
|
|
|
|
|
|
$self->{'_ports'} = 0; |
38
|
0
|
|
|
|
|
|
bless ($self, $class); |
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub init |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $getOptFrame = new Device::Conrad::Frame(CMD_GET_OPT, $self->address(), 0); |
47
|
0
|
|
|
|
|
|
my $optFrame = $self->{'_ctrl'}->sendFrame($getOptFrame); |
48
|
0
|
0
|
|
|
|
|
unless($optFrame) |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
|
carp "options read failed\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if(($optFrame->data() & 1) == 1) |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
|
$self->{'_bcast_exec'} = 1; |
56
|
0
|
0
|
|
|
|
|
print "controller ".$self->address()." is set up to execute broadcasts\n" if $VERBOSE; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if(($optFrame->data() & 2) == 2) |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
|
$self->{'_bcast_block'} = 1; |
62
|
0
|
0
|
|
|
|
|
print "controller ".$self->address()." is set up to block broadcasts\n" if $VERBOSE; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $getPortFrame = new Device::Conrad::Frame(CMD_GET_PORT, $self->address(), 0); |
66
|
0
|
|
|
|
|
|
my $portFrame = $self->{'_ctrl'}->sendFrame($getPortFrame); |
67
|
0
|
|
|
|
|
|
$self->{'_ports'} = $portFrame->data(); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if($VERBOSE) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
|
$self->showPortInfo(); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub ports |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if(@_) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
|
my $ports = shift; |
83
|
0
|
0
|
|
|
|
|
if($self->{'_ports'} != $ports) |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
|
|
|
my $setPortFrame = new Device::Conrad::Frame(CMD_SET_PORT, $self->address(), $ports); |
86
|
0
|
|
|
|
|
|
my $portFrame = $self->{'_ctrl'}->sendFrame($setPortFrame); |
87
|
0
|
|
|
|
|
|
$self->{'_ports'} = $ports; |
88
|
0
|
0
|
|
|
|
|
$self->showPortInfo() if $VERBOSE; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
return $self->{'_ports'}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub address |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if(@_) |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
|
|
|
$self->{'_addr'} = shift; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
return $self->{'_addr'}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub broadcastExecute |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if(@_) |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
|
|
|
|
|
$self->{'_bcast_exec'} = shift; |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
return $self->{'_bcast_exec'}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub broadcastBlock |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if(@_) |
121
|
|
|
|
|
|
|
{ |
122
|
0
|
|
|
|
|
|
$self->{'_bcast_block'} = shift; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
return $self->{'_bcast_block'}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub close |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
0
|
0
|
|
my($self, $portNum) = @_; |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
if($portNum > NUMRELAIS) |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
|
|
|
|
|
die "$portNum exceeds NUMRELAIS relais\n"; |
134
|
|
|
|
|
|
|
} |
135
|
0
|
|
|
|
|
|
my $ports = $self->ports(); |
136
|
0
|
|
|
|
|
|
$ports |= 2**$portNum; |
137
|
0
|
|
|
|
|
|
return $self->ports($ports); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub open |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
0
|
0
|
|
my($self, $portNum) = @_; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $ports = $self->ports(); |
145
|
0
|
|
|
|
|
|
$ports &= 255 - 2**$portNum; |
146
|
0
|
|
|
|
|
|
return $self->ports($ports); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub test() |
150
|
|
|
|
|
|
|
{ |
151
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $testFrame = new Device::Conrad::Frame(CMD_NOP, $self->address(), 0); |
154
|
0
|
|
|
|
|
|
my $crcFrame = $testFrame->createCRCFrame(); |
155
|
0
|
|
|
|
|
|
my $testResp = $self->{'_ctrl'}->sendFrame($testFrame); |
156
|
0
|
0
|
|
|
|
|
if($testResp->equals($crcFrame)) |
157
|
|
|
|
|
|
|
{ |
158
|
0
|
|
|
|
|
|
return 1; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
else |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
|
|
|
|
|
return 0; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub showPortInfo |
167
|
|
|
|
|
|
|
{ |
168
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $i; |
171
|
0
|
|
|
|
|
|
print "port status = ".$self->{'_ports'}."\n"; |
172
|
0
|
|
|
|
|
|
for $i (0..NUMRELAIS-1) |
173
|
|
|
|
|
|
|
{ |
174
|
0
|
0
|
|
|
|
|
if(($self->{'_ports'} & (2**$i)) > 0) |
175
|
|
|
|
|
|
|
{ |
176
|
0
|
|
|
|
|
|
print "Relais ".($i+1)." is closed\n"; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
else |
179
|
|
|
|
|
|
|
{ |
180
|
0
|
|
|
|
|
|
print "Relais ".($i+1)." is open\n"; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub END |
186
|
|
|
|
|
|
|
{ |
187
|
1
|
|
|
1
|
|
4
|
my($self) = shift; |
188
|
1
|
|
|
|
|
9
|
unlink $self->{'_lockFile'}; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
1; |
191
|
|
|
|
|
|
|
__END__ |