2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

42_Nextion: fault tolerance in reader / fixes

git-svn-id: https://svn.fhem.de/fhem/trunk@14371 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
viegener 2017-05-25 16:12:04 +00:00
parent 617a362cc4
commit badde0e765
2 changed files with 45 additions and 19 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- change: 42_Nextion: fault tolerance in reader / fixes
- feature: 50_TelegramBot: favorites rework - inline / allow : in inline - feature: 50_TelegramBot: favorites rework - inline / allow : in inline
- change: 49_TBot_List: changed query data to prefix TBL_ / quiet peerid - change: 49_TBot_List: changed query data to prefix TBL_ / quiet peerid
- feature: 98_alarmclock: New features AlarmTime9_Vacation, skip next Alarm - feature: 98_alarmclock: New features AlarmTime9_Vacation, skip next Alarm

View File

@ -60,25 +60,29 @@
# _connect/Disconnect/isConnected subs # _connect/Disconnect/isConnected subs
# init device after notify on initialized # init device after notify on initialized
# fix connection - to work also if nextion is unavailable # fix connection - to work also if nextion is unavailable
#
#
# Extended log for read function
# remove leading ff
# fault tolerant command reader allow empty commands and missing \xff
# print filtered messages - with quoted chars
# changed log levels to 4 for verbose / 5 will print all messages
# fix replacesetmagic to ensure device hash is given
# 2016-05-25 fault tolerance in reader / fixes
#
#
# #
############################################## ##############################################
############################################## ##############################################
### TODO ### TODO
# #
# #
# rectextold1-5 --> #msg611695
# timeout with checkalive check? # timeout with checkalive check?
# #
# react on events with commands allowing values from FHEM # react on events with commands allowing values from FHEM
# remove wait for answer by attribute # remove wait for answer by attribute
# commands
# set - page x
# set - text elem text
# set - val elem val
# picture setting
# init page from fhem might sent a magic starter and finisher something like get 4711 to recognize the init command results (can be filtered away)
# number of pages as define (std max 0-9) # number of pages as define (std max 0-9)
# add 0x65 code
# progress bar
# #
############################################## ##############################################
############################################## ##############################################
@ -106,6 +110,7 @@ use strict;
use warnings; use warnings;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use Encode qw( decode encode ); use Encode qw( decode encode );
use Data::Dumper;
######################### #########################
# Forward declaration # Forward declaration
@ -270,7 +275,7 @@ Nextion_Set($@)
} }
if ( ! defined( $ret ) ) { if ( ! defined( $ret ) ) {
Log3 $name, 5, "Nextion_Set $name: $type done succesful: "; Log3 $name, 4, "Nextion_Set $name: $type done succesful: ";
} else { } else {
Log3 $name, 1, "Nextion_Set $name: $type failed with :$ret: "; Log3 $name, 1, "Nextion_Set $name: $type failed with :$ret: ";
} }
@ -283,14 +288,14 @@ sub Nextion_Attr(@) {
my ($cmd,$name,$aName,$aVal) = @_; my ($cmd,$name,$aName,$aVal) = @_;
my $hash = $defs{$name}; my $hash = $defs{$name};
Log3 $name, 5, "Nextion_Attr $name: called "; Log3 $name, 4, "Nextion_Attr $name: called ";
return "\"Nextion_Attr: \" $name does not exist" if (!defined($hash)); return "\"Nextion_Attr: \" $name does not exist" if (!defined($hash));
if (defined($aVal)) { if (defined($aVal)) {
Log3 $name, 5, "Nextion_Attr $name: $cmd on $aName to $aVal"; Log3 $name, 4, "Nextion_Attr $name: $cmd on $aName to $aVal";
} else { } else {
Log3 $name, 5, "Nextion_Attr $name: $cmd on $aName to <undef>"; Log3 $name, 4, "Nextion_Attr $name: $cmd on $aName to <undef>";
} }
# $cmd can be "del" or "set" # $cmd can be "del" or "set"
# $name is device name # $name is device name
@ -348,7 +353,7 @@ sub Nextion_Disconnect($)
my $hash = shift; my $hash = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3 $name, 5, "Nextion_Disconnect: $name"; Log3 $name, 4, "Nextion_Disconnect: $name";
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
} }
@ -454,7 +459,7 @@ Nextion_SendCommand($$$)
Log3 $name, 4, "Nextion_SendCommand $name: send commands :".$msg.": "; Log3 $name, 4, "Nextion_SendCommand $name: send commands :".$msg.": ";
# First replace any magics # First replace any magics
my %dummy; # my %dummy;
# my ($err, @a) = ReplaceSetMagic(\%dummy, 0, ( $msg ) ); # my ($err, @a) = ReplaceSetMagic(\%dummy, 0, ( $msg ) );
# if ( $err ) { # if ( $err ) {
@ -471,7 +476,7 @@ Nextion_SendCommand($$$)
while(defined($singleMsg = shift @msgList)) { while(defined($singleMsg = shift @msgList)) {
$singleMsg =~ s/SeMiCoLoN/;/g; $singleMsg =~ s/SeMiCoLoN/;/g;
my ($err, @a) = ReplaceSetMagic(\%dummy, 0, ( $singleMsg ) ); my ($err, @a) = ReplaceSetMagic($hash, 0, ( $singleMsg ) );
if ( $err ) { if ( $err ) {
Log3 $name, 1, "$name: Nextion_SendCommand failed on ReplaceSetmagic with :$err: on commands :$singleMsg:"; Log3 $name, 1, "$name: Nextion_SendCommand failed on ReplaceSetmagic with :$err: on commands :$singleMsg:";
} else { } else {
@ -549,9 +554,18 @@ Nextion_Read($@)
while(length($data) > 0) { while(length($data) > 0) {
if ( $data =~ /^([^\xff]*)\xff\xff\xff(.*)$/ ) { # if ( $data =~ /^([^\xff]*)\xff\xff\xff(.*)$/ ) {
if ( $data =~ /^([^\xff]*)(\xff+)([^\xff].*)?$/ ) {
my $rcvd = $1; my $rcvd = $1;
$data = $2; my $ffpart = $2;
$data = $3;
$data = "" if ( ! defined($data) );
if ( length($ffpart) != 3 ) {
Log3 $name, 4, "Nextion/RAW: shortened ffh end sequence (".length($ffpart).") ".Data::Dumper::qquote($rcvd) ;
} else {
Log3 $name, 5, "Nextion/RAW: message found ".Data::Dumper::qquote($rcvd) ;
}
if ( length($rcvd) > 0 ) { if ( length($rcvd) > 0 ) {
@ -592,8 +606,19 @@ Nextion_Read($@)
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
} else {
Log3 $name, 5, "Nextion/RAW: match with zero length - command missing - ffh #".length($ffpart);
} }
} else { } else {
# not matching
# if ( $data =~ /^\xff+([^\xff].*)/ ) {
# Log3 $name, 5, "Nextion/RAW: remove leading ff ";
# $data = $1;
# } elsif ( $data =~ /^[^\xff]*(\xff+)/ ) {
# Log3 $name, 5, "Nextion/RAW: not matching commands but contains ff :".length($1).":";
# } else {
# Log3 $name, 5, "Nextion/RAW: not matching commands no ff";
# }
last; last;
} }