00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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) {
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"];
00046 if (strlen ($s)<2) {
00047 $s='$PTNT,HPR*';
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