..."; $DecodeString= ""; $Scalar = 65536; // fixed-point scaling at 2^16 $ScaledHalf = 32768; // 2^-1 * 2^16 = 2^15 $PctCalc = 400; // 16384^-1 * 100 scaled 2*16 (to calculate percentage) $Hunnerd = 100; $length = strlen($Reply); // ========================================================== // = Secret Decoder Ring is called to translate the machine = // = code reply returned by the camera into something more = // = easily understood. To do this, the function is provided= // = with a string which identifies the command issued, and = // = the hex code reply returned by the camera. = // = While there is a sufficient reply string remaining, = // = we "tokenize" each element of the reply string, then = // = interpret it based upon the type command which evoked = // = the reply. = // = Thus, a $Cmd of "Zoom Inquiry" = // = and a $Reply of "9051ff905000000000ff" = // = produces the comment "-Completion- (0000)", indicating = // = the presence of a completion code, and a Zoom Position = // = value of "0000" (Zoom fully OUT). = // = = // = Script has been updated to provide "Zoom Percentage" to= // = translate the hex zoom position into a percentage which= // = is more easily understood = // ========================================================== while ($length >= $MinimallyAcceptable) { // Grab the next token (if it exists) .// first, find the next delimiter ... $delim = strpos($Reply, $Delimiter); // If there is no next token, we're done ... break out of here if (!$delim) break; // if the next token will be large enuf (i.e. not cascaded delims) // then grab the token and work with it. if ($delim >= $SmallestToken) { $Token = substr($Reply, 0, $delim); $TmpString = ""; $id = 0; switch ($Cmd) { case "DZoomMode": $index = SearchArray($OnO, $Token); $TmpString = (($index > 0) ? $OnO['keystrings'][$index] : $Ack['keystrings'][SearchArray($Ack, $Token)]); if (strlen($TmpString) >= $SmallestToken) { $DecodeString = $DecodeString . $TmpString; } break; case "DZoomCSmode": $index = SearchArray($DCSmode, $Token); $TmpString = (($index > 0) ? $DCSmode['keystrings'][$index] : $Ack['keystrings'][SearchArray($Ack, $Token)]); if (strlen($TmpString) >= $SmallestToken) { $DecodeString = $DecodeString . $TmpString; } break; case "Zoom Inquiry": case "DZoomPos": if (strlen($Token) == $PosInquiry) { if(!strcmp($Cmd, "Zoom Inquiry")) $HexDigits = $Token[5] . $Token[7] . $Token[9] . $Token[11]; else $HexDigits = $Token[9] . $Token[11]; $A = (DecodeHexString($HexDigits) * $PctCalc); $B = (int)($A / $Scalar); $C = (($A - ($Scalar * $B)) * $Hunnerd + $ScaledHalf) / $Scalar; if(strlen($DecodeString)) $DecodeString .= "
"; $DecodeString .= (' (' . $HexDigits . " = " . sprintf("%2d.%2d%%", $B, $C) . ') '); } else $DecodeString .= ($Ack['keystrings'][SearchArray($Ack, $Token)]); break; default: $TmpString = ($Ack['keystrings'][SearchArray($Ack, $Token)]); $DecodeString = $DecodeString . $TmpString; break; } // end of switch statement } // end of if large enuf .// now detach that token and prepare for the next. $length = $length - $delim - $DelimSize; $Reply = substr($Reply, $delim+$DelimSize, $length); } // end while length is great enuf to proceed ... return ((strlen($DecodeString) < $SmallestToken) ? $NoComment : $DecodeString); } ?>