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

Basic funkbus support #1102

Merged
merged 26 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
83870dd
SD_ProtocolData.pm
sidey79 May 18, 2022
edcd4df
Automatic updated controls and CHANGED
actions-user May 18, 2022
49fdb7b
Update Versiondate
actions-user May 18, 2022
2c88dc5
Merge branch 'master' into funkbus
sidey79 May 18, 2022
8e09baf
Update Versiondate
actions-user May 18, 2022
3684562
SD_Protocols.pm
sidey79 May 21, 2022
c55b2ff
Merge branch 'funkbus' of https://github.com/RFD-FHEM/RFFHEM into fun…
sidey79 May 21, 2022
ca10761
SD_Protocols.pm
sidey79 May 21, 2022
a828fab
Update Versiondate
actions-user May 21, 2022
8a7134c
08_DeviceData_rmsg.t
sidey79 May 22, 2022
5403cfd
SD_Protocols.pm
sidey79 May 22, 2022
b659c3c
SD_Protocols.pm
sidey79 May 22, 2022
92f86e8
Merge branch 'funkbus' of https://github.com/RFD-FHEM/RFFHEM into fun…
sidey79 May 22, 2022
aa26b0c
Update Versiondate
actions-user May 22, 2022
2dd2296
Merge branch 'master' into funkbus
sidey79 May 22, 2022
7e85e24
Update Versiondate
actions-user May 22, 2022
aec2120
SD_Protocols.pm
sidey79 May 27, 2022
26ffc63
Merge branch 'funkbus' of https://github.com/RFD-FHEM/RFFHEM into fun…
sidey79 May 27, 2022
08aa0c0
Update Versiondate
actions-user May 27, 2022
17f48be
SD_Protocols.pm
sidey79 May 27, 2022
5068ce7
Merge branch 'funkbus' of https://github.com/RFD-FHEM/RFFHEM into fun…
sidey79 May 27, 2022
2672874
Update Versiondate
actions-user May 27, 2022
c699a46
Merge branch 'master' into funkbus
sidey79 May 30, 2022
c480da5
Update Versiondate
actions-user May 30, 2022
36ae953
SD_ProtcolData.pm
sidey79 May 30, 2022
0abe448
Update Versiondate
actions-user May 30, 2022
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
23 changes: 20 additions & 3 deletions FHEM/lib/SD_ProtocolData.pm
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -573,7 +573,7 @@ package lib::SD_ProtocolData;
format => 'twostate',
preamble => 'P13#',
clientmodule => 'FLAMINGO',
#modulematch => '',
# => '',
length_min => '24',
length_max => '24',
},
Expand Down Expand Up @@ -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 #### ####

Expand Down
113 changes: 112 additions & 1 deletion FHEM/lib/SD_Protocols.pm
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;$i<length($bitData)-1;$i+=2)
{
push (@bitmsg, (substr($bitData,$i,1) eq substr($bitData,$i+1,1)) ? 0 : 1); # demodulated differential manchester
}
return join "", @bitmsg ; # demodulated differential manchester as string
}


############################# package lib::SD_Protocols, test exists
=item mcBit2Funkbus()

This function is a output helper for funkbus manchester signals.

Input: $object,$name,$bitData,$id,$mcbitnum
Output:
hex string
or array (-1,"Error message")

=cut

sub mcBit2Funkbus
{
my $self = shift // carp 'Not called within an object' && return (0,'no object provided');
my $name = shift // 'anonymous';
my $bitData = shift // carp 'bitData must be perovided' && return (0,'no bitData provided');
my $id = shift // carp 'protocol ID must be provided' && return (0,'no protocolId provided');
my $mcbitnum = shift // length $bitData;

return (-1,' message is to short') if ($mcbitnum < $self->checkProperty($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.
Expand Down
4 changes: 2 additions & 2 deletions controls_signalduino.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 5 additions & 8 deletions t/FHEM/00_SIGNALduino/08_DeviceData_rmsg.t
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},



);


Expand Down
40 changes: 40 additions & 0 deletions t/SD_Protocols/02_mc2dmc.t
Original file line number Diff line number Diff line change
@@ -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]);
};
45 changes: 45 additions & 0 deletions t/SD_Protocols/02_mcBit2Funkbus.t
Original file line number Diff line number Diff line change
@@ -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]);
};