|| $bytes[4] & 0x01
|| $bytes[5] & 0x01;
+ my $nonzero = grep { $_ != 0 } @bytes;
+
my $car = $bytes[0];
my $round = 256*$bytes[1] + $bytes[2]
+ ($bytes[3] & 2 ? 256 : 0)
my $time = 256*$bytes[4] + $bytes[5]
+ ($bytes[3] & 8 ? 256 : 0)
+ ($bytes[3] & 4 ? 1 : 0);
- $time *= 0.01024;
-
- $self->track->car($car)->set_lap($round);
- $self->track->car($car)->set_laptime($time);
+ 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;
+ $self->track->race_setup($bytes[0] == 0x00
+ ? 0
+ : $bytes[1] & 0x0F * 256
+ + $bytes[2] & 0x0F * 16
+ + $bytes[3] & 0x0F);
+
return $msg; # FIXME - to be implemented
}
|| $bytes[4] != 0xFF
|| $bytes[5] != 0xFF;
- return $msg; # FIXME - to be implemented
+ $self->track->qualification_start;
+
+ return $msg;
}
|| $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 $too_fast;
+ my @cars_finished;
+ for my $i (0..5) {
+ my $byte = $bytes[$i];
+
+ $pit_lane_entry = 1 if $byte == 0xF0;
+ $too_fast = 1 if $byte == 0xFF;
+
+ push @cars_finished, $i if $byte == 0xE7;
+ }
+
+ if ($pit_lane_entry) {
+ for my $car (@cars_finished) {
+ $self->track->car($car)->enter_pit_lane;
+ }
+ } else {
+ for my $car (@cars_finished) {
+ $self->track->car($car)->leave_pit_lane;
+ }
+ }
+
return $msg; # FIXME - to be implemented
}
-
sub controller_status_packet {
my ($self, @bytes) = @_;
my $fail;
for my $byte (@bytes) {
- next if $byte == 0xA0;
+ next if $byte == 0xAA;
$fail = 1
if ($byte & 0xC0) != 0xC0
|| ($byte & 0x0F) > 12