From 9bbf7153e759e32f9844ff157aa84c207457053d Mon Sep 17 00:00:00 2001 From: HomeAutoUser Date: Wed, 8 Jun 2022 13:02:55 +0200 Subject: [PATCH] Squashed commit of the following: commit 4806d2e781978b101cb018b67d115bc2fe125684 Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue Jun 7 22:21:10 2022 +0200 Bump fhem/fhem-controls-actions from 2.0.3 to 2.1.0 (#1105) Bumps [fhem/fhem-controls-actions](https://github.com/fhem/fhem-controls-actions) from 2.0.3 to 2.1.0. - [Release notes](https://github.com/fhem/fhem-controls-actions/releases) - [Commits](https://github.com/fhem/fhem-controls-actions/compare/v2.0.3...v2.1.0) --- updated-dependencies: - dependency-name: fhem/fhem-controls-actions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> commit 6bb37f9df7af4d80db60900eba1528732db16d44 Author: sidey79 <7968127+sidey79@users.noreply.github.com> Date: Tue May 31 17:12:21 2022 +0200 Basic funkbus support (#1102) * SD_ProtocolData.pm added funkbus protocol 119 from forum https://forum.fhem.de/index.php/topic,19065.msg1217972.html#msg1217972 * SD_Protocols.pm - sub mcBit2Funkbus added - sub mc2dmc added - Tests added --- .github/workflows/update.yml | 4 +- .github/workflows/version.yml | 4 +- FHEM/lib/SD_ProtocolData.pm | 23 ++++- FHEM/lib/SD_Protocols.pm | 113 ++++++++++++++++++++- controls_signalduino.txt | 4 +- t/FHEM/00_SIGNALduino/08_DeviceData_rmsg.t | 13 +-- t/SD_Protocols/02_mc2dmc.t | 40 ++++++++ t/SD_Protocols/02_mcBit2Funkbus.t | 45 ++++++++ 8 files changed, 228 insertions(+), 18 deletions(-) create mode 100644 t/SD_Protocols/02_mc2dmc.t create mode 100644 t/SD_Protocols/02_mcBit2Funkbus.t diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index c739c9571..cc33a9262 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -63,12 +63,12 @@ jobs: persist-credentials: false - name: update controls file (FHEM) if: needs.pr_check.outputs.result != 'true' - uses: fhem/fhem-controls-actions@v2.0.3 + uses: fhem/fhem-controls-actions@v2.1.0 with: filename: controls_signalduino.txt - name: update controls file (lib) if: needs.pr_check.outputs.result != 'true' - uses: fhem/fhem-controls-actions@v2.0.3 + uses: fhem/fhem-controls-actions@v2.1.0 with: filename: controls_signalduino.txt directory: FHEM/lib diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index 305ef1f6a..2c3dc57f6 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -154,11 +154,11 @@ jobs: find ./FHEM -name "$FILE" -exec cp $FPATH "{}" \; done - name: update controls file (FHEM) - uses: fhem/fhem-controls-actions@v2.0.3 + uses: fhem/fhem-controls-actions@v2.1.0 with: filename: controls_signalduino.txt - name: update controls file (lib) - uses: fhem/fhem-controls-actions@v2.0.3 + uses: fhem/fhem-controls-actions@v2.1.0 with: filename: controls_signalduino.txt directory: FHEM/lib diff --git a/FHEM/lib/SD_ProtocolData.pm b/FHEM/lib/SD_ProtocolData.pm index 3eea05a1b..cc53925ae 100644 --- a/FHEM/lib/SD_ProtocolData.pm +++ b/FHEM/lib/SD_ProtocolData.pm @@ -1,5 +1,5 @@ ########################################################################################################################################### -# $Id: SD_ProtocolData.pm 3.5.4 2022-04-16 09:19:56Z elektron-bbs $ +# $Id: SD_ProtocolData.pm 3.5.4 2022-05-30 20:10:51Z sidey79 $ # The file is part of the SIGNALduino project. # All protocol definitions are contained in this file. # @@ -86,7 +86,7 @@ package lib::SD_ProtocolData; use strict; use warnings; - our $VERSION = '1.44'; + our $VERSION = '1.45'; our %protocols = ( "0" => ## various weather sensors (500 | 9100) @@ -573,7 +573,7 @@ package lib::SD_ProtocolData; format => 'twostate', preamble => 'P13#', clientmodule => 'FLAMINGO', - #modulematch => '', + # => '', length_min => '24', length_max => '24', }, @@ -3177,6 +3177,23 @@ package lib::SD_ProtocolData; length_min => '24', length_max => '25', }, + + "119" => ## Funkbus + # + { + name => 'Funkbus', + comment => 'only Typ 43', + id => '119', + clockrange => [490,520], # min , max + format => 'manchester', + clientmodule => 'IFB', + #modulematch => '', + preamble => 'J', + length_min => '47', + length_max => '52', + method => \&lib::SD_Protocols::mcBit2Funkbus, + }, + ######################################################################## #### ### register informations from other hardware protocols #### #### diff --git a/FHEM/lib/SD_Protocols.pm b/FHEM/lib/SD_Protocols.pm index 6ad29e790..5faad333e 100644 --- a/FHEM/lib/SD_Protocols.pm +++ b/FHEM/lib/SD_Protocols.pm @@ -1,5 +1,5 @@ ################################################################################ -# $Id: SD_ProtocolData.pm 3.5.x 2022-01-30 10:19:30Z elektron-bbs $ +# $Id: SD_ProtocolData.pm 3.5.x 2022-05-30 20:10:51Z sidey79 $ # # The file is part of the SIGNALduino project # v3.5.x - https://github.com/RFD-FHEM/RFFHEM @@ -411,7 +411,118 @@ sub LengthInRange { return (1,q{}); } + ############################# package lib::SD_Protocols, test exists +=item mc2dmc() + +This function is a helper for remudlation of a manchester signal to a differental manchester signal afterwards + +Input: $object,$bitData (string) +Output: + string of converted bits + or array (-1,"Error message") + +=cut + +sub mc2dmc +{ + my $self = shift // carp 'Not called within an object' && return (0,'no object provided'); + my $bitData = shift // carp 'bitData must be perovided' && return (0,'no bitData provided'); + + my @bitmsg; + my $i; + + $bitData =~ s/1/lh/g; # 0 ersetzen mit low high + $bitData =~ s/0/hl/g; # 1 ersetzen durch high low ersetzen + + for ($i=1;$icheckProperty($id,'length_min',-1) ); + return (-1,' message is to long') if (defined $self->getProperty($id,'length_max' ) && $mcbitnum > $self->getProperty($id,'length_max') ); + + $self->_logging( qq[lib/mcBitFunkbus, $name Funkbus: raw=$bitData], 5 ); + + $bitData =~ s/1/lh/g; # 0 ersetzen mit low high + $bitData =~ s/0/hl/g; # 1 ersdetzen durch high low ersetzen + + my $s_bitmsg = $self->mc2dmc($bitData); # Convert to differential manchester + + if ($id == 119) { + my $pos = index($s_bitmsg,'01100'); + if ($pos >= 0 && $pos < 5) { + $s_bitmsg = '001' . substr($s_bitmsg,$pos); + return (-1,'wrong bits at begin') if (length($s_bitmsg) < 48); + } else { + return (-1,'wrong bits at begin'); + } + } else { + $s_bitmsg = q[0] . $s_bitmsg; + } + + my $data; + my $xor = 0; + my $chk = 0; + my $p = 0; # parity + my $hex = q[]; + for (my $i=0; $i<6;$i++) { # checksum + $data = oct(q[b].substr($s_bitmsg, $i*8,8)); + $hex .= sprintf('%02X', $data); + if ($i<5) { + $xor ^= $data; + } else { + $chk = $data & 0x0F; + $xor ^= $data & 0xE0; + $data &= 0xF0; + } + while ($data) { # parity + $p^=($data & 1); + $data>>=1; + } + } + return (-1,'parity error') if ($p == 1); + + my $xor_nibble = (($xor & 0xF0) >> 4) ^ ($xor & 0x0F); + my $result = 0; + $result = ($xor_nibble & 0x8) ? $result ^ 0xC : $result; + $result = ($xor_nibble & 0x4) ? $result ^ 0x2 : $result; + $result = ($xor_nibble & 0x2) ? $result ^ 0x8 : $result; + $result = ($xor_nibble & 0x1) ? $result ^ 0x3 : $result; + + return (-1,'checksum error') if ($result != $chk); + + $self->_logging( qq[lib/mcBitFunkbus, $name Funkbus: len=]. length($s_bitmsg).q[ bit49=].substr($s_bitmsg,48,1).qq[ parity=$p res=$result chk=$chk msg=$s_bitmsg hex=$hex], 4 ); + + return (1,$hex); +} + + + =item MCRAW() This function is desired to be used as a default output helper for manchester signals. diff --git a/controls_signalduino.txt b/controls_signalduino.txt index 705aa1cb5..025c1f798 100644 --- a/controls_signalduino.txt +++ b/controls_signalduino.txt @@ -14,5 +14,5 @@ UPD 2022-04-15_20:58:20 35384 FHEM/14_SD_WS09.pm UPD 2020-04-13_23:15:56 14325 FHEM/14_SD_WS_Maverick.pm UPD 2021-08-11_21:38:30 37904 FHEM/41_OREGON.pm UPD 2020-12-17_23:16:30 15582 FHEM/90_SIGNALduino_un.pm -UPD 2022-04-17_21:56:43 229099 FHEM/lib/SD_ProtocolData.pm -UPD 2022-03-07_20:25:23 75991 FHEM/lib/SD_Protocols.pm +UPD 2022-05-30_22:10:08 229520 FHEM/lib/SD_ProtocolData.pm +UPD 2022-05-30_19:35:15 79342 FHEM/lib/SD_Protocols.pm diff --git a/t/FHEM/00_SIGNALduino/08_DeviceData_rmsg.t b/t/FHEM/00_SIGNALduino/08_DeviceData_rmsg.t index b4196d076..cb94d6569 100644 --- a/t/FHEM/00_SIGNALduino/08_DeviceData_rmsg.t +++ b/t/FHEM/00_SIGNALduino/08_DeviceData_rmsg.t @@ -69,21 +69,18 @@ InternalTimer(time()+1, sub { my @TestList = ( { testname => 'Test with pre-release SD_Device_ProtocolList', - url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/pre-release/FHEM/lib/SD_Device_ProtocolList.json', - todo => 'Checking with pre-release Version of SD_Device_ProtocolList which can fail', + url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/pre-release/FHEM/lib/SD_Device_ProtocolList.json', + todo => 'Checking with pre-release Version of SD_Device_ProtocolList which can fail', }, { testname => 'Test with master SD_Device_ProtocolList', - url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/master/FHEM/lib/SD_Device_ProtocolList.json', - todo => 'Checking with master Version of SD_Device_ProtocolList which can fail', + url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/master/FHEM/lib/SD_Device_ProtocolList.json', + todo => 'Checking with master Version of SD_Device_ProtocolList which can fail', }, { testname => 'Test with patched SD_Device_ProtocolList', - url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/patch-fixTests/FHEM/lib/SD_Device_ProtocolList.json', + url => 'https://raw.githubusercontent.com/RFD-FHEM/SIGNALduino_TOOL/patch-fixTests/FHEM/lib/SD_Device_ProtocolList.json', }, - - - ); diff --git a/t/SD_Protocols/02_mc2dmc.t b/t/SD_Protocols/02_mc2dmc.t new file mode 100644 index 000000000..aea363368 --- /dev/null +++ b/t/SD_Protocols/02_mc2dmc.t @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test2::V0; +use lib::SD_Protocols; +use Test2::Tools::Compare qw{is}; + +plan(3); + +my ($rcode,$bitresult); +my $Protocols = +new lib::SD_Protocols( filetype => 'json', filename => './t/SD_Protocols/test_protocolData.json' ); + + + +subtest 'mc2dmc without arguments' => sub { + plan(1); + + my $bitData='110010'; + $bitresult=$Protocols->mc2dmc(); + is($bitresult,q[no bitData provided],q[check result mc2dmc]); +}; + +subtest 'mc2dmc 1001 => 010' => sub { + plan(1); + + my $bitData='1001'; + $bitresult=$Protocols->mc2dmc($bitData); + is($bitresult,q[010],q[check result mc2dmc]); +}; + + +subtest 'mc2dmc 110010 => 10100' => sub { + plan(1); + + my $bitData='110010'; + $bitresult=$Protocols->mc2dmc($bitData); + is($bitresult,q[10100],q[check result mc2dmc]); +}; diff --git a/t/SD_Protocols/02_mcBit2Funkbus.t b/t/SD_Protocols/02_mcBit2Funkbus.t new file mode 100644 index 000000000..357aa12e3 --- /dev/null +++ b/t/SD_Protocols/02_mcBit2Funkbus.t @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test2::V0; +use lib::SD_Protocols; +use Test2::Tools::Compare qw{is}; + +plan(3); + +my $id=119; +my ($rcode,$hexresult); +my $Protocols = +new lib::SD_Protocols( filetype => 'json', filename => './t/SD_Protocols/test_protocolData.json' ); + +# Mock protocol for this test +$Protocols->{_protocols}->{119}{length_min} = 47; +$Protocols->{_protocols}->{119}{length_max} = 52; + +subtest 'mcBit2Funkbus good message' => sub { + plan(2); + + my $bitData='1001110101001111001111110111010101010101101000000000'; + ($rcode,$hexresult)=$Protocols->mcBit2Funkbus(q[some_name],$bitData,$id,length $bitData); + is($rcode,1,q[check returncode for mcBit2Funkbus]); + is($hexresult,q[2C175F30008F],q[check result mcBit2Funkbus]); +}; + +subtest 'mcBit2Funkbus wrong parity' => sub { + plan(2); + + my $bitData='100111010100111100111111011101010101010110110000000'; + ($rcode,$hexresult)=$Protocols->mcBit2Funkbus(q[some_name],$bitData,$id,length $bitData); + is($rcode,-1,q[check returncode for mcBit2Funkbus]); + is($hexresult,q[parity error],q[check result mcBit2Funkbus]); +}; + +subtest 'mcBit2Funkbus wrong checksum' => sub { + plan(2); + + my $bitData='1001110101001111101111110111010101010101101000000000'; + ($rcode,$hexresult)=$Protocols->mcBit2Funkbus(q[some_name],$bitData,$id,length $bitData); + is($rcode,-1,q[check returncode for mcBit2Funkbus]); + is($hexresult,q[checksum error],q[check result mcBit2Funkbus]); +}; \ No newline at end of file