From 4c01175af93c2a0ab1dfbb4ad4bf00ff7ebacd0e Mon Sep 17 00:00:00 2001 From: ntruchsess <> Date: Mon, 4 Aug 2014 21:08:18 +0000 Subject: [PATCH] OWX_SER/DS2480/DS9097: fix bugs of commit 3ddd112c6b0d19094e0c0fd791d44fd30c0b43fc git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@6361 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/00_OWX_ASYNC.pm | 1 + FHEM/OWX_DS2480.pm | 6 ++++-- FHEM/OWX_DS9097.pm | 28 +++++++++++----------------- FHEM/OWX_SER.pm | 8 +++++--- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/FHEM/00_OWX_ASYNC.pm b/FHEM/00_OWX_ASYNC.pm index 9207a786c..0d9a615ff 100644 --- a/FHEM/00_OWX_ASYNC.pm +++ b/FHEM/00_OWX_ASYNC.pm @@ -745,6 +745,7 @@ sub OWX_ASYNC_Init ($) { eval { $ret = $owx->initialize($hash); }; + Log3 ($hash->{NAME},4,"OWX_ASYNC_Init failed: $@") if $@; if (my $err = GP_Catch($@)) { $hash->{PRESENT} = 0; $hash->{STATE} = "Init Failed: $err"; diff --git a/FHEM/OWX_DS2480.pm b/FHEM/OWX_DS2480.pm index 738a9ad3e..255347998 100644 --- a/FHEM/OWX_DS2480.pm +++ b/FHEM/OWX_DS2480.pm @@ -354,11 +354,11 @@ sub pt_next ($$) { my $response = substr($serial->{string_in},1); #-- interpret the return data if( length($response)!=16 ) { - die "OWX_DS2480: Search 2nd return has wrong parameter with length = ".(length($response)."")); + die "OWX_DS2480: Search 2nd return has wrong parameter with length = ".(length($response).""); } #-- Response search data parsing (Fig. 11 of Maxim AN192) # operates on a 16 byte search response = 64 pairs of two bits - my $id_bit_number = 1; + $id_bit_number = 1; #-- clear 8 byte of device id for current search $context->{ROM_ID} = [0,0,0,0 ,0,0,0,0]; @@ -386,7 +386,9 @@ sub pt_next ($$) { #-- increment number $id_bit_number++; + main::Log3 ($serial->{name},5,"id_bit_number: $id_bit_number, LastDiscrepancy: $context->{LastDiscrepancy} ROM_ID: ".sprintf("%02X.%02X%02X%02X%02X%02X%02X.%02X",@{$context->{ROM_ID}})) if ($main::owx_async_debug > 2); } + PT_END; }); } diff --git a/FHEM/OWX_DS9097.pm b/FHEM/OWX_DS9097.pm index 48d7e2a43..aa2b37483 100644 --- a/FHEM/OWX_DS9097.pm +++ b/FHEM/OWX_DS9097.pm @@ -96,7 +96,7 @@ sub get_pt_execute($$$$) { $pt_query = $self->pt_query($select); PT_WAIT_THREAD($pt_query); die $pt_query->PT_CAUSE() if ($pt_query->PT_STATE() == PT_ERROR || $pt_query->PT_STATE() == PT_CANCELED); - my $res = pack "B*",$pt_query->PT_RETVAL(); + my $res = pack "b*",$pt_query->PT_RETVAL(); main::Log3($self->{name},5,"OWX_DS9097::pt_execute: Receiving ".unpack ("H*",$res)) if( $main::owx_async_debug > 1); PT_EXIT($res); } else { @@ -113,13 +113,13 @@ sub reset() { $hwdevice->baudrate(9600); $hwdevice->write_settings; - $hwdevice->write("0xF0"); - + main::Log3($serial->{name},5, "OWX_DS9097 9600 baud") if ( $main::owx_async_debug > 2 ); + $hwdevice->write("\xF0"); + main::Log3($serial->{name},5, "OWX_DS9097 reset") if ( $main::owx_async_debug > 1 ); while ($serial->poll()) {}; - $hwdevice->baudrate(115200); $hwdevice->write_settings; - + main::Log3($serial->{name},5, "OWX_DS9097 115200 baud") if ( $main::owx_async_debug > 2 ); } } @@ -127,7 +127,7 @@ sub block($) { my ( $serial, $block ) = @_; if (defined (my $hwdevice = $serial->{hash}->{USBDev})) { main::Log3($serial->{name},5, "OWX_DS9097 block: ".unpack "H*",$block) if ( $main::owx_async_debug > 1 ); - foreach my $bit (split //,unpack "B*",$block) { + foreach my $bit (split //,unpack "b*",$block) { $serial->bit($bit); } } else { @@ -139,7 +139,7 @@ sub bit($) { my ( $serial, $bit ) = @_; if (defined (my $hwdevice = $serial->{hash}->{USBDev})) { my $sp1 = $bit == 1 ? "\xFF" : "\x00"; - main::Log3($serial->{name},5, sprintf("OWX_DS9097 bit: %02X",ord($sp1))) if ( $main::owx_async_debug > 2 ); + main::Log3($serial->{name},5, sprintf("OWX_DS9097 bit: %02x",ord($sp1))) if ( $main::owx_async_debug > 2 ); $hwdevice->write($sp1); } else { die "no USBDev"; @@ -154,7 +154,7 @@ sub pt_query($) { return PT_THREAD(sub { my ( $thread ) = @_; PT_BEGIN($thread); - main::Log3($serial->{name},5, "OWX_DS9097 pt_query: ".$query) if( $main::owx_async_debug > 1 ); + main::Log3($serial->{name},5, "OWX_DS9097 pt_query out: ".$query) if( $main::owx_async_debug > 1 ); while (defined ($bit = shift @bitsout)) { while ($serial->poll()) {}; $serial->{string_raw} = ""; @@ -162,6 +162,7 @@ sub pt_query($) { PT_WAIT_UNTIL(length($serial->{string_raw}) > 0); $bitsin .= substr($serial->{string_raw},0,1) eq ($bit == 1 ? "\xFF" : "\x00") ? "1" : "0"; }; + main::Log3($serial->{name},5,"OWX_DS9097 pt_query in: ".$bitsin) if ( $main::owx_async_debug > 1 ); PT_EXIT($bitsin); PT_END; }); @@ -174,6 +175,7 @@ sub read() { if (defined $string_part and length($string_part) > 0) { $serial->{string_raw} .= $string_part; main::Log3($serial->{name},5, "OWX_DS9097 read: Loop no. $serial->{num_reads}, Receiving: ".unpack("H*",$string_part)) if( $main::owx_async_debug > 1 ); + return 1; } elsif ($main::owx_async_debug > 2) { main::Log3($serial->{name},5, "OWX_DS9097 read: Loop no. $serial->{num_reads}, no data read:"); foreach my $i (0..6) { @@ -185,14 +187,6 @@ sub read() { return undef; } -sub response_ready() { - my ( $serial ) = @_; - $serial->{string_in} = pack "B*",$serial->{string_raw}; - main::Log3($serial->{name},5, "OWX_DS9097 response_ready: Received raw: ".$serial->{string_raw}) if( $main::owx_async_debug > 2 ); - main::Log3($serial->{name},5, "OWX_DS9097 response_ready: Received: ".unpack("H*",$serial->{string_in})) if( $main::owx_async_debug > 1 ); - return 1; -} - sub pt_next ($$) { my ($serial,$context,$mode)=@_; @@ -278,7 +272,7 @@ sub pt_next ($$) { $rom_byte_mask = 1; } $context->{LastDiscrepancy} = $last_zero; - main::Log3 ($serial->{name},5,"id_bit_number: $id_bit_number, search_direction: $search_direction, LastDiscrepancy: $serial->{LastDiscrepancy} ROM_ID: ".sprintf("%02X.%02X%02X%02X%02X%02X%02X.%02X",@{$context->{ROM_ID}})); + main::Log3 ($serial->{name},5,"id_bit_number: $id_bit_number, search_direction: $search_direction, LastDiscrepancy: $context->{LastDiscrepancy} ROM_ID: ".sprintf("%02X.%02X%02X%02X%02X%02X%02X.%02X",@{$context->{ROM_ID}})) if ($main::owx_async_debug > 2); } PT_END; }); diff --git a/FHEM/OWX_SER.pm b/FHEM/OWX_SER.pm index b88473345..5cac771be 100644 --- a/FHEM/OWX_SER.pm +++ b/FHEM/OWX_SER.pm @@ -135,7 +135,7 @@ sub get_pt_alarms() { return PT_THREAD(sub { my ($thread) = @_; PT_BEGIN($thread); - $self->{alarmdevs} = []; + $thread->{alarmdevs} = []; #-- Discover all alarmed devices on the 1-Wire bus $self->first($thread); do { @@ -173,7 +173,7 @@ sub get_pt_discover() { PT_WAIT_THREAD($pt_next); die $pt_next->PT_CAUSE() if ($pt_next->PT_STATE() == PT_ERROR || $pt_next->PT_STATE() == PT_CANCELED); $self->next_response($thread,"discover"); - } while( $self->{LastDeviceFlag}==0 ); + } while( $thread->{LastDeviceFlag}==0 ); PT_EXIT($thread->{devs}); PT_END; }); @@ -216,7 +216,7 @@ sub initialize() { $hwdevice->purge_all; $hwdevice->baudrate(4800); $hwdevice->write_settings; - $hwdevice->write(sprintf("\x00")); + $hwdevice->write("\x00"); select(undef,undef,undef,0.5); #-- timing byte for DS2480 $ds2480->start_query(); @@ -329,6 +329,7 @@ sub get_pt_verify($) { #-- reset the search state $thread->{LastDiscrepancy} = 64; $thread->{LastDeviceFlag} = 0; + $thread->{LastFamilyDiscrepancy} = 0; #-- now do the search $pt_next = $self->pt_next($thread,"verify"); @@ -339,6 +340,7 @@ sub get_pt_verify($) { #-- reset the search state $thread->{LastDiscrepancy} = 0; $thread->{LastDeviceFlag} = 0; + $thread->{LastFamilyDiscrepancy} = 0; #-- check result if ($dev eq $dev2){ PT_EXIT(1);