Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleemanj/c51dabfcff7ba73d454f27deb78c54f9 to your computer and use it in GitHub Desktop.
Save sleemanj/c51dabfcff7ba73d454f27deb78c54f9 to your computer and use it in GitHub Desktop.
Quick kludgy script to take a Pronto Hex format of code from the remotecentral.com database and blindly assuming it is NEC format with a single pulse lead-in and 32 bits, convert to NEC device and Function.
<?php
$Pronto = "0000 006d 0022 0002 0155 00ab 0015 0015 0015 0015 0015 0015 0015 0040 0015 0040 0015 0040 0015 0015 0015 0040 0015 0040 0015 0040 0015 0040 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 0040 0015 0040 0015 0040 0015 0040 0015 0040 0015 0040 0015 0015 0015 0040 0015 0015 0015 0015 0015 05ea 0155 0055 0015 0e3d";
$Pronto = preg_split('/ /', $Pronto);
// Remove header
array_shift($Pronto);
array_shift($Pronto);
array_shift($Pronto);
array_shift($Pronto);
// Remove leadin
array_shift($Pronto);
array_shift($Pronto);
// Decode 32 bits
$Bits = array();
while(count($Pronto) && count($Bits) < 32)
{
$A = preg_match('/001/', array_shift($Pronto))?1:0;
$B = preg_match('/001/', array_shift($Pronto))?1:0;
$Bits[] = $A && $B ? 0 : 1;
}
$Bytes = preg_split('/ /', chunk_split(implode($Bits,''),8," "));
if(
(intval($Bytes[0],2) + intval($Bytes[1],2)) !== 255
)
{
echo "Device: {$Bytes[0]} but check complement {$Bytes[1]} does not match \n";
echo " : could be " . strtr($Bytes[1],'01','10') . " maybe.\n";
}
else
{
echo "Device: {$Bytes[0]}\n";
}
if(
(intval($Bytes[2],2) + intval($Bytes[3],2)) !== 255
)
{
echo "Function: {$Bytes[2]} but check complement {$Bytes[3]} does not match \n";
echo " : could be " . strtr($Bytes[3],'01','10') . " maybe.\n";
}
else
{
echo "Function: {$Bytes[2]}\n";
}
?>
@sleemanj
Copy link
Author

sleemanj commented Jan 3, 2022

I made this to decode the Kenwood IR codes which have lengths of about 001something for the first half and 004x for the second half of each bit, you can see where we determine each bit half in line 20 and 21, it's very slack, either it's 001something or it's not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment