mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-25 09:55:38 +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:
parent
3171b52d29
commit
61a3d7a971
@ -4,7 +4,7 @@
|
||||
#
|
||||
# net4home Busconnector Device
|
||||
#
|
||||
# (c) 2014-2018 Oliver Koerber <koerber@net4home.de>
|
||||
# (c) 2014-2023 Oliver Koerber <koerber@net4home.de>
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
@ -14,10 +14,11 @@ package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DevIo;
|
||||
use POSIX;
|
||||
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_Write($$$$);
|
||||
@ -28,8 +29,6 @@ sub N4HBUS_CompressSection($$);
|
||||
sub N4HBUS_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
require "$attr{global}{modpath}/FHEM/DevIo.pm";
|
||||
|
||||
# Provider
|
||||
$hash->{ReadFn} = "N4HBUS_Read";
|
||||
$hash->{WriteFn} = "N4HBUS_Write";
|
||||
@ -51,8 +50,8 @@ sub N4HBUS_Define($$) {
|
||||
my @a = split("[ \t]+", $def);
|
||||
|
||||
if(@a != 3) {
|
||||
my $msg = "wrong syntax: define <name> N4HBUS hostname:port";
|
||||
Log3 $hash, 2, $msg;
|
||||
my $msg = "wrong syntax: define <name> N4HBUS hostname/IP:port";
|
||||
Log3 $hash, 1, $msg;
|
||||
return $msg;
|
||||
}
|
||||
DevIo_CloseDev($hash);
|
||||
@ -63,13 +62,13 @@ sub N4HBUS_Define($$) {
|
||||
$hash->{VERSION} = $n4hbus_Version;
|
||||
$hash->{DeviceName} = $dev;
|
||||
$hash->{Clients} = ":N4HMODULE:";
|
||||
my %matchList = ( "1:N4HMODULE" => ".*" );
|
||||
my %matchList = ( "1:N4HMODULE" => "^[0-9A-Fa-f]" );
|
||||
$hash->{MatchList} = \%matchList;
|
||||
|
||||
Log3 $hash, 3, "N4HBUS_Define -> $name at $dev";
|
||||
Log3 $hash, 3, "N4HBUS Define -> $name at $dev";
|
||||
|
||||
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;
|
||||
return undef;
|
||||
}
|
||||
@ -107,7 +106,7 @@ sub N4HBUS_Undef($@) {
|
||||
my ( $hash, $arg ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Log3 $hash, 2, "close port for $name";
|
||||
Log3 $hash, 0, "N4HBUS Close port for $name";
|
||||
DevIo_CloseDev($hash);
|
||||
|
||||
return undef;
|
||||
@ -393,7 +392,8 @@ sub N4HBUS_Read($@) {
|
||||
$hash->{RAWMSG} = $msg;
|
||||
|
||||
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
|
||||
|
||||
@ -408,7 +408,7 @@ sub N4HBUS_Ready($) {
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
Log3 $hash, 1, "N4HBUS_Ready";
|
||||
Log3 $hash, 0, "N4HBUS Connected";
|
||||
return DevIo_OpenDev($hash, 1, "N4HBUS_DoInit");
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ sub N4HMODULE_Get ($$@);
|
||||
sub N4HMODULE_Update($@);
|
||||
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 = (
|
||||
"1" => {"name" => "leer", "OTcanSet" => "false", "OTcanReq" => "false", "fields" => [] },
|
||||
@ -126,6 +126,7 @@ sub N4HMODULE_Initialize($) {
|
||||
$hash->{DefFn} = "N4HMODULE_Define";
|
||||
$hash->{UndefFn} = "N4HMODULE_Undefine";
|
||||
$hash->{ParseFn} = "N4HMODULE_Parse";
|
||||
$hash->{FingerprintFn} = "N4HMODULE_Fingerprint";
|
||||
$hash->{SetFn} = "N4HMODULE_Set";
|
||||
$hash->{GetFn} = "N4HMODULE_Get";
|
||||
$hash->{AttrFn} = "N4HMODULE_Attr";
|
||||
@ -133,6 +134,8 @@ sub N4HMODULE_Initialize($) {
|
||||
"$readingFnAttributes ";
|
||||
# "OT:" .join(",", sort @otlist);
|
||||
$hash->{DbLog_splitFn} = "N4HMODULE_DbLog_splitFn";
|
||||
$hash->{Match} = ".";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +150,7 @@ sub N4HMODULE_Define($$) {
|
||||
|
||||
if(@args < 4) {
|
||||
my $msg = "Usage: define <name> N4HMODULE <N4HBUS> <OBJECTTYPE> <OBJADDR>";
|
||||
Log3 $hash, 2, $msg;
|
||||
Log3 $hash, 1, $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
@ -165,9 +168,8 @@ sub N4HMODULE_Define($$) {
|
||||
$hash->{Interval} = 0;
|
||||
|
||||
$modules{N4HMODULE}{defptr}{$objadr} = $hash;
|
||||
|
||||
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}{value} = '';
|
||||
@ -193,16 +195,19 @@ sub N4HMODULE_Define($$) {
|
||||
($ot == 245)) { #Regenmenge l/h
|
||||
|
||||
my $state_format;
|
||||
my $icon;
|
||||
|
||||
if( $ot == 24 ) {
|
||||
$state_format .= " " if( $state_format );
|
||||
$state_format .= "T: temperature";
|
||||
$icon = "temp_temperature";
|
||||
} elsif( $ot == 25 ) {
|
||||
$state_format .= " " if( $state_format );
|
||||
$state_format .= "L: brightness";
|
||||
} elsif( $ot == 26 ) {
|
||||
$state_format .= " " if( $state_format );
|
||||
$state_format .= "H: humidity";
|
||||
$icon = "weather_humidity";
|
||||
} elsif( $ot == 240 ) {
|
||||
$state_format .= " " if( $state_format );
|
||||
$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}{icon} = $icon if( !defined($attr{$name}{icon}) && defined($icon) );
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
|
||||
$hash->{Interval} = 30;
|
||||
|
||||
# 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 );
|
||||
} elsif (( $ot == 34 ) or # TLH
|
||||
( $ot == 3 ) or # Aktor, Relais
|
||||
( $ot == 5)) { # Aktor, Dimmer
|
||||
# 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 );
|
||||
}
|
||||
return undef;
|
||||
@ -288,7 +294,7 @@ sub N4HMODULE_Undefine($$) {
|
||||
my ($hash,$arg) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Log3 $hash, 3, "N4HMODULE_Undefine -> $name";
|
||||
Log3 $hash, 3, "N4HMODULE Undefine -> $name";
|
||||
RemoveInternalTimer( $hash );
|
||||
delete($modules{N4HMODULE}{defptr}{$hash->{OBJADR}});
|
||||
return undef;
|
||||
@ -335,6 +341,7 @@ sub N4HMODULE_Parse($$) {
|
||||
my $ioName = $iodev->{NAME};
|
||||
my $object = "";
|
||||
|
||||
|
||||
# Modul suchen
|
||||
my $type8 = hex(substr($msg,0,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 $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";
|
||||
|
||||
if ( length($msg) <= $pos ) {
|
||||
@ -371,7 +380,7 @@ sub N4HMODULE_Parse($$) {
|
||||
|
||||
if(!$hash) {
|
||||
my $ret = "Undefined ObjectAddress ($object)";
|
||||
return "";
|
||||
return undef;
|
||||
}
|
||||
|
||||
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($@) {
|
||||
##################################################################################
|
||||
@ -961,7 +985,7 @@ sub N4HMODULE_Get($$@) {
|
||||
my $ipdst = $hash->{OBJADR};
|
||||
my $ddata = "";
|
||||
my $fieldcmd = "";
|
||||
my $list = "";
|
||||
my $list = "";
|
||||
|
||||
my $list = "desired-temperature:noArg";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user