Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace round main with round in FHEM::Core::Utils::Math #1154

Merged
merged 4 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions FHEM/00_SIGNALduino.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $Id: 00_SIGNALduino.pm 3.5.5 2023-01-15 02:03:31Z sidey79 $
# $Id: 00_SIGNALduino.pm 3.5.5 2023-01-23 17:24:05Z sidey79 $
# v3.5.5 - https://github.com/RFD-FHEM/RFFHEM/tree/master
# The module is inspired by the FHEMduino project and modified in serval ways for processing the incoming messages
# see http://www.fhemwiki.de/wiki/SIGNALDuino
Expand All @@ -15,6 +15,7 @@ package main;
use strict;
use warnings;
use Storable qw(dclone);
use FHEM::Core::Utils::Math;
#use version 0.77; our $VERSION = version->declare('v3.5.5');

my $missingModulSIGNALduino = ' ';
Expand All @@ -37,11 +38,11 @@ use List::Util qw(first);

#$| = 1; #Puffern abschalten, Hilfreich fuer PEARL WARNINGS Search

#use Math::Round qw();



use constant {
SDUINO_VERSION => '3.5.5+20230115', # Datum wird automatisch bei jedem pull request aktualisiert
SDUINO_VERSION => '3.5.5+20230123', # Datum wird automatisch bei jedem pull request aktualisiert
SDUINO_INIT_WAIT_XQ => 1.5, # wait disable device
SDUINO_INIT_WAIT => 2,
SDUINO_INIT_MAXRETRY => 3,
Expand Down Expand Up @@ -389,11 +390,6 @@ sub SIGNALduino_Define {
DevIo_CloseDev($hash);
my $name = $a[0];

if (!exists &round)
{
Log3 $name, 1, "$name: Define, Signalduino can't be activated (sub round not found). Please update Fhem via update command";
return ;
}

my $dev = $a[2];
#Debug "dev: $dev" if ($debug);
Expand Down Expand Up @@ -861,7 +857,7 @@ sub SIGNALduino_Set_sendMsg {
if (defined($hash->{protocolObject}->getProperty($protocol,'format')) && $hash->{protocolObject}->getProperty($protocol,'format') eq 'manchester')
{
$clock += $_ for( @{$hash->{protocolObject}->getProperty($protocol,'clockrange')} );
$clock = round($clock/2,0);
$clock = FHEM::Core::Utils::Math::round($clock/2,0);

my $intro;
my $outro;
Expand Down Expand Up @@ -1218,7 +1214,7 @@ sub SIGNALduino_CheckccConfResponse {

if ($msg2 !~ /Modulation:\sASK\/OOK/) {
$msg2 .= ", Syncmod: ".$syncmod[($r{"12"})&7]; #Syncmod | Register 0x12
$msg2 .= ", Deviation: ".round((8+($r{"15"}&7))*(2**(($r{"15"}>>4)&7)) *26000/(2**17),2) .' kHz'; #Deviation | Register 0x15
$msg2 .= ", Deviation: ".FHEM::Core::Utils::Math::round((8+($r{"15"}&7))*(2**(($r{"15"}>>4)&7)) *26000/(2**17),2) .' kHz'; #Deviation | Register 0x15
}

readingsBeginUpdate($_[0]);
Expand Down Expand Up @@ -2379,7 +2375,7 @@ sub SIGNALduino_Parse_MS {
#Debug 'List of pattern:';
my $clockabs= $msg_parts{pattern}{$msg_parts{clockidx}};
return if ($clockabs == 0);
$patternList{$_} = round($msg_parts{pattern}{$_}/$clockabs,1) for keys %{$msg_parts{pattern}};
$patternList{$_} = FHEM::Core::Utils::Math::round($msg_parts{pattern}{$_}/$clockabs,1) for keys %{$msg_parts{pattern}};

#Debug Dumper(\%patternList);

Expand Down Expand Up @@ -2607,10 +2603,10 @@ sub SIGNALduino_Parse_MU {
(my $count_changes,$rawData,my %patternListRaw_tmp) = $method->($name,$id,$rawData,%patternListRaw);
use strict "refs";

%patternList = map { $_ => round($patternListRaw_tmp{$_}/$clockabs,1) } keys %patternListRaw_tmp;
%patternList = map { $_ => FHEM::Core::Utils::Math::round($patternListRaw_tmp{$_}/$clockabs,1) } keys %patternListRaw_tmp;
}
} else {
%patternList = map { $_ => round($patternListRaw{$_}/$clockabs,1) } keys %patternListRaw;
%patternList = map { $_ => FHEM::Core::Utils::Math::round($patternListRaw{$_}/$clockabs,1) } keys %patternListRaw;
}

Debug qq[Testing against protocol id $id -> ]. $hash->{protocolObject}->getProperty($id,'name') if ($debug);
Expand Down Expand Up @@ -4180,7 +4176,7 @@ sub CalcDataRate {
$DRATE_E = int($DRATE_E);

my $DRATE_M = (($dr*1000) * (2**28) / (26000000 * (2**$DRATE_E))) - 256;
my $DRATE_Mr = main::round($DRATE_M,0);
my $DRATE_Mr = FHEM::Core::Utils::Math::round($DRATE_M,0);
$DRATE_M = int($DRATE_M);

my $datarate0 = ( ((256+$DRATE_M)*(2**($DRATE_E & 15 )))*26000000/(2**28) / 1000);
Expand Down
5 changes: 3 additions & 2 deletions FHEM/14_SD_AS.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##############################################
# $Id: 14_SD_AS.pm 350 2023-01-09 19:54:08Z sidey79 $
# $Id: 14_SD_AS.pm 350 2023-01-23 17:24:05Z sidey79 $
# The file is part of the SIGNALduino project
# see http://www.fhemwiki.de/wiki/SIGNALduino
# and was created to provide support for self build sensors.
Expand All @@ -15,6 +15,7 @@ use strict;
use warnings;
use POSIX;
use FHEM::Meta;
use FHEM::Core::Utils::Math;

#####################################
sub
Expand Down Expand Up @@ -205,7 +206,7 @@ SD_AS_Parse
$batteryVoltage = $Sigval;
# $bat = (hex(substr($msg,7,2))>>1)&3; # ???
$bat = hex(substr($rawData,2,2))>>6;
$Sigval = round($Sigval / 1000, 2); # Vcc is send in millivolts
$Sigval = FHEM::Core::Utils::Math::round($Sigval / 1000, 2); # Vcc is send in millivolts
$val = "V: $Sigval";
}
elsif ($model eq "raw") { # 10
Expand Down
33 changes: 18 additions & 15 deletions FHEM/14_SD_WS.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $Id: 14_SD_WS.pm 26982 2023-01-13 19:55:16Z elektron-bbs $
# $Id: 14_SD_WS.pm 26982 2023-01-23 17:24:05Z sidey79 $
#
# The purpose of this module is to support serval
# weather sensors which use various protocol
Expand Down Expand Up @@ -47,6 +47,8 @@
# 23.05.2022 neues Protokoll 120: Wetterstation TFA 35.1077.54.S2 mit 30.3151 (Thermo/Hygro-Sender), 30.3152 (Regenmesser), 30.3153 (Windmesser)
# 11.06.2022 neues Protokoll 122: TM40, Wireless Grill-, Meat-, Roasting-Thermometer with 4 Temperature Sensors
# 06.01.2023 neues Protokoll 123: Inkbird IBS-P01R Pool Thermometer, Inkbird ITH-20R (not tested)
# 21.01.2023 use round from package FHEM::Core::Utils::Math;


package main;

Expand All @@ -56,6 +58,7 @@ use strict;
use warnings;
use Carp qw(carp);
use FHEM::Meta;
use FHEM::Core::Utils::Math;

# Forward declarations
sub SD_WS_LFSR_digest8_reflect;
Expand Down Expand Up @@ -386,7 +389,7 @@ sub SD_WS_Parse {
}
},
id => sub {my (undef,$bitData) = @_; return SD_WS_binaryToNumber($bitData,0,9); }, # id
temp => sub {my (undef,$bitData) = @_; return round(((SD_WS_binaryToNumber($bitData,22,25)*256 + SD_WS_binaryToNumber($bitData,18,21)*16 + SD_WS_binaryToNumber($bitData,14,17)) - 1220) * 5 / 90.0 , 1); }, #temp
temp => sub {my (undef,$bitData) = @_; return FHEM::Core::Utils::Math::round(((SD_WS_binaryToNumber($bitData,22,25)*256 + SD_WS_binaryToNumber($bitData,18,21)*16 + SD_WS_binaryToNumber($bitData,14,17)) - 1220) * 5 / 90.0 , 1); }, #temp
hum => sub {my (undef,$bitData) = @_; return (SD_WS_binaryToNumber($bitData,30,33)*16 + SD_WS_binaryToNumber($bitData,26,29)); }, #hum
channel => sub {my (undef,$bitData) = @_; return (SD_WS_binaryToNumber($bitData,12,13)+1 ); }, # channel
bat => sub {my (undef,$bitData) = @_; return substr($bitData,34,1) eq "0" ? "ok" : "low";}, # other or modul orginal
Expand Down Expand Up @@ -452,7 +455,7 @@ sub SD_WS_Parse {
sendmode => sub {my (undef,$bitData) = @_; return substr($bitData,12,1) eq "1" ? "manual" : "auto";},
bat => sub {my (undef,$bitData) = @_; return substr($bitData,13,1) eq "1" ? "low" : "ok";},
trend => sub {my (undef,$bitData) = @_; return ('consistent', 'rising', 'falling', 'unknown')[SD_WS_binaryToNumber($bitData,14,15)];},
temp => sub {my (undef,$bitData) = @_; return round(((SD_WS_binaryToNumber($bitData,16,27)) - 1220) * 5 / 90.0 , 1); },
temp => sub {my (undef,$bitData) = @_; return FHEM::Core::Utils::Math::round(((SD_WS_binaryToNumber($bitData,16,27)) - 1220) * 5 / 90.0 , 1); },
hum => sub {my (undef,$bitData) = @_; return (SD_WS_binaryToNumber($bitData,28,31) * 10) + (SD_WS_binaryToNumber($bitData,32,35));},
channel => sub {my (undef,$bitData) = @_; return (SD_WS_binaryToNumber($bitData,38,39) );},
},
Expand Down Expand Up @@ -612,7 +615,7 @@ sub SD_WS_Parse {
id => sub {my (undef,$bitData) = @_; return SD_WS_binaryToNumber($bitData,8,15); }, # random id
bat => sub {my (undef,$bitData) = @_; return SD_WS_binaryToNumber($bitData,16) eq "1" ? "low" : "ok";}, # bat?
channel => sub {my (undef,$bitData) = @_; return (SD_WS_binaryToNumber($bitData,17,19) + 1 ); }, # channel
temp => sub {my (undef,$bitData) = @_; return round((SD_WS_binaryToNumber($bitData,20,31)-720)*0.0556,1); }, # temp
temp => sub {my (undef,$bitData) = @_; return FHEM::Core::Utils::Math::round((SD_WS_binaryToNumber($bitData,20,31)-720)*0.0556,1); }, # temp
hum => sub {my ($rawData,$bitData) = @_; return substr($rawData,1,1) eq "5" ? (SD_WS_binaryToNumber($bitData,32,39)) : 0;}, # hum
} ,
84 =>
Expand Down Expand Up @@ -697,7 +700,7 @@ sub SD_WS_Parse {
winddir => sub {my (undef,$bitData) = @_;
if (substr($bitData,30,2) eq "10") { # message 2 winddirection
$winddir = SD_WS_binaryToNumber($bitData,44,55);
return ($winddir * 1, $winddirtxtar[round(($winddir / 22.5),0)]);
return ($winddir * 1, $winddirtxtar[FHEM::Core::Utils::Math::round(($winddir / 22.5),0)]);
} else {
return;
}
Expand Down Expand Up @@ -798,7 +801,7 @@ sub SD_WS_Parse {
$rawTemp = SD_WS_binaryToNumber($bitData,8,21);
my $tempFh = $rawTemp / 20 - 90; # Grad Fahrenheit
Log3 $name, 4, "$name: SD_WS_106_T tempraw = $rawTemp, temp = $tempFh Fahrenheit";
return (round((($tempFh - 32) * 5 / 9) , 1)); # Grad Celsius
return (FHEM::Core::Utils::Math::round((($tempFh - 32) * 5 / 9) , 1)); # Grad Celsius
},
crcok => sub {return 1;}, # CRC test method does not exist
} ,
Expand All @@ -825,7 +828,7 @@ sub SD_WS_Parse {
model => 'SD_WS_107_H',
prematch => sub { ($rawData,undef) = @_; return 1 if ($rawData =~ /^51[0-9A-F]{16}[F]{6}/); },
id => sub { my ($rawData,undef) = @_; return substr($rawData,2,6); },
batVoltage => sub { my (undef,$bitData) = @_; return round(SD_WS_binaryToNumber($bitData,35,39) / 10 , 1); },
batVoltage => sub { my (undef,$bitData) = @_; return FHEM::Core::Utils::Math::round(SD_WS_binaryToNumber($bitData,35,39) / 10 , 1); },
adc => sub { my (undef,$bitData) = @_; return SD_WS_binaryToNumber($bitData,62,71); },
hum => sub { my ($rawData,undef) = @_; return hex(substr($rawData,12,2)); },
crcok => sub { my $rawData = shift;
Expand Down Expand Up @@ -981,7 +984,7 @@ sub SD_WS_Parse {
return ($rawRainCounterMessage + 10) * 0.1;
}
},
temp => sub { my (undef,$bitData) = @_; return round(((SD_WS_binaryToNumber($bitData,48,55) * 256 + SD_WS_binaryToNumber($bitData,40,47)) - 1220) * 5 / 90.0 , 1); },
temp => sub { my (undef,$bitData) = @_; return FHEM::Core::Utils::Math::round(((SD_WS_binaryToNumber($bitData,48,55) * 256 + SD_WS_binaryToNumber($bitData,40,47)) - 1220) * 5 / 90.0 , 1); },
crcok => sub { my (undef,$bitData) = @_;
my $sum = 0;
for (my $n = 0; $n < 56; $n += 8) {
Expand Down Expand Up @@ -1056,13 +1059,13 @@ sub SD_WS_Parse {
$rawTemp = SD_WS_binaryToNumber($bitData,12,13) * 256 + SD_WS_binaryToNumber($bitData,16,23);
my $tempFh = $rawTemp - 90; # Grad Fahrenheit
Log3 $name, 4, "$name: SD_WS_113_T tempraw1 = $rawTemp, temp1 = $tempFh Grad Fahrenheit";
return (round((($tempFh - 32) * 5 / 9) , 0)); # Grad Celsius
return (FHEM::Core::Utils::Math::round((($tempFh - 32) * 5 / 9) , 0)); # Grad Celsius
},
temp2 => sub { my (undef,$bitData) = @_;
$rawTemp = SD_WS_binaryToNumber($bitData,14,15) * 256 + SD_WS_binaryToNumber($bitData,24,31);
my $tempFh = $rawTemp - 90; # Grad Fahrenheit
Log3 $name, 4, "$name: SD_WS_113_T tempraw2 = $rawTemp, temp2 = $tempFh Grad Fahrenheit";
return (round((($tempFh - 32) * 5 / 9) , 0)); # Grad Celsius
return (FHEM::Core::Utils::Math::round((($tempFh - 32) * 5 / 9) , 0)); # Grad Celsius
},
crcok => sub {return 1;}, # Check could not be determined yet.
} ,
Expand Down Expand Up @@ -1129,7 +1132,7 @@ sub SD_WS_Parse {
winddir => sub {my ($rawData,undef) = @_;
return if (substr($rawData,12,1) ne '1' || substr($rawData,20,3) !~ m/^\d+$/xms); # only weather station
$winddir = substr($rawData,20,3);
return ($winddir * 1, $winddirtxtar[round(($winddir / 22.5),0)]);
return ($winddir * 1, $winddirtxtar[FHEM::Core::Utils::Math::round(($winddir / 22.5),0)]);
},
temp => sub {my ($rawData,$bitData) = @_;
# uncoverable condition right
Expand All @@ -1142,7 +1145,7 @@ sub SD_WS_Parse {
$rawTemp *= -1; # Bresser 3in1
}
}
return round($rawTemp,1);
return FHEM::Core::Utils::Math::round($rawTemp,1);
},
hum => sub {my ($rawData,undef) = @_;
# uncoverable condition right
Expand Down Expand Up @@ -1276,7 +1279,7 @@ sub SD_WS_Parse {
id => sub {my ($rawData,undef) = @_; return substr($rawData,4,4); },
winddir => sub {my ($rawData,undef) = @_;
$winddir = substr($rawData,8,3);
return ($winddir * 1, $winddirtxtar[round(($winddir / 22.5),0)]);
return ($winddir * 1, $winddirtxtar[FHEM::Core::Utils::Math::round(($winddir / 22.5),0)]);
},
batChange => sub {my (undef,$bitData) = @_; return substr($bitData,52,1) eq '0' ? '1' : '0';},
windgust => sub {my ($rawData,undef) = @_; return substr($rawData,14,3) * 0.1;},
Expand Down Expand Up @@ -1335,11 +1338,11 @@ sub SD_WS_Parse {
},
windspeed => sub {my (undef,$bitData) = @_;
return if (substr($bitData,19,1) eq '1');
return round((SD_WS_binaryToNumber($bitData,39,46) / 3.0),1);
return FHEM::Core::Utils::Math::round((SD_WS_binaryToNumber($bitData,39,46) / 3.0),1);
},
windgust => sub {my (undef,$bitData) = @_;
return if (substr($bitData,19,1) eq '1');
return round((SD_WS_binaryToNumber($bitData,47,54) / 3.0),1);
return FHEM::Core::Utils::Math::round((SD_WS_binaryToNumber($bitData,47,54) / 3.0),1);
},
rawRainCounter => sub {my (undef,$bitData) = @_;
return if (substr($bitData,19,1) eq '1');
Expand Down
Loading