#!/usr/bin/perl -w #2345678911234567892123456789312345678941234567895123456789612345678971234567898 # 1cm of real rain is about 50mm recorded. # License: GPL v3 # Author: Marc MERLIN 2010/05/01 # $Id: parse_rfx-xpl 356 2011-09-24 23:25:47Z svnuser $ use strict; use Date::Manip; use FileHandle; my $VERBOSE = 0; my $LOGFILE = "/var/log/xpl.log"; $LOGFILE=$ENV{'TEMPLOGFILE'} if ($ENV{'TEMPLOGFILE'}); open(XPL, "/var/local/src/rfxcom_xpl/rfx-xpl-static -interface eth1 -d 2>&1 |"); open(LOG, ">>$LOGFILE"); LOG->autoflush; my $lastprocess = ""; while () { next if (/process\[\d+\] return:/); my $date = UnixDate("now", "%Y/%m/%d %T"); # remove garbage character from rfx-xpl: s/ //g; if (/process\[\d+\]: .* cnt=/) { $lastprocess = $_ ; next; } elsif ($lastprocess) { $lastprocess =~ s/:.* cnt/ cnt/; print LOG "$date: $lastprocess"; $lastprocess = ""; } if (not /^X10: \S+ o(n|ff)$/ and not /^X10 Sec: addr/ and not / addr: / ) { next; } s/(hum: \d+)/$1 %/; if ( /(\d+) hPa/ ) { my $pres = $1; my $inhg = sprintf("%5.2f", $pres / 33.8639); s#(\d+) hPa#$pres hPa / $inhg inHg#; } elsif ( m#speed (\S+) m/s average (\S+) m/s# ) { my ($speed1, $speed2) = ($1, $2); my $knots1 = int($speed1 * 1.94384449); my $knots2 = int($speed2 * 1.94384449); s#speed (\S+) m/s average (\S+) m/s#speed $speed1 m/s / $knots1 kts average $speed2 m/s / $knots2 kts#; } print LOG "$date: $_"; } # vim:sts=4:sw=4