Skip to content

Instantly share code, notes, and snippets.

@jhgorse
Last active September 9, 2021 04:34
Show Gist options
  • Save jhgorse/28656c0acac6398f080c31e02e7c4c82 to your computer and use it in GitHub Desktop.
Save jhgorse/28656c0acac6398f080c31e02e7c4c82 to your computer and use it in GitHub Desktop.
output power details to csv
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
my @a;
my $ts;
my $count;
START:
## begin line 1 of 7
$_ = <> or die "read failed.";
chomp;
@a = split /,/;
scalar @a == 6 or goto START; # die "stuff"; # assert start with status line
printf "%05d,", ++$count;
$ts = $a[0]; # set timestamp to match against later
print "$a[0],$a[1],$a[2],$a[3],";
my $bin = sprintf("%016b", hex($a[3]) & 0xFFFF);
foreach my $c (split //, $bin) {
print $c.",";
}
print "$a[4],$a[5]";
### end line 1 of 7
for (1..6) {
$_ = <> or die; chomp;
@a = split /,/;
scalar @a == 10 or die; # asset 10 elements for the next 6 lines
$ts eq $a[0] or die; # assert timestamp is the same
print ",$_";
}
print "\n";
### end line 7 of 7
goto START;
# 81 commas
# 2021-06-09 00:00:00.442,1,0,1010,0,42,65535,37,14709,2114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment