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

Hideki fix inverted message #974

Merged
merged 12 commits into from
Jun 2, 2021
27 changes: 14 additions & 13 deletions CHANGED
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2021-05-31 - Merge branch 'master' into master_hideki_fix
2021-05-31 - Update SD_Protocols.pm

* fix https://github.com/RFD-FHEM/RFFHEM/issues/944
2021-05-28 - new protocol 108 for BRESSER 5-in-1 Weather Center, Bresser Professional Rain Gauge (#973)

* Update 14_SD_WS.pm
Expand All @@ -9,7 +13,6 @@ not all tests are finished, need some more testdata
- Fehlermeldung von bitsum auf checksum geändert
- Prüfung auf Mindestlänge um Perl Warnings zu vermeiden
- Berechnung der checksumme vereinfacht
Co-authored-by: sidey79 <7968127+sidey79@users.noreply.github.com>
2021-05-27 - SD_Protocols.pm

- Fehlermeldung von bitsum auf checksum geändert
Expand All @@ -32,26 +35,24 @@ Co-authored-by: sidey79 <7968127+sidey79@users.noreply.github.com>
* Update README.md

2021-05-15 - FSK check msg length (#959)
before: check only min message length
after: chek min and max message lenght
* before: check only min message length
* after: chek min and max message lenght

2021-04-30 - enable delete attribute rfmode
- Added tests for delete and partial rfmode attr
- Added exact match of rfmode instead of pattern matching
Co-authored-by: sidey79 <7968127+sidey79@users.noreply.github.com>
* Added tests for delete and partial rfmode attr
* Added exact match of rfmode instead of pattern matching

2021-04-26 - delete attribute rfmode
00_SIGNALduinio.pm: Bugfix: "Rfmode" attribute could not be deleted.
* 00_SIGNALduinio.pm: Bugfix: "Rfmode" attribute could not be deleted.

2021-04-25 - Revolt enhacement (#956)
SD_ProtocolData.pm: Feature: Added crc checksum verification to avoid autocrate on broken transmissions
SD_Protocols.pm: changed length
* SD_ProtocolData.pm: Feature: Added crc checksum verification to avoid autocrate on broken transmissions
* SD_Protocols.pm: changed length

2021-04-10 - FSK optimization (#953)
More than one FSK protocol can also be received.
Method lib::SD_Protocols::... not strictly necessary.
Modified tests, to adapt new dispatch behaviour, which is independent from attribute rfmode
Co-authored-by: sidey79 <7968127+sidey79@users.noreply.github.com>
* More than one FSK protocol can also be received.
* Method lib::SD_Protocols::... not strictly necessary.
* Modified tests, to adapt new dispatch behaviour, which is independent from attribute rfmode

2021-03-22 - 14_SD_BELL.pm - Adjusted little things (#937)
* Update 14_SD_BELL.pm
Expand Down
21 changes: 15 additions & 6 deletions FHEM/lib/SD_Protocols.pm
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,21 @@ sub mcBit2Hideki {
my $id = shift // carp 'protocol ID must be provided' && return (0,'no protocolId provided');
my $mcbitnum = shift // length $bitData;

my $message_start = index($bitData,'10101110');
if ($mcbitnum == 89) { # optimization when the beginning was missing
sidey79 marked this conversation as resolved.
Show resolved Hide resolved
my $bit0 = substr($bitData,0,1);
$bit0 = $bit0 ^ 1;
$bitData = $bit0 . $bitData;
$self->_logging( qq[lib/mcBit2Hideki, L=$mcbitnum add bit $bit0 at begin $bitData], 5 );
}

my $message_start = index($bitData,'10101110'); # normal rawMSG
my $invert = 0;
my $message_start_invert = index($bitData,'01010001'); # invert rawMSG
# 10101110 can occur again in raw MSG -> comparison with inverted start 01010001

if ($message_start < 0) {
$bitData =~ tr/01/10/; # invert message
$message_start = index($bitData,'10101110'); # 0x75 but in reverse order
if ( $message_start < 0 || ( $message_start_invert!= -1 && $message_start > 0 && ($message_start_invert < $message_start) ) ) {
sidey79 marked this conversation as resolved.
Show resolved Hide resolved
$bitData =~ tr/01/10/; # invert message
$message_start = index($bitData,'10101110'); # 0x75 but in reverse order
$invert = 1;
}

Expand All @@ -606,8 +615,8 @@ sub mcBit2Hideki {
# Todo: Mindest Laenge fuer startpunkt vorspringen
# Todo: Wiederholung auch an das Modul weitergeben, damit es dort geprueft werden kann
my $message_end = index($bitData,'10101110',$message_start+71); # pruefen auf ein zweites 0x75, mindestens 72 bit nach 1. 0x75, da der Regensensor minimum 8 Byte besitzt je byte haben wir 9 bit
$message_end = length($bitData) if ($message_end == -1);
my $message_length = $message_end - $message_start;
$message_end = length($bitData) if ($message_end == -1);
my $message_length = $message_end - $message_start;

return (-1,' message is to short') if ($message_length < $self->checkProperty($id,'length_min',-1) );
return (-1,' message is to long') if (defined $self->getProperty($id,'length_max' ) && $message_length > $self->getProperty($id,'length_max') );
Expand Down
2 changes: 1 addition & 1 deletion controls_signalduino.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ UPD 2020-04-13_23:15:56 14325 FHEM/14_SD_WS_Maverick.pm
UPD 2018-07-04_21:56:16 37910 FHEM/41_OREGON.pm
UPD 2020-12-17_23:16:30 15582 FHEM/90_SIGNALduino_un.pm
UPD 2021-05-28_16:17:04 209726 FHEM/lib/SD_ProtocolData.pm
UPD 2021-05-28_16:17:04 71111 FHEM/lib/SD_Protocols.pm
UPD 2021-05-31_20:42:28 71700 FHEM/lib/SD_Protocols.pm
34 changes: 28 additions & 6 deletions t/SD_Protocols/02_mcBit2Hideki.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use lib::SD_Protocols;
use Test2::Tools::Compare qw{is};
use Test2::Todo;

plan(4);
plan(6);

my $id=5012;
my ($rcode,$hexresult);
Expand All @@ -26,7 +26,7 @@ subtest 'message good' => sub {
my $bitdata='101010001100001000110011101101010011101000111110000010100000011110000011';

($rcode,$hexresult)=$Protocols->mcBit2Hideki(undef,$bitdata,$id,length $bitdata);
is($rcode,1,'check returncode for single Hideki transmission');
is($rcode,1,'check returncode for Hideki transmission');
is($hexresult,'75EF46351DBE3F3E','check result for single Hideki transmission');
};

Expand All @@ -37,7 +37,7 @@ subtest 'message without preamble' => sub {
my $bitdata='010001100001000110011101101010011101000111110000010100000011110000011';

($rcode,$hexresult)=$Protocols->mcBit2Hideki(undef,$bitdata,$id,length $bitdata);
is($rcode,-1,'check returncode for single Hideki transmission');
is($rcode,-1,'check returncode for Hideki transmission');
is($hexresult,U(),'check result for single Hideki transmission');
};

Expand All @@ -48,7 +48,7 @@ subtest 'message is to short' => sub {
my $bitdata='10101000110000100011001110110101001110100011111000001';

($rcode,$hexresult)=$Protocols->mcBit2Hideki(undef,$bitdata,$id,length $bitdata);
is($rcode,-1,'check returncode for single OSV1 transmission');
is($rcode,-1,'check returncode for Hideki transmission');
is($hexresult,' message is to short','check result message to short');
};

Expand All @@ -59,6 +59,28 @@ subtest 'message is to long' => sub {
my $bitdata='10101000110000100011001110110101001110100011111000001010000001111000001100000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000101010100000000000000000000000000';

($rcode,$hexresult)=$Protocols->mcBit2Hideki(undef,$bitdata,$id,length $bitdata);
is($rcode,-1,'check returncode for single OSV1 transmission');
is($rcode,-1,'check returncode for Hideki transmission');
is($hexresult,' message is to long','check result message to long');
};
};


subtest 'message is inverted' => sub {
plan(2);

my $bitdata='10101000111001001111010001011010111011011111010000001010111110010111010110010101011101100110';

($rcode,$hexresult)=$Protocols->mcBit2Hideki(undef,$bitdata,$id,length $bitdata);
is($rcode,1,'check returncode for Hideki transmission');
is($hexresult,'7536BA8A82BFC151AB6401','check result');
};


subtest 'message had 89 bits' => sub {
plan(2);

my $bitdata='01010001100100100110100010110101110100110111110000010101110111101101010110000000110111001000';

($rcode,$hexresult)=$Protocols->mcBit2Hideki(undef,$bitdata,$id,89);
is($rcode,1,'check returncode for Hideki transmission');
is($hexresult,'75DBBA8A13BE11A9FE6203','check result');
};