Skip to content

Commit

Permalink
sub SIGNALduino_CheckccConfResponse - is more robust #1015 (#1031)
Browse files Browse the repository at this point in the history
* Update 00_SIGNALduino.pm
  #1015

* Update 02_SIGNALduino_CheckccConfResponse.t
  test added with wrong value
  • Loading branch information
HomeAutoUser authored Nov 4, 2021
1 parent 367dcf9 commit 7b884a5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions FHEM/00_SIGNALduino.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $Id: 00_SIGNALduino.pm v3.5.2 2021-08-29 21:54:48Z elektron-bbs $
# $Id: 00_SIGNALduino.pm v3.5.2 2021-11-03 13:02:40Z HomeAutoUser $
#
# v3.5.2 - 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
Expand Down Expand Up @@ -39,7 +39,7 @@ use List::Util qw(first);


use constant {
SDUINO_VERSION => '3.5.2+20210829', # Datum wird automatisch bei jedem pull request aktualisiert
SDUINO_VERSION => '3.5.2+20211103', # 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 @@ -1174,6 +1174,11 @@ sub SIGNALduino_CheckCmdsResponse {
sub SIGNALduino_CheckccConfResponse {
my (undef,$str) = split('=', $_[1]);
my $var;

# https://github.com/RFD-FHEM/RFFHEM/issues/1015 | value can arise due to an incorrect transmission from serial
# $str = "216%E857C43023B900070018146C040091";
return ('invalid value from uC. Only hexadecimal values are allowed. Please query again.',undef) if($str !~ /^[A-F0-9a-f]+$/);

my %r = ( '0D'=>1,'0E'=>1,'0F'=>1,'10'=>1,'11'=>1,'12'=>1,'1B'=>1,'1D'=>1, '15'=>1);
foreach my $a (sort keys %r) {
$var = substr($str,(hex($a)-13)*2, 2);
Expand Down
2 changes: 1 addition & 1 deletion controls_signalduino.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UPD 2021-08-30_16:54:51 229349 FHEM/00_SIGNALduino.pm
UPD 2021-11-03_13:01:09 229643 FHEM/00_SIGNALduino.pm
UPD 2020-06-15_17:41:39 17876 FHEM/10_FS10.pm
UPD 2020-05-26_11:51:12 20465 FHEM/10_SD_GT.pm
UPD 2021-08-11_21:38:30 10096 FHEM/14_BresserTemeo.pm
Expand Down
15 changes: 12 additions & 3 deletions t/FHEM/00_SIGNALduino/02_SIGNALduino_CheckccConfResponse.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use Test2::Tools::Compare qw{ is };
our %defs;

InternalTimer(time(), sub {
plan(2);
plan(3);

subtest 'Test cconf response ASK/OOK (C0Dn11=10B07157C43023B900070018146C070091)' => sub {
plan(3);
my $target='dummyDuino';
my $targetHash = $defs{$target};

my ($ret)=SIGNALduino_CheckccConfResponse($targetHash,"C0Dn11=10B07157C43023B900070018146C070091");
my ($ret)=SIGNALduino_CheckccConfResponse($targetHash,'C0Dn11=10B07157C43023B900070018146C070091');
is($ret,"Freq: 433.920 MHz, Bandwidth: 325 kHz, rAmpl: 42 dB, sens: 8 dB, DataRate: 5.60 kBaud, Modulation: ASK/OOK","check return message");
is(ReadingsVal($target,"cc1101_config",undef),"Freq: 433.920 MHz, Bandwidth: 325 kHz, rAmpl: 42 dB, sens: 8 dB, DataRate: 5.60 kBaud","check reading cc1101_config value");
is(ReadingsVal($target,"cc1101_config_ext",undef),"Modulation: ASK/OOK","check reading cc1101_config_ext value");
Expand All @@ -25,12 +25,21 @@ InternalTimer(time(), sub {
my $target='dummyDuino';
my $targetHash = $defs{$target};

my ($ret)=SIGNALduino_CheckccConfResponse($targetHash,"C0Dn11=10AA568AF80222F851070018166C434091");
my ($ret)=SIGNALduino_CheckccConfResponse($targetHash,'C0Dn11=10AA568AF80222F851070018166C434091');
is($ret,"Freq: 433.300 MHz, Bandwidth: 203 kHz, rAmpl: 33 dB, sens: 8 dB, DataRate: 49.99 kBaud, Modulation: 2-FSK, Syncmod: 16/16 sync word bits detected, Deviation: 57.13 kHz","check return message");
is(ReadingsVal($target,"cc1101_config",undef),"Freq: 433.300 MHz, Bandwidth: 203 kHz, rAmpl: 33 dB, sens: 8 dB, DataRate: 49.99 kBaud","check reading cc1101_config value");
is(ReadingsVal($target,"cc1101_config_ext",undef),"Modulation: 2-FSK, Syncmod: 16/16 sync word bits detected, Deviation: 57.13 kHz");
};

subtest 'Test cconf response wrong value (C0Dn11=216%E857C43023B900070018146C040091)' => sub {
plan(1);
my $target='dummyDuino';
my $targetHash = $defs{$target};

my ($ret)=SIGNALduino_CheckccConfResponse($targetHash,'C0Dn11=216%E857C43023B900070018146C040091');
is($ret,'invalid value from uC. Only hexadecimal values are allowed. Please query again.','check return message');
};

exit(0);
}, 0);

Expand Down

0 comments on commit 7b884a5

Please sign in to comment.