apps/compass/honeywell_compass.php

Go to the documentation of this file.
00001 <?php
00002 /*!*******************************************************************************
00003 *! FILE NAME  : honeywell_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: honeywell_compass.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 
00036 
00038   $hpr_cmd=false;
00039   $error=false;
00040   $xml = new SimpleXMLElement("<?xml version='1.0'?><hpr/>");
00041   if (count(file("/proc/tty/driver/serial"))<3) { //no dummy port found - "4: uart:CRISv32 port:00000001 irq:0 tx:0 rx:0 RTS|DTR"
00042     $xml->addChild ('error',"Serial port 0 is used for debug console, you have to disable it in the system config file to use attached serial devices, like Honeywell HMR3000 Compass module.");
00043     $error=true;
00044   } else {
00045     $s=$_SERVER["QUERY_STRING"]; // starts with "$" or "N" (instead of the "#"), ends with "*"
00046     if (strlen ($s)<2) {
00047        $s='$PTNT,HPR*'; //request a single HPR data set
00048        $hpr_cmd=true;
00049     } else {
00050        if ($s[0]=="N") $s[0]="#"; 
00051        if ((($s[0]!='#') && ($s[0]!='$')) || ($s[strlen($s)-1]!='*')) {
00052          $xml->addChild ('error',"Command requested is '".$s."'. Valid commands start with '$' or '#' (use 'N' instead for CGI url line) and end with '*' (checksum will be added automatically). See HMR3000 manual for the list of commands.");
00053          $error=true;
00054        }
00055     }
00056   }
00057   if (!$error) {
00058     $s1=substr($s,1,strlen($s)-2);
00059     $cs=0;
00060     $s1=str_split($s1);
00061     foreach ($s1 as $c) {
00062       $cs^=ord($c);
00063     }
00064     $s=sprintf("%s%X%X",$s,(($cs>>4) & 0xf),($cs & 0xf));
00065     exec ("stty -F /dev/ttyS0 onlcr -echo speed 19200");
00066     $sero=fopen("/dev/ttyS0","w");
00067     $seri=fopen("/dev/ttyS0","r");
00068     $n=fwrite($sero,$s."\n");
00069     $response=fgets($seri);
00070     fclose ($sero);
00071     fclose ($seri);
00072     if ($hpr_cmd) {
00073       $hpr=explode(",",$response);
00074       $xml->addChild ('heading',$hpr[1]);
00075       $xml->addChild ('pitch',$hpr[3]);
00076       $xml->addChild ('roll',$hpr[5]);
00077     }
00078     $xml->addChild ('raw',$response);
00079   }
00080   $rslt=$xml->asXML();
00081   header("Content-Type: text/xml");
00082   header("Content-Length: ".strlen($rslt)."\n");
00083   header("Pragma: no-cache\n");
00084   printf($rslt);
00085 ?>
00086  

Generated on Thu Aug 7 16:18:59 2008 for elphel by  doxygen 1.5.1