mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-01 20:20:10 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@1409 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
49624de6c2
commit
ac75fe9602
@ -73,9 +73,6 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
sub Log($$);
|
sub Log($$);
|
||||||
|
|
||||||
#-- value globals
|
|
||||||
my @owg_status;
|
|
||||||
my $owg_state;
|
|
||||||
#-- channel name - fixed is the first array, variable the second
|
#-- channel name - fixed is the first array, variable the second
|
||||||
my @owg_fixed = ("A","B");
|
my @owg_fixed = ("A","B");
|
||||||
my @owg_channel;
|
my @owg_channel;
|
||||||
@ -246,7 +243,7 @@ sub OWCOUNT_InitializeDevice($) {
|
|||||||
#-- put into readings
|
#-- put into readings
|
||||||
$hash->{READINGS}{"$owg_channel[$i]"}{TYPE} = defined($cnama[1]) ? $cnama[1] : "unknown";
|
$hash->{READINGS}{"$owg_channel[$i]"}{TYPE} = defined($cnama[1]) ? $cnama[1] : "unknown";
|
||||||
$hash->{READINGS}{"$owg_channel[$i]"}{UNIT} = $unarr[0];
|
$hash->{READINGS}{"$owg_channel[$i]"}{UNIT} = $unarr[0];
|
||||||
$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR} = defined($unarr[1]) ? $unarr[1] : "?";
|
$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR} = defined($unarr[1]) ? $unarr[1] : "";
|
||||||
$hash->{READINGS}{"$owg_channel[$i]"}{OFFSET} = $offset;
|
$hash->{READINGS}{"$owg_channel[$i]"}{OFFSET} = $offset;
|
||||||
$hash->{READINGS}{"$owg_channel[$i]"}{FACTOR} = $factor;
|
$hash->{READINGS}{"$owg_channel[$i]"}{FACTOR} = $factor;
|
||||||
}
|
}
|
||||||
@ -293,7 +290,11 @@ sub OWCOUNT_FormatValues($) {
|
|||||||
$offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET};
|
$offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET};
|
||||||
$factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR};
|
$factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR};
|
||||||
#-- correct values for proper offset, factor
|
#-- correct values for proper offset, factor
|
||||||
$vval = int(($owg_val[$i] + $offset)*$factor*1000)/1000;;
|
if( $factor == 1.0 ){
|
||||||
|
$vval = ($owg_val[$i] + $offset)*$factor;
|
||||||
|
} else {
|
||||||
|
$vval = int(($owg_val[$i] + $offset)*$factor*1000)/1000;
|
||||||
|
}
|
||||||
#-- put into READINGS
|
#-- put into READINGS
|
||||||
$hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vval;
|
$hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vval;
|
||||||
$hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn;
|
$hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn;
|
||||||
@ -433,8 +434,8 @@ sub OWCOUNT_GetValues($) {
|
|||||||
#-- Get readings, alarms and stati according to interface type
|
#-- Get readings, alarms and stati according to interface type
|
||||||
my $interface= $hash->{IODev}->{TYPE};
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
if( $interface eq "OWX" ){
|
if( $interface eq "OWX" ){
|
||||||
$ret = OWXAD_GetPage($hash,"reading");
|
$ret = OWXCOUNT_GetPage($hash,14);
|
||||||
$ret = OWXAD_GetPage($hash,"status");
|
$ret = OWXCOUNT_GetPage($hash,15);
|
||||||
#}elsif( $interface eq "OWFS" ){
|
#}elsif( $interface eq "OWFS" ){
|
||||||
# $ret = OWFSAD_GetValues($hash);
|
# $ret = OWFSAD_GetValues($hash);
|
||||||
}else{
|
}else{
|
||||||
@ -474,11 +475,6 @@ sub OWCOUNT_Set($@) {
|
|||||||
#-- for the selector: which values are possible
|
#-- for the selector: which values are possible
|
||||||
if (@a == 2){
|
if (@a == 2){
|
||||||
my $newkeys = join(" ", sort keys %sets);
|
my $newkeys = join(" ", sort keys %sets);
|
||||||
for( my $i=0;$i<4;$i++ ){
|
|
||||||
$newkeys .= " ".$owg_channel[$i]."Alarm";
|
|
||||||
$newkeys .= " ".$owg_channel[$i]."Low";
|
|
||||||
$newkeys .= " ".$owg_channel[$i]."High";
|
|
||||||
}
|
|
||||||
return $newkeys ;
|
return $newkeys ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +483,7 @@ sub OWCOUNT_Set($@) {
|
|||||||
if( int(@a)!=3 );
|
if( int(@a)!=3 );
|
||||||
|
|
||||||
#-- check argument
|
#-- check argument
|
||||||
if( !defined($sets{$a[1]}) && !($key =~ m/.*(Alarm|Low|High)/) ){
|
if( !defined($sets{$a[1]}) ){
|
||||||
return "OWCOUNT: Set with unknown argument $a[1]";
|
return "OWCOUNT: Set with unknown argument $a[1]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,44 +509,6 @@ sub OWCOUNT_Set($@) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-- find out which channel we have
|
|
||||||
my $tc =$key;
|
|
||||||
if( $tc =~ s/(.*)(Alarm|Low|High)/$channel=$1/se ) {
|
|
||||||
for (my $i=0;$i<4;$i++){
|
|
||||||
if( $tc eq $owg_channel[$i] ){
|
|
||||||
$channo = $i;
|
|
||||||
$channel = $tc;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "OWCOUNT: Cannot determine channel from parameter $a[1]"
|
|
||||||
if( !(defined($channo)));
|
|
||||||
|
|
||||||
#-- set these values depending on interface type
|
|
||||||
my $interface= $hash->{IODev}->{TYPE};
|
|
||||||
|
|
||||||
#-- OWX interface
|
|
||||||
if( $interface eq "OWX" ){
|
|
||||||
$ret = OWXAD_SetPage($hash,"status");
|
|
||||||
return $ret
|
|
||||||
if(defined($ret));
|
|
||||||
#-- OWFS interface
|
|
||||||
#}elsif( $interface eq "OWFS" ){
|
|
||||||
# $ret = OWFSAD_SetValues($hash,@a);
|
|
||||||
# return $ret
|
|
||||||
# if(defined($ret));
|
|
||||||
} else {
|
|
||||||
return "OWCOUNT: Set with wrong IODev type $interface";
|
|
||||||
}
|
|
||||||
|
|
||||||
#-- process results
|
|
||||||
|
|
||||||
$hash->{PRESENT} = 1;
|
|
||||||
OWCOUNT_FormatValues($hash);
|
|
||||||
|
|
||||||
Log 4, "OWCOUNT: Set $hash->{NAME} $key $value";
|
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
@ -598,7 +556,6 @@ sub OWCOUNT_Undef ($) {
|
|||||||
########################################################################################
|
########################################################################################
|
||||||
|
|
||||||
sub OWXCOUNT_GetPage($$) {
|
sub OWXCOUNT_GetPage($$) {
|
||||||
|
|
||||||
my ($hash,$page) = @_;
|
my ($hash,$page) = @_;
|
||||||
|
|
||||||
#-- For now, switch on conversion command
|
#-- For now, switch on conversion command
|
||||||
@ -646,7 +603,7 @@ sub OWXCOUNT_GetPage($$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
print "Have received ".length($res)." bytes\n";
|
#print "Have received ".length($res)." bytes\n";
|
||||||
|
|
||||||
#-- get 32 bytes
|
#-- get 32 bytes
|
||||||
$select="";
|
$select="";
|
||||||
@ -657,7 +614,7 @@ sub OWXCOUNT_GetPage($$) {
|
|||||||
$res=OWX_Block($master,$select);
|
$res=OWX_Block($master,$select);
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
print "Have received ".length($res)." bytes\n";
|
#print "Have received ".length($res)." bytes\n";
|
||||||
|
|
||||||
#-- get 10 bytes
|
#-- get 10 bytes
|
||||||
$select="";
|
$select="";
|
||||||
@ -671,7 +628,7 @@ sub OWXCOUNT_GetPage($$) {
|
|||||||
OWX_Reset($master);
|
OWX_Reset($master);
|
||||||
|
|
||||||
#-- process results
|
#-- process results
|
||||||
print "Have received ".length($res)." bytes\n";
|
#print "Have received ".length($res)." bytes\n";
|
||||||
@data=split(//,$res);
|
@data=split(//,$res);
|
||||||
if ( ($data[4] | $data[5] | $data[6] | $data[7]) ne "\x00" ){
|
if ( ($data[4] | $data[5] | $data[6] | $data[7]) ne "\x00" ){
|
||||||
return "OWXCOUNT: Device $owx_dev returns invalid data";
|
return "OWXCOUNT: Device $owx_dev returns invalid data";
|
||||||
@ -680,7 +637,12 @@ sub OWXCOUNT_GetPage($$) {
|
|||||||
#-- for now ignore memory and only use counter
|
#-- for now ignore memory and only use counter
|
||||||
|
|
||||||
my $value = ord($data[3])*4096 + ord($data[2])*256 +ord($data[1])*16 + ord($data[0]);
|
my $value = ord($data[3])*4096 + ord($data[2])*256 +ord($data[1])*16 + ord($data[0]);
|
||||||
print "Value received = $value\n";
|
#print "Value received = $value\n";
|
||||||
|
if( $page == 14) {
|
||||||
|
$owg_val[0] = $value;
|
||||||
|
}elsif( $page == 15) {
|
||||||
|
$owg_val[1] = $value;
|
||||||
|
}
|
||||||
return undef
|
return undef
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -719,16 +681,16 @@ sub OWXCOUNT_SetPage($$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#=============== set the alarm values ===============================
|
#=============== set the alarm values ===============================
|
||||||
if ( $page eq "test" ) {
|
#if ( $page eq "test" ) {
|
||||||
#-- issue the match ROM command \x55 and the set alarm page command
|
#-- issue the match ROM command \x55 and the set alarm page command
|
||||||
# \x55\x10\x00 reading 8 data bytes and 2 CRC bytes
|
# \x55\x10\x00 reading 8 data bytes and 2 CRC bytes
|
||||||
$select=sprintf("\x55%c%c%c%c%c%c%c%c\x55\x10\x00",
|
# $select=sprintf("\x55%c%c%c%c%c%c%c%c\x55\x10\x00",
|
||||||
@owx_ROM_ID);
|
# @owx_ROM_ID);
|
||||||
|
#
|
||||||
#=============== wrong page write attempt ===============================
|
#=============== wrong page write attempt ===============================
|
||||||
} else {
|
#} else {
|
||||||
return "OWXCOUNT: Wrong memory page write attempt";
|
return "OWXCOUNT: Wrong memory page write attempt";
|
||||||
}
|
#}
|
||||||
|
|
||||||
OWX_Reset($master);
|
OWX_Reset($master);
|
||||||
$res=OWX_Block($master,$select);
|
$res=OWX_Block($master,$select);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user