Feat: Use datetime for time conversion
drop dependency Posix::strptime in favor of Datetime::Format::Strptime Signed-off-by: Patrick Menschel <menschel.p@posteo.de>
This commit is contained in:
parent
f67726828b
commit
66b3041f5b
20
iec1107.pm
20
iec1107.pm
@ -4,7 +4,7 @@
|
||||
# This is my first my perl module and these resources were a good kickstart
|
||||
# https://learn.perl.org/books/beginning-perl/
|
||||
# https://wiki.volkszaehler.org/hardware/channels/meters/power/eastron_drs155m
|
||||
# Menschel (C) 2020
|
||||
# Menschel (C) 2020-2021
|
||||
|
||||
package iec1107; # we name our package iec1107 as this is the original protocol name
|
||||
|
||||
@ -15,8 +15,7 @@ use Carp;
|
||||
use Device::SerialPort;
|
||||
|
||||
#for time conversion
|
||||
use POSIX::strptime qw( strptime );
|
||||
use POSIX qw{strftime};
|
||||
use DateTime::Format::Strptime qw( strptime );
|
||||
|
||||
#constants
|
||||
our $SOH = chr(0x01);
|
||||
@ -41,7 +40,7 @@ our %drs110m_values = (
|
||||
'Reactive Power'=>[ 4, \&_scale_mul_by_10,'VAr'],
|
||||
'Apparent Power'=>[ 5, \&_scale_mul_by_10, 'VA'],
|
||||
'Active Energy' =>[10, \&_scale_1_to_1, 'Wh'],
|
||||
'Time' =>[31, \&_scale_to_time, ''],
|
||||
'Time' =>[31, \&_scale_raw_time_to_datetime, ''],
|
||||
'Temperature' =>[32, \&_scale_to_temp, '°C'],
|
||||
);
|
||||
#actually there are more registers, but who cares about cosphi for example?!
|
||||
@ -177,16 +176,11 @@ sub _scale_1_to_1($){
|
||||
return $val;
|
||||
};
|
||||
|
||||
sub _scale_to_time($){
|
||||
sub _scale_raw_time_to_datetime($){
|
||||
my ($str) = @_;
|
||||
my $fmt = "%y%m%d0%w%H%M%S";
|
||||
my @time = (POSIX::strptime($str,$fmt))[0..7];
|
||||
if (wantarray){
|
||||
return @time;
|
||||
}
|
||||
else{
|
||||
return strftime("%Y-%m-%d %H:%M:%S",@time);
|
||||
};
|
||||
my $fmt = "%y%m%d%w%H%M%S";
|
||||
my $dt = strptime($fmt, $str);
|
||||
return $dt;
|
||||
};
|
||||
|
||||
sub _scale_to_temp($){
|
||||
|
Loading…
x
Reference in New Issue
Block a user