mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-01 20:20:10 +00:00
00_SIGNALduino: Missing module like Digest::CRC does not prevent loading the module
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@25549 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
bee8c27481
commit
f75f7285f6
@ -1,5 +1,5 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
# v3.5.2 - https://github.com/RFD-FHEM/RFFHEM/tree/master
|
# v3.5.3 - 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
|
# The module is inspired by the FHEMduino project and modified in serval ways for processing the incoming messages
|
||||||
# see http://www.fhemwiki.de/wiki/SIGNALDuino
|
# see http://www.fhemwiki.de/wiki/SIGNALDuino
|
||||||
# It was modified also to provide support for raw message handling which can be send from the SIGNALduino
|
# It was modified also to provide support for raw message handling which can be send from the SIGNALduino
|
||||||
@ -14,9 +14,9 @@
|
|||||||
package main;
|
package main;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
#use version 0.77; our $VERSION = version->declare('v3.5.2');
|
#use version 0.77; our $VERSION = version->declare('v3.5.3');
|
||||||
|
|
||||||
my $missingModulSIGNALduino = '';
|
my $missingModulSIGNALduino = ' ';
|
||||||
|
|
||||||
use DevIo;
|
use DevIo;
|
||||||
require "99_Utils.pm" if (!defined $modules{"Utils"} || !exists $modules{"Utils"}{"LOADED"} ); ## no critic
|
require "99_Utils.pm" if (!defined $modules{"Utils"} || !exists $modules{"Utils"}{"LOADED"} ); ## no critic
|
||||||
@ -24,8 +24,8 @@ use Carp;
|
|||||||
no warnings 'portable';
|
no warnings 'portable';
|
||||||
|
|
||||||
eval {use Data::Dumper qw(Dumper);1};
|
eval {use Data::Dumper qw(Dumper);1};
|
||||||
eval {use Digest::CRC;1 or $missingModulSIGNALduino .= 'Digest::CRC '};
|
|
||||||
eval {use JSON;1 or $missingModulSIGNALduino .= 'JSON '};
|
use constant HAS_JSON => defined eval { require JSON; JSON->import; };
|
||||||
|
|
||||||
eval {use Scalar::Util qw(looks_like_number);1};
|
eval {use Scalar::Util qw(looks_like_number);1};
|
||||||
eval {use Time::HiRes qw(gettimeofday);1} ;
|
eval {use Time::HiRes qw(gettimeofday);1} ;
|
||||||
@ -38,7 +38,7 @@ use List::Util qw(first);
|
|||||||
|
|
||||||
|
|
||||||
use constant {
|
use constant {
|
||||||
SDUINO_VERSION => '3.5.2', # Datum wird automatisch bei jedem pull request aktualisiert
|
SDUINO_VERSION => '3.5.3', # Datum wird automatisch bei jedem pull request aktualisiert
|
||||||
SDUINO_INIT_WAIT_XQ => 1.5, # wait disable device
|
SDUINO_INIT_WAIT_XQ => 1.5, # wait disable device
|
||||||
SDUINO_INIT_WAIT => 2,
|
SDUINO_INIT_WAIT => 2,
|
||||||
SDUINO_INIT_MAXRETRY => 3,
|
SDUINO_INIT_MAXRETRY => 3,
|
||||||
@ -295,15 +295,17 @@ sub SIGNALduino_Initialize {
|
|||||||
Log3 'SIGNALduino', 4, qq[SIGNALduino_Initialize: rfmode list: @rfmode];
|
Log3 'SIGNALduino', 4, qq[SIGNALduino_Initialize: rfmode list: @rfmode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hash->{DefFn} = \&SIGNALduino_Define;
|
||||||
|
$hash->{UndefFn} = \&SIGNALduino_Undef;
|
||||||
|
|
||||||
|
|
||||||
# Provider
|
# Provider
|
||||||
$hash->{ReadFn} = \&SIGNALduino_Read;
|
$hash->{ReadFn} = \&SIGNALduino_Read;
|
||||||
$hash->{WriteFn} = \&SIGNALduino_Write;
|
$hash->{WriteFn} = \&SIGNALduino_Write;
|
||||||
$hash->{ReadyFn} = \&SIGNALduino_Ready;
|
$hash->{ReadyFn} = \&SIGNALduino_Ready;
|
||||||
|
|
||||||
# Normal devices
|
# Normal devices
|
||||||
$hash->{DefFn} = \&SIGNALduino_Define;
|
|
||||||
$hash->{FingerprintFn} = \&SIGNALduino_FingerprintFn;
|
$hash->{FingerprintFn} = \&SIGNALduino_FingerprintFn;
|
||||||
$hash->{UndefFn} = \&SIGNALduino_Undef;
|
|
||||||
$hash->{GetFn} = \&SIGNALduino_Get;
|
$hash->{GetFn} = \&SIGNALduino_Get;
|
||||||
$hash->{SetFn} = \&SIGNALduino_Set;
|
$hash->{SetFn} = \&SIGNALduino_Set;
|
||||||
$hash->{AttrFn} = \&SIGNALduino_Attr;
|
$hash->{AttrFn} = \&SIGNALduino_Attr;
|
||||||
@ -1065,7 +1067,7 @@ sub SIGNALduino_Get_FhemWebList {
|
|||||||
sub SIGNALduino_Get_availableFirmware {
|
sub SIGNALduino_Get_availableFirmware {
|
||||||
my ($hash, @a) = @_;
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
if ($missingModulSIGNALduino =~ m/JSON/ )
|
if ( !HAS_JSON )
|
||||||
{
|
{
|
||||||
$hash->{logMethod}->($hash->{NAME}, 1, "$hash->{NAME}: get $a[0] failed. Please install Perl module JSON. Example: sudo apt-get install libjson-perl");
|
$hash->{logMethod}->($hash->{NAME}, 1, "$hash->{NAME}: get $a[0] failed. Please install Perl module JSON. Example: sudo apt-get install libjson-perl");
|
||||||
return "$a[0]: \n\nFetching from github is not possible. Please install JSON. Example:<br><code>sudo apt-get install libjson-perl</code>";
|
return "$a[0]: \n\nFetching from github is not possible. Please install JSON. Example:<br><code>sudo apt-get install libjson-perl</code>";
|
||||||
@ -2940,7 +2942,8 @@ sub SIGNALduino_Parse_MN {
|
|||||||
my $method = $hash->{protocolObject}->getProperty($id,'method',undef);
|
my $method = $hash->{protocolObject}->getProperty($id,'method',undef);
|
||||||
my @methodReturn = defined $method ? $method->($hash->{protocolObject},$rawData) : ($rawData);
|
my @methodReturn = defined $method ? $method->($hash->{protocolObject},$rawData) : ($rawData);
|
||||||
if ($#methodReturn != 0) {
|
if ($#methodReturn != 0) {
|
||||||
$hash->{logMethod}->($name, 4, qq{$name: Parse_MN, Error! method $methodReturn[1]});
|
my $vl = $methodReturn[1] =~ /missing\smodule/xms ? 1 : 4;
|
||||||
|
$hash->{logMethod}->($name, $vl, qq{$name: Parse_MN, Error! method $methodReturn[1]});
|
||||||
next mnIDLoop;
|
next mnIDLoop;
|
||||||
}
|
}
|
||||||
$dmsg = sprintf('%s%s',$hash->{protocolObject}->checkProperty($id,'preamble',''),$methodReturn[0]);
|
$dmsg = sprintf('%s%s',$hash->{protocolObject}->checkProperty($id,'preamble',''),$methodReturn[0]);
|
||||||
@ -3958,6 +3961,7 @@ sub SIGNALduino_githubParseHttpResponse {
|
|||||||
}
|
}
|
||||||
elsif($data ne '' && defined($hardware)) # wenn die Abfrage erfolgreich war ($data enthaelt die Ergebnisdaten des HTTP Aufrufes)
|
elsif($data ne '' && defined($hardware)) # wenn die Abfrage erfolgreich war ($data enthaelt die Ergebnisdaten des HTTP Aufrufes)
|
||||||
{
|
{
|
||||||
|
|
||||||
my $json_array = decode_json($data);
|
my $json_array = decode_json($data);
|
||||||
#print Dumper($json_array);
|
#print Dumper($json_array);
|
||||||
if ($param->{command} eq 'queryReleases') {
|
if ($param->{command} eq 'queryReleases') {
|
||||||
|
@ -13,7 +13,9 @@ package lib::SD_Protocols;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Carp qw(croak carp);
|
use Carp qw(croak carp);
|
||||||
use Digest::CRC;
|
use constant HAS_DigestCRC => defined eval { require Digest::CRC; };
|
||||||
|
use constant HAS_JSON => defined eval { require JSON; };
|
||||||
|
|
||||||
our $VERSION = '2.05';
|
our $VERSION = '2.05';
|
||||||
use Storable qw(dclone);
|
use Storable qw(dclone);
|
||||||
use Scalar::Util qw(blessed);
|
use Scalar::Util qw(blessed);
|
||||||
@ -142,7 +144,11 @@ sub LoadHashFromJson {
|
|||||||
my $json_text = do { local $/ = undef; <$json_fh> };
|
my $json_text = do { local $/ = undef; <$json_fh> };
|
||||||
close $json_fh or croak "Can't close '$filename' after reading";
|
close $json_fh or croak "Can't close '$filename' after reading";
|
||||||
|
|
||||||
use JSON;
|
if (!HAS_JSON)
|
||||||
|
{
|
||||||
|
croak("Perl Module JSON not availble. Needs to be installed.");
|
||||||
|
}
|
||||||
|
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
$json = $json->relaxed(1);
|
$json = $json->relaxed(1);
|
||||||
my $ver = $json->incr_parse($json_text);
|
my $ver = $json->incr_parse($json_text);
|
||||||
@ -1819,7 +1825,13 @@ sub ConvBresser_6in1 {
|
|||||||
my $hexLength = length ($hexData);
|
my $hexLength = length ($hexData);
|
||||||
|
|
||||||
return ( 1, 'ConvBresser_6in1, hexData is to short' ) if ( $hexLength < 36 ); # check double, in def length_min set
|
return ( 1, 'ConvBresser_6in1, hexData is to short' ) if ( $hexLength < 36 ); # check double, in def length_min set
|
||||||
|
|
||||||
|
|
||||||
|
return ( 1,'ConvBresser_6in1, missing module , please install modul Digest::CRC' )
|
||||||
|
if (!HAS_DigestCRC);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
my $crc = substr( $hexData, 0, 4 );
|
my $crc = substr( $hexData, 0, 4 );
|
||||||
my $ctx = Digest::CRC->new(width => 16, poly => 0x1021);
|
my $ctx = Digest::CRC->new(width => 16, poly => 0x1021);
|
||||||
my $calcCrc = sprintf( "%04X", $ctx->add( pack 'H*', substr( $hexData, 4, 30 ) )->digest );
|
my $calcCrc = sprintf( "%04X", $ctx->add( pack 'H*', substr( $hexData, 4, 30 ) )->digest );
|
||||||
@ -1858,6 +1870,9 @@ sub ConvPCA301 {
|
|||||||
'ConvPCA301, Usage: Input #1, $hexData needs to be at least 24 chars long'
|
'ConvPCA301, Usage: Input #1, $hexData needs to be at least 24 chars long'
|
||||||
) if ( length($hexData) < 24 ); # check double, in def length_min set
|
) if ( length($hexData) < 24 ); # check double, in def length_min set
|
||||||
|
|
||||||
|
return ( 1,'ConvPCA301, missing module , please install modul Digest::CRC' )
|
||||||
|
if (!HAS_DigestCRC);
|
||||||
|
|
||||||
my $checksum = substr( $hexData, 20, 4 );
|
my $checksum = substr( $hexData, 20, 4 );
|
||||||
my $ctx = Digest::CRC->new(
|
my $ctx = Digest::CRC->new(
|
||||||
width => 16,
|
width => 16,
|
||||||
@ -1980,6 +1995,9 @@ sub ConvLaCrosse {
|
|||||||
return ( 1,'ConvLaCrosse, Usage: Input #1, $hexData needs to be at least 8 chars long' )
|
return ( 1,'ConvLaCrosse, Usage: Input #1, $hexData needs to be at least 8 chars long' )
|
||||||
if ( length($hexData) < 8 ) ; # check number of length for this sub to not throw an error
|
if ( length($hexData) < 8 ) ; # check number of length for this sub to not throw an error
|
||||||
|
|
||||||
|
return ( 1,'ConvLaCrosse, missing module , please install modul Digest::CRC' )
|
||||||
|
if (!HAS_DigestCRC);
|
||||||
|
|
||||||
my $ctx = Digest::CRC->new( width => 8, poly => 0x31 );
|
my $ctx = Digest::CRC->new( width => 8, poly => 0x31 );
|
||||||
my $calcCrc = $ctx->add( pack 'H*', substr( $hexData, 0, 8 ) )->digest;
|
my $calcCrc = $ctx->add( pack 'H*', substr( $hexData, 0, 8 ) )->digest;
|
||||||
my $checksum = sprintf( "%d", hex( substr( $hexData, 8, 2 ) ) );
|
my $checksum = sprintf( "%d", hex( substr( $hexData, 8, 2 ) ) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user