00001 #!/usr/local/sbin/php -q
00002 <?php
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 $wait_time=20;
00038 $compass=null;
00039 $GPS=null;
00040 find_gps_compass();
00041
00042
00043 if ((!$compass || !$GPS) && ((exec('date +%s')+0) <30)) {
00044 echo "waiting $wait_time sec for USB devices to start up\n";
00045 sleep($wait_time);
00046 echo "Retrying detection\n";
00047 find_gps_compass();
00048 }
00049
00050
00051 $noGPS= ($compass || $GPS)?"" : "noGPS";
00052 $nocompass=($compass)?"" : "nocompass";
00053 $cmd="/usr/html/exif.php init $noGPS $nocompass";
00054 echo "Initializing Exif template: $cmd\n";
00055 exec($cmd);
00056
00057 exec("killall -q garminusb2exif");
00058 exec("killall -q compass");
00059 if ($GPS) {
00060 echo "Starting ".$GPS["name"]. " as ". $GPS["file"]. "\n";
00061 $cmd ="/usr/local/bin/garminusb2exif ". $GPS["file"]." &";
00062 echo "exec: $cmd \n";
00063 popen($cmd,"r");
00064 }
00065 if ($compass) {
00066 echo "Starting ".$compass["name"]. " as ". $compass["file"]. "\n";
00067 exec ("stty -F ".$compass["file"]." -echo speed 19200");
00068 $cmd="/usr/local/bin/compass ". $compass["file"]." &";
00069 echo "exec: $cmd \n";
00070 popen($cmd,"r");
00071 }
00072 exit (($compass?2:0) | ($GPS?1:0));
00073
00074 function find_gps_compass() {
00075 global $GPS, $compass;
00076 $devices=array(
00077 "compass"=>array(array("name"=>"Ocean Server OS-5000","driver"=>"cp2101")),
00078 "GPS" =>array(array("name"=>"Garmin GPS 18 USB","driver"=>"garmin_gps")));
00079 exec("ls /sys/bus/usb-serial/devices",$usb_ser_devs);
00080 $devs = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><USB_serial_devices/>");
00081
00082 foreach ($usb_ser_devs as $dev) {
00083 $arr=split("/",exec("ls /sys/bus/usb-serial/devices/".$dev."/driver -l"));
00084 $driver=$arr[count($arr)-1];
00085 foreach ($devices["compass"] as $d) {
00086 if ($d["driver"]==$driver) {
00087 $dd=$devs->addChild ('compass');
00088 $dd->addChild ('name',$d["name"]);
00089 $dd->addChild ('driver',$d["driver"]);
00090 $dd->addChild ('file',"/dev/".$dev);
00091 }
00092 }
00093 foreach ($devices["GPS"] as $d) {
00094 if ($d["driver"]==$driver) {
00095 $dd=$devs->addChild ('GPS');
00096 $dd->addChild ('name',$d["name"]);
00097 $dd->addChild ('driver',$d["driver"]);
00098 $dd->addChild ('file',"/dev/".$dev);
00099 }
00100 }
00101 }
00102
00103 $state_file=fopen("/var/html/gps_compass.xml","w");
00104 fwrite($state_file,$devs->asXML());
00105 fclose($state_file);
00106
00107
00108 foreach ($devs->compass as $a) {
00109 $compass=array("file"=>(string) $a->file, "name"=> (string) $a->name);
00110 break;
00111 }
00112 foreach ($devs->GPS as $a) {
00113 $GPS=array("file"=>(string) $a->file, "name"=> (string) $a->name);
00114 break;
00115 }
00116 }
00117
00118
00119
00120
00121 ?>