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
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) {
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"];
00049 if (strlen ($s)<2) {
00050 $s='$PTNT,HPR*';
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