mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +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_SimpleWrite
|
||||
DevIo_SimpleRead
|
||||
DevIo_getState
|
||||
DevIo_CloseDev
|
||||
RemoveInternalTimer
|
||||
InternalTimer
|
||||
@ -117,7 +118,7 @@ my %sensorAttr = (
|
||||
sub Define {
|
||||
my $hash = shift // return;
|
||||
|
||||
InternalTimer(time, 'MYSENSORS::Start', $hash,0);
|
||||
InternalTimer(time, \&Start, $hash,0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -481,7 +482,7 @@ sub Attr {
|
||||
}
|
||||
if ($attribute eq 'disable') {
|
||||
return Stop($hash) if $command eq 'set' && $value;
|
||||
InternalTimer(time, "MYSENSORS::Start", $hash,0);
|
||||
InternalTimer(time, \&Start, $hash,0);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
@ -497,7 +498,12 @@ sub Start {
|
||||
getFirmwareTypes($hash, 'start');
|
||||
return if IsDisabled( $hash->{NAME} );
|
||||
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 {
|
||||
@ -510,8 +516,9 @@ sub Stop {
|
||||
|
||||
sub Ready {
|
||||
my $hash = shift // return;
|
||||
return DevIo_OpenDev($hash, 1, "MYSENSORS::Init") if($hash->{STATE} eq 'disconnected');
|
||||
if(defined($hash->{USBDev})) {
|
||||
return if AttrVal($hash->{NAME}, 'disable', 0);
|
||||
return DevIo_OpenDev($hash, 1, \&Init) if DevIo_getState($hash) eq 'disconnected';
|
||||
if ( defined $hash->{USBDev} ) {
|
||||
my $po = $hash->{USBDev};
|
||||
my ( $BlockingFlags, $InBytes, $OutBytes, $ErrorFlags ) = $po->status;
|
||||
return ( $InBytes > 0 );
|
||||
@ -555,8 +562,8 @@ sub GetConnectStatus {
|
||||
Log3( $name, 4, "MySensors: GetConnectStatus called ..." );
|
||||
|
||||
# neuen Timer starten in einem konfigurierten Interval.
|
||||
InternalTimer(gettimeofday()+300, "MYSENSORS::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()+300, \&GetConnectStatus, $hash);# Restart check in 5 mins again
|
||||
InternalTimer(gettimeofday()+5, \&Start, $hash); #Start timer for reset if after 5 seconds RESPONSE is not received
|
||||
#query heartbeat from gateway
|
||||
return sendMessage($hash,
|
||||
radioId => 0,
|
||||
@ -606,8 +613,8 @@ sub Read {
|
||||
if ($msg->{ack}) {
|
||||
onAcknowledge($hash,$msg);
|
||||
}
|
||||
RemoveInternalTimer($hash,"MYSENSORS::GetConnectStatus");
|
||||
InternalTimer(gettimeofday()+300, "MYSENSORS::GetConnectStatus", $hash);# Restart check in 5 mins again
|
||||
RemoveInternalTimer($hash,\&GetConnectStatus);
|
||||
InternalTimer(gettimeofday()+300, \&GetConnectStatus, $hash);# Restart check in 5 mins again
|
||||
|
||||
my $type = $msg->{cmd};
|
||||
my $dispatch = {
|
||||
@ -701,11 +708,11 @@ sub onInternalMsg {
|
||||
my $client = shift;
|
||||
MYSENSORS::DEVICE::onGatewayStarted($client);
|
||||
});
|
||||
return InternalTimer(gettimeofday()+300, "MYSENSORS::GetConnectStatus", $hash);
|
||||
return InternalTimer(gettimeofday()+300, \&GetConnectStatus, $hash);
|
||||
}
|
||||
|
||||
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);
|
||||
if ($client = matchClient($hash,$msg)){
|
||||
return if IsDisabled( $client->{NAME} );
|
||||
@ -898,14 +905,14 @@ sub sendMessage {
|
||||
sub _scheduleTimer {
|
||||
my $hash = shift;
|
||||
$hash->{outstandingAck} = 0;
|
||||
RemoveInternalTimer($hash,"MYSENSORS::Timer");
|
||||
RemoveInternalTimer($hash,\&Timer);
|
||||
my $next;
|
||||
for my $radioid (keys %{$hash->{messagesForRadioId}}) {
|
||||
my $msgsForId = $hash->{messagesForRadioId}->{$radioid};
|
||||
$hash->{outstandingAck} += @{$msgsForId->{messages}};
|
||||
$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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user