2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

20_N4HBUS:Changes on matchlist and decoding of messages

21_N4HMODULE:Optimized Log3 messages


git-svn-id: https://svn.fhem.de/fhem/trunk@28132 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
oliverk 2023-11-07 10:49:44 +00:00
parent 9fe8ff2fb6
commit 08d9304658
2 changed files with 45 additions and 21 deletions

View File

@ -4,7 +4,7 @@
# #
# net4home Busconnector Device # net4home Busconnector Device
# #
# (c) 2014-2018 Oliver Koerber <koerber@net4home.de> # (c) 2014-2023 Oliver Koerber <koerber@net4home.de>
# #
# $Id$ # $Id$
# #
@ -14,10 +14,11 @@ package main;
use strict; use strict;
use warnings; use warnings;
use DevIo;
use POSIX; use POSIX;
use Data::Dumper; use Data::Dumper;
my $n4hbus_Version = "1.0.2.0 - 30.12.2017"; my $n4hbus_Version = "1.0.3.0 - 29.10.2023";
sub N4HBUS_Read($@); sub N4HBUS_Read($@);
sub N4HBUS_Write($$$$); sub N4HBUS_Write($$$$);
@ -28,8 +29,6 @@ sub N4HBUS_CompressSection($$);
sub N4HBUS_Initialize($) sub N4HBUS_Initialize($)
{ {
my ($hash) = @_; my ($hash) = @_;
require "$attr{global}{modpath}/FHEM/DevIo.pm";
# Provider # Provider
$hash->{ReadFn} = "N4HBUS_Read"; $hash->{ReadFn} = "N4HBUS_Read";
$hash->{WriteFn} = "N4HBUS_Write"; $hash->{WriteFn} = "N4HBUS_Write";
@ -51,8 +50,8 @@ sub N4HBUS_Define($$) {
my @a = split("[ \t]+", $def); my @a = split("[ \t]+", $def);
if(@a != 3) { if(@a != 3) {
my $msg = "wrong syntax: define <name> N4HBUS hostname:port"; my $msg = "wrong syntax: define <name> N4HBUS hostname/IP:port";
Log3 $hash, 2, $msg; Log3 $hash, 1, $msg;
return $msg; return $msg;
} }
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
@ -63,13 +62,13 @@ sub N4HBUS_Define($$) {
$hash->{VERSION} = $n4hbus_Version; $hash->{VERSION} = $n4hbus_Version;
$hash->{DeviceName} = $dev; $hash->{DeviceName} = $dev;
$hash->{Clients} = ":N4HMODULE:"; $hash->{Clients} = ":N4HMODULE:";
my %matchList = ( "1:N4HMODULE" => ".*" ); my %matchList = ( "1:N4HMODULE" => "^[0-9A-Fa-f]" );
$hash->{MatchList} = \%matchList; $hash->{MatchList} = \%matchList;
Log3 $hash, 3, "N4HBUS_Define -> $name at $dev"; Log3 $hash, 3, "N4HBUS Define -> $name at $dev";
if($dev eq "none") { if($dev eq "none") {
Log3 $hash, 1, "N4HBUS device is none, commands will be echoed only"; Log3 $hash, 0, "N4HBUS device is none, commands will be echoed only";
$attr{$name}{dummy} = 1; $attr{$name}{dummy} = 1;
return undef; return undef;
} }
@ -107,7 +106,7 @@ sub N4HBUS_Undef($@) {
my ( $hash, $arg ) = @_; my ( $hash, $arg ) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3 $hash, 2, "close port for $name"; Log3 $hash, 0, "N4HBUS Close port for $name";
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
return undef; return undef;
@ -393,7 +392,8 @@ sub N4HBUS_Read($@) {
$hash->{RAWMSG} = $msg; $hash->{RAWMSG} = $msg;
my %addvals = (RAWMSG => $data); my %addvals = (RAWMSG => $data);
Dispatch($hash, $msg, \%addvals) if($init_done); Log3 $hash, 5, "N4HBUS (DECOMP) a10f: Dispatch $msg - ".$hash->{NAME};
Dispatch($hash, $msg, \%addvals, 1) if($init_done);
} }
} # a10f - Statuspaket } # a10f - Statuspaket
@ -408,7 +408,7 @@ sub N4HBUS_Ready($) {
my ($hash) = @_; my ($hash) = @_;
Log3 $hash, 1, "N4HBUS_Ready"; Log3 $hash, 0, "N4HBUS Connected";
return DevIo_OpenDev($hash, 1, "N4HBUS_DoInit"); return DevIo_OpenDev($hash, 1, "N4HBUS_DoInit");
} }

View File

@ -22,7 +22,7 @@ sub N4HMODULE_Get ($$@);
sub N4HMODULE_Update($@); sub N4HMODULE_Update($@);
sub N4HMODULE_DbLog_splitFn($$); sub N4HMODULE_DbLog_splitFn($$);
my $n4hmodule_Version = "1.0.2.0 - 30.12.2017"; my $n4hmodule_Version = "1.0.3.0 - 29.10.2023";
my %OT_devices = ( my %OT_devices = (
"1" => {"name" => "leer", "OTcanSet" => "false", "OTcanReq" => "false", "fields" => [] }, "1" => {"name" => "leer", "OTcanSet" => "false", "OTcanReq" => "false", "fields" => [] },
@ -126,6 +126,7 @@ sub N4HMODULE_Initialize($) {
$hash->{DefFn} = "N4HMODULE_Define"; $hash->{DefFn} = "N4HMODULE_Define";
$hash->{UndefFn} = "N4HMODULE_Undefine"; $hash->{UndefFn} = "N4HMODULE_Undefine";
$hash->{ParseFn} = "N4HMODULE_Parse"; $hash->{ParseFn} = "N4HMODULE_Parse";
$hash->{FingerprintFn} = "N4HMODULE_Fingerprint";
$hash->{SetFn} = "N4HMODULE_Set"; $hash->{SetFn} = "N4HMODULE_Set";
$hash->{GetFn} = "N4HMODULE_Get"; $hash->{GetFn} = "N4HMODULE_Get";
$hash->{AttrFn} = "N4HMODULE_Attr"; $hash->{AttrFn} = "N4HMODULE_Attr";
@ -133,6 +134,8 @@ sub N4HMODULE_Initialize($) {
"$readingFnAttributes "; "$readingFnAttributes ";
# "OT:" .join(",", sort @otlist); # "OT:" .join(",", sort @otlist);
$hash->{DbLog_splitFn} = "N4HMODULE_DbLog_splitFn"; $hash->{DbLog_splitFn} = "N4HMODULE_DbLog_splitFn";
$hash->{Match} = ".";
} }
@ -147,7 +150,7 @@ sub N4HMODULE_Define($$) {
if(@args < 4) { if(@args < 4) {
my $msg = "Usage: define <name> N4HMODULE <N4HBUS> <OBJECTTYPE> <OBJADDR>"; my $msg = "Usage: define <name> N4HMODULE <N4HBUS> <OBJECTTYPE> <OBJADDR>";
Log3 $hash, 2, $msg; Log3 $hash, 1, $msg;
return $msg; return $msg;
} }
@ -165,9 +168,8 @@ sub N4HMODULE_Define($$) {
$hash->{Interval} = 0; $hash->{Interval} = 0;
$modules{N4HMODULE}{defptr}{$objadr} = $hash; $modules{N4HMODULE}{defptr}{$objadr} = $hash;
AssignIoPort($hash, $n4hbus); AssignIoPort($hash, $n4hbus);
Log3 $hash, 3, "N4HMODULE_Define -> $name ($ot) at device $n4hbus with objectadr $objadr"; Log3 $hash, 3, "N4HMODULE Define -> $name ($ot) at device $n4hbus with objectadr $objadr";
$hash->{helper}{from} = ''; $hash->{helper}{from} = '';
$hash->{helper}{value} = ''; $hash->{helper}{value} = '';
@ -193,16 +195,19 @@ sub N4HMODULE_Define($$) {
($ot == 245)) { #Regenmenge l/h ($ot == 245)) { #Regenmenge l/h
my $state_format; my $state_format;
my $icon;
if( $ot == 24 ) { if( $ot == 24 ) {
$state_format .= " " if( $state_format ); $state_format .= " " if( $state_format );
$state_format .= "T: temperature"; $state_format .= "T: temperature";
$icon = "temp_temperature";
} elsif( $ot == 25 ) { } elsif( $ot == 25 ) {
$state_format .= " " if( $state_format ); $state_format .= " " if( $state_format );
$state_format .= "L: brightness"; $state_format .= "L: brightness";
} elsif( $ot == 26 ) { } elsif( $ot == 26 ) {
$state_format .= " " if( $state_format ); $state_format .= " " if( $state_format );
$state_format .= "H: humidity"; $state_format .= "H: humidity";
$icon = "weather_humidity";
} elsif( $ot == 240 ) { } elsif( $ot == 240 ) {
$state_format .= " " if( $state_format ); $state_format .= " " if( $state_format );
$state_format .= "W: wind"; $state_format .= "W: wind";
@ -218,19 +223,20 @@ sub N4HMODULE_Define($$) {
} }
$attr{$name}{stateFormat} = $state_format if( !defined($attr{$name}{stateFormat}) && defined($state_format) ); $attr{$name}{stateFormat} = $state_format if( !defined($attr{$name}{stateFormat}) && defined($state_format) );
$attr{$name}{icon} = $icon if( !defined($attr{$name}{icon}) && defined($icon) );
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
$hash->{Interval} = 30; $hash->{Interval} = 30;
# Timer Zeitversetzt starten, damit nicht alles auf den Bus gleichzeit kommt 30 Sekunden + x # Timer Zeitversetzt starten, damit nicht alles auf den Bus gleichzeit kommt 30 Sekunden + x
Log3 $hash, 3, "N4HMODULE_Define (set timer) -> $name ($ot)"; Log3 $hash, 3, "N4HMODULE Define (set timer) -> $name ($ot)";
InternalTimer( gettimeofday() + 30 + int(rand(15)) , "N4HMODULE_Start", $hash, 0 ); InternalTimer( gettimeofday() + 30 + int(rand(15)) , "N4HMODULE_Start", $hash, 0 );
} elsif (( $ot == 34 ) or # TLH } elsif (( $ot == 34 ) or # TLH
( $ot == 3 ) or # Aktor, Relais ( $ot == 3 ) or # Aktor, Relais
( $ot == 5)) { # Aktor, Dimmer ( $ot == 5)) { # Aktor, Dimmer
# get initial value from bus after first start # get initial value from bus after first start
Log3 $hash, 3, "N4HMODULE_Define (get) -> $name ($ot)"; Log3 $hash, 3, "N4HMODULE Define (get) -> $name ($ot)";
InternalTimer( gettimeofday() + int(rand(10)) , "N4HMODULE_Start", $hash, 0 ); InternalTimer( gettimeofday() + int(rand(10)) , "N4HMODULE_Start", $hash, 0 );
} }
return undef; return undef;
@ -288,7 +294,7 @@ sub N4HMODULE_Undefine($$) {
my ($hash,$arg) = @_; my ($hash,$arg) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3 $hash, 3, "N4HMODULE_Undefine -> $name"; Log3 $hash, 3, "N4HMODULE Undefine -> $name";
RemoveInternalTimer( $hash ); RemoveInternalTimer( $hash );
delete($modules{N4HMODULE}{defptr}{$hash->{OBJADR}}); delete($modules{N4HMODULE}{defptr}{$hash->{OBJADR}});
return undef; return undef;
@ -335,6 +341,7 @@ sub N4HMODULE_Parse($$) {
my $ioName = $iodev->{NAME}; my $ioName = $iodev->{NAME};
my $object = ""; my $object = "";
# Modul suchen # Modul suchen
my $type8 = hex(substr($msg,0,2)); my $type8 = hex(substr($msg,0,2));
my $ipsrc = substr($msg,4,2).substr($msg,2,2); my $ipsrc = substr($msg,4,2).substr($msg,2,2);
@ -344,6 +351,8 @@ sub N4HMODULE_Parse($$) {
my $ddata = substr($msg,16, ($datalen*2)); my $ddata = substr($msg,16, ($datalen*2));
my $pos = $datalen*2+16; my $pos = $datalen*2+16;
# 0c 6100 ff7f d817 05 65 09 05 01 67 4004000001ff4004000001f8403600c000000659
# Log3 "xx", 1, "(DECOMP2): T8($type8) - MI$ipsrc DST-> $ipdst SRC<-$objsrc"; # Log3 "xx", 1, "(DECOMP2): T8($type8) - MI$ipsrc DST-> $ipdst SRC<-$objsrc";
if ( length($msg) <= $pos ) { if ( length($msg) <= $pos ) {
@ -371,7 +380,7 @@ sub N4HMODULE_Parse($$) {
if(!$hash) { if(!$hash) {
my $ret = "Undefined ObjectAddress ($object)"; my $ret = "Undefined ObjectAddress ($object)";
return ""; return undef;
} }
my $devtype = $hash->{OT}; my $devtype = $hash->{OT};
@ -381,6 +390,21 @@ sub N4HMODULE_Parse($$) {
} }
##################################################################################
sub N4HMODULE_Fingerprint($$) {
##################################################################################
my ( $io_name, $msg ) = @_;
# substr( $msg, 2, 2, "--" ); # entferne Empfangsadresse
# substr( $msg, 4, 1, "-" ); # entferne Hop-Count
return ( $io_name, $msg );
}
################################################################################## ##################################################################################
sub N4HMODULE_ParsePayload($@) { sub N4HMODULE_ParsePayload($@) {
################################################################################## ##################################################################################
@ -961,7 +985,7 @@ sub N4HMODULE_Get($$@) {
my $ipdst = $hash->{OBJADR}; my $ipdst = $hash->{OBJADR};
my $ddata = ""; my $ddata = "";
my $fieldcmd = ""; my $fieldcmd = "";
my $list = ""; my $list = "";
my $list = "desired-temperature:noArg"; my $list = "desired-temperature:noArg";