Behebung eines Timing-Problems für passive Adapter
git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1279 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
# via an active DS2480/DS2490/DS9097U bus master interface or
|
# via an active DS2480/DS2490/DS9097U bus master interface or
|
||||||
# via a passive DS9097 interface
|
# via a passive DS9097 interface
|
||||||
#
|
#
|
||||||
# Version 1.0 - February 21, 2012
|
# Version 1.01 - February 23, 2012
|
||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2011
|
# Prof. Dr. Peter A. Henning, 2011
|
||||||
#
|
#
|
||||||
@@ -366,53 +366,62 @@ sub OWX_Discover ($) {
|
|||||||
while( $owx_LastDeviceFlag==0 && $res!=0 ){
|
while( $owx_LastDeviceFlag==0 && $res!=0 ){
|
||||||
$res = $res & OWX_Next($hash,"discover");
|
$res = $res & OWX_Next($hash,"discover");
|
||||||
}
|
}
|
||||||
if( @owx_devs == 0){
|
|
||||||
return "OWX: No devices found ";
|
|
||||||
}
|
|
||||||
|
|
||||||
#-- Check, which of these is already defined in the cfg file
|
#-- Check, which of these is already defined in the cfg file
|
||||||
foreach my $owx_dev (@owx_devs) {
|
foreach my $owx_dev (@owx_devs) {
|
||||||
#-- two pieces of the ROM ID found on the bus
|
#-- two pieces of the ROM ID found on the bus
|
||||||
my $owx_rnf = substr($owx_dev,3,12);
|
my $owx_rnf = substr($owx_dev,3,12);
|
||||||
my $owx_f = substr($owx_dev,0,2);
|
my $owx_f = substr($owx_dev,0,2);
|
||||||
my $id_owx = $owx_f.".".$owx_rnf;
|
my $id_owx = $owx_f.".".$owx_rnf;
|
||||||
|
|
||||||
my $match = 0;
|
my $match = 0;
|
||||||
|
|
||||||
#-- check against all existing devices
|
#-- check against all existing devices
|
||||||
foreach my $fhem_dev (sort keys %main::defs) {
|
foreach my $fhem_dev (sort keys %main::defs) {
|
||||||
#-- all OW types start with OW
|
#-- all OW types start with OW
|
||||||
next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW");
|
next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW");
|
||||||
next if( $main::defs{$fhem_dev}{ROM_ID} eq "FF");
|
next if( $main::defs{$fhem_dev}{ROM_ID} eq "FF");
|
||||||
my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15);
|
my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15);
|
||||||
#-- testing if present in defined devices
|
#-- testing if present in defined devices
|
||||||
if( $id_fhem eq $id_owx ){
|
if( $id_fhem eq $id_owx ){
|
||||||
push(@owx_names,$main::defs{$fhem_dev}{NAME});
|
push(@owx_names,$main::defs{$fhem_dev}{NAME});
|
||||||
#-- replace the ROM ID by the proper value
|
#-- replace the ROM ID by the proper value
|
||||||
$main::defs{$fhem_dev}{ROM_ID}=$owx_dev;
|
$main::defs{$fhem_dev}{ROM_ID}=$owx_dev;
|
||||||
$match = 1;
|
$main::defs{$fhem_dev}{PRESENT}=1;
|
||||||
last;
|
$match = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#-- autocreate the device
|
#-- autocreate the device
|
||||||
if( $match==0 ){
|
if( $match==0 ){
|
||||||
#-- Default name OWX_FF_XXXXXXXXXXXX, default type = OWX_FF
|
#-- Default name OWX_FF_XXXXXXXXXXXX, default type = OWX_FF
|
||||||
my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf;
|
my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf;
|
||||||
|
|
||||||
if( $owx_f eq "10" ){
|
if( $owx_f eq "10" ){
|
||||||
#-- Family 10 = Temperature sensor, assume DS1820 as default
|
#-- Family 10 = Temperature sensor, assume DS1820 as default
|
||||||
CommandDefine(undef,"$name OWTEMP DS1820 $owx_rnf");
|
CommandDefine(undef,"$name OWTEMP DS1820 $owx_rnf");
|
||||||
#-- default room
|
$main::defs{$name}{PRESENT}=1;
|
||||||
CommandAttr (undef,"$name IODev $hash->{NAME}");
|
#-- default room
|
||||||
CommandAttr (undef,"$name room OWX");
|
CommandAttr (undef,"$name IODev $hash->{NAME}");
|
||||||
push(@owx_names,$name);
|
CommandAttr (undef,"$name room OWX");
|
||||||
} else {
|
push(@owx_names,$name);
|
||||||
Log 1, "OWX: Undefined device family $owx_f";
|
} else {
|
||||||
|
Log 1, "OWX: Undefined device family $owx_f";
|
||||||
|
}
|
||||||
|
#-- replace the ROM ID by the proper value
|
||||||
|
$main::defs{$name}{ROM_ID}=$owx_dev;
|
||||||
}
|
}
|
||||||
#-- replace the ROM ID by the proper value
|
|
||||||
$main::defs{$name}{ROM_ID}=$owx_dev;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-- final step: Undefine all 1-Wire devices which are not on the bus
|
||||||
|
# TODO: IF WE HAVE MULTIPLE IO Devices ???
|
||||||
|
foreach my $fhem_dev (sort keys %main::defs) {
|
||||||
|
#-- all OW types start with OW
|
||||||
|
next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW");
|
||||||
|
next if( $main::defs{$fhem_dev}{ROM_ID} eq "FF");
|
||||||
|
next if( $main::defs{$fhem_dev}{PRESENT} == 1);
|
||||||
|
CommandDelete(undef,$main::defs{$fhem_dev}{NAME});
|
||||||
}
|
}
|
||||||
Log 1, "OWX: 1-Wire devices found (".join(",",@owx_names).")";
|
Log 1, "OWX: 1-Wire devices found (".join(",",@owx_names).")";
|
||||||
return "OWX: 1-Wire devices found (".join(",",@owx_names).")";
|
return "OWX: 1-Wire devices found (".join(",",@owx_names).")";
|
||||||
@@ -566,7 +575,6 @@ sub OWX_Search ($$) {
|
|||||||
$owx_LastFamilyDiscrepancy = 0;
|
$owx_LastFamilyDiscrepancy = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#print "Reset ok when starting search \n";
|
|
||||||
|
|
||||||
#-- Here we call the device dependent part
|
#-- Here we call the device dependent part
|
||||||
if( $owx_interface eq "DS2480" ){
|
if( $owx_interface eq "DS2480" ){
|
||||||
@@ -577,7 +585,6 @@ sub OWX_Search ($$) {
|
|||||||
Log 1,"OWX: Search called with unknown interface";
|
Log 1,"OWX: Search called with unknown interface";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#--check if we really found a device
|
#--check if we really found a device
|
||||||
if( OWX_CRC()!= 0){
|
if( OWX_CRC()!= 0){
|
||||||
#-- reset the search
|
#-- reset the search
|
||||||
@@ -750,7 +757,6 @@ sub OWX_Verify ($$) {
|
|||||||
if ($dev eq $dev2){
|
if ($dev eq $dev2){
|
||||||
return 1;
|
return 1;
|
||||||
}else{
|
}else{
|
||||||
# print "Searching for $dev, but found $dev2\n";
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -793,8 +799,8 @@ sub OWX_Block_2480 ($$) {
|
|||||||
Log 5, "OWX_Block: OK";
|
Log 5, "OWX_Block: OK";
|
||||||
return $res;
|
return $res;
|
||||||
} else {
|
} else {
|
||||||
Log 3, "OWX_Block: failure, length=".length($res);
|
Log 3, "OWX_Block: DAS 2480 failure, received ".length($data)." bytes";
|
||||||
return $res;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -890,7 +896,7 @@ sub OWX_Query_2480 ($$) {
|
|||||||
my $count_out = $owx_serport->write($cmd);
|
my $count_out = $owx_serport->write($cmd);
|
||||||
|
|
||||||
Log 1, "OWX: Write incomplete $count_out ne ".(length($cmd))."" if ( $count_out != length($cmd) );
|
Log 1, "OWX: Write incomplete $count_out ne ".(length($cmd))."" if ( $count_out != length($cmd) );
|
||||||
#-- sleeping 0.03 seconds
|
#-- sleeping for some time
|
||||||
select(undef,undef,undef,0.04);
|
select(undef,undef,undef,0.04);
|
||||||
|
|
||||||
#-- read the data
|
#-- read the data
|
||||||
@@ -906,7 +912,7 @@ sub OWX_Query_2480 ($$) {
|
|||||||
Log 3, $res;
|
Log 3, $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-- sleeping 0.03 seconds
|
#-- sleeping for some time
|
||||||
select(undef,undef,undef,0.04);
|
select(undef,undef,undef,0.04);
|
||||||
|
|
||||||
$owx_serport->close();
|
$owx_serport->close();
|
||||||
@@ -1123,14 +1129,16 @@ sub OWX_Block_9097 ($$) {
|
|||||||
my ($hash,$data) =@_;
|
my ($hash,$data) =@_;
|
||||||
|
|
||||||
my $data2="";
|
my $data2="";
|
||||||
|
my $res=0;
|
||||||
for (my $i=0; $i<length($data);$i++){
|
for (my $i=0; $i<length($data);$i++){
|
||||||
$data2 = $data2.OWX_TouchByte_9097($hash,ord(substr($data,$i,1)));
|
$res = OWX_TouchByte_9097($hash,ord(substr($data,$i,1)));
|
||||||
|
$data2 = $data2.chr($res);
|
||||||
}
|
}
|
||||||
#-- process result
|
#-- process result
|
||||||
if( length($data2) == length($data) ){
|
if( length($data2) == length($data) ){
|
||||||
return $data2;
|
return $data2;
|
||||||
} else {
|
} else {
|
||||||
Log 3, "OWX: DS9097 block failure";
|
Log 3, "OWX: DS9097 block failure, received ".length($data2)." bytes";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1178,9 +1186,8 @@ sub OWX_Query_9097 ($$) {
|
|||||||
my $count_out = $owx_serport->write($cmd);
|
my $count_out = $owx_serport->write($cmd);
|
||||||
|
|
||||||
Log 1, "OWX: Write incomplete $count_out ne ".(length($cmd))."" if ( $count_out != length($cmd) );
|
Log 1, "OWX: Write incomplete $count_out ne ".(length($cmd))."" if ( $count_out != length($cmd) );
|
||||||
#-- sleeping 0.03 seconds
|
#-- sleeping for some time
|
||||||
#select(undef,undef,undef,0.03);
|
select(undef,undef,undef,0.01);
|
||||||
#select(undef,undef,undef,0.05);
|
|
||||||
|
|
||||||
#-- read the data
|
#-- read the data
|
||||||
my ($count_in, $string_in) = $owx_serport->read(32);
|
my ($count_in, $string_in) = $owx_serport->read(32);
|
||||||
@@ -1195,9 +1202,8 @@ sub OWX_Query_9097 ($$) {
|
|||||||
Log 3, $res;
|
Log 3, $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-- sleeping 0.03 seconds
|
#-- sleeping for some time
|
||||||
#select(undef,undef,undef,0.03);
|
select(undef,undef,undef,0.01);
|
||||||
select(undef,undef,undef,0.05);
|
|
||||||
|
|
||||||
$owx_serport->close();
|
$owx_serport->close();
|
||||||
return($string_in);
|
return($string_in);
|
||||||
@@ -1408,6 +1414,7 @@ sub OWX_TouchByte_9097 ($$) {
|
|||||||
|
|
||||||
my $loop;
|
my $loop;
|
||||||
my $result=0;
|
my $result=0;
|
||||||
|
my $bytein=$byte;
|
||||||
|
|
||||||
for( $loop=0; $loop < 8; $loop++ ){
|
for( $loop=0; $loop < 8; $loop++ ){
|
||||||
#-- shift result to get ready for the next bit
|
#-- shift result to get ready for the next bit
|
||||||
@@ -1422,6 +1429,10 @@ sub OWX_TouchByte_9097 ($$) {
|
|||||||
}
|
}
|
||||||
$byte >>= 1;
|
$byte >>= 1;
|
||||||
}
|
}
|
||||||
|
#print "-----------------------\n";
|
||||||
|
#printf "Sending byte /%02x/\n",$bytein;
|
||||||
|
#printf "Receiving byte /%02x/\n",$result;
|
||||||
|
#print "-----------------------\n";
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
# Martin Fischer, 2011
|
# Martin Fischer, 2011
|
||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
#
|
#
|
||||||
# Version 1.0 - February 21, 2012
|
# Version 1.01 - February 23, 2012
|
||||||
#
|
#
|
||||||
# Setup bus device in fhem.cfg as
|
# Setup bus device in fhem.cfg as
|
||||||
# define <name> OWTEMP [<model>] <ROM_ID> [interval] [alarminterval]
|
# define <name> OWTEMP [<model>] <ROM_ID> [interval] [alarminterval]
|
||||||
@@ -81,7 +81,7 @@ my $scale;
|
|||||||
#"family" => "10",
|
#"family" => "10",
|
||||||
#"id" => "",
|
#"id" => "",
|
||||||
#"locator" => "",
|
#"locator" => "",
|
||||||
#"power" => "",
|
"interval" => "",
|
||||||
"present" => "",
|
"present" => "",
|
||||||
"temperature" => "",
|
"temperature" => "",
|
||||||
"temphigh" => "",
|
"temphigh" => "",
|
||||||
@@ -169,7 +169,7 @@ sub OWTEMP_Define ($$) {
|
|||||||
Log 1, "OWTEMP: Parameter [alarminterval] is obsolete now - must be set with I/O-Device"
|
Log 1, "OWTEMP: Parameter [alarminterval] is obsolete now - must be set with I/O-Device"
|
||||||
if(int(@a) == 6);
|
if(int(@a) == 6);
|
||||||
} else {
|
} else {
|
||||||
return "OWTEMP: $a[0] hat missing ID or wrong ID format $a[2], specify a 12 digit value or set it to none for demo mode";
|
return "OWTEMP: $a[0] ID $a[2] invalid, specify a 12 digit value or set it to none for demo mode";
|
||||||
}
|
}
|
||||||
|
|
||||||
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
||||||
@@ -287,6 +287,12 @@ sub OWTEMP_Get($@) {
|
|||||||
$value = $hash->{INTERVAL};
|
$value = $hash->{INTERVAL};
|
||||||
return "$a[0] $reading => $value";
|
return "$a[0] $reading => $value";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# get present
|
||||||
|
if($a[1] eq "present") {
|
||||||
|
$value = $hash->{PRESENT};
|
||||||
|
return "$a[0] $reading => $value";
|
||||||
|
}
|
||||||
|
|
||||||
#-- Get other values according to interface type
|
#-- Get other values according to interface type
|
||||||
my $interface= $hash->{IODev}->{TYPE};
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
@@ -323,6 +329,7 @@ sub OWTEMP_Get($@) {
|
|||||||
$hash->{READINGS}{temphigh}{TIME} = $tn;
|
$hash->{READINGS}{temphigh}{TIME} = $tn;
|
||||||
|
|
||||||
#-- return the special reading
|
#-- return the special reading
|
||||||
|
$reading = "temp" if( $reading eq "temperature");
|
||||||
if(defined($hash->{READINGS}{$reading})) {
|
if(defined($hash->{READINGS}{$reading})) {
|
||||||
$value = $hash->{READINGS}{$reading}{VAL};
|
$value = $hash->{READINGS}{$reading}{VAL};
|
||||||
}
|
}
|
||||||
@@ -371,6 +378,7 @@ sub OWTEMP_GetUpdate($@) {
|
|||||||
my $interface= $hash->{IODev}->{TYPE};
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
#-- real sensor
|
#-- real sensor
|
||||||
if($hash->{OW_ID} ne "none") {
|
if($hash->{OW_ID} ne "none") {
|
||||||
|
$hash->{PRESENT} = 0;
|
||||||
#-- Get values according to interface type
|
#-- Get values according to interface type
|
||||||
my $interface= $hash->{IODev}->{TYPE};
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
@@ -516,13 +524,13 @@ sub OWTEMP_Set($@) {
|
|||||||
#
|
#
|
||||||
# OWTEMP_Undef - Implements UndefFn function
|
# OWTEMP_Undef - Implements UndefFn function
|
||||||
#
|
#
|
||||||
# Parameter hash = hash of device addressed, name
|
# Parameter hash = hash of device addressed
|
||||||
#
|
#
|
||||||
########################################################################################
|
########################################################################################
|
||||||
|
|
||||||
sub OWTEMP_Undef ($$) {
|
sub OWTEMP_Undef ($) {
|
||||||
my ($hash, $name) = @_;
|
my ($hash) = @_;
|
||||||
delete($modules{OWTEMP}{defptr}{$hash->{CODE}});
|
#delete($modules{OWTEMP}{defptr}{$hash->{CODE}});
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@@ -645,9 +653,17 @@ sub OWXTEMP_GetValues($) {
|
|||||||
if( $res eq 0 ){
|
if( $res eq 0 ){
|
||||||
return "OWXTEMP: Device $owx_dev not accessible in 2nd step";
|
return "OWXTEMP: Device $owx_dev not accessible in 2nd step";
|
||||||
}
|
}
|
||||||
|
my $res2 = "====> OWXTEMP Received ";
|
||||||
|
for(my $i=0;$i<19;$i++){
|
||||||
|
my $j=int(ord(substr($res,$i,1))/16);
|
||||||
|
my $k=ord(substr($res,$i,1))%16;
|
||||||
|
$res2.=sprintf "0x%1x%1x ",$j,$k;
|
||||||
|
}
|
||||||
|
Log 1, $res2;
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
my @data=split(//,$res);
|
my @data=split(//,$res);
|
||||||
if (@data == 19){
|
if ( (@data == 19) && (ord($data[17])>0) ){
|
||||||
my $count_remain = ord($data[16]);
|
my $count_remain = ord($data[16]);
|
||||||
my $count_perc = ord($data[17]);
|
my $count_perc = ord($data[17]);
|
||||||
my $delta = -0.25 + ($count_perc - $count_remain)/$count_perc;
|
my $delta = -0.25 + ($count_perc - $count_remain)/$count_perc;
|
||||||
@@ -660,10 +676,12 @@ sub OWXTEMP_GetValues($) {
|
|||||||
}
|
}
|
||||||
$owg_th = ord($data[12]) > 127 ? 128-ord($data[12]) : ord($data[12]);
|
$owg_th = ord($data[12]) > 127 ? 128-ord($data[12]) : ord($data[12]);
|
||||||
$owg_tl = ord($data[13]) > 127 ? 128-ord($data[13]) : ord($data[13]);
|
$owg_tl = ord($data[13]) > 127 ? 128-ord($data[13]) : ord($data[13]);
|
||||||
|
|
||||||
|
Log 1, "====> OWXTEMP Conversion result is temp = $owg_temp, delta $delta";
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
} else {
|
} else {
|
||||||
return "OWXTEMP: Device $owx_dev returns wrong number @data of bytes";
|
return "OWXTEMP: Device $owx_dev returns invalid data";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 28 KiB |
Reference in New Issue
Block a user