mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-07 19:04:20 +00:00
21_OWAD.pm: Bugfix
git-svn-id: https://svn.fhem.de/fhem/trunk@8520 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
8a25bef34c
commit
796fe16fd2
@ -74,9 +74,23 @@ package main;
|
|||||||
use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
|
use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use GPUtils qw(:all);
|
||||||
|
use Time::HiRes qw( gettimeofday );
|
||||||
|
|
||||||
|
#add FHEM/lib to @INC if it's not allready included. Should rather be in fhem.pl than here though...
|
||||||
|
BEGIN {
|
||||||
|
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||||
|
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||||
|
push @INC,$inc."/lib";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
use ProtoThreads;
|
||||||
|
no warnings 'deprecated';
|
||||||
sub Log($$);
|
sub Log($$);
|
||||||
|
|
||||||
my $owx_version="5.12";
|
my $owx_version="5.20";
|
||||||
#-- fixed raw channel name, flexible channel name
|
#-- fixed raw channel name, flexible channel name
|
||||||
my @owg_fixed = ("A","B","C","D");
|
my @owg_fixed = ("A","B","C","D");
|
||||||
my @owg_channel = ("A","B","C","D");
|
my @owg_channel = ("A","B","C","D");
|
||||||
@ -143,9 +157,11 @@ sub OWAD_Initialize ($) {
|
|||||||
$hash->{UndefFn} = "OWAD_Undef";
|
$hash->{UndefFn} = "OWAD_Undef";
|
||||||
$hash->{GetFn} = "OWAD_Get";
|
$hash->{GetFn} = "OWAD_Get";
|
||||||
$hash->{SetFn} = "OWAD_Set";
|
$hash->{SetFn} = "OWAD_Set";
|
||||||
|
$hash->{NotifyFn}= "OWAD_Notify";
|
||||||
|
$hash->{InitFn} = "OWAD_Init";
|
||||||
$hash->{AttrFn} = "OWAD_Attr";
|
$hash->{AttrFn} = "OWAD_Attr";
|
||||||
|
|
||||||
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2450 loglevel:0,1,2,3,4,5 ".
|
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2450 verbose:0,1,2,3,4,5 ".
|
||||||
"stateAL0 stateAL1 stateAH0 stateAH1 ".
|
"stateAL0 stateAL1 stateAH0 stateAH1 ".
|
||||||
"interval ".
|
"interval ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
@ -174,8 +190,6 @@ sub OWAD_Initialize ($) {
|
|||||||
$hash->{owg_vlow} = [];
|
$hash->{owg_vlow} = [];
|
||||||
$hash->{owg_vhigh} = [];
|
$hash->{owg_vhigh} = [];
|
||||||
|
|
||||||
#-- this function is needed for asynchronous execution of the device reads
|
|
||||||
$hash->{AfterExecuteFn} = "OWXAD_BinValues";
|
|
||||||
#-- make sure OWX is loaded so OWX_CRC is available if running with OWServer
|
#-- make sure OWX is loaded so OWX_CRC is available if running with OWServer
|
||||||
main::LoadModule("OWX");
|
main::LoadModule("OWX");
|
||||||
}
|
}
|
||||||
@ -250,24 +264,57 @@ sub OWAD_Define ($$) {
|
|||||||
$hash->{PRESENT} = 0;
|
$hash->{PRESENT} = 0;
|
||||||
$hash->{INTERVAL} = $interval;
|
$hash->{INTERVAL} = $interval;
|
||||||
$hash->{ERRCOUNT} = 0;
|
$hash->{ERRCOUNT} = 0;
|
||||||
$hash->{ASYNC} = 0; #-- false for now
|
|
||||||
|
|
||||||
#-- Couple to I/O device
|
#-- Couple to I/O device
|
||||||
AssignIoPort($hash);
|
AssignIoPort($hash);
|
||||||
if( !defined($hash->{IODev}->{NAME}) | !defined($hash->{IODev}) ){
|
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||||
return "OWAD: Warning, no 1-Wire I/O device found for $name.";
|
return "OWAD: Warning, no 1-Wire I/O device found for $name.";
|
||||||
|
} else {
|
||||||
|
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||||
}
|
}
|
||||||
|
|
||||||
$main::modules{OWAD}{defptr}{$id} = $hash;
|
$main::modules{OWAD}{defptr}{$id} = $hash;
|
||||||
#--
|
#--
|
||||||
readingsSingleUpdate($hash,"state","defined",1);
|
readingsSingleUpdate($hash,"state","defined",1);
|
||||||
Log 3, "OWAD: Device $name defined.";
|
Log 3, "OWAD: Device $name defined.";
|
||||||
|
|
||||||
#-- Initialization reading according to interface type
|
$hash->{NOTIFYDEV} = "global";
|
||||||
my $interface= $hash->{IODev}->{TYPE};
|
|
||||||
|
|
||||||
|
if ($init_done) {
|
||||||
|
OWAD_Init($hash);
|
||||||
|
}
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
#
|
||||||
|
# OWAD_Notify Function -
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
# dev = device
|
||||||
|
#
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
sub OWAD_Notify ($$) {
|
||||||
|
my ($hash,$dev) = @_;
|
||||||
|
if( grep(m/^(INITIALIZED|REREADCFG)$/, @{$dev->{CHANGED}}) ) {
|
||||||
|
OWAD_Init($hash);
|
||||||
|
} elsif( grep(m/^SAVE$/, @{$dev->{CHANGED}}) ) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################################################################################
|
||||||
|
#
|
||||||
|
# OWAD_Init Function -
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
#
|
||||||
|
#
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
|
sub OWAD_Init ($) {
|
||||||
|
my ($hash)=@_;
|
||||||
#-- Start timer for updates
|
#-- Start timer for updates
|
||||||
InternalTimer(time()+60, "OWAD_GetValues", $hash, 0);
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer(gettimeofday()+10, "OWAD_InitializeDevice", $hash, 0);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,7 +343,7 @@ sub OWAD_Attr(@) {
|
|||||||
$hash->{INTERVAL} = $value;
|
$hash->{INTERVAL} = $value;
|
||||||
if ($init_done) {
|
if ($init_done) {
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 1);
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 0);
|
||||||
}
|
}
|
||||||
last;
|
last;
|
||||||
};
|
};
|
||||||
@ -307,7 +354,17 @@ sub OWAD_Attr(@) {
|
|||||||
if( $hash->{READINGS}{"state"}{VAL} eq "defined" );
|
if( $hash->{READINGS}{"state"}{VAL} eq "defined" );
|
||||||
$ret = OWAD_Set($hash,($name,$key,$value));
|
$ret = OWAD_Set($hash,($name,$key,$value));
|
||||||
last;
|
last;
|
||||||
}
|
};
|
||||||
|
$key eq "IODev" and do {
|
||||||
|
AssignIoPort($hash,$value);
|
||||||
|
if( defined($hash->{IODev}) ) {
|
||||||
|
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||||
|
if ($init_done) {
|
||||||
|
OWAD_Init($hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} elsif ( $do eq "del" ) {
|
} elsif ( $do eq "del" ) {
|
||||||
ARGUMENT_HANDLER: {
|
ARGUMENT_HANDLER: {
|
||||||
@ -540,9 +597,17 @@ sub OWAD_Get($@) {
|
|||||||
|
|
||||||
#-- get present
|
#-- get present
|
||||||
if($a[1] eq "present") {
|
if($a[1] eq "present") {
|
||||||
#-- hash of the busmaster
|
#-- asynchronous mode
|
||||||
my $master = $hash->{IODev};
|
if( $hash->{ASYNC} ){
|
||||||
$value = OWX_Verify($master,$owx_dev);
|
my ($task,$task_state);
|
||||||
|
eval {
|
||||||
|
OWX_ASYNC_RunToCompletion($hash,OWX_ASYNC_PT_Verify($hash));
|
||||||
|
};
|
||||||
|
return GP_Catch($@) if $@;
|
||||||
|
return "$name.present => ".ReadingsVal($name,"present","unknown");
|
||||||
|
} else {
|
||||||
|
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||||
|
}
|
||||||
$hash->{PRESENT} = $value;
|
$hash->{PRESENT} = $value;
|
||||||
return "$name.present => $value";
|
return "$name.present => $value";
|
||||||
}
|
}
|
||||||
@ -564,6 +629,11 @@ sub OWAD_Get($@) {
|
|||||||
#-- OWX interface
|
#-- OWX interface
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
$ret = OWXAD_GetPage($hash,"reading",1);
|
$ret = OWXAD_GetPage($hash,"reading",1);
|
||||||
|
}elsif( $interface eq "OWX_ASYNC" ){
|
||||||
|
eval {
|
||||||
|
$ret = OWX_ASYNC_RunToCompletion($hash,OWXAD_PT_GetPage($hash,"reading",1));
|
||||||
|
};
|
||||||
|
$ret = GP_Catch($@) if $@;
|
||||||
#-- OWFS interface
|
#-- OWFS interface
|
||||||
}elsif( $interface eq "OWServer" ){
|
}elsif( $interface eq "OWServer" ){
|
||||||
$ret = OWFSAD_GetPage($hash,"reading",1);
|
$ret = OWFSAD_GetPage($hash,"reading",1);
|
||||||
@ -573,7 +643,7 @@ sub OWAD_Get($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
if( defined($ret) ){
|
if( defined($ret) ){
|
||||||
$hash->{ERRCOUNT}=$hash->{ERRCOUNT}+1;
|
$hash->{ERRCOUNT}=$hash->{ERRCOUNT}+1;
|
||||||
if( $hash->{ERRCOUNT} > 5 ){
|
if( $hash->{ERRCOUNT} > 5 ){
|
||||||
$hash->{INTERVAL} = 9999;
|
$hash->{INTERVAL} = 9999;
|
||||||
@ -588,6 +658,11 @@ sub OWAD_Get($@) {
|
|||||||
#-- OWX interface
|
#-- OWX interface
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
$ret = OWXAD_GetPage($hash,"alarm",1);
|
$ret = OWXAD_GetPage($hash,"alarm",1);
|
||||||
|
}elsif( $interface eq "OWX_ASYNC" ){
|
||||||
|
eval {
|
||||||
|
$ret = OWX_ASYNC_RunToCompletion($hash,OWXAD_PT_GetPage($hash,"alarm",1));
|
||||||
|
};
|
||||||
|
$ret = GP_Catch($@) if $@;
|
||||||
#-- OWFS interface
|
#-- OWFS interface
|
||||||
}elsif( $interface eq "OWServer" ){
|
}elsif( $interface eq "OWServer" ){
|
||||||
$ret = OWFSAD_GetPage($hash,"alarm",1);
|
$ret = OWFSAD_GetPage($hash,"alarm",1);
|
||||||
@ -597,7 +672,7 @@ sub OWAD_Get($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
if( defined($ret) ){
|
if( defined($ret) ){
|
||||||
$hash->{ERRCOUNT}=$hash->{ERRCOUNT}+1;
|
$hash->{ERRCOUNT}=$hash->{ERRCOUNT}+1;
|
||||||
if( $hash->{ERRCOUNT} > 5 ){
|
if( $hash->{ERRCOUNT} > 5 ){
|
||||||
$hash->{INTERVAL} = 9999;
|
$hash->{INTERVAL} = 9999;
|
||||||
@ -620,6 +695,11 @@ sub OWAD_Get($@) {
|
|||||||
#-- OWX interface
|
#-- OWX interface
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
$ret = OWXAD_GetPage($hash,"status",1);
|
$ret = OWXAD_GetPage($hash,"status",1);
|
||||||
|
}elsif( $interface eq "OWX_ASYNC" ){
|
||||||
|
eval {
|
||||||
|
$ret = OWX_ASYNC_RunToCompletion($hash,OWXAD_PT_GetPage($hash,"status",1));
|
||||||
|
};
|
||||||
|
$ret = GP_Catch($@) if $@;
|
||||||
#-- OWFS interface
|
#-- OWFS interface
|
||||||
}elsif( $interface eq "OWServer" ){
|
}elsif( $interface eq "OWServer" ){
|
||||||
$ret = OWFSAD_GetPage($hash,"status",1);
|
$ret = OWFSAD_GetPage($hash,"status",1);
|
||||||
@ -629,7 +709,7 @@ sub OWAD_Get($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
if( defined($ret) ){
|
if( defined($ret) ){
|
||||||
$hash->{ERRCOUNT}=$hash->{ERRCOUNT}+1;
|
$hash->{ERRCOUNT}=$hash->{ERRCOUNT}+1;
|
||||||
if( $hash->{ERRCOUNT} > 5 ){
|
if( $hash->{ERRCOUNT} > 5 ){
|
||||||
$hash->{INTERVAL} = 9999;
|
$hash->{INTERVAL} = 9999;
|
||||||
@ -690,17 +770,13 @@ sub OWAD_GetValues($) {
|
|||||||
my $ret = "";
|
my $ret = "";
|
||||||
my ($ret1,$ret2,$ret3);
|
my ($ret1,$ret2,$ret3);
|
||||||
|
|
||||||
#-- check if device needs to be initialized
|
|
||||||
OWAD_InitializeDevice($hash)
|
|
||||||
if( $hash->{READINGS}{"state"}{VAL} eq "defined");
|
|
||||||
|
|
||||||
#-- define warnings
|
#-- define warnings
|
||||||
my $warn = "none";
|
my $warn = "none";
|
||||||
$hash->{ALARM} = "0";
|
$hash->{ALARM} = "0";
|
||||||
|
|
||||||
#-- restart timer for updates
|
#-- restart timer for updates
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(time()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 1);
|
InternalTimer(time()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 0);
|
||||||
|
|
||||||
#-- Get readings, alarms and stati according to interface type
|
#-- Get readings, alarms and stati according to interface type
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
@ -710,6 +786,13 @@ sub OWAD_GetValues($) {
|
|||||||
$ret2 = OWXAD_GetPage($hash,"alarm",0);
|
$ret2 = OWXAD_GetPage($hash,"alarm",0);
|
||||||
$ret3 = OWXAD_GetPage($hash,"status",1);
|
$ret3 = OWXAD_GetPage($hash,"status",1);
|
||||||
#}
|
#}
|
||||||
|
}elsif( $interface eq "OWX_ASYNC" ){
|
||||||
|
eval {
|
||||||
|
OWX_ASYNC_Schedule( $hash, OWXAD_PT_GetPage($hash,"reading",0));
|
||||||
|
OWX_ASYNC_Schedule( $hash, OWXAD_PT_GetPage($hash,"alarm",0));
|
||||||
|
OWX_ASYNC_Schedule( $hash, OWXAD_PT_GetPage($hash,"status",1));
|
||||||
|
};
|
||||||
|
$ret .= GP_Catch($@) if $@;
|
||||||
}elsif( $interface eq "OWServer" ){
|
}elsif( $interface eq "OWServer" ){
|
||||||
$ret1 = OWFSAD_GetPage($hash,"reading",0);
|
$ret1 = OWFSAD_GetPage($hash,"reading",0);
|
||||||
$ret2 = OWFSAD_GetPage($hash,"alarm",0);
|
$ret2 = OWFSAD_GetPage($hash,"alarm",0);
|
||||||
@ -799,6 +882,12 @@ sub OWAD_InitializeDevice($) {
|
|||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
$ret1 = OWXAD_SetPage($hash,"status");
|
$ret1 = OWXAD_SetPage($hash,"status");
|
||||||
$ret2 = OWXAD_SetPage($hash,"alarm");
|
$ret2 = OWXAD_SetPage($hash,"alarm");
|
||||||
|
}elsif( $interface eq "OWX_ASYNC" ){
|
||||||
|
eval {
|
||||||
|
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"status"));
|
||||||
|
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"alarm"));
|
||||||
|
};
|
||||||
|
$ret .= GP_Catch($@) if $@;
|
||||||
#-- OWFS interface
|
#-- OWFS interface
|
||||||
}elsif( $interface eq "OWServer" ){
|
}elsif( $interface eq "OWServer" ){
|
||||||
$ret1 = OWFSAD_SetPage($hash,"status");
|
$ret1 = OWFSAD_SetPage($hash,"status");
|
||||||
@ -816,7 +905,7 @@ sub OWAD_InitializeDevice($) {
|
|||||||
#-- Set state to initialized
|
#-- Set state to initialized
|
||||||
readingsSingleUpdate($hash,"state","initialized",1);
|
readingsSingleUpdate($hash,"state","initialized",1);
|
||||||
|
|
||||||
return undef;
|
return OWAD_GetValues($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#######################################################################################
|
#######################################################################################
|
||||||
@ -871,7 +960,7 @@ sub OWAD_Set($@) {
|
|||||||
# update timer
|
# update timer
|
||||||
$hash->{INTERVAL} = $value;
|
$hash->{INTERVAL} = $value;
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 1);
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 0);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -916,6 +1005,11 @@ sub OWAD_Set($@) {
|
|||||||
#-- OWX interface
|
#-- OWX interface
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
$ret = OWXAD_SetPage($hash,"status");
|
$ret = OWXAD_SetPage($hash,"status");
|
||||||
|
}elsif( $interface eq "OWX_ASYNC" ){
|
||||||
|
eval {
|
||||||
|
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"status"));
|
||||||
|
};
|
||||||
|
$ret = GP_Catch($@) if $@;
|
||||||
#-- OWFS interface
|
#-- OWFS interface
|
||||||
}elsif( $interface eq "OWServer" ){
|
}elsif( $interface eq "OWServer" ){
|
||||||
$ret = OWFSAD_SetPage($hash,"status");
|
$ret = OWFSAD_SetPage($hash,"status");
|
||||||
@ -962,6 +1056,11 @@ sub OWAD_Set($@) {
|
|||||||
#-- OWX interface
|
#-- OWX interface
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
$ret = OWXAD_SetPage($hash,"alarm");
|
$ret = OWXAD_SetPage($hash,"alarm");
|
||||||
|
}elsif( $interface eq "OWX_ASYNC" ){
|
||||||
|
eval {
|
||||||
|
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"status"));
|
||||||
|
};
|
||||||
|
$ret = GP_Catch($@) if $@;
|
||||||
#-- OWFS interface
|
#-- OWFS interface
|
||||||
}elsif( $interface eq "OWServer" ){
|
}elsif( $interface eq "OWServer" ){
|
||||||
$ret = OWFSAD_SetPage($hash,"alarm");
|
$ret = OWFSAD_SetPage($hash,"alarm");
|
||||||
@ -1221,34 +1320,35 @@ sub OWFSAD_SetPage($$) {
|
|||||||
########################################################################################
|
########################################################################################
|
||||||
|
|
||||||
sub OWXAD_BinValues($$$$$$$$) {
|
sub OWXAD_BinValues($$$$$$$$) {
|
||||||
my ($hash, $context, $success, $reset, $owx_dev, $command, $final, $res) = @_;
|
my ($hash, $context, $success, $reset, $owx_dev, $command, $numread, $res) = @_;
|
||||||
|
|
||||||
#-- always check for success, unused are reset
|
#-- always check for success, unused are reset
|
||||||
return unless ($success and $context);
|
return unless ($success and $context);
|
||||||
#Log 1,"OWXAD_BinValues context = $context";
|
#Log 1,"OWXAD_BinValues context = $context";
|
||||||
|
my $final = ($context =~ /\.final$/ );
|
||||||
|
|
||||||
my ($i,$j,$k,@data,$ow_thn,$ow_tln);
|
my ($i,$j,$k,@data,$ow_thn,$ow_tln);
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
@data=split(//,substr($res,3,10));
|
@data=split(//,$res);
|
||||||
return "invalid data length, ".int(@data)." instead of 10 bytes"
|
return "invalid data length, ".int(@data)." instead of 10 bytes"
|
||||||
if (@data != 10);
|
if (@data != 10);
|
||||||
return "invalid CRC"
|
return "invalid CRC"
|
||||||
if (OWX_CRC16(substr($res,9,11),$data[11],$data[12])==0);
|
if (OWX_CRC16($command.substr($res,0,8),$data[8],$data[9])==0);
|
||||||
|
|
||||||
#=============== get the voltage reading ===============================
|
#=============== get the voltage reading ===============================
|
||||||
if( $context eq "ds2450.getreading"){
|
if( $context =~ /^ds2450.getreading/ ){
|
||||||
for( $i=0;$i<int(@owg_fixed);$i++){
|
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||||
$hash->{owg_val}->[$i]= (ord($data[2*$i])+256*ord($data[1+2*$i]) )/(1<<$owg_resoln[$i]) * $owg_range[$i]/1000;
|
$hash->{owg_val}->[$i]= (ord($data[2*$i])+256*ord($data[1+2*$i]) )/(1<<$owg_resoln[$i]) * $owg_range[$i]/1000;
|
||||||
}
|
}
|
||||||
#=============== get the alarm reading ===============================
|
#=============== get the alarm reading ===============================
|
||||||
} elsif ( $context eq "ds2450.getalarm" ) {
|
} elsif ( $context =~ /^ds2450.getalarm/ ){
|
||||||
for( $i=0;$i<int(@owg_fixed);$i++){
|
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||||
$hash->{owg_vlow}->[$i] = int(ord($data[2*$i])/256 * $owg_range[$i]+0.5)/1000;
|
$hash->{owg_vlow}->[$i] = int(ord($data[2*$i])/256 * $owg_range[$i]+0.5)/1000;
|
||||||
$hash->{owg_vhigh}->[$i] = int(ord($data[1+2*$i])/256 * $owg_range[$i]+0.5)/1000;
|
$hash->{owg_vhigh}->[$i] = int(ord($data[1+2*$i])/256 * $owg_range[$i]+0.5)/1000;
|
||||||
}
|
}
|
||||||
#=============== get the status reading ===============================
|
#=============== get the status reading ===============================
|
||||||
} elsif ( $context eq "ds2450.getstatus" ) {
|
} elsif ( $context =~ /^ds2450.getstatus/ ) {
|
||||||
my ($sb1,$sb2);
|
my ($sb1,$sb2);
|
||||||
for( my $i=0;$i<int(@owg_fixed);$i++){
|
for( my $i=0;$i<int(@owg_fixed);$i++){
|
||||||
$sb1 = ord($data[2*$i]);
|
$sb1 = ord($data[2*$i]);
|
||||||
@ -1304,7 +1404,7 @@ sub OWXAD_BinValues($$$$$$$$) {
|
|||||||
}
|
}
|
||||||
#-- and now from raw to formatted values
|
#-- and now from raw to formatted values
|
||||||
$hash->{PRESENT} = 1;
|
$hash->{PRESENT} = 1;
|
||||||
if( $final==1 ){
|
if( $final ){
|
||||||
my $value = OWAD_FormatValues($hash);
|
my $value = OWAD_FormatValues($hash);
|
||||||
Log 5, $value;
|
Log 5, $value;
|
||||||
}
|
}
|
||||||
@ -1321,9 +1421,9 @@ sub OWXAD_BinValues($$$$$$$$) {
|
|||||||
#
|
#
|
||||||
########################################################################################
|
########################################################################################
|
||||||
|
|
||||||
sub OWXAD_GetPage($$$) {
|
sub OWXAD_GetPage($$$@) {
|
||||||
|
|
||||||
my ($hash,$page,$final) = @_;
|
my ($hash,$page,$final,$sync) = @_;
|
||||||
|
|
||||||
my ($select, $res, $res2, $res3, @data, $an, $vn);
|
my ($select, $res, $res2, $res3, @data, $an, $vn);
|
||||||
|
|
||||||
@ -1339,22 +1439,13 @@ sub OWXAD_GetPage($$$) {
|
|||||||
#=============== get the voltage reading ===============================
|
#=============== get the voltage reading ===============================
|
||||||
if( $page eq "reading") {
|
if( $page eq "reading") {
|
||||||
#-- issue the match ROM command \x55 and the start conversion command
|
#-- issue the match ROM command \x55 and the start conversion command
|
||||||
#-- asynchronous mode
|
OWX_Reset($master);
|
||||||
# difficult here, shoul dbe put into Binvalues as in OWSWITCH
|
$res= OWX_Complex($master,$owx_dev,"\x3C\x0F\x00\xFF\xFF",0);
|
||||||
if( $hash->{ASYNC} ){
|
if( $res eq 0 ){
|
||||||
if (!OWX_Execute( $master, "getpageconvert", 1, $owx_dev, "\x3C\x0F\x00\xFF\xFF", 0, 20 )) {
|
return "not accessible for conversion";
|
||||||
return "not accessible for conversion";
|
|
||||||
}
|
|
||||||
#-- synchronous mode
|
|
||||||
} else {
|
|
||||||
OWX_Reset($master);
|
|
||||||
$res= OWX_Complex($master,$owx_dev,"\x3C\x0F\x00\xFF\xFF",0);
|
|
||||||
if( $res eq 0 ){
|
|
||||||
return "not accessible for conversion";
|
|
||||||
}
|
|
||||||
#-- conversion needs some 5 ms per channel
|
|
||||||
select(undef,undef,undef,0.02);
|
|
||||||
}
|
}
|
||||||
|
#-- conversion needs some 5 ms per channel
|
||||||
|
select(undef,undef,undef,0.02);
|
||||||
|
|
||||||
#-- issue the match ROM command \x55 and the read conversion page command
|
#-- issue the match ROM command \x55 and the read conversion page command
|
||||||
# \xAA\x00\x00
|
# \xAA\x00\x00
|
||||||
@ -1373,29 +1464,17 @@ sub OWXAD_GetPage($$$) {
|
|||||||
} else {
|
} else {
|
||||||
return "wrong memory page requested from $owx_dev";
|
return "wrong memory page requested from $owx_dev";
|
||||||
}
|
}
|
||||||
#-- asynchronous mode
|
my $context = "ds2450.get".$page.($final ? ".final" : "");
|
||||||
if( $hash->{ASYNC} ){
|
#-- reset the bus
|
||||||
#-- reading 9 + 3 + 8 data bytes and 2 CRC bytes = 22 bytes
|
OWX_Reset($master);
|
||||||
if (OWX_Execute( $master, "ds2450.get".$page, 1, $owx_dev, $select, 10, undef)) {
|
#-- reading 9 + 3 + 8 data bytes and 2 CRC bytes = 22 bytes
|
||||||
return OWX_AwaitExecuteResponse( $master, "getpage$page", $owx_dev );
|
$res=OWX_Complex($master,$owx_dev,$select,10);
|
||||||
} else {
|
return "$owx_dev not accessible in reading page $page"
|
||||||
return "$owx_dev not accessible in reading $page page";
|
if( $res eq 0 );
|
||||||
}
|
return "$owx_dev has returned invalid data"
|
||||||
#-- synchronous mode
|
if( length($res)!=22);
|
||||||
} else {
|
#-- for processing we also need the 3 command bytes
|
||||||
#-- reset the bus
|
return OWXAD_BinValues($hash,$context,1,undef,$owx_dev,$select,10,substr($res,12,10));
|
||||||
OWX_Reset($master);
|
|
||||||
#-- reading 9 + 3 + 8 data bytes and 2 CRC bytes = 22 bytes
|
|
||||||
$res=OWX_Complex($master,$owx_dev,$select,10);
|
|
||||||
return "$owx_dev not accessible in reading page $page"
|
|
||||||
if( $res eq 0 );
|
|
||||||
return "$owx_dev has returned invalid data"
|
|
||||||
if( length($res)!=22);
|
|
||||||
#-- for processing we also need the 3 command bytes
|
|
||||||
OWXAD_BinValues($hash,"ds2450.get".$page,1,undef,$owx_dev,undef,$final,substr($res,9,13));
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
@ -1463,24 +1542,163 @@ sub OWXAD_SetPage($$) {
|
|||||||
} else {
|
} else {
|
||||||
return "wrong memory page write attempt";
|
return "wrong memory page write attempt";
|
||||||
}
|
}
|
||||||
#-- asynchronous mode
|
OWX_Reset($master);
|
||||||
if( $hash->{ASYNC} ){
|
$res=OWX_Complex($master,$owx_dev,$select,0);
|
||||||
if (OWX_Execute( $master, "setpage", 1, $owx_dev, $select, 0, undef )) {
|
if( $res eq 0 ){
|
||||||
return undef;
|
|
||||||
} else {
|
|
||||||
return "device $owx_dev not accessible for writing";
|
return "device $owx_dev not accessible for writing";
|
||||||
}
|
|
||||||
#-- synchronous mode
|
|
||||||
} else {
|
|
||||||
OWX_Reset($master);
|
|
||||||
$res=OWX_Complex($master,$owx_dev,$select,0);
|
|
||||||
if( $res eq 0 ){
|
|
||||||
return "device $owx_dev not accessible for writing";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWXAD_PT_GetPage - Get one memory page from device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
# page = "reading", "alarm" or "status"
|
||||||
|
# final= 1 if FormatValues is to be called
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWXAD_PT_GetPage($$$) {
|
||||||
|
|
||||||
|
my ($hash,$page,$final) = @_;
|
||||||
|
|
||||||
|
return PT_THREAD(sub {
|
||||||
|
|
||||||
|
my ($thread) = @_;
|
||||||
|
|
||||||
|
my ($res, $res2, $res3, @data, $an, $vn);
|
||||||
|
|
||||||
|
#-- ID of the device, hash of the busmaster
|
||||||
|
my $owx_dev = $hash->{ROM_ID};
|
||||||
|
my $master = $hash->{IODev};
|
||||||
|
|
||||||
|
my ($i,$j,$k);
|
||||||
|
|
||||||
|
PT_BEGIN($thread);
|
||||||
|
|
||||||
|
#=============== get the voltage reading ===============================
|
||||||
|
if( $page eq "reading") {
|
||||||
|
#-- issue the match ROM command \x55 and the start conversion command
|
||||||
|
|
||||||
|
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, "\x3C\x0F\x00\xFF\xFF", 0 );
|
||||||
|
$thread->{ExecuteTime} = gettimeofday() + 0.07; # was 0.02
|
||||||
|
PT_WAIT_THREAD($thread->{pt_execute});
|
||||||
|
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||||
|
|
||||||
|
PT_YIELD_UNTIL(gettimeofday() >= $thread->{ExecuteTime});
|
||||||
|
delete $thread->{ExecuteTime};
|
||||||
|
|
||||||
|
#-- issue the match ROM command \x55 and the read conversion page command
|
||||||
|
# \xAA\x00\x00
|
||||||
|
$thread->{'select'}="\xAA\x00\x00";
|
||||||
|
#=============== get the alarm reading ===============================
|
||||||
|
} elsif ( $page eq "alarm" ) {
|
||||||
|
#-- issue the match ROM command \x55 and the read alarm page command
|
||||||
|
# \xAA\x10\x00
|
||||||
|
$thread->{'select'}="\xAA\x10\x00";
|
||||||
|
#=============== get the status reading ===============================
|
||||||
|
} elsif ( $page eq "status" ) {
|
||||||
|
#-- issue the match ROM command \x55 and the read status memory page command
|
||||||
|
# \xAA\x08\x00 r
|
||||||
|
$thread->{'select'}="\xAA\x08\x00";
|
||||||
|
#=============== wrong value requested ===============================
|
||||||
|
} else {
|
||||||
|
die "wrong memory page requested from $owx_dev";
|
||||||
|
}
|
||||||
|
#-- reading 9 + 3 + 8 data bytes and 2 CRC bytes = 22 bytes
|
||||||
|
|
||||||
|
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $thread->{'select'}, 10 );
|
||||||
|
PT_WAIT_THREAD($thread->{pt_execute});
|
||||||
|
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||||
|
my $response = $thread->{pt_execute}->PT_RETVAL();
|
||||||
|
my $res = OWXAD_BinValues($hash,"ds2450.get".$page.($final ? ".final" : ""),1,1,$owx_dev,$thread->{'select'},10,$response);
|
||||||
|
if ($res) {
|
||||||
|
die $res;
|
||||||
|
}
|
||||||
|
PT_END;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWXAD_PT_SetPage - Set one page of device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
# page = "alarm" or "status"
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWXAD_PT_SetPage($$) {
|
||||||
|
|
||||||
|
my ($hash,$page) = @_;
|
||||||
|
|
||||||
|
return PT_THREAD(sub {
|
||||||
|
|
||||||
|
my ($thread) = @_;
|
||||||
|
my ($select, $res, $res2, $res3, @data);
|
||||||
|
|
||||||
|
#-- ID of the device, hash of the busmaster
|
||||||
|
my $owx_dev = $hash->{ROM_ID};
|
||||||
|
my $master = $hash->{IODev};
|
||||||
|
|
||||||
|
my ($i,$j,$k);
|
||||||
|
|
||||||
|
PT_BEGIN($thread);
|
||||||
|
|
||||||
|
#=============== set the alarm values ===============================
|
||||||
|
if ( $page eq "alarm" ) {
|
||||||
|
#-- issue the match ROM command \x55 and the set alarm page command
|
||||||
|
# \x55\x10\x00 reading 8 data bytes and 2 CRC bytes
|
||||||
|
$select="\x55\x10\x00";
|
||||||
|
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||||
|
$select .= sprintf "%c\xFF\xFF\xFF",int($hash->{owg_vlow}->[$i]*256000/$owg_range[$i]);
|
||||||
|
$select .= sprintf "%c\xFF\xFF\xFF",int($hash->{owg_vhigh}->[$i]*256000/$owg_range[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#++Use of uninitialized value within @owg_vlow in multiplication at
|
||||||
|
#++/usr/share/fhem/FHEM/21_OWAD.pm line 1362.
|
||||||
|
#=============== set the status ===============================
|
||||||
|
} elsif ( $page eq "status" ) {
|
||||||
|
my ($sb1,$sb2)=(0,0);
|
||||||
|
#-- issue the match ROM command \x55 and the set status memory page command
|
||||||
|
# \x55\x08\x00 reading 8 data bytes and 2 CRC bytes
|
||||||
|
$select="\x55\x08\x00";
|
||||||
|
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||||
|
#if( $owg_mode[$i] eq "input" ){
|
||||||
|
if( 1 > 0){
|
||||||
|
#-- resolution (TODO: check !)
|
||||||
|
$sb1 = $owg_resoln[$i] & 15;
|
||||||
|
#-- alarm enabled
|
||||||
|
if( defined($hash->{owg_slow}->[$i]) ){
|
||||||
|
$sb2 = ( $hash->{owg_slow}->[$i] ne 0 ) ? 4 : 0;
|
||||||
|
}
|
||||||
|
if( defined($hash->{owg_shigh}->[$i]) ){
|
||||||
|
$sb2 += ( $hash->{owg_shigh}->[$i] ne 0 ) ? 8 : 0;
|
||||||
|
}
|
||||||
|
#-- range
|
||||||
|
$sb2 |= 1
|
||||||
|
if( $owg_range[$i] > 2560 );
|
||||||
|
} else {
|
||||||
|
$sb1 = 128;
|
||||||
|
$sb2 = 0;
|
||||||
|
}
|
||||||
|
$select .= sprintf "%c\xFF\xFF\xFF",$sb1;
|
||||||
|
$select .= sprintf "%c\xFF\xFF\xFF",$sb2;
|
||||||
|
}
|
||||||
|
#=============== wrong page write attempt ===============================
|
||||||
|
} else {
|
||||||
|
PT_EXIT("wrong memory page write attempt");
|
||||||
|
}
|
||||||
|
#"setpage"
|
||||||
|
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $select, 0 );
|
||||||
|
PT_WAIT_THREAD($thread->{pt_execute});
|
||||||
|
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||||
|
PT_END;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
@ -1612,7 +1830,7 @@ sub OWXAD_SetPage($$) {
|
|||||||
href="#event-on-update-reading">event-on-update-reading</a>, <a
|
href="#event-on-update-reading">event-on-update-reading</a>, <a
|
||||||
href="#event-on-change-reading">event-on-change-reading</a>, <a
|
href="#event-on-change-reading">event-on-change-reading</a>, <a
|
||||||
href="#stateFormat">stateFormat</a>, <a href="#room"
|
href="#stateFormat">stateFormat</a>, <a href="#room"
|
||||||
>room</a>, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>,
|
>room</a>, <a href="#eventMap">eventMap</a>, <a href="#verbose">verbose</a>,
|
||||||
<a href="#webCmd">webCmd</a></li>
|
<a href="#webCmd">webCmd</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user