]> dxcluster.org Git - dweather.git/commitdiff
rename some vars to make more sense
authorDirk Koopman <djk@tobit.co.uk>
Mon, 14 Jul 2014 17:31:05 +0000 (18:31 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Mon, 14 Jul 2014 17:31:05 +0000 (18:31 +0100)
loop.pl

diff --git a/loop.pl b/loop.pl
index e4a1fb69eb2c341a26d3af625c1ad03ecb6ca336..a9b7f2d3245a9f62a5bdb675964ce2bc29eee074 100755 (executable)
--- a/loop.pl
+++ b/loop.pl
@@ -21,7 +21,7 @@ my $state = "ready";
 my $buf;
 my $dbg;
 my $last_reading;
-my $s;                                                 # the serial port Mojo::IOLoop::Stream
+my $ser;                                                       # the serial port Mojo::IOLoop::Stream
 our $ending = 0;
 
 our $json = JSON->new->canonical(1);
@@ -110,7 +110,7 @@ exit 0;
 
 sub on_read
 {
-       my ($str, $d) = @_;
+       my ($ser, $d) = @_;
        $buf .= $d;
        $d =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg; 
        dbg "read added '$d' buf lth=" . length $buf if isdbg 'raw';
@@ -120,7 +120,7 @@ sub on_read
                undef $tid;
                undef $buf;
                $nlcount = 0;
-               $s->write("LPS 1 1\n");
+               $ser->write("LPS 1 1\n");
                chgstate("waitloop");
        } elsif ($state eq "waitloop") {
                if ($buf =~ /\x06/) {
@@ -142,7 +142,7 @@ sub start_loop
 {
        $nlcount = 1;
        dbg "start_loop writing $nlcount \\n" if isdbg 'state';
-       $s->write("\n");
+       $ser->write("\n");
        Mojo::IOLoop->remove($tid) if $tid;
        undef $tid;
        $tid = Mojo::IOLoop->recurring(0.6 => sub {
@@ -152,7 +152,7 @@ sub start_loop
                                                                                   return;
                                                                           }
                                                                           dbg "writing $nlcount \\n" if isdbg 'state'; 
-                                                                          $s->write("\n");
+                                                                          $ser->write("\n");
                                                                   });
        chgstate("waitnl");
 }
@@ -168,7 +168,7 @@ sub do_reopen
        my $name = shift;
        dbg "do reopen on '$name' ending $ending";
        unless ($ending) {
-               $s = do_open($name);
+               $ser = do_open($name);
                start_loop();
                chgstate('');
                $nlcount = 0;
@@ -180,18 +180,18 @@ sub do_open
 {
        my $name = shift;
 
-       $s->close if $s;
-       undef $s;
+       $ser->close if $ser;
+       undef $ser;
 
        my $ob = Serial->new($name, 19200) || die "$name $!\n";
        dbg "streaming $name fileno(" . fileno($ob) . ")" if isdbg 'chan';
        
-       my $str = Mojo::IOLoop::Stream->new($ob);
-       $str->on(error=>sub {dbg "serial $_[1]"; do_reopen($name) unless $ending});
-       $str->on(close=>sub {dbg "serial closing"; do_reopen($name) unless $ending});
-       $str->on(timeout=>sub {dbg "serial timeout";});
-       $str->on(read=>sub {on_read(@_)});
-       $str->start;
+       my $ser = Mojo::IOLoop::Stream->new($ob);
+       $ser->on(error=>sub {dbg "serial $_[1]"; do_reopen($name) unless $ending});
+       $ser->on(close=>sub {dbg "serial closing"; do_reopen($name) unless $ending});
+       $ser->on(timeout=>sub {dbg "serial timeout";});
+       $ser->on(read=>sub {on_read(@_)});
+       $ser->start;
 
        Mojo::IOLoop->remove($tid) if $tid;
        undef $tid;
@@ -203,7 +203,7 @@ sub do_open
        chgstate('');
        $nlcount = 0;
        
-       return $str;
+       return $ser;
 }
 
 my @min;
@@ -284,7 +284,7 @@ sub process
        if ($crc_calc==0) {
                my $ts = time;
                my $j;
-               my $str;
+               my $s;
                if ($ts >= $last_hour + 3600) {
                        $h{Pressure_Trend}    = unpack("C", substr $blk,3,1);
                        $h{Pressure_Trend_txt} = $bar_trend{$h{Pressure_Trend}};
@@ -311,7 +311,7 @@ sub process
                        $last_rain_min = $last_rain_hour = $rain;
 
                        $j = $json->encode(\%h);
-                       $str = qq|{"t":$ts,"h":$j}|;
+                       $s = qq|{"t":$ts,"h":$j}|;
                        $last_hour = int($ts/3600)*3600;
                        $last_min = int($ts/60)*60;
                        @hour = ();
@@ -331,19 +331,19 @@ sub process
                        $last_rain_min = $rain;
 
                        $j = $json->encode(\%h);
-                       $str = qq|{"t":$ts,"m":$j}|;
+                       $s = qq|{"t":$ts,"m":$j}|;
                        $last_min = int($ts/60)*60;
                        @min = ();
                } else {
                        my $o = gen_hash_diff($last_reading, \%h);
                        if ($o) {
                                $j = $json->encode($o);
-                               $str = qq|{"t":$ts,"r":$j}|;
+                               $s = qq|{"t":$ts,"r":$j}|;
                        } else {
                                dbg "loop rec not changed" if isdbg 'chan';
                        }
                }
-               output_str($str) if $str;
+               output_str($s) if $s;
                $last_reading = \%h;
                ++$loop_count;
        } else {
@@ -354,10 +354,10 @@ sub process
 
 sub output_str
 {
-       my $str = shift;
-       dbg $str;
-#      say $str;
-       $dlog->writenow($str);
+       my $s = shift;
+       dbg $s;
+#      say $s;
+       $dlog->writenow($s);
 }
 
 sub gen_hash_diff