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

Completely Rewritten Insteon Message Parser #388

Merged
merged 7 commits into from
Apr 15, 2014
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
76 changes: 65 additions & 11 deletions lib/Insteon/BaseInterface.pm
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,17 @@ sub queue_message
if (defined $message)
{
my $setby = $message->setby;
if ($self->_is_duplicate($message->interface_data) && !($message->isa('Insteon::X10Message')))
{
&main::print_log("[Insteon::BaseInterface] Attempt to queue command already in queue; skipping ...") if $self->debuglevel(1, 'insteon');
if ($self->_is_duplicate($message->interface_data)
&& !($message->isa('Insteon::X10Message'))){
::print_log("[Insteon::BaseInterface] WARN queuing a ".
"duplicate command already in queue.")
if $self->debuglevel(1, 'insteon');
}
else
{
if ($setby and ref($setby) and $setby->can('set_retry_timeout')
and $setby->get_object_name)
{
$message->callback($setby->get_object_name . "->set_retry_timeout()");
}
unshift(@{$$self{command_stack2}}, $message);
if ($setby and ref($setby) and $setby->can('set_retry_timeout')
and $setby->get_object_name) {
$message->callback($setby->get_object_name . "->set_retry_timeout()");
}
unshift(@{$$self{command_stack2}}, $message);
}
# and, begin processing either this entry or the oldest one in the queue
$self->process_queue();
Expand Down Expand Up @@ -494,10 +492,66 @@ sub delete_orphan_links
return $self->_aldb->delete_orphan_links($audit_mode) if $self->_aldb;
}

=item C<plm_get_config>

Used to obtain the configuration flags from the PLM. May be used in conjunction
with C<enable_monitor_mode>.

=cut

sub plm_get_config {
my ($self) = @_;
$self->queue_message(new Insteon::InsteonMessage('plm_get_config', $self));
}

sub plm_config {
my ($self, $p_config) = @_;
$$self{config} = $p_config if defined $p_config;
return $$self{config};
}

=item C<enable_monitor_mode(boolean)>

If boolean is true, enables monitor mode on the PLM, else disables monitor mode.
If you have manually set any other PLM flags (unlikely), you should first call
C<plm_get_config> to prevent these settings from being altered.

=cut

sub enable_monitor_mode {
my ($self, $enable) = @_;
my $config = hex($self->plm_config);
if ($enable){
$config = $config | 64;
}
else {
$config = $config & 191;
}
my $message = new Insteon::InsteonMessage('plm_set_config', $self);
$message->interface_data(sprintf("%02X",$config));
$self->queue_message($message);
}

######################
### EVENT HANDLERS ###
######################

=item C<on_interface_config_received>

Called to process the plm_get_config request sent by the C<plm_get_config()> command.
Prints output to log.

=cut

sub on_interface_config_received
{
my ($self,$data) = @_;
$data = $self->plm_config(substr($data,0,2));
&::print_log("[Insteon_PLM] PLM config flags: $data")
if $self->debuglevel(1, 'insteon');
$self->clear_active_message();
}

=item C<on_interface_info_received>

Called to process the plm_info request sent by the C<poll_all()> command.
Expand Down
4 changes: 2 additions & 2 deletions lib/Insteon/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ sub command_to_hash
$msg{type} = 'broadcast';
$msg{devcat} = substr($p_state,6,4);
$msg{firmware} = substr($p_state,10,2);
$msg{is_master} = substr($p_state,16,2);
$msg{dev_attribs} = substr($p_state,18,2);
$msg{is_master} = substr($p_state,14,2);
$msg{dev_attribs} = substr($p_state,16,2);
}
elsif ($msgflag ==6)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Insteon/MessageDecoder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ my %plmcmdlen = (
'0270' => [3, 4],
'0271' => [4, 5],
'0272' => [2, 3],
'0273' => [5, 6],
'0273' => [2, 6],
);


Expand Down
Loading