3 package SCX::LogPrinter;
7 use base qw(SCX::Parser);
9 our $UNIQ_TIMEOUT = 2.0;
12 my ($class, $args) = @_;
14 my $self = SCX::Parser->new();
17 $self->{dump_bad_bytes} = 1 if $args->{dump_bad_bytes};
18 $self->{dump_strange} = 1 if $args->{dump_strage};
19 $self->{uniq_only} = 1 if $args->{uniq_only};
20 $self->{skip_types} = $args->{skip_types};
26 my ($self, $key, @vals) = @_;
28 return if $self->{skip_types}->{$key};
30 if ($key !~ /finish_line/ && @vals) {
31 my $val = join('|', @vals);
32 return if $self->{uniq_only}
33 && defined $self->{uniq}->{$key}
34 && $self->{uniq}->{$key} eq $val;
36 $self->{uniq}->{$key} = $val;
38 my $time = $self->now;
39 return if $self->{uniq_only}
40 && defined $self->{uniq}->{$key}
41 && $time - $self->{uniq}->{$key} < $UNIQ_TIMEOUT;
42 $self->{uniq}->{$key} = $time;
45 $self->do_print($key, @vals);
51 return join(' ', map { sprintf("%02X", $_) } @data);
55 my ($self, @data) = @_;
57 print join(' ', $self->now, @data), "\n";
61 my ($self, @data) = @_;
63 return if !$self->{dump_bad_bytes};
64 $self->do_print('bad_bytes', stringify_data(@data));
68 my ($self, $name, @data) = @_;
70 return if !$self->{dump_strage};
71 $self->do_print('strange', $name, stringify_data(@data));
75 my ($self, @data) = @_;
77 $self->do_print('unknown_packet', stringify_data(@data));
81 my ($self, @data) = @_;
83 $self->cond_print('bus_free_time', @data);
87 my ($self, @data) = @_;
89 $self->cond_print('car_programming', @data);
93 my ($self, @data) = @_;
95 $self->cond_print('reset', @data);
99 my ($self, @data) = @_;
101 $self->cond_print('standings', @data);
105 my ($self, $car, @data) = @_;
107 $self->cond_print('car_lap_time_' . $car, @data);
111 my ($self, @data) = @_;
113 $self->cond_print('race_setup', @data);
117 my ($self, @data) = @_;
120 if ($self->{prev_fuel_levels}) {
122 if ($self->{prev_fuel_levels}->[$i] < $data[$i]) {
123 push @newdata, $data[$i] . '+';
125 push @newdata, $data[$i] . ' ';
129 $self->{prev_fuel_levels} = \@data;
131 $self->cond_print('fuel_level', @newdata);
135 my ($self, @data) = @_;
137 $self->cond_print('brake_set', @data);
141 my ($self, @data) = @_;
143 $self->cond_print('qualification', @data);
147 my ($self, @data) = @_;
149 $self->cond_print('end_of_race', @data);
153 my ($self, @data) = @_;
155 $self->cond_print('race_start', @data);
159 my ($self, @data) = @_;
161 $self->cond_print('display_change', @data);
165 my ($self, $regular, @cars) = @_;
167 for my $car (@cars) {
168 $self->cond_print('finish_line_' . $car, $regular);
172 sub controller_status {
173 my ($self, @ctrls) = @_;
182 push @data, sprintf('% 2d', $c->{throttle})
183 . ($c->{button} ? '/' : '.');
184 # Ignore lights for now
187 $self->cond_print('controller', @data);