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