Device-WxM2
view release on metacpan or search on metacpan
}
$self->{avgOutTemp} = sprintf("%02.1f", $outTemp);
$self->{loTemp} = sprintf("%02.1f", $outTempLo);
$self->{hiTemp} = sprintf("%02.1f", $outTempHi);
$self->{avgInTemp} = sprintf("%02.1f",$inTemp);
$self->{baro} = sprintf("%5.3f", $baro);
$self->{avgWindSpeed} = $wind;
$self->{avgWindDir} = $avgWindDir;
$self->{windGust} = $windGust;
$self->{rainInPrd} = sprintf("%3.2f", $rainInPrd);
$self->{inHum} = $inHum;
$self->{outHum} = $outHum;
$self->{date} = $mon . "/" . sprintf("%02d",$day);
$self->{time} = $hour . ":" . sprintf("%02d", $min);
$self->{thi} = sprintf "%5.1f", $outTHI;
$self->{hiTHI} = sprintf "%5.1f", $outTHIHi;
$self->{windChillLo} = sprintf "%5.1f", $windChillLo;
# Calculate Dewpoint. Don't return it with array, just store it in class vars.
my $dpt = $self->calcDewPoint();
$self->{avgDewpoint} = sprintf "%4.1f", $dpt;
return ($inTemp, $outTemp, $outTempHi, $outTempLo, $baro,
$wind, $avgWindDir, $windGust, $rainInPrd, $inHum,
$outHum, $mon, $day, $hour, $min, $outTHI, $outTHIHi,
$windChill, $windChillLo);
} else { # get_ack failed
# print results
my($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $wxPort->status;
printf "OutBytes=%d\n",$OutBytes;
printf "InBytes=%d\n",$InBytes;
return 0;
}
}
sub batchRetrieveArchives {
my ($self, $num, $file) = @_;
my $lastPtr = $self->getLastPtr;
my $sizeOfBatch = 21 * $num;
# 21 bytes does not divide evenly into 32K bytes. The last valid
# pointer address is 0x7fe3. The next pointer would be 0x7ff8,
# but it would not have the full 21 bytes before wrapping to
# address 0x0. So an additional 8 bytes are subtracted when
# calculating the wrap address.
my $firstPtr;
if ($sizeOfBatch > $lastPtr) {
$firstPtr = ($lastPtr - $sizeOfBatch - 8) & 0x7fff;
} else {
$firstPtr = $lastPtr - $sizeOfBatch;
}
printf "firstPtr=%d lastPtr=%d\n", $firstPtr, $lastPtr;
return $self->updateArchiveFromPtr($firstPtr, $file);
}
sub updateArchiveFromPtr {
my ($self, $lastArchivedPtr, $file) = @_;
my $i;
my $rdFailed = 0;
my $newPtrHex = $self->getNewPtr();
return 0 unless defined $newPtrHex;
my $newPtr = hex($newPtrHex) - 21;
$lastArchivedPtr += 21;
if ($lastArchivedPtr > 0x7FFF) {
$lastArchivedPtr -= 0x7FFF;
}
# Push $file using local
local $self->{archiveLogFile} = $file;
printf "Update from %x to %x\n", $lastArchivedPtr, $newPtr
if $DEBUG > 0;
# test for address wrapping here
if ($newPtr < $lastArchivedPtr) {
# Last valid ptr addr = 0x7fe3. 0x7ff8 is NOT valid.
for ($i=$lastArchivedPtr; $i < 0x7FF8; $i+=21) {
unless ($self->getArcImg($i)) {
$rdFailed = 1;
last;
}
$self->archiveCurImage();
printf "Archived address %x\n",$i if $DEBUG > 0;
}
$lastArchivedPtr = 0;
}
return 0 if $rdFailed;
for ($i=$lastArchivedPtr; $i <= $newPtr; $i+=21) {
$self->getArcImg($i);
#unless ($self->getArcImg($i)) {
# return 0;
#}
$self->archiveCurImage();
printf "Archived address %x\n",$i if $DEBUG > 0;
}
return 1;
}
##
## `getSensorImage' enables a continuous streaming of 18 byte chunks of
## weather data from the Davis Wx Station. I've found this stream to be
## very easy to get out of sync, so this funcion read a single 18 byte chunk,
## stops the streaming, and flushes the serial Rx buffer
##
sub getSensorImage {
##### LOOP ######
# Monitor, Wizard, and Perception Sensor Image:
# start of block 1 byte
# inside temperature 2 bytes
# outside temperature 2 bytes
# wind speed 1 byte
# wind direction 2 bytes
# barometer 2 bytes
# inside humidity 1 byte
# outside humidity 1 byte
( run in 3.534 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )