From ee39392e14850e17077d9e1a7ad78cde835a230c Mon Sep 17 00:00:00 2001 From: breaker27 <> Date: Wed, 28 Sep 2022 19:51:36 +0000 Subject: [PATCH] 37_SHC.pm: Updated for current smarthomatic v0.12.0 (Forum #129298) git-svn-id: https://svn.fhem.de/fhem/trunk@26451 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 ++ fhem/FHEM/37_SHC.pm | 58 ++++++++++++++------ fhem/FHEM/37_SHCdev.pm | 83 +++++++++++++++++++++++------ fhem/FHEM/SHC_datafields.pm | 70 ++++++++++++++++++++---- fhem/FHEM/SHC_parser.pm | 54 ++++++++++++++----- fhem/FHEM/lib/SHC_packet_layout.xml | 73 +++++++++++++++++++++++++ 6 files changed, 288 insertions(+), 53 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 597de19ae..93b768aae 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - change: 37_SHC: Support current smarthomatic version. + Basestation uses 115200 Baud by default and CRC. + EnvSensor supports particulate matter sensor. - bugfix: 73_NUKIBridge: Fix 503 Unavailable message - change: 88_HMCCU: Switched close to closed - bugfix: 70_Klafs: package main was removed from source code diff --git a/fhem/FHEM/37_SHC.pm b/fhem/FHEM/37_SHC.pm index 7d6678a29..cae031475 100644 --- a/fhem/FHEM/37_SHC.pm +++ b/fhem/FHEM/37_SHC.pm @@ -2,6 +2,7 @@ # This file is part of the smarthomatic module for FHEM. # # Copyright (c) 2014 Stefan Baumann +# 2015, 2022 Uwe Freese # # You can find smarthomatic at www.smarthomatic.org. # You can find FHEM at www.fhem.de. @@ -26,6 +27,8 @@ package main; use strict; use warnings; use Time::HiRes qw(gettimeofday); +use Digest::CRC qw(crc32); # linux packet libdigest-crc-perl +use DevIo; sub SHC_Parse($$$$); sub SHC_Read($); @@ -37,7 +40,7 @@ sub SHC_SimpleWrite(@); my $clientsSHC = ":SHCdev:BASE:xxx:"; my %matchListSHC = ( - "1:SHCdev" => "^Packet Data: SenderID=[1-9]|0[1-9]|[1-9][0-9]|[0-9][0-9][0-9]|[0-3][0-9][0-9][0-9]|40[0-8][0-9]|409[0-6]", #1-4096 with leading zeros + "1:SHCdev" => "^PKT:SID=([1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-3][0-9][0-9][0-9]|40[0-8][0-9]|409[0-6]);", #1-4096 "2:xxx" => "^\\S+\\s+22", "3:xxx" => "^\\S+\\s+11", "4:xxx" => "^\\S+\\s+9 ", @@ -47,8 +50,6 @@ sub SHC_Initialize($) { my ($hash) = @_; - require "$attr{global}{modpath}/FHEM/DevIo.pm"; - # Provider $hash->{ReadFn} = "SHC_Read"; $hash->{WriteFn} = "SHC_Write"; @@ -69,7 +70,7 @@ sub SHC_Define($$) my @a = split("[ \t][ \t]*", $def); if (@a != 3) { - my $msg = "wrong syntax: define SHC {devicename[\@baudrate] " . "| devicename\@directio}"; + my $msg = "wrong syntax: define SHC {devicename[\@baudrate]}"; Log3 undef, 2, $msg; return $msg; } @@ -78,7 +79,7 @@ sub SHC_Define($$) my $name = $a[0]; my $dev = $a[2]; - $dev .= "\@19200" if ($dev !~ m/\@/); + $dev .= "\@115200" if ($dev !~ m/\@/); $hash->{Clients} = $clientsSHC; $hash->{MatchList} = \%matchListSHC; @@ -221,7 +222,6 @@ sub SHC_ReadAnswer($$$$) undef, $mpandata ); } - } ##################################### @@ -269,11 +269,15 @@ sub SHC_Parse($$$$) next if (!$dmsg || length($dmsg) < 1); # Bogus messages - if ($dmsg !~ m/^Packet Data: SenderID=/) { + if ($dmsg =~ m/^PKT:SID=0;/) { # "echo" from message sent by FHEM itself + return; + } + + if ($dmsg !~ m/^PKT:SID=/) { # Messages just to dipose - if ( $dmsg =~ m/^\*\*\* Enter AES key nr/ - || $dmsg =~ m/^\*\*\* Received character/) + if ( $dmsg =~ m/^\*\*\* Enter data/ + || $dmsg =~ m/^\*\*\* 0x/) { return; } @@ -294,17 +298,34 @@ sub SHC_Parse($$$$) # -Verbosity level 4 if ( $dmsg =~ m/^Request added to queue/ || $dmsg =~ m/^Request Buffer/ - || $dmsg =~ m/^Request (q|Q)ueue/) + || $dmsg =~ m/^Request Queue/) { Log3 $name, 4, "$name: $dmsg"; return; } + # -Verbosity level 1 + if ( $dmsg =~ m/^CRC Error/ ) + { + Log3 $name, 1, "$name: $dmsg"; + return; + } + # Anything else in verbosity level 3 Log3 $name, 3, "$name: $dmsg"; return; } + # check CRC of "PKT:..." message and ignore message if necessary + my $crc = crc32(substr($dmsg, 4, length($dmsg) - 12)); + $crc = sprintf("%08x", $crc); + + if ($crc ne substr($dmsg, length($dmsg) - 8)) + { + Log3 $name, 1, "$name: CRC Error (" . $crc . ") $dmsg"; + return; + } + $hash->{"${name}_MSGCNT"}++; $hash->{"${name}_TIME"} = TimeNow(); $hash->{RAWMSG} = $rmsg; @@ -345,26 +366,33 @@ sub SHC_SimpleWrite(@) syswrite($hash->{DIODev}, $msg) if ($hash->{DIODev}); # Some linux installations are broken with 0.001, T01 returns no answer - select(undef, undef, undef, 0.01); + #select(undef, undef, undef, 0.01); + + # Sleep for 250 milliseconds to make sure the base station can process the command before the next is sent + select(undef, undef, undef, 0.25); } 1; =pod +=item summary support the basestation of smarthomatic (www.smarthomatic.org) +=item summary_DE Unterstützung der Basisstation von smarthomatic (www.smarthomatic.org) =begin html

SHC