2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +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

View File

@ -124,7 +124,7 @@ my %c2bset; # Setteable values
my %defptr;
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;
#####################################
@ -159,72 +159,92 @@ FHT_Initialize($)
}
sub
FHT_Set($@)
{
my ($hash, @a) = @_;
my $ret = undef;
my ($hash, @a) = @_;
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 $cmd = $a[1];
my $name = shift(@a);
return "Unknown argument $cmd, choose one of " .
join(" ", sort {$c2bset{$a} cmp $c2bset{$b} } keys %c2bset)
if(!defined($c2bset{$cmd}));
return "\"set $a[0]\" needs two parameters"
if(@a != 3 && !(@a == 2 && $nosetarg{$cmd}));
my $ncmd = 0;
my $arg = "020183" . $hash->{CODE};
my ($cmd, $val) = ("", "");
my $val = $a[2];
my $arg = "020183" . $hash->{CODE} . $c2bset{$cmd};
while(@a) {
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 "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 "Unknown argument $lcmd, choose one of " .
join(" ", sort {$c2bset{$a} cmp $c2bset{$b} } keys %c2bset)
if(!defined($c2bset{$lcmd}));
return "\"set $name\" needs a parameters"
if(@a < 1 && !$nosetarg{$lcmd});
$ncmd++;
} 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)/);
my $a = ($1*6) + ($2/10);
$arg .= sprintf("%02x", $a);
$arg .= $c2bset{$lcmd};
my $nt = sprintf("%02d:%02d", $1, ($2/10)*10);
$ret = "Rounded time to $nt" if($nt ne $val);
$val = $nt;
if ($lcmd =~ m/-temp/) {
} 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)
if(!defined($m2c{$val}));
$arg .= sprintf("%02x", $m2c{$val});
} elsif($lcmd =~ m/-from/ || $lcmd =~ m/-to/) {
} 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"
if($val !~ m/^[1-5]$/);
$arg .= sprintf("%02x", $val);
$val = "$val.0";
my $nt = sprintf("%02d:%02d", $1, ($2/10)*10);
$ret = "Rounded time to $nt" if($nt ne $val);
$val = $nt;
} 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 = "";
$ioname = $hash->{IODev}->{NAME} if($hash->{IODev});
if($attr{$ioname} && $attr{$ioname}{fhtsoftbuffer}) {
if($ncmd > 1) {
return "Cannot accept multiple FHT commands with fhtsoftbuffer enabled";
}
my $io = $hash->{IODev};
my %h = (HASH => $hash, CMD => $cmd, VAL => $val, ARG => $arg);

View File

@ -277,7 +277,7 @@ EmGetData($$)
$serport->stopbits(1);
$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";
for(my $rep = 0; $rep < 3; $rep++) {

View File

@ -447,8 +447,8 @@ split in multiple lines<br><br>
Used for at commands: skip the execution of the command the next
time.</li><br>
<a name="softbuffer"></a>
<li>softbuffer<br />
<a name="fhtsoftbuffer"></a>
<li>fhtsoftbuffer<br />
Can be applied to FHZ devices.<br />
As the FHZ command buffer for FHT devices is limited, and commands
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>
<li>retrycount<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
no confirmation message is rececived from the corresponding FHT
device.<br>
@ -474,7 +474,7 @@ split in multiple lines<br><br>
<code>attr lamp dummy</code><br>
<code>attr lamp loglevel 6</code><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 softmaxretry 4 # stop resending failed commands to FHT devices after 4 retries.</code> </ul>
<br>