From 631bc0f2b224c9ebfd1dd5827814e5aba3e6d023 Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Thu, 10 May 2012 16:18:21 +0100 Subject: [PATCH 1/1] wip --- .gitignore | 5 +++ DWeather/dweather | 36 +++++++++++++++++++++ DWeather/lib/DWeather.pm | 3 ++ DWeather/lib/DWeather/Debug.pm | 8 ++--- DWeather/lib/DWeather/{Log.pm => Logger.pm} | 11 ++++--- DWeather/lib/DWeather/Serial.pm | 8 ++++- DWeather/lib/DWeather/Station.pm | 26 +++++++++++++++ DWeather/lib/DWeather/Station/Vantage.pm | 35 ++++++++++++++++++++ DWeather/lib/DWeather/Vantage.pm | 30 +++++++++++++++++ 9 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 DWeather/dweather rename DWeather/lib/DWeather/{Log.pm => Logger.pm} (95%) create mode 100644 DWeather/lib/DWeather/Station.pm create mode 100644 DWeather/lib/DWeather/Station/Vantage.pm create mode 100644 DWeather/lib/DWeather/Vantage.pm diff --git a/.gitignore b/.gitignore index b25c15b..f020ecd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ *~ +blib +MYMETA* +Makefile +logs +pm_to_blib diff --git a/DWeather/dweather b/DWeather/dweather new file mode 100644 index 0000000..3844fcc --- /dev/null +++ b/DWeather/dweather @@ -0,0 +1,36 @@ +#!/usr/bin/perl +# +# dweather - a distributed weather station +# +# copyright (c) 2012 Dirk Koopman G1TLH +# +# + +use strict; +use warnings; + +use lib qw(. ./blib ./lib ./DWeather/lib); + +use DWeather; +use DWeather::Logger; +use DWeather::Debug; +use AnyEvent; + +my $sigint = AnyEvent->signal (signal => "INT", cb => sub { my $sig = shift; terminate("on signal $sig")}); +my $sigterm = AnyEvent->signal (signal => "TERM", cb => sub { my $sig = shift; terminate("on signal $sig")}); + +dbginit(); +dbg("*** dweather started"); + +my $cv = AnyEvent->condvar; +my @res = $cv->recv; + +exit 0; + + +sub terminate +{ + my $m = shift; + dbg("*** dweather ended" . ($m ? " $m" : ' normally')); + exit(0); +} diff --git a/DWeather/lib/DWeather.pm b/DWeather/lib/DWeather.pm index cbe5b97..5c10481 100644 --- a/DWeather/lib/DWeather.pm +++ b/DWeather/lib/DWeather.pm @@ -11,6 +11,9 @@ our @ISA = qw(Exporter); our $VERSION = '0.01'; +use DWeather::Logger; +use DWeather::Debug; +use DWeather::Serial; # Preloaded methods go here. diff --git a/DWeather/lib/DWeather/Debug.pm b/DWeather/lib/DWeather/Debug.pm index bf81520..3535184 100644 --- a/DWeather/lib/DWeather/Debug.pm +++ b/DWeather/lib/DWeather/Debug.pm @@ -10,7 +10,7 @@ # modify it under the same terms as Perl itself. # -package Debug; +package DWeather::Debug; require Exporter; @ISA = qw(Exporter); @@ -20,7 +20,7 @@ $VERSION = sprintf( "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/ ); use strict; use vars qw(%dbglevel $fp); -use SMGLog (); +use DWeather::Logger; use Carp qw(cluck); %dbglevel = (); @@ -52,8 +52,6 @@ if (!defined $DB::VERSION) { ); } -dbginit(); - sub dbg { my $t = time; @@ -78,7 +76,7 @@ sub dbginit $SIG{__DIE__} = sub { dbg($@, Carp::longmess(@_)); }; } - $fp = SMGLog->new('debug', 'dat', 'd'); + $fp = DWeather::Logger->new('debug', 'log', 'd') unless $fp; } sub dbgclose diff --git a/DWeather/lib/DWeather/Log.pm b/DWeather/lib/DWeather/Logger.pm similarity index 95% rename from DWeather/lib/DWeather/Log.pm rename to DWeather/lib/DWeather/Logger.pm index 4d801be..b8233bf 100644 --- a/DWeather/lib/DWeather/Log.pm +++ b/DWeather/lib/DWeather/Logger.pm @@ -16,7 +16,7 @@ # modify it under the same terms as Perl itself. # -package SMGLog; +package DWeather::Logger; use IO::File; use Exporter; @@ -32,12 +32,11 @@ use vars qw($log $path); $log = undef; $path = './logs'; -init(); - # make the Log() export use this default file sub init { - $log = SMGLog->new("sys_log"); + my $default_dir = shift || 'sys_log'; + $log = __PACKAGE__->new($default_dir) unless $log; } # create a log object that contains all the useful info needed @@ -172,7 +171,9 @@ sub Log sub LogDbg { Log(@_); - Debug::dbg(@_) if Debug::isdbg('chan'); + DWeather::Debug::dbg(@_) if DWeather::Debug::isdbg('chan'); } +init(); + 1; diff --git a/DWeather/lib/DWeather/Serial.pm b/DWeather/lib/DWeather/Serial.pm index 44da24f..40ac160 100644 --- a/DWeather/lib/DWeather/Serial.pm +++ b/DWeather/lib/DWeather/Serial.pm @@ -4,7 +4,7 @@ use strict; -package Serial; +package DWeather::Serial; use POSIX qw(:termios_h); use Fcntl; @@ -87,4 +87,10 @@ sub close $self->SUPER::close; } +sub DESTROY +{ + my $self = shift; + $self->close; +} + 1; diff --git a/DWeather/lib/DWeather/Station.pm b/DWeather/lib/DWeather/Station.pm new file mode 100644 index 0000000..f9c45fe --- /dev/null +++ b/DWeather/lib/DWeather/Station.pm @@ -0,0 +1,26 @@ +# +# General device abtraction for DWeather interfaces +# +# + +package DWeather::Station; + +use strict; +use warnings; + +use base qw(DWeather::Serial); +use DWeather::Debug; + +# return a File::IO handle set up for serial operations + +sub new +{ + my $pkg = shift; + my $class = ref $pkg || $pkg; + my $device = shift || "/dev/ttyS0"; + + my $self = $class->SUPER::new($device, @_); + return $self; +} + +1; diff --git a/DWeather/lib/DWeather/Station/Vantage.pm b/DWeather/lib/DWeather/Station/Vantage.pm new file mode 100644 index 0000000..5f3749e --- /dev/null +++ b/DWeather/lib/DWeather/Station/Vantage.pm @@ -0,0 +1,35 @@ +# +# Vantage Pro 2 interface for DWeather +# +# + +package DWeather::Station::Vantage; + +use strict; +use warnings; + +use base qw(DWeather::Station); +use DWeather::Debug; +use AnyEvent; + +sub new +{ + my $pkg = shift; + my $class = ref $pkg || $pkg; + my $device = shift; + + my $d = $class->SUPER::new($device, 19200); + return $d; +} + +sub reset +{ + +} + +sub poll +{ + +} + +1; diff --git a/DWeather/lib/DWeather/Vantage.pm b/DWeather/lib/DWeather/Vantage.pm new file mode 100644 index 0000000..54cbb4a --- /dev/null +++ b/DWeather/lib/DWeather/Vantage.pm @@ -0,0 +1,30 @@ +# +# Vantage Pro 2 interface for DWeather +# +# + +use strict; +use warnings; + +use base qw(DWeather::Serial); +use AnyEvent; + +sub new +{ + my $pkg = shift; + my $class = ref $pkg || $pkg; + my $device = shift || '/dev/ttyS0'; + + my $self = $class->SUPER::new($device, 19200); + return $self; +} + +sub send +{ + +} + +sub run +{ + +} -- 2.43.0