|| (defined $self->{throttle} && defined $val
&& $self->{throttle} == $val);
+ if ($self->{in_pit_lane} && defined $val && $val > 3) {
+ delete $self->{in_pit_lane};
+ $self->gui->leave_pit_lane;
+ }
+
$self->{throttle} = $val;
$self->gui->set_throttle($self->{order}, $val);
}
return if (!defined $self->{car_icon} && !defined $name)
|| (defined $self->{car_icon} && defined $name
- && $self->{car_icon} ne $name);
+ && $self->{car_icon} eq $name);
$self->{car_icon} = $name;
$self->gui->set_car_icon($self->{order}, $name);
return if (!defined $self->{lap} && !defined $lap_nr)
|| (defined $self->{lap} && defined $lap_nr
- && $self->{lap} != $lap_nr);
+ && $self->{lap} == $lap_nr);
$self->{lap} = $lap_nr;
- $self->gui->set_lap($self->{order}, $lap_nr || 'N/A');
+ $self->gui->set_lap($self->{order}, defined $lap_nr ? $lap_nr : 'N/A');
}
sub set_laptime {
if (defined $lap_time) {
$lap_time = sprintf("%.2f", $lap_time);
- if (!defined $self->{best_lap}
- || $self->{best_lap} > $lap_time) {
+ if ($lap_time > 1.0 && (
+ !$self->{in_pit_lane} && !defined $self->{best_lap}
+ || $self->{best_lap} > $lap_time
+ )) {
$self->gui->set_best_lap($self->{order}, $lap_time);
$self->{best_lap} = $lap_time;
}
+ } else {
+ $self->gui->set_best_lap($self->{order}, 'N/A');
+ $self->{best_lap} = undef;
}
return if (!defined $self->{laptime} && !defined $lap_time)
|| (defined $self->{laptime} && defined $lap_time
- && $self->{laptime} != $lap_time);
+ && $self->{laptime} == $lap_time);
$self->{laptime} = $lap_time;
- $self->gui->set_laptime($self->{order}, $lap_time || 'N/A');
+ $self->gui->set_laptime($self->{order}, defined $lap_time
+ ? $lap_time : 'N/A');
}
sub set_driver {
return if (!defined $self->{driver} && !defined $driver_name)
|| (defined $self->{driver} && defined $driver_name
- && $self->{driver} != $driver_name);
+ && $self->{driver} == $driver_name);
$self->{driver} = $driver_name;
$self->gui->set_driver($self->{order}, $driver_name || 'N/A');
}
+sub enter_pit_lane {
+ my ($self) = @_;
+
+ $self->{in_pit_lane} = 1;
+ $self->gui->enter_pit_lane;
+}
+
1;
$label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
}
+sub enter_pit_lane {
+ my ($self, $row) = @_;
+ $self->set_laptime($row, 'PIT');
+}
+
+sub leave_pit_lane {
+ my ($self, $row) = @_;
+ $self->set_laptime($row, '--');
+}
+
1;
|| $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;
+ 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
sub car { return shift->{cars}->[shift]; }
+sub race_start {
+ my ($self) = @_;
+
+ $self->{race_running} = 1;
+
+}
+
+sub race_end {
+ my ($self) = @_;
+
+ $self->{race_running} = 0;
+}
+
1;
use SCX::Track;
use SCX::Reader;
-my $no_reader = 1;
+my $no_reader = 0;
my $gui = SCX::GUI->new;
my $track = SCX::Track->new({ gui => $gui });
--- /dev/null
+7 kol, prujezd boxy asi ve 3., rychly prujezd v 5., tankovani v 6.
+
+ 6.071 55 d3 82 ff ff ff ff ff d5 05
+ 6.173 55 d6 83 88 88 14 50 aa 93 05
+ 6.327 55 d4 02 00 08 0c 00 66 9c 05
+ 6.361 55 d5 ff 00 00 07 ff ff 05 05 # Race setup down 7 kol
+ 6.573 55 d0 ff 0a 05 aa aa aa ad 05 # Reset
+ 6.609 55 dd 00 aa aa aa aa aa 42 05 # race start
+ 6.931 55 d6 83 88 88 14 50 aa 93 05
+ 9.180 55 aa 18 06 f0 f0 f0 f0 93 05
+ 9.187 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 9.216 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 9.224 55 d4 02 00 00 01 00 00 a0 05 # Car 2 round 1 time 0
+ 9.228 55 d3 82 ff ff ff ff ff d5 05 # Standing 2 _ _ _ _ _
+ 9.250 55 aa 18 06 f0 f0 f0 f0 93 05
+ 9.258 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 9.286 55 ee fe fe fe aa aa aa a1 05 # No car crosses finish line
+ 9.352 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 12.943 55 ee 02 00 e7 01 00 00 cf 05 # Strange finish_line packet
+ 12.951 55 d4 02 00 02 0c 00 6a fa 05 # Car 2 round 2 time xxx
+ 13.581 55 ee fe fe e7 aa aa aa 1e 05 # Normal finish line packet
+ 13.700 55 d4 02 00 02 00 00 00 e1 05 # Car 2 round 2 time 0
+ 16.765 55 aa 18 06 f0 f0 f0 f0 93 05
+ 16.772 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 16.801 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 16.809 55 d4 02 00 02 0d 00 78 9d 05 # Car 2 round 3 time xxx
+ 16.836 55 aa 18 06 f0 f0 f0 f0 93 05
+ 16.843 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 16.871 55 ee fe fe fe aa aa aa a1 05 # No car crosses finish line
+ 16.936 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 20.076 55 aa 18 06 f0 f0 f0 f0 93 05
+ 20.083 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 20.112 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 20.120 55 d4 02 00 04 08 00 42 e5 05 # Car 2 round 4 time xxx
+ 20.146 55 aa 18 06 f0 f0 f0 f0 93 05
+ 20.154 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 20.182 55 ee fe fe fe aa aa aa a1 05 # No car crosses finish line
+ 20.248 55 ee fe fe e7 aa aa aa 1e 05
+ 23.555 55 aa 18 06 f0 f0 f0 f0 93 05
+ 23.563 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 23.591 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 23.599 55 d4 02 00 04 0d 00 54 6f 05 # Car 2 round 5 time xxx
+ 23.626 55 aa 18 06 f0 f0 f0 f0 93 05
+ 23.633 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 23.662 55 ee fe fe fe aa aa aa a1 05 # No car crosses finish line
+ 23.726 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 26.048 55 d6 83 78 88 14 50 aa 65 05 # Car 2 fuel 7
+ 26.928 55 ee 82 ff e7 ff ff ff 90 05 # Strange finish_line packet (too fast?)
+ 26.936 55 d4 02 00 06 0c 00 48 10 05 # Car 2 round 6 time xxx
+ 28.032 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 32.195 55 ee f0 f0 e7 aa aa aa b1 05 # Car 2 crosses finish line
+ 32.203 55 d4 02 00 06 0d 00 fe 4f 05 # Car 2 round 7 time ff ..
+ 32.315 55 d4 02 00 06 01 00 00 a9 05 # Car 2 round 7 time 00
+ 34.005 55 d4 02 00 06 09 fe fe 13 05 # Car 2 round 7 time feff?
+ 35.700 55 d6 83 88 88 14 50 aa 93 05 # Car 2 fuel 8
+ 42.156 55 aa 18 06 f0 f0 f0 f0 93 05
+ 42.163 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 42.191 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 42.213 55 dc ff ff ff ff ff ff df 05 # End of race
+ 42.228 55 aa 18 06 f0 f0 f0 f0 93 05
+ 42.235 55 aa 0c 06 f0 f0 f0 f0 7b 05
+ 42.264 55 ee fe fe fe aa aa aa a1 05 # No car crosses finish line
+ 42.341 55 ee fe fe e7 aa aa aa 1e 05 # Car 2 crosses finish line
+ 42.381 55 d4 02 00 08 0c 02 d4 98 05 # Car 2 round 8 time ...
+ 51.997 55 dc ff ff ff ff ff ff df 05 # End of race
+ 52.003 55 dc ff ff ff ff ff ff df 05
55 D4 01 00 02 08 00 E8 32 (round 2)
55 D4 01 00 02 0D 00 B6 3C (round 3)
55 D4 01 00 04 0C 04 98 69 (round 4)
+Box entry example
+32.203 55 d4 02 00 06 0d 00 fe 4f 05 # Car 2 round 7 time ff ..
+32.315 55 d4 02 00 06 01 00 00 a9 05 # Car 2 round 7 time 00
+34.005 55 d4 02 00 06 09 fe fe 13 05 # Here the back button has been presed
-0xD5 - race start
+
+0xD5 - race setup
-----------------
Format: 0x055 0xD5 DI R2-R0 0xFF 0xFF CRC
R0-R5 - one byte for each car. 0xE7 means that this car has crossed the
finish line, every other value means it did not cross it:
0xAA is sent for unconnected controllers.
- My pit box with 020 firmware has been seen sending either
- 0xF0 or 0xFE values as well
Example:
55 EE F0 E7 F0 AA AA AA 3C
-55 EE FE FE E7 AA AA AA 1E
+55 EE FE FE E7 AA AA AA 1E # Car 2 crosses normal finish line
+55 EE 02 00 E7 01 00 00 CF # Car 2 drives through pit lane
+55 EE 82 FF E7 FF FF Ff 90 # Car 2 enters pit lane too fast
+55 EE F0 F0 E7 AA AA AA B1 # Car 2 enters pit lane
+
0xFF - controller status