git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@1980 2b470e98-0d58-463d-a4d8-8e2adae1ed80

This commit is contained in:
pahenning 2012-10-16 18:15:47 +00:00
parent 9f1043d4a9
commit eaf100d5e9
4 changed files with 52 additions and 42 deletions

View File

@ -12,7 +12,7 @@
# Internally these interfaces are vastly different, read the corresponding Wiki pages # Internally these interfaces are vastly different, read the corresponding Wiki pages
# http://fhemwiki.de/wiki/Interfaces_f%C3%BCr_1-Wire # http://fhemwiki.de/wiki/Interfaces_f%C3%BCr_1-Wire
# #
# Version 2.20 - October, 2012 # Version 2.22 - October, 2012
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
@ -151,7 +151,7 @@ sub OWX_Define ($$) {
} }
#-- check syntax #-- check syntax
Log 1,"OWX: Warning - Some parameter(s) ignored, must be define <name> OWX <serial-device>|<cuno-device>" Log 1,"OWX: Warning - Some parameter(s) ignored, must be define <name> OWX <serial-device>|<cuno/coc-device>"
if(int(@a) > 3); if(int(@a) > 3);
#-- If this line contains 3 parameters, it is the bus master definition #-- If this line contains 3 parameters, it is the bus master definition
my $dev = $a[2]; my $dev = $a[2];
@ -161,7 +161,7 @@ sub OWX_Define ($$) {
#-- Dummy 1-Wire ROM identifier #-- Dummy 1-Wire ROM identifier
$hash->{ROM_ID} = "FF"; $hash->{ROM_ID} = "FF";
#-- First step: check if we have a directly connected serial interface or a CUNO attached #-- First step: check if we have a directly connected serial interface or a CUNO/COC attached
# (mod suggested by T.Faust) # (mod suggested by T.Faust)
if ( $dev =~ m/\/dev\/.*/ ){ if ( $dev =~ m/\/dev\/.*/ ){
#-- TODO: what should we do when the specified device name contains @ already ? #-- TODO: what should we do when the specified device name contains @ already ?
@ -386,6 +386,7 @@ sub OWX_CRC ($) {
sub OWX_CRC8 ($$) { sub OWX_CRC8 ($$) {
my ($string,$crc) = @_; my ($string,$crc) = @_;
my $crc0=ord($crc);
my $crc8=0; my $crc8=0;
my @strhex; my @strhex;
@ -395,7 +396,7 @@ sub OWX_CRC8 ($$) {
} }
if( defined($crc) ){ if( defined($crc) ){
if ( $crc = $crc8 ){ if ( $crc0 == $crc8 ){
return 1; return 1;
}else{ }else{
return 0; return 0;
@ -445,17 +446,6 @@ sub OWX_DOCRC16($$) {
return ($crc); return ($crc);
} }
#//-------------------------------------------------------------------#
#Aufruf der Funktion im Programm:
#{
#//...
# unsigned int DEVICE_CRC16=0;
# DEVICE_CRC16 = calcCRC16r (DEVICE_CRC16,chr,0xA001);
#//...
#}
######################################################################################## ########################################################################################
# #
# OWX_Detect - Detect 1-Wire interface # OWX_Detect - Detect 1-Wire interface
@ -610,6 +600,7 @@ sub OWX_Discover ($) {
#-- sleeping for some time #-- sleeping for some time
select(undef,undef,undef,3); select(undef,undef,undef,3);
CUL_SimpleWrite($owx_hwdevice, "Oc"); CUL_SimpleWrite($owx_hwdevice, "Oc");
select(undef,undef,undef,0.5);
my $ob = OWX_SimpleRead($owx_hwdevice); my $ob = OWX_SimpleRead($owx_hwdevice);
if( $ob ){ if( $ob ){
foreach my $dx (split(/\n/,$ob)){ foreach my $dx (split(/\n/,$ob)){
@ -1956,10 +1947,10 @@ sub OWX_Receive_CUNO ($$) {
}elsif( length($ob) == 20 ){ }elsif( length($ob) == 20 ){
$numread++; $numread++;
}else{ }else{
Log 1,"OWX: Received unexpected number of ".length($ob)." bytes from CUNO"; Log 1,"OWX: Received unexpected number of ".length($ob)." bytes from CUNO/COC";
} }
} }
Log 3, "OWX: Receive from CUNO $numread bytes = $res2" Log 3, "OWX: Receive from CUNO/COC $numread bytes = $res2"
if( $owx_debug > 1); if( $owx_debug > 1);
return($res); return($res);
@ -2010,7 +2001,7 @@ sub OWX_Send_CUNO ($$) {
$res2.=sprintf "0x%1x%1x ",$j,$k; $res2.=sprintf "0x%1x%1x ",$j,$k;
CUL_SimpleWrite($owx_hwdevice, $res); CUL_SimpleWrite($owx_hwdevice, $res);
} }
Log 3,"OWX: Send to CUNO $res2" Log 3,"OWX: Send to CUNO/COC $res2"
if( $owx_debug > 1); if( $owx_debug > 1);
} }

View File

@ -14,7 +14,7 @@
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
# Version 2.18 - September, 2012 # Version 2.22 - September, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@ -44,6 +44,8 @@
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B # Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
# Note: attributes are read only during initialization procedure - later changes are not used. # Note: attributes are read only during initialization procedure - later changes are not used.
# #
# attr <name> event on-change/on-update = when to write an event (default= on-update)
#
# attr <name> UnitInReading = whether the physical unit is written into the reading = 1 (default) or 0 # attr <name> UnitInReading = whether the physical unit is written into the reading = 1 (default) or 0
# attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value # attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value
# attr <name> <channel>Unit <string>|<string> = unit of measurement for this channel | its abbreviation # attr <name> <channel>Unit <string>|<string> = unit of measurement for this channel | its abbreviation
@ -142,7 +144,8 @@ sub OWCOUNT_Initialize ($) {
$hash->{SetFn} = "OWCOUNT_Set"; $hash->{SetFn} = "OWCOUNT_Set";
#-- see header for attributes #-- see header for attributes
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2423 loglevel:0,1,2,3,4,5 UnitInReading:0,1"; my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2423 loglevel:0,1,2,3,4,5 UnitInReading:0,1 ".
"event:on-update,on-change";
for( my $i=0;$i<int(@owg_fixed);$i++ ){ for( my $i=0;$i<int(@owg_fixed);$i++ ){
$attlist .= " ".$owg_fixed[$i]."Name"; $attlist .= " ".$owg_fixed[$i]."Name";
$attlist .= " ".$owg_fixed[$i]."Offset"; $attlist .= " ".$owg_fixed[$i]."Offset";
@ -257,7 +260,7 @@ sub OWCOUNT_InitializeDevice($) {
my $unit = defined($attr{$name}{$owg_fixed[$i]."Unit"}) ? $attr{$name}{$owg_fixed[$i]."Unit"} : "counts|cts"; my $unit = defined($attr{$name}{$owg_fixed[$i]."Unit"}) ? $attr{$name}{$owg_fixed[$i]."Unit"} : "counts|cts";
my @unarr= split(/\|/,$unit); my @unarr= split(/\|/,$unit);
if( int(@unarr)!=2 ){ if( int(@unarr)!=2 ){
Log 1, "OWCOUNT: Incomplete channel unit specification $unit. Better use $unit|<abbreviation>"; Log 1, "OWCOUNT: Incomplete channel unit specification $unit. Better use <long unit desc>|$unit";
push(@unarr,""); push(@unarr,"");
} }
@ -694,12 +697,18 @@ sub OWCOUNT_GetValues($) {
return "OWCOUNT: Could not get values from device $name"; return "OWCOUNT: Could not get values from device $name";
} }
$hash->{PRESENT} = 1; $hash->{PRESENT} = 1;
$value=OWCOUNT_FormatValues($hash);
#--logging
Log 5, $value;
$hash->{CHANGED}[0] = $value;
#-- old state, new state
my $oldval = $hash->{STATE};
$value=OWCOUNT_FormatValues($hash);
my $newval = $hash->{STATE};
#--logging depends on setting of the event-attribute
Log 5, $value;
my $ev = defined($attr{$name}{"event"}) ? $attr{$name}{"event"} : "on-update";
if( ($ev eq "on-update") || (($ev eq "on-change") && ($newval ne $oldval)) ){
$hash->{CHANGED}[0] = $value;
DoTrigger($name, undef); DoTrigger($name, undef);
}
return undef; return undef;
} }
@ -909,11 +918,13 @@ sub OWXCOUNT_GetPage($$) {
OWX_Reset($master); OWX_Reset($master);
#-- process results #-- process results
if( length($res) < 54){ @data=split(//,$res);
Log 1, "OWXCOUNT: warning, have received ".length($res)." bytes in three steps"; return "OWXCOUNT: invalid data length, ".length($res)." bytes in three steps"
#return "OWXCOUNT: warning, have received ".length($res)." bytes in three steps"; if( length($res) < 54);
} #return "invalid data"
#Log 1, "OWXCOUNT: warning, have received ".length($res)." bytes in three steps"; # if (ord($data[17])<=0);
#return "invalid CRC"
# if (OWX_CRC8(substr($res,10,8),$data[18])==0);
#-- first 12 byte are 9 ROM ID +3 command, next 32 are memory #-- first 12 byte are 9 ROM ID +3 command, next 32 are memory
#-- memory part, treated as string #-- memory part, treated as string
@ -927,7 +938,7 @@ sub OWXCOUNT_GetPage($$) {
} }
#-- first ignore memory and only use counter (Fehler gefunden von jamesgo) #-- first ignore memory and only use counter (Fehler gefunden von jamesgo)
my $value = (ord($data[3])<<32) + (ord($data[2])<<16) +(ord($data[1])<<8) + ord($data[0]); my $value = (ord($data[3])<<24) + (ord($data[2])<<16) +(ord($data[1])<<8) + ord($data[0]);
if( $page == 14) { if( $page == 14) {
$owg_val[0] = $value; $owg_val[0] = $value;

View File

@ -17,7 +17,7 @@
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
# Version 2.18 - September, 2012 # Version 2.22 - September, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@ -719,6 +719,12 @@ sub OWXSWITCH_GetState($) {
#-- process results #-- process results
@data=split(//,substr($res,10)); @data=split(//,substr($res,10));
#return "invalid data length"
# if (@data != 22);
#return "invalid data"
# if (ord($data[17])<=0);
#return "invalid CRC"
# if (OWX_CRC8(substr($res,10,8),$data[18])==0);
#-- reset the bus #-- reset the bus
OWX_Reset($master); OWX_Reset($master);

View File

@ -15,7 +15,7 @@
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# Martin Fischer, 2011 # Martin Fischer, 2011
# #
# Version 2.20 - October, 2012 # Version 2.22 - October, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@ -469,12 +469,14 @@ sub OWTHERM_GetValues($@) {
}elsif( $interface eq "OWFS" ){ }elsif( $interface eq "OWFS" ){
$ret = OWFSTHERM_GetValues($hash); $ret = OWFSTHERM_GetValues($hash);
}else{ }else{
return "OWTHERM: GetValues with wrong IODev type $interface"; Log 3, "OWTHERM: GetValues with wrong IODev type $interface";
return 1;
} }
#-- process results #-- process results
if( defined($ret) ){ if( defined($ret) ){
return "OWTHERM: Could not get values from device $name, reason $ret"; Log 3, "OWTHERM: Could not get values from device $name, reason $ret";
return 1;
} }
$hash->{PRESENT} = 1; $hash->{PRESENT} = 1;
@ -677,7 +679,7 @@ sub OWXTHERM_GetValues($) {
OWX_Reset($master); OWX_Reset($master);
#-- issue the match ROM command \x55 and the start conversion command #-- issue the match ROM command \x55 and the start conversion command
if( OWX_Complex($master,$owx_dev,"\x44",0) eq 0 ){ if( OWX_Complex($master,$owx_dev,"\x44",0) eq 0 ){
return "OWXTHERM: Device $owx_dev not accessible"; return "$owx_dev not accessible";
} }
#-- conversion needs some 950 ms - but we may also do it in shorter time ! #-- conversion needs some 950 ms - but we may also do it in shorter time !
select(undef,undef,undef,1.0); select(undef,undef,undef,1.0);
@ -691,7 +693,7 @@ sub OWXTHERM_GetValues($) {
#Log 1,"OWXTHERM: data length from reading device is ".length($res)." bytes"; #Log 1,"OWXTHERM: data length from reading device is ".length($res)." bytes";
#-- process results #-- process results
if( $res eq 0 ){ if( $res eq 0 ){
return "OWXTHERM: Device $owx_dev not accessible in 2nd step"; return "$owx_dev not accessible in 2nd step";
} }
#if (length($res) == 10){ #if (length($res) == 10){
@ -708,11 +710,11 @@ sub OWXTHERM_GetValues($) {
#$res="000000000".$res #$res="000000000".$res
# if(length($res)==10); # if(length($res)==10);
my @data=split(//,$res); my @data=split(//,$res);
return "OWTHERM: invalid data length, ".int(@data)." bytes" return "invalid data length, ".int(@data)." bytes"
if (@data != 19); if (@data != 19);
return "OWXTHERM: invalid data" return "invalid data"
if (ord($data[17])<=0); if (ord($data[17])<=0);
return "OWXTHERM: invalid CRC" return "invalid CRC"
if (OWX_CRC8(substr($res,10,8),$data[18])==0); if (OWX_CRC8(substr($res,10,8),$data[18])==0);
#-- this must be different for the different device types #-- this must be different for the different device types