Device-ELM327

 view release on metacpan or  search on metacpan

lib/Device/ELM327.pm  view on Meta::CPAN



#*****************************************************************

=head2 DecodeTroubleCode

Expand a trouble code (e.g. 4216) to the full ISO code (C0216)

This function is called by 'Read'.

 $decoded_code = $obd->DecodeTroubleCode($code);
=cut

sub DecodeTroubleCode
{
	my ($self, $code) = @_;

  my @codes = ("P0","P1","P2","P3","C0","C1","C2","C3","B0","B1","B2","B3","U0","U1","U2","U3");

  my $code_prefix_mask = 61440;
  my $code_mask = 4095;
  my $number_of_codes_mask = 127;

	if ($code eq "no result" || $code == 0)
	{
		return "No Trouble Code";
	}

  my $code_prefix = ($code & $code_prefix_mask) >> 12;
  $code &= $code_mask;
  $code = sprintf("%03X", $code);
  my $decoded_code = "$codes[$code_prefix]$code";

  if ($self->{'debug_level'} > 1)
  {
    print "Code prefix: $code_prefix, Code: $code, Decoded: $decoded_code\n";
  }
	return $decoded_code;
}


#*****************************************************************

=head2 CalibrateVoltage

Changes the calibration value used by the ELM module. The value
$Voltage is a string containing a fixed point value of the form:
xx.xx, e.g "11.99", "12.01" etc.

lib/Device/ELM327.pm  view on Meta::CPAN


    #Now turn the hex byte strings into numbers...
    foreach (@{$self->{'results'}->{$address}->{'result'}})
    {
      $_ = hex($_);
    }
  }

  if ($self->{'debug_level'} > 1)
  {
    print "\nFully decoded results:\n";  
    print Dumper($self->{'results'});
  }

  return $status;
}


#*****************************************************************

=head2 GetResultsCommand06_CAN



( run in 0.417 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )