Skip to content

Commit

Permalink
Insteon: Add Time to Allow for ACK to Finish Transmitting
Browse files Browse the repository at this point in the history
MH already pauses to all hops_left time to expire.

This adds a pause for messages that require ACKs to be sent to devices.  MH doesn't send the ACKs, they are automatically sent by the PLM.  However, anecdotal evidence suggests that the PLM doesn't abide by collision avoidance, ie it seems to permit a message to be sent immediately after an ACK without concern for allowing the ACK hops to complete.
  • Loading branch information
krkeegan committed May 9, 2013
1 parent fb0d7d6 commit 40d15cd
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions lib/Insteon/BaseInterface.pm
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,23 @@ sub on_standard_insteon_received
return if $self->_is_duplicate_received($message_data, %msg);
if (%msg)
{
if ($msg{hopsleft} > 0) {
&::print_log("[Insteon::BaseInterface] DEBUG2: Message received with $msg{hopsleft} hops left, delaying next "
."transmit to avoid collisions with remaining hops.") if $main::Debug{insteon} >= 2;
$self->_set_timeout('xmit', $msg{hopsleft} * 100) #Standard msgs should only take 50 millis;
}
else {
#This prevents the majority of corrupt messages on aldb scans
#For some reason duplicate messages arrive with the same hop count
#My theory is that they are created by bridging the powerline and rf
#A mere 50 millisecond pause seems to fix everything.
$self->_set_timeout('xmit', 50);
my $wait_time;
my $wait_message = "[Insteon::BaseInterface] DEBUG3: Message received "
."with $msg{hopsleft} hops left, ";
if (!$msg{is_ack} && !$msg{is_nack} && $msg{type} ne 'alllink'
&& $msg{type} ne 'broadcast') {
#Wait for ACK to be delivered
$wait_time = $msg{maxhops};
$wait_message .= "plus ACK will take $msg{maxhops} to deliver, ";
}
$wait_time += $msg{hopsleft};
#Standard msgs should only take 50 millis, but in practice additional
#time has been required. Extra 50 millis helps prevent dupes
$wait_time = ($wait_time * 100) + 50;
$wait_message .= "delaying next transmit by $wait_time milliseconds to avoid collisions.";
::print_log($wait_message) if ($main::Debug{insteon} >= 3 && $wait_time > 50);
$self->_set_timeout('xmit', $wait_time);

# get the matching object
my $object = &Insteon::get_object($msg{source}, $msg{group});
if (defined $object)
Expand Down Expand Up @@ -481,18 +486,23 @@ sub on_extended_insteon_received
return if $self->_is_duplicate_received($message_data, %msg);
if (%msg)
{
if ($msg{hopsleft} > 0) {
&::print_log("[Insteon::BaseInterface] DEBUG2: Message received with $msg{hopsleft} hops left, delaying next "
."transmit to avoid collisions with remaining hops.") if $main::Debug{insteon} >= 2;
$self->_set_timeout('xmit', $msg{hopsleft} * 200) #Extended msgs take longer to deliver;
my $wait_time;
my $wait_message = "[Insteon::BaseInterface] DEBUG3: Message received "
."with $msg{hopsleft} hops left, ";
if (!$msg{is_ack} && !$msg{is_nack} && $msg{type} ne 'alllink'
&& $msg{type} ne 'broadcast') {
#Wait for ACK to be delivered
$wait_time = $msg{maxhops};
$wait_message .= "plus ACK will take $msg{maxhops} to deliver, ";
}
else {
#This prevents the majority of corrupt messages on aldb scans
#For some reason duplicate messages arrive with the same hop count
#My theory is that they are created by bridging the powerline and rf
#A mere 50 millisecond pause seems to fix everything.
$self->_set_timeout('xmit', 50);
}
$wait_time += $msg{hopsleft};
#Standard msgs should only take 108 millis, but in practice additional
#time has been required. Extra 50 millis helps prevent dupes
$wait_time = ($wait_time * 200) + 50;
$wait_message .= "delaying next transmit by $wait_time milliseconds to avoid collisions.";
::print_log($wait_message) if ($main::Debug{insteon} >= 3 && $wait_time > 50);
$self->_set_timeout('xmit', $wait_time);

# get the matching object
my $object = &Insteon::get_object($msg{source}, $msg{group});
if (defined $object)
Expand Down

0 comments on commit 40d15cd

Please sign in to comment.