mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
55_PIFACE: Watchdog function incorrectly by restart. Previous version restored.
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@19459 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b62dc62972
commit
47743b185e
@ -74,7 +74,7 @@ sub PIFACE_Initialize($){
|
|||||||
" watchdog:on,off,silent watchdogInterval";
|
" watchdog:on,off,silent watchdogInterval";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub PIFACE_Define($$) {
|
sub PIFACE_Define($$){
|
||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
$hash->{NOTIFYDEV} = "global";
|
$hash->{NOTIFYDEV} = "global";
|
||||||
@ -83,14 +83,14 @@ sub PIFACE_Define($$) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub PIFACE_Undefine($$) {
|
sub PIFACE_Undefine($$){
|
||||||
my($hash, $name) = @_;
|
my($hash, $name) = @_;
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub PIFACE_Set($@) {
|
sub PIFACE_Set($@) {
|
||||||
my ($hash, @a) = @_;
|
my ($hash, @a) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
if (IsDisabled($name)) {
|
if (IsDisabled($name)) {
|
||||||
Log3 $name, 4, "PIFACE $name set commands disabled.";
|
Log3 $name, 4, "PIFACE $name set commands disabled.";
|
||||||
@ -100,11 +100,11 @@ sub PIFACE_Set($@) {
|
|||||||
my $val = $a[2];
|
my $val = $a[2];
|
||||||
my ($adr, $cmd, $i, $j, $k);
|
my ($adr, $cmd, $i, $j, $k);
|
||||||
my $usage = "Unknown argument $port, choose one of all 0:0,1 1:0,1 2:0,1 3:0,1 4:0,1 5:0,1 6:0,1 7:0,1 ";
|
my $usage = "Unknown argument $port, choose one of all 0:0,1 1:0,1 2:0,1 3:0,1 4:0,1 5:0,1 6:0,1 7:0,1 ";
|
||||||
return $usage if ($port eq "?");
|
return $usage if $port eq "?";
|
||||||
if ($port ne "all") {
|
if ($port ne "all") {
|
||||||
$adr = $base + $port;
|
$adr = $base + $port;
|
||||||
Log3($name, 3, "PIFACE $name set port $port $val");
|
Log3($name, 3, "PIFACE $name set port $port $val");
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 write $adr $val";
|
$cmd = "$gpioCmd -p write $adr $val";
|
||||||
$cmd = `$cmd`;
|
$cmd = `$cmd`;
|
||||||
readingsSingleUpdate($hash, 'out'.$port, $val, 1);
|
readingsSingleUpdate($hash, 'out'.$port, $val, 1);
|
||||||
} else {
|
} else {
|
||||||
@ -116,7 +116,7 @@ sub PIFACE_Set($@) {
|
|||||||
$k = ($k) ? 1 : 0;
|
$k = ($k) ? 1 : 0;
|
||||||
Log3($name, 3, "PIFACE $name set port $i $k");
|
Log3($name, 3, "PIFACE $name set port $i $k");
|
||||||
$adr = $base + $i;
|
$adr = $base + $i;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 write $adr $k";
|
$cmd = "$gpioCmd -p write $adr $k";
|
||||||
$cmd = `$cmd`;
|
$cmd = `$cmd`;
|
||||||
readingsBulkUpdate($hash, 'out'.$i, $k);
|
readingsBulkUpdate($hash, 'out'.$i, $k);
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ sub PIFACE_Set($@) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub PIFACE_Get($@) {
|
sub PIFACE_Get($@){
|
||||||
my ($hash, @a) = @_;
|
my ($hash, @a) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $port = $a[1];
|
my $port = $a[1];
|
||||||
@ -137,22 +137,17 @@ sub PIFACE_Get($@) {
|
|||||||
if ($port eq "all") {
|
if ($port eq "all") {
|
||||||
PIFACE_Read_Inports(1, $hash);
|
PIFACE_Read_Inports(1, $hash);
|
||||||
PIFACE_Read_Outports(1, $hash);
|
PIFACE_Read_Outports(1, $hash);
|
||||||
Log3($name, 3, "PIFACE $name get port $port");
|
|
||||||
} elsif ($port eq "in") {
|
} elsif ($port eq "in") {
|
||||||
PIFACE_Read_Inports(1, $hash);
|
PIFACE_Read_Inports(0, $hash);
|
||||||
Log3($name, 3, "PIFACE $name get port $port");
|
|
||||||
} elsif ($port eq "out") {
|
} elsif ($port eq "out") {
|
||||||
PIFACE_Read_Outports(1, $hash);
|
PIFACE_Read_Outports(0, $hash);
|
||||||
Log3($name, 3, "PIFACE $name get port $port");
|
|
||||||
} else {
|
} else {
|
||||||
# get state of in port
|
$adr = $base + $port;
|
||||||
$adr = $base + 8 + $port;
|
$cmd = "$gpioCmd -p read $adr";
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 read $adr";
|
|
||||||
$val = `$cmd`;
|
$val = `$cmd`;
|
||||||
$val =~ s/\n//g;
|
$val =~ s/\n//g;
|
||||||
$val =~ s/\r//g;
|
$val =~ s/\r//g;
|
||||||
readingsSingleUpdate($hash, 'in' . $port, $val, 1);
|
readingsSingleUpdate($hash, 'in'.$port, $val, 1);
|
||||||
Log3($name, 3, "PIFACE $name get port in$port");
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -160,7 +155,7 @@ sub PIFACE_Get($@) {
|
|||||||
sub PIFACE_Attr(@) {
|
sub PIFACE_Attr(@) {
|
||||||
my ($cmd, $name, $attrName, $attrVal) = @_;
|
my ($cmd, $name, $attrName, $attrVal) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
return undef if (!$init_done);
|
|
||||||
if ($attrName eq "pollInterval") {
|
if ($attrName eq "pollInterval") {
|
||||||
if (!defined $attrVal) {
|
if (!defined $attrVal) {
|
||||||
#RemoveInternalTimer($hash);
|
#RemoveInternalTimer($hash);
|
||||||
@ -175,26 +170,25 @@ sub PIFACE_Attr(@) {
|
|||||||
} elsif ($attrName eq "defaultState") {
|
} elsif ($attrName eq "defaultState") {
|
||||||
if (!defined $attrVal){
|
if (!defined $attrVal){
|
||||||
|
|
||||||
} elsif ($attrVal !~ m/^last|off|[01]$/) {
|
} elsif ($attrVal !~ m/^(last|off|[01])$/) {
|
||||||
Log3($name, 3, "PIFACE $name attribute-value [$attrName] = $attrVal wrong");
|
Log3($name, 3, "PIFACE $name attribute-value [$attrName] = $attrVal wrong");
|
||||||
CommandDeleteAttr(undef, "$name defaultState");
|
CommandDeleteAttr(undef, "$name defaultState");
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif ($attrName =~ m/^portMode(.)/) {
|
} elsif ($attrName =~ m/^portMode/) {
|
||||||
my $port = $1;
|
my $port = substr($attrName, 8, 1);
|
||||||
#my $port = substr($attrName, 8, 1);
|
my $adr = $base + $port;
|
||||||
my $adr = $base + 8 + $port;
|
|
||||||
my $portMode = $attrVal;
|
my $portMode = $attrVal;
|
||||||
my $val;
|
my $val;
|
||||||
$portMode = "tri" if (!defined $attrVal);
|
$portMode = "tri" if (!defined $attrVal);
|
||||||
if ($attrVal !~ m/^tri|up$/) {
|
if ($attrVal !~ m/^(tri|up)$/) {
|
||||||
$portMode = "tri" ;
|
$portMode = "tri" ;
|
||||||
Log3($name, 3, "PIFACE $name attribute-value [$attrName] = $attrVal wrong");
|
Log3($name, 3, "PIFACE $name attribute-value [$attrName] = $attrVal wrong");
|
||||||
CommandDeleteAttr(undef, "$name portMode$port");
|
CommandDeleteAttr(undef, "$name $port");
|
||||||
}
|
}
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 mode $adr $portMode";
|
$cmd = "$gpioCmd -p mode $adr $portMode";
|
||||||
$val = `$cmd`;
|
$val = `$cmd`;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 read $adr";
|
$cmd = "$gpioCmd -p read $adr";
|
||||||
$val = `$cmd`;
|
$val = `$cmd`;
|
||||||
$val =~ s/\n//g;
|
$val =~ s/\n//g;
|
||||||
$val =~ s/\r//g;
|
$val =~ s/\r//g;
|
||||||
@ -205,13 +199,12 @@ sub PIFACE_Attr(@) {
|
|||||||
$attrVal = "off" ;
|
$attrVal = "off" ;
|
||||||
CommandDeleteReading(undef, "$name watchdog");
|
CommandDeleteReading(undef, "$name watchdog");
|
||||||
}
|
}
|
||||||
if ($attrVal !~ m/^on|off|silent$/) {
|
if ($attrVal !~ m/^(on|off|silent)$/) {
|
||||||
Log3($name, 3, "PIFACE $name attribute-value [$attrName] = $attrVal wrong");
|
Log3($name, 3, "PIFACE $name attribute-value [$attrName] = $attrVal wrong");
|
||||||
CommandDeleteAttr(undef, "$name watchdog");
|
CommandDeleteAttr(undef, "$name watchdog");
|
||||||
}
|
}
|
||||||
if ($attrVal =~ m/^on|silent$/) {
|
if ($attrVal =~ m/^(on|silent)$/) {
|
||||||
readingsSingleUpdate($hash, 'watchdog', 'start', 1);
|
readingsSingleUpdate($hash, 'watchdog', 'start', 1);
|
||||||
$attr{$name}{$attrName} = $attrVal;
|
|
||||||
PIFACE_Watchdog($hash);
|
PIFACE_Watchdog($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,14 +220,13 @@ sub PIFACE_Attr(@) {
|
|||||||
sub PIFACE_Notify(@) {
|
sub PIFACE_Notify(@) {
|
||||||
my ($hash, $dev) = @_;
|
my ($hash, $dev) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
if ($dev->{NAME} eq "global" && grep (m/^INITIALIZED|REREADCFG$/,@{$dev->{CHANGED}})){
|
if ($dev->{NAME} eq "global" && grep (m/^INITIALIZED$/,@{$dev->{CHANGED}})){
|
||||||
PIFACE_Restore_Inports_Mode($hash);
|
Log3($name, 3, "PIFACE $name initialized");
|
||||||
PIFACE_Restore_Outports_State($hash);
|
PIFACE_Restore_Outports_State($hash);
|
||||||
#PIFACE_Read_Inports(0, $hash);
|
PIFACE_Read_Inports(0, $hash);
|
||||||
#PIFACE_Read_Outports(0, $hash);
|
PIFACE_Read_Outports(0, $hash);
|
||||||
PIFACE_GetUpdate($hash);
|
PIFACE_GetUpdate($hash);
|
||||||
PIFACE_Watchdog($hash);
|
PIFACE_Watchdog($hash);
|
||||||
Log3($name, 3, "PIFACE $name initialized");
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -245,15 +237,15 @@ sub PIFACE_Read_Outports($$){
|
|||||||
my ($cmd, $i, $port, $val);
|
my ($cmd, $i, $port, $val);
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
for($i=0; $i<8; $i++){
|
for($i=0; $i<8; $i++){
|
||||||
$port = $base + $i;
|
$port = $base + $i + 8;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 read $port";
|
$cmd = "$gpioCmd -p read $port";
|
||||||
$val = `$cmd`;
|
$val = `$cmd`;
|
||||||
$val =~ s/\n//g;
|
$val =~ s/\n//g;
|
||||||
$val =~ s/\r//g;
|
$val =~ s/\r//g;
|
||||||
if ($updateMode == 1){
|
if ($updateMode == 1){
|
||||||
readingsBulkUpdate($hash, 'out'.$i, $val);
|
readingsBulkUpdate($hash, 'out'.$i, $val);
|
||||||
} else {
|
} else {
|
||||||
readingsBulkUpdateIfChanged($hash, 'out'.$i, $val);
|
readingsBulkUpdate($hash, 'out'.$i, $val) if(ReadingsVal($name, 'out'.$i, '') ne $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
@ -266,15 +258,15 @@ sub PIFACE_Read_Inports($$){
|
|||||||
my ($cmd, $i, $j, $port, $portMode, $val);
|
my ($cmd, $i, $j, $port, $portMode, $val);
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
for($i=0; $i<8; $i++){
|
for($i=0; $i<8; $i++){
|
||||||
$port = $base + 8 + $i;
|
$port = $base + $i;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 read $port";
|
$cmd = "$gpioCmd -p read $port";
|
||||||
$val = `$cmd`;
|
$val = `$cmd`;
|
||||||
$val =~ s/\n//g;
|
$val =~ s/\n//g;
|
||||||
$val =~ s/\r//g;
|
$val =~ s/\r//g;
|
||||||
if ($updateMode == 1) {
|
if ($updateMode == 1) {
|
||||||
readingsBulkUpdate($hash, 'in'.$i, $val);
|
readingsBulkUpdate($hash, 'in'.$i, $val);
|
||||||
} else {
|
} else {
|
||||||
readingsBulkUpdateIfChanged($hash, 'in'.$i, $val);
|
readingsBulkUpdate($hash, 'in'.$i, $val) if(ReadingsVal($name, 'in'.$i, '') ne $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
@ -303,21 +295,8 @@ sub PIFACE_Restore_Outports_State($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub PIFACE_Restore_Inports_Mode($) {
|
sub
|
||||||
my ($hash) = @_;
|
PIFACE_GetUpdate($) {
|
||||||
my $name = $hash->{NAME};
|
|
||||||
my ($cmd, $port, $portMode, $valIn);
|
|
||||||
for (my $i = 0; $i <= 7; $i++) {
|
|
||||||
$port = $base + 8 + $i;
|
|
||||||
$portMode = AttrVal($name, "portMode" . $i, "tri");
|
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 mode $port $portMode";
|
|
||||||
$valIn = `$cmd`;
|
|
||||||
}
|
|
||||||
PIFACE_Read_Inports(1, $hash);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub PIFACE_GetUpdate($) {
|
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $pollInterval = AttrVal($name, "pollInterval", "off");
|
my $pollInterval = AttrVal($name, "pollInterval", "off");
|
||||||
@ -329,7 +308,8 @@ sub PIFACE_GetUpdate($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub PIFACE_Watchdog($) {
|
sub
|
||||||
|
PIFACE_Watchdog($) {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my ($cmd, $port, $portMode, $valIn, $valOut0, $valOut1);
|
my ($cmd, $port, $portMode, $valIn, $valOut0, $valOut1);
|
||||||
@ -340,29 +320,29 @@ sub PIFACE_Watchdog($) {
|
|||||||
if (!defined $watchdog) {
|
if (!defined $watchdog) {
|
||||||
CommandDeleteReading(undef, "$name watchdog");
|
CommandDeleteReading(undef, "$name watchdog");
|
||||||
|
|
||||||
} elsif ($watchdog =~ m/^on|silent$/) {
|
} elsif ($watchdog =~ m/^(on|silent)$/) {
|
||||||
InternalTimer(gettimeofday() + $watchdogInterval, "PIFACE_Watchdog", $hash, 1);
|
InternalTimer(gettimeofday() + $watchdogInterval, "PIFACE_Watchdog", $hash, 1);
|
||||||
for (my $i=0; $i<7; $i++) {
|
for (my $i=0; $i<7; $i++) {
|
||||||
$port = $base + 8 + $i;
|
$port = $base + $i;
|
||||||
$portMode = AttrVal($name, "portMode" . $i, "tri");
|
$portMode = AttrVal($name, "portMode" . $i, "tri");
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 mode $port $portMode";
|
$cmd = "$gpioCmd -p mode $port $portMode";
|
||||||
$valIn = `$cmd`;
|
$valIn = `$cmd`;
|
||||||
}
|
}
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 mode 215 up";
|
$cmd = "$gpioCmd -p mode 207 up";
|
||||||
$valIn = `$cmd`;
|
$valIn = `$cmd`;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 read 215";
|
$cmd = "$gpioCmd -p read 207";
|
||||||
$valIn = `$cmd`;
|
$valIn = `$cmd`;
|
||||||
$valIn =~ s/\n//g;
|
$valIn =~ s/\n//g;
|
||||||
$valIn =~ s/\r//g;
|
$valIn =~ s/\r//g;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 write 207 0";
|
$cmd = "$gpioCmd -p write 207 0";
|
||||||
$cmd = `$cmd`;
|
$cmd = `$cmd`;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 read 207";
|
$cmd = "$gpioCmd -p read 215";
|
||||||
$valOut0 = `$cmd`;
|
$valOut0 = `$cmd`;
|
||||||
$valOut0 =~ s/\n//g;
|
$valOut0 =~ s/\n//g;
|
||||||
$valOut0 =~ s/\r//g;
|
$valOut0 =~ s/\r//g;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 write 207 1";
|
$cmd = "$gpioCmd -p write 207 1";
|
||||||
$cmd = `$cmd`;
|
$cmd = `$cmd`;
|
||||||
$cmd = "$gpioCmd -x mcp23s17:200:0:0 read 207";
|
$cmd = "$gpioCmd -p read 215";
|
||||||
$valOut1 = `$cmd`;
|
$valOut1 = `$cmd`;
|
||||||
$valOut1 =~ s/\n//g;
|
$valOut1 =~ s/\n//g;
|
||||||
$valOut1 =~ s/\r//g;
|
$valOut1 =~ s/\r//g;
|
||||||
@ -454,9 +434,9 @@ sub PIFACE_Watchdog($) {
|
|||||||
and set the <code>A5 SPI</code> option to "Yes".
|
and set the <code>A5 SPI</code> option to "Yes".
|
||||||
</li>
|
</li>
|
||||||
<li>The function of the PiFace Digital can be tested at OS command line. For example:<br>
|
<li>The function of the PiFace Digital can be tested at OS command line. For example:<br>
|
||||||
<code>gpio -x mcp23s17:200:0:0 readall</code><br>
|
<code>gpio -p readall</code><br>
|
||||||
<code>gpio -x mcp23s17:200:0:0 read 200</code><br>
|
<code>gpio -p read 200</code><br>
|
||||||
<code>gpio -x mcp23s17:200:0:0 write 201 0</code> or <code>gpio -x mcp23s17:200:0:0 write 201 1</code><br>
|
<code>gpio -p write 201 0</code> or <code>gpio -p write 201 1</code><br>
|
||||||
</li>
|
</li>
|
||||||
<li>The watchdog function monitors the input port 7 and the output port 7.<br>
|
<li>The watchdog function monitors the input port 7 and the output port 7.<br>
|
||||||
If the watchdog is enabled, this ports can not be used for other tasks.
|
If the watchdog is enabled, this ports can not be used for other tasks.
|
||||||
@ -474,9 +454,9 @@ sub PIFACE_Watchdog($) {
|
|||||||
and set the <code>A6 SPI</code> option to "Yes".
|
and set the <code>A6 SPI</code> option to "Yes".
|
||||||
</li>
|
</li>
|
||||||
<li>The function of the PiFace Digital can be tested at OS command line. For example:<br>
|
<li>The function of the PiFace Digital can be tested at OS command line. For example:<br>
|
||||||
<code>gpio -x mcp23s17:200:0:0 readall</code><br>
|
<code>gpio -p readall</code><br>
|
||||||
<code>gpio -x mcp23s17:200:0:0 read 200</code><br>
|
<code>gpio -p read 200</code><br>
|
||||||
<code>gpio -x mcp23s17:200:0:0 write 201 0</code> or <code>gpio -x mcp23s17:200:0:0 write 201 1</code><br>
|
<code>gpio -p write 201 0</code> or <code>gpio -p write 201 1</code><br>
|
||||||
</li>
|
</li>
|
||||||
<li>The watchdog function monitors the input port 7 and the output port 7.<br>
|
<li>The watchdog function monitors the input port 7 and the output port 7.<br>
|
||||||
If the watchdog is enabled, this ports can not be used for other tasks.
|
If the watchdog is enabled, this ports can not be used for other tasks.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user