2016-05-06 13:36:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2016 PX4 Development Team. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2019-10-25 10:56:32 +02:00
|
|
|
#include <px4_platform_common/px4_config.h>
|
|
|
|
|
#include <px4_platform_common/console_buffer.h>
|
2016-04-25 17:36:13 -04:00
|
|
|
#include "logger.h"
|
2016-05-17 16:54:20 +02:00
|
|
|
#include "messages.h"
|
2018-05-03 11:36:51 +02:00
|
|
|
#include "watchdog.h"
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2017-04-07 17:51:06 +02:00
|
|
|
#include <dirent.h>
|
2016-04-25 17:36:13 -04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
2016-06-10 12:45:22 +02:00
|
|
|
#include <stdlib.h>
|
2016-05-11 10:08:25 +02:00
|
|
|
#include <time.h>
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2019-07-03 16:30:21 -04:00
|
|
|
#include <uORB/PublicationQueued.hpp>
|
2016-04-25 17:36:13 -04:00
|
|
|
#include <uORB/uORBTopics.h>
|
2016-05-11 10:08:25 +02:00
|
|
|
#include <uORB/topics/parameter_update.h>
|
2016-10-12 16:42:57 +02:00
|
|
|
#include <uORB/topics/vehicle_command_ack.h>
|
2016-05-11 10:08:25 +02:00
|
|
|
|
2016-07-16 01:55:32 +02:00
|
|
|
#include <drivers/drv_hrt.h>
|
2019-04-08 07:53:45 +02:00
|
|
|
#include <mathlib/math/Limits.hpp>
|
2019-10-25 10:56:32 +02:00
|
|
|
#include <px4_platform_common/getopt.h>
|
|
|
|
|
#include <px4_platform_common/log.h>
|
|
|
|
|
#include <px4_platform_common/posix.h>
|
|
|
|
|
#include <px4_platform_common/sem.h>
|
|
|
|
|
#include <px4_platform_common/shutdown.h>
|
|
|
|
|
#include <px4_platform_common/tasks.h>
|
2016-05-11 11:05:05 +02:00
|
|
|
#include <systemlib/mavlink_log.h>
|
2016-06-10 12:45:22 +02:00
|
|
|
#include <replay/definitions.hpp>
|
2016-12-19 16:57:37 +01:00
|
|
|
#include <version/version.h>
|
2016-05-11 11:05:05 +02:00
|
|
|
|
2016-05-06 11:37:29 +02:00
|
|
|
//#define DBGPRINT //write status output every few seconds
|
2016-04-25 17:36:13 -04:00
|
|
|
|
|
|
|
|
#if defined(DBGPRINT)
|
|
|
|
|
// needed for mallinfo
|
|
|
|
|
#if defined(__PX4_POSIX) && !defined(__PX4_DARWIN)
|
|
|
|
|
#include <malloc.h>
|
|
|
|
|
#endif /* __PX4_POSIX */
|
|
|
|
|
|
|
|
|
|
// struct mallinfo not available on OSX?
|
|
|
|
|
#if defined(__PX4_DARWIN)
|
|
|
|
|
#undef DBGPRINT
|
|
|
|
|
#endif /* defined(__PX4_DARWIN) */
|
|
|
|
|
#endif /* defined(DBGPRINT) */
|
|
|
|
|
|
|
|
|
|
using namespace px4::logger;
|
2019-06-11 11:00:55 +02:00
|
|
|
using namespace time_literals;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-05-03 10:58:00 +02:00
|
|
|
|
|
|
|
|
struct timer_callback_data_s {
|
|
|
|
|
px4_sem_t semaphore;
|
|
|
|
|
|
2018-05-03 11:36:51 +02:00
|
|
|
watchdog_data_t watchdog_data;
|
|
|
|
|
volatile bool watchdog_triggered = false;
|
2018-05-03 10:58:00 +02:00
|
|
|
};
|
|
|
|
|
|
2016-07-16 01:55:32 +02:00
|
|
|
/* This is used to schedule work for the logger (periodic scan for updated topics) */
|
|
|
|
|
static void timer_callback(void *arg)
|
|
|
|
|
{
|
2018-05-03 10:58:00 +02:00
|
|
|
/* Note: we are in IRQ context here (on NuttX) */
|
|
|
|
|
|
|
|
|
|
timer_callback_data_s *data = (timer_callback_data_s *)arg;
|
|
|
|
|
|
2018-05-03 11:36:51 +02:00
|
|
|
if (watchdog_update(data->watchdog_data)) {
|
|
|
|
|
data->watchdog_triggered = true;
|
|
|
|
|
}
|
2018-02-27 18:39:59 +01:00
|
|
|
|
|
|
|
|
/* check the value of the semaphore: if the logger cannot keep up with running it's main loop as fast
|
|
|
|
|
* as the timer_callback here increases the semaphore count, the counter would increase unbounded,
|
|
|
|
|
* leading to an overflow at some point. This case we want to avoid here, so we check the current
|
|
|
|
|
* value against a (somewhat arbitrary) threshold, and avoid calling sem_post() if it's exceeded.
|
|
|
|
|
* (it's not a problem if the threshold is a bit too large, it just means the logger will do
|
|
|
|
|
* multiple iterations at once, the next time it's scheduled). */
|
|
|
|
|
int semaphore_value;
|
|
|
|
|
|
2018-05-03 10:58:00 +02:00
|
|
|
if (px4_sem_getvalue(&data->semaphore, &semaphore_value) == 0 && semaphore_value > 1) {
|
2018-02-27 18:39:59 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-03 10:58:00 +02:00
|
|
|
px4_sem_post(&data->semaphore);
|
|
|
|
|
|
2016-07-16 01:55:32 +02:00
|
|
|
}
|
2016-05-24 15:07:11 +02:00
|
|
|
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
int logger_main(int argc, char *argv[])
|
|
|
|
|
{
|
2016-05-03 16:50:12 -04:00
|
|
|
// logger currently assumes little endian
|
|
|
|
|
int num = 1;
|
|
|
|
|
|
|
|
|
|
if (*(char *)&num != 1) {
|
|
|
|
|
PX4_ERR("Logger only works on little endian!\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
return Logger::main(argc, argv);
|
|
|
|
|
}
|
2016-05-31 09:24:19 -06:00
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
namespace px4
|
|
|
|
|
{
|
|
|
|
|
namespace logger
|
|
|
|
|
{
|
2016-05-31 09:24:19 -06:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
constexpr const char *Logger::LOG_ROOT[(int)LogType::Count];
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
int Logger::custom_command(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
if (!is_running()) {
|
|
|
|
|
print_usage("logger not running");
|
2016-05-31 09:24:19 -06:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
if (!strcmp(argv[0], "on")) {
|
|
|
|
|
get_instance()->set_arm_override(true);
|
2016-04-25 17:36:13 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
if (!strcmp(argv[0], "off")) {
|
|
|
|
|
get_instance()->set_arm_override(false);
|
|
|
|
|
return 0;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
return print_usage("unknown command");
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
int Logger::task_spawn(int argc, char *argv[])
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2017-04-27 17:05:37 +02:00
|
|
|
_task_id = px4_task_spawn_cmd("logger",
|
|
|
|
|
SCHED_DEFAULT,
|
2017-07-09 21:54:15 +02:00
|
|
|
SCHED_PRIORITY_LOG_CAPTURE,
|
2019-04-03 09:03:03 -04:00
|
|
|
3700,
|
2017-04-27 17:05:37 +02:00
|
|
|
(px4_main_t)&run_trampoline,
|
|
|
|
|
(char *const *)argv);
|
|
|
|
|
|
|
|
|
|
if (_task_id < 0) {
|
|
|
|
|
_task_id = -1;
|
2016-04-25 17:36:13 -04:00
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
return 0;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
int Logger::print_status()
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2016-10-12 15:35:20 +02:00
|
|
|
PX4_INFO("Running in mode: %s", configured_backend_mode());
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2017-10-12 16:40:47 +02:00
|
|
|
bool is_logging = false;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (_writer.is_started(LogType::Full, LogWriter::BackendFile)) {
|
|
|
|
|
PX4_INFO("Full File Logging Running:");
|
|
|
|
|
print_statistics(LogType::Full);
|
|
|
|
|
is_logging = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_writer.is_started(LogType::Mission, LogWriter::BackendFile)) {
|
|
|
|
|
PX4_INFO("Mission File Logging Running:");
|
|
|
|
|
print_statistics(LogType::Mission);
|
2017-10-12 16:40:47 +02:00
|
|
|
is_logging = true;
|
2016-10-07 17:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (_writer.is_started(LogType::Full, LogWriter::BackendMavlink)) {
|
|
|
|
|
PX4_INFO("Mavlink Logging Running (Full log)");
|
2017-10-12 16:40:47 +02:00
|
|
|
is_logging = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_logging) {
|
|
|
|
|
PX4_INFO("Not logging");
|
2016-06-10 08:50:16 +02:00
|
|
|
}
|
2017-04-27 17:05:37 +02:00
|
|
|
|
|
|
|
|
return 0;
|
2016-06-10 08:50:16 +02:00
|
|
|
}
|
2016-10-07 17:58:02 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::print_statistics(LogType type)
|
2016-06-10 08:50:16 +02:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
if (!_writer.is_started(type, LogWriter::BackendFile)) { //currently only statistics for file logging
|
2016-06-10 08:50:16 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
Statistics &stats = _statistics[(int)type];
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-10-12 15:35:20 +02:00
|
|
|
/* this is only for the file backend */
|
2018-10-22 11:37:26 +02:00
|
|
|
float kibibytes = _writer.get_total_written_file(type) / 1024.0f;
|
2016-06-10 08:50:16 +02:00
|
|
|
float mebibytes = kibibytes / 1024.0f;
|
2018-10-22 11:37:26 +02:00
|
|
|
float seconds = ((float)(hrt_absolute_time() - stats.start_time_file)) / 1000000.0f;
|
2016-05-06 11:37:29 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
PX4_INFO("Log file: %s/%s/%s", LOG_ROOT[(int)type], _file_name[(int)type].log_dir, _file_name[(int)type].log_file_name);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (mebibytes < 0.1f) {
|
|
|
|
|
PX4_INFO("Wrote %4.2f KiB (avg %5.2f KiB/s)", (double)kibibytes, (double)(kibibytes / seconds));
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
} else {
|
|
|
|
|
PX4_INFO("Wrote %4.2f MiB (avg %5.2f KiB/s)", (double)mebibytes, (double)(kibibytes / seconds));
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2016-06-10 08:50:16 +02:00
|
|
|
PX4_INFO("Since last status: dropouts: %zu (max len: %.3f s), max used buffer: %zu / %zu B",
|
2018-10-22 11:37:26 +02:00
|
|
|
stats.write_dropouts, (double)stats.max_dropout_duration, stats.high_water, _writer.get_buffer_size_file(type));
|
|
|
|
|
stats.high_water = 0;
|
|
|
|
|
stats.write_dropouts = 0;
|
|
|
|
|
stats.max_dropout_duration = 0.f;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-28 11:42:11 +02:00
|
|
|
Logger *Logger::instantiate(int argc, char *argv[])
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2016-07-16 01:55:32 +02:00
|
|
|
uint32_t log_interval = 3500;
|
2016-04-25 17:36:13 -04:00
|
|
|
int log_buffer_size = 12 * 1024;
|
|
|
|
|
bool log_on_start = false;
|
2016-05-11 15:32:29 +02:00
|
|
|
bool log_until_shutdown = false;
|
2019-04-17 07:07:46 +02:00
|
|
|
Logger::LogMode log_mode = Logger::LogMode::while_armed;
|
2016-04-25 17:36:13 -04:00
|
|
|
bool error_flag = false;
|
2016-05-11 10:08:25 +02:00
|
|
|
bool log_name_timestamp = false;
|
2016-10-19 09:16:39 +02:00
|
|
|
LogWriter::Backend backend = LogWriter::BackendAll;
|
2017-03-01 12:10:41 +01:00
|
|
|
const char *poll_topic = nullptr;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
|
|
|
|
int myoptind = 1;
|
|
|
|
|
int ch;
|
2017-01-28 20:21:58 -05:00
|
|
|
const char *myoptarg = nullptr;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2019-08-06 02:07:29 -04:00
|
|
|
while ((ch = px4_getopt(argc, argv, "r:b:etfm:p:x", &myoptind, &myoptarg)) != EOF) {
|
2016-04-25 17:36:13 -04:00
|
|
|
switch (ch) {
|
|
|
|
|
case 'r': {
|
2017-01-28 20:21:58 -05:00
|
|
|
unsigned long r = strtoul(myoptarg, nullptr, 10);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
|
|
|
|
if (r <= 0) {
|
2016-07-05 13:40:01 +02:00
|
|
|
r = 1e6;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_interval = 1e6 / r;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
case 'x':
|
|
|
|
|
log_mode = Logger::LogMode::rc_aux1;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
case 'e':
|
|
|
|
|
log_on_start = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'b': {
|
2017-01-28 20:21:58 -05:00
|
|
|
unsigned long s = strtoul(myoptarg, nullptr, 10);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
|
|
|
|
if (s < 1) {
|
|
|
|
|
s = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_buffer_size = 1024 * s;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2016-05-11 10:08:25 +02:00
|
|
|
case 't':
|
|
|
|
|
log_name_timestamp = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-05-11 15:32:29 +02:00
|
|
|
case 'f':
|
|
|
|
|
log_on_start = true;
|
|
|
|
|
log_until_shutdown = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-10-07 17:58:02 +02:00
|
|
|
case 'm':
|
|
|
|
|
if (!strcmp(myoptarg, "file")) {
|
|
|
|
|
backend = LogWriter::BackendFile;
|
|
|
|
|
|
|
|
|
|
} else if (!strcmp(myoptarg, "mavlink")) {
|
|
|
|
|
backend = LogWriter::BackendMavlink;
|
|
|
|
|
|
|
|
|
|
} else if (!strcmp(myoptarg, "all")) {
|
|
|
|
|
backend = LogWriter::BackendAll;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
PX4_ERR("unknown mode: %s", myoptarg);
|
|
|
|
|
error_flag = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2017-03-01 12:10:41 +01:00
|
|
|
case 'p':
|
|
|
|
|
poll_topic = myoptarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
case '?':
|
|
|
|
|
error_flag = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
PX4_WARN("unrecognized flag");
|
|
|
|
|
error_flag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (log_on_start) {
|
|
|
|
|
if (log_until_shutdown) {
|
|
|
|
|
log_mode = Logger::LogMode::boot_until_shutdown;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
} else {
|
|
|
|
|
log_mode = Logger::LogMode::boot_until_disarm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
if (error_flag) {
|
2017-04-27 17:05:37 +02:00
|
|
|
return nullptr;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-06 02:07:29 -04:00
|
|
|
Logger *logger = new Logger(backend, log_buffer_size, log_interval, poll_topic, log_mode, log_name_timestamp);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-04-29 10:35:37 -06:00
|
|
|
#if defined(DBGPRINT) && defined(__PX4_NUTTX)
|
2016-05-06 11:37:29 +02:00
|
|
|
struct mallinfo alloc_info = mallinfo();
|
2016-06-10 08:50:16 +02:00
|
|
|
PX4_INFO("largest free chunk: %d bytes", alloc_info.mxordblk);
|
|
|
|
|
PX4_INFO("remaining free heap: %d bytes", alloc_info.fordblks);
|
2016-04-29 06:54:58 -06:00
|
|
|
#endif /* DBGPRINT */
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
if (logger == nullptr) {
|
2016-06-10 08:50:16 +02:00
|
|
|
PX4_ERR("alloc failed");
|
2016-05-03 16:50:12 -04:00
|
|
|
|
|
|
|
|
} else {
|
2017-03-29 18:47:20 +02:00
|
|
|
#ifndef __PX4_NUTTX
|
2016-06-10 12:45:22 +02:00
|
|
|
//check for replay mode
|
|
|
|
|
const char *logfile = getenv(px4::replay::ENV_FILENAME);
|
|
|
|
|
|
|
|
|
|
if (logfile) {
|
2017-04-27 17:05:37 +02:00
|
|
|
logger->setReplayFile(logfile);
|
2016-06-10 12:45:22 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-29 18:47:20 +02:00
|
|
|
#endif /* __PX4_NUTTX */
|
|
|
|
|
|
2016-05-03 16:50:12 -04:00
|
|
|
}
|
2016-05-09 17:24:54 +02:00
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
return logger;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-03-01 12:10:41 +01:00
|
|
|
Logger::Logger(LogWriter::Backend backend, size_t buffer_size, uint32_t log_interval, const char *poll_topic_name,
|
2019-08-06 02:07:29 -04:00
|
|
|
LogMode log_mode, bool log_name_timestamp) :
|
2019-04-17 07:07:46 +02:00
|
|
|
_log_mode(log_mode),
|
2016-05-11 10:08:25 +02:00
|
|
|
_log_name_timestamp(log_name_timestamp),
|
2019-08-06 02:07:29 -04:00
|
|
|
_writer(backend, buffer_size),
|
2017-07-03 23:57:49 -04:00
|
|
|
_log_interval(log_interval)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2016-05-11 10:08:25 +02:00
|
|
|
_log_utc_offset = param_find("SDLOG_UTC_OFFSET");
|
2017-04-10 14:01:41 +02:00
|
|
|
_log_dirs_max = param_find("SDLOG_DIRS_MAX");
|
2017-06-29 07:32:30 -04:00
|
|
|
_sdlog_profile_handle = param_find("SDLOG_PROFILE");
|
2018-10-22 11:37:26 +02:00
|
|
|
_mission_log = param_find("SDLOG_MISSION");
|
2017-03-01 12:10:41 +01:00
|
|
|
|
|
|
|
|
if (poll_topic_name) {
|
2019-06-07 16:41:30 -04:00
|
|
|
const orb_metadata *const *topics = orb_get_topics();
|
2017-03-01 12:10:41 +01:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < orb_topics_count(); i++) {
|
|
|
|
|
if (strcmp(poll_topic_name, topics[i]->o_name) == 0) {
|
|
|
|
|
_polling_topic_meta = topics[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_polling_topic_meta) {
|
|
|
|
|
PX4_ERR("Failed to find topic %s", poll_topic_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger::~Logger()
|
|
|
|
|
{
|
2016-06-10 12:45:22 +02:00
|
|
|
if (_replay_file_name) {
|
|
|
|
|
free(_replay_file_name);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 15:11:18 +02:00
|
|
|
if (_msg_buffer) {
|
|
|
|
|
delete[](_msg_buffer);
|
|
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
bool Logger::request_stop_static()
|
2017-04-18 14:08:48 +02:00
|
|
|
{
|
2017-04-27 17:05:37 +02:00
|
|
|
if (is_running()) {
|
|
|
|
|
get_instance()->request_stop();
|
|
|
|
|
return false;
|
2017-04-18 14:08:48 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
return true;
|
2017-04-18 14:08:48 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
LoggerSubscription *Logger::add_topic(const orb_metadata *topic, uint32_t interval_ms, uint8_t instance)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2017-10-16 14:52:02 +02:00
|
|
|
LoggerSubscription *subscription = nullptr;
|
2016-05-18 09:46:10 +02:00
|
|
|
size_t fields_len = strlen(topic->o_fields) + strlen(topic->o_name) + 1; //1 for ':'
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-05-31 17:32:13 +02:00
|
|
|
if (fields_len > sizeof(ulog_message_format_s::format)) {
|
2016-05-02 14:47:58 +02:00
|
|
|
PX4_WARN("skip topic %s, format string is too large: %zu (max is %zu)", topic->o_name, fields_len,
|
2016-05-31 17:32:13 +02:00
|
|
|
sizeof(ulog_message_format_s::format));
|
2016-05-02 14:47:58 +02:00
|
|
|
|
2017-10-16 14:52:02 +02:00
|
|
|
return nullptr;
|
2016-05-02 14:47:58 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
if (_subscriptions.push_back(LoggerSubscription{topic, interval_ms, instance})) {
|
2017-10-16 14:52:02 +02:00
|
|
|
subscription = &_subscriptions[_subscriptions.size() - 1];
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2017-10-16 14:52:02 +02:00
|
|
|
} else {
|
2019-08-07 11:02:16 -04:00
|
|
|
PX4_WARN("Too many subscriptions, failed to add: %s %d", topic->o_name, instance);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2017-10-16 14:52:02 +02:00
|
|
|
return subscription;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
bool Logger::add_topic(const char *name, uint32_t interval_ms, uint8_t instance)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2019-08-07 11:02:16 -04:00
|
|
|
// if we poll on a topic, we don't use the interval and let the polled topic define the maximum interval
|
|
|
|
|
if (_polling_topic_meta) {
|
|
|
|
|
interval_ms = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-07 16:41:30 -04:00
|
|
|
const orb_metadata *const *topics = orb_get_topics();
|
2017-10-16 14:52:02 +02:00
|
|
|
LoggerSubscription *subscription = nullptr;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < orb_topics_count(); i++) {
|
|
|
|
|
if (strcmp(name, topics[i]->o_name) == 0) {
|
2017-06-30 11:41:30 +02:00
|
|
|
bool already_added = false;
|
|
|
|
|
|
|
|
|
|
// check if already added: if so, only update the interval
|
|
|
|
|
for (size_t j = 0; j < _subscriptions.size(); ++j) {
|
2019-08-07 11:02:16 -04:00
|
|
|
if ((_subscriptions[j].get_topic() == topics[i]) && (_subscriptions[j].get_instance() == instance)) {
|
|
|
|
|
|
|
|
|
|
PX4_DEBUG("logging topic %s(%d), interval: %i, already added, only setting interval",
|
|
|
|
|
topics[i]->o_name, instance, interval_ms);
|
|
|
|
|
|
|
|
|
|
_subscriptions[j].set_interval_ms(interval_ms);
|
|
|
|
|
|
2017-10-16 14:52:02 +02:00
|
|
|
subscription = &_subscriptions[j];
|
2017-06-30 11:41:30 +02:00
|
|
|
already_added = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!already_added) {
|
2019-08-07 11:02:16 -04:00
|
|
|
subscription = add_topic(topics[i], interval_ms, instance);
|
|
|
|
|
PX4_DEBUG("logging topic: %s(%d), interval: %i", topics[i]->o_name, instance, interval_ms);
|
2017-06-30 11:41:30 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
return (subscription != nullptr);
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
bool Logger::add_topic_multi(const char *name, uint32_t interval_ms)
|
|
|
|
|
{
|
|
|
|
|
// add all possible instances
|
|
|
|
|
for (uint8_t instance = 0; instance < ORB_MULTI_MAX_INSTANCES; instance++) {
|
|
|
|
|
add_topic(name, interval_ms, instance);
|
2017-10-16 14:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
return true;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
bool Logger::copy_if_updated(int sub_idx, void *buffer, bool try_to_subscribe)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
LoggerSubscription &sub = _subscriptions[sub_idx];
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
bool updated = false;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
if (sub.valid()) {
|
|
|
|
|
updated = sub.update(buffer);
|
2016-05-17 14:18:59 +02:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
} else if (try_to_subscribe) {
|
|
|
|
|
if (sub.subscribe()) {
|
|
|
|
|
write_add_logged_msg(LogType::Full, sub);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (sub_idx < _num_mission_subs) {
|
2019-08-07 11:02:16 -04:00
|
|
|
write_add_logged_msg(LogType::Mission, sub);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
// copy first data
|
|
|
|
|
updated = sub.copy(buffer);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return updated;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-14 10:08:50 +02:00
|
|
|
void Logger::add_default_topics()
|
2016-05-31 09:24:19 -06:00
|
|
|
{
|
2017-03-10 11:56:10 +01:00
|
|
|
add_topic("actuator_controls_0", 100);
|
|
|
|
|
add_topic("actuator_controls_1", 100);
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("airspeed", 200);
|
2019-08-07 13:06:00 +02:00
|
|
|
add_topic("airspeed_validated", 200);
|
2017-07-03 23:57:49 -04:00
|
|
|
add_topic("camera_capture");
|
|
|
|
|
add_topic("camera_trigger");
|
2018-11-15 10:51:33 +01:00
|
|
|
add_topic("camera_trigger_secondary");
|
2017-07-03 23:57:49 -04:00
|
|
|
add_topic("cpuload");
|
2019-11-11 10:27:57 +01:00
|
|
|
add_topic("estimator_innovations", 200);
|
|
|
|
|
add_topic("estimator_innovation_variances", 200);
|
|
|
|
|
add_topic("estimator_innovation_test_ratios", 200);
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic("ekf_gps_drift");
|
2017-03-10 11:56:10 +01:00
|
|
|
add_topic("esc_status", 250);
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("estimator_status", 200);
|
2017-12-16 17:55:21 -05:00
|
|
|
add_topic("home_position");
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("input_rc", 200);
|
2017-09-05 13:53:09 -04:00
|
|
|
add_topic("manual_control_setpoint", 200);
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic("mission");
|
|
|
|
|
add_topic("mission_result");
|
2017-07-03 23:57:49 -04:00
|
|
|
add_topic("optical_flow", 50);
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic("position_controller_status", 500);
|
2017-07-03 23:57:49 -04:00
|
|
|
add_topic("position_setpoint_triplet", 200);
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic("radio_status");
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("rate_ctrl_status", 200);
|
2017-07-03 23:57:49 -04:00
|
|
|
add_topic("sensor_combined", 100);
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("sensor_preflight", 200);
|
|
|
|
|
add_topic("system_power", 500);
|
|
|
|
|
add_topic("tecs_status", 200);
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("trajectory_setpoint", 200);
|
2018-09-24 12:07:01 +02:00
|
|
|
add_topic("vehicle_air_data", 200);
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("vehicle_angular_velocity", 20);
|
|
|
|
|
add_topic("vehicle_attitude", 50);
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("vehicle_attitude_setpoint", 100);
|
2017-07-03 23:57:49 -04:00
|
|
|
add_topic("vehicle_command");
|
|
|
|
|
add_topic("vehicle_global_position", 200);
|
|
|
|
|
add_topic("vehicle_land_detected");
|
|
|
|
|
add_topic("vehicle_local_position", 100);
|
|
|
|
|
add_topic("vehicle_local_position_setpoint", 100);
|
2018-09-24 12:07:01 +02:00
|
|
|
add_topic("vehicle_magnetometer", 200);
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("vehicle_rates_setpoint", 20);
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("vehicle_status", 200);
|
2017-12-20 19:51:49 -05:00
|
|
|
add_topic("vehicle_status_flags");
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("vtol_vehicle_status", 200);
|
2018-03-04 14:18:33 -05:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic_multi("actuator_outputs", 100);
|
|
|
|
|
add_topic_multi("battery_status", 500);
|
|
|
|
|
add_topic_multi("distance_sensor", 100);
|
2019-10-14 20:09:39 -04:00
|
|
|
add_topic_multi("sensor_accel_status", 1000);
|
|
|
|
|
add_topic_multi("sensor_gyro_status", 1000);
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic_multi("telemetry_status");
|
|
|
|
|
add_topic_multi("vehicle_gps_position");
|
2019-08-29 15:48:46 +02:00
|
|
|
add_topic_multi("wind_estimate", 200);
|
2019-08-07 11:02:16 -04:00
|
|
|
|
2018-11-23 12:39:44 -05:00
|
|
|
#ifdef CONFIG_ARCH_BOARD_PX4_SITL
|
2019-08-07 11:02:16 -04:00
|
|
|
|
2018-03-04 14:18:33 -05:00
|
|
|
add_topic("actuator_controls_virtual_fw");
|
|
|
|
|
add_topic("actuator_controls_virtual_mc");
|
|
|
|
|
add_topic("fw_virtual_attitude_setpoint");
|
|
|
|
|
add_topic("mc_virtual_attitude_setpoint");
|
|
|
|
|
add_topic("offboard_control_mode");
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("position_controller_status");
|
2018-03-04 14:18:33 -05:00
|
|
|
add_topic("time_offset");
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("vehicle_angular_velocity", 10);
|
2018-03-04 14:18:33 -05:00
|
|
|
add_topic("vehicle_attitude_groundtruth", 10);
|
|
|
|
|
add_topic("vehicle_global_position_groundtruth", 100);
|
|
|
|
|
add_topic("vehicle_local_position_groundtruth", 100);
|
|
|
|
|
add_topic("vehicle_roi");
|
2019-08-07 11:02:16 -04:00
|
|
|
|
|
|
|
|
add_topic_multi("multirotor_motor_limits");
|
|
|
|
|
|
2018-11-23 12:39:44 -05:00
|
|
|
#endif /* CONFIG_ARCH_BOARD_PX4_SITL */
|
2017-06-29 07:32:30 -04:00
|
|
|
}
|
2016-07-11 10:04:44 +02:00
|
|
|
|
2017-10-14 09:21:34 +02:00
|
|
|
void Logger::add_high_rate_topics()
|
|
|
|
|
{
|
|
|
|
|
// maximum rate to analyze fast maneuvers (e.g. for racing)
|
|
|
|
|
add_topic("actuator_controls_0");
|
|
|
|
|
add_topic("actuator_outputs");
|
|
|
|
|
add_topic("manual_control_setpoint");
|
2018-01-04 12:37:00 -05:00
|
|
|
add_topic("rate_ctrl_status");
|
2018-01-09 15:22:52 +01:00
|
|
|
add_topic("sensor_combined");
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("vehicle_angular_velocity");
|
2017-10-14 09:21:34 +02:00
|
|
|
add_topic("vehicle_attitude");
|
|
|
|
|
add_topic("vehicle_attitude_setpoint");
|
|
|
|
|
add_topic("vehicle_rates_setpoint");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Logger::add_debug_topics()
|
|
|
|
|
{
|
2019-08-06 12:55:25 -04:00
|
|
|
add_topic("debug_array");
|
2017-10-14 09:21:34 +02:00
|
|
|
add_topic("debug_key_value");
|
|
|
|
|
add_topic("debug_value");
|
|
|
|
|
add_topic("debug_vect");
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 07:32:30 -04:00
|
|
|
void Logger::add_estimator_replay_topics()
|
|
|
|
|
{
|
|
|
|
|
// for estimator replay (need to be at full rate)
|
2017-03-03 08:33:42 +01:00
|
|
|
add_topic("ekf2_timestamps");
|
2018-07-23 02:18:30 +10:00
|
|
|
add_topic("ekf_gps_position");
|
2017-09-05 10:43:38 -04:00
|
|
|
|
|
|
|
|
// current EKF2 subscriptions
|
|
|
|
|
add_topic("airspeed");
|
|
|
|
|
add_topic("optical_flow");
|
2016-07-11 10:04:44 +02:00
|
|
|
add_topic("sensor_combined");
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("sensor_selection");
|
2018-02-18 11:44:21 -05:00
|
|
|
add_topic("vehicle_air_data");
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("vehicle_land_detected");
|
2018-02-18 11:44:21 -05:00
|
|
|
add_topic("vehicle_magnetometer");
|
2017-09-05 10:43:38 -04:00
|
|
|
add_topic("vehicle_status");
|
2018-11-15 15:35:28 +00:00
|
|
|
add_topic("vehicle_visual_odometry");
|
2019-09-23 20:24:52 +02:00
|
|
|
add_topic("vehicle_visual_odometry_aligned");
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic_multi("distance_sensor");
|
|
|
|
|
add_topic_multi("vehicle_gps_position");
|
2016-05-31 09:24:19 -06:00
|
|
|
}
|
|
|
|
|
|
2017-06-29 07:32:30 -04:00
|
|
|
void Logger::add_thermal_calibration_topics()
|
2017-01-20 08:10:30 +11:00
|
|
|
{
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic_multi("sensor_accel", 100);
|
|
|
|
|
add_topic_multi("sensor_baro", 100);
|
|
|
|
|
add_topic_multi("sensor_gyro", 100);
|
2017-01-20 08:10:30 +11:00
|
|
|
}
|
|
|
|
|
|
2017-10-21 00:30:55 +11:00
|
|
|
void Logger::add_sensor_comparison_topics()
|
|
|
|
|
{
|
2019-08-07 11:02:16 -04:00
|
|
|
add_topic_multi("sensor_accel", 100);
|
|
|
|
|
add_topic_multi("sensor_baro", 100);
|
|
|
|
|
add_topic_multi("sensor_gyro", 100);
|
|
|
|
|
add_topic_multi("sensor_mag", 100);
|
2017-10-21 00:30:55 +11:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 10:52:43 +01:00
|
|
|
void Logger::add_vision_and_avoidance_topics()
|
|
|
|
|
{
|
2019-11-13 15:19:02 +01:00
|
|
|
add_topic("cellular_status", 200);
|
2018-12-07 10:52:43 +01:00
|
|
|
add_topic("collision_constraints");
|
2019-06-25 08:52:11 +02:00
|
|
|
add_topic("obstacle_distance_fused");
|
2019-10-13 08:56:00 +02:00
|
|
|
add_topic("onboard_computer_status", 200);
|
2018-12-07 10:52:43 +01:00
|
|
|
add_topic("vehicle_mocap_odometry", 30);
|
|
|
|
|
add_topic("vehicle_trajectory_waypoint", 200);
|
|
|
|
|
add_topic("vehicle_trajectory_waypoint_desired", 200);
|
|
|
|
|
add_topic("vehicle_visual_odometry", 30);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 07:32:30 -04:00
|
|
|
void Logger::add_system_identification_topics()
|
|
|
|
|
{
|
|
|
|
|
// for system id need to log imu and controls at full rate
|
|
|
|
|
add_topic("actuator_controls_0");
|
|
|
|
|
add_topic("actuator_controls_1");
|
2017-07-03 23:57:49 -04:00
|
|
|
add_topic("sensor_combined");
|
2017-06-29 07:32:30 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-30 20:30:04 -06:00
|
|
|
int Logger::add_topics_from_file(const char *fname)
|
|
|
|
|
{
|
2019-08-07 11:02:16 -04:00
|
|
|
int ntopics = 0;
|
2016-05-30 20:30:04 -06:00
|
|
|
|
|
|
|
|
/* open the topic list file */
|
2019-08-07 11:02:16 -04:00
|
|
|
FILE *fp = fopen(fname, "r");
|
2016-05-30 20:30:04 -06:00
|
|
|
|
2017-01-28 20:21:58 -05:00
|
|
|
if (fp == nullptr) {
|
2016-05-30 20:30:04 -06:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* call add_topic for each topic line in the file */
|
|
|
|
|
for (;;) {
|
|
|
|
|
/* get a line, bail on error/EOF */
|
2019-08-07 11:02:16 -04:00
|
|
|
char line[80];
|
2016-05-30 20:30:04 -06:00
|
|
|
line[0] = '\0';
|
|
|
|
|
|
2017-01-28 20:21:58 -05:00
|
|
|
if (fgets(line, sizeof(line), fp) == nullptr) {
|
2016-05-30 20:30:04 -06:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* skip comment lines */
|
2016-05-31 07:03:08 -06:00
|
|
|
if ((strlen(line) < 2) || (line[0] == '#')) {
|
2016-05-30 20:30:04 -06:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 13:32:10 +01:00
|
|
|
// read line with format: <topic_name>[, <interval>]
|
2019-08-07 11:02:16 -04:00
|
|
|
char topic_name[80];
|
|
|
|
|
uint32_t interval_ms = 0;
|
|
|
|
|
int nfields = sscanf(line, "%s %u", topic_name, &interval_ms);
|
2016-05-31 09:24:19 -06:00
|
|
|
|
2016-05-31 07:03:08 -06:00
|
|
|
if (nfields > 0) {
|
2017-01-06 13:32:10 +01:00
|
|
|
int name_len = strlen(topic_name);
|
|
|
|
|
|
|
|
|
|
if (name_len > 0 && topic_name[name_len - 1] == ',') {
|
|
|
|
|
topic_name[name_len - 1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
/* add topic with specified interval_ms */
|
|
|
|
|
if (add_topic(topic_name, interval_ms)) {
|
2017-01-06 13:32:10 +01:00
|
|
|
ntopics++;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
PX4_ERR("Failed to add topic %s", topic_name);
|
|
|
|
|
}
|
2016-05-30 20:30:04 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return ntopics;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 15:35:20 +02:00
|
|
|
const char *Logger::configured_backend_mode() const
|
|
|
|
|
{
|
|
|
|
|
switch (_writer.backend()) {
|
|
|
|
|
case LogWriter::BackendFile: return "file";
|
|
|
|
|
|
|
|
|
|
case LogWriter::BackendMavlink: return "mavlink";
|
|
|
|
|
|
|
|
|
|
case LogWriter::BackendAll: return "all";
|
|
|
|
|
|
|
|
|
|
default: return "several";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-22 11:37:26 +02:00
|
|
|
|
|
|
|
|
void Logger::initialize_mission_topics(MissionLogType type)
|
|
|
|
|
{
|
|
|
|
|
if (type == MissionLogType::Complete) {
|
|
|
|
|
add_mission_topic("camera_capture");
|
|
|
|
|
add_mission_topic("mission_result");
|
|
|
|
|
add_mission_topic("vehicle_global_position", 1000);
|
|
|
|
|
add_mission_topic("vehicle_status", 1000);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
} else if (type == MissionLogType::Geotagging) {
|
|
|
|
|
add_mission_topic("camera_capture");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 16:02:43 +02:00
|
|
|
void Logger::initialize_configured_topics()
|
|
|
|
|
{
|
|
|
|
|
// get the logging profile
|
|
|
|
|
SDLogProfileMask sdlog_profile = SDLogProfileMask::DEFAULT;
|
|
|
|
|
|
|
|
|
|
if (_sdlog_profile_handle != PARAM_INVALID) {
|
2019-06-07 16:41:30 -04:00
|
|
|
param_get(_sdlog_profile_handle, (int32_t *)&sdlog_profile);
|
2018-10-08 16:02:43 +02:00
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-08 16:02:43 +02:00
|
|
|
if ((int32_t)sdlog_profile == 0) {
|
|
|
|
|
PX4_WARN("No logging profile selected. Using default set");
|
|
|
|
|
sdlog_profile = SDLogProfileMask::DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// load appropriate topics for profile
|
|
|
|
|
// the order matters: if several profiles add the same topic, the logging rate of the last one will be used
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::DEFAULT) {
|
|
|
|
|
add_default_topics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::ESTIMATOR_REPLAY) {
|
|
|
|
|
add_estimator_replay_topics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::THERMAL_CALIBRATION) {
|
|
|
|
|
add_thermal_calibration_topics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::SYSTEM_IDENTIFICATION) {
|
|
|
|
|
add_system_identification_topics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::HIGH_RATE) {
|
|
|
|
|
add_high_rate_topics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::DEBUG_TOPICS) {
|
|
|
|
|
add_debug_topics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::SENSOR_COMPARISON) {
|
|
|
|
|
add_sensor_comparison_topics();
|
|
|
|
|
}
|
2018-12-07 10:52:43 +01:00
|
|
|
|
|
|
|
|
if (sdlog_profile & SDLogProfileMask::VISION_AND_AVOIDANCE) {
|
|
|
|
|
add_vision_and_avoidance_topics();
|
|
|
|
|
}
|
2018-10-08 16:02:43 +02:00
|
|
|
}
|
2016-10-12 15:35:20 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
void Logger::add_mission_topic(const char *name, uint32_t interval_ms)
|
2018-10-22 11:37:26 +02:00
|
|
|
{
|
|
|
|
|
if (_num_mission_subs >= MAX_MISSION_TOPICS_NUM) {
|
|
|
|
|
PX4_ERR("Max num mission topics exceeded");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
if (add_topic(name, interval_ms)) {
|
|
|
|
|
_mission_subscriptions[_num_mission_subs].min_delta_ms = interval_ms;
|
2018-10-22 11:37:26 +02:00
|
|
|
_mission_subscriptions[_num_mission_subs].next_write_time = 0;
|
|
|
|
|
++_num_mission_subs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
void Logger::run()
|
|
|
|
|
{
|
2016-10-12 15:35:20 +02:00
|
|
|
PX4_INFO("logger started (mode=%s)", configured_backend_mode());
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-10-12 15:35:20 +02:00
|
|
|
if (_writer.backend() & LogWriter::BackendFile) {
|
2018-10-22 11:37:26 +02:00
|
|
|
int mkdir_ret = mkdir(LOG_ROOT[(int)LogType::Full], S_IRWXU | S_IRWXG | S_IRWXO);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-10-12 15:35:20 +02:00
|
|
|
if (mkdir_ret == 0) {
|
2018-10-22 11:37:26 +02:00
|
|
|
PX4_INFO("log root dir created: %s", LOG_ROOT[(int)LogType::Full]);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-10-12 15:35:20 +02:00
|
|
|
} else if (errno != EEXIST) {
|
2018-10-22 11:37:26 +02:00
|
|
|
PX4_ERR("failed creating log root dir: %s (%i)", LOG_ROOT[(int)LogType::Full], errno);
|
2016-10-12 16:32:02 +02:00
|
|
|
|
|
|
|
|
if ((_writer.backend() & ~LogWriter::BackendFile) == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-12 15:35:20 +02:00
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-10-08 15:28:52 +02:00
|
|
|
int32_t max_log_dirs_to_keep = 0;
|
|
|
|
|
|
|
|
|
|
if (_log_dirs_max != PARAM_INVALID) {
|
|
|
|
|
param_get(_log_dirs_max, &max_log_dirs_to_keep);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (util::check_free_space(LOG_ROOT[(int)LogType::Full], max_log_dirs_to_keep, _mavlink_log_pub,
|
2019-06-07 16:41:30 -04:00
|
|
|
_file_name[(int)LogType::Full].sess_dir_index) == 1) {
|
2016-10-12 15:35:20 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2016-05-11 11:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-06 02:02:24 -04:00
|
|
|
uORB::Subscription parameter_update_sub(ORB_ID(parameter_update));
|
2016-05-06 13:12:50 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
// mission log topics if enabled (must be added first)
|
|
|
|
|
int32_t mission_log_mode = 0;
|
|
|
|
|
|
|
|
|
|
if (_mission_log != PARAM_INVALID) {
|
|
|
|
|
param_get(_mission_log, &mission_log_mode);
|
|
|
|
|
initialize_mission_topics((MissionLogType)mission_log_mode);
|
|
|
|
|
|
|
|
|
|
if (_num_mission_subs > 0) {
|
|
|
|
|
int mkdir_ret = mkdir(LOG_ROOT[(int)LogType::Mission], S_IRWXU | S_IRWXG | S_IRWXO);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (mkdir_ret != 0 && errno != EEXIST) {
|
|
|
|
|
PX4_ERR("failed creating log root dir: %s (%i)", LOG_ROOT[(int)LogType::Mission], errno);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
add posix shell
squashed & rebased version, not including:
- listener changes
- src/firmware renaming
Commits:
tag_to_version.py: fix Python3 error
subprocess.communicate returns bytes instead of a str which is not the
same for Python3. Therefore, we need to decode the bytes.
cmake: remove folder src/firmware
The folder src/firmware was not intuitive. Why would the binaries for
SITL be inside a src and why even inside a src/firmware folder. Also,
the rootfs was put there which made it even more confusing.
The CMakeLists.txt files are moved into cmake/ and get now called from
the main CMakeLists.txt.
qshell: support for return value
Instead of just sending commands, qshell will now also wait until
the command has finished on QURT and sent back a return value. This will
allow all modules on the DSP side to be spawned from the Linux side
meaning that we only need one config/startup file instead of two.
adb_upload: create folders before pushing
Previously the script failed if the folder on the destination was not
already existing. This therefore makes pushing easier.
posix: spawn PX4 modules in bash
This adds the possibility to spawn PX4 modules out of bash. Basically,
the main executable can now be started as a server/daemon or as a
client.
The server replaces the existing functionality of the main exe with
the pxh shell, however, it also opens a pipe that clients can talk to.
Clients can run or spawn PX4 modules or commands by connecting to the
server over the pipe. They clients will get the stdout and return value
of their commands via a client specific pipe back.
This work will allow to start all modules using a bash script similar to
the way it is done in NuttX where the NuttShell scripts the startup
scripts and starts the modules.
SITL: use new client shell in SITL
This is a first step to use the new shell capabilities for SITL.
The new startup bash script rcS merges (and therefore replaces) the two
existing scripts rcS_gazebo_iris and rcS_jmavsim_iris.
More cleanup will be necessary for the rest of the SITL startup scripts.
Snapdragon: use new shell to start all modules
Instead of different mainapp.config and px4.config files, we can now use
a unified rcS bash script which starts all the modules based on
parameters, mainly the SYS_AUTOSTART param.
Snapdragon: fix the airframe description
pxh: argv needs to end with a nullptr
The comment was wrong that argv needs an additional 0 termination.
Instead it needs a nullptr at the end.
px4_posix_tasks: variable cleanup
The px4_task_spawn_cmd function got a cleanup while debugging, however,
no functional changes.
Snapdragon: move some drivers to 4100 config
These drivers are supported by the community, so they go into the 4100
config.
Snapdragon: update 210qc platform
px4_daemon: use doxygen comments
apps.h_in: fix string printf: use .c_str()
px4_daemon: \b -> \n in printf
px4_daemon: handle error in generate_uuid (close the file on error)
posix main: some clarifications in comment (it's the symlinks not the script aliases)
cmake: remove new install command again
This one was probably wrong and untested. Installing needs revisiting.
POSIX: remove argument USES_TERMINAL
POSIX: copy init and mixer files for SITL
Instead of using non-working install commands, the mixer and startup
files are now copied as part of the build in cmake.
adb_upload.sh: remove leftover commented printf
POSIX main: just the pointer instead of memmove
POSIX main: remove chroot
chroot is removed because it hasn't been used anywhere and seems
untested.
px4_daemon: remove client pipe when cleaning up
px4_daemon: fail if the client pipe already exists
The client pipe is supposed to be specific (by UUID), so the path
shouldn't exist already.
history: limit the number of history entries
This is a protection to avoid filling the memory if we are entering a
lot of commands (e.g. auto-generated).
px4_daemon: add a threadsafe map and use it
px4_daemon: whitespace
px4_daemon: fix client parsing
Sometimes the client ends up reading more than one packet in one read.
The parsing is not made for this and would require a (ring)buffer for
it.
The solution of this commit just reads as much as needed from the pipe
which avoids having to do buffering and parsing.
posix: changes sitl_run.sh and main.cpp cleanup
This changes the paths in sitl_run.sh quite a bit to allow the px4
binary to run in the rootfs directory which should make it convenient
and very close to the NuttX variant.
Also main.cpp got a big cleanup after the big rebase with some
conflicts. Quite some functionality was removed but it has yet to be
seen if it needs to be re-added.
px4_log: cleanup log levels, now they make sense
Before DEBUG and INFO log levels where inverted which didn't make much
sense in my eyes.
dataman: fix path for bash shell
logger: fix paths for bash shell
mavlink: fix paths for bash shell
param: fix path for bash shell
inav: fix paths for bash shell
sdlog2: fix paths for bash shell
ROMFS: add forgotten mixer to list
SITL init: more models, more options
- Support for different models using the unified startup
script rcS.
- Support to choose the estimator by setting the environment variable
PX4_ESTIMATOR.
- Support to choose the logger by setting the environment variable
PX4_LOGGER.
rcS: fix string comparison
listener: use template file
Instead of having all of the C++ code inside the Python file it is
nicer to have a separate template file with the C++ headers, etc.
px4_log: add PX4_INFO_RAW for raw printfs
This allows to do custom formatting but is still transported over
sockets to clients.
topic_listener: use PX4_INFO_RAW instead of printf
commander: use PX4_INFO_RAW for status
listener: rewrite to classes and factory
posix: fix some argument warnings
generate_listener.py: by accident changed shebang
listener: big refactor of the generator
Hopefully this makes it easier to read and change in the future.
rcS: manually take over rebase changes
listener: remove leftover try
listener: properly clean up topic instance
rcS: take over some vehicle specific changes
posix-configs: vehicle specifics to separate files
posix-configs: remove leftover lines
uORBDevices: new PX4_INFO_RAW instead of printf
px4_log: just use printf on NuttX
listener: use less binary space, strip on NuttX
generate_listener.py: remove commented code
cmake: fix syntax error from merge
px4_daemon: fixes after rebase of apps.h/cpp fix
px4_daemon: namespace missing
posix: only create stub for fsync on QURT
unitests: reduce dependencies of param test
This makes the unit test compile and link again after the bash changes.
QURT: some compile fixes after a rebase
SITL: arg change for sitl_run.sh to use rcS_test
This allows to use a custom startup file for testing.
SITL: add the folder test_data
SITL: implement shutdown command as systemcmd
The shutdown command needs to be a proper systemcmd, otherwise the alias
and symlink generation doesn't work and we end up calling shutdown of
the host computer which is to be avoided.
px4fmu_test: same IO_pass mixer as px4fmu_default
px4fmu_test: use normal quad x mixer
There is no good reason to use a specific test mixer, except more cmake
code around it. Therefore just use the same mixer as default, and at
some point px4fmu_test and px4fmu_default can get merged
POSIX: cleanup, dir and symlink fixes
This cleans up the logic behind the symlinking and creating directories.
POSIX: correct arg order in usage info
tests: fix paths for SITL tests
POSIX: printf fix
sitl_run.sh: try to make this run on Mac as well
cmake: try to make jenkins happier
Path cleanup, the bin is no longer in src/firmware
POSIX: fix symlink logic
SITL: prefix all exported env variables
cmake: fix path for ROS tests
integrationtests: fix log path
launch: try to make tets with ROS working again
px4_defines: fix after wrong merge deconflicting
px4_defines: get paths for POSIX correct
cmake: fix cmake arguments
This was fine with cmake 3.6 but did not work with cmake 3.2.2
cmake: use cp instead of cmake -E copy
cmake -E copy does not support copying multiple files with versions <
3.5. Therefore, just use cp for now.
ROMFS: fix build error after rebase
cmake: fix paths in configs
launch: use `spawn_model` again
cmake: various fixes after big rebase
param: path fixes after rebase
posix platform: fixes after rebase
test_mixer: fix screwed up rebase
2018-08-02 21:32:51 +02:00
|
|
|
|
2018-08-04 12:54:09 +02:00
|
|
|
int ntopics = add_topics_from_file(PX4_STORAGEDIR "/etc/logging/logger_topics.txt");
|
2016-05-31 09:24:19 -06:00
|
|
|
|
2016-06-10 08:50:16 +02:00
|
|
|
if (ntopics > 0) {
|
|
|
|
|
PX4_INFO("logging %d topics from logger_topics.txt", ntopics);
|
|
|
|
|
|
|
|
|
|
} else {
|
2018-10-08 16:02:43 +02:00
|
|
|
initialize_configured_topics();
|
2016-05-31 09:24:19 -06:00
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-06-04 15:11:18 +02:00
|
|
|
//all topics added. Get required message buffer size
|
2018-06-30 10:58:44 -04:00
|
|
|
int max_msg_size = 0;
|
2016-06-04 15:11:18 +02:00
|
|
|
|
|
|
|
|
for (const auto &subscription : _subscriptions) {
|
|
|
|
|
//use o_size, because that's what orb_copy will use
|
2019-08-07 11:02:16 -04:00
|
|
|
if (subscription.get_topic()->o_size > max_msg_size) {
|
|
|
|
|
max_msg_size = subscription.get_topic()->o_size;
|
2016-06-04 15:11:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max_msg_size += sizeof(ulog_message_data_header_s);
|
|
|
|
|
|
2018-06-30 10:58:44 -04:00
|
|
|
if (sizeof(ulog_message_logging_s) > (size_t)max_msg_size) {
|
2016-06-04 17:23:20 +02:00
|
|
|
max_msg_size = sizeof(ulog_message_logging_s);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-01 12:10:41 +01:00
|
|
|
if (_polling_topic_meta && _polling_topic_meta->o_size > max_msg_size) {
|
|
|
|
|
max_msg_size = _polling_topic_meta->o_size;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 15:11:18 +02:00
|
|
|
if (max_msg_size > _msg_buffer_len) {
|
|
|
|
|
if (_msg_buffer) {
|
|
|
|
|
delete[](_msg_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_msg_buffer_len = max_msg_size;
|
|
|
|
|
_msg_buffer = new uint8_t[_msg_buffer_len];
|
|
|
|
|
|
|
|
|
|
if (!_msg_buffer) {
|
|
|
|
|
PX4_ERR("failed to alloc message buffer");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-05-02 15:07:15 +02:00
|
|
|
if (!_writer.init()) {
|
2016-10-07 17:07:37 +02:00
|
|
|
PX4_ERR("writer init failed");
|
2016-05-02 14:44:45 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-10-22 11:49:46 +02:00
|
|
|
/* debug stats */
|
2016-04-25 17:36:13 -04:00
|
|
|
hrt_abstime timer_start = 0;
|
|
|
|
|
uint32_t total_bytes = 0;
|
|
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
px4_register_shutdown_hook(&Logger::request_stop_static);
|
2017-04-18 14:08:48 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (_log_mode == LogMode::boot_until_disarm || _log_mode == LogMode::boot_until_shutdown) {
|
2018-10-22 11:37:26 +02:00
|
|
|
start_log_file(LogType::Full);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-16 01:55:32 +02:00
|
|
|
/* init the update timer */
|
2019-06-07 16:41:30 -04:00
|
|
|
struct hrt_call timer_call {};
|
2018-05-03 10:58:00 +02:00
|
|
|
timer_callback_data_s timer_callback_data;
|
|
|
|
|
px4_sem_init(&timer_callback_data.semaphore, 0, 0);
|
2016-12-12 03:22:22 -10:00
|
|
|
/* timer_semaphore use case is a signal */
|
2018-05-03 10:58:00 +02:00
|
|
|
px4_sem_setprotocol(&timer_callback_data.semaphore, SEM_PRIO_NONE);
|
2016-12-12 03:22:22 -10:00
|
|
|
|
2017-03-01 12:10:41 +01:00
|
|
|
int polling_topic_sub = -1;
|
2016-12-12 03:22:22 -10:00
|
|
|
|
2017-03-01 12:10:41 +01:00
|
|
|
if (_polling_topic_meta) {
|
|
|
|
|
polling_topic_sub = orb_subscribe(_polling_topic_meta);
|
|
|
|
|
|
|
|
|
|
if (polling_topic_sub < 0) {
|
|
|
|
|
PX4_ERR("Failed to subscribe (%i)", errno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2018-05-03 10:58:00 +02:00
|
|
|
|
2018-05-03 11:36:51 +02:00
|
|
|
if (_writer.backend() & LogWriter::BackendFile) {
|
|
|
|
|
|
|
|
|
|
const pid_t pid_self = getpid();
|
2018-05-03 13:18:45 +02:00
|
|
|
const pthread_t writer_thread = _writer.thread_id_file();
|
2018-05-03 11:36:51 +02:00
|
|
|
|
|
|
|
|
// sched_note_start is already called from pthread_create and task_create,
|
|
|
|
|
// which means we can expect to find the tasks in system_load.tasks, as required in watchdog_initialize
|
2018-05-03 13:18:45 +02:00
|
|
|
watchdog_initialize(pid_self, writer_thread, timer_callback_data.watchdog_data);
|
2018-05-03 11:36:51 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-03 10:58:00 +02:00
|
|
|
hrt_call_every(&timer_call, _log_interval, _log_interval, timer_callback, &timer_callback_data);
|
2017-03-01 12:10:41 +01:00
|
|
|
}
|
2016-07-16 01:55:32 +02:00
|
|
|
|
2016-10-18 10:08:18 +02:00
|
|
|
// check for new subscription data
|
|
|
|
|
hrt_abstime next_subscribe_check = 0;
|
|
|
|
|
int next_subscribe_topic_index = -1; // this is used to distribute the checks over time
|
2016-07-16 01:55:32 +02:00
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
while (!should_exit()) {
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
// Start/stop logging (depending on logging mode, by default when arming/disarming)
|
2019-08-06 02:02:24 -04:00
|
|
|
const bool logging_started = start_stop_logging((MissionLogType)mission_log_mode);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-08 16:02:43 +02:00
|
|
|
if (logging_started) {
|
2016-04-25 17:36:13 -04:00
|
|
|
#ifdef DBGPRINT
|
2018-10-08 16:02:43 +02:00
|
|
|
timer_start = hrt_absolute_time();
|
|
|
|
|
total_bytes = 0;
|
2016-04-25 17:36:13 -04:00
|
|
|
#endif /* DBGPRINT */
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 16:02:43 +02:00
|
|
|
/* check for logging command from MAVLink (start/stop streaming) */
|
2019-08-06 02:02:24 -04:00
|
|
|
handle_vehicle_command_update();
|
2016-10-12 16:42:57 +02:00
|
|
|
|
2018-05-03 11:36:51 +02:00
|
|
|
if (timer_callback_data.watchdog_triggered) {
|
|
|
|
|
timer_callback_data.watchdog_triggered = false;
|
|
|
|
|
initialize_load_output(PrintLoadReason::Watchdog);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2017-10-16 14:54:37 +02:00
|
|
|
const hrt_abstime loop_time = hrt_absolute_time();
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (_writer.is_started(LogType::Full)) { // mission log only runs when full log is also started
|
2017-03-16 08:50:29 +01:00
|
|
|
|
|
|
|
|
/* check if we need to output the process load */
|
|
|
|
|
if (_next_load_print != 0 && loop_time >= _next_load_print) {
|
|
|
|
|
_next_load_print = 0;
|
2018-10-22 11:37:26 +02:00
|
|
|
write_load_output();
|
2017-03-16 08:50:29 +01:00
|
|
|
|
|
|
|
|
if (_should_stop_file_log) {
|
|
|
|
|
_should_stop_file_log = false;
|
2018-10-22 11:37:26 +02:00
|
|
|
stop_log_file(LogType::Full);
|
2017-03-16 08:50:29 +01:00
|
|
|
continue; // skip to next loop iteration
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-30 17:36:38 -06:00
|
|
|
/* Check if parameters have changed */
|
2017-12-07 11:05:42 +01:00
|
|
|
if (!_should_stop_file_log) { // do not record param changes after disarming
|
2019-07-28 11:55:52 -04:00
|
|
|
if (parameter_update_sub.updated()) {
|
|
|
|
|
// clear update
|
|
|
|
|
parameter_update_s pupdate;
|
|
|
|
|
parameter_update_sub.copy(&pupdate);
|
2019-08-06 02:02:24 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_changed_parameters(LogType::Full);
|
2017-12-07 11:05:42 +01:00
|
|
|
}
|
2016-04-30 17:36:38 -06:00
|
|
|
}
|
|
|
|
|
|
2016-05-06 09:31:15 +02:00
|
|
|
/* wait for lock on log buffer */
|
|
|
|
|
_writer.lock();
|
|
|
|
|
|
2016-10-18 10:08:18 +02:00
|
|
|
int sub_idx = 0;
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
for (LoggerSubscription &sub : _subscriptions) {
|
|
|
|
|
/* if this topic has been updated, copy the new data into the message buffer
|
|
|
|
|
* and write a message to the log
|
|
|
|
|
*/
|
2019-08-07 11:02:16 -04:00
|
|
|
const bool try_to_subscribe = (sub_idx == next_subscribe_topic_index);
|
|
|
|
|
|
|
|
|
|
if (copy_if_updated(sub_idx, _msg_buffer + sizeof(ulog_message_data_header_s), try_to_subscribe)) {
|
|
|
|
|
// each message consists of a header followed by an orb data object
|
|
|
|
|
const size_t msg_size = sizeof(ulog_message_data_header_s) + sub.get_topic()->o_size_no_padding;
|
|
|
|
|
const uint16_t write_msg_size = static_cast<uint16_t>(msg_size - ULOG_MSG_HEADER_LEN);
|
|
|
|
|
const uint16_t write_msg_id = sub.msg_id;
|
2016-05-03 16:50:12 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
//write one byte after another (necessary because of alignment)
|
|
|
|
|
_msg_buffer[0] = (uint8_t)write_msg_size;
|
|
|
|
|
_msg_buffer[1] = (uint8_t)(write_msg_size >> 8);
|
|
|
|
|
_msg_buffer[2] = static_cast<uint8_t>(ULogMessageType::DATA);
|
|
|
|
|
_msg_buffer[3] = (uint8_t)write_msg_id;
|
|
|
|
|
_msg_buffer[4] = (uint8_t)(write_msg_id >> 8);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
// PX4_INFO("topic: %s, size = %zu, out_size = %zu", sub.get_topic()->o_name, sub.get_topic()->o_size, msg_size);
|
2016-05-03 16:50:12 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
// full log
|
|
|
|
|
if (write_message(LogType::Full, _msg_buffer, msg_size)) {
|
2016-04-25 17:36:13 -04:00
|
|
|
|
|
|
|
|
#ifdef DBGPRINT
|
2019-08-07 11:02:16 -04:00
|
|
|
total_bytes += msg_size;
|
2016-05-06 11:37:29 +02:00
|
|
|
#endif /* DBGPRINT */
|
2019-08-07 11:02:16 -04:00
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
// mission log
|
|
|
|
|
if (sub_idx < _num_mission_subs) {
|
|
|
|
|
if (_writer.is_started(LogType::Mission)) {
|
|
|
|
|
if (_mission_subscriptions[sub_idx].next_write_time < (loop_time / 100000)) {
|
|
|
|
|
unsigned delta_time = _mission_subscriptions[sub_idx].min_delta_ms;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
if (delta_time > 0) {
|
|
|
|
|
_mission_subscriptions[sub_idx].next_write_time = (loop_time / 100000) + delta_time / 100;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-08-10 08:08:11 +02:00
|
|
|
write_message(LogType::Mission, _msg_buffer, msg_size);
|
2018-10-22 11:37:26 +02:00
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-18 10:08:18 +02:00
|
|
|
|
|
|
|
|
++sub_idx;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-06 02:02:24 -04:00
|
|
|
// check for new logging message(s)
|
|
|
|
|
log_message_s log_message;
|
2016-10-18 09:25:44 +02:00
|
|
|
|
2019-08-06 02:02:24 -04:00
|
|
|
if (_log_message_sub.update(&log_message)) {
|
2016-10-18 09:25:44 +02:00
|
|
|
const char *message = (const char *)log_message.text;
|
2016-05-24 15:05:49 +02:00
|
|
|
int message_len = strlen(message);
|
|
|
|
|
|
|
|
|
|
if (message_len > 0) {
|
2016-06-04 17:23:20 +02:00
|
|
|
uint16_t write_msg_size = sizeof(ulog_message_logging_s) - sizeof(ulog_message_logging_s::message)
|
2016-06-06 15:34:58 +02:00
|
|
|
- ULOG_MSG_HEADER_LEN + message_len;
|
2016-06-04 17:23:20 +02:00
|
|
|
_msg_buffer[0] = (uint8_t)write_msg_size;
|
|
|
|
|
_msg_buffer[1] = (uint8_t)(write_msg_size >> 8);
|
|
|
|
|
_msg_buffer[2] = static_cast<uint8_t>(ULogMessageType::LOGGING);
|
2016-10-18 09:25:44 +02:00
|
|
|
_msg_buffer[3] = log_message.severity + '0';
|
|
|
|
|
memcpy(_msg_buffer + 4, &log_message.timestamp, sizeof(ulog_message_logging_s::timestamp));
|
2016-06-06 15:34:58 +02:00
|
|
|
strncpy((char *)(_msg_buffer + 12), message, sizeof(ulog_message_logging_s::message));
|
2016-06-04 17:23:20 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(LogType::Full, _msg_buffer, write_msg_size + ULOG_MSG_HEADER_LEN);
|
2016-05-24 15:05:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 11:00:55 +02:00
|
|
|
// Add sync magic
|
|
|
|
|
if (loop_time - _last_sync_time > 500_ms) {
|
|
|
|
|
uint16_t write_msg_size = static_cast<uint16_t>(sizeof(ulog_message_sync_s) - ULOG_MSG_HEADER_LEN);
|
|
|
|
|
_msg_buffer[0] = (uint8_t)write_msg_size;
|
|
|
|
|
_msg_buffer[1] = (uint8_t)(write_msg_size >> 8);
|
|
|
|
|
_msg_buffer[2] = static_cast<uint8_t>(ULogMessageType::SYNC);
|
|
|
|
|
|
|
|
|
|
// sync byte sequence
|
|
|
|
|
_msg_buffer[3] = 0x2F;
|
|
|
|
|
_msg_buffer[4] = 0x73;
|
|
|
|
|
_msg_buffer[5] = 0x13;
|
|
|
|
|
_msg_buffer[6] = 0x20;
|
|
|
|
|
_msg_buffer[7] = 0x25;
|
|
|
|
|
_msg_buffer[8] = 0x0C;
|
|
|
|
|
_msg_buffer[9] = 0xBB;
|
|
|
|
|
_msg_buffer[10] = 0x12;
|
|
|
|
|
|
|
|
|
|
write_message(LogType::Full, _msg_buffer, write_msg_size + ULOG_MSG_HEADER_LEN);
|
|
|
|
|
_last_sync_time = loop_time;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
// update buffer statistics
|
|
|
|
|
for (int i = 0; i < (int)LogType::Count; ++i) {
|
2019-08-06 02:02:24 -04:00
|
|
|
if (!_statistics[i].dropout_start && (_writer.get_buffer_fill_count_file((LogType)i) > _statistics[i].high_water)) {
|
2018-10-22 11:37:26 +02:00
|
|
|
_statistics[i].high_water = _writer.get_buffer_fill_count_file((LogType)i);
|
|
|
|
|
}
|
2016-05-06 11:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
/* release the log buffer */
|
|
|
|
|
_writer.unlock();
|
|
|
|
|
|
2019-08-10 08:08:11 +02:00
|
|
|
/* notify the writer thread */
|
|
|
|
|
_writer.notify();
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-10-18 10:08:18 +02:00
|
|
|
/* subscription update */
|
|
|
|
|
if (next_subscribe_topic_index != -1) {
|
2018-06-30 10:58:44 -04:00
|
|
|
if (++next_subscribe_topic_index >= (int)_subscriptions.size()) {
|
2016-10-18 10:08:18 +02:00
|
|
|
next_subscribe_topic_index = -1;
|
2017-03-16 08:50:29 +01:00
|
|
|
next_subscribe_check = loop_time + TRY_SUBSCRIBE_INTERVAL;
|
2016-10-18 10:08:18 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-16 08:50:29 +01:00
|
|
|
} else if (loop_time > next_subscribe_check) {
|
2016-10-18 10:08:18 +02:00
|
|
|
next_subscribe_topic_index = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:49:46 +02:00
|
|
|
debug_print_buffer(total_bytes, timer_start);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2017-10-16 14:54:37 +02:00
|
|
|
} else { // not logging
|
|
|
|
|
|
|
|
|
|
// try to subscribe to new topics, even if we don't log, so that:
|
|
|
|
|
// - we avoid subscribing to many topics at once, when logging starts
|
|
|
|
|
// - we'll get the data immediately once we start logging (no need to wait for the next subscribe timeout)
|
|
|
|
|
if (next_subscribe_topic_index != -1) {
|
2019-08-07 11:02:16 -04:00
|
|
|
if (!_subscriptions[next_subscribe_topic_index].valid()) {
|
|
|
|
|
_subscriptions[next_subscribe_topic_index].subscribe();
|
2017-10-16 14:54:37 +02:00
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-06-30 10:58:44 -04:00
|
|
|
if (++next_subscribe_topic_index >= (int)_subscriptions.size()) {
|
2017-10-16 14:54:37 +02:00
|
|
|
next_subscribe_topic_index = -1;
|
|
|
|
|
next_subscribe_check = loop_time + TRY_SUBSCRIBE_INTERVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (loop_time > next_subscribe_check) {
|
|
|
|
|
next_subscribe_topic_index = 0;
|
|
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2017-03-01 12:10:41 +01:00
|
|
|
// wait for next loop iteration...
|
|
|
|
|
if (polling_topic_sub >= 0) {
|
|
|
|
|
px4_pollfd_struct_t fds[1];
|
|
|
|
|
fds[0].fd = polling_topic_sub;
|
|
|
|
|
fds[0].events = POLLIN;
|
|
|
|
|
int pret = px4_poll(fds, 1, 1000);
|
|
|
|
|
|
|
|
|
|
if (pret < 0) {
|
|
|
|
|
PX4_ERR("poll failed (%i)", pret);
|
|
|
|
|
|
|
|
|
|
} else if (pret != 0) {
|
|
|
|
|
if (fds[0].revents & POLLIN) {
|
2018-10-22 11:37:26 +02:00
|
|
|
// need to to an orb_copy so that the next poll will not return immediately
|
2017-03-01 12:10:41 +01:00
|
|
|
orb_copy(_polling_topic_meta, polling_topic_sub, _msg_buffer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* We wait on the semaphore, which periodically gets updated by a high-resolution timer.
|
|
|
|
|
* The simpler alternative would be:
|
|
|
|
|
* usleep(max(300, _log_interval - elapsed_time_since_loop_start));
|
|
|
|
|
* And on linux this is quite accurate as well, but under NuttX it is not accurate,
|
|
|
|
|
* because usleep() has only a granularity of CONFIG_MSEC_PER_TICK (=1ms).
|
|
|
|
|
*/
|
2019-10-27 19:33:10 -04:00
|
|
|
while (px4_sem_wait(&timer_callback_data.semaphore) != 0) {}
|
2017-03-01 12:10:41 +01:00
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
stop_log_file(LogType::Full);
|
|
|
|
|
stop_log_file(LogType::Mission);
|
2017-03-16 08:50:29 +01:00
|
|
|
|
2016-07-16 01:55:32 +02:00
|
|
|
hrt_cancel(&timer_call);
|
2018-05-03 10:58:00 +02:00
|
|
|
px4_sem_destroy(&timer_callback_data.semaphore);
|
2016-07-16 01:55:32 +02:00
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
// stop the writer thread
|
|
|
|
|
_writer.thread_stop();
|
|
|
|
|
|
2017-03-01 12:10:41 +01:00
|
|
|
if (polling_topic_sub >= 0) {
|
|
|
|
|
orb_unsubscribe(polling_topic_sub);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 11:05:05 +02:00
|
|
|
if (_mavlink_log_pub) {
|
|
|
|
|
orb_unadvertise(_mavlink_log_pub);
|
|
|
|
|
_mavlink_log_pub = nullptr;
|
|
|
|
|
}
|
2016-10-12 16:42:57 +02:00
|
|
|
|
2017-04-27 17:05:37 +02:00
|
|
|
px4_unregister_shutdown_hook(&Logger::request_stop_static);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:49:46 +02:00
|
|
|
void Logger::debug_print_buffer(uint32_t &total_bytes, hrt_abstime &timer_start)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DBGPRINT
|
|
|
|
|
double deltat = (double)(hrt_absolute_time() - timer_start) * 1e-6;
|
|
|
|
|
|
|
|
|
|
if (deltat > 4.0) {
|
|
|
|
|
struct mallinfo alloc_info = mallinfo();
|
|
|
|
|
double throughput = total_bytes / deltat;
|
|
|
|
|
PX4_INFO("%8.1f kB/s, %zu highWater, %d dropouts, %5.3f sec max, free heap: %d",
|
2019-06-07 16:41:30 -04:00
|
|
|
throughput / 1.e3, _statistics[0].high_water, _statistics[0].write_dropouts,
|
|
|
|
|
(double)_statistics[0].max_dropout_duration, alloc_info.fordblks);
|
2018-10-22 11:49:46 +02:00
|
|
|
|
|
|
|
|
_statistics[0].high_water = 0;
|
|
|
|
|
_statistics[0].max_dropout_duration = 0.f;
|
|
|
|
|
total_bytes = 0;
|
|
|
|
|
timer_start = hrt_absolute_time();
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:49:46 +02:00
|
|
|
#endif /* DBGPRINT */
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 02:02:24 -04:00
|
|
|
bool Logger::start_stop_logging(MissionLogType mission_log_type)
|
2018-10-08 16:02:43 +02:00
|
|
|
{
|
|
|
|
|
bool bret = false;
|
2019-04-17 07:07:46 +02:00
|
|
|
bool want_start = false;
|
|
|
|
|
bool want_stop = false;
|
|
|
|
|
|
|
|
|
|
if (_log_mode == LogMode::rc_aux1) {
|
|
|
|
|
|
2019-08-06 02:02:24 -04:00
|
|
|
// aux1-based logging
|
|
|
|
|
manual_control_setpoint_s manual_sp;
|
|
|
|
|
|
|
|
|
|
if (_manual_control_sp_sub.update(&manual_sp)) {
|
|
|
|
|
|
|
|
|
|
bool should_start = ((manual_sp.aux1 > 0.3f) || _manually_logging_override);
|
2019-04-17 07:07:46 +02:00
|
|
|
|
|
|
|
|
if (_prev_state != should_start) {
|
|
|
|
|
_prev_state = should_start;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (should_start) {
|
|
|
|
|
want_start = true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
want_stop = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-08 16:02:43 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
} else {
|
|
|
|
|
// arming-based logging
|
2019-08-06 02:02:24 -04:00
|
|
|
vehicle_status_s vehicle_status;
|
|
|
|
|
|
|
|
|
|
if (_vehicle_status_sub.update(&vehicle_status)) {
|
2018-10-08 16:02:43 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
bool armed = (vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED) || _manually_logging_override;
|
2018-10-08 16:02:43 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (_prev_state != armed && _log_mode != LogMode::boot_until_shutdown) {
|
|
|
|
|
_prev_state = armed;
|
2018-10-08 16:02:43 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (armed) {
|
|
|
|
|
want_start = true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
want_stop = true;
|
2018-10-08 16:02:43 +02:00
|
|
|
}
|
2019-04-17 07:07:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-08 16:02:43 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (want_start) {
|
|
|
|
|
if (_should_stop_file_log) { // happens on quick stop/start toggling
|
|
|
|
|
_should_stop_file_log = false;
|
|
|
|
|
stop_log_file(LogType::Full);
|
|
|
|
|
}
|
2018-10-08 16:02:43 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
start_log_file(LogType::Full);
|
|
|
|
|
bret = true;
|
2018-10-22 11:37:26 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (mission_log_type != MissionLogType::Disabled) {
|
|
|
|
|
start_log_file(LogType::Mission);
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
} else if (want_stop) {
|
|
|
|
|
// delayed stop: we measure the process loads and then stop
|
|
|
|
|
initialize_load_output(PrintLoadReason::Postflight);
|
|
|
|
|
_should_stop_file_log = true;
|
2018-10-22 11:37:26 +02:00
|
|
|
|
2019-04-17 07:07:46 +02:00
|
|
|
if (mission_log_type != MissionLogType::Disabled) {
|
|
|
|
|
stop_log_file(LogType::Mission);
|
2018-10-08 16:02:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-08 16:02:43 +02:00
|
|
|
return bret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 02:02:24 -04:00
|
|
|
void Logger::handle_vehicle_command_update()
|
2018-10-08 16:02:43 +02:00
|
|
|
{
|
2019-08-06 02:02:24 -04:00
|
|
|
vehicle_command_s command;
|
2018-10-08 16:02:43 +02:00
|
|
|
|
2019-08-06 02:02:24 -04:00
|
|
|
if (_vehicle_command_sub.update(&command)) {
|
2018-10-08 16:02:43 +02:00
|
|
|
|
|
|
|
|
if (command.command == vehicle_command_s::VEHICLE_CMD_LOGGING_START) {
|
2019-08-06 02:02:24 -04:00
|
|
|
|
2018-10-08 16:02:43 +02:00
|
|
|
if ((int)(command.param1 + 0.5f) != 0) {
|
2019-07-03 16:30:21 -04:00
|
|
|
ack_vehicle_command(&command, vehicle_command_s::VEHICLE_CMD_RESULT_UNSUPPORTED);
|
2018-10-08 16:02:43 +02:00
|
|
|
|
|
|
|
|
} else if (can_start_mavlink_log()) {
|
2019-07-03 16:30:21 -04:00
|
|
|
ack_vehicle_command(&command, vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED);
|
2018-10-08 16:02:43 +02:00
|
|
|
start_log_mavlink();
|
|
|
|
|
|
|
|
|
|
} else {
|
2019-07-03 16:30:21 -04:00
|
|
|
ack_vehicle_command(&command, vehicle_command_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED);
|
2018-10-08 16:02:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (command.command == vehicle_command_s::VEHICLE_CMD_LOGGING_STOP) {
|
|
|
|
|
stop_log_mavlink();
|
2019-07-03 16:30:21 -04:00
|
|
|
ack_vehicle_command(&command, vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED);
|
2018-10-08 16:02:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
bool Logger::write_message(LogType type, void *ptr, size_t size)
|
2016-05-24 15:05:49 +02:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
Statistics &stats = _statistics[(int)type];
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (_writer.write_message(type, ptr, size, stats.dropout_start) != -1) {
|
2016-05-24 15:05:49 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (stats.dropout_start) {
|
|
|
|
|
float dropout_duration = (float)(hrt_elapsed_time(&stats.dropout_start) / 1000) / 1.e3f;
|
2016-05-24 15:05:49 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (dropout_duration > stats.max_dropout_duration) {
|
|
|
|
|
stats.max_dropout_duration = dropout_duration;
|
2016-05-24 15:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
stats.dropout_start = 0;
|
2016-05-24 15:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (!stats.dropout_start) {
|
|
|
|
|
stats.dropout_start = hrt_absolute_time();
|
|
|
|
|
++stats.write_dropouts;
|
|
|
|
|
stats.high_water = 0;
|
2016-05-24 15:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
int Logger::create_log_dir(LogType type, tm *tt, char *log_dir, int log_dir_len)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2019-06-07 16:41:30 -04:00
|
|
|
LogFileName &file_name = _file_name[(int)type];
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
/* create dir on sdcard if needed */
|
|
|
|
|
int n = snprintf(log_dir, log_dir_len, "%s/", LOG_ROOT[(int)type]);
|
2016-07-27 09:55:29 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (n >= log_dir_len) {
|
|
|
|
|
PX4_ERR("log path too long");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2016-07-27 09:55:29 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (tt) {
|
|
|
|
|
strftime(file_name.log_dir, sizeof(LogFileName::log_dir), "%Y-%m-%d", tt);
|
|
|
|
|
strncpy(log_dir + n, file_name.log_dir, log_dir_len - n);
|
|
|
|
|
int mkdir_ret = mkdir(log_dir, S_IRWXU | S_IRWXG | S_IRWXO);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-05-11 10:08:25 +02:00
|
|
|
if (mkdir_ret != OK && errno != EEXIST) {
|
2018-10-22 11:37:26 +02:00
|
|
|
PX4_ERR("failed creating new dir: %s", log_dir);
|
2016-04-25 17:36:13 -04:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 10:08:25 +02:00
|
|
|
} else {
|
2018-10-22 11:37:26 +02:00
|
|
|
uint16_t dir_number = file_name.sess_dir_index;
|
|
|
|
|
|
|
|
|
|
if (file_name.has_log_dir) {
|
|
|
|
|
strncpy(log_dir + n, file_name.log_dir, log_dir_len - n);
|
|
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-05-11 10:08:25 +02:00
|
|
|
/* look for the next dir that does not exist */
|
2018-10-22 11:37:26 +02:00
|
|
|
while (!file_name.has_log_dir) {
|
|
|
|
|
/* format log dir: e.g. /fs/microsd/log/sess001 */
|
|
|
|
|
int n2 = snprintf(file_name.log_dir, sizeof(LogFileName::log_dir), "sess%03u", dir_number);
|
2016-07-27 09:55:29 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (n2 >= (int)sizeof(LogFileName::log_dir)) {
|
2017-04-07 17:51:06 +02:00
|
|
|
PX4_ERR("log path too long (%i)", n);
|
2016-07-27 09:55:29 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
strncpy(log_dir + n, file_name.log_dir, log_dir_len - n);
|
|
|
|
|
int mkdir_ret = mkdir(log_dir, S_IRWXU | S_IRWXG | S_IRWXO);
|
2016-05-11 10:08:25 +02:00
|
|
|
|
|
|
|
|
if (mkdir_ret == 0) {
|
2018-10-22 11:37:26 +02:00
|
|
|
PX4_DEBUG("log dir created: %s", log_dir);
|
|
|
|
|
file_name.has_log_dir = true;
|
2016-05-11 10:08:25 +02:00
|
|
|
|
|
|
|
|
} else if (errno != EEXIST) {
|
2018-10-22 11:37:26 +02:00
|
|
|
PX4_ERR("failed creating new dir: %s (%i)", log_dir, errno);
|
2016-05-11 10:08:25 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* dir exists already */
|
|
|
|
|
dir_number++;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
file_name.has_log_dir = true;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
return strlen(log_dir);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_size)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2017-04-27 20:54:38 -04:00
|
|
|
tm tt = {};
|
2016-05-11 10:08:25 +02:00
|
|
|
bool time_ok = false;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-05-11 10:08:25 +02:00
|
|
|
if (_log_name_timestamp) {
|
2018-10-08 15:28:52 +02:00
|
|
|
int32_t utc_offset = 0;
|
|
|
|
|
|
|
|
|
|
if (_log_utc_offset != PARAM_INVALID) {
|
|
|
|
|
param_get(_log_utc_offset, &utc_offset);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
/* use RTC time for log file naming, e.g. /fs/microsd/log/2014-01-19/19_37_52.ulg */
|
2018-10-08 15:28:52 +02:00
|
|
|
time_ok = util::get_log_time(&tt, utc_offset * 60, false);
|
2016-05-11 10:08:25 +02:00
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-05-24 15:07:11 +02:00
|
|
|
const char *replay_suffix = "";
|
|
|
|
|
|
|
|
|
|
if (_replay_file_name) {
|
|
|
|
|
replay_suffix = "_replayed";
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
char *log_file_name = _file_name[(int)type].log_file_name;
|
2016-05-24 15:07:11 +02:00
|
|
|
|
2016-05-11 10:08:25 +02:00
|
|
|
if (time_ok) {
|
2018-10-22 11:37:26 +02:00
|
|
|
int n = create_log_dir(type, &tt, file_name, file_name_size);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (n < 0) {
|
2016-05-11 10:08:25 +02:00
|
|
|
return -1;
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2016-08-12 09:04:05 +02:00
|
|
|
char log_file_name_time[16] = "";
|
|
|
|
|
strftime(log_file_name_time, sizeof(log_file_name_time), "%H_%M_%S", &tt);
|
2018-10-22 11:37:26 +02:00
|
|
|
snprintf(log_file_name, sizeof(LogFileName::log_file_name), "%s%s.ulg", log_file_name_time, replay_suffix);
|
|
|
|
|
snprintf(file_name + n, file_name_size - n, "/%s", log_file_name);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-05-11 10:08:25 +02:00
|
|
|
} else {
|
2018-10-22 11:37:26 +02:00
|
|
|
int n = create_log_dir(type, nullptr, file_name, file_name_size);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (n < 0) {
|
2016-05-11 10:08:25 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t file_number = 1; // start with file log001
|
|
|
|
|
|
|
|
|
|
/* look for the next file that does not exist */
|
|
|
|
|
while (file_number <= MAX_NO_LOGFILE) {
|
2018-10-22 11:37:26 +02:00
|
|
|
/* format log file path: e.g. /fs/microsd/log/sess001/log001.ulg */
|
|
|
|
|
snprintf(log_file_name, sizeof(LogFileName::log_file_name), "log%03u%s.ulg", file_number, replay_suffix);
|
|
|
|
|
snprintf(file_name + n, file_name_size - n, "/%s", log_file_name);
|
2016-05-11 10:08:25 +02:00
|
|
|
|
2018-10-08 15:28:52 +02:00
|
|
|
if (!util::file_exist(file_name)) {
|
2016-05-11 10:08:25 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_number++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file_number > MAX_NO_LOGFILE) {
|
|
|
|
|
/* we should not end up here, either we have more than MAX_NO_LOGFILE on the SD card, or another problem */
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-24 15:07:11 +02:00
|
|
|
void Logger::setReplayFile(const char *file_name)
|
|
|
|
|
{
|
|
|
|
|
if (_replay_file_name) {
|
|
|
|
|
free(_replay_file_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_replay_file_name = strdup(file_name);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::start_log_file(LogType type)
|
2016-05-11 10:08:25 +02:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
if (_writer.is_started(type, LogWriter::BackendFile) || (_writer.backend() & LogWriter::BackendFile) == 0) {
|
2016-05-11 15:32:29 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
PX4_INFO("Start file log (type: %s)", log_type_str(type));
|
2016-05-11 10:08:25 +02:00
|
|
|
|
2016-07-27 09:55:29 +02:00
|
|
|
char file_name[LOG_DIR_LEN] = "";
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (get_log_file_name(type, file_name, sizeof(file_name))) {
|
|
|
|
|
PX4_ERR("failed to get log file name");
|
2016-04-25 17:36:13 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (type == LogType::Full) {
|
|
|
|
|
/* print logging path, important to find log file later */
|
|
|
|
|
mavlink_log_info(&_mavlink_log_pub, "[logger] file: %s", file_name);
|
|
|
|
|
}
|
2016-05-11 11:05:05 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
_writer.start_log_file(type, file_name);
|
2016-10-12 16:42:57 +02:00
|
|
|
_writer.select_write_backend(LogWriter::BackendFile);
|
2016-10-08 09:48:52 +02:00
|
|
|
_writer.set_need_reliable_transfer(true);
|
2018-10-22 11:37:26 +02:00
|
|
|
write_header(type);
|
|
|
|
|
write_version(type);
|
|
|
|
|
write_formats(type);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (type == LogType::Full) {
|
|
|
|
|
write_parameters(type);
|
|
|
|
|
write_perf_data(true);
|
2019-04-08 07:53:45 +02:00
|
|
|
write_console_output();
|
2018-10-22 11:37:26 +02:00
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_all_add_logged_msg(type);
|
2016-10-08 09:48:52 +02:00
|
|
|
_writer.set_need_reliable_transfer(false);
|
2016-10-12 16:42:57 +02:00
|
|
|
_writer.unselect_write_backend();
|
2016-05-04 11:23:51 +02:00
|
|
|
_writer.notify();
|
2016-10-12 15:35:20 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (type == LogType::Full) {
|
|
|
|
|
/* reset performance counters to get in-flight min and max values in post flight log */
|
|
|
|
|
perf_reset_all();
|
2017-03-16 08:50:29 +01:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
initialize_load_output(PrintLoadReason::Preflight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_statistics[(int)type].start_time_file = hrt_absolute_time();
|
2017-03-16 08:50:29 +01:00
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::stop_log_file(LogType type)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
if (!_writer.is_started(type, LogWriter::BackendFile)) {
|
2017-03-16 08:50:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (type == LogType::Full) {
|
|
|
|
|
_writer.set_need_reliable_transfer(true);
|
|
|
|
|
write_perf_data(false);
|
|
|
|
|
_writer.set_need_reliable_transfer(false);
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
_writer.stop_log_file(type);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
2016-10-12 16:42:57 +02:00
|
|
|
void Logger::start_log_mavlink()
|
|
|
|
|
{
|
|
|
|
|
if (!can_start_mavlink_log()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PX4_INFO("Start mavlink log");
|
|
|
|
|
|
|
|
|
|
_writer.start_log_mavlink();
|
|
|
|
|
_writer.select_write_backend(LogWriter::BackendMavlink);
|
|
|
|
|
_writer.set_need_reliable_transfer(true);
|
2018-10-22 11:37:26 +02:00
|
|
|
write_header(LogType::Full);
|
|
|
|
|
write_version(LogType::Full);
|
|
|
|
|
write_formats(LogType::Full);
|
|
|
|
|
write_parameters(LogType::Full);
|
2017-03-16 08:50:29 +01:00
|
|
|
write_perf_data(true);
|
2019-04-08 07:53:45 +02:00
|
|
|
write_console_output();
|
2018-10-22 11:37:26 +02:00
|
|
|
write_all_add_logged_msg(LogType::Full);
|
2016-10-12 16:42:57 +02:00
|
|
|
_writer.set_need_reliable_transfer(false);
|
|
|
|
|
_writer.unselect_write_backend();
|
|
|
|
|
_writer.notify();
|
2017-03-16 08:50:29 +01:00
|
|
|
|
2018-05-03 10:54:56 +02:00
|
|
|
initialize_load_output(PrintLoadReason::Preflight);
|
2016-10-12 16:42:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Logger::stop_log_mavlink()
|
|
|
|
|
{
|
2017-03-16 08:50:29 +01:00
|
|
|
// don't write perf data since a client does not expect more data after a stop command
|
2016-10-12 16:42:57 +02:00
|
|
|
PX4_INFO("Stop mavlink log");
|
|
|
|
|
_writer.stop_log_mavlink();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 08:50:29 +01:00
|
|
|
struct perf_callback_data_t {
|
|
|
|
|
Logger *logger;
|
|
|
|
|
int counter;
|
|
|
|
|
bool preflight;
|
|
|
|
|
char *buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void Logger::perf_iterate_callback(perf_counter_t handle, void *user)
|
|
|
|
|
{
|
|
|
|
|
perf_callback_data_t *callback_data = (perf_callback_data_t *)user;
|
2019-04-08 07:53:45 +02:00
|
|
|
const int buffer_length = 220;
|
2017-03-16 08:50:29 +01:00
|
|
|
char buffer[buffer_length];
|
2017-07-04 10:41:12 +02:00
|
|
|
const char *perf_name;
|
2017-03-16 08:50:29 +01:00
|
|
|
|
|
|
|
|
perf_print_counter_buffer(buffer, buffer_length, handle);
|
|
|
|
|
|
|
|
|
|
if (callback_data->preflight) {
|
2017-07-04 10:41:12 +02:00
|
|
|
perf_name = "perf_counter_preflight";
|
2017-03-16 08:50:29 +01:00
|
|
|
|
|
|
|
|
} else {
|
2017-07-04 10:41:12 +02:00
|
|
|
perf_name = "perf_counter_postflight";
|
2017-03-16 08:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
callback_data->logger->write_info_multiple(LogType::Full, perf_name, buffer, callback_data->counter != 0);
|
2017-03-16 08:50:29 +01:00
|
|
|
++callback_data->counter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Logger::write_perf_data(bool preflight)
|
|
|
|
|
{
|
2017-04-27 20:54:38 -04:00
|
|
|
perf_callback_data_t callback_data = {};
|
2017-03-16 08:50:29 +01:00
|
|
|
callback_data.logger = this;
|
|
|
|
|
callback_data.counter = 0;
|
|
|
|
|
callback_data.preflight = preflight;
|
|
|
|
|
|
|
|
|
|
// write the perf counters
|
|
|
|
|
perf_iterate_all(perf_iterate_callback, &callback_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::print_load_callback(void *user)
|
|
|
|
|
{
|
|
|
|
|
perf_callback_data_t *callback_data = (perf_callback_data_t *)user;
|
2017-07-04 10:41:12 +02:00
|
|
|
const char *perf_name;
|
2017-03-16 08:50:29 +01:00
|
|
|
|
|
|
|
|
if (!callback_data->buffer) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-03 10:54:56 +02:00
|
|
|
switch (callback_data->logger->_print_load_reason) {
|
2019-06-07 16:41:30 -04:00
|
|
|
case PrintLoadReason::Preflight:
|
|
|
|
|
perf_name = "perf_top_preflight";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PrintLoadReason::Postflight:
|
|
|
|
|
perf_name = "perf_top_postflight";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PrintLoadReason::Watchdog:
|
|
|
|
|
perf_name = "perf_top_watchdog";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
perf_name = "perf_top";
|
|
|
|
|
break;
|
2017-03-16 08:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-07 16:41:30 -04:00
|
|
|
callback_data->logger->write_info_multiple(LogType::Full, perf_name, callback_data->buffer,
|
|
|
|
|
callback_data->counter != 0);
|
2017-03-16 08:50:29 +01:00
|
|
|
++callback_data->counter;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-03 10:54:56 +02:00
|
|
|
void Logger::initialize_load_output(PrintLoadReason reason)
|
2017-03-16 08:50:29 +01:00
|
|
|
{
|
|
|
|
|
perf_callback_data_t callback_data;
|
|
|
|
|
callback_data.logger = this;
|
|
|
|
|
callback_data.counter = 0;
|
2017-03-16 09:31:37 +01:00
|
|
|
callback_data.buffer = nullptr;
|
2017-03-16 08:50:29 +01:00
|
|
|
char buffer[140];
|
|
|
|
|
hrt_abstime curr_time = hrt_absolute_time();
|
|
|
|
|
init_print_load_s(curr_time, &_load);
|
|
|
|
|
// this will not yet print anything
|
|
|
|
|
print_load_buffer(curr_time, buffer, sizeof(buffer), print_load_callback, &callback_data, &_load);
|
|
|
|
|
_next_load_print = curr_time + 1000000;
|
2018-05-03 10:54:56 +02:00
|
|
|
_print_load_reason = reason;
|
2017-03-16 08:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-03 10:54:56 +02:00
|
|
|
void Logger::write_load_output()
|
2017-03-16 08:50:29 +01:00
|
|
|
{
|
2018-05-03 11:36:51 +02:00
|
|
|
if (_print_load_reason == PrintLoadReason::Watchdog) {
|
|
|
|
|
PX4_ERR("Writing watchdog data"); // this is just that we see it easily in the log
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2017-04-27 20:54:38 -04:00
|
|
|
perf_callback_data_t callback_data = {};
|
2017-03-16 08:50:29 +01:00
|
|
|
char buffer[140];
|
|
|
|
|
callback_data.logger = this;
|
|
|
|
|
callback_data.counter = 0;
|
|
|
|
|
callback_data.buffer = buffer;
|
|
|
|
|
hrt_abstime curr_time = hrt_absolute_time();
|
|
|
|
|
_writer.set_need_reliable_transfer(true);
|
|
|
|
|
// TODO: maybe we should restrict the output to a selected backend (eg. when file logging is running
|
|
|
|
|
// and mavlink log is started, this will be added to the file as well)
|
|
|
|
|
print_load_buffer(curr_time, buffer, sizeof(buffer), print_load_callback, &callback_data, &_load);
|
|
|
|
|
_writer.set_need_reliable_transfer(false);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 07:53:45 +02:00
|
|
|
void Logger::write_console_output()
|
|
|
|
|
{
|
|
|
|
|
const int buffer_length = 220;
|
|
|
|
|
char buffer[buffer_length];
|
|
|
|
|
int size = px4_console_buffer_size();
|
|
|
|
|
int offset = -1;
|
|
|
|
|
bool first = true;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-04-08 07:53:45 +02:00
|
|
|
while (size > 0) {
|
2019-06-07 16:41:30 -04:00
|
|
|
int read_size = px4_console_buffer_read(buffer, buffer_length - 1, &offset);
|
|
|
|
|
|
2019-04-08 07:53:45 +02:00
|
|
|
if (read_size <= 0) { break; }
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-04-08 07:53:45 +02:00
|
|
|
buffer[math::min(read_size, size)] = '\0';
|
|
|
|
|
write_info_multiple(LogType::Full, "boot_console_output", buffer, !first);
|
|
|
|
|
|
|
|
|
|
size -= read_size;
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-07 16:41:30 -04:00
|
|
|
void Logger::write_format(LogType type, const orb_metadata &meta, WrittenFormats &written_formats,
|
|
|
|
|
ulog_message_format_s &msg, int level)
|
2018-10-09 06:21:10 +02:00
|
|
|
{
|
|
|
|
|
if (level > 3) {
|
|
|
|
|
// precaution: limit recursion level. If we land here it's either a bug or nested topic definitions. In the
|
|
|
|
|
// latter case, increase the maximum level.
|
|
|
|
|
PX4_ERR("max recursion level reached (%i)", level);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 16:16:22 +02:00
|
|
|
// check if we already wrote the format
|
|
|
|
|
for (const auto &written_format : written_formats) {
|
|
|
|
|
if (written_format == &meta) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
// Write the current format (we don't need to check if we already added it to written_formats)
|
|
|
|
|
int format_len = snprintf(msg.format, sizeof(msg.format), "%s:%s", meta.o_name, meta.o_fields);
|
|
|
|
|
size_t msg_size = sizeof(msg) - sizeof(msg.format) + format_len;
|
|
|
|
|
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, &msg, msg_size);
|
2018-10-09 06:21:10 +02:00
|
|
|
|
|
|
|
|
if (!written_formats.push_back(&meta)) {
|
|
|
|
|
PX4_ERR("Array too small");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now go through the fields and check for nested type usages.
|
|
|
|
|
// o_fields looks like this for example: "uint64_t timestamp;uint8_t[5] array;"
|
2019-06-07 16:41:30 -04:00
|
|
|
const char *fmt = meta.o_fields;
|
|
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
while (fmt && *fmt) {
|
|
|
|
|
// extract the type name
|
|
|
|
|
char type_name[64];
|
|
|
|
|
const char *space = strchr(fmt, ' ');
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
if (!space) {
|
|
|
|
|
PX4_ERR("invalid format %s", fmt);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
const char *array_start = strchr(fmt, '['); // check for an array
|
|
|
|
|
|
|
|
|
|
int type_length;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
if (array_start && array_start < space) {
|
|
|
|
|
type_length = array_start - fmt;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
} else {
|
|
|
|
|
type_length = space - fmt;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
if (type_length >= (int)sizeof(type_name)) {
|
|
|
|
|
PX4_ERR("buf len too small");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
memcpy(type_name, fmt, type_length);
|
|
|
|
|
type_name[type_length] = '\0';
|
|
|
|
|
|
|
|
|
|
// ignore built-in types
|
|
|
|
|
if (strcmp(type_name, "int8_t") != 0 &&
|
2019-06-07 16:41:30 -04:00
|
|
|
strcmp(type_name, "uint8_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "int16_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "uint16_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "int16_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "uint16_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "int32_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "uint32_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "int64_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "uint64_t") != 0 &&
|
|
|
|
|
strcmp(type_name, "float") != 0 &&
|
|
|
|
|
strcmp(type_name, "double") != 0 &&
|
2019-07-03 10:00:50 +02:00
|
|
|
strcmp(type_name, "bool") != 0 &&
|
|
|
|
|
strcmp(type_name, "char") != 0) {
|
2018-10-09 06:21:10 +02:00
|
|
|
|
|
|
|
|
// find orb meta for type
|
2019-06-07 16:41:30 -04:00
|
|
|
const orb_metadata *const *topics = orb_get_topics();
|
2018-10-09 06:21:10 +02:00
|
|
|
const orb_metadata *found_topic = nullptr;
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
for (size_t i = 0; i < orb_topics_count(); i++) {
|
|
|
|
|
if (strcmp(topics[i]->o_name, type_name) == 0) {
|
|
|
|
|
found_topic = topics[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
if (found_topic) {
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-08-21 16:16:22 +02:00
|
|
|
write_format(type, *found_topic, written_formats, msg, level + 1);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
} else {
|
|
|
|
|
PX4_ERR("No definition for topic %s found", fmt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt = strchr(fmt, ';');
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
if (fmt) { ++fmt; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_formats(LogType type)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
|
|
|
|
_writer.lock();
|
|
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
// both of these are large and thus we need to be careful in terms of stack size requirements
|
|
|
|
|
ulog_message_format_s msg;
|
|
|
|
|
WrittenFormats written_formats;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-10-09 06:21:10 +02:00
|
|
|
// write all subscribed formats
|
2018-10-22 11:37:26 +02:00
|
|
|
size_t sub_count = _subscriptions.size();
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (type == LogType::Mission) {
|
|
|
|
|
sub_count = _num_mission_subs;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
for (size_t i = 0; i < sub_count; ++i) {
|
|
|
|
|
const LoggerSubscription &sub = _subscriptions[i];
|
2019-08-07 11:02:16 -04:00
|
|
|
write_format(type, *sub.get_topic(), written_formats, msg);
|
2016-05-17 14:18:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_writer.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_all_add_logged_msg(LogType type)
|
2016-05-17 14:18:59 +02:00
|
|
|
{
|
|
|
|
|
_writer.lock();
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
size_t sub_count = _subscriptions.size();
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
if (type == LogType::Mission) {
|
|
|
|
|
sub_count = _num_mission_subs;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
for (size_t i = 0; i < sub_count; ++i) {
|
|
|
|
|
LoggerSubscription &sub = _subscriptions[i];
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
if (sub.valid()) {
|
|
|
|
|
write_add_logged_msg(type, sub);
|
2016-05-17 14:18:59 +02:00
|
|
|
}
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_writer.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
void Logger::write_add_logged_msg(LogType type, LoggerSubscription &subscription)
|
2016-05-17 14:18:59 +02:00
|
|
|
{
|
2016-05-31 17:32:13 +02:00
|
|
|
ulog_message_add_logged_s msg;
|
2016-05-17 14:18:59 +02:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
if (subscription.msg_id == MSG_ID_INVALID) {
|
|
|
|
|
if (_next_topic_id == MSG_ID_INVALID) {
|
2018-10-17 15:59:50 +02:00
|
|
|
// if we land here an uint8 is too small -> switch to uint16
|
|
|
|
|
PX4_ERR("limit for _next_topic_id reached");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
subscription.msg_id = _next_topic_id++;
|
2016-10-11 21:19:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
msg.msg_id = subscription.msg_id;
|
|
|
|
|
msg.multi_id = subscription.get_instance();
|
2016-05-17 14:18:59 +02:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
int message_name_len = strlen(subscription.get_topic()->o_name);
|
2016-05-17 14:18:59 +02:00
|
|
|
|
2019-08-07 11:02:16 -04:00
|
|
|
memcpy(msg.message_name, subscription.get_topic()->o_name, message_name_len);
|
2016-05-17 14:18:59 +02:00
|
|
|
|
|
|
|
|
size_t msg_size = sizeof(msg) - sizeof(msg.message_name) + message_name_len;
|
2016-05-31 17:32:13 +02:00
|
|
|
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
|
2016-05-17 14:18:59 +02:00
|
|
|
|
2016-10-08 09:48:52 +02:00
|
|
|
bool prev_reliable = _writer.need_reliable_transfer();
|
|
|
|
|
_writer.set_need_reliable_transfer(true);
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, &msg, msg_size);
|
2016-10-08 09:48:52 +02:00
|
|
|
_writer.set_need_reliable_transfer(prev_reliable);
|
2016-05-17 14:18:59 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_info(LogType type, const char *name, const char *value)
|
2016-04-30 09:11:21 -06:00
|
|
|
{
|
|
|
|
|
_writer.lock();
|
2017-04-27 20:54:38 -04:00
|
|
|
ulog_message_info_header_s msg = {};
|
2016-10-18 08:41:03 +02:00
|
|
|
uint8_t *buffer = reinterpret_cast<uint8_t *>(&msg);
|
|
|
|
|
msg.msg_type = static_cast<uint8_t>(ULogMessageType::INFO);
|
2016-04-30 09:11:21 -06:00
|
|
|
|
|
|
|
|
/* construct format key (type and name) */
|
|
|
|
|
size_t vlen = strlen(value);
|
2019-07-24 13:27:02 -07:00
|
|
|
msg.key_len = snprintf(msg.key, sizeof(msg.key), "char[%zu] %s", vlen, name);
|
2017-07-04 10:41:12 +02:00
|
|
|
size_t msg_size = sizeof(msg) - sizeof(msg.key) + msg.key_len;
|
|
|
|
|
|
|
|
|
|
/* copy string value directly to buffer */
|
|
|
|
|
if (vlen < (sizeof(msg) - msg_size)) {
|
|
|
|
|
memcpy(&buffer[msg_size], value, vlen);
|
|
|
|
|
msg_size += vlen;
|
|
|
|
|
|
|
|
|
|
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, buffer, msg_size);
|
2017-07-04 10:41:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_writer.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_info_multiple(LogType type, const char *name, const char *value, bool is_continued)
|
2017-07-04 10:41:12 +02:00
|
|
|
{
|
|
|
|
|
_writer.lock();
|
|
|
|
|
ulog_message_info_multiple_header_s msg;
|
|
|
|
|
uint8_t *buffer = reinterpret_cast<uint8_t *>(&msg);
|
|
|
|
|
msg.msg_type = static_cast<uint8_t>(ULogMessageType::INFO_MULTIPLE);
|
|
|
|
|
msg.is_continued = is_continued;
|
|
|
|
|
|
|
|
|
|
/* construct format key (type and name) */
|
|
|
|
|
size_t vlen = strlen(value);
|
2019-07-24 13:27:02 -07:00
|
|
|
msg.key_len = snprintf(msg.key, sizeof(msg.key), "char[%zu] %s", vlen, name);
|
2016-10-18 08:41:03 +02:00
|
|
|
size_t msg_size = sizeof(msg) - sizeof(msg.key) + msg.key_len;
|
2016-04-30 09:11:21 -06:00
|
|
|
|
|
|
|
|
/* copy string value directly to buffer */
|
2016-10-18 08:41:03 +02:00
|
|
|
if (vlen < (sizeof(msg) - msg_size)) {
|
2016-04-30 09:11:21 -06:00
|
|
|
memcpy(&buffer[msg_size], value, vlen);
|
|
|
|
|
msg_size += vlen;
|
|
|
|
|
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
|
2016-04-30 09:11:21 -06:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, buffer, msg_size);
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2019-04-08 07:53:45 +02:00
|
|
|
} else {
|
|
|
|
|
PX4_ERR("info_multiple str too long (%i), key=%s", msg.key_len, msg.key);
|
2016-04-30 09:11:21 -06:00
|
|
|
}
|
2016-05-04 12:26:08 +02:00
|
|
|
|
2016-05-04 11:23:51 +02:00
|
|
|
_writer.unlock();
|
2016-04-30 09:11:21 -06:00
|
|
|
}
|
2016-12-20 15:02:34 +01:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_info(LogType type, const char *name, int32_t value)
|
2016-12-20 15:02:34 +01:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info_template<int32_t>(type, name, value, "int32_t");
|
2016-12-20 15:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_info(LogType type, const char *name, uint32_t value)
|
2016-12-20 15:02:34 +01:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info_template<uint32_t>(type, name, value, "uint32_t");
|
2016-12-20 15:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_info_template(LogType type, const char *name, T value, const char *type_str)
|
2016-05-17 12:28:23 +02:00
|
|
|
{
|
|
|
|
|
_writer.lock();
|
2017-04-27 20:54:38 -04:00
|
|
|
ulog_message_info_header_s msg = {};
|
2016-10-18 08:41:03 +02:00
|
|
|
uint8_t *buffer = reinterpret_cast<uint8_t *>(&msg);
|
|
|
|
|
msg.msg_type = static_cast<uint8_t>(ULogMessageType::INFO);
|
2016-05-17 12:28:23 +02:00
|
|
|
|
|
|
|
|
/* construct format key (type and name) */
|
2016-12-20 15:02:34 +01:00
|
|
|
msg.key_len = snprintf(msg.key, sizeof(msg.key), "%s %s", type_str, name);
|
2016-10-18 08:41:03 +02:00
|
|
|
size_t msg_size = sizeof(msg) - sizeof(msg.key) + msg.key_len;
|
2016-05-17 12:28:23 +02:00
|
|
|
|
|
|
|
|
/* copy string value directly to buffer */
|
2016-12-20 15:02:34 +01:00
|
|
|
memcpy(&buffer[msg_size], &value, sizeof(T));
|
|
|
|
|
msg_size += sizeof(T);
|
2016-05-17 12:28:23 +02:00
|
|
|
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
|
2016-05-17 12:28:23 +02:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, buffer, msg_size);
|
2016-05-17 12:28:23 +02:00
|
|
|
|
|
|
|
|
_writer.unlock();
|
|
|
|
|
}
|
2016-04-30 09:11:21 -06:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_header(LogType type)
|
2016-05-17 11:10:37 +02:00
|
|
|
{
|
2017-04-27 20:54:38 -04:00
|
|
|
ulog_file_header_s header = {};
|
2016-05-17 11:10:37 +02:00
|
|
|
header.magic[0] = 'U';
|
|
|
|
|
header.magic[1] = 'L';
|
|
|
|
|
header.magic[2] = 'o';
|
|
|
|
|
header.magic[3] = 'g';
|
|
|
|
|
header.magic[4] = 0x01;
|
|
|
|
|
header.magic[5] = 0x12;
|
|
|
|
|
header.magic[6] = 0x35;
|
2017-07-03 17:54:53 +02:00
|
|
|
header.magic[7] = 0x01; //file version 1
|
2016-05-17 11:10:37 +02:00
|
|
|
header.timestamp = hrt_absolute_time();
|
|
|
|
|
_writer.lock();
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, &header, sizeof(header));
|
2017-07-03 17:54:53 +02:00
|
|
|
|
|
|
|
|
// write the Flags message: this MUST be written right after the ulog header
|
2018-05-07 13:18:32 +02:00
|
|
|
ulog_message_flag_bits_s flag_bits{};
|
2017-07-03 17:54:53 +02:00
|
|
|
|
|
|
|
|
flag_bits.msg_size = sizeof(flag_bits) - ULOG_MSG_HEADER_LEN;
|
|
|
|
|
flag_bits.msg_type = static_cast<uint8_t>(ULogMessageType::FLAG_BITS);
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, &flag_bits, sizeof(flag_bits));
|
2017-07-03 17:54:53 +02:00
|
|
|
|
2016-05-17 11:10:37 +02:00
|
|
|
_writer.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_version(LogType type)
|
2016-04-30 09:11:21 -06:00
|
|
|
{
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "ver_sw", px4_firmware_version_string());
|
|
|
|
|
write_info(type, "ver_sw_release", px4_firmware_version());
|
2017-10-05 11:38:45 +02:00
|
|
|
uint32_t vendor_version = px4_firmware_vendor_version();
|
|
|
|
|
|
|
|
|
|
if (vendor_version > 0) {
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "ver_vendor_sw_release", vendor_version);
|
2017-10-05 11:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "ver_hw", px4_board_name());
|
2018-04-04 08:34:10 +02:00
|
|
|
const char *board_sub_type = px4_board_sub_type();
|
|
|
|
|
|
|
|
|
|
if (board_sub_type && board_sub_type[0]) {
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "ver_hw_subtype", board_sub_type);
|
2018-04-04 08:34:10 +02:00
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "sys_name", "PX4");
|
|
|
|
|
write_info(type, "sys_os_name", px4_os_name());
|
2016-12-20 15:02:34 +01:00
|
|
|
const char *os_version = px4_os_version_string();
|
|
|
|
|
|
2017-07-03 17:46:56 +02:00
|
|
|
const char *git_branch = px4_firmware_git_branch();
|
|
|
|
|
|
|
|
|
|
if (git_branch && git_branch[0]) {
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "ver_sw_branch", git_branch);
|
2017-07-03 17:46:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-20 15:02:34 +01:00
|
|
|
if (os_version) {
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "sys_os_ver", os_version);
|
2016-12-20 15:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "sys_os_ver_release", px4_os_version());
|
|
|
|
|
write_info(type, "sys_toolchain", px4_toolchain_name());
|
|
|
|
|
write_info(type, "sys_toolchain_ver", px4_toolchain_version());
|
2016-12-20 15:02:34 +01:00
|
|
|
|
2019-06-07 16:41:30 -04:00
|
|
|
const char *ecl_version = px4_ecl_lib_version_string();
|
2018-06-21 11:41:03 -04:00
|
|
|
|
|
|
|
|
if (ecl_version && ecl_version[0]) {
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "sys_lib_ecl_ver", ecl_version);
|
2018-06-21 11:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-25 08:13:01 -10:00
|
|
|
char revision = 'U';
|
|
|
|
|
const char *chip_name = nullptr;
|
2016-12-20 15:02:34 +01:00
|
|
|
|
2017-01-25 08:13:01 -10:00
|
|
|
if (board_mcu_version(&revision, &chip_name, nullptr) >= 0) {
|
2016-12-20 15:02:34 +01:00
|
|
|
char mcu_ver[64];
|
2016-12-21 08:59:10 +01:00
|
|
|
snprintf(mcu_ver, sizeof(mcu_ver), "%s, rev. %c", chip_name, revision);
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "sys_mcu", mcu_ver);
|
2016-12-20 15:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-24 08:15:56 +02:00
|
|
|
#ifndef BOARD_HAS_NO_UUID
|
2016-12-20 15:02:34 +01:00
|
|
|
/* write the UUID if enabled */
|
|
|
|
|
param_t write_uuid_param = param_find("SDLOG_UUID");
|
|
|
|
|
|
|
|
|
|
if (write_uuid_param != PARAM_INVALID) {
|
2017-10-24 22:00:21 +02:00
|
|
|
int32_t write_uuid;
|
2016-12-20 15:02:34 +01:00
|
|
|
param_get(write_uuid_param, &write_uuid);
|
|
|
|
|
|
|
|
|
|
if (write_uuid == 1) {
|
2017-09-07 14:12:24 -10:00
|
|
|
char px4_uuid_string[PX4_GUID_FORMAT_SIZE];
|
|
|
|
|
board_get_px4_guid_formated(px4_uuid_string, sizeof(px4_uuid_string));
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "sys_uuid", px4_uuid_string);
|
2016-12-20 15:02:34 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2017-07-24 08:15:56 +02:00
|
|
|
#endif /* BOARD_HAS_NO_UUID */
|
2016-12-20 15:02:34 +01:00
|
|
|
|
2016-05-17 12:28:23 +02:00
|
|
|
int32_t utc_offset = 0;
|
|
|
|
|
|
|
|
|
|
if (_log_utc_offset != PARAM_INVALID) {
|
|
|
|
|
param_get(_log_utc_offset, &utc_offset);
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "time_ref_utc", utc_offset * 60);
|
2016-05-17 12:28:23 +02:00
|
|
|
}
|
2016-05-24 15:07:11 +02:00
|
|
|
|
|
|
|
|
if (_replay_file_name) {
|
2018-10-22 11:37:26 +02:00
|
|
|
write_info(type, "replay", _replay_file_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == LogType::Mission) {
|
|
|
|
|
write_info(type, "log_type", "mission");
|
2016-05-24 15:07:11 +02:00
|
|
|
}
|
2016-04-30 09:11:21 -06:00
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_parameters(LogType type)
|
2016-04-25 17:36:13 -04:00
|
|
|
{
|
|
|
|
|
_writer.lock();
|
2017-04-27 20:54:38 -04:00
|
|
|
ulog_message_parameter_header_s msg = {};
|
2016-10-18 08:41:03 +02:00
|
|
|
uint8_t *buffer = reinterpret_cast<uint8_t *>(&msg);
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.msg_type = static_cast<uint8_t>(ULogMessageType::PARAMETER);
|
2016-04-25 17:36:13 -04:00
|
|
|
int param_idx = 0;
|
|
|
|
|
param_t param = 0;
|
|
|
|
|
|
|
|
|
|
do {
|
2018-01-07 12:22:27 +01:00
|
|
|
// skip over all parameters which are not invalid and not used
|
2016-04-25 17:36:13 -04:00
|
|
|
do {
|
|
|
|
|
param = param_for_index(param_idx);
|
|
|
|
|
++param_idx;
|
|
|
|
|
} while (param != PARAM_INVALID && !param_used(param));
|
|
|
|
|
|
2016-04-30 17:36:38 -06:00
|
|
|
// save parameters which are valid AND used
|
2016-04-25 17:36:13 -04:00
|
|
|
if (param != PARAM_INVALID) {
|
2018-01-07 12:22:27 +01:00
|
|
|
// get parameter type and size
|
2016-04-25 17:36:13 -04:00
|
|
|
const char *type_str;
|
2018-10-22 11:37:26 +02:00
|
|
|
param_type_t ptype = param_type(param);
|
2016-04-30 17:36:38 -06:00
|
|
|
size_t value_size = 0;
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
switch (ptype) {
|
2016-04-30 17:36:38 -06:00
|
|
|
case PARAM_TYPE_INT32:
|
|
|
|
|
type_str = "int32_t";
|
|
|
|
|
value_size = sizeof(int32_t);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PARAM_TYPE_FLOAT:
|
|
|
|
|
type_str = "float";
|
|
|
|
|
value_size = sizeof(float);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 12:22:27 +01:00
|
|
|
// format parameter key (type and name)
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.key_len = snprintf(msg.key, sizeof(msg.key), "%s %s", type_str, param_name(param));
|
|
|
|
|
size_t msg_size = sizeof(msg) - sizeof(msg.key) + msg.key_len;
|
2016-04-30 17:36:38 -06:00
|
|
|
|
2018-01-07 12:22:27 +01:00
|
|
|
// copy parameter value directly to buffer
|
2018-10-22 11:37:26 +02:00
|
|
|
switch (ptype) {
|
2017-10-24 22:00:21 +02:00
|
|
|
case PARAM_TYPE_INT32:
|
2019-06-07 16:41:30 -04:00
|
|
|
param_get(param, (int32_t *)&buffer[msg_size]);
|
2017-10-24 22:00:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PARAM_TYPE_FLOAT:
|
2019-06-07 16:41:30 -04:00
|
|
|
param_get(param, (float *)&buffer[msg_size]);
|
2017-10-24 22:00:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2016-04-30 17:36:38 -06:00
|
|
|
msg_size += value_size;
|
|
|
|
|
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
|
2016-04-30 17:36:38 -06:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, buffer, msg_size);
|
2016-04-30 17:36:38 -06:00
|
|
|
}
|
|
|
|
|
} while ((param != PARAM_INVALID) && (param_idx < (int) param_count()));
|
|
|
|
|
|
|
|
|
|
_writer.unlock();
|
|
|
|
|
_writer.notify();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
void Logger::write_changed_parameters(LogType type)
|
2016-04-30 17:36:38 -06:00
|
|
|
{
|
|
|
|
|
_writer.lock();
|
2017-04-27 20:54:38 -04:00
|
|
|
ulog_message_parameter_header_s msg = {};
|
2016-10-18 08:41:03 +02:00
|
|
|
uint8_t *buffer = reinterpret_cast<uint8_t *>(&msg);
|
2016-04-30 17:36:38 -06:00
|
|
|
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.msg_type = static_cast<uint8_t>(ULogMessageType::PARAMETER);
|
2016-04-30 17:36:38 -06:00
|
|
|
int param_idx = 0;
|
|
|
|
|
param_t param = 0;
|
|
|
|
|
|
|
|
|
|
do {
|
2018-01-07 12:22:27 +01:00
|
|
|
// skip over all parameters which are not invalid and not used
|
2016-04-30 17:36:38 -06:00
|
|
|
do {
|
|
|
|
|
param = param_for_index(param_idx);
|
|
|
|
|
++param_idx;
|
|
|
|
|
} while (param != PARAM_INVALID && !param_used(param));
|
|
|
|
|
|
|
|
|
|
// log parameters which are valid AND used AND unsaved
|
|
|
|
|
if ((param != PARAM_INVALID) && param_value_unsaved(param)) {
|
|
|
|
|
|
2018-01-07 12:22:27 +01:00
|
|
|
// get parameter type and size
|
2016-04-30 17:36:38 -06:00
|
|
|
const char *type_str;
|
2018-10-22 11:37:26 +02:00
|
|
|
param_type_t ptype = param_type(param);
|
2016-04-25 17:36:13 -04:00
|
|
|
size_t value_size = 0;
|
|
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
switch (ptype) {
|
2016-04-25 17:36:13 -04:00
|
|
|
case PARAM_TYPE_INT32:
|
|
|
|
|
type_str = "int32_t";
|
|
|
|
|
value_size = sizeof(int32_t);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PARAM_TYPE_FLOAT:
|
|
|
|
|
type_str = "float";
|
|
|
|
|
value_size = sizeof(float);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-07 12:22:27 +01:00
|
|
|
// format parameter key (type and name)
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.key_len = snprintf(msg.key, sizeof(msg.key), "%s %s", type_str, param_name(param));
|
|
|
|
|
size_t msg_size = sizeof(msg) - sizeof(msg.key) + msg.key_len;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-01-07 12:22:27 +01:00
|
|
|
// copy parameter value directly to buffer
|
2018-10-22 11:37:26 +02:00
|
|
|
switch (ptype) {
|
2017-10-24 22:00:21 +02:00
|
|
|
case PARAM_TYPE_INT32:
|
2019-06-07 16:41:30 -04:00
|
|
|
param_get(param, (int32_t *)&buffer[msg_size]);
|
2017-10-24 22:00:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PARAM_TYPE_FLOAT:
|
2019-06-07 16:41:30 -04:00
|
|
|
param_get(param, (float *)&buffer[msg_size]);
|
2017-10-24 22:00:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-06-07 16:41:30 -04:00
|
|
|
|
2016-04-25 17:36:13 -04:00
|
|
|
msg_size += value_size;
|
|
|
|
|
|
2018-01-07 12:22:27 +01:00
|
|
|
// msg_size is now 1 (msg_type) + 2 (msg_size) + 1 (key_len) + key_len + value_size
|
2016-10-18 08:41:03 +02:00
|
|
|
msg.msg_size = msg_size - ULOG_MSG_HEADER_LEN;
|
2016-04-25 17:36:13 -04:00
|
|
|
|
2018-10-22 11:37:26 +02:00
|
|
|
write_message(type, buffer, msg_size);
|
2016-04-25 17:36:13 -04:00
|
|
|
}
|
|
|
|
|
} while ((param != PARAM_INVALID) && (param_idx < (int) param_count()));
|
|
|
|
|
|
|
|
|
|
_writer.unlock();
|
|
|
|
|
_writer.notify();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:30:21 -04:00
|
|
|
void Logger::ack_vehicle_command(vehicle_command_s *cmd, uint32_t result)
|
2016-10-12 16:42:57 +02:00
|
|
|
{
|
2018-07-22 12:45:52 -04:00
|
|
|
vehicle_command_ack_s vehicle_command_ack = {};
|
|
|
|
|
vehicle_command_ack.timestamp = hrt_absolute_time();
|
|
|
|
|
vehicle_command_ack.command = cmd->command;
|
|
|
|
|
vehicle_command_ack.result = (uint8_t)result;
|
|
|
|
|
vehicle_command_ack.target_system = cmd->source_system;
|
|
|
|
|
vehicle_command_ack.target_component = cmd->source_component;
|
2016-10-12 16:42:57 +02:00
|
|
|
|
2019-07-03 16:30:21 -04:00
|
|
|
uORB::PublicationQueued<vehicle_command_ack_s> cmd_ack_pub{ORB_ID(vehicle_command_ack)};
|
|
|
|
|
cmd_ack_pub.publish(vehicle_command_ack);
|
2016-10-12 16:42:57 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-07 16:41:30 -04:00
|
|
|
int Logger::print_usage(const char *reason)
|
|
|
|
|
{
|
|
|
|
|
if (reason) {
|
|
|
|
|
PX4_WARN("%s\n", reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PRINT_MODULE_DESCRIPTION(
|
|
|
|
|
R"DESCR_STR(
|
|
|
|
|
### Description
|
|
|
|
|
System logger which logs a configurable set of uORB topics and system printf messages
|
|
|
|
|
(`PX4_WARN` and `PX4_ERR`) to ULog files. These can be used for system and flight performance evaluation,
|
|
|
|
|
tuning, replay and crash analysis.
|
|
|
|
|
|
|
|
|
|
It supports 2 backends:
|
|
|
|
|
- Files: write ULog files to the file system (SD card)
|
|
|
|
|
- MAVLink: stream ULog data via MAVLink to a client (the client must support this)
|
|
|
|
|
|
|
|
|
|
Both backends can be enabled and used at the same time.
|
|
|
|
|
|
|
|
|
|
The file backend supports 2 types of log files: full (the normal log) and a mission
|
|
|
|
|
log. The mission log is a reduced ulog file and can be used for example for geotagging or
|
|
|
|
|
vehicle management. It can be enabled and configured via SDLOG_MISSION parameter.
|
|
|
|
|
The normal log is always a superset of the mission log.
|
|
|
|
|
|
|
|
|
|
### Implementation
|
|
|
|
|
The implementation uses two threads:
|
|
|
|
|
- The main thread, running at a fixed rate (or polling on a topic if started with -p) and checking for
|
|
|
|
|
data updates
|
|
|
|
|
- The writer thread, writing data to the file
|
|
|
|
|
|
|
|
|
|
In between there is a write buffer with configurable size (and another fixed-size buffer for
|
|
|
|
|
the mission log). It should be large to avoid dropouts.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
|
|
|
Typical usage to start logging immediately:
|
|
|
|
|
$ logger start -e -t
|
|
|
|
|
|
|
|
|
|
Or if already running:
|
|
|
|
|
$ logger on
|
|
|
|
|
)DESCR_STR");
|
|
|
|
|
|
|
|
|
|
PRINT_MODULE_USAGE_NAME("logger", "system");
|
|
|
|
|
PRINT_MODULE_USAGE_COMMAND("start");
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_STRING('m', "all", "file|mavlink|all", "Backend mode", true);
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('x', "Enable/disable logging via Aux1 RC channel", true);
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('e', "Enable logging right after start until disarm (otherwise only when armed)", true);
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('f', "Log until shutdown (implies -e)", true);
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_FLAG('t', "Use date/time for naming log directories and files", true);
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('r', 280, 0, 8000, "Log rate in Hz, 0 means unlimited rate", true);
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_INT('b', 12, 4, 10000, "Log buffer size in KiB", true);
|
|
|
|
|
PRINT_MODULE_USAGE_PARAM_STRING('p', nullptr, "<topic_name>",
|
|
|
|
|
"Poll on a topic instead of running with fixed rate (Log rate and topic intervals are ignored if this is set)", true);
|
|
|
|
|
PRINT_MODULE_USAGE_COMMAND_DESCR("on", "start logging now, override arming (logger must be running)");
|
|
|
|
|
PRINT_MODULE_USAGE_COMMAND_DESCR("off", "stop logging now, override arming (logger must be running)");
|
|
|
|
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 20:54:38 -04:00
|
|
|
} // namespace logger
|
|
|
|
|
} // namespace px4
|