Commit ed26a679 authored by Andrey Filippov's avatar Andrey Filippov

working on event logger

parent 14632e65
...@@ -44,228 +44,256 @@ ...@@ -44,228 +44,256 @@
*! *!
*/ */
#require 'i2c.inc'; #require 'i2c.inc';
set_include_path(get_include_path() . PATH_SEPARATOR . '/www/pages/include'); set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
require 'i2c_include.php'; require 'i2c_include.php';
# $xclk_freq=80000000; // 80 MHz in NC353 // $xclk_freq=80000000; // 80 MHz in NC353
$xclk_freq=100000000; // 100 MHz in NC393 $xclk_freq = 100000000; // 100 MHz in NC393
$messageOffset=0xb0; // offset to start of "odometer" message in the device driver file $messageOffset = 0xb0; // offset to start of "odometer" message in the device driver file
$config_name="/etc/elphel393/imu_logger.xml"; $config_name = "/etc/elphel393/imu_logger.xml";
$gps_compass_xml = "/www/pages/gps_compass.xml"; $gps_compass_xml = "/www/pages/gps_compass.xml";
$i2cbus = 4; $i2cbus = 4;
if (isset($_SERVER["SERVER_PROTOCOL"])) { if (isset ( $_SERVER ["SERVER_PROTOCOL"] )) {
// echo "web server\n"; // echo "web server\n";
if (isset($_GET['msg'])) { if (isset ( $_GET ['msg'] )) {
setMessage(urldecode($_GET['msg'])); setMessage ( urldecode ( $_GET ['msg'] ) );
} else if (isset($_GET['lmsg'])) { } else if (isset ( $_GET ['lmsg'] )) {
setMessage(urldecode($_GET['msg'])); setMessage ( urldecode ( $_GET ['msg'] ) );
// software toggle input "odometer" line // software toggle input "odometer" line
} }
/// modify parameters if specified // / modify parameters if specified
$conf=readSettings(init_default_config()); // read current settings $conf = readSettings ( init_default_config () ); // read current settings
$apply=0; $apply = 0;
// echo "<pre>\n"; // echo "<pre>\n";
if (count($_GET)==0) { if (count ( $_GET ) == 0) {
help(); help ();
exit(0); exit ( 0 );
} }
if (array_key_exists('source',$_GET)) { if (array_key_exists ( 'source', $_GET )) {
$source=file_get_contents ($_SERVER['SCRIPT_FILENAME']); $source = file_get_contents ( $_SERVER ['SCRIPT_FILENAME'] );
header("Content-Type: text/php"); header ( "Content-Type: text/php" );
header("Content-Length: ".strlen($source)."\n"); header ( "Content-Length: " . strlen ( $source ) . "\n" );
header("Pragma: no-cache\n"); header ( "Pragma: no-cache\n" );
echo $source; echo $source;
exit (0); exit ( 0 );
} }
foreach ($_GET as $key=>$value) { foreach ( $_GET as $key => $value ) {
$access=split(':',$key); $access = split ( ':', $key );
if ($value==='') continue; if ($value === '')
if (count($access)<1) continue; continue;
if (!isset($conf[$access[0]])) continue; if (count ( $access ) < 1)
if (count($access)==1) { continue;
if (($access[0]=='imu_period') && ($value=='auto')) $value = 0xffffff00; if (! isset ( $conf [$access [0]] ))
if (is_string($conf[$access[0]])) $conf[$access[0]]=$value; continue;
else $conf[$access[0]]=$value+0; if (count ( $access ) == 1) {
$apply++; if (($access [0] == 'imu_period') && ($value == 'auto'))
$value = 0xffffff00;
if (is_string ( $conf [$access [0]] ))
$conf [$access [0]] = $value;
else
$conf [$access [0]] = $value + 0;
$apply ++;
} else { // count($access)>1 } else { // count($access)>1
if (!isset($conf[$access[0]][$access[1]])) continue; if (! isset ( $conf [$access [0]] [$access [1]] ))
if (count($access)==2) { continue;
if (is_string($conf[$access[0]][$access[1]])) $conf[$access[0]][$access[1]]=$value; if (count ( $access ) == 2) {
else $conf[$access[0]][$access[1]]=$value+0; if (is_string ( $conf [$access [0]] [$access [1]] ))
$apply++; $conf [$access [0]] [$access [1]] = $value;
else
$conf [$access [0]] [$access [1]] = $value + 0;
$apply ++;
} else { // count($access)>2) } else { // count($access)>2)
if (count($access)>3) continue; if (count ( $access ) > 3)
if ($access[2]=='sentence') $access[2]=0; continue;
else if ($access[2]=='format') $access[2]=1; if ($access [2] == 'sentence')
if (!isset($conf[$access[0]][$access[1]][$access[2]])) continue; $access [2] = 0;
if (is_string($conf[$access[0]][$access[1]][$access[2]])) $conf[$access[0]][$access[1]][$access[2]]=$value; else if ($access [2] == 'format')
else $conf[$access[0]][$access[1]][$access[2]]=$value+0; $access [2] = 1;
$apply++; if (! isset ( $conf [$access [0]] [$access [1]] [$access [2]] ))
} continue;
if (is_string ( $conf [$access [0]] [$access [1]] [$access [2]] ))
$conf [$access [0]] [$access [1]] [$access [2]] = $value;
else
$conf [$access [0]] [$access [1]] [$access [2]] = $value + 0;
$apply ++;
}
}
/*
* echo 'key='.$key."\n";
* print_r($access);
* var_dump($value);
*/
}
if ($apply > 0) {
echo 'modified ' . $apply . "parameters<br/>\n";
// print_r($conf);
setup_IMU_logger ( $conf );
}
if (isset ( $_GET ['save'] )) {
// if ($verbose) echo 'Writing IMU logger configuration to '. $config_name."\n";
$conf = readSettings ( init_default_config () );
$logger_xml = loggerConfigToXML ( $conf );
$conf_file = fopen ( $config_name, "w" );
fwrite ( $conf_file, $logger_xml->asXML () );
fclose ( $conf_file );
exec ( 'sync' );
} }
/*
echo 'key='.$key."\n"; if (isset ( $_GET ['list'] )) {
print_r($access); $conf = readSettings ( init_default_config () );
var_dump($value); $logger_xml = loggerConfigToXML ( $conf );
*/ $logger_xml_text = $logger_xml->asXML ();
} header ( "Content-Type: text/xml" );
if ($apply>0) { header ( "Content-Length: " . strlen ( $logger_xml_text ) . "\n" );
echo 'modified '.$apply."parameters<br/>\n"; header ( "Pragma: no-cache\n" );
// print_r($conf); printf ( $logger_xml_text );
setup_IMU_logger($conf); } else
}
if (isset($_GET['save'])) {
// if ($verbose) echo 'Writing IMU logger configuration to '. $config_name."\n";
$conf=readSettings(init_default_config());
$logger_xml=loggerConfigToXML($conf);
$conf_file=fopen($config_name,"w");
fwrite($conf_file,$logger_xml->asXML());
fclose($conf_file);
exec ('sync');
}
if (isset($_GET['list'])) {
$conf=readSettings(init_default_config());
$logger_xml=loggerConfigToXML($conf);
$logger_xml_text=$logger_xml->asXML();
header("Content-Type: text/xml");
header("Content-Length: ".strlen($logger_xml_text)."\n");
header("Pragma: no-cache\n");
printf($logger_xml_text);
} else echo 'OK';
exit(0);
} else {
// echo "CGI\n";
}
/*
echo "<!--\n";
var_dump($_GET);
var_dump($_SERVER);
echo "-->";
echo 'OK'; echo 'OK';
exit(0); exit ( 0 );
*/ } else {
//! Here comes if CLI // echo "CGI\n";
$ids=scanGrandDaughters(); }
$b_index=indexGrandDaughters($ids); /*
* echo "<!--\n";
* var_dump($_GET);
* var_dump($_SERVER);
* echo "-->";
* echo 'OK';
* exit(0);
*/
// ! Here comes if CLI
/** TODO: Not yet updated for NC393 - use start_gps_compass.php */
$ids = scanGrandDaughters ();
$b_index = indexGrandDaughters ( $ids );
// print_r($ids); // print_r($ids);
// print_r($b_index); // print_r($b_index);
$baud=null; $baud = null;
if (isset($b_index[103696])) { if (isset ( $b_index [103696] )) {
$baud=$ids[$b_index[103696]]['baud']; $baud = $ids [$b_index [103696]] ['baud'];
if ($baud===0) $baud=='auto'; if ($baud === 0)
} $baud == 'auto';
}
// exit (0); // exit (0);
$wait_time=20; // wait for $wait_time if both devices were not found, retry $wait_time = 20; // wait for $wait_time if both devices were not found, retry
$compass=null; $compass = null;
$GPS=null; $GPS = null;
$verbose=true; $verbose = true;
foreach ($_SERVER['argv'] as $param) { foreach ( $_SERVER ['argv'] as $param ) {
if ((substr($param,0,2)=="-q") || (substr($param,0,8)=="--silent")){ if ((substr ( $param, 0, 2 ) == "-q") || (substr ( $param, 0, 8 ) == "--silent")) {
$verbose=false; $verbose = false;
}
} }
}
/// kill those GPS and compass if they are running already // / kill those GPS and compass if they are running already
exec('killall -q garminusb2exif'); exec ( 'killall -q garminusb2exif' );
exec('killall -q nmea2exif'); exec ( 'killall -q nmea2exif' );
exec('killall -q compass'); exec ( 'killall -q compass' );
// find_gps_compass(); // find_gps_compass();
$devs=find_gps_compass($baud); $devs = find_gps_compass ( $baud );
// echo "compass: ";var_dump($compass);echo "\n"; // echo "compass: ";var_dump($compass);echo "\n";
// echo "GPS: ";var_dump($GPS);echo "\n"; // echo "GPS: ";var_dump($GPS);echo "\n";
// if ((!$compass || !$GPS) && ((exec('date +%s')+0) <30)) { // if ((!$compass || !$GPS) && ((exec('date +%s')+0) <30)) {
if ((count($devs)==0) && ((exec('date +%s')+0) <30)) { if ((count ( $devs ) == 0) && ((exec ( 'date +%s' ) + 0) < 30)) {
if ($verbose) echo "waiting $wait_time sec for USB devices to start up\n"; if ($verbose)
sleep($wait_time); echo "waiting $wait_time sec for USB devices to start up\n";
if ($verbose) echo "Retrying detection\n"; sleep ( $wait_time );
$devs=find_gps_compass($baud); if ($verbose)
} echo "Retrying detection\n";
listSensorDevices($devs,$b_index,$ids); $devs = find_gps_compass ( $baud );
//var_dump($GPS); }
listSensorDevices ( $devs, $b_index, $ids );
// var_dump($GPS);
// if (file_exists ($sensor_state_file)) $sensor_board=parse_ini_file($sensor_state_file); // if (file_exists ($sensor_state_file)) $sensor_board=parse_ini_file($sensor_state_file);
// exec ('sync'); // exec ('sync');
$logger_config=null; $logger_config = null;
$write_config=false; $write_config = false;
if (file_exists ($config_name)) { if (file_exists ( $config_name )) {
if ($verbose) echo 'Reading IMU logger configuration from '. $config_name."\n"; if ($verbose)
$config_xml = simplexml_load_file($config_name); echo 'Reading IMU logger configuration from ' . $config_name . "\n";
$logger_config=loggerConfigFromXML($config_xml); $config_xml = simplexml_load_file ( $config_name );
} else if (isset($b_index[103696]) || isset($b_index[103696])) { $logger_config = loggerConfigFromXML ( $config_xml );
if ($verbose) echo "Generating IMU logger configuration\n"; } else if (isset ( $b_index [103696] ) || isset ( $b_index [103696] )) {
// $default_config=init_default_config(); if ($verbose)
// $logger_config=init_default_config(); echo "Generating IMU logger configuration\n";
$logger_config=array(); // $default_config=init_default_config();
if (isset($GPS) && isset($b_index[103696])) { // $logger_config=init_default_config();
$logger_config['baud_rate']=$GPS['baud']; $logger_config = array ();
$logger_config['gps_slot']=$ids[$b_index[103696]]['port']; if (isset ( $GPS ) && isset ( $b_index [103696] )) {
$logger_config['gps_mode']=$ids[$b_index[103696]]['sync']; $logger_config ['baud_rate'] = $GPS ['baud'];
} $logger_config ['gps_slot'] = $ids [$b_index [103696]] ['port'];
if (isset($b_index[103695])) { $logger_config ['gps_mode'] = $ids [$b_index [103696]] ['sync'];
$logger_config['imu_slot']=$ids[$b_index[103695]]['port']; }
$logger_config['imu_sa']=$b_index[103695]; if (isset ( $b_index [103695] )) {
} $logger_config ['imu_slot'] = $ids [$b_index [103695]] ['port'];
$write_config=true; // write configuration to /etc after applying defaults $logger_config ['imu_sa'] = $b_index [103695];
} }
if (isset($logger_config)){ $write_config = true; // write configuration to /etc after applying defaults
// var_dump($logger_config); }
$logger_config=combineLoggerConfigs($logger_config,init_default_config()); if (isset ( $logger_config )) {
// var_dump($logger_config); // var_dump($logger_config);
// var_dump($default_config); $logger_config = combineLoggerConfigs ( $logger_config, init_default_config () );
$logger_xml=loggerConfigToXML($logger_config); // var_dump($logger_config);
$conf_file=fopen('/var/html/logger_config.xml',"w"); // var_dump($default_config);
fwrite($conf_file,$logger_xml->asXML()); $logger_xml = loggerConfigToXML ( $logger_config );
fclose($conf_file); $conf_file = fopen ( '/var/html/logger_config.xml', "w" );
setup_IMU_logger($logger_config); fwrite ( $conf_file, $logger_xml->asXML () );
fclose ( $conf_file );
setup_IMU_logger ( $logger_config );
if ($write_config) { if ($write_config) {
if ($verbose) echo 'Writing IMU logger configuration to '. $config_name."\n"; if ($verbose)
$conf_file=fopen($config_name,"w"); echo 'Writing IMU logger configuration to ' . $config_name . "\n";
fwrite($conf_file,$logger_xml->asXML()); $conf_file = fopen ( $config_name, "w" );
fclose($conf_file); fwrite ( $conf_file, $logger_xml->asXML () );
exec ('sync'); fclose ( $conf_file );
} exec ( 'sync' );
} }
}
// echo "compass: ";var_dump($compass);echo "\n"; // echo "compass: ";var_dump($compass);echo "\n";
// echo "GPS: ";var_dump($GPS);echo "\n"; // echo "GPS: ";var_dump($GPS);echo "\n";
$noGPS= ($compass || $GPS)?"" : "noGPS"; $noGPS = ($compass || $GPS) ? "" : "noGPS";
$nocompass=($compass)?"" : "nocompass"; $nocompass = ($compass) ? "" : "nocompass";
$cmd="/usr/html/exif.php init $noGPS $nocompass"; $cmd = "/usr/html/exif.php init $noGPS $nocompass";
if ($verbose) echo "Initializing Exif template: $cmd\n"; if ($verbose)
exec($cmd); echo "Initializing Exif template: $cmd\n";
if ($GPS) { exec ( $cmd );
if ($verbose) echo "Starting ".$GPS["name"]. " as ". $GPS["file"]. "\n"; if ($GPS) {
if (strpos($GPS['name'],'NMEA')!==false) { if ($verbose)
$cmd ="/usr/local/bin/nmea2exif ". $GPS["file"]." &"; echo "Starting " . $GPS ["name"] . " as " . $GPS ["file"] . "\n";
if (strpos ( $GPS ['name'], 'NMEA' ) !== false) {
$cmd = "/usr/local/bin/nmea2exif " . $GPS ["file"] . " &";
} else { } else {
$cmd ="/usr/local/bin/garminusb2exif ". $GPS["file"]." &"; $cmd = "/usr/local/bin/garminusb2exif " . $GPS ["file"] . " &";
} }
if ($verbose) echo "exec: $cmd \n"; if ($verbose)
popen($cmd,"r"); echo "exec: $cmd \n";
} popen ( $cmd, "r" );
if ($compass) { }
if ($verbose) echo "Starting ".$compass["name"]. " as ". $compass["file"]. "\n"; if ($compass) {
exec ("stty -F ".$compass["file"]." -echo speed 19200"); if ($verbose)
$cmd="/usr/local/bin/compass ". $compass["file"]." &"; echo "Starting " . $compass ["name"] . " as " . $compass ["file"] . "\n";
if ($verbose) echo "exec: $cmd \n"; exec ( "stty -F " . $compass ["file"] . " -echo speed 19200" );
popen($cmd,"r"); $cmd = "/usr/local/bin/compass " . $compass ["file"] . " &";
} if ($verbose)
exit ((isset($b_index[103695])?4:0) | ($compass?2:0) | ($GPS?1:0)); echo "exec: $cmd \n";
function help(){ popen ( $cmd, "r" );
$GP='$GP'; }
$GPRMC='$GPRMC'; exit ( (isset ( $b_index [103695] ) ? 4 : 0) | ($compass ? 2 : 0) | ($GPS ? 1 : 0) );
$GPGGA='$GPGGA'; function help() {
$GPGSA='$GPGSA'; $GP = '$GP';
$GPVTG='$GPVTG'; $GPRMC = '$GPRMC';
$script_name=$_SERVER['SCRIPT_NAME']; $GPGGA = '$GPGGA';
$prefix_url='http://'.$_SERVER['SERVER_ADDR'].$_SERVER['SCRIPT_NAME']; $GPGSA = '$GPGSA';
// echo <<<USAGE $GPVTG = '$GPVTG';
// <h4> Control links:</h4> $script_name = $_SERVER ['SCRIPT_NAME'];
// <ul> $prefix_url = 'http://' . $_SERVER ['SERVER_ADDR'] . $_SERVER ['SCRIPT_NAME'];
// <li><a href="?$url_init">Initialization Parameters (i.e. after powerup)</a></li> // echo <<<USAGE
// <h4> Control links:</h4>
// <ul>
// <li><a href="?$url_init">Initialization Parameters (i.e. after powerup)</a></li>
echo <<<USAGE echo <<<USAGE
<head> <head>
...@@ -363,7 +391,6 @@ function help(){ ...@@ -363,7 +391,6 @@ function help(){
</p> </p>
</body> </body>
USAGE; USAGE;
} }
function scanGrandDaughters() { function scanGrandDaughters() {
global $i2cbus; global $i2cbus;
...@@ -390,205 +417,233 @@ function indexGrandDaughters($ids) { ...@@ -390,205 +417,233 @@ function indexGrandDaughters($ids) {
} }
return $index; return $index;
} }
/// compass/GPS programs should be killed before detection // / compass/GPS programs should be killed before detection
// baud=null - search USB Garmin and compass // baud=null - search USB Garmin and compass
// baud=auto - try to autodetect baud rate // baud=auto - try to autodetect baud rate
// baud=number - used specified baud rate, do not wait for the GPS response // baud=number - used specified baud rate, do not wait for the GPS response
function find_gps_compass($baud=null,$timeout=5) { function find_gps_compass($baud = null, $timeout = 5) {
global $verbose; global $verbose;
$ttyOptions=array ( $ttyOptions = array (
'-echo speed 19200', /// maybe other options, like '-echo speed 4800 -ixoff' '-echo speed 19200', // / maybe other options, like '-echo speed 4800 -ixoff'
'-echo speed 9600', '-echo speed 9600',
'-echo speed 4800', '-echo speed 4800',
'-echo speed 2400' '-echo speed 2400'
); );
if (isset($baud) && ($baud!='auto') && ($baud!=0)) { if (isset ( $baud ) && ($baud != 'auto') && ($baud != 0)) {
$ttyOptions=array ( $ttyOptions = array (
'-echo speed '.$baud); '-echo speed ' . $baud
} );
// global $GPS, $compass; }
$devices=array( // global $GPS, $compass;
"compass"=>array(array("name"=>"Ocean Server OS-5000","driver"=>"cp2101")), $devices = array (
"GPS" =>array(array("name"=>"Garmin GPS 18 USB","driver"=>"garmin_gps"))); "compass" => array (
exec("ls /sys/bus/usb-serial/devices",$usb_ser_devs); // ("ttyUSB0","ttyUSB1") array (
$devs = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><USB_serial_devices/>"); "name" => "Ocean Server OS-5000",
$serialDevices=array(); "driver" => "cp2101"
$compassPresent=false; )
$gpsPresent=false; ),
$driver=array(); "GPS" => array (
//echo "usb_ser_devs"; var_dump($usb_ser_devs); array (
foreach ($usb_ser_devs as $dev) { "name" => "Garmin GPS 18 USB",
//echo "dev=$dev\n"; "driver" => "garmin_gps"
$arr=split("/",exec("ls /sys/bus/usb-serial/devices/".$dev."/driver -l")); )
$driver[$dev]=$arr[count($arr)-1]; )
$serialDevices[$dev]=''; );
if (!isset($baud)) { // if baud is set (auto or number - skip compass, it is 103696) exec ( "ls /sys/bus/usb-serial/devices", $usb_ser_devs ); // ("ttyUSB0","ttyUSB1")
foreach ($devices["compass"] as $d) { $devs = new SimpleXMLElement ( "<?xml version='1.0' standalone='yes'?><USB_serial_devices/>" );
if ($d["driver"]==$driver[$dev]) { $serialDevices = array ();
$dd=$devs->addChild ('compass'); $compassPresent = false;
$dd->addChild ('name',$d["name"]); $gpsPresent = false;
$dd->addChild ('driver',$d["driver"]); $driver = array ();
$dd->addChild ('file',"/dev/".$dev); // echo "usb_ser_devs"; var_dump($usb_ser_devs);
$serialDevices[$dev]='compass'; foreach ( $usb_ser_devs as $dev ) {
$compassPresent=true; // echo "dev=$dev\n";
} $arr = split ( "/", exec ( "ls /sys/bus/usb-serial/devices/" . $dev . "/driver -l" ) );
} $driver [$dev] = $arr [count ( $arr ) - 1];
} $serialDevices [$dev] = '';
if ($serialDevices[$dev]) continue; if (! isset ( $baud )) { // if baud is set (auto or number - skip compass, it is 103696)
foreach ($devices["GPS"] as $d) { foreach ( $devices ["compass"] as $d ) {
if ($d["driver"]==$driver[$dev]) { if ($d ["driver"] == $driver [$dev]) {
$dd=$devs->addChild ('GPS'); $dd = $devs->addChild ( 'compass' );
$dd->addChild ('name',$d["name"]); $dd->addChild ( 'name', $d ["name"] );
$dd->addChild ('driver',$d["driver"]); $dd->addChild ( 'driver', $d ["driver"] );
$dd->addChild ('file',"/dev/".$dev); $dd->addChild ( 'file', "/dev/" . $dev );
$serialDevices[$dev]='gps'; $serialDevices [$dev] = 'compass';
$gpsPresent=true; $compassPresent = true;
} }
} }
} }
/// Do we need to look for a NMEA GPS? if ($serialDevices [$dev])
if (!$gpsPresent) foreach ($serialDevices as $dev=>$type) if (!$type && !$gpsPresent) { continue;
if ($verbose) printf ("could be $dev\n"); foreach ( $devices ["GPS"] as $d ) {
foreach ($ttyOptions as $ttyOpt) { if ($d ["driver"] == $driver [$dev]) {
$cmd='stty -F /dev/'.$dev.' '.$ttyOpt; $dd = $devs->addChild ( 'GPS' );
if (count($ttyOptions)==1) { /// single baud option, will not wait for confirmation. Has to be only one serial adapter !! $dd->addChild ( 'name', $d ["name"] );
if ($verbose) echo "Setting: $cmd\n"; $dd->addChild ( 'driver', $d ["driver"] );
exec ($cmd); $dd->addChild ( 'file', "/dev/" . $dev );
$gpsPresent=true; $serialDevices [$dev] = 'gps';
$gpsPresent = true;
}
}
}
// / Do we need to look for a NMEA GPS?
if (! $gpsPresent)
foreach ( $serialDevices as $dev => $type )
if (! $type && ! $gpsPresent) {
if ($verbose)
printf ( "could be $dev\n" );
foreach ( $ttyOptions as $ttyOpt ) {
$cmd = 'stty -F /dev/' . $dev . ' ' . $ttyOpt;
if (count ( $ttyOptions ) == 1) { // / single baud option, will not wait for confirmation. Has to be only one serial adapter !!
if ($verbose)
echo "Setting: $cmd\n";
exec ( $cmd );
$gpsPresent = true;
} else { } else {
if ($verbose) echo "Trying: $cmd\n"; if ($verbose)
exec ($cmd); echo "Trying: $cmd\n";
unset ($fullOutput); exec ( $cmd );
exec ('timeout '.$timeout.' cat /dev/'.$dev, $fullOutput); // &$fullOutput - Fatal error: Call-time pass-by-reference has been removed in php unset ( $fullOutput );
//var_dump($fullOutput); exec ( 'timeout ' . $timeout . ' cat /dev/' . $dev, $fullOutput ); // &$fullOutput - Fatal error: Call-time pass-by-reference has been removed in php
foreach ($fullOutput as $line) if (strpos ($line, '$GP')===0) { // var_dump($fullOutput);
$gpsPresent=true; foreach ( $fullOutput as $line )
if (strpos ( $line, '$GP' ) === 0) {
$gpsPresent = true;
break; break;
} }
} }
if ($gpsPresent) { if ($gpsPresent) {
$dd=$devs->addChild ('GPS'); $dd = $devs->addChild ( 'GPS' );
$dd->addChild ('name','NMEA 0183 GPS receiver'); $dd->addChild ( 'name', 'NMEA 0183 GPS receiver' );
$dd->addChild ('driver',$driver[$dev]); $dd->addChild ( 'driver', $driver [$dev] );
$dd->addChild ('file',"/dev/".$dev); $dd->addChild ( 'file', "/dev/" . $dev );
$arr=split(" ",$ttyOpt); $arr = split ( " ", $ttyOpt );
$dd->addChild ('baud',$arr[count($arr)-1]); $dd->addChild ( 'baud', $arr [count ( $arr ) - 1] );
$serialDevices[$dev]='gps'; $serialDevices [$dev] = 'gps';
if ($verbose) echo "\nfound NMEA GPS unit\n"; if ($verbose)
echo "\nfound NMEA GPS unit\n";
break; break;
} }
// var_dump($fullOutput); // var_dump($fullOutput);
} }
} }
/// list unused USB serial adapters // / list unused USB serial adapters
foreach ($serialDevices as $dev=>$type) if (!$type) { foreach ( $serialDevices as $dev => $type )
$dd=$devs->addChild ('unused'); if (! $type) {
$dd->addChild ('name','USB serial converter'); $dd = $devs->addChild ( 'unused' );
$dd->addChild ('driver',$driver[$dev]); $dd->addChild ( 'name', 'USB serial converter' );
$dd->addChild ('file',"/dev/".$dev); $dd->addChild ( 'driver', $driver [$dev] );
$dd->addChild ( 'file', "/dev/" . $dev );
} }
return $devs; return $devs;
} }
function listSensorDevices($devs,$b_index,$ids) { function listSensorDevices($devs, $b_index, $ids) {
global $GPS, $compass,$gps_compass_xml; global $GPS, $compass, $gps_compass_xml;
foreach ($devs->compass as $a) { foreach ( $devs->compass as $a ) {
$compass=array("file"=>(string) $a->file, "name"=> (string) $a->name); $compass = array (
"file" => ( string ) $a->file,
"name" => ( string ) $a->name
);
break; // use first one break; // use first one
} }
foreach ($devs->GPS as $a) { foreach ( $devs->GPS as $a ) {
$GPS=array("file"=>(string) $a->file, "name"=> (string) $a->name, "baud"=>(string) $a->baud); $GPS = array (
if (isset($b_index[103696])) { "file" => ( string ) $a->file,
$a->addChild ('part_number',$ids[$b_index[103696]]['part']); "name" => ( string ) $a->name,
$a->addChild ('port',$ids[$b_index[103696]]['port']); "baud" => ( string ) $a->baud
$a->addChild ('mode',$ids[$b_index[103696]]['mode']); );
if (isset ( $b_index [103696] )) {
$a->addChild ( 'part_number', $ids [$b_index [103696]] ['part'] );
$a->addChild ( 'port', $ids [$b_index [103696]] ['port'] );
$a->addChild ( 'mode', $ids [$b_index [103696]] ['mode'] );
} }
break; // use first one break; // use first one
} }
$state_file=fopen($gps_compass_xml,"w"); $state_file = fopen ( $gps_compass_xml, "w" );
fwrite($state_file,$devs->asXML()); fwrite ( $state_file, $devs->asXML () );
fclose($state_file); fclose ( $state_file );
} }
function loggerConfigToXML($conf){ function loggerConfigToXML($conf) {
$logger_xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><Logger_configuration/>"); $logger_xml = new SimpleXMLElement ( "<?xml version='1.0' standalone='yes'?><Logger_configuration/>" );
foreach ($conf as $key=>$value) { foreach ( $conf as $key => $value ) {
switch ($key) { switch ($key) {
case 'imu_registers': case 'imu_registers' :
$subtree=$logger_xml->addChild ($key); $subtree = $logger_xml->addChild ( $key );
for ($i=0;$i<count($value);$i++) { for($i = 0; $i < count ( $value ); $i ++) {
$subtree->addChild ('R_'.sprintf('%02d',$i),sprintf("0x%02x",$value[$i])); $subtree->addChild ( 'R_' . sprintf ( '%02d', $i ), sprintf ( "0x%02x", $value [$i] ) );
} }
break; break;
case 'nmea': case 'nmea' :
$subtree=$logger_xml->addChild ($key); $subtree = $logger_xml->addChild ( $key );
for ($i=0;$i<count($value);$i++) { for($i = 0; $i < count ( $value ); $i ++) {
$sentence=$subtree->addChild ('S_'.sprintf('%01d',$i)); $sentence = $subtree->addChild ( 'S_' . sprintf ( '%01d', $i ) );
$sentence->addChild ('sentence',$value[$i][0]); $sentence->addChild ( 'sentence', $value [$i] [0] );
$sentence->addChild ('format',$value[$i][1]); $sentence->addChild ( 'format', $value [$i] [1] );
} }
break; break;
default: default :
$logger_xml->addChild ($key,$value); $logger_xml->addChild ( $key, $value );
} }
} }
return $logger_xml; return $logger_xml;
} }
function loggerConfigFromXML($confXML){ function loggerConfigFromXML($confXML) {
$conf=array(); $conf = array ();
// var_dump($confXML); // var_dump($confXML);
foreach ($confXML as $item) { foreach ( $confXML as $item ) {
// var_dump($item); // var_dump($item);
$key=$item->getName(); $key = $item->getName ();
switch ($key) { switch ($key) {
case 'imu_registers': case 'imu_registers' :
$conf[$key]=array(); $conf [$key] = array ();
foreach ($item as $reg) { foreach ( $item as $reg ) {
$rname=substr($reg->getName(),2); $rname = substr ( $reg->getName (), 2 );
$conf[$key][$rname+0]=((string) $reg)+0; $conf [$key] [$rname + 0] = (( string ) $reg) + 0;
} }
break; break;
case 'nmea': case 'nmea' :
$conf[$key]=array(); $conf [$key] = array ();
foreach ($item as $reg) { foreach ( $item as $reg ) {
$rname=substr($reg->getName(),2); $rname = substr ( $reg->getName (), 2 );
$conf[$key][$rname+0]=array((string) $reg->sentence, (string) $reg->format); $conf [$key] [$rname + 0] = array (
( string ) $reg->sentence,
( string ) $reg->format
);
} }
break; break;
case 'imu_period': case 'imu_period' :
$conf[$key]=(string) $item; $conf [$key] = ( string ) $item;
if ($conf[$key]!='auto') $conf[$key]+=0; if ($conf [$key] != 'auto')
$conf [$key] += 0;
break; break;
case 'message': case 'message' :
$conf[$key]=(string) $item; $conf [$key] = ( string ) $item;
break; break;
default: default :
// $conf[$key]=(int) $item; // $conf[$key]=(int) $item;
$conf[$key]=((string) $item)+0; $conf [$key] = (( string ) $item) + 0;
} }
} }
return $conf; return $conf;
} }
function init_default_config() {
$default_config = array (
'imu_period' => 'auto', // 0xFFFFFFFF, // 0 - off, >=0xff000000 - "when ready", else - number of SCLK periods
function init_default_config(){ 'sclk_freq' => 5000000, // $clkr_divr= 8, // 80MHz divisor to get half SCLK rate (defaulkt SCLK=5MHz)
$default_config=array(
'imu_period'=>'auto',// 0xFFFFFFFF, // 0 - off, >=0xff000000 - "when ready", else - number of SCLK periods
'sclk_freq'=>5000000, // $clkr_divr= 8, // 80MHz divisor to get half SCLK rate (defaulkt SCLK=5MHz)
'stall' => 2, // SPI stall time in usec 'stall' => 2, // SPI stall time in usec
'baud_rate'=>19200, // $rs232_div=80/2/$baud 'baud_rate' => 19200, // $rs232_div=80/2/$baud
'imu_slot'=>1, 'imu_slot' => 1,
'gps_slot'=>2, 'gps_slot' => 2,
'gps_mode'=>2, // 0 - pps neg, 1 - pps pos, 2 - start of first sentence after pause, 3 start of sentence 'gps_mode' => 2, // 0 - pps neg, 1 - pps pos, 2 - start of first sentence after pause, 3 start of sentence
'msg_conf'=>10, // GPIO bit number for external (odometer) input (+16 - invert polarity). Timestamp uses leading edge, software may write to 56-byte buffer before the trailing edge 'msg_conf' => 10, // GPIO bit number for external (odometer) input (+16 - invert polarity). Timestamp uses leading edge, software may write to 56-byte buffer before the trailing edge
'img_sync'=>1, // enable logging image acquisition starts (0 - disable) 'img_sync' => 1, // enable logging image acquisition starts (0 - disable)
'extra_conf'=>4, // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A" 'extra_conf' => 4, // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
'slow_spi'=>0, // set to 1 for slow SPI devices (0 for ADIS-16375) 'slow_spi' => 0, // set to 1 for slow SPI devices (0 for ADIS-16375)
'imu_sa'=>3, // i2c slave address modifier for the 103695A pca9500 'imu_sa' => 3, // i2c slave address modifier for the 103695A pca9500
'sleep_busy'=>30000, //microseconds 'sleep_busy' => 30000, // microseconds
'imu_registers'=>array( /// Up to 28 total 'imu_registers' => array ( // / Up to 28 total
0x10, // x gyro low 0x10, // x gyro low
0x12, // x gyro high 0x12, // x gyro high
0x14, // y gyro low 0x14, // y gyro low
...@@ -620,327 +675,379 @@ function init_default_config(){ ...@@ -620,327 +675,379 @@ function init_default_config(){
0x0e, // temperature 0x0e, // temperature
0x70, // time m/s 0x70, // time m/s
0x72, // time d/h 0x72, // time d/h
0x74// time y/m 0x74
) // time y/m
,
'nmea' => array (
// / first three letters - sentence to log (letters after "$GP"). next "n"/"b" (up to 24 total) - "n" number (will be encoded 2 digits/byte, follwed by "0xF"
// / "b" - byte - all but last will have MSB 0 (& 0x7f), the last one - with MSB set (| 0x80). If there are no characters in the field 0xff will be output
array (
'RMC',
'nbnbnbnnnnb'
), ),
'nmea'=>array( array (
/// first three letters - sentence to log (letters after "$GP"). next "n"/"b" (up to 24 total) - "n" number (will be encoded 2 digits/byte, follwed by "0xF" 'GGA',
/// "b" - byte - all but last will have MSB 0 (& 0x7f), the last one - with MSB set (| 0x80). If there are no characters in the field 0xff will be output 'nnbnbnnnnbnbbb'
array('RMC','nbnbnbnnnnb'),
array('GGA','nnbnbnnnnbnbbb'),
array('GSA','bnnnnnnnnnnnnnnnn'),
array('VTG','nbnbnbnb')
), ),
'message'=>'Odometer message' // Message - up to 56 bytes array (
); 'GSA',
'bnnnnnnnnnnnnnnnn'
),
array (
'VTG',
'nbnbnbnb'
)
),
'message' => 'Odometer message'
) // Message - up to 56 bytes
;
return $default_config; return $default_config;
} }
/** /**
Combines $conf and $dflt arrays - all driver parameters are overwritten aftre the call * Combines $conf and $dflt arrays - all driver parameters are overwritten aftre the call
*/ */
function combineLoggerConfigs($new_conf,$dflt=null){ function combineLoggerConfigs($new_conf, $dflt = null) {
global $default_config; global $default_config;
# $xclk_freq=80000000; // 80 MHz in NC353 // $xclk_freq=80000000; // 80 MHz in NC353
$xclk_freq=100000000; // 100 MHz in NC393 $xclk_freq = 100000000; // 100 MHz in NC393
$data=array(); $data = array ();
$index=0; $index = 0;
if (!isset ($dflt)) { if (! isset ( $dflt )) {
$dflt=$default_config; $dflt = $default_config;
} }
$conf=$dflt; $conf = $dflt;
if (isset($new_conf)) foreach ($conf as $key=>$oldvalue) if (isset($new_conf[$key])) $conf[$key]=$new_conf[$key]; if (isset ( $new_conf ))
/// fix insufficient data from default foreach ( $conf as $key => $oldvalue )
if (isset ( $new_conf [$key] ))
while (count($conf['imu_registers'])<28) $conf['imu_registers'][count($conf['imu_registers'])]=0; // zero pad if less than 28 registers $conf [$key] = $new_conf [$key];
/// Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults // / fix insufficient data from default
while (count($conf['nmea'])<4) {
for ($i=0;$i<4;$i++) { while ( count ( $conf ['imu_registers'] ) < 28 )
$new=true; $conf ['imu_registers'] [count ( $conf ['imu_registers'] )] = 0; // zero pad if less than 28 registers
for ($j=0;$j<count($conf['nmea']);$j++) if ($conf['nmea'][$j][0]==$dflt['nmea'][$i][0]){ // compare sentence code last 3 letters // / Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
$new=false; while ( count ( $conf ['nmea'] ) < 4 ) {
for($i = 0; $i < 4; $i ++) {
$new = true;
for($j = 0; $j < count ( $conf ['nmea'] ); $j ++)
if ($conf ['nmea'] [$j] [0] == $dflt ['nmea'] [$i] [0]) { // compare sentence code last 3 letters
$new = false;
break; break;
} }
if ($new) { if ($new) {
$conf['nmea'][count($conf['nmea'])]=$dflt['nmea'][$i]; $conf ['nmea'] [count ( $conf ['nmea'] )] = $dflt ['nmea'] [$i];
break; break;
} }
} }
} }
for ($i=0;$i<4;$i++) { for($i = 0; $i < 4; $i ++) {
while (strlen($conf['nmea'][$i][0])<3) $conf['nmea'][$i][0].="A"; // just to avoid errors - nonexistent sentences will not hurt, just never logged while ( strlen ( $conf ['nmea'] [$i] [0] ) < 3 )
$conf ['nmea'] [$i] [0] .= "A"; // just to avoid errors - nonexistent sentences will not hurt, just never logged
} }
return $conf; return $conf;
} }
function setup_IMU_logger($conf){ function setup_IMU_logger($conf) {
global $verbose,$xclk_freq; global $verbose, $xclk_freq;
$data=array(); $data = array ();
$index=0; $index = 0;
/// program period // / program period
if (strtolower($conf['imu_period'])=='auto') $conf['imu_period']=0xffffffff; if (strtolower ( $conf ['imu_period'] ) == 'auto')
else $conf['imu_period']+=0; $conf ['imu_period'] = 0xffffffff;
$data[$index++]= $conf['imu_period'] & 0xff; else
$data[$index++]=($conf['imu_period']>> 8) & 0xff; $conf ['imu_period'] += 0;
$data[$index++]=($conf['imu_period']>>16) & 0xff; $data [$index ++] = $conf ['imu_period'] & 0xff;
$data[$index++]=($conf['imu_period']>>24) & 0xff; $data [$index ++] = ($conf ['imu_period'] >> 8) & 0xff;
/// program SCLK divisor and SPI stall time $data [$index ++] = ($conf ['imu_period'] >> 16) & 0xff;
$sclk_div=round($xclk_freq/$conf['sclk_freq']/2); $data [$index ++] = ($conf ['imu_period'] >> 24) & 0xff;
if ($sclk_div<1) $sclk_div=1; // / program SCLK divisor and SPI stall time
else if ($sclk_div>255) $sclk_div=255; $sclk_div = round ( $xclk_freq / $conf ['sclk_freq'] / 2 );
$conf['sclk_freq']=$xclk_freq/$sclk_div/2; if ($sclk_div < 1)
$stall=(( $conf['stall'] * ( $xclk_freq / $sclk_div )) / 1000000 ); $sclk_div = 1;
if ($stall< 1) $stall= 1; /// does 0 work? need to verify else if ($sclk_div > 255)
else if ($stall>255) $stall=255; $sclk_div = 255;
$conf['stall']=$stall * 1000000 / ($xclk_freq / $sclk_div); $conf ['sclk_freq'] = $xclk_freq / $sclk_div / 2;
$data[$index++]= $sclk_div; $stall = (($conf ['stall'] * ($xclk_freq / $sclk_div)) / 1000000);
$data[$index++]= $stall; if ($stall < 1)
$data[$index++]= 0; $stall = 1; // / does 0 work? need to verify
$data[$index++]= 0; else if ($stall > 255)
/// Program rs232 baud rate $stall = 255;
$rs232_div=round($xclk_freq /2/$conf['baud_rate']); $conf ['stall'] = $stall * 1000000 / ($xclk_freq / $sclk_div);
$conf['baud_rate']=$xclk_freq /2/$rs232_div; $data [$index ++] = $sclk_div;
$data[$index++]= $rs232_div & 0xff; $data [$index ++] = $stall;
$data[$index++]=($rs232_div>> 8) & 0xff; $data [$index ++] = 0;
$data[$index++]=($rs232_div>>16) & 0xff; $data [$index ++] = 0;
$data[$index++]=($rs232_div>>24) & 0xff; // / Program rs232 baud rate
/// Program logger configuration (possible to modify only some fields - maybe support it here?) $rs232_div = round ( $xclk_freq / 2 / $conf ['baud_rate'] );
$logger_conf=0; $conf ['baud_rate'] = $xclk_freq / 2 / $rs232_div;
/// #define IMUCR__IMU_SLOT__BITNM 0 // slot, where 103695 (imu) board is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11) $data [$index ++] = $rs232_div & 0xff;
/// #define IMUCR__IMU_SLOT__WIDTH 2 $data [$index ++] = ($rs232_div >> 8) & 0xff;
$logger_conf |= (($conf['imu_slot'] & 0x3) | 0x4 )<< 0; /// "4" (bit 2 set) here means that the data in bits 0,1 will be applied in the FPGA register $data [$index ++] = ($rs232_div >> 16) & 0xff;
$data [$index ++] = ($rs232_div >> 24) & 0xff;
/// #define IMUCR__GPS_CONF__BITNM 3 // slot, where 103695 (imu) bnoard is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11) // / Program logger configuration (possible to modify only some fields - maybe support it here?)
/// #define IMUCR__GPS_CONF__WIDTH 4 // bits 0,1 - slot #, same as for IMU_SLOT, bits 2,3: $logger_conf = 0;
// / #define IMUCR__IMU_SLOT__BITNM 0 // slot, where 103695 (imu) board is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
// / #define IMUCR__IMU_SLOT__WIDTH 2
$logger_conf |= (($conf ['imu_slot'] & 0x3) | 0x4) << 0; // / "4" (bit 2 set) here means that the data in bits 0,1 will be applied in the FPGA register
// / #define IMUCR__GPS_CONF__BITNM 3 // slot, where 103695 (imu) bnoard is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
// / #define IMUCR__GPS_CONF__WIDTH 4 // bits 0,1 - slot #, same as for IMU_SLOT, bits 2,3:
// 0 - ext pulse, leading edge, // 0 - ext pulse, leading edge,
// 1 - ext pulse, trailing edge // 1 - ext pulse, trailing edge
// 2 - start of the first rs232 character after pause // 2 - start of the first rs232 character after pause
// 3 - start of the last "$" character (start of each NMEA sentence) // 3 - start of the last "$" character (start of each NMEA sentence)
$logger_conf |= ((($conf['gps_slot'] & 0x3) | (($conf['gps_mode'] & 0x3)<<2) ) | 0x10 )<< 3; $logger_conf |= ((($conf ['gps_slot'] & 0x3) | (($conf ['gps_mode'] & 0x3) << 2)) | 0x10) << 3;
/// #define IMUCR__MSG_CONF__BITNM 8 // source of external pulses to log: // / #define IMUCR__MSG_CONF__BITNM 8 // source of external pulses to log:
/// #define IMUCR__MSG_CONF__WIDTH 5 // bits 0-3 - number of fpga GPIO input 0..11 (i.e. 0x0a - external optoisolated sync input (J15) // / #define IMUCR__MSG_CONF__WIDTH 5 // bits 0-3 - number of fpga GPIO input 0..11 (i.e. 0x0a - external optoisolated sync input (J15)
// 0x0f - disable MSG module // 0x0f - disable MSG module
// bit 4 - invert polarity: 0 - timestamp leading edge, log at trailing edge, 1 - opposite // bit 4 - invert polarity: 0 - timestamp leading edge, log at trailing edge, 1 - opposite
// software may set (up to 56 bytes) log message before trailing end of the pulse // software may set (up to 56 bytes) log message before trailing end of the pulse
$logger_conf |= (($conf['msg_conf'] & 0x1f) | 0x20 )<< 8; $logger_conf |= (($conf ['msg_conf'] & 0x1f) | 0x20) << 8;
/// #define IMUCR__SYN_CONF__BITNM 14 // logging frame time stamps (may be synchronized by another camera and have timestamp of that camera) // / #define IMUCR__SYN_CONF__BITNM 14 // logging frame time stamps (may be synchronized by another camera and have timestamp of that camera)
/// #define IMUCR__SYN_CONF__WIDTH 1 // 0 - disable, 1 - enable // / #define IMUCR__SYN_CONF__WIDTH 1 // 0 - disable, 1 - enable
$logger_conf |= (($conf['img_sync'] & 0x1) | 0x2 )<< 14; $logger_conf |= (($conf ['img_sync'] & 0x1) | 0x2) << 14;
/// #define IMUCR__RST_CONF__BITNM 16 // reset module // / #define IMUCR__RST_CONF__BITNM 16 // reset module
/// #define IMUCR__RST_CONF__WIDTH 1 // 0 - enable, 1 -reset (needs resettimng DMA address in ETRAX also) // / #define IMUCR__RST_CONF__WIDTH 1 // 0 - enable, 1 -reset (needs resettimng DMA address in ETRAX also)
/// #define IMUCR__DBG_CONF__BITNM 18 // several extra IMU configuration bits
/// #define IMUCR__DBG_CONF__WIDTH 4 // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
$logger_conf |= (($conf['extra_conf'] & 0xf) | 0x10 )<< 18;
/// next bits used by the driver only, not the FPGA
/// ((SLOW_SPI & 1)<<23) | \
/// (DFLT_SLAVE_ADDR << 24))
$logger_conf |= ($conf['slow_spi'] & 0x1)<< 23;
$logger_conf |= ($conf['imu_sa'] & 0x7)<< 24;
$data[$index++]= $logger_conf & 0xff;
$data[$index++]=($logger_conf>> 8) & 0xff;
$data[$index++]=($logger_conf>>16) & 0xff;
$data[$index++]=($logger_conf>>24) & 0xff;
/// Set time driver will go to sleep if the data is not ready yet (less than full sample in the buffer)
$data[$index++]= $conf['sleep_busy'] & 0xff;
$data[$index++]=($conf['sleep_busy']>> 8) & 0xff;
$data[$index++]=($conf['sleep_busy']>>16) & 0xff;
$data[$index++]=($conf['sleep_busy']>>24) & 0xff;
/// Set IMU register addresses to logger
// echo "1\n";
for ($i=0;$i<28;$i++) $data[$index++]= $conf['imu_registers'][$i]; // truncate to 28
/// Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
// echo "2\n";
for ($i=0;$i<4;$i++) {
$d =str_split($conf['nmea'][$i][0]);
// print_r($d);
for ($j=0;$j<3;$j++) $data[$index++]=ord($d[$j]);
$d =str_split($conf['nmea'][$i][1]);
// print_r($d);
for ($j=0;$j<29;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
}
// echo "3\n";
/// Set default message
$d =str_split($conf['message']);
for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
// Print the result array as hex data
/*
print_r($conf);
echo "\n"; // / #define IMUCR__DBG_CONF__BITNM 18 // several extra IMU configuration bits
for ($i=0;$i<count($data);$i++) { // / #define IMUCR__DBG_CONF__WIDTH 4 // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
if (($i & 0xf)==0) printf ("\n%04x:",$i); $logger_conf |= (($conf ['extra_conf'] & 0xf) | 0x10) << 18;
printf (" %02x",$data[$i]); // / next bits used by the driver only, not the FPGA
} // / ((SLOW_SPI & 1)<<23) | \
echo "\n"; // / (DFLT_SLAVE_ADDR << 24))
*/ $logger_conf |= ($conf ['slow_spi'] & 0x1) << 23;
$bindata=""; $logger_conf |= ($conf ['imu_sa'] & 0x7) << 24;
for($i=0;$i<count($data);$i++) $bindata.=chr($data[$i]); $data [$index ++] = $logger_conf & 0xff;
$dev_imu_ctl = fopen('/dev/imu_ctl', 'w'); $data [$index ++] = ($logger_conf >> 8) & 0xff;
fwrite($dev_imu_ctl, $bindata, strlen($bindata)); $data [$index ++] = ($logger_conf >> 16) & 0xff;
fseek($dev_imu_ctl,3,SEEK_END); // start IMU $data [$index ++] = ($logger_conf >> 24) & 0xff;
fclose($dev_imu_ctl); // / Set time driver will go to sleep if the data is not ready yet (less than full sample in the buffer)
/// Readback - just testing $data [$index ++] = $conf ['sleep_busy'] & 0xff;
$bd=file_get_contents('/dev/imu_ctl'); $data [$index ++] = ($conf ['sleep_busy'] >> 8) & 0xff;
$data =str_split($bd); $data [$index ++] = ($conf ['sleep_busy'] >> 16) & 0xff;
$data [$index ++] = ($conf ['sleep_busy'] >> 24) & 0xff;
// / Set IMU register addresses to logger
// echo "1\n";
for($i = 0; $i < 28; $i ++)
$data [$index ++] = $conf ['imu_registers'] [$i]; // truncate to 28
// / Configure NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
// echo "2\n";
for($i = 0; $i < 4; $i ++) {
$d = str_split ( $conf ['nmea'] [$i] [0] );
// print_r($d);
for($j = 0; $j < 3; $j ++)
$data [$index ++] = ord ( $d [$j] );
$d = str_split ( $conf ['nmea'] [$i] [1] );
// print_r($d);
for($j = 0; $j < 29; $j ++)
$data [$index ++] = ($j < count ( $d )) ? ord ( $d [$j] ) : 0;
}
// echo "3\n";
// / Set default message
$d = str_split ( $conf ['message'] );
for($j = 0; $j < 56; $j ++)
$data [$index ++] = ($j < count ( $d )) ? ord ( $d [$j] ) : 0;
// Print the result array as hex data
/*
* print_r($conf);
*
* echo "\n";
* for ($i=0;$i<count($data);$i++) {
* if (($i & 0xf)==0) printf ("\n%04x:",$i);
* printf (" %02x",$data[$i]);
* }
* echo "\n";
*/
$bindata = "";
for($i = 0; $i < count ( $data ); $i ++)
$bindata .= chr ( $data [$i] );
$dev_imu_ctl = fopen ( '/dev/imu_ctl', 'w' );
fwrite ( $dev_imu_ctl, $bindata, strlen ( $bindata ) );
fseek ( $dev_imu_ctl, 3, SEEK_END ); // start IMU
fclose ( $dev_imu_ctl );
// / Readback - just testing
$bd = file_get_contents ( '/dev/imu_ctl' );
$data = str_split ( $bd );
if ($verbose) { if ($verbose) {
echo "\n"; echo "\n";
for ($i=0;$i<count($data);$i++) { for($i = 0; $i < count ( $data ); $i ++) {
if (($i & 0xf)==0) printf ("\n%04x:",$i); if (($i & 0xf) == 0)
printf (" %02x",ord($data[$i])); printf ( "\n%04x:", $i );
printf ( " %02x", ord ( $data [$i] ) );
} }
echo "\n"; echo "\n";
} }
} }
function setMessage($msg) { function setMessage($msg) {
global $messageOffset; global $messageOffset;
$data=array(); $data = array ();
$d =str_split($msg); $d = str_split ( $msg );
$index=0; $index = 0;
for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0; for($j = 0; $j < 56; $j ++)
$bindata=""; $data [$index ++] = ($j < count ( $d )) ? ord ( $d [$j] ) : 0;
for($i=0;$i<count($data);$i++) $bindata.=chr($data[$i]); $bindata = "";
$dev_imu_ctl = fopen('/dev/imu_ctl', 'w'); for($i = 0; $i < count ( $data ); $i ++)
fseek($dev_imu_ctl,$messageOffset,SEEK_SET); // start IMU $bindata .= chr ( $data [$i] );
echo ftell($dev_imu_ctl)."<br/>\n"; $dev_imu_ctl = fopen ( '/dev/imu_ctl', 'w' );
fwrite($dev_imu_ctl, $bindata, strlen($bindata)); fseek ( $dev_imu_ctl, $messageOffset, SEEK_SET ); // start IMU
// fseek($dev_imu_ctl,3,SEEK_END); // start IMU echo ftell ( $dev_imu_ctl ) . "<br/>\n";
fclose($dev_imu_ctl); fwrite ( $dev_imu_ctl, $bindata, strlen ( $bindata ) );
var_dump ( $bindata); // fseek($dev_imu_ctl,3,SEEK_END); // start IMU
fclose ( $dev_imu_ctl );
var_dump ( $bindata );
} }
function readSettings($conf = null) {
function readSettings($conf=null) {
global $xclk_freq; // =80000000; // 80 MHz global $xclk_freq; // =80000000; // 80 MHz
$bd=file_get_contents('/dev/imu_ctl'); $bd = file_get_contents ( '/dev/imu_ctl' );
$data =str_split($bd); $data = str_split ( $bd );
for ($i=0;$i<count($data);$i++) $data[$i]=ord($data[$i]); for($i = 0; $i < count ( $data ); $i ++)
/* $data [$i] = ord ( $data [$i] );
// if ($verbose) { /*
echo "\n"; * // if ($verbose) {
for ($i=0;$i<count($data);$i++) { * echo "\n";
if (($i & 0xf)==0) printf ("\n%04x:",$i); * for ($i=0;$i<count($data);$i++) {
printf (" %02x",$data[$i]); * if (($i & 0xf)==0) printf ("\n%04x:",$i);
} * printf (" %02x",$data[$i]);
echo "\n"; * }
// } * echo "\n";
*/ * // }
if ($conf!=null) { */
if ($conf != null) {
/// read current period // / read current period
$conf['imu_period'] =$data[$index++]; $conf ['imu_period'] = $data [$index ++];
$conf['imu_period']|=$data[$index++]<<8; $conf ['imu_period'] |= $data [$index ++] << 8;
$conf['imu_period']|=$data[$index++]<<16; $conf ['imu_period'] |= $data [$index ++] << 16;
$conf['imu_period']|=$data[$index++]<<24; $conf ['imu_period'] |= $data [$index ++] << 24;
/// read current SCLK divisor and SPI stall time // / read current SCLK divisor and SPI stall time
$sclk_div =$data[$index++]; $sclk_div = $data [$index ++];
$stall =$data[$index++]; $stall = $data [$index ++];
$index++; $index ++;
$index++; $index ++;
$conf['sclk_freq']=$xclk_freq/$sclk_div/2; $conf ['sclk_freq'] = $xclk_freq / $sclk_div / 2;
$conf['stall']=$stall * 1000000 / ($xclk_freq / $sclk_div); $conf ['stall'] = $stall * 1000000 / ($xclk_freq / $sclk_div);
/// read current rs232 baud rate // / read current rs232 baud rate
$rs232_div =$data[$index++]; $rs232_div = $data [$index ++];
$rs232_div|=$data[$index++]<<8; $rs232_div |= $data [$index ++] << 8;
$rs232_div|=$data[$index++]<<16; $rs232_div |= $data [$index ++] << 16;
$rs232_div|=$data[$index++]<<24; $rs232_div |= $data [$index ++] << 24;
$conf['baud_rate']=$xclk_freq /2/$rs232_div; $conf ['baud_rate'] = $xclk_freq / 2 / $rs232_div;
/// read current logger configuration (possible to modify only some fields - maybe support it here?) // / read current logger configuration (possible to modify only some fields - maybe support it here?)
/// assuming set bits are set, otherwise it is impossible to find out the old value // / assuming set bits are set, otherwise it is impossible to find out the old value
$logger_conf =$data[$index++]; $logger_conf = $data [$index ++];
$logger_conf|=$data[$index++]<<8; $logger_conf |= $data [$index ++] << 8;
$logger_conf|=$data[$index++]<<16; $logger_conf |= $data [$index ++] << 16;
$logger_conf|=$data[$index++]<<24; $logger_conf |= $data [$index ++] << 24;
/// #define IMUCR__IMU_SLOT__BITNM 0 // slot, where 103695 (imu) board is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11) // / #define IMUCR__IMU_SLOT__BITNM 0 // slot, where 103695 (imu) board is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__IMU_SLOT__WIDTH 2 // / #define IMUCR__IMU_SLOT__WIDTH 2
$conf['imu_slot']= ($logger_conf>>0) & 3; $conf ['imu_slot'] = ($logger_conf >> 0) & 3;
/// #define IMUCR__GPS_CONF__BITNM 3 // slot, where 103695 (imu) bnoard is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11) // / #define IMUCR__GPS_CONF__BITNM 3 // slot, where 103695 (imu) bnoard is connected: 0 - none, 1 - J9, 2 - J10, 3 - J11)
/// #define IMUCR__GPS_CONF__WIDTH 4 // bits 0,1 - slot #, same as for IMU_SLOT, bits 2,3: // / #define IMUCR__GPS_CONF__WIDTH 4 // bits 0,1 - slot #, same as for IMU_SLOT, bits 2,3:
// 0 - ext pulse, leading edge, // 0 - ext pulse, leading edge,
// 1 - ext pulse, trailing edge // 1 - ext pulse, trailing edge
// 2 - start of the first rs232 character after pause // 2 - start of the first rs232 character after pause
// 3 - start of the last "$" character (start of each NMEA sentence) // 3 - start of the last "$" character (start of each NMEA sentence)
// $logger_conf |= ((($conf['gps_slot'] & 0x3) | (($conf['gps_mode'] & 0x3)<<2) ) | 0x10 )<< 3; // $logger_conf |= ((($conf['gps_slot'] & 0x3) | (($conf['gps_mode'] & 0x3)<<2) ) | 0x10 )<< 3;
$conf['gps_slot']= ($logger_conf >> 3) & 3; $conf ['gps_slot'] = ($logger_conf >> 3) & 3;
$conf['gps_mode']= ($logger_conf >> 5) & 3; $conf ['gps_mode'] = ($logger_conf >> 5) & 3;
/// #define IMUCR__MSG_CONF__BITNM 8 // source of external pulses to log: // / #define IMUCR__MSG_CONF__BITNM 8 // source of external pulses to log:
/// #define IMUCR__MSG_CONF__WIDTH 5 // bits 0-3 - number of fpga GPIO input 0..11 (i.e. 0x0a - external optoisolated sync input (J15) // / #define IMUCR__MSG_CONF__WIDTH 5 // bits 0-3 - number of fpga GPIO input 0..11 (i.e. 0x0a - external optoisolated sync input (J15)
// 0x0f - disable MSG module // 0x0f - disable MSG module
// bit 4 - invert polarity: 0 - timestamp leading edge, log at trailing edge, 1 - opposite // bit 4 - invert polarity: 0 - timestamp leading edge, log at trailing edge, 1 - opposite
// software may set (up to 56 bytes) log message before trailing end of the pulse // software may set (up to 56 bytes) log message before trailing end of the pulse
// $logger_conf |= (($conf['msg_conf'] & 0x1f) | 0x20 )<< 8; // $logger_conf |= (($conf['msg_conf'] & 0x1f) | 0x20 )<< 8;
$conf['msg_conf']= ($logger_conf >> 8) & 0x1f; $conf ['msg_conf'] = ($logger_conf >> 8) & 0x1f;
/// #define IMUCR__SYN_CONF__BITNM 14 // logging frame time stamps (may be synchronized by another camera and have timestamp of that camera) // / #define IMUCR__SYN_CONF__BITNM 14 // logging frame time stamps (may be synchronized by another camera and have timestamp of that camera)
/// #define IMUCR__SYN_CONF__WIDTH 1 // 0 - disable, 1 - enable // / #define IMUCR__SYN_CONF__WIDTH 1 // 0 - disable, 1 - enable
// $logger_conf |= (($conf['img_sync'] & 0x1) | 0x2 )<< 14; // $logger_conf |= (($conf['img_sync'] & 0x1) | 0x2 )<< 14;
$conf['img_sync']= ($logger_conf >> 14) & 0x1; $conf ['img_sync'] = ($logger_conf >> 14) & 0x1;
/// #define IMUCR__RST_CONF__BITNM 16 // reset module // / #define IMUCR__RST_CONF__BITNM 16 // reset module
/// #define IMUCR__RST_CONF__WIDTH 1 // 0 - enable, 1 -reset (needs resettimng DMA address in ETRAX also) // / #define IMUCR__RST_CONF__WIDTH 1 // 0 - enable, 1 -reset (needs resettimng DMA address in ETRAX also)
/// #define IMUCR__DBG_CONF__BITNM 18 // several extra IMU configuration bits // / #define IMUCR__DBG_CONF__BITNM 18 // several extra IMU configuration bits
/// #define IMUCR__DBG_CONF__WIDTH 4 // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A" // / #define IMUCR__DBG_CONF__WIDTH 4 // 0 - config_long_sda_en, 1 -config_late_clk, 2 - config_single_wire, should be set for 103695 rev "A"
// $logger_conf |= (($conf['extra_conf'] & 0xf) | 0x10 )<< 18; // $logger_conf |= (($conf['extra_conf'] & 0xf) | 0x10 )<< 18;
$conf['extra_conf']= ($logger_conf >> 18) & 0xf; $conf ['extra_conf'] = ($logger_conf >> 18) & 0xf;
/// next bits used by the driver only, not the FPGA // / next bits used by the driver only, not the FPGA
/// ((SLOW_SPI & 1)<<23) | \ // / ((SLOW_SPI & 1)<<23) | \
/// (DFLT_SLAVE_ADDR << 24)) // / (DFLT_SLAVE_ADDR << 24))
// $logger_conf |= ($conf['slow_spi'] & 0x1)<< 23; // $logger_conf |= ($conf['slow_spi'] & 0x1)<< 23;
// $logger_conf |= ($conf['imu_sa'] & 0x7)<< 24; // $logger_conf |= ($conf['imu_sa'] & 0x7)<< 24;
$conf['slow_spi']= ($logger_conf >> 23) & 0x1; $conf ['slow_spi'] = ($logger_conf >> 23) & 0x1;
$conf['imu_sa']= ($logger_conf >> 24) & 0x7; $conf ['imu_sa'] = ($logger_conf >> 24) & 0x7;
/// read current time driver will go to sleep if the data is not ready yet (less than full sample in the buffer) // / read current time driver will go to sleep if the data is not ready yet (less than full sample in the buffer)
$conf['sleep_busy'] =$data[$index++]; $conf ['sleep_busy'] = $data [$index ++];
$conf['sleep_busy']|=$data[$index++]<<8; $conf ['sleep_busy'] |= $data [$index ++] << 8;
$conf['sleep_busy']|=$data[$index++]<<16; $conf ['sleep_busy'] |= $data [$index ++] << 16;
$conf['sleep_busy']|=$data[$index++]<<24; $conf ['sleep_busy'] |= $data [$index ++] << 24;
// / read current IMU register addresses to logger
/// read current IMU register addresses to logger // echo "1\n";
// echo "1\n"; // for ($i=0;$i<28;$i++) $data[$index++]= $conf['imu_registers'][$i]; // truncate to 28
// for ($i=0;$i<28;$i++) $data[$index++]= $conf['imu_registers'][$i]; // truncate to 28 for($i = 0; $i < 28; $i ++)
for ($i=0;$i<28;$i++) $conf['imu_registers'][$i]=$data[$index++]; $conf ['imu_registers'] [$i] = $data [$index ++];
/// read current NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults // / read current NMEA sentences to log. If there are less than 4 - copy additional (unique) from defaults
// echo "2\n"; // echo "2\n";
$conf['nmea']=array(array("",""),array("",""),array("",""),array("","")); $conf ['nmea'] = array (
for ($i=0;$i<count($conf['nmea']);$i++) { array (
// $d =str_split($conf['nmea'][$i][0]); "",
// for ($j=0;$j<3;$j++) $data[$index++]=ord($d[$j]); ""
for ($j=0;$j<3;$j++) $conf['nmea'][$i][0].=chr($data[$index++]); ),
// $d =str_split($conf['nmea'][$i][1]); array (
// for ($j=0;$j<29;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0; "",
for ($j=0;$j<29;$j++) { ""
$d=$data[$index++]; ),
if ($d!=0) $conf['nmea'][$i][1].=chr($d); array (
"",
""
),
array (
"",
""
)
);
for($i = 0; $i < count ( $conf ['nmea'] ); $i ++) {
// $d =str_split($conf['nmea'][$i][0]);
// for ($j=0;$j<3;$j++) $data[$index++]=ord($d[$j]);
for($j = 0; $j < 3; $j ++)
$conf ['nmea'] [$i] [0] .= chr ( $data [$index ++] );
// $d =str_split($conf['nmea'][$i][1]);
// for ($j=0;$j<29;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
for($j = 0; $j < 29; $j ++) {
$d = $data [$index ++];
if ($d != 0)
$conf ['nmea'] [$i] [1] .= chr ( $d );
else { else {
$index+=(29-1-$j); $index += (29 - 1 - $j);
break; break;
} }
} }
} }
/// read current message // / read current message
// $conf['message_offset']=$index; // $conf['message_offset']=$index;
// $d =str_split($conf['message']); // $d =str_split($conf['message']);
// for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0; // for ($j=0;$j<56;$j++) $data[$index++]=($j<count($d))?ord($d[$j]):0;
$conf['message']=""; $conf ['message'] = "";
for ($j=0;$j<56;$j++) { for($j = 0; $j < 56; $j ++) {
$d=$data[$index++]; $d = $data [$index ++];
if ($d!=0) $conf['message'].=chr($d); if ($d != 0)
$conf ['message'] .= chr ( $d );
else { else {
$index+=(56-1-$j); $index += (56 - 1 - $j);
break; break;
} }
} }
// var_dump ($conf); // var_dump ($conf);
return $conf; return $conf;
} }
} }
......
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
/* /*
*! FILE NAME : start_gps_compass.php * ! FILE NAME : start_gps_compass.php
*! DESCRIPTION: Looks for USB GPS (currently Garmin GPS 18 USB) and compass * ! DESCRIPTION: Looks for USB GPS (currently Garmin GPS 18 USB) and compass
*! (currently Ocean Server OS-5000), re-initializes Exif header * ! (currently Ocean Server OS-5000), re-initializes Exif header
*! and starts the devices if found * ! and starts the devices if found
*! * !
*! Copyright (C) 2008 Elphel, Inc * ! Copyright (C) 2008 Elphel, Inc
*! -----------------------------------------------------------------------------** * ! -----------------------------------------------------------------------------**
*! * !
*! This program is free software: you can redistribute it and/or modify * ! This program is free software: you can redistribute it and/or modify
*! it under the terms of the GNU General Public License as published by * ! it under the terms of the GNU General Public License as published by
*! the Free Software Foundation, either version 3 of the License, or * ! the Free Software Foundation, either version 3 of the License, or
*! (at your option) any later version. * ! (at your option) any later version.
*! * !
*! This program is distributed in the hope that it will be useful, * ! This program is distributed in the hope that it will be useful,
*! but WITHOUT ANY WARRANTY; without even the implied warranty of * ! but WITHOUT ANY WARRANTY; without even the implied warranty of
*! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*! GNU General Public License for more details. * ! GNU General Public License for more details.
*! * !
*! You should have received a copy of the GNU General Public License * ! You should have received a copy of the GNU General Public License
*! along with this program. If not, see <http://www.gnu.org/licenses/>. * ! along with this program. If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------** * ! -----------------------------------------------------------------------------**
*! $Log: start_gps_compass.php,v $ * ! $Log: start_gps_compass.php,v $
*! Revision 1.6 2012/03/14 00:05:41 elphel * ! Revision 1.6 2012/03/14 00:05:41 elphel
*! 8.2.1 - GPS speed, x353.bit file tested on Eyesis * ! 8.2.1 - GPS speed, x353.bit file tested on Eyesis
*! * !
*! Revision 1.5 2011/08/13 00:55:14 elphel * ! Revision 1.5 2011/08/13 00:55:14 elphel
*! support for detection 103595 and 103696 boards, programming the logger * ! support for detection 103595 and 103696 boards, programming the logger
*! * !
*! Revision 1.4 2011/01/15 23:22:10 elphel * ! Revision 1.4 2011/01/15 23:22:10 elphel
*! added 19200 * ! added 19200
*! * !
*! Revision 1.3 2009/02/20 21:49:52 elphel * ! Revision 1.3 2009/02/20 21:49:52 elphel
*! bugfix - was killing daemons after detection, not before (as should) * ! bugfix - was killing daemons after detection, not before (as should)
*! * !
*! Revision 1.2 2009/02/19 22:38:37 elphel * ! Revision 1.2 2009/02/19 22:38:37 elphel
*! 8.0.2.3 - added several USB serial adapters, nmea->exif support, detection of NMEA GPS at boot * ! 8.0.2.3 - added several USB serial adapters, nmea->exif support, detection of NMEA GPS at boot
*! * !
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel * ! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*! * !
*! * !
*! Revision 1.2 2008/11/20 07:03:40 elphel * ! Revision 1.2 2008/11/20 07:03:40 elphel
*! exit value now encodes detected devices * ! exit value now encodes detected devices
*! * !
*! Revision 1.1 2008/04/07 09:14:47 elphel * ! Revision 1.1 2008/04/07 09:14:47 elphel
*! Discover/startup GPS and compass * ! Discover/startup GPS and compass
*! * !
*/ */
//look uptime, sleep if just started (no USB yet) // look uptime, sleep if just started (no USB yet)
//require '/usr/html/includes/i2c.inc'; // require '/usr/html/includes/i2c.inc';
#require 'i2c.inc'; // require 'i2c.inc';
set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' ); set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
require 'i2c_include.php'; require 'i2c_include.php';
$config_name = '/etc/elphel393/imu_logger.xml'; $config_name = '/etc/elphel393/imu_logger.xml';
...@@ -64,6 +64,7 @@ $b_index = indexGrandDaughters ( $ids ); ...@@ -64,6 +64,7 @@ $b_index = indexGrandDaughters ( $ids );
// print_r($ids); // print_r($ids);
// print_r($b_index); // print_r($b_index);
$baud = null; $baud = null;
$binfile = "/var/imu_config.bin"; // comment out if not needed - debug feature
if (isset ( $b_index [103696] )) { if (isset ( $b_index [103696] )) {
$baud = $ids [$b_index [103696]] ['baud']; $baud = $ids [$b_index [103696]] ['baud'];
if ($baud === 0) if ($baud === 0)
...@@ -151,11 +152,15 @@ if (isset ( $logger_config )) { ...@@ -151,11 +152,15 @@ if (isset ( $logger_config )) {
$noGPS = ($compass || $GPS) ? "" : "noGPS"; $noGPS = ($compass || $GPS) ? "" : "noGPS";
$nocompass = ($compass) ? "" : "nocompass"; $nocompass = ($compass) ? "" : "nocompass";
// Just debugging: // Just debugging:
//$nocompass = ""; $nocompass = "";
/*
* Actually there is a problem - when compass is disabled, imgsrv incorrectly decodes meta (image number, sensor number)
* Even if re-srated after running exif.php
*/
$cmd = $exif_php." init $noGPS $nocompass"; $cmd = $exif_php . " init $noGPS $nocompass";
if ($verbose) if ($verbose)
echo "Initializing Exif template: $cmd\n"; echo "Initializing Exif template: $cmd\n";
exec ( $cmd ); exec ( $cmd );
...@@ -163,9 +168,9 @@ if ($GPS) { ...@@ -163,9 +168,9 @@ if ($GPS) {
if ($verbose) if ($verbose)
echo "Starting " . $GPS ["name"] . " as " . $GPS ["file"] . "\n"; echo "Starting " . $GPS ["name"] . " as " . $GPS ["file"] . "\n";
if (strpos ( $GPS ['name'], 'NMEA' ) !== false) { if (strpos ( $GPS ['name'], 'NMEA' ) !== false) {
$cmd = $bindir."nmea2exif " . $GPS ["file"] . " &"; $cmd = $bindir . "nmea2exif " . $GPS ["file"] . " &";
} else { } else {
$cmd = $bindir."garminusb2exif " . $GPS ["file"] . " &"; // BUG: Not ported! $cmd = $bindir . "garminusb2exif " . $GPS ["file"] . " &"; // BUG: Not ported!
} }
if ($verbose) if ($verbose)
echo "exec: $cmd \n"; echo "exec: $cmd \n";
...@@ -175,7 +180,7 @@ if ($compass) { ...@@ -175,7 +180,7 @@ if ($compass) {
if ($verbose) if ($verbose)
echo "Starting " . $compass ["name"] . " as " . $compass ["file"] . "\n"; echo "Starting " . $compass ["name"] . " as " . $compass ["file"] . "\n";
exec ( "stty -F " . $compass ["file"] . " -echo speed 19200" ); exec ( "stty -F " . $compass ["file"] . " -echo speed 19200" );
$cmd = $bindir."compass " . $compass ["file"] . " &"; $cmd = $bindir . "compass " . $compass ["file"] . " &";
if ($verbose) if ($verbose)
echo "exec: $cmd \n"; echo "exec: $cmd \n";
popen ( $cmd, "r" ); popen ( $cmd, "r" );
...@@ -468,8 +473,7 @@ function init_default_config() { ...@@ -468,8 +473,7 @@ function init_default_config() {
0x70, // time m/s 0x70, // time m/s
0x72, // time d/h 0x72, // time d/h
0x74 0x74
) // time y/m ), // time y/m
,
'nmea' => array ( 'nmea' => array (
// / first three letters - sentence to log (letters after "$GP"). next "n"/"b" (up to 24 total) - "n" number (will be encoded 4 digits/byte, follwed by "0xF" // / first three letters - sentence to log (letters after "$GP"). next "n"/"b" (up to 24 total) - "n" number (will be encoded 4 digits/byte, follwed by "0xF"
// / "b" - byte - all but last will have MSB 0 (& 0x7f), the last one - with MSB set (| 0x80). If there are no characters in the field 0xff will be output // / "b" - byte - all but last will have MSB 0 (& 0x7f), the last one - with MSB set (| 0x80). If there are no characters in the field 0xff will be output
...@@ -491,8 +495,8 @@ function init_default_config() { ...@@ -491,8 +495,8 @@ function init_default_config() {
) )
), ),
'message' => 'Odometer message' 'message' => 'Odometer message'
) // Message - up to 56 bytes ); // Message - up to 56 bytes
;
return $default_config; return $default_config;
} }
/** /**
...@@ -539,7 +543,7 @@ function combineLoggerConfigs($new_conf, $dflt = null) { ...@@ -539,7 +543,7 @@ function combineLoggerConfigs($new_conf, $dflt = null) {
return $conf; return $conf;
} }
function setup_IMU_logger($conf) { function setup_IMU_logger($conf) {
global $verbose; global $verbose, $binfile;
// $xclk_freq=80000000; // 80 MHz in NC353 // $xclk_freq=80000000; // 80 MHz in NC353
$xclk_freq = 100000000; // 100 MHz in NC393 $xclk_freq = 100000000; // 100 MHz in NC393
$data = array (); $data = array ();
...@@ -610,12 +614,12 @@ function setup_IMU_logger($conf) { ...@@ -610,12 +614,12 @@ function setup_IMU_logger($conf) {
// / (DFLT_SLAVE_ADDR << 24)) // / (DFLT_SLAVE_ADDR << 24))
$logger_conf |= ($conf ['slow_spi'] & 0x1) << 23; $logger_conf |= ($conf ['slow_spi'] & 0x1) << 23;
$logger_conf |= ($conf ['imu_sa'] & 0x7) << 24; $logger_conf |= ($conf ['imu_sa'] & 0x7) << 24;
$data [$index ++] = $logger_conf & 0xff; $data [$index ++] = $logger_conf & 0xff; // DWORD 0x03
$data [$index ++] = ($logger_conf >> 8) & 0xff; $data [$index ++] = ($logger_conf >> 8) & 0xff;
$data [$index ++] = ($logger_conf >> 16) & 0xff; $data [$index ++] = ($logger_conf >> 16) & 0xff;
$data [$index ++] = ($logger_conf >> 24) & 0xff; $data [$index ++] = ($logger_conf >> 24) & 0xff;
// / Set time driver will go to sleep if the data is not ready yet (less than full sample in the buffer) // / Set time driver will go to sleep if the data is not ready yet (less than full sample in the buffer)
$data [$index ++] = $conf ['sleep_busy'] & 0xff; $data [$index ++] = $conf ['sleep_busy'] & 0xff; // DWORD 0x04 (software only)
$data [$index ++] = ($conf ['sleep_busy'] >> 8) & 0xff; $data [$index ++] = ($conf ['sleep_busy'] >> 8) & 0xff;
$data [$index ++] = ($conf ['sleep_busy'] >> 16) & 0xff; $data [$index ++] = ($conf ['sleep_busy'] >> 16) & 0xff;
$data [$index ++] = ($conf ['sleep_busy'] >> 24) & 0xff; $data [$index ++] = ($conf ['sleep_busy'] >> 24) & 0xff;
...@@ -660,6 +664,13 @@ function setup_IMU_logger($conf) { ...@@ -660,6 +664,13 @@ function setup_IMU_logger($conf) {
fwrite ( $dev_imu_ctl, $bindata, strlen ( $bindata ) ); fwrite ( $dev_imu_ctl, $bindata, strlen ( $bindata ) );
fseek ( $dev_imu_ctl, 3, SEEK_END ); // start IMU fseek ( $dev_imu_ctl, 3, SEEK_END ); // start IMU
fclose ( $dev_imu_ctl ); fclose ( $dev_imu_ctl );
if (isset($binfile)){
$dev_imu_ctl = fopen ( $binfile, 'w' );
fwrite ( $dev_imu_ctl, $bindata, strlen ( $bindata ) );
fclose ( $dev_imu_ctl );
}
// / Readback - just testing // / Readback - just testing
$bd = file_get_contents ( '/dev/imu_ctl' ); $bd = file_get_contents ( '/dev/imu_ctl' );
$data = str_split ( $bd ); $data = str_split ( $bd );
...@@ -674,11 +685,7 @@ function setup_IMU_logger($conf) { ...@@ -674,11 +685,7 @@ function setup_IMU_logger($conf) {
} }
} }
// ls /sys/bus/usb-serial/devices/ttyUSB0/driver -l
//ls /sys/bus/usb-serial/devices/ttyUSB0/driver -l
// $xml->addChild ('error','No sync capable board detected, use "role=self" for the onboard timer'); // $xml->addChild ('error','No sync capable board detected, use "role=self" for the onboard timer');
// $sxml=$xml->asXML(); // $sxml=$xml->asXML();
?> ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment