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.1.1  2008/11/27 20:04:01  elphel
00028 *!
00029 *!
00030 *!  Revision 1.1  2008/04/07 09:17:01  elphel
00031 *!  manual interface to compass modules
00032 *!
00033 *!  Revision 1.1  2008/03/23 20:13:47  elphel
00034 *!  added support for the Honeywell HMR3000 compass module attached to the serial port.
00035 *!
00036 *!
00037 */
00038 
00039 
00041   $hpr_cmd=false;
00042   $error=false;
00043   $xml = new SimpleXMLElement("<?xml version='1.0'?><hpr/>");
00044   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"
00045     $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.");
00046     $error=true;
00047   } else {
00048     $s=$_SERVER["QUERY_STRING"]; // starts with "$" or "N" (instead of the "#"), ends with "*"
00049     if (strlen ($s)<2) {
00050        $s='$PTNT,HPR*'; //request a single HPR data set
00051        $hpr_cmd=true;
00052     } else {
00053        if ($s[0]=="N") $s[0]="#"; 
00054        if ((($s[0]!='#') && ($s[0]!='$')) || ($s[strlen($s)-1]!='*')) {
00055          $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.");
00056          $error=true;
00057        }
00058     }
00059   }
00060   if (!$error) {
00061     $s1=substr($s,1,strlen($s)-2);
00062     $cs=0;
00063     $s1=str_split($s1);
00064     foreach ($s1 as $c) {
00065       $cs^=ord($c);
00066     }
00067     $s=sprintf("%s%X%X",$s,(($cs>>4) & 0xf),($cs & 0xf));
00068     exec ("stty -F /dev/ttyS0 onlcr -echo speed 19200");
00069     $sero=fopen("/dev/ttyS0","w");
00070     $seri=fopen("/dev/ttyS0","r");
00071     $n=fwrite($sero,$s."\n");
00072     $response=fgets($seri);
00073     fclose ($sero);
00074     fclose ($seri);
00075     if ($hpr_cmd) {
00076       $hpr=explode(",",$response);
00077       $xml->addChild ('heading',$hpr[1]);
00078       $xml->addChild ('pitch',$hpr[3]);
00079       $xml->addChild ('roll',$hpr[5]);
00080     }
00081     $xml->addChild ('raw',$response);
00082   }
00083   $rslt=$xml->asXML();
00084   header("Content-Type: text/xml");
00085   header("Content-Length: ".strlen($rslt)."\n");
00086   header("Pragma: no-cache\n");
00087   printf($rslt);
00088 ?>
00089  

Generated on Fri Nov 28 00:06:21 2008 for elphel by  doxygen 1.5.1