9 use Glib qw(TRUE FALSE);
10 use Time::HiRes qw(time usleep);
19 if (!getopts('b:e:ft:l:', \%opt)) {
23 if (($opt{t} && $opt{l})
24 || (!$opt{l} && ($opt{b} || $opt{e} || $opt{f}))) {
28 my $gui = SCX::GUI->new({ img_height => 70 });
29 my $track = SCX::Track->new({ gui => $gui, no_semaphore => $opt{f} });
33 my $parser = SCX::RaceParser->new({
35 logfile => $opt{l} ? undef : $logfile,
38 my ($log_reader, $tty_reader);
40 if ($opt{l}) { # Log file replay mode
41 $log_reader = SCX::LogReader->new({
43 begin_time => $opt{b},
47 my $tty = $opt{t} || '/dev/ttyUSB0';
60 print STDERR "Demo mode only: $@";
64 $track->car(0)->set_model('F1 Ferrari');
65 $track->car(1)->set_model('F1 McLaren');
66 #$track->car(2)->set_model('F1 Williams');
67 $track->car(2)->set_model('Citroen Xsara');
68 $track->car(3)->set_model('Chevrolet Corvette gelb');
69 $track->car(4)->set_model('Ferrari 360 Red Bull');
70 $track->car(5)->set_model('Ferrari 360 Cric Crac');
72 $track->car(0)->set_driver('Ferrari');
73 $track->car(1)->set_driver('McLaren');
74 $track->car(2)->set_driver('Xsara');
77 Glib::IO->add_watch(fileno($tty_reader->fh), 'in',
78 \&scx_read, $tty_reader);
79 } elsif ($log_reader) {
80 Glib::Idle->add(\&log_read_start, [ $log_reader, $parser, $opt{f} ]);
82 # Just display some random values
86 $gui->best_lap('12.3');
89 $track->{race_running_since} = $now;
90 $track->{race_running} = 1;
92 $track->finish_line($now + 0.5, 1, 2);
93 $track->finish_line($now + 0.7, 1, 1);
94 $track->finish_line($now + 4.9, 1, 1);
95 $track->finish_line($now + 5.3, 1, 2);
96 $track->finish_line($now + 7.2, 1, 1);
97 $track->finish_line($now + 8.1, 0, 2);
98 # $track->car(0)->set_lap(13);
99 # $track->car(1)->set_lap(11);
100 # $track->car(2)->set_lap(10);
101 # $track->car(3)->set_lap(undef);
102 # $track->car(4)->set_lap(undef);
103 # $track->car(5)->set_lap(undef);
105 $track->car(0)->set_laptime(9.12322);
106 $track->car(1)->set_laptime(15.313);
107 $track->car(2)->set_laptime(5.989);
109 $track->car(0)->set_fuel(6);
110 $track->car(1)->set_fuel(2);
111 $track->car(2)->set_fuel(8);
113 $track->car(0)->set_throttle(0);
114 $track->car(1)->set_throttle(8, 1);
115 $track->car(2)->set_throttle(12);
130 my ($event, $fh, $reader) = @_;
137 die "Usage: $0 [-t tty_line]\n"
138 . "or: $0 -l logfile [-b starttime] [-e endtime] [-f]\n"
139 . "-f ... replay as fast as possible\n";
145 my ($logreader, $parser, $fast) = @$data;
147 our ($starttime, $log_starttime);
149 my ($l_time, @data) = $logreader->get_data();
150 return FALSE if !$l_time;
155 $log_starttime ||= $l_time;
157 my $time_diff = ($l_time - $log_starttime) - ($now - $starttime);
158 if (!$fast && $time_diff > 0) {
159 # print "sleeping for $time_diff s\n";
160 usleep(1_000_000 * $time_diff);
163 $parser->add_data($l_time, @data);