2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-28 02:44:53 +00:00

Multiple FHT command mode implemented

git-svn-id: https://svn.fhem.de/fhem/trunk@146 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2008-01-17 21:08:15 +00:00
parent 5833bc1e61
commit fffce6f2ed
3 changed files with 67 additions and 47 deletions

@ -124,7 +124,7 @@ my %c2bset; # Setteable values
my %defptr; my %defptr;
my $minFhzHardwareBuffer = 10; # min fhtbuf free bytes before sending commands my $minFhzHardwareBuffer = 10; # min fhtbuf free bytes before sending commands
my $retryafter = 240; # in seconds, only when softbuffer is active my $retryafter = 240; # in seconds, only when fhtsoftbuffer is active
my $cmdcount = 0; my $cmdcount = 0;
##################################### #####################################
@ -159,72 +159,92 @@ FHT_Initialize($)
} }
sub sub
FHT_Set($@) FHT_Set($@)
{ {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $ret = undef; my $ret;
return "\"set $a[0]\" needs two parameters" if(@a < 2); return "\"set $a[0]\" needs at least two parameters" if(@a < 2);
my $name = $a[0]; my $name = shift(@a);
my $cmd = $a[1];
return "Unknown argument $cmd, choose one of " . my $ncmd = 0;
join(" ", sort {$c2bset{$a} cmp $c2bset{$b} } keys %c2bset) my $arg = "020183" . $hash->{CODE};
if(!defined($c2bset{$cmd})); my ($cmd, $val) = ("", "");
return "\"set $a[0]\" needs two parameters"
if(@a != 3 && !(@a == 2 && $nosetarg{$cmd}));
my $val = $a[2]; while(@a) {
my $arg = "020183" . $hash->{CODE} . $c2bset{$cmd}; my $lcmd = shift(@a);
if ($cmd =~ m/-temp/) { $cmd .=" " if($cmd);
$cmd .= $lcmd;
return "Invalid temperature, use NN.N" if($val !~ m/^\d*\.?\d+$/); return "Unknown argument $lcmd, choose one of " .
return "Invalid temperature, must between 5.5 and 30.5" join(" ", sort {$c2bset{$a} cmp $c2bset{$b} } keys %c2bset)
if($val < 5.5 || $val > 30.5); if(!defined($c2bset{$lcmd}));
my $a = int($val*2); return "\"set $name\" needs a parameters"
$arg .= sprintf("%02x", $a); if(@a < 1 && !$nosetarg{$lcmd});
$ret = sprintf("Rounded temperature to %.1f", $a/2) if($a/2 != $val); $ncmd++;
$val = sprintf("%.1f", $a/2);
} elsif($cmd =~ m/-from/ || $cmd =~ m/-to/) { if(!$nosetarg{$lcmd}) {
$val = shift(@a);
$cmd .= " $val";
} else {
$val = undef;
}
return "Invalid timeformat, use HH:MM" if($val !~ m/^([0-2]\d):([0-5]\d)/); $arg .= $c2bset{$lcmd};
my $a = ($1*6) + ($2/10);
$arg .= sprintf("%02x", $a);
my $nt = sprintf("%02d:%02d", $1, ($2/10)*10); if ($lcmd =~ m/-temp/) {
$ret = "Rounded time to $nt" if($nt ne $val);
$val = $nt;
} elsif($cmd eq "mode") { return "Invalid temperature, use NN.N" if($val !~ m/^\d*\.?\d+$/);
return "Invalid temperature, must between 5.5 and 30.5"
if($val < 5.5 || $val > 30.5);
my $a = int($val*2);
$arg .= sprintf("%02x", $a);
$ret = sprintf("Rounded temperature to %.1f", $a/2) if($a/2 != $val);
$val = sprintf("%.1f", $a/2);
return "Invalid mode, use one of " . join(" ", sort keys %m2c) } elsif($lcmd =~ m/-from/ || $lcmd =~ m/-to/) {
if(!defined($m2c{$val}));
$arg .= sprintf("%02x", $m2c{$val});
} elsif ($cmd eq "lowtemp-offset") { return "Invalid timeformat, use HH:MM"
if($val !~ m/^([0-2]\d):([0-5]\d)/);
my $a = ($1*6) + ($2/10);
$arg .= sprintf("%02x", $a);
return "Invalid lowtemperature-offset, must between 1 and 5" my $nt = sprintf("%02d:%02d", $1, ($2/10)*10);
if($val !~ m/^[1-5]$/); $ret = "Rounded time to $nt" if($nt ne $val);
$arg .= sprintf("%02x", $val); $val = $nt;
$val = "$val.0";
} else { # Holiday1, Holiday2 } elsif($lcmd eq "mode") {
$arg .= sprintf("%02x", $val) if(defined($val)); return "Invalid mode, use one of " . join(" ", sort keys %m2c)
if(!defined($m2c{$val}));
$arg .= sprintf("%02x", $m2c{$val});
} elsif ($lcmd eq "lowtemp-offset") {
return "Invalid lowtemperature-offset, must between 1 and 5"
if($val !~ m/^[1-5]$/);
$arg .= sprintf("%02x", $val);
$val = "$val.0";
} else { # Holiday1, Holiday2
$arg .= sprintf("%02x", $val) if(defined($val));
}
} }
$val = "" if (!defined($val)); $val = "" if (!defined($val) || $ncmd > 1);
my $ioname = ""; my $ioname = "";
$ioname = $hash->{IODev}->{NAME} if($hash->{IODev}); $ioname = $hash->{IODev}->{NAME} if($hash->{IODev});
if($attr{$ioname} && $attr{$ioname}{fhtsoftbuffer}) { if($attr{$ioname} && $attr{$ioname}{fhtsoftbuffer}) {
if($ncmd > 1) {
return "Cannot accept multiple FHT commands with fhtsoftbuffer enabled";
}
my $io = $hash->{IODev}; my $io = $hash->{IODev};
my %h = (HASH => $hash, CMD => $cmd, VAL => $val, ARG => $arg); my %h = (HASH => $hash, CMD => $cmd, VAL => $val, ARG => $arg);

@ -277,7 +277,7 @@ EmGetData($$)
$serport->stopbits(1); $serport->stopbits(1);
$serport->handshake('none'); $serport->handshake('none');
Log 4, "EM: Sending " . unpack('H*', $d) . "\n"; Log 4, "EM: Sending " . unpack('H*', $d);
my $rm = "EM timeout reading the answer"; my $rm = "EM timeout reading the answer";
for(my $rep = 0; $rep < 3; $rep++) { for(my $rep = 0; $rep < 3; $rep++) {

@ -447,8 +447,8 @@ split in multiple lines<br><br>
Used for at commands: skip the execution of the command the next Used for at commands: skip the execution of the command the next
time.</li><br> time.</li><br>
<a name="softbuffer"></a> <a name="fhtsoftbuffer"></a>
<li>softbuffer<br /> <li>fhtsoftbuffer<br />
Can be applied to FHZ devices.<br /> Can be applied to FHZ devices.<br />
As the FHZ command buffer for FHT devices is limited, and commands As the FHZ command buffer for FHT devices is limited, and commands
are only sent to the FHT devices every 150 seconds, the hardware are only sent to the FHT devices every 150 seconds, the hardware
@ -459,7 +459,7 @@ split in multiple lines<br><br>
<a name="retrycount"></a> <a name="retrycount"></a>
<li>retrycount<br /> <li>retrycount<br />
Can be applied to FHT devices.<br /> Can be applied to FHT devices.<br />
If the <a href="#softbuffer">softbuffer</a> attribute is set, then If the <a href="#fhtsoftbuffer">fhtsoftbuffer</a> attribute is set, then
resend commands <code>retrycount</code> times if after 240 seconds resend commands <code>retrycount</code> times if after 240 seconds
no confirmation message is rececived from the corresponding FHT no confirmation message is rececived from the corresponding FHT
device.<br> device.<br>
@ -474,7 +474,7 @@ split in multiple lines<br><br>
<code>attr lamp dummy</code><br> <code>attr lamp dummy</code><br>
<code>attr lamp loglevel 6</code><br /> <code>attr lamp loglevel 6</code><br />
<br> <br>
<code>attr FHZ softbuffer 0 # disable the softbuffer for FHT devices</code><br /> <code>attr FHZ fhtsoftbuffer 0 # disable the fhtsoftbuffer for FHT devices</code><br />
<code>attr FHZ softrepeat 300 # resend failed commands to FHT devices after 300 seconds </code><br /> <code>attr FHZ softrepeat 300 # resend failed commands to FHT devices after 300 seconds </code><br />
<code>attr FHZ softmaxretry 4 # stop resending failed commands to FHT devices after 4 retries.</code> </ul> <code>attr FHZ softmaxretry 4 # stop resending failed commands to FHT devices after 4 retries.</code> </ul>
<br> <br>