From df71a4e96592d60eaaf409591b590326db3ee9f4 Mon Sep 17 00:00:00 2001 From: realraum Date: Tue, 13 Dec 2011 00:02:14 +0000 Subject: [PATCH] added basic decoder --- rf433rcv/pc/decode.pl | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 rf433rcv/pc/decode.pl diff --git a/rf433rcv/pc/decode.pl b/rf433rcv/pc/decode.pl new file mode 100755 index 0000000..c5822e5 --- /dev/null +++ b/rf433rcv/pc/decode.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +use strict; +my @data = split /,/,<>; + +my @statistics; + +my $start = $data[0]; +my $current = $start; +my @lengths; +my $count=0; +for my $input (@data) +{ + $count++; + if ($input != $current) + { + push @lengths,[$current,$count]; + $statistics[$current]{$count}++; + $count=0; + $current=$input; + } +} + +for my $i (0..1) +{ + print "$i:\n"; + my $stat = $statistics[$i]; + for my $key (sort {$a <=> $b} keys %$stat) + { + print "$key $stat->{$key}\n"; + } +} +my $seq; +if (my $delemiter = $ARGV[0]) +{ + print "Starting decoding: $delemiter\n"; + my ($state,$time)=split /,/,$delemiter; + my $start = 0; + for my $data (@lengths) + { + if ($start) + { + print $data->[0] . " => " . $data->[1] ."\n"; + $seq.= ($data->[0].',') x $data->[1]; + } + if ($data->[0]==$state && $data->[1]==$time) + { + if ($start) + { last; + } else { + $start =1; + } + } + } + chop $seq; + print STDERR "$seq\n"; +} -- 1.7.10.4