Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elphel-apps-gps
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
elphel-apps-gps
Commits
2be574ef
Commit
2be574ef
authored
Jul 08, 2023
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating to match camogm behavior
parent
4a35837c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
246 additions
and
42 deletions
+246
-42
logger_launcher.php
src/logger_launcher.php
+246
-42
No files found.
src/logger_launcher.php
View file @
2be574ef
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
/*!***************************************************************************
/*!***************************************************************************
*! FILE NAME : logger_launcher.php
*! FILE NAME : logger_launcher.php
*! DESCRIPTION: launches the event logger (IMU/GPS/External trigger/Other sensor) a dies
*! DESCRIPTION: launches the event logger (IMU/GPS/External trigger/Other sensor) a dies
*! Copyright (C) 2012 Elphel, Inc
*! Copyright (C) 2012
-2023
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
...
@@ -37,23 +37,59 @@
...
@@ -37,23 +37,59 @@
*!
*!
*!
*!
*/
*/
define
(
'SUFFIX_LEN'
,
5
);
// file suffix length
define
(
'LOGGER_CONF'
,
'/etc/elphel393/imu_logger.xml'
);
define
(
'BIN_NAME'
,
'log_imu'
);
define
(
'DEFAULT_MNT'
,
'/mnt/sda1'
);
define
(
'DEFAULT_DIR'
,
'test00'
);
define
(
'DEFAULT_FILE'
,
'log_file'
);
define
(
'DEFAULT_FLEN'
,
5000000
);
// 5 M records, 64 bytes each (total 320MB)
define
(
'LOGGER_MNT'
,
'logger_mnt'
);
define
(
'LOGGER_DIR'
,
'logger_dir'
);
define
(
'LOGGER_FILE'
,
'logger_file'
);
define
(
'LOGGER_FLEN'
,
'logger_flen'
);
include
'include/show_source_include.php'
;
set_include_path
(
get_include_path
()
.
PATH_SEPARATOR
.
'/www/pages/include'
);
include
'show_source_include.php'
;
include
"elphel_functions_include.php"
;
// includes curl functions
//default parameters
//default parameters
$cmd
=
"start"
;
//
$cmd = "start";
$file
=
"/mnt/sda1/imu_log.log"
;
//
$file = "/mnt/sda1/imu_log.log";
$index
=
1
;
//
$index = 1;
$n
=
5000000
;
//
$n = 5000000;
$mount_point
=
"/mnt/sda1"
;
//
$mount_point = "/mnt/sda1";
$force_dev
=
false
;
$force_dev
=
false
;
$xml
=
new
SimpleXMLElement
(
"<?xml version='1.0' standalone='yes'?><Document/>"
);
if
(
file_exists
(
LOGGER_CONF
))
{
$config_xml
=
simplexml_load_file
(
LOGGER_CONF
);
$logger_config
=
loggerConfigFromXML
(
$config_xml
);
/*
echo "<pre>";
var_dump($logger_config);
echo "</pre>";
exit (0);
*/
}
else
{
$xml
->
addChild
(
'error'
,
'no config'
);
$xml
->
addChild
(
'description'
,
'Configuarion file '
.
LOGGER_CONF
.
' does not exist. It is created by /usr/bin/start_ims.php'
);
send_response
(
$xml
);
exit
(
1
);
}
if
(
!
isset
(
$logger_config
[
LOGGER_MNT
]))
$logger_config
[
LOGGER_MNT
]
=
DEFAULT_MNT
;
if
(
!
isset
(
$logger_config
[
LOGGER_DIR
]))
$logger_config
[
LOGGER_DIR
]
=
DEFAULT_DIR
;
if
(
!
isset
(
$logger_config
[
LOGGER_FILE
]))
$logger_config
[
LOGGER_FILE
]
=
DEFAULT_FILE
;
if
(
!
isset
(
$logger_config
[
LOGGER_FLEN
]))
$logger_config
[
LOGGER_FLEN
]
=
DEFAULT_FLEN
;
$xml
=
"<Document>
\n
"
;
if
(
isset
(
$_GET
[
LOGGER_MNT
]))
$logger_config
[
LOGGER_MNT
]
=
$_GET
[
LOGGER_MNT
];
if
(
isset
(
$_GET
[
LOGGER_DIR
]))
$logger_config
[
LOGGER_DIR
]
=
$_GET
[
LOGGER_DIR
];
if
(
isset
(
$_GET
[
LOGGER_FILE
]))
$logger_config
[
LOGGER_FILE
]
=
$_GET
[
LOGGER_FILE
];
if
(
isset
(
$_GET
[
LOGGER_FLEN
]))
$logger_config
[
LOGGER_FLEN
]
=
$_GET
[
LOGGER_FLEN
];
//get parameters
//get parameters
if
(
isset
(
$_GET
[
'cmd'
]))
$cmd
=
$_GET
[
'cmd'
];
if
(
isset
(
$_GET
[
'cmd'
]))
$cmd
=
$_GET
[
'cmd'
];
/*
if (isset($_GET['file'])) $file = $_GET['file'];
if (isset($_GET['file'])) $file = $_GET['file'];
if (isset($_GET['index'])) $index = $_GET['index'];
if (isset($_GET['index'])) $index = $_GET['index'];
if (isset($_GET['n'])) $n = $_GET['n'];
if (isset($_GET['n'])) $n = $_GET['n'];
...
@@ -63,54 +99,153 @@ if (isset($_GET['dev'])) {
...
@@ -63,54 +99,153 @@ if (isset($_GET['dev'])) {
$dev = $_GET['dev'];
$dev = $_GET['dev'];
$force_dev = true;
$force_dev = true;
}
}
*/
if
(
$cmd
==
"start"
)
{
switch
(
$cmd
)
{
case
'readconf'
:
if
(
!
is_dir
(
$mount_point
))
mkdir
(
$mount_point
);
$xml
=
loggerConfigToXML
(
$logger_config
);
break
;
//detect devices
case
'writeconf'
:
//$dev = "/dev/hda1";
$xml
=
loggerConfigToXML
(
$logger_config
);
$conf_file
=
fopen
(
LOGGER_CONF
,
"w"
);
if
(
!
$force_dev
)
{
fwrite
(
$conf_file
,
$xml
->
asXML
()
);
$sda1
=
exec
(
"cat /proc/diskstats | grep 'sda1'"
);
fclose
(
$conf_file
);
break
;
if
(
strlen
(
$sda1
)
>
0
)
$dev
=
"/dev/sda1"
;
case
'stop'
:
else
{
$proc
=
getPIDByName
(
'log_imu'
);
$xml
.=
"
\t
<error>CF cards not found</error>
\n
"
;
$was_running
=
count
(
$proc
)
>
0
;
$xml
->
addChild
(
'prev_state'
,
$was_running
?
'RUNNING'
:
'STOPPED'
);
if
(
$was_running
){
exec
(
"killall -1 "
.
BIN_NAME
);
}
// unmount
// exec("umount $mount_point");
exec
(
"sync"
);
add_state_to_xml
(
$xml
);
break
;
case
'start'
:
$proc
=
getPIDByName
(
'log_imu'
);
$was_running
=
count
(
$proc
)
>
0
;
$xml
->
addChild
(
'prev_state'
,
$was_running
?
'RUNNING'
:
'STOPPED'
);
if
(
$was_running
)
{
$xml
->
addChild
(
'error'
,
'was running'
);
add_state_to_xml
(
$xml
);
send_response
(
$xml
);
break
;
}
$dir_path
=
$logger_config
[
LOGGER_MNT
];
if
(
$logger_config
[
LOGGER_DIR
])
{
$dir_path
.=
'/'
.
$logger_config
[
LOGGER_DIR
];
}
$pref_path
=
$dir_path
.
'/'
.
$logger_config
[
LOGGER_FILE
];
$xml
->
addChild
(
'dir_path'
,
$dir_path
);
$xml
->
addChild
(
'pref_path'
,
$pref_path
);
$indx
=
get_next_index
(
$dir_path
,
$logger_config
[
LOGGER_FILE
]);
if
(
$indx
==
-
1
){
// create directory recursive if it does not exist
$xml
->
addChild
(
'mkdir'
,
$dir_path
);
if
(
!
mkdir
(
$dir_path
,
0777
,
true
)){
$xml
->
addChild
(
'error'
,
'mkdir error'
);
send_response
(
$xml
);
send_response
(
$xml
);
exit
(
0
);
}
$indx
=
get_next_index
(
$dir_path
,
$logger_config
[
LOGGER_FILE
]);
}
if
(
$indx
==
-
1
)
{
$xml
->
addChild
(
'error'
,
'write dir does not exist'
);
break
;
}
}
if
(
$indx
==
-
2
)
{
$xml
->
addChild
(
'error'
,
'write dir is not a directory'
);
break
;
}
}
$exe
=
'/usr/bin/'
.
BIN_NAME
;
$flen
=
$logger_config
[
LOGGER_FLEN
];
exec
(
"
$exe
$pref_path
$indx
$flen
>/dev/null 2>&1 &"
);
add_state_to_xml
(
$xml
);
break
;
exec
(
"mount
$dev
$mount_point
"
);
case
'state'
:
exec
(
"/usr/bin/log_imu
$file
$index
$n
>/dev/null 2>&1 &"
);
add_state_to_xml
(
$xml
);
$xml
.=
"
\t
<result>ok</result>
\n
"
;
break
;
case
'next_index'
:
$dir_path
=
$logger_config
[
LOGGER_MNT
];
if
(
$logger_config
[
LOGGER_DIR
])
{
$dir_path
.=
'/'
.
$logger_config
[
LOGGER_DIR
];
}
$xml
->
addChild
(
'dir_path'
,
$dir_path
);
$xml
->
addChild
(
'pref_path'
,
$dir_path
.
'/'
.
$logger_config
[
LOGGER_FILE
]);
$indx
=
get_next_index
(
$dir_path
,
$logger_config
[
LOGGER_FILE
]);
switch
(
$indx
)
{
case
-
1
:
$xml
->
addChild
(
'error'
,
'write dir does not exist'
);
break
;
case
-
2
:
$xml
->
addChild
(
'error'
,
'write dir is not a directory'
);
break
;
default
:
$xml
->
addChild
(
'next_index'
,
$indx
);
}
break
;
}
}
send_response
(
$xml
);
exit
(
0
);
if
(
$cmd
==
"stop"
)
{
function
add_state_to_xml
(
&
$xml
){
$proc
=
getPIDByName
(
'log_imu'
);
exec
(
"killall -1 log_imu"
);
if
(
count
(
$proc
))
{
//unmount
$xml
->
addChild
(
'state'
,
'RUNNING'
);
//exec("umount $mount_point");
if
(
count
(
$proc
[
0
][
'argv'
])
>
1
){
exec
(
"sync"
);
$xml
->
addChild
(
'outfile'
,
$proc
[
0
][
'argv'
][
1
]);
$xml
.=
"
\t
<result>ok</result>
\n
"
;
if
(
count
(
$proc
[
0
][
'argv'
])
>
2
){
$xml
->
addChild
(
'start_index'
,
$proc
[
0
][
'argv'
][
2
]);
if
(
count
(
$proc
[
0
][
'argv'
])
>
3
){
$xml
->
addChild
(
'num_records'
,
$proc
[
0
][
'argv'
][
3
]);
if
(
count
(
$proc
[
0
][
'argv'
])
>
4
){
$xml
->
addChild
(
'rewind_by'
,
$proc
[
0
][
'argv'
][
4
]);
}
}
}
}
}
else
{
$xml
->
addChild
(
'state'
,
'STOPPED'
);
}
}
}
function
get_next_index
(
$dir_path
,
$logger_file
)
{
$xml
.=
"</Document>"
;
if
(
!
file_exists
(
$dir_path
))
{
return
-
1
;
send_response
(
$xml
);
}
else
if
(
!
is_dir
(
$dir_path
))
{
return
-
2
;
}
$indx
=
-
1
;
$dirlist
=
scandir
(
$dir_path
,
SCANDIR_SORT_ASCENDING
);
$prefix_len
=
strlen
(
$logger_file
);
$entry_len
=
$prefix_len
+
1
+
SUFFIX_LEN
;
foreach
(
$dirlist
as
$logfile
)
{
if
(
strlen
(
$logfile
)
==
$entry_len
)
{
if
(
strncmp
(
$logger_file
,
$logfile
,
$prefix_len
)
===
0
){
$i
=
intval
(
substr
(
$logfile
,
-
SUFFIX_LEN
));
if
(
$i
>
$indx
){
$indx
=
$i
;
}
}
}
}
return
$indx
+
1
;
}
function
send_response
(
$xml
){
function
send_response
(
$xml
){
$rslt
=
$xml
->
asXML
();
header
(
"Content-Type: text/xml"
);
header
(
"Content-Type: text/xml"
);
header
(
"Content-Length: "
.
strlen
(
$
xml
)
.
"
\n
"
);
header
(
"Content-Length: "
.
strlen
(
$
rslt
)
.
"
\n
"
);
header
(
"Pragma: no-cache
\n
"
);
header
(
"Pragma: no-cache
\n
"
);
printf
(
"%s"
,
$xml
);
printf
(
$rslt
);
flush
();
flush
();
}
}
function
_help
(){
function
_help
(){
echo
"<pre>
\n
"
;
echo
"<pre>
\n
"
;
echo
"Usage example: 'http://192.168.0.9/logger_launcher.php?file=/mnt/sda1/test.log&index=1&n=1000000&dev=/dev/sda1', where
\n
"
;
echo
"Usage example
(OBSOLETE)
: 'http://192.168.0.9/logger_launcher.php?file=/mnt/sda1/test.log&index=1&n=1000000&dev=/dev/sda1', where
\n
"
;
echo
"'file'- log name (includes absolute path), '/usr/html/CF/' is the 'dev's mount point
\n
"
;
echo
"'file'- log name (includes absolute path), '/usr/html/CF/' is the 'dev's mount point
\n
"
;
echo
"'index'- index added to the log name
\n
"
;
echo
"'index'- index added to the log name
\n
"
;
echo
"'n'- max number of records in a single log file
\n
"
;
echo
"'n'- max number of records in a single log file
\n
"
;
...
@@ -120,5 +255,74 @@ function _help(){
...
@@ -120,5 +255,74 @@ function _help(){
function
_usage
(){
function
_usage
(){
_help
();
_help
();
}
}
function
loggerConfigFromXML
(
$confXML
)
{
$conf
=
array
();
// var_dump($confXML);
foreach
(
$confXML
as
$item
)
{
// var_dump($item);
$key
=
$item
->
getName
();
switch
(
$key
)
{
case
'imu_registers'
:
$conf
[
$key
]
=
array
();
foreach
(
$item
as
$reg
)
{
$rname
=
substr
(
$reg
->
getName
(),
2
);
$conf
[
$key
]
[
$rname
+
0
]
=
((
string
)
$reg
)
+
0
;
}
break
;
case
'nmea'
:
$conf
[
$key
]
=
array
();
foreach
(
$item
as
$reg
)
{
$rname
=
substr
(
$reg
->
getName
(),
2
);
$conf
[
$key
]
[
$rname
+
0
]
=
array
(
(
string
)
$reg
->
sentence
,
(
string
)
$reg
->
format
);
}
break
;
case
'imu_period'
:
$conf
[
$key
]
=
(
string
)
$item
;
if
(
$conf
[
$key
]
!=
'auto'
)
$conf
[
$key
]
+=
0
;
break
;
case
'message'
:
case
'logger_mnt'
:
case
'logger_dir'
:
case
'logger_file'
:
$conf
[
$key
]
=
(
string
)
$item
;
break
;
default
:
// $conf[$key]=(int) $item;
$conf
[
$key
]
=
((
string
)
$item
)
+
0
;
}
}
return
$conf
;
}
function
loggerConfigToXML
(
$conf
)
{
$logger_xml
=
new
SimpleXMLElement
(
"<?xml version='1.0' standalone='yes'?><Logger_configuration/>"
);
foreach
(
$conf
as
$key
=>
$value
)
{
switch
(
$key
)
{
case
'imu_registers'
:
$subtree
=
$logger_xml
->
addChild
(
$key
);
for
(
$i
=
0
;
$i
<
count
(
$value
);
$i
++
)
{
$subtree
->
addChild
(
'R_'
.
sprintf
(
'%02d'
,
$i
),
sprintf
(
"0x%02x"
,
$value
[
$i
]
)
);
}
break
;
case
'nmea'
:
$subtree
=
$logger_xml
->
addChild
(
$key
);
for
(
$i
=
0
;
$i
<
count
(
$value
);
$i
++
)
{
$sentence
=
$subtree
->
addChild
(
'S_'
.
sprintf
(
'%01d'
,
$i
)
);
$sentence
->
addChild
(
'sentence'
,
$value
[
$i
]
[
0
]
);
$sentence
->
addChild
(
'format'
,
$value
[
$i
]
[
1
]
);
}
break
;
default
:
$logger_xml
->
addChild
(
$key
,
$value
);
}
}
return
$logger_xml
;
}
?>
?>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment