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
26
iec1107.pm
26
iec1107.pm
@ -4,7 +4,7 @@
|
|||||||
# This is my first my perl module and these resources were a good kickstart
|
# This is my first my perl module and these resources were a good kickstart
|
||||||
# https://learn.perl.org/books/beginning-perl/
|
# https://learn.perl.org/books/beginning-perl/
|
||||||
# https://wiki.volkszaehler.org/hardware/channels/meters/power/eastron_drs155m
|
# 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
|
package iec1107; # we name our package iec1107 as this is the original protocol name
|
||||||
|
|
||||||
@ -15,8 +15,7 @@ use Carp;
|
|||||||
use Device::SerialPort;
|
use Device::SerialPort;
|
||||||
|
|
||||||
#for time conversion
|
#for time conversion
|
||||||
use POSIX::strptime qw( strptime );
|
use DateTime::Format::Strptime qw( strptime );
|
||||||
use POSIX qw{strftime};
|
|
||||||
|
|
||||||
#constants
|
#constants
|
||||||
our $SOH = chr(0x01);
|
our $SOH = chr(0x01);
|
||||||
@ -34,14 +33,14 @@ our $ENDCHARACTER = "!";
|
|||||||
|
|
||||||
our %drs110m_values = (
|
our %drs110m_values = (
|
||||||
#'<measurement>'=>[<address>,<scalingfunction>,'<unit>'],
|
#'<measurement>'=>[<address>,<scalingfunction>,'<unit>'],
|
||||||
'Voltage' =>[ 0,\&_scale_div_by_10, 'V'],
|
'Voltage' =>[ 0, \&_scale_div_by_10, 'V'],
|
||||||
'Current' =>[ 1,\&_scale_div_by_10, 'A'],
|
'Current' =>[ 1, \&_scale_div_by_10, 'A'],
|
||||||
'Frequency' =>[ 2,\&_scale_div_by_10, 'Hz'],
|
'Frequency' =>[ 2, \&_scale_div_by_10, 'Hz'],
|
||||||
'Active Power' =>[ 3, \&_scale_mul_by_10, 'W'],
|
'Active Power' =>[ 3, \&_scale_mul_by_10, 'W'],
|
||||||
'Reactive Power'=>[ 4, \&_scale_mul_by_10,'VAr'],
|
'Reactive Power'=>[ 4, \&_scale_mul_by_10,'VAr'],
|
||||||
'Apparent Power'=>[ 5, \&_scale_mul_by_10, 'VA'],
|
'Apparent Power'=>[ 5, \&_scale_mul_by_10, 'VA'],
|
||||||
'Active Energy' =>[10, \&_scale_1_to_1, 'Wh'],
|
'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'],
|
'Temperature' =>[32, \&_scale_to_temp, '°C'],
|
||||||
);
|
);
|
||||||
#actually there are more registers, but who cares about cosphi for example?!
|
#actually there are more registers, but who cares about cosphi for example?!
|
||||||
@ -177,16 +176,11 @@ sub _scale_1_to_1($){
|
|||||||
return $val;
|
return $val;
|
||||||
};
|
};
|
||||||
|
|
||||||
sub _scale_to_time($){
|
sub _scale_raw_time_to_datetime($){
|
||||||
my ($str) = @_;
|
my ($str) = @_;
|
||||||
my $fmt = "%y%m%d0%w%H%M%S";
|
my $fmt = "%y%m%d%w%H%M%S";
|
||||||
my @time = (POSIX::strptime($str,$fmt))[0..7];
|
my $dt = strptime($fmt, $str);
|
||||||
if (wantarray){
|
return $dt;
|
||||||
return @time;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return strftime("%Y-%m-%d %H:%M:%S",@time);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sub _scale_to_temp($){
|
sub _scale_to_temp($){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user