Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017
view release on metacpan or search on metacpan
devdata/https_mojolicious.io_blog_2017_12_21_day-21-virtually-a-lumberjack view on Meta::CPAN
<p>And add a method which progresses us through the script:</p>
<pre><code>sub instruction_show {
my $self = shift;
my $instruction = shift @{$self->instructions};
return $self->loop->stop_gracefully unless defined $instruction;
say $instruction->[1];
$self->loop->timer(
$instruction->[0] => sub { $self->instruction_show },
);
$self->loop->timer($instruction->[0] / 2, sub {
my $type = (split / /, $self->instructions->[0][1])[1];
my $file_count = $self->file_count;
my $path = sprintf '%i_%s.pgm', $file_count, uc $type;
$self->file( $self->file_start($path) );
}) if $instruction->[1] eq 'Steady';
}
</code></pre>
<p>As you can see, we ask the loop to stop gracefully when there are no more
instructions.
devdata/https_mojolicious.io_blog_2017_12_21_day-21-virtually-a-lumberjack view on Meta::CPAN
to be done in the amount of seconds we specified in the script.</p>
<p>If the action is to steady the HMD, we know we are going to start another
action shortly so, in half of the wait time, we start a new file.
This should mean that the end and start of each file, the HMD is not moving
(much).</p>
<p>Then we need to start walking through this script by adding this before
starting the event loop in <em>main</em>:</p>
<pre><code>$self->loop->timer(0 => sub { $self->instruction_show });
</code></pre>
<p>Running this now prompts the user to move the HMD while outputting the packet
data in an image named after the movement that image represents!</p>
<h2>Get Your Head(er) Checked</h2>
<p>As mentioned, the PGM header is broken as it is supposed to contain the number
of rows and columns in the image, but this isn't known in advance.
We put an 8 character per value placeholder there and use this small shell
devdata/https_mojolicious.io_blog_2017_12_21_day-21-virtually-a-lumberjack view on Meta::CPAN
<p>Now these are valid PGM images and we can open them to see the data stream!</p>
<p><img alt="Section of Yaw PGM" src="yaw.png"></p>
<p>(The above has been rotated and flipped, the original image is a thin
"waterfall".)</p>
<p>Some parts are immediately obvious.
Very smooth gradients next to larger smooth blocks or gradients hints at a
high-precision timer, which tend to be 32 bits (4 bytes) wide.
This can be seen at the top of the example.</p>
<p>Other aspects are only noticeable when compared to the other movements.
The simple file format makes it very easy to graph the data with gnuplot.
In the worst/simple case scenario, you can simply graph at each offset and
various sizes until you see a (rough) sine wave, indicating you've got the
right offset and number of bytes for that part of the puzzle!</p>
<h2>Moving On To Greater Things</h2>
( run in 1.374 second using v1.01-cache-2.11-cpan-49f99fa48dc )