|| $bytes[4] & 0x01
|| $bytes[5] & 0x01;
- return $msg; # FIXME - to be implemented
+ my $nonzero = grep { $_ != 0 } @bytes;
+
+ my $car = $bytes[0];
+ my $round = 256*$bytes[1] + $bytes[2]
+ + ($bytes[3] & 2 ? 256 : 0)
+ + ($bytes[3] & 1 ? 1 : 0);
+ my $time = 256*$bytes[4] + $bytes[5]
+ + ($bytes[3] & 8 ? 256 : 0)
+ + ($bytes[3] & 4 ? 1 : 0);
+ if ($time == 65535) {
+ $self->track->car($car)->enter_pit_lane;
+ } else {
+ $time *= 0.01024;
+
+ if ($nonzero) {
+ $self->track->car($car)->set_lap($round);
+ $self->track->car($car)->set_laptime($time);
+ } else {
+ # FIXME - probably reset race time or whatever
+ # all-zeros packet is sent after the race setup
+ }
+ }
+
+ return $msg;
}
|| $bytes[4] != 0xFF
|| $bytes[5] != 0xFF;
+ for my $car (0..5) {
+ $self->track->car($car)->set_lap(undef);
+ $self->track->car($car)->set_laptime(undef);
+ }
+
return $msg; # FIXME - to be implemented
}
|| $bytes[4] != 0xFF
|| $bytes[5] != 0xFF;
+ for my $car (0..5) {
+ $self->track->car($car)->set_lap(undef);
+ $self->track->car($car)->set_laptime(undef);
+ }
+
return $msg; # FIXME - to be implemented
}
|| $bytes[4] != 0xFF
|| $bytes[5] != 0xFF;
+ $self->track->race_end;
+
return $msg; # FIXME - to be implemented
}
|| $bytes[4] != 0xAA
|| $bytes[5] != 0xAA;
+ $self->track->race_start;
+
return $msg; # FIXME - to be implemented
}
my $msg = 'Strange finish_line packet'
if $fail;
+ my $pit_lane_entry;
+ my @cars_finished;
+ for my $i (0..5) {
+ my $byte = $bytes[$i];
+
+ $pit_lane_entry = 1 if $byte == 0xF0;
+ push @cars_finished, $i if $byte == 0xE7;
+ }
+
+ if ($pit_lane_entry) {
+ for my $car (@cars_finished) {
+ $self->track->car($car)->enter_pit_lane;
+ }
+ }
+
return $msg; # FIXME - to be implemented
}
my $fail;
for my $byte (@bytes) {
- next if $byte == 0xA0;
+ next if $byte == 0xAA;
$fail = 1
if ($byte & 0xC0) != 0xC0
|| ($byte & 0x0F) > 12