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::Frame; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1527
|
|
10
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use constant FRAMESIZE => 4; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1034
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
17
|
|
|
|
|
|
|
{ |
18
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
19
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
20
|
0
|
|
|
|
|
|
my $self = {}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$self->{'_cmd'} = shift; |
23
|
0
|
|
|
|
|
|
$self->{'_addr'} = shift; |
24
|
0
|
|
|
|
|
|
$self->{'_data'} = shift; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
bless ($self, $class); |
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub command |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if(@_) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
|
$self->{'_cmd'} = shift; |
37
|
0
|
|
|
|
|
|
$self->{'_crc'} = undef; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
return $self->{'_cmd'}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub address |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if(@_) |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
|
|
|
$self->{'_addr'} = shift; |
49
|
0
|
|
|
|
|
|
$self->{'_crc'} = undef; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
return $self->{'_addr'}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub data |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if(@_) |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
|
|
|
$self->{'_data'} = shift; |
61
|
0
|
|
|
|
|
|
$self->{'_crc'} = undef; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
return $self->{'_data'}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub crc |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
unless(defined($self->{'_crc'})) |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
|
|
|
$self->{'_crc'} = $self->{'_cmd'} ^ $self->{'_addr'} ^ $self->{_data}; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
return $self->{'_crc'}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub setPacket |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
0
|
|
my($self, $packet) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $crc; |
82
|
0
|
|
|
|
|
|
($self->{'_cmd'}, $self->{'_addr'}, $self->{'_data'}, $crc) = |
83
|
|
|
|
|
|
|
unpack('CCCC', $packet); |
84
|
0
|
0
|
|
|
|
|
if($crc != $self->crc()) |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
|
carp "setPacket(): wrong checksum in frame ".$self->toString." got crc: $crc"; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
print "checksum: ".$self->crc()."\n"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub createFromPacket |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
0
|
0
|
|
my($packet) = shift; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my ($cmd, $addr, $data, $crc); |
96
|
0
|
|
|
|
|
|
($cmd, $addr, $data, $crc) = unpack('CCCC', $packet); |
97
|
0
|
|
|
|
|
|
my $frame = new Device::Conrad::Frame($cmd,$addr,$data); |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if($crc != $frame->crc()) |
100
|
|
|
|
|
|
|
{ |
101
|
0
|
|
|
|
|
|
carp "createFromPacket(): wrong checksum in frame ".$frame->toString." got crc: $crc"; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
return $frame; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub toPacket |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return pack('CCCC', |
111
|
|
|
|
|
|
|
$self->command(), |
112
|
|
|
|
|
|
|
$self->address(), |
113
|
|
|
|
|
|
|
$self->data(), |
114
|
|
|
|
|
|
|
$self->crc()); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub createCRCFrame |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $crcCmd = $self->command() ^ 255; |
122
|
0
|
|
|
|
|
|
my $crcFrame = new Device::Conrad::Frame($crcCmd , $self->address(),$self->data()); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return $crcFrame; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub display |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
130
|
0
|
|
|
|
|
|
my(@vals); |
131
|
|
|
|
|
|
|
my $i; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
print "== Frame == "; |
134
|
0
|
|
|
|
|
|
print "cmd = ",$self->command()," "; |
135
|
0
|
|
|
|
|
|
print "addr = ",$self->address()," "; |
136
|
0
|
|
|
|
|
|
print "data = ",$self->data()," "; |
137
|
0
|
|
|
|
|
|
print "\n"; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub toString |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $str = $self->command().",".$self->address().","; |
145
|
0
|
|
|
|
|
|
$str .= $self->data().",".$self->crc(); |
146
|
0
|
|
|
|
|
|
return $str; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub equals |
150
|
|
|
|
|
|
|
{ |
151
|
0
|
|
|
0
|
0
|
|
my($self, $frame) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if($self->command() == $frame->command()) |
154
|
|
|
|
|
|
|
{ |
155
|
0
|
|
|
|
|
|
return 1; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
|
|
|
return 0; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
1; |