00001 <?php 00002 /*!******************************************************************************* 00003 *! FILE NAME : compass.php 00004 *! DESCRIPTION: Reads Heading, Roll, Pitch from the Honeywell HMR3000 compass 00005 *! module attached to the serial port of the Elphel model 353 camera 00006 *! Requires 10349/10369 boards with extra connection to +5V 00007 *! (on 10369 can use 4-pin RJ45 sync out as power). 00008 *! Needs system to be configured with the debug port disabled. 00009 *! Copyright (C) 2008 Elphel, Inc 00010 *! -----------------------------------------------------------------------------** 00011 *! 00012 *! This program is free software: you can redistribute it and/or modify 00013 *! it under the terms of the GNU General Public License as published by 00014 *! the Free Software Foundation, either version 3 of the License, or 00015 *! (at your option) any later version. 00016 *! 00017 *! This program is distributed in the hope that it will be useful, 00018 *! but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 *! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 *! GNU General Public License for more details. 00021 *! 00022 *! You should have received a copy of the GNU General Public License 00023 *! along with this program. If not, see <http://www.gnu.org/licenses/>. 00024 *! -----------------------------------------------------------------------------** 00025 *! 00026 *! $Log: compass_os5000.php,v $ 00027 *! Revision 1.1 2008/04/07 09:17:01 elphel 00028 *! manual interface to compass modules 00029 *! 00030 *! Revision 1.1 2008/03/23 20:13:47 elphel 00031 *! added support for the Honeywell HMR3000 compass module attached to the serial port. 00032 *! 00033 *! 00034 */ 00035 // command code and value come with no spaces 00036 // example: "http://192.168.1.75/var/compass.php?*1", * - command, 1 - value 00037 $ser_port="/dev/ttyUSB0"; 00038 00039 $xml = new SimpleXMLElement("<?xml version='1.0'?><hpr/>"); 00040 00041 $s=str_split($_SERVER["QUERY_STRING"]); 00042 00043 for ($i=1; $i<sizeof($s); $i++) { 00044 $s1.= $s[$i]; 00045 } 00046 00047 exec ("stty -F $ser_port onlcr -echo speed 19200"); 00048 00049 $sero=fopen($ser_port,"w"); 00050 $seri=fopen($ser_port,"r"); 00051 00052 $n=fwrite($sero,chr(27).$s[0]."\n");// chr(27) - ESC character, $s[0] - command,"\n" - <enter> 00053 $response=fgets($seri); // here the compass writes "enter value or esc" 00054 $n=fwrite($sero,"$s1\n"); // command value is written 00055 00056 for ($i=0; $i<3; $i++) { 00057 fgets($seri); 00058 $response.="; ".fgets($seri); 00059 } 00060 00061 fclose ($sero); 00062 fclose ($seri); 00063 00064 $xml->addChild ('raw',$response); 00065 00066 $rslt=$xml->asXML(); 00067 header("Content-Type: text/xml"); 00068 header("Content-Length: ".strlen($rslt)."\n"); 00069 header("Pragma: no-cache\n"); 00070 printf($rslt); 00071 ?> 00072