Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insteon: Self Adjusting Hop Count #62

Merged
merged 5 commits into from
Feb 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Insteon/BaseInsteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ sub group
sub default_hop_count
{
my ($self, $hop_count) = @_;
$$self{default_hop_count} = $hop_count if defined($hop_count);
unshift(@{$$self{hop_array}}, $$self{default_hop_count}) if (!defined(@{$$self{hop_array}}));
unshift(@{$$self{hop_array}}, $hop_count) if defined($hop_count);
pop(@{$$self{hop_array}}) if (scalar(@{$$self{hop_array}}) >20);
my $high = 0;
foreach (@{$$self{hop_array}}){
$high = $_ if ($high < $_);;
}
$$self{default_hop_count} = $high;
return $$self{default_hop_count};
}

Expand Down Expand Up @@ -471,6 +478,7 @@ sub _process_message
# of the responder based upon the link controller's request is handled
# by Insteon_Link.
$$self{m_is_locally_set} = 1 if $msg{source} eq lc $self->device_id;
$self->default_hop_count($msg{maxhops}-$msg{hopsleft}) if (!$self->isa('Insteon::InterfaceController'));
if ($msg{is_ack}) {
my $pending_cmd = ($$self{_prior_msg}) ? $$self{_prior_msg}->command : $msg{command};
if ($$self{awaiting_ack})
Expand Down
12 changes: 6 additions & 6 deletions lib/Insteon/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ sub send
# revise default hop count to reflect retries
if (ref $self->setby && $self->setby->isa('Insteon::BaseObject'))
{
if (($self->send_attempts > $self->setby->default_hop_count)
and ($self->send_attempts <= 3))
if ($self->setby->default_hop_count < 3)
{
&main::print_log("[Insteon::Message] Now setting default hop count for "
. $self->setby->get_object_name . " to "
. $self->send_attempts);
$self->setby->default_hop_count($self->send_attempts);
$self->setby->default_hop_count($self->setby->default_hop_count + 1);
&main::print_log("[Insteon::Message] Now adding hop count of "
. $self->setby->default_hop_count . " to hop history of "
. $self->setby->get_object_name);
}
}
}
Expand Down Expand Up @@ -183,6 +182,7 @@ sub command_to_hash
my ($p_state) = @_;
my %msg = ();
my $hopflag = hex(uc substr($p_state,13,1));
$msg{maxhops} = $hopflag&0b0011;
$msg{hopsleft} = $hopflag >> 2;
my $msgflag = hex(uc substr($p_state,12,1));
$msg{is_extended} = (0x01 & $msgflag) ? 1 : 0;
Expand Down