forked from nihilanth41/ble
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.pl
More file actions
executable file
·46 lines (34 loc) · 881 Bytes
/
parse.pl
File metadata and controls
executable file
·46 lines (34 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
use strict;
use warnings;
# Check input args
my $ARGC = scalar @ARGV;
$ARGC >= 1 or die "Error: not enough arguments.\nUsage is: $0 <filename>\n";
# Open input file
my $filepath = shift;
open(my $fh_r, "<:encoding(UTF-8)", $filepath) or die "Can't open file $filepath. $!";
my @lines = (); # lines as seen from serial monitor
my $words; # temporary var to concatenate $word
while(<$fh_r>) {
my $i=0;
if (/0x([[:xdigit:]]+)/) {
my $hexstr = $1;
if($hexstr =~ /0a/) {
push @lines, $words;
$i++;
$words = "";
}
my $word;
while ($hexstr =~ /(..)/g) {$word .= chr hex $1}
$words .= $word;
}
}
chop(@lines); # Remove newline
chop(@lines); # Remove trailing '|'
# @lines is now a csv of x-accel,y-accel,z-accel in m/s^2
# E.g. |0.00|0.00|9.5|
foreach(@lines) {
my $line = substr $_, 2;
$line =~ s/\|/\,/g;
print "$line\n";
}