Commit ed26a679 authored by Andrey Filippov's avatar Andrey Filippov

working on event logger

parent 14632e65
This diff is collapsed.
#!/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