mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@5337 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
d6044ba21f
commit
70247afbf3
@ -76,7 +76,7 @@ use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
my $owx_version="5.06";
|
||||
my $owx_version="5.11";
|
||||
#-- fixed raw channel name, flexible channel name
|
||||
my @owg_fixed = ("A","B","C","D");
|
||||
my @owg_channel = ("A","B","C","D");
|
||||
@ -98,6 +98,7 @@ my %gets = (
|
||||
);
|
||||
|
||||
my %sets = (
|
||||
"initialize" => "",
|
||||
"interval" => "",
|
||||
"AAlarm" => "",
|
||||
"ALow" => "",
|
||||
@ -658,7 +659,7 @@ sub OWAD_Get($@) {
|
||||
$value .= "alarmed low, ";
|
||||
}
|
||||
if (!defined $hash->{owg_shigh}) {
|
||||
$value .= "high aralm undefined";
|
||||
$value .= "high alarm undefined";
|
||||
} elsif( $hash->{owg_shigh}->[$i]==0 ) {
|
||||
$value .= "high alarm disabled";
|
||||
} elsif( $hash->{owg_shigh}->[$i]==1 ) {
|
||||
@ -860,7 +861,13 @@ sub OWAD_Set($@) {
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
|
||||
#-- set new timer interval
|
||||
#-- re-intialize
|
||||
if($key eq "initialize") {
|
||||
OWADInitializeDevice($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-- set new timer interval
|
||||
if($key eq "interval") {
|
||||
# check value
|
||||
return "OWAD: Set with short interval, must be > 1"
|
||||
@ -1384,9 +1391,10 @@ sub OWXAD_GetPage($$$) {
|
||||
OWX_Reset($master);
|
||||
#-- reading 9 + 3 + 8 data bytes and 2 CRC bytes = 22 bytes
|
||||
$res=OWX_Complex($master,$owx_dev,$select,10);
|
||||
if( $res eq 0 ){
|
||||
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"
|
||||
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));
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
#
|
||||
# where <name> may be replaced by any name string
|
||||
#
|
||||
# <model> is a 1-Wire device type DS2423 or DS2423emu. If omitted, we assume this to be an
|
||||
# <model> is a 1-Wire device type DS2423,DS2423ene,wDS2423eold. If omitted, we assume this to be an
|
||||
# DS2423 Counter/RAM
|
||||
# <FAM_ID> is a 1-Wire family id, currently allowed value is 1D
|
||||
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
||||
@ -35,7 +35,9 @@
|
||||
#
|
||||
# set <name> interval => set query interval for measurement
|
||||
# set <name> memory <page> => 32 byte string into page 0..13
|
||||
# set <name> midnight <channel> => todays starting value for counter
|
||||
# set <name> midnight <channel> => todays starting value for counter
|
||||
# set <name> counter <channel> => correct midnight value such that
|
||||
# counter shows this value
|
||||
#
|
||||
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
|
||||
#
|
||||
@ -84,7 +86,7 @@ use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
my $owx_version="5.09";
|
||||
my $owx_version="5.11";
|
||||
#-- fixed raw channel name, flexible channel name
|
||||
my @owg_fixed = ("A","B");
|
||||
my @owg_channel = ("A","B");
|
||||
@ -106,7 +108,8 @@ my %gets = (
|
||||
my %sets = (
|
||||
"interval" => "",
|
||||
"memory" => "",
|
||||
"midnight" => ""
|
||||
"midnight" => "",
|
||||
"counter" => ""
|
||||
);
|
||||
|
||||
my %updates = (
|
||||
@ -137,7 +140,7 @@ sub OWCOUNT_Initialize ($) {
|
||||
$hash->{SetFn} = "OWCOUNT_Set";
|
||||
$hash->{AttrFn} = "OWCOUNT_Attr";
|
||||
#-- see header for attributes
|
||||
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2423,DS2423emu loglevel:0,1,2,3,4,5 LogM LogY ".
|
||||
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2423,DS2423enew,DS2423eold loglevel:0,1,2,3,4,5 LogM LogY ".
|
||||
"nomemory:1,0 interval ".
|
||||
$readingFnAttributes;
|
||||
for( my $i=0;$i<int(@owg_fixed);$i++ ){
|
||||
@ -213,9 +216,12 @@ sub OWCOUNT_Define ($$) {
|
||||
if( $model eq "DS2423" ){
|
||||
$fam = "1D";
|
||||
CommandAttr (undef,"$name model DS2423");
|
||||
}elsif( $model eq "DS2423emu" ){
|
||||
}elsif( $model eq "DS2423enew" ){
|
||||
$fam = "1D";
|
||||
CommandAttr (undef,"$name model DS2423emu");
|
||||
CommandAttr (undef,"$name model DS2423enew");
|
||||
}elsif( $model eq "DS2423eold" ){
|
||||
$fam = "1D";
|
||||
CommandAttr (undef,"$name model DS2423eold");
|
||||
CommandAttr (undef,"$name nomemory 1");
|
||||
}else{
|
||||
return "OWCOUNT: Wrong 1-Wire device model $model";
|
||||
@ -676,34 +682,38 @@ sub OWCOUNT_Get($@) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-- get memory page/counter according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- check syntax for getting memory page 0..13 or midnight A/B
|
||||
my $nomemory = defined($attr{$name}{"nomemory"}) ? $attr{$name}{"nomemory"} : 0;
|
||||
if( ($reading eq "memory") || ($reading eq "midnight") ){
|
||||
if( $reading eq "memory" ){
|
||||
return "OWCOUNT: Memory usage disabled"
|
||||
if( $nomemory==1 );
|
||||
return "OWCOUNT: Get needs parameter when reading memory: <page>"
|
||||
if( int(@a)<2 );
|
||||
$page=int($a[2]);
|
||||
if( ($page<0) || ($page>13) ){
|
||||
return "OWXCOUNT: Wrong memory page requested";
|
||||
}
|
||||
if( $reading eq "memory" ){
|
||||
return "OWCOUNT: Memory usage disabled"
|
||||
if( $nomemory==1 );
|
||||
return "OWCOUNT: Get needs parameter when reading memory: <page>"
|
||||
if( int(@a)<2 );
|
||||
$page=int($a[2]);
|
||||
if( ($page<0) || ($page>13) ){
|
||||
return "OWXCOUNT: Wrong memory page requested";
|
||||
}
|
||||
$ret = OWCOUNT_GetPage($hash,$page,1);
|
||||
#-- when we have a return code, we have an error
|
||||
if( $ret ){
|
||||
return "OWCOUNT: Could not get values from device $name, reason: ".$ret;
|
||||
}else{
|
||||
return "OWCOUNT: get needs parameter when reading midnight: <channel>"
|
||||
if( int(@a)<2 );
|
||||
#-- find out which channel we have
|
||||
if( ($a[2] eq $owg_channel[0]) || ($a[2] eq "A") ){
|
||||
$page=14;
|
||||
}elsif( ($a[2] eq $owg_channel[1]) || ($a[2] eq "B") ){
|
||||
$page=15;
|
||||
} else {
|
||||
return "OWCOUNT: Invalid midnight counter address, must be A, B or defined channel name"
|
||||
}
|
||||
return "OWCOUNT: $name.$reading [$page] =>".$hash->{owg_str}->[$page];
|
||||
}
|
||||
}
|
||||
if( $reading eq "midnight" ){
|
||||
return "OWCOUNT: get needs parameter when reading midnight: <channel>"
|
||||
if( int(@a)<3 );
|
||||
#-- find out which channel we have
|
||||
if( ($a[2] eq $owg_channel[0]) || ($a[2] eq "A") ){
|
||||
$page=14;
|
||||
}elsif( ($a[2] eq $owg_channel[1]) || ($a[2] eq "B") ){
|
||||
$page=15;
|
||||
} else {
|
||||
return "OWCOUNT: Invalid midnight counter address, must be A, B or defined channel name"
|
||||
}
|
||||
$ret = OWCOUNT_GetPage($hash,$page,1);
|
||||
#-- when we have a return code, we have an error
|
||||
@ -791,28 +801,28 @@ sub OWCOUNT_GetPage ($$$) {
|
||||
}else{
|
||||
return "OWCOUNT: GetPage with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- process results
|
||||
if( defined($ret) ){
|
||||
return "OWCOUNT: Could not get values from device $name, reason: ".$ret;
|
||||
} else {
|
||||
return undef
|
||||
if ($nomemory==0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#-- when we are here, we need to read the files
|
||||
my $strval = OWCOUNT_recall($hash,"OWCOUNT_".$name."_".$page.".dat");
|
||||
if( ($page==14)||($page==15) ){
|
||||
#-- when we are here, we need to read the files
|
||||
my $strval = OWCOUNT_recall($hash,"OWCOUNT_".$name."_".$page.".dat");
|
||||
|
||||
#-- midnight value
|
||||
#-- new format
|
||||
if ($strval =~ /^\d\d\d\d-\d\d-\d\d.*/){
|
||||
my @data=split(' ',$strval);
|
||||
$strval = $data[2];
|
||||
}
|
||||
#-- parse float from midnight
|
||||
$strval =~ s/[^\d\.]+//g;
|
||||
$strval = 0.0 if(!defined($strval) or $strval !~ /^\d+\.\d*$/);
|
||||
$strval = int($strval*100)/100;
|
||||
$hash->{owg_midnight}->[$page-14] = $strval;
|
||||
#-- midnight value
|
||||
#-- new format
|
||||
if ($strval =~ /^\d\d\d\d-\d\d-\d\d.*/){
|
||||
my @data=split(' ',$strval);
|
||||
$strval = $data[2];
|
||||
}
|
||||
#-- parse float from midnight
|
||||
$strval =~ s/[^\d\.]+//g;
|
||||
$strval = 0.0 if(!defined($strval) or $strval !~ /^\d+\.\d*$/);
|
||||
$strval = int($strval*100)/100;
|
||||
$hash->{owg_midnight}->[$page-14] = $strval;
|
||||
}
|
||||
OWCOUNT_FormatValues($hash)
|
||||
if($oldfinal==1);
|
||||
|
||||
@ -889,7 +899,6 @@ sub OWCOUNT_GetMonth($) {
|
||||
return "cannot open logfile of LogM";
|
||||
}
|
||||
|
||||
|
||||
#-- sum and average
|
||||
for (my $i=0;$i<int(@owg_fixed);$i++){
|
||||
$total = 0.0;
|
||||
@ -1089,10 +1098,31 @@ sub OWCOUNT_InitializeDevice($) {
|
||||
}
|
||||
|
||||
#-- testing if it is the emulator
|
||||
#-- The model may be DS2423 or DS2423emu. Some weird people are violating 1-Wire integrity by using the
|
||||
#-- The model may be DS2423, DS2423enew or DS2423eold. Some weird people are violating 1-Wire integrity by using the
|
||||
# the same family ID although the DS2423emu does not fully support the DS2423 commands.
|
||||
# Model attribute will be modified now after checking for memory
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXCOUNT_GetPage($hash,14,0);
|
||||
$olddata = $hash->{owg_str}->[14];
|
||||
$ret = OWXCOUNT_SetPage($hash,14,$newdata);
|
||||
$ret = OWXCOUNT_GetPage($hash,14,0);
|
||||
$ret = OWXCOUNT_SetPage($hash,14,$olddata);
|
||||
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWXCOUNT_GetPage($hash,14,0);
|
||||
$olddata = $hash->{owg_str}->[14];
|
||||
$ret = OWFSCOUNT_SetPage($hash,14,$newdata);
|
||||
$ret = OWFSCOUNT_GetPage($hash,14,0);
|
||||
$ret = OWFSCOUNT_SetPage($hash,14,$olddata);
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWCOUNT: InitializeDevice with wrong IODev type $interface";
|
||||
}
|
||||
#Log 1,"FIRST CHECK: written $newdata, read ".substr($hash->{owg_str}->[14],0,length($newdata));
|
||||
my $nomid = ( substr($hash->{owg_str}->[14],0,length($newdata)) ne $newdata );
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXCOUNT_GetPage($hash,0,0);
|
||||
$olddata = $hash->{owg_str}->[0];
|
||||
@ -1111,13 +1141,19 @@ sub OWCOUNT_InitializeDevice($) {
|
||||
}else{
|
||||
return "OWCOUNT: InitializeDevice with wrong IODev type $interface";
|
||||
}
|
||||
#Log 1,"SECOND CHECK: written $newdata, read ".substr($hash->{owg_str}->[0],0,length($newdata));
|
||||
my $nomem = ( substr($hash->{owg_str}->[0],0,length($newdata)) ne $newdata );
|
||||
#-- Here we test if writing the memory is ok.
|
||||
if( substr($hash->{owg_str}->[0],0,length($newdata)) ne $newdata ){
|
||||
Log 1,"OWCOUNT: model attribute of $name set to DS2423emu because no memory found";
|
||||
CommandAttr (undef,"$name model DS2423emu");
|
||||
if( !$nomid && $nomem ){
|
||||
Log 1,"OWCOUNT: model attribute of $name set to DS2423enew";
|
||||
CommandAttr (undef,"$name model DS2423enew");
|
||||
CommandAttr (undef,"$name nomemory 0");
|
||||
} elsif( $nomid && $nomem ){
|
||||
Log 1,"OWCOUNT: model attribute of $name set to DS2423eold because no memory found";
|
||||
CommandAttr (undef,"$name model DS2423eold");
|
||||
CommandAttr (undef,"$name nomemory 1");
|
||||
}
|
||||
|
||||
|
||||
#-- Set state to initialized
|
||||
readingsSingleUpdate($hash,"state","initialized",1);
|
||||
|
||||
@ -1179,7 +1215,7 @@ sub OWCOUNT_Set($@) {
|
||||
#-- set memory page/counter according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- check syntax for setting memory page 0..13 or midnight A/B
|
||||
#-- check syntax for setting memory page 0..13
|
||||
my $nomemory = defined($attr{$name}{"nomemory"}) ? $attr{$name}{"nomemory"} : 0;
|
||||
if( $key eq "memory" ){
|
||||
return "OWCOUNT: Memory usage disabled"
|
||||
@ -1204,8 +1240,10 @@ sub OWCOUNT_Set($@) {
|
||||
}
|
||||
$ret = OWCOUNT_SetPage($hash,$page,$data);
|
||||
}
|
||||
if( $key eq "midnight" ){
|
||||
return "OWCOUNT: Set needs parameter when writing midnight: <channel>"
|
||||
|
||||
#-- other commands are per channel
|
||||
if( ($key eq "midnight") || ($key eq "counter" )){
|
||||
return "OWCOUNT: Set $key needs parameter: <channel>"
|
||||
if( int(@a)<2 );
|
||||
#-- find out which channel we have
|
||||
if( ($a[2] eq $owg_channel[0]) || ($a[2] eq "A") ){
|
||||
@ -1213,12 +1251,34 @@ sub OWCOUNT_Set($@) {
|
||||
}elsif( ($a[2] eq $owg_channel[1]) || ($a[2] eq "B") ){
|
||||
$page=15;
|
||||
} else {
|
||||
return "OWCOUNT: Invalid midnight counter address, must be A, B or defined channel name"
|
||||
return "OWCOUNT: Invalid counter address, must be A, B or defined channel name"
|
||||
}
|
||||
#-- mode normal or daily
|
||||
my $daily = 0;
|
||||
if( defined($attr{$name}{$owg_fixed[$page-14]."Mode"} )){
|
||||
if( $attr{$name}{$owg_fixed[$page-14]."Mode"} eq "daily"){
|
||||
$daily = 1;
|
||||
}
|
||||
}
|
||||
return "OWCOUNT: Set $key for channel $a[2] not possible, is not in daily mode"
|
||||
if( $daily==0 );
|
||||
|
||||
my ($sec, $min, $hour, $day, $month, $year, $wday,$yday,$isdst) = localtime(time);
|
||||
$data = sprintf("%4d-%02d-%02d midnight %7.2f",
|
||||
|
||||
if( $key eq "midnight" ){
|
||||
$data = sprintf("%4d-%02d-%02d midnight %7.2f",
|
||||
$year+1900,$month+1,$day,$a[3]);
|
||||
$ret = OWCOUNT_SetPage($hash,$page,$data);
|
||||
$ret = OWCOUNT_SetPage($hash,$page,$data);
|
||||
}
|
||||
#--
|
||||
if( $key eq "counter" ){
|
||||
my $midnew=($hash->{owg_val}->[$page-14] + $hash->{READINGS}{$owg_channel[$page-14]}{OFFSET})*
|
||||
$hash->{READINGS}{$owg_channel[$page-14]}{FACTOR} - $a[3];
|
||||
$data = sprintf("%4d-%02d-%02d midnight %7.2f",
|
||||
$year+1900,$month+1,$day,$midnew);
|
||||
#Log 1,"OLD MIDNIGHT ".$hash->{owg_midnight}->[$page-14]." NEW $midnew";
|
||||
$ret = OWCOUNT_SetPage($hash,$page,$data);
|
||||
}
|
||||
}
|
||||
#-- process results - we have to reread the device
|
||||
if( defined($ret) && ($ret ne "") ){
|
||||
@ -1390,6 +1450,12 @@ sub OWFSCOUNT_GetPage($$$) {
|
||||
|
||||
$hash->{owg_val}->[0] = $vval;
|
||||
$hash->{owg_str}->[14] = $strval;
|
||||
#-- midnight value
|
||||
#-- new format
|
||||
if ($strval =~ /^\d\d\d\d-\d\d-\d\d.*/){
|
||||
my @data=split(' ',$strval);
|
||||
$strval = $data[2];
|
||||
}
|
||||
#-- parse float from midnight
|
||||
$strval =~ s/[^\d\.]+//g;
|
||||
$strval = 0.0 if(!defined($strval) or $strval !~ /^\d+\.?\d*$/);
|
||||
@ -1407,6 +1473,12 @@ sub OWFSCOUNT_GetPage($$$) {
|
||||
$hash->{owg_val}->[1] = $vval;
|
||||
$hash->{owg_str}->[15] = $strval;
|
||||
|
||||
#-- midnight value
|
||||
#-- new format
|
||||
if ($strval =~ /^\d\d\d\d-\d\d-\d\d.*/){
|
||||
my @data=split(' ',$strval);
|
||||
$strval = $data[2];
|
||||
}
|
||||
#-- parse float from midnight
|
||||
$strval =~ s/[^\d\.]+//g;
|
||||
$strval = 0.0 if(!defined($strval) or $strval !~ /^\d+\.\d*$/);
|
||||
@ -1451,6 +1523,21 @@ sub OWFSCOUNT_SetPage($$$) {
|
||||
if( ($page<0) || ($page>15) ){
|
||||
return "wrong memory page write attempt";
|
||||
}
|
||||
#=============== midnight value =====================================
|
||||
if( ($page==14) || ($page==15) ){
|
||||
my $strval=$data;
|
||||
#-- midnight value
|
||||
#-- new format
|
||||
if ($strval =~ /^\d\d\d\d-\d\d-\d\d.*/){
|
||||
my @datan=split(' ',$strval);
|
||||
$strval = $datan[2];
|
||||
}
|
||||
#-- parse float from midnight
|
||||
$strval =~ s/[^\d\.]+//g;
|
||||
$strval = 0.0 if(!defined($strval) or $strval !~ /^\d+\.\d*$/);
|
||||
$strval = int($strval*100)/100;
|
||||
$hash->{owg_midnight}->[$page-14] = $strval;
|
||||
}
|
||||
OWServer_Write($master, "/$owx_add/pages/page.".$page,$data );
|
||||
return undef
|
||||
}
|
||||
@ -1487,15 +1574,25 @@ sub OWXCOUNT_BinValues($$$$$$$$) {
|
||||
if( int(@data) < 45);
|
||||
#return "invalid data"
|
||||
# if (ord($data[17])<=0);
|
||||
Log 1,"invalid CRC"
|
||||
Log 1,"invalid CRC, ".ord($data[43])." ".ord($data[44])
|
||||
if (OWX_CRC16(substr($res,0,43),$data[43],$data[44]) == 0);
|
||||
|
||||
#-- first 3 command, next 32 are memory
|
||||
#my $res2 = "OWCOUNT FIRST 10 BYTES for device $owx_dev ARE ";
|
||||
#for($i=0;$i<10;$i++){
|
||||
# $j=int(ord(substr($res,$i,1))/16);
|
||||
# $k=ord(substr($res,$i,1))%16;
|
||||
# $res2.=sprintf "0x%1x%1x ",$j,$k;
|
||||
#}
|
||||
#main::Log(1, $res2);
|
||||
|
||||
#--
|
||||
my $nomemory = defined($attr{$name}{"nomemory"}) ? $attr{$name}{"nomemory"} : 0;
|
||||
if( $nomemory==0 ){
|
||||
#-- memory part, treated as string
|
||||
$strval=substr($res,3,32);
|
||||
$hash->{owg_str}->[$page]=$strval;
|
||||
#Log 1," retrieved on device $owx_dev for page $page STRING $strval";
|
||||
}
|
||||
#-- counter part
|
||||
if( ($page == 14) || ($page == 15) ){
|
||||
@ -1551,7 +1648,7 @@ sub OWXCOUNT_GetPage($$$) {
|
||||
|
||||
#-- reset presence
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
#=============== wrong value requested ===============================
|
||||
@ -1596,8 +1693,11 @@ sub OWXCOUNT_GetPage($$$) {
|
||||
#-- reset the bus (needed to stop receiving data ?)
|
||||
OWX_Reset($master);
|
||||
#-- for processing we need 45 bytes
|
||||
OWXCOUNT_BinValues($hash,$page,undef,undef,$owx_dev,undef,$final,substr($res,9))
|
||||
if( length($res)==54 );
|
||||
return "$owx_dev not accessible in reading"
|
||||
if( $res eq 0 );
|
||||
return "$owx_dev has returned invalid data"
|
||||
if( length($res)!=54);
|
||||
OWXCOUNT_BinValues($hash,$page,undef,undef,$owx_dev,undef,$final,substr($res,9));
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
@ -1617,6 +1717,8 @@ sub OWXCOUNT_SetPage($$$) {
|
||||
|
||||
my ($select, $res, $res2, $res3);
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
@ -1625,19 +1727,44 @@ sub OWXCOUNT_SetPage($$$) {
|
||||
if( ($page<0) || ($page>15) ){
|
||||
return "wrong memory page write attempt";
|
||||
}
|
||||
#=============== midnight value =====================================
|
||||
if( ($page==14) || ($page==15) ){
|
||||
my $strval=$data;
|
||||
#-- midnight value
|
||||
#-- new format
|
||||
if ($strval =~ /^\d\d\d\d-\d\d-\d\d.*/){
|
||||
my @datan=split(' ',$strval);
|
||||
$strval = $datan[2];
|
||||
}
|
||||
#-- parse float from midnight
|
||||
$strval =~ s/[^\d\.]+//g;
|
||||
$strval = 0.0 if(!defined($strval) or $strval !~ /^\d+\.\d*$/);
|
||||
$strval = int($strval*100)/100;
|
||||
$hash->{owg_midnight}->[$page-14] = $strval;
|
||||
}
|
||||
#=============== set memory =========================================
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command
|
||||
# \x0F TA1 TA2 and the read scratchpad command reading 3 data bytes
|
||||
# \x0F TA1 TA2 followed by the data
|
||||
my $ta2 = ($page*32) >> 8;
|
||||
my $ta1 = ($page*32) & 255;
|
||||
#Log 1, "OWXCOUNT: setting page Nr. $ta2 $ta1";
|
||||
#Log 1, "OWXCOUNT: setting page Nr. $ta2 $ta1 $data";
|
||||
$select=sprintf("\x0F%c%c",$ta1,$ta2).$data;
|
||||
|
||||
#-- first command, next 2 are address, then data
|
||||
#$res2 = "OWCOUNT SET PAGE 1 device $owx_dev ";
|
||||
#for($i=0;$i<10;$i++){
|
||||
# $j=int(ord(substr($select,$i,1))/16);
|
||||
# $k=ord(substr($select,$i,1))%16;
|
||||
# $res2.=sprintf "0x%1x%1x ",$j,$k;
|
||||
#}
|
||||
#main::Log(1, $res2);
|
||||
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "setpage", 1, $owx_dev, $select, 0, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "device $owx_dev not accessible for writing";
|
||||
return "device $owx_dev not accessible in writing scratchpad";
|
||||
}
|
||||
#-- synchronous mode
|
||||
} else {
|
||||
@ -1649,34 +1776,53 @@ sub OWXCOUNT_SetPage($$$) {
|
||||
}
|
||||
}
|
||||
#-- issue the match ROM command \x55 and the read scratchpad command
|
||||
# \xAA
|
||||
# \xAA, receiving 2 address bytes, 1 status byte and scratchpad content
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "setpage", 1, $owx_dev, "\xAA", 0, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "device $owx_dev not accessible for writing";
|
||||
return "device $owx_dev not accessible in reading scratchpad";
|
||||
}
|
||||
#-- synchronous mode
|
||||
} else {
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- reading 9 + 4 + 16 bytes = 28 bytes
|
||||
#-- reading 9 + 3 + up to 32 bytes
|
||||
# TODO: sometimes much less than 28
|
||||
$res=OWX_Complex($master,$owx_dev,"\xAA",28);
|
||||
if( length($res) < 13 ){
|
||||
return "device $owx_dev not accessible in reading scratchpad";
|
||||
}
|
||||
|
||||
#-- first 1 command, next 2 are address, then data
|
||||
#$res3 = substr($res,9,10);
|
||||
#$res2 = "OWCOUNT SET PAGE 2 device $owx_dev ";
|
||||
#for($i=0;$i<10;$i++){
|
||||
# $j=int(ord(substr($res3,$i,1))/16);
|
||||
# $k=ord(substr($res3,$i,1))%16;
|
||||
# $res2.=sprintf "0x%1x%1x ",$j,$k;
|
||||
#}
|
||||
#main::Log(1, $res2);
|
||||
}
|
||||
#-- issue the match ROM command \x55 and the copy scratchpad command
|
||||
# \x5A followed by 3 byte authentication code
|
||||
# \x5A followed by 3 byte authentication code obtained in previous read
|
||||
$select="\x5A".substr($res,10,3);
|
||||
#-- asynchronous mode
|
||||
#-- first command, next 2 are address, then data
|
||||
#$res2 = "OWCOUNT SET PAGE 3 device $owx_dev ";
|
||||
#for($i=0;$i<10;$i++){
|
||||
# $j=int(ord(substr($select,$i,1))/16);
|
||||
# $k=ord(substr($select,$i,1))%16;
|
||||
# $res2.=sprintf "0x%1x%1x ",$j,$k;
|
||||
#}
|
||||
#main::Log(1, $res2);
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
# THIS IS WRONG !!
|
||||
if (OWX_Execute( $master, "setpage", 1, $owx_dev, "\xAA", 0, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "device $owx_dev not accessible for writing";
|
||||
return "device $owx_dev not accessible for copying scratchpad";
|
||||
}
|
||||
#-- synchronous mode
|
||||
} else {
|
||||
@ -1686,7 +1832,7 @@ sub OWXCOUNT_SetPage($$$) {
|
||||
|
||||
#-- process results
|
||||
if( $res eq 0 ){
|
||||
return "device $owx_dev not accessible for writing";
|
||||
return "device $owx_dev not accessible for copying scratchpad";
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
@ -1729,7 +1875,8 @@ sub OWXCOUNT_SetPage($$$) {
|
||||
id), currently the following values are permitted: <ul>
|
||||
<li>model DS2423 with family id 1D (default if the model parameter is
|
||||
omitted)</li>
|
||||
<li>model DS2423emu with family id 1D - works like DS2423 except that the internal memory is not used</li>
|
||||
<li>model DS2423enew with family id 1D - emulator, works like DS2423</li>
|
||||
<li>model DS2423eold with family id 1D - emulator, works like DS2423 except that the internal memory is not present</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
@ -1755,9 +1902,13 @@ sub OWXCOUNT_SetPage($$$) {
|
||||
<code>set <name> memory <page> <string></code></a><br />Write 32 bytes to
|
||||
memory page 0..13 </li>
|
||||
<li><a name="owcount_midnight">
|
||||
<code>set <name> midnight <channel-name> <int></code></a><br />Write the
|
||||
<code>set <name> midnight <channel-name> <val></code></a><br />Write the
|
||||
day's starting value for counter <channel> (A, B or named channel, see
|
||||
below)</li>
|
||||
<li><a name="owcount_counter">
|
||||
<code>set <name> counter <channel-name> <val></code></a><br />Correct the midnight
|
||||
value such that counter <channel> (A, B or named channel, see
|
||||
below) displays value <val></li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWCOUNTget"></a>
|
||||
|
@ -49,11 +49,13 @@
|
||||
package main;
|
||||
|
||||
use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
|
||||
use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
my $owx_version="5.06";
|
||||
my $owx_version="5.11";
|
||||
#-- declare variables
|
||||
my %gets = (
|
||||
"present" => "",
|
||||
@ -134,6 +136,9 @@ sub OWID_Define ($$) {
|
||||
if( $fam eq "01" ){
|
||||
$model = "DS2401";
|
||||
CommandAttr (undef,"$name model DS2401");
|
||||
}elsif( $fam eq "09" ){
|
||||
$model = "DS2502";
|
||||
CommandAttr (undef,"$name model DS2502");
|
||||
}else{
|
||||
$model = "unknown";
|
||||
CommandAttr (undef,"$name model unknown");
|
||||
@ -148,6 +153,9 @@ sub OWID_Define ($$) {
|
||||
if( $fam eq "01" ){
|
||||
$model = "DS2401";
|
||||
CommandAttr (undef,"$name model DS2401");
|
||||
}elsif( $fam eq "09" ){
|
||||
$model = "DS2502";
|
||||
CommandAttr (undef,"$name model DS2502");
|
||||
}else{
|
||||
$model = "unknown";
|
||||
CommandAttr (undef,"$name model unknown");
|
||||
@ -157,6 +165,9 @@ sub OWID_Define ($$) {
|
||||
if( $model eq "DS2401" ){
|
||||
$fam = "01";
|
||||
CommandAttr (undef,"$name model DS2401");
|
||||
}elsif( $model eq "DS2502" ){
|
||||
$fam = "09";
|
||||
CommandAttr (undef,"$name model DS2502");
|
||||
}else{
|
||||
return "OWID: Unknown 1-Wire device model $model";
|
||||
}
|
||||
@ -306,7 +317,7 @@ sub OWID_GetValues($) {
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $value = "";
|
||||
my $value = 0;
|
||||
my $ret = "";
|
||||
my $offset;
|
||||
my $factor;
|
||||
@ -317,7 +328,18 @@ sub OWID_GetValues($) {
|
||||
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||
|
||||
#-- measure elapsed time
|
||||
my $t0 = [gettimeofday];
|
||||
|
||||
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||
|
||||
#my $thr = threads->create('OWX_Verify', $master, $hash->{ROM_ID});
|
||||
#$thr->detach();
|
||||
|
||||
my $t1 = [gettimeofday];
|
||||
my $t0_t1 = tv_interval $t0, $t1;
|
||||
#Log 1,"====> Time for verify = $t0_t1";
|
||||
|
||||
#-- generate an event only if presence has changed
|
||||
if( $value == 0 ){
|
||||
|
@ -70,7 +70,7 @@ use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
my $owx_version="5.06";
|
||||
my $owx_version="5.11";
|
||||
#-- flexible channel name
|
||||
my $owg_channel;
|
||||
|
||||
@ -913,9 +913,10 @@ sub OWXMULTI_GetValues($$) {
|
||||
OWX_Reset($master);
|
||||
$res=OWX_Complex($master,$owx_dev,"\xBE\x00",9);
|
||||
#Log 1,"OWXMULTI: data length from reading device is ".length($res)." bytes";
|
||||
if( $res eq 0 ){
|
||||
return "$owx_dev not accessible in 2nd step";
|
||||
}
|
||||
return "$owx_dev not accessible in 2nd step"
|
||||
if( $res eq 0 );
|
||||
return "$owx_dev has returned invalid data"
|
||||
if( length($res)!=20);
|
||||
OWXMULTI_BinValues($hash,"ds2438.getvdd",1,undef,$owx_dev,undef,undef,substr($res,11));
|
||||
}
|
||||
#------------------------------------------------------------------------------------
|
||||
@ -994,9 +995,10 @@ sub OWXMULTI_GetValues($$) {
|
||||
OWX_Reset($master);
|
||||
$res=OWX_Complex($master,$owx_dev,"\xBE\x00",9);
|
||||
#-- process results
|
||||
if( $res eq 0 ){
|
||||
return "$owx_dev not accessible in 2nd step";
|
||||
}
|
||||
return "$owx_dev not accessible in 2nd step"
|
||||
if( $res eq 0 );
|
||||
return "$owx_dev has returned invalid data"
|
||||
if( length($res)!=20);
|
||||
OWXMULTI_BinValues($hash,"ds2438.getvad",1,undef,$owx_dev,undef,undef,substr($res,11));
|
||||
}
|
||||
return undef;
|
||||
|
@ -76,7 +76,7 @@ use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
my $owx_version="5.06";
|
||||
my $owx_version="5.11";
|
||||
#-- fixed raw channel name, flexible channel name
|
||||
my @owg_fixed = ("A","B","C","D","E","F","G","H");
|
||||
my @owg_channel = ("A","B","C","D","E","F","G","H");
|
||||
@ -1123,9 +1123,10 @@ sub OWXSWITCH_GetState($) {
|
||||
}else{
|
||||
OWX_Reset($master);
|
||||
$res=OWX_Complex($master,$owx_dev,$select,4);
|
||||
if( $res eq 0 ){
|
||||
return "not accessible in reading";
|
||||
}
|
||||
return "$owx_dev not accessible in reading"
|
||||
if( $res eq 0 );
|
||||
return "$owx_dev has returned invalid data"
|
||||
if( length($res)!=16);
|
||||
OWX_Reset($master);
|
||||
OWXSWITCH_BinValues($hash,"ds2406.getstate",1,undef,$owx_dev,substr($res,9,3),undef,substr($res,12));
|
||||
}
|
||||
@ -1148,9 +1149,10 @@ sub OWXSWITCH_GetState($) {
|
||||
}else{
|
||||
OWX_Reset($master);
|
||||
$res=OWX_Complex($master,$owx_dev,$select,10);
|
||||
if( $res eq 0 ){
|
||||
return "not accessible in reading";
|
||||
}
|
||||
return "$owx_dev not accessible in reading"
|
||||
if( $res eq 0 );
|
||||
return "$owx_dev has returned invalid data"
|
||||
if( length($res)!=22);
|
||||
OWX_Reset($master);
|
||||
return OWXSWITCH_BinValues($hash,"ds2408.getstate",1,undef,$owx_dev,substr($res,9,3),undef,substr($res,12));
|
||||
}
|
||||
@ -1172,10 +1174,11 @@ sub OWXSWITCH_GetState($) {
|
||||
}else{
|
||||
OWX_Reset($master);
|
||||
$res=OWX_Complex($master,$owx_dev,"\xF5",2);
|
||||
if( $res eq 0 ){
|
||||
return "not accessible in reading";
|
||||
}
|
||||
OWX_Reset($master);
|
||||
return "$owx_dev not accessible in reading"
|
||||
if( $res eq 0 );
|
||||
return "$owx_dev has returned invalid data"
|
||||
if( length($res)!=12);
|
||||
#OWX_Reset($master);
|
||||
return OWXSWITCH_BinValues($hash,"ds2413.getstate",1,undef,$owx_dev,substr($res,9,1),undef,substr($res,10));
|
||||
}
|
||||
} else {
|
||||
|
@ -75,7 +75,7 @@ use warnings;
|
||||
sub Log($$);
|
||||
sub AttrVal($$$);
|
||||
|
||||
my $owx_version="5.06";
|
||||
my $owx_version="5.11";
|
||||
|
||||
my %gets = (
|
||||
"id" => "",
|
||||
@ -966,9 +966,10 @@ sub OWXTHERM_GetValues($) {
|
||||
} else {
|
||||
OWX_Reset($master);
|
||||
my $res=OWX_Complex($master,$owx_dev,"\xBE",9);
|
||||
if( $res eq 0 ){
|
||||
return "$owx_dev not accessible in reading";
|
||||
}
|
||||
return "$owx_dev not accessible in reading"
|
||||
if( $res eq 0 );
|
||||
return "$owx_dev has returned invalid data"
|
||||
if( length($res)!=19);
|
||||
OWXTHERM_BinValues($hash,"ds182x.reading",1,undef,$owx_dev,undef,undef,substr($res,10,9));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user