2012-09-16T10:29:12 gtrdriverUnd wie sah dieser Perl-Code aus? Was hast du da probiert?selbst versucht, der Sache auf den Grund zu gehen und verschiedene im Netz gefundene Perl Schnipsel für einen Socket Server getestet - diese funktionieren auch bei einer Plain ASCII Telnet Sitzung - bei den eingesetzen Endgeräten produzieren diese aber nur Fehlermeldungen oder funktionieren überhaupt nicht.
2012-09-16T14:27:29 gtrdriver[...]
Zitat: "Please note that all binary message formats are described as Big-Endian"
Zudem gibt es zu jeder Request art eine kleine Tabelle:
Byte: 0 Name: Transaction ID Size: 2 Type: Unsigned Integer Description: 16 -Bit Transaction ID
[...]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
use 5.012; use warnings; use IO::Handle; use constant { PKF_PACKET => '(SCC)>', LEN_PACKET => 4, ENC_BIN => 0, ENC_AT => 1, TYP_ATOK => 0x01, TYP_ATERR => 0x04, PKF_AT => 'S>', LEN_AT => 2, TYP_ASYNC => 0x02, PKF_ASYNC => '(QSS)>', LEN_ASYNC => 12, TYP_ACK => 0x03, PKF_ACK => 'S>', LEN_ACK => 2, DECODER => 0, ENCODER => 1, PKF_HEARTBEAT => 'CCCCCC', LEN_HEARTBEAT => 6 }; my %messages; sub read_packet { my ($fh) = @_; if ($fh->read(my $_, LEN_PACKET) == LEN_PACKET) { my ($transaction, $encoding, $type) = unpack PKF_PACKET; given ($type) { when ([TYP_ATOK, TYP_ATERR]) { if ($fh->read(my $_, LEN_AT) == LEN_AT) { my ($length) = unpack PKF_AT; my $body; unless ($fh->read($body, $length) == $length) { die 'failed to read AT message body'; } return { type => $type, transaction => $transaction, body => $body } } else { die 'failed to read AT message header'; } } when (TYP_ASYNC) { if ($fh->read(my $_, LEN_ASYNC) == LEN_ASYNC) { my ($modem, $message, $length) = unpack PKF_ASYNC; my $body; unless ($fh->read($body, $length) == $length) { die 'failed to read asynchronous message body'; } my $decoder; unless (defined($decoder = $messages{$message}->[DECODER])) { die "no decode delegate for message $message"; } return { type => $type, transaction => $transaction, modem => $modem, message => $message, body => $decoder->($body) }; } else { die 'failed to read asynchronous message header'; } } when (TYP_ACK) { if ($fh->read(my $_, LEN_ACK) == LEN_ACK) { my ($status) = unpack PKF_ACK; return { type => $type, transaction => $transaction, status => $status }; } else { die 'failed to read acknowledgement'; } } default { die "unknown message type $_"; } } } else { die 'failed to read packet header'; } } sub write_packet { my ($fh, $packet) = @_; my $encoding; my $type = $packet->{type}; given ($type) { when ([TYP_ATOK, TYP_ATERR]) { $encoding = ENC_AT; } default { $encoding = ENC_BIN; } } my $data = pack(PKF_PACKET, $packet->{transaction}, $encoding, $type); given ($type) { when ([TYP_ATOK, TYP_ATERR]) { $data .= pack(PKF_AT, length($packet->{body})); $data .= $packet->{body}; } when (TYP_ASYNC) { my $message = $packet->{message}; my $encoder; unless (defined($encoder = $messages{$message}->[ENCODER])) { die "no encode delegate for message $message"; } my $body = $encoder->($packet->{body}); $data .= pack(PKF_ASYNC, $packet->{modem}, $packet->{message}, length($body)); $data .= $body; } when (TYP_ACK) { $data .= pack(PKF_ACK, $packet->{status}); } default { die "unknown message type $_"; } } $fh->write($data, length($data)); } $messages{0xAB}->[DECODER] = sub { [unpack PKF_HEARTBEAT, $_[0]]; }; $messages{0xAB}->[ENCODER] = sub { pack PKF_HEARTBEAT, @{$_[0]}; };
1
2
3
4
5
6
7
8
9
10
11
12
13
"my" variable $_ masks earlier declaration in same scope at ./tra.pl line 91.
"my" variable $status masks earlier declaration in same scope at ./tra.pl line 98.
syntax error at ./tra.pl line 42, near ") {"
syntax error at ./tra.pl line 63, near ") {"
Global symbol "$fh" requires explicit package name at ./tra.pl line 64.
Global symbol "$fh" requires explicit package name at ./tra.pl line 68.
Global symbol "$type" requires explicit package name at ./tra.pl line 78.
Global symbol "$transaction" requires explicit package name at ./tra.pl line 79.
syntax error at ./tra.pl line 84, near "}"
Global symbol "$fh" requires explicit package name at ./tra.pl line 91.
syntax error at ./tra.pl line 99, near "}"
Can't use global @_ in "my" at ./tra.pl line 116, near "= @_"
./tra.pl has too many errors.