| 1 | # | ||||||||||||||||||||
| 2 | # Rinchi Common Image Generator Interface for Perl | ||||||||||||||||||||
| 3 | # Class Identifier: f78b3ded-200e-11de-bdd4-001c25551abc | ||||||||||||||||||||
| 4 | # Author: Brian M. Ames | ||||||||||||||||||||
| 5 | # | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | package Rinchi::CIGIPP::ImageGeneratorMessage; | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | require Exporter; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||
| 19 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||
| 20 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # This allows declaration use Rinchi::CIGI::AtmosphereControl ':all'; | ||||||||||||||||||||
| 23 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||
| 24 | # will save memory. | ||||||||||||||||||||
| 25 | 2 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | ) ] ); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 2 | our @EXPORT = qw( | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # Preloaded methods go here. | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =head1 NAME | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | Rinchi::CIGIPP::ImageGeneratorMessage - Perl extension for the Common Image | ||||||||||||||||||||
| 42 | Generator Interface - Image Generator Message data packet. | ||||||||||||||||||||
| 43 | data packet. | ||||||||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | use Rinchi::CIGIPP::ImageGeneratorMessage; | ||||||||||||||||||||
| 47 | my $ig_msg = Rinchi::CIGIPP::ImageGeneratorMessage->new(); | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | $packet_type = $ig_msg->packet_type(); | ||||||||||||||||||||
| 50 | $packet_size = $ig_msg->packet_size(); | ||||||||||||||||||||
| 51 | $message_ident = $ig_msg->message_ident(32020); | ||||||||||||||||||||
| 52 | $message = $ig_msg->message('Error 1234'); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head1 DESCRIPTION | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | The Image Generator Message packet is used to pass error, debugging, and other | ||||||||||||||||||||
| 57 | text messages to the Host. | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | These messages may be saved to a log file and/or written to the console or | ||||||||||||||||||||
| 60 | other user interface. Because file and console I/O are not typically real-time | ||||||||||||||||||||
| 61 | in nature, it is recommended that the IG only send Image Generator Message | ||||||||||||||||||||
| 62 | packets while in Debug mode. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | Each message is composed of multiple eight-bit character data. The text message | ||||||||||||||||||||
| 65 | must be terminated by NULL, or zero (0). If the terminating byte is not the | ||||||||||||||||||||
| 66 | last byte of the eight-byte double-word, then the remainder of the double-word | ||||||||||||||||||||
| 67 | must be padded with zeroes. Zero-length messages must be terminated with four | ||||||||||||||||||||
| 68 | bytes containing NULL (to maintain 64-bit alignment). The maximum text length | ||||||||||||||||||||
| 69 | is 100 characters, including a terminating NULL. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head2 EXPORT | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | None by default. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | #============================================================================== | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =item new $ig_msg = Rinchi::CIGIPP::ImageGeneratorMessage->new() | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Constructor for Rinchi::ImageGeneratorMessage. | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=29.8
Pod
documented
| |||||||||||||||||||||
| 84 | 2 | my $class = shift; | |||||||||||||||||||
| 85 | 2 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 2 | my $self = { | |||||||||||||||||||
| 88 | '_Buffer' => '', | ||||||||||||||||||||
| 89 | '_ClassIdent' => 'f78b3ded-200e-11de-bdd4-001c25551abc', | ||||||||||||||||||||
| 90 | '_Pack' => 'CCS', | ||||||||||||||||||||
| 91 | '_Swap1' => 'CCv', | ||||||||||||||||||||
| 92 | '_Swap2' => 'CCn', | ||||||||||||||||||||
| 93 | 'packetType' => 117, | ||||||||||||||||||||
| 94 | 'packetSize' => 8, | ||||||||||||||||||||
| 95 | 'messageIdent' => 0, | ||||||||||||||||||||
| 96 | 'message' => '', | ||||||||||||||||||||
| 97 | '_pad' => "\0\0\0\0", | ||||||||||||||||||||
| 98 | }; | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 2 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 0 | ▶ | if (ref($_[0]) eq 'ARRAY') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 102 | 0 | $self->{'_Buffer'} = $_[0][0]; | |||||||||||||||||||
| 103 | } elsif (ref($_[0]) eq 'HASH') { | ||||||||||||||||||||
| 104 | 0 | foreach my $attr (keys %{$_[0]}) { | |||||||||||||||||||
| 105 | 0 | ▶ | $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 2 | bless($self,$class); | |||||||||||||||||||
| 111 | 2 | return $self; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | #============================================================================== | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =item sub packet_type() | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | $value = $ig_msg->packet_type(); | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | Data Packet Identifier. | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | This attribute identifies this data packet as the Image Generation Message | ||||||||||||||||||||
| 123 | packet. The value of this attribute must be 117. | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 2 | ▶ | sub packet_type() { | ||||||||||||||||||
|
Subroutine
packet_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 128 | 2 | my ($self) = @_; | |||||||||||||||||||
| 129 | 2 | return $self->{'packetType'}; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | #============================================================================== | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =item sub packet_size([$newValue]) | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | $value = $ig_msg->packet_size($newValue); | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | Data Packet Size. | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | This attribute indicates the number of bytes in this data packet. The value of | ||||||||||||||||||||
| 141 | this attribute must be 4 plus the length of the message text, including NULL | ||||||||||||||||||||
| 142 | characters. The value of this attribute must be at least 8 and no more than 104 | ||||||||||||||||||||
| 143 | bytes. This allows for a message length of up to 100 characters, including the | ||||||||||||||||||||
| 144 | terminating NULL. | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Note: Because all packets must begin and end on a 64-bit boundary, the value of | ||||||||||||||||||||
| 147 | this attribute must be an even multiple of eight (8). | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 2 | ▶ | sub packet_size() { | ||||||||||||||||||
|
Subroutine
packet_size: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 152 | 2 | my ($self,$nv) = @_; | |||||||||||||||||||
| 153 | 2 | ▶ | if (defined($nv)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | 0 | $self->{'packetSize'} = $nv; | |||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | 2 | return $self->{'packetSize'}; | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | #============================================================================== | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =item sub message_ident([$newValue]) | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | $value = $ig_msg->message_ident($newValue); | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | Message ID. | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | This attribute specifies a numerical identifier for the message. | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 2 | ▶ | sub message_ident() { | ||||||||||||||||||
|
Subroutine
message_ident: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 172 | 2 | my ($self,$nv) = @_; | |||||||||||||||||||
| 173 | 2 | ▶ | if (defined($nv)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | 2 | $self->{'messageIdent'} = $nv; | |||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | 2 | return $self->{'messageIdent'}; | |||||||||||||||||||
| 177 | } | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | #============================================================================== | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | =item sub message([$newValue]) | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | $value = $ig_msg->message($newValue); | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | Message string. | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | These 8-bit data are used to store the ANSI codes for each character in the | ||||||||||||||||||||
| 188 | message string. | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | Note: The maximum number of characters, including a terminating NULL, is 100. | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 4 | ▶ | sub message() { | ||||||||||||||||||
|
Subroutine
message: called CC=4 SCAR=14.4
Pod
documented
| |||||||||||||||||||||
| 195 | 4 | my ($self,$nv) = @_; | |||||||||||||||||||
| 196 | 4 | ▶ | if (defined($nv)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 197 | 4 | my $len = length($nv); | |||||||||||||||||||
| 198 | 4 | ▶ | if ($len < 100) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 199 | 4 | $self->{'message'} = $nv; | |||||||||||||||||||
| 200 | 4 | $self->{'_pad'} = substr("\0\0\0\0\0\0\0\0",(($len+4)%8)); | |||||||||||||||||||
| 201 | 4 | $self->{'packetSize'} = $len + 4 + length($self->{'_pad'}); | |||||||||||||||||||
| 202 | } else { | ||||||||||||||||||||
| 203 | 0 | carp "New value exceeds 99 bytes"; | |||||||||||||||||||
| 204 | } | ||||||||||||||||||||
| 205 | } | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | 4 | ▶ | if (defined($nv)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 208 | 4 | $self->{'message'} = $nv; | |||||||||||||||||||
| 209 | } | ||||||||||||||||||||
| 210 | 4 | return $self->{'message'}; | |||||||||||||||||||
| 211 | } | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | #========================================================================== | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | =item sub pack() | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | $value = $ig_msg->pack(); | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | Returns the packed data packet. | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | 5 | ▶ | sub pack($) { | ||||||||||||||||||
|
Subroutine
pack: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 224 | 5 | my $self = shift ; | |||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | $self->{'_Buffer'} = CORE::pack($self->{'_Pack'}, | ||||||||||||||||||||
| 227 | $self->{'packetType'}, | ||||||||||||||||||||
| 228 | $self->{'packetSize'}, | ||||||||||||||||||||
| 229 | $self->{'messageIdent'} | ||||||||||||||||||||
| 230 | 5 | ) . $self->{'message'} . $self->{'_pad'}; | |||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | 5 | return $self->{'_Buffer'}; | |||||||||||||||||||
| 233 | } | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | #========================================================================== | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | =item sub unpack() | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | $value = $ig_msg->unpack(); | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | Unpacks the packed data packet. | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | =cut | ||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 0 | ▶ | sub unpack($) { | ||||||||||||||||||
|
Subroutine
unpack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 246 | 0 | my $self = shift @_; | |||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 0 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 249 | 0 | $self->{'_Buffer'} = shift @_; | |||||||||||||||||||
| 250 | } | ||||||||||||||||||||
| 251 | 0 | my ($a,$b,$c) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'}); | |||||||||||||||||||
| 252 | 0 | my $d = substr($self->{'_Buffer'},4); | |||||||||||||||||||
| 253 | 0 | $d =~ s/(\0+)$//; | |||||||||||||||||||
| 254 | 0 | my $e = $1; | |||||||||||||||||||
| 255 | 0 | $self->{'packetType'} = $a; | |||||||||||||||||||
| 256 | 0 | $self->{'packetSize'} = $b; | |||||||||||||||||||
| 257 | 0 | $self->{'messageIdent'} = $c; | |||||||||||||||||||
| 258 | 0 | $self->{'message'} = $d; | |||||||||||||||||||
| 259 | 0 | $self->{'_pad'} = $e; | |||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | 0 | return $self->{'_Buffer'}; | |||||||||||||||||||
| 262 | } | ||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | #========================================================================== | ||||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | =item sub byte_swap() | ||||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | $obj_name->byte_swap(); | ||||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | Byte swaps the packed data packet. | ||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | 0 | ▶ | sub byte_swap($) { | ||||||||||||||||||
|
Subroutine
byte_swap: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 275 | 0 | my $self = shift @_; | |||||||||||||||||||
| 276 | |||||||||||||||||||||
| 277 | 0 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 278 | 0 | $self->{'_Buffer'} = shift @_; | |||||||||||||||||||
| 279 | } else { | ||||||||||||||||||||
| 280 | 0 | $self->pack(); | |||||||||||||||||||
| 281 | } | ||||||||||||||||||||
| 282 | 0 | my ($a,$b,$c) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'}); | |||||||||||||||||||
| 283 | 0 | my $padded_message = substr($self->{'_Buffer'},4); | |||||||||||||||||||
| 284 | |||||||||||||||||||||
| 285 | 0 | $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c) . $padded_message; | |||||||||||||||||||
| 286 | 0 | $self->unpack(); | |||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | 0 | return $self->{'_Buffer'}; | |||||||||||||||||||
| 289 | } | ||||||||||||||||||||
| 290 | |||||||||||||||||||||
| 291 | 2 | 1; | |||||||||||||||||||
| 292 | __END__ | ||||||||||||||||||||