mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
00_MYSENSORS: some rework on DevIo functionality
git-svn-id: https://svn.fhem.de/fhem/trunk@25007 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
3c3fffcc57
commit
5cef3d1b0f
@ -97,6 +97,7 @@ BEGIN { GP_Import(
|
|||||||
DevIo_OpenDev
|
DevIo_OpenDev
|
||||||
DevIo_SimpleWrite
|
DevIo_SimpleWrite
|
||||||
DevIo_SimpleRead
|
DevIo_SimpleRead
|
||||||
|
DevIo_getState
|
||||||
DevIo_CloseDev
|
DevIo_CloseDev
|
||||||
RemoveInternalTimer
|
RemoveInternalTimer
|
||||||
InternalTimer
|
InternalTimer
|
||||||
@ -117,7 +118,7 @@ my %sensorAttr = (
|
|||||||
sub Define {
|
sub Define {
|
||||||
my $hash = shift // return;
|
my $hash = shift // return;
|
||||||
|
|
||||||
InternalTimer(time, 'MYSENSORS::Start', $hash,0);
|
InternalTimer(time, \&Start, $hash,0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +482,7 @@ sub Attr {
|
|||||||
}
|
}
|
||||||
if ($attribute eq 'disable') {
|
if ($attribute eq 'disable') {
|
||||||
return Stop($hash) if $command eq 'set' && $value;
|
return Stop($hash) if $command eq 'set' && $value;
|
||||||
InternalTimer(time, "MYSENSORS::Start", $hash,0);
|
InternalTimer(time, \&Start, $hash,0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -497,7 +498,12 @@ sub Start {
|
|||||||
getFirmwareTypes($hash, 'start');
|
getFirmwareTypes($hash, 'start');
|
||||||
return if IsDisabled( $hash->{NAME} );
|
return if IsDisabled( $hash->{NAME} );
|
||||||
DevIo_CloseDev($hash);
|
DevIo_CloseDev($hash);
|
||||||
return DevIo_OpenDev($hash, 0, "MYSENSORS::Init");
|
if($dev eq 'none') {
|
||||||
|
Log3($hash, 1, "$hash->{NAME} device is none, commands will be echoed only");
|
||||||
|
$::attr{$hash->{NAME}}{disable} = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return DevIo_OpenDev($hash, 0, \&Init);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Stop {
|
sub Stop {
|
||||||
@ -510,8 +516,9 @@ sub Stop {
|
|||||||
|
|
||||||
sub Ready {
|
sub Ready {
|
||||||
my $hash = shift // return;
|
my $hash = shift // return;
|
||||||
return DevIo_OpenDev($hash, 1, "MYSENSORS::Init") if($hash->{STATE} eq 'disconnected');
|
return if AttrVal($hash->{NAME}, 'disable', 0);
|
||||||
if(defined($hash->{USBDev})) {
|
return DevIo_OpenDev($hash, 1, \&Init) if DevIo_getState($hash) eq 'disconnected';
|
||||||
|
if ( defined $hash->{USBDev} ) {
|
||||||
my $po = $hash->{USBDev};
|
my $po = $hash->{USBDev};
|
||||||
my ( $BlockingFlags, $InBytes, $OutBytes, $ErrorFlags ) = $po->status;
|
my ( $BlockingFlags, $InBytes, $OutBytes, $ErrorFlags ) = $po->status;
|
||||||
return ( $InBytes > 0 );
|
return ( $InBytes > 0 );
|
||||||
@ -555,8 +562,8 @@ sub GetConnectStatus {
|
|||||||
Log3( $name, 4, "MySensors: GetConnectStatus called ..." );
|
Log3( $name, 4, "MySensors: GetConnectStatus called ..." );
|
||||||
|
|
||||||
# neuen Timer starten in einem konfigurierten Interval.
|
# neuen Timer starten in einem konfigurierten Interval.
|
||||||
InternalTimer(gettimeofday()+300, "MYSENSORS::GetConnectStatus", $hash);# Restart check in 5 mins again
|
InternalTimer(gettimeofday()+300, \&GetConnectStatus, $hash);# Restart check in 5 mins again
|
||||||
InternalTimer(gettimeofday()+5, "MYSENSORS::Start", $hash); #Start timer for reset if after 5 seconds RESPONSE is not received
|
InternalTimer(gettimeofday()+5, \&Start, $hash); #Start timer for reset if after 5 seconds RESPONSE is not received
|
||||||
#query heartbeat from gateway
|
#query heartbeat from gateway
|
||||||
return sendMessage($hash,
|
return sendMessage($hash,
|
||||||
radioId => 0,
|
radioId => 0,
|
||||||
@ -606,8 +613,8 @@ sub Read {
|
|||||||
if ($msg->{ack}) {
|
if ($msg->{ack}) {
|
||||||
onAcknowledge($hash,$msg);
|
onAcknowledge($hash,$msg);
|
||||||
}
|
}
|
||||||
RemoveInternalTimer($hash,"MYSENSORS::GetConnectStatus");
|
RemoveInternalTimer($hash,\&GetConnectStatus);
|
||||||
InternalTimer(gettimeofday()+300, "MYSENSORS::GetConnectStatus", $hash);# Restart check in 5 mins again
|
InternalTimer(gettimeofday()+300, \&GetConnectStatus, $hash);# Restart check in 5 mins again
|
||||||
|
|
||||||
my $type = $msg->{cmd};
|
my $type = $msg->{cmd};
|
||||||
my $dispatch = {
|
my $dispatch = {
|
||||||
@ -701,11 +708,11 @@ sub onInternalMsg {
|
|||||||
my $client = shift;
|
my $client = shift;
|
||||||
MYSENSORS::DEVICE::onGatewayStarted($client);
|
MYSENSORS::DEVICE::onGatewayStarted($client);
|
||||||
});
|
});
|
||||||
return InternalTimer(gettimeofday()+300, "MYSENSORS::GetConnectStatus", $hash);
|
return InternalTimer(gettimeofday()+300, \&GetConnectStatus, $hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type == I_HEARTBEAT_RESPONSE) {
|
if ($type == I_HEARTBEAT_RESPONSE) {
|
||||||
RemoveInternalTimer($hash,"MYSENSORS::Start"); ## Reset reconnect because timeout was not reached
|
RemoveInternalTimer($hash,\&Start); ## Reset reconnect because timeout was not reached
|
||||||
readingsSingleUpdate($hash, 'heartbeat', 'alive', 0);
|
readingsSingleUpdate($hash, 'heartbeat', 'alive', 0);
|
||||||
if ($client = matchClient($hash,$msg)){
|
if ($client = matchClient($hash,$msg)){
|
||||||
return if IsDisabled( $client->{NAME} );
|
return if IsDisabled( $client->{NAME} );
|
||||||
@ -898,14 +905,14 @@ sub sendMessage {
|
|||||||
sub _scheduleTimer {
|
sub _scheduleTimer {
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
$hash->{outstandingAck} = 0;
|
$hash->{outstandingAck} = 0;
|
||||||
RemoveInternalTimer($hash,"MYSENSORS::Timer");
|
RemoveInternalTimer($hash,\&Timer);
|
||||||
my $next;
|
my $next;
|
||||||
for my $radioid (keys %{$hash->{messagesForRadioId}}) {
|
for my $radioid (keys %{$hash->{messagesForRadioId}}) {
|
||||||
my $msgsForId = $hash->{messagesForRadioId}->{$radioid};
|
my $msgsForId = $hash->{messagesForRadioId}->{$radioid};
|
||||||
$hash->{outstandingAck} += @{$msgsForId->{messages}};
|
$hash->{outstandingAck} += @{$msgsForId->{messages}};
|
||||||
$next = $msgsForId->{nexttry} if (!defined $next || $next >= $msgsForId->{nexttry});
|
$next = $msgsForId->{nexttry} if (!defined $next || $next >= $msgsForId->{nexttry});
|
||||||
};
|
};
|
||||||
InternalTimer($next, "MYSENSORS::Timer", $hash, 0) if (defined $next);
|
InternalTimer($next, \&Timer, $hash, 0) if defined $next;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user