| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2023-2026 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Object::Pad 0.822 ':experimental(adjust_params inherit_field)'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Sublike::Extended 0.29 qw( method ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package Device::Serial::SLuRM::Protocol 0.11; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | class Device::Serial::SLuRM::Protocol | ||||||||||||||||||||||||||||||||||||||||||
| 13 | :lexical_new; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | ▶ | use Future::Buffer 0.03; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | use Future::IO; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | ▶ | use Digest::CRC qw( crc8 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 12 | ▶ | use constant DEBUG => $ENV{SLURM_DEBUG} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{"SLURM_DEBUG"} // 0
MC/DC0%0/1
$ENV{"SLURM_DEBUG"} // 0
$ENV{"SLURM_DEBUG"}
Truth table50%1/2
A
A= $ENV{"SLURM_DEBUG"}
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # builtin::false only turned up at 5.36, grrrr | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | use constant false => !!0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | C<Device::Serial::SLuRM::Protocol> - implements the lower-level packet format of the SLµRM protocol | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | This class provides the inner logic used by L<Device::Serial::SLuRM> and | ||||||||||||||||||||||||||||||||||||||||||
| 37 | L<Device::Serial::MSLuRM>. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 12 | SLURM_PKTCTRL_META => 0x00, | |||||||||||||||||||||||||||||||||||||||||
| 43 | SLURM_PKTCTRL_META_RESET => 0x01, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | SLURM_PKTCTRL_META_RESETACK => 0x02, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | SLURM_PKTCTRL_NOTIFY => 0x10, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | SLURM_PKTCTRL_REQUEST => 0x30, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | SLURM_PKTCTRL_RESPONSE => 0xB0, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | SLURM_PKTCTRL_ACK => 0xC0, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | SLURM_PKTCTRL_ERR => 0xE0, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # Metrics support is entirely optional | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | our $METRICS; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | ▶ | require Metrics::Any and Metrics::Any->VERSION( '0.05' ) and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
require Metrics::Any and "Metrics::Any"->VERSION("0.05")
MC/DC0%0/2
require Metrics::Any and "Metrics::Any"->VERSION("0.05")
require Metrics::Any
"Metrics::Any"->VERSION("0.05")
Truth table0%0/3
A and B
A= require Metrics::AnyB= "Metrics::Any"->VERSION("0.05")
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | Metrics::Any->import( '$METRICS', name_prefix => [ 'slurm' ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | my %PKTTYPE_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 12 | ▶ | if( defined $METRICS ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $METRICS->make_counter( discards => | |||||||||||||||||||||||||||||||||||||||||
| 66 | description => "Number of received packets discarded due to CRC check", | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $METRICS->make_counter( packets => | |||||||||||||||||||||||||||||||||||||||||
| 70 | description => "Number of packets sent and received, by type", | ||||||||||||||||||||||||||||||||||||||||||
| 71 | labels => [qw( dir type )], | ||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $METRICS->make_distribution( request_success_attempts => | |||||||||||||||||||||||||||||||||||||||||
| 75 | description => "How many requests eventually succeeded after a given number of transmissions", | ||||||||||||||||||||||||||||||||||||||||||
| 76 | units => "", | ||||||||||||||||||||||||||||||||||||||||||
| 77 | buckets => [ 1 .. 3 ], | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $METRICS->make_timer( request_duration => | |||||||||||||||||||||||||||||||||||||||||
| 81 | description => "How long it took to get a response to each request", | ||||||||||||||||||||||||||||||||||||||||||
| 82 | buckets => [ 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5 ], | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $METRICS->make_counter( retransmits => | |||||||||||||||||||||||||||||||||||||||||
| 86 | description => "Number of retransmits of packets", | ||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $METRICS->make_counter( serial_bytes => | |||||||||||||||||||||||||||||||||||||||||
| 90 | description => "Total number of bytes sent and received on the serial link", | ||||||||||||||||||||||||||||||||||||||||||
| 91 | labels => [qw( dir )], | ||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $METRICS->make_counter( timeouts => | |||||||||||||||||||||||||||||||||||||||||
| 95 | description => "Number of transactions that were abandoned due to eventual timeout", | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | %PKTTYPE_NAME = map { __PACKAGE__->can( "SLURM_PKTCTRL_$_" )->() => $_ } | |||||||||||||||||||||||||||||||||||||||||
| 99 | qw( META NOTIFY REQUEST RESPONSE ERR ACK ); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | # Keep prometheus increase() happy by initialising all the counters to zero | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $METRICS->inc_counter_by( discards => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | foreach my $dir (qw( rx tx )) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $METRICS->inc_counter_by( packets => 0, [ dir => $dir, type => $_ ] ) for values %PKTTYPE_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $METRICS->inc_counter_by( serial_bytes => 0, [ dir => $dir ] ); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $METRICS->inc_counter_by( retransmits => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $METRICS->inc_counter_by( timeouts => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | field $_multidrop :param :inheritable = 0; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # To calculate baud-independent timeout values we need a rough estimate of the | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # time to send each byte | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | ▶ | field $_bps :reader :inheritable; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bps: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 12 | ▶ | method new :common ( %params ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | my $transport = $params{transport} // | ||||||||||||||||||||||||||||||||||||||||||
| 120 | ( defined $params{dev} ? "serial" : | ||||||||||||||||||||||||||||||||||||||||||
| 121 | defined $params{host} ? "udp" : | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | ▶ | defined $params{fh} ? "serial" : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%2/2
$params{"transport"} // (defined $params{"dev"} ? "serial" : (defined $params{"host"} ? "udp" : (defined $params{"fh"} ? "serial" : croak("Require either a 'dev', 'host', or 'fh' parameter"))))
MC/DC100%1/1
$params{"transport"} // (defined $params{"dev"} ? "serial" : (defined $params{"host"} ? "udp" : (defined $params{"fh"} ? "serial" : croak("Require either a 'dev', 'host', or 'fh' parameter"))))
$params{"transport"}
Truth table100%2/2
A
A= $params{"transport"}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | croak "Require either a 'dev', 'host', or 'fh' parameter" ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 12 | ▶ | if( $transport eq "serial" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | return Device::Serial::SLuRM::Protocol::_Serial->new( | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 11 | %params{qw( fh dev baud multidrop )} | |||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | elsif( $transport eq "udp" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | return Device::Serial::SLuRM::Protocol::_Udp->new( | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | %params{qw( fh host port multidrop )} | |||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | croak "Unrecognised 'transport' type $transport"; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | async method recv | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 73 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recv: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 73 | my ( $pktctrl, $addr, $payload ) = await $self->recv_packet(); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 50 | printf STDERR "SLuRM <-RX%s {%02X/%v02X}\n", | |||||||||||||||||||||||||||||||||||||||||
| 145 | ( $_multidrop ? sprintf "(%d)", $addr : "" ), $pktctrl, $payload | ||||||||||||||||||||||||||||||||||||||||||
| 146 | if DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | $METRICS and | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 50 | ▶ | $METRICS->inc_counter( packets => [ dir => "rx", type => $PKTTYPE_NAME{ $pktctrl & 0xF0 } // "UNKNOWN" ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$PKTTYPE_NAME{$pktctrl & 240} // "UNKNOWN"
MC/DC0%0/1
$PKTTYPE_NAME{$pktctrl & 240} // "UNKNOWN"
$PKTTYPE_NAME{$pktctrl & 240}
Truth table0%0/2
A
A= $PKTTYPE_NAME{$pktctrl & 240}
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 50 | return $pktctrl, $addr, $payload; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 62 | ▶ | async method send ( $pktctrl, $addr, $payload, :$linestuff = false ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 62 | { | |||||||||||||||||||||||||||||||||||||||||
| 156 | 62 | printf STDERR "SLuRM TX%s-> {%02X/%v02X}\n", | |||||||||||||||||||||||||||||||||||||||||
| 157 | ( $_multidrop ? sprintf "(%d)", $addr & 0x7F : "" ), $pktctrl, $payload | ||||||||||||||||||||||||||||||||||||||||||
| 158 | if DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | $METRICS and | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 62 | ▶ | $METRICS->inc_counter( packets => [ dir => "tx", type => $PKTTYPE_NAME{ $pktctrl & 0xF0 } // "UNKNOWN" ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$PKTTYPE_NAME{$pktctrl & 240} // "UNKNOWN"
MC/DC0%0/1
$PKTTYPE_NAME{$pktctrl & 240} // "UNKNOWN"
$PKTTYPE_NAME{$pktctrl & 240}
Truth table0%0/2
A
A= $PKTTYPE_NAME{$pktctrl & 240}
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 62 | return await $self->send_packet( $pktctrl, $addr, $payload, linestuff => $linestuff ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 22 | ▶ | async method interpacket_delay () | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interpacket_delay: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 22 | { | |||||||||||||||||||||||||||||||||||||||||
| 168 | # wait 20-ish byte times as a gap between packets | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 22 | await Future::IO->sleep( 20 / $_bps ); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 11 | ▶ | async method send_twice ( $pktctrl, $node_id, $payload ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_twice: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 11 | { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 11 | await $self->send( $pktctrl, $node_id, $payload ); | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 11 | await $self->interpacket_delay; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 11 | await $self->send( $pktctrl, $node_id, $payload ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | class Device::Serial::SLuRM::Protocol::_Serial | ||||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 12 | inherit Device::Serial::SLuRM::Protocol qw( $_bps $_multidrop ); | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 12 | ▶ | use constant DEBUG => Device::Serial::SLuRM::Protocol::DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 12 | ▶ | use constant false => !!0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 12 | ▶ | use Digest::CRC qw( crc8 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 12 | field $_fh; | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | ADJUST :params ( | ||||||||||||||||||||||||||||||||||||||||||
| 194 | :$fh = undef, | ||||||||||||||||||||||||||||||||||||||||||
| 195 | :$dev = undef, | ||||||||||||||||||||||||||||||||||||||||||
| 196 | :$baud //= 115200, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | if( defined $fh ) { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | $_bps = $baud / 10; | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | elsif( defined $dev ) { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | require IO::Termios; | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | $fh = IO::Termios->open( $dev, "$baud,8,n,1" ) or | ||||||||||||||||||||||||||||||||||||||||||
| 205 | croak "Cannot open device $dev - $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | $fh->cfmakeraw; | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | $_bps = $fh->getobaud / 10; | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | croak "Serial transport protocol requires fh or dev"; | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | $_fh = $fh; | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 12 | field $_recv_buffer; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 12 | field @_linestuff_queue; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 9 | ▶ | async method _drain1_linestuff () | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_drain1_linestuff: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 9 | { | |||||||||||||||||||||||||||||||||||||||||
| 223 | 9 | my $bytes = shift @_linestuff_queue; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 9 | my ( $pktctrl ) = unpack "C", $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | ▶ | $METRICS and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | $METRICS->inc_counter_by( serial_bytes => 1 + length $bytes, [ dir => "tx" ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 9 | printf STDERR "SLuRM DEV WRITE: %v02X\n", "\x55" . $bytes | |||||||||||||||||||||||||||||||||||||||||
| 231 | if DEBUG > 2; | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 9 | await Future::IO->syswrite_exactly( $_fh, "\x55" . $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 72 | ▶ | async method recv_packet () | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recv_packet: called CC=12 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 72 | { | |||||||||||||||||||||||||||||||||||||||||
| 238 | $_recv_buffer //= Future::Buffer->new( | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 72 | ▶ | fill => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 72 | my $f = Future::IO->sysread( $_fh, 8192 ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | $f->on_done( sub { $METRICS->inc_counter_by( serial_bytes => length $_[0], [ dir => "rx" ] ) } ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 72 | ▶ | if $METRICS; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | $f->on_done( sub { printf STDERR "SLuRM SERIAL READ: %v02X\n", $_[0] } ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 72 | if DEBUG > 2; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 72 | $f; | |||||||||||||||||||||||||||||||||||||||||
| 246 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 72 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_recv_buffer //= "Future::Buffer"->new("fill", sub {
my $f = "Future::IO"->sysread($_fh, 8192);
$f->on_done(sub {
$Device::Serial::SLuRM::Protocol::METRICS->inc_counter_by("serial_bytes", length $_[0], ["dir", "rx"]);
}
) if $Device::Serial::SLuRM::Protocol::METRICS;
'???';
$f;
}
)
MC/DC0%0/2
$_recv_buffer //= "Future::Buffer"->new("fill", sub {
my $f = "Future::IO"->sysread($_fh, 8192);
$f->on_done(sub {
$Device::Serial::SLuRM::Protocol::METRICS->inc_counter_by("serial_bytes", length $_[0], ["dir", "rx"]);
}
) if $Device::Serial::SLuRM::Protocol::METRICS;
'???';
$f;
}
)
$_recv_buffer
"Future::Buffer"->new("fill", sub {
my $f = "Future::IO"->sysread($_fh, 8192);
$f->on_done(sub {
$Device::Serial::SLuRM::Protocol::METRICS->inc_counter_by("serial_bytes", length $_[0], ["dir", "rx"]);
}
) if $Device::Serial::SLuRM::Protocol::METRICS;
'???';
$f;
}
)
Truth table66%2/3
A //= B
A= $_recv_bufferB= "Future::Buffer"->new("fill", sub {
my $f = "Future::IO"->sysread($_fh, 8192);
$f->on_done(sub {
$Device::Serial::SLuRM::Protocol::METRICS->inc_counter_by("serial_bytes", length $_[0], ["dir", "rx"]);
}
) if $Device::Serial::SLuRM::Protocol::METRICS;
'???';
$f;
}
)
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 72 | my $headerlen = 3 + !!$_multidrop; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | PACKET: { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | # await start-of-frame while line-stuffing | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 72 | while(1) { | |||||||||||||||||||||||||||||||||||||||||
| 254 | 84 | my $f = $_recv_buffer->read_until( qr/\x55/ ); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 84 | ▶ | if( @_linestuff_queue ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 11 | $f = Future->wait_any( $f, | |||||||||||||||||||||||||||||||||||||||||
| 257 | $self->interpacket_delay->then_done( "" ), | ||||||||||||||||||||||||||||||||||||||||||
| 258 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 84 | ▶ | last if length await $f; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 9 | await $self->_drain1_linestuff; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 52 | ▶ | defined( my $pkt = await $_recv_buffer->read_exactly( $headerlen ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | or return; # EOF | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 52 | my ( $pktctrl, $addr, $len ); | |||||||||||||||||||||||||||||||||||||||||
| 270 | 52 | ▶ | $_multidrop ? ( ( $pktctrl, $addr, $len ) = unpack "C C C", $pkt ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | : ( ( $addr, $pktctrl, $len ) = ( 0, unpack "C C", $pkt ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 52 | ▶ | if( crc8( $pkt ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | # Header checksum failed | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | ▶ | $METRICS and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | $METRICS->inc_counter( discards => ); | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | ▶ | $pkt =~ m/\x55/ and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | $_recv_buffer->unread( substr $pkt, $-[0] ); | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | redo PACKET; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 51 | $pkt .= await $_recv_buffer->read_exactly( $len + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 51 | ▶ | if( crc8( $pkt ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | # Body checksum failed | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | ▶ | $METRICS and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | $METRICS->inc_counter( discards => ); | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | ▶ | $pkt =~ m/\x55/ and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | $_recv_buffer->unread( substr $pkt, $-[0] ); | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | redo PACKET; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 49 | my $body = substr( $pkt, $headerlen, $len ); | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 49 | return ( $pktctrl, $addr, $body ); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 61 | ▶ | async method send_packet ( $pktctrl, $addr, $body, :$linestuff = false ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_packet: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 61 | { | |||||||||||||||||||||||||||||||||||||||||
| 303 | 61 | ▶ | my $bytes = $_multidrop | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$addr // die("ADDR must be defined for multidrop")
MC/DC0%0/1
$addr // die("ADDR must be defined for multidrop")
$addr
Truth table50%1/2
A
A= $addr
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | ? pack( "C C C", $pktctrl, $addr // die( "ADDR must be defined for multidrop" ), length $body ) | ||||||||||||||||||||||||||||||||||||||||||
| 305 | : pack( "C C", $pktctrl, length $body ); | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 61 | $bytes .= pack( "C", crc8( $bytes ) ); | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 61 | $bytes .= $body; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 61 | $bytes .= pack( "C", crc8( $bytes ) ); | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 61 | ▶ | if( $linestuff ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 9 | push @_linestuff_queue, $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | $METRICS and | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 52 | ▶ | $METRICS->inc_counter_by( serial_bytes => 1 + length $bytes, [ dir => "tx" ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 52 | printf STDERR "SLuRM SERIAL WRITE: %v02X\n", "\x55" . $bytes | |||||||||||||||||||||||||||||||||||||||||
| 320 | if DEBUG > 2; | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 52 | return await Future::IO->syswrite_exactly( $_fh, "\x55" . $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 12 | class Device::Serial::SLuRM::Protocol::_Udp | |||||||||||||||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 12 | inherit Device::Serial::SLuRM::Protocol qw( $_bps $_multidrop ); | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 12 | ▶ | use constant DEBUG => Device::Serial::SLuRM::Protocol::DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 12 | ▶ | use constant false => !!0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 12 | ▶ | use Digest::CRC qw( crc8 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 12 | ▶ | use IO::Socket::IP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 12 | field $_sock; | |||||||||||||||||||||||||||||||||||||||||
| 339 | ADJUST :params ( :$fh = undef, :$host, :$port ) | ||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | $_multidrop or croak "Cannot use UDP transport if not in multidrop mode"; | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # UDP doesn't really define this; lets make it a really low generous | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # value to account for network delays | ||||||||||||||||||||||||||||||||||||||||||
| 345 | $_bps = 2400; | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | $_sock = $fh // IO::Socket::IP->new( | ||||||||||||||||||||||||||||||||||||||||||
| 348 | Type => Socket::SOCK_DGRAM, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | #Proto => 'udp', | ||||||||||||||||||||||||||||||||||||||||||
| 350 | PeerHost => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 351 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||
| 352 | ) or die "Cannot create UDP socket - $@"; | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | async method recv_packet () | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recv_packet: called CC=10 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | { | |||||||||||||||||||||||||||||||||||||||||
| 357 | PACKET: { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | my $pkt = await Future::IO->recv( $_sock, 512 ); | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | printf STDERR "SLuRM UDP RECV: %v02X\n", $pkt | |||||||||||||||||||||||||||||||||||||||||
| 361 | if DEBUG > 2; | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | length $pkt >= 12 or redo PACKET; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | my ( $signature, $ver_maj, $ver_min, $op ) = unpack( "a8 C C S>", | |||||||||||||||||||||||||||||||||||||||||
| 366 | substr( $pkt, 0, 12, "" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | ▶ | if( $signature ne "udpSLuRM" or $ver_maj != 0 or $ver_min != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$signature ne "udpSLuRM" or $ver_maj != 0 or $ver_min != 0
$signature ne "udpSLuRM" or $ver_maj != 0
MC/DC0%0/3
$signature ne "udpSLuRM" or $ver_maj != 0 or $ver_min != 0
$signature ne "udpSLuRM"
$ver_maj != 0
$ver_min != 0
Truth table25%1/4
A or B or C
A= $signature ne "udpSLuRM"B= $ver_maj != 0C= $ver_min != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | warn "Bad signature or version number\n"; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | redo PACKET; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | ▶ | if( $op == 0x0001 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | # Because of how the CRCs work, the first 4 bytes and also the | ||||||||||||||||||||||||||||||||||||||||||
| 375 | # entire packet body should come to zero | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ▶ | if( crc8( substr( $pkt, 0, 4 ) ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | $METRICS and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | $METRICS->inc_counter( discards => ); | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | redo PACKET; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | my ( $pktctrl, $addr, $len ) = unpack( "C C C", $pkt ); | |||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | ▶ | if( crc8( substr( $pkt, 0, 4 + $len + 1 ) ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | $METRICS and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | $METRICS->inc_counter( discards => ); | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | redo PACKET; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | my $body = substr $pkt, 4, $len; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | return ( $pktctrl, $addr, $body ); | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | warn "Bad opcode\n"; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | redo PACKET; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | async method send_packet ( $pktctrl, $addr, $body, :$linestuff = false ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_packet: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | { | |||||||||||||||||||||||||||||||||||||||||
| 402 | # We currently ignore linestuffing, but maybe it will be a UDP flag? | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | # SLuRM header | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | my $pkt = pack( "C C C", $pktctrl, $addr, length $body ); | |||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | $pkt .= pack( "C", crc8( $pkt ) ); | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | $pkt .= $body; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | $pkt .= pack( "C", crc8( $pkt ) ); | |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | # udpSLuRM packet header | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | my $bytes = pack( "a8 C C S> a*", | |||||||||||||||||||||||||||||||||||||||||
| 413 | 'udpSLuRM', 0, 0, 0x0001, | ||||||||||||||||||||||||||||||||||||||||||
| 414 | $pkt ); | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | printf STDERR "SLuRM UDP SEND: %v02X\n", $bytes | |||||||||||||||||||||||||||||||||||||||||
| 417 | if DEBUG > 2; | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | return await Future::IO->send( $_sock, $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 420 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 12 | =head1 AUTHOR | |||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 12 | 0x55AA; | |||||||||||||||||||||||||||||||||||||||||