- my $msg = 'Strange reset packet'
- if $bytes[0] != 0xFF
- || $bytes[3] != 0xAA
- || $bytes[4] != 0xAA
- || $bytes[5] != 0xAA;
-
- return $msg; # FIXME - to be implemented
-}
-
-sub standings_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange standings packet'
- if ($bytes[0] != 0xFF && ($bytes[0] & 0x07) > 5)
- || ($bytes[1] != 0xFF && ($bytes[1] & 0x07) > 5)
- || ($bytes[2] != 0xFF && ($bytes[2] & 0x07) > 5)
- || ($bytes[3] != 0xFF && ($bytes[3] & 0x07) > 5)
- || ($bytes[4] != 0xFF && ($bytes[4] & 0x07) > 5)
- || ($bytes[5] != 0xFF && ($bytes[5] & 0x07) > 5);
-
- my @standings;
-
- push @standings, map { $_ != 0xFF ? $_ & (0x07) : () } @bytes;
-
- return $msg; # FIXME - to be implemented
-}
-
-sub lap_time_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange lap time packet'
- if $bytes[0] > 5
- || $bytes[1] & 0x01
- || $bytes[2] & 0x01
- || ($bytes[3] & 0xF0) != 0
- || $bytes[4] & 0x01
- || $bytes[5] & 0x01;
-
- 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);
- $time *= 0.01024;
-
- $self->track->car($car)->set_lap($round);
- $self->track->car($car)->set_laptime($time);
-
- return $msg;
-}
-
-
-sub race_setup_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange race setup packet'
- if ($bytes[0] != 0x00 && $bytes[0] != 0xFF)
- || $bytes[1] & 0xF0
- || $bytes[2] & 0xF0
- || $bytes[3] & 0xF0
- || $bytes[4] != 0xFF
- || $bytes[5] != 0xFF;
-
- return $msg; # FIXME - to be implemented
-}
-
-
-sub fuel_level_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange fuel_level packet'
- if ($bytes[0] >> 4) > 8
- || ($bytes[0] & 0x0F) > 8
- || ($bytes[1] >> 4) > 8
- || ($bytes[1] & 0x0F) > 8
- || ($bytes[2] >> 4) > 8
- || ($bytes[2] & 0x0F) > 8
- || ($bytes[5] != 0xAA && $bytes[5] != 0xFF);
-
- my @fuel = (
- $bytes[0] >> 4, $bytes[0] & 0x0f,
- $bytes[1] >> 4, $bytes[1] & 0x0f,
- $bytes[2] >> 4, $bytes[2] & 0x0f,
- );
-
- for my $car (0..5) {
- $self->track->car($car)->set_fuel($fuel[$car]);
- }
-
- return $msg;
-}
-
-
-sub brake_set_packet {
- my ($self, @bytes) = @_;
-
- return 'Unexpected brake_set packet (should be in the pit lane only)';
-}
-
-
-sub qualification_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange qualification packet'
- if $bytes[0] & 0xF0
- || $bytes[1] & 0xF0
- || $bytes[2] & 0xF0
- || $bytes[3] > 5
- || $bytes[4] != 0xFF
- || $bytes[5] != 0xFF;
-
- return $msg; # FIXME - to be implemented
-}
-
-
-sub end_of_race_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange end_of_race packet'
- if $bytes[0] != 0xFF
- || $bytes[1] != 0xFF
- || $bytes[2] != 0xFF
- || $bytes[3] != 0xFF
- || $bytes[4] != 0xFF
- || $bytes[5] != 0xFF;
-
- return $msg; # FIXME - to be implemented
-}
-
-
-sub race_start_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange race_start packet'
- if $bytes[0] != 0x00
- || $bytes[1] != 0xAA
- || $bytes[2] != 0xAA
- || $bytes[3] != 0xAA
- || $bytes[4] != 0xAA
- || $bytes[5] != 0xAA;
-
- return $msg; # FIXME - to be implemented
-}
-
-
-sub display_change_packet {
- my ($self, @bytes) = @_;
-
- my $msg = 'Strange display_change packet'
- if $bytes[0] & 0xFE
- || $bytes[1] != 0xFF
- || $bytes[2] != 0xFF
- || $bytes[3] != 0xFF
- || $bytes[4] != 0xFF
- || $bytes[5] != 0xFF;
-
- return $msg; # FIXME - to be implemented
-}
-
-
-sub finish_line_packet {
- my ($self, @bytes) = @_;
-
- my $fail;
- for my $byte (@bytes) {
- $fail = 1
- if $byte != 0xAA
- && $byte != 0xE7
- && $byte != 0xF0
- && $byte != 0xFE
- }
-
- my $msg = 'Strange finish_line packet'
- if $fail;
-
- return $msg; # FIXME - to be implemented
-}
-
-
-sub controller_status_packet {
- my ($self, @bytes) = @_;
-
- my $fail;
- for my $byte (@bytes) {
- next if $byte == 0xA0;
- $fail = 1
- if ($byte & 0xC0) != 0xC0
- || ($byte & 0x0F) > 12
- }
-
- my $msg = 'Strange controller_status packet'
- if $fail;
-
- my @fuel = (
- $bytes[1] >> 4, $bytes[1] & 0x0f,
- $bytes[2] >> 4, $bytes[2] & 0x0f,
- $bytes[3] >> 4, $bytes[3] & 0x0f,
- );
-
- for my $car (0..5) {
- my $byte = $bytes[$car];
-
- if ($byte == 0xAA) {
- $self->track->car($car)->set_throttle(undef);
- next;
- }
-
- my $light = !($byte & 0x20);
- my $backbutton = !($byte & 0x10);
- my $throttle = $byte & 0x0f;
-
- $self->track->car($car)->set_throttle($throttle);
- $self->track->car($car)->set_light($light);
- $self->track->car($car)->set_backbutton($backbutton);
- }