mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 10:46:33 +08:00
logger use uORB::PublicationQueued for ulog_stream
- queue depth is now set by the msg
This commit is contained in:
@@ -15,3 +15,5 @@ uint8 first_message_offset # offset into data where first message starts. This
|
|||||||
uint16 sequence # allows determine drops
|
uint16 sequence # allows determine drops
|
||||||
uint8 flags # see FLAGS_*
|
uint8 flags # see FLAGS_*
|
||||||
uint8[249] data # ulog data
|
uint8[249] data # ulog data
|
||||||
|
|
||||||
|
uint8 ORB_QUEUE_LENGTH = 14 # TODO: we might be able to reduce this if mavlink polled on the topic
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace px4
|
|||||||
namespace logger
|
namespace logger
|
||||||
{
|
{
|
||||||
|
|
||||||
LogWriter::LogWriter(Backend configured_backend, size_t file_buffer_size, unsigned int queue_size)
|
LogWriter::LogWriter(Backend configured_backend, size_t file_buffer_size)
|
||||||
: _backend(configured_backend)
|
: _backend(configured_backend)
|
||||||
{
|
{
|
||||||
if (configured_backend & BackendFile) {
|
if (configured_backend & BackendFile) {
|
||||||
@@ -50,7 +50,7 @@ LogWriter::LogWriter(Backend configured_backend, size_t file_buffer_size, unsign
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configured_backend & BackendMavlink) {
|
if (configured_backend & BackendMavlink) {
|
||||||
_log_writer_mavlink_for_write = _log_writer_mavlink = new LogWriterMavlink(queue_size);
|
_log_writer_mavlink_for_write = _log_writer_mavlink = new LogWriterMavlink();
|
||||||
|
|
||||||
if (!_log_writer_mavlink) {
|
if (!_log_writer_mavlink) {
|
||||||
PX4_ERR("LogWriterMavlink allocation failed");
|
PX4_ERR("LogWriterMavlink allocation failed");
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
static constexpr Backend BackendMavlink = 1 << 1;
|
static constexpr Backend BackendMavlink = 1 << 1;
|
||||||
static constexpr Backend BackendAll = BackendFile | BackendMavlink;
|
static constexpr Backend BackendAll = BackendFile | BackendMavlink;
|
||||||
|
|
||||||
LogWriter(Backend configured_backend, size_t file_buffer_size, unsigned int queue_size);
|
LogWriter(Backend configured_backend, size_t file_buffer_size);
|
||||||
~LogWriter();
|
~LogWriter();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
|||||||
@@ -45,9 +45,7 @@ namespace px4
|
|||||||
namespace logger
|
namespace logger
|
||||||
{
|
{
|
||||||
|
|
||||||
|
LogWriterMavlink::LogWriterMavlink()
|
||||||
LogWriterMavlink::LogWriterMavlink(unsigned int queue_size) :
|
|
||||||
_queue_size(queue_size)
|
|
||||||
{
|
{
|
||||||
_ulog_stream_data.length = 0;
|
_ulog_stream_data.length = 0;
|
||||||
}
|
}
|
||||||
@@ -62,21 +60,10 @@ LogWriterMavlink::~LogWriterMavlink()
|
|||||||
if (_ulog_stream_ack_sub >= 0) {
|
if (_ulog_stream_ack_sub >= 0) {
|
||||||
orb_unsubscribe(_ulog_stream_ack_sub);
|
orb_unsubscribe(_ulog_stream_ack_sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ulog_stream_pub) {
|
|
||||||
orb_unadvertise(_ulog_stream_pub);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogWriterMavlink::start_log()
|
void LogWriterMavlink::start_log()
|
||||||
{
|
{
|
||||||
if (_ulog_stream_pub == nullptr) {
|
|
||||||
memset(&_ulog_stream_data, 0, sizeof(_ulog_stream_data));
|
|
||||||
// advertise before we subscribe: this is a trick to reduce the number of needed file descriptors
|
|
||||||
// (the advertise temporarily opens a file descriptor)
|
|
||||||
_ulog_stream_pub = orb_advertise_queue(ORB_ID(ulog_stream), &_ulog_stream_data, _queue_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_ulog_stream_ack_sub == -1) {
|
if (_ulog_stream_ack_sub == -1) {
|
||||||
_ulog_stream_ack_sub = orb_subscribe(ORB_ID(ulog_stream_ack));
|
_ulog_stream_ack_sub = orb_subscribe(ORB_ID(ulog_stream_ack));
|
||||||
}
|
}
|
||||||
@@ -84,9 +71,11 @@ void LogWriterMavlink::start_log()
|
|||||||
// make sure we don't get any stale ack's by doing an orb_copy
|
// make sure we don't get any stale ack's by doing an orb_copy
|
||||||
ulog_stream_ack_s ack;
|
ulog_stream_ack_s ack;
|
||||||
orb_copy(ORB_ID(ulog_stream_ack), _ulog_stream_ack_sub, &ack);
|
orb_copy(ORB_ID(ulog_stream_ack), _ulog_stream_ack_sub, &ack);
|
||||||
|
|
||||||
_ulog_stream_data.sequence = 0;
|
_ulog_stream_data.sequence = 0;
|
||||||
_ulog_stream_data.length = 0;
|
_ulog_stream_data.length = 0;
|
||||||
_ulog_stream_data.first_message_offset = 0;
|
_ulog_stream_data.first_message_offset = 0;
|
||||||
|
|
||||||
_is_started = true;
|
_is_started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,12 +136,7 @@ int LogWriterMavlink::publish_message()
|
|||||||
_ulog_stream_data.flags = _ulog_stream_data.FLAGS_NEED_ACK;
|
_ulog_stream_data.flags = _ulog_stream_data.FLAGS_NEED_ACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ulog_stream_pub == nullptr) {
|
_ulog_stream_pub.publish(_ulog_stream_data);
|
||||||
_ulog_stream_pub = orb_advertise_queue(ORB_ID(ulog_stream), &_ulog_stream_data, _queue_size);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
orb_publish(ORB_ID(ulog_stream), _ulog_stream_pub, &_ulog_stream_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_need_reliable_transfer) {
|
if (_need_reliable_transfer) {
|
||||||
// we need to wait for an ack. Note that this blocks the main logger thread, so if a file logging
|
// we need to wait for an ack. Note that this blocks the main logger thread, so if a file logging
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <uORB/PublicationQueued.hpp>
|
||||||
#include <uORB/topics/ulog_stream.h>
|
#include <uORB/topics/ulog_stream.h>
|
||||||
#include <uORB/topics/ulog_stream_ack.h>
|
#include <uORB/topics/ulog_stream_ack.h>
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ namespace logger
|
|||||||
class LogWriterMavlink
|
class LogWriterMavlink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LogWriterMavlink(unsigned int queue_size);
|
LogWriterMavlink();
|
||||||
~LogWriterMavlink();
|
~LogWriterMavlink();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
@@ -75,12 +76,11 @@ private:
|
|||||||
/** publish message, wait for ack if needed & reset message */
|
/** publish message, wait for ack if needed & reset message */
|
||||||
int publish_message();
|
int publish_message();
|
||||||
|
|
||||||
ulog_stream_s _ulog_stream_data;
|
ulog_stream_s _ulog_stream_data{};
|
||||||
orb_advert_t _ulog_stream_pub = nullptr;
|
uORB::PublicationQueued<ulog_stream_s> _ulog_stream_pub{ORB_ID(ulog_stream)};
|
||||||
int _ulog_stream_ack_sub = -1;
|
int _ulog_stream_ack_sub{-1};
|
||||||
bool _need_reliable_transfer = false;
|
bool _need_reliable_transfer{false};
|
||||||
bool _is_started = false;
|
bool _is_started{false};
|
||||||
const unsigned int _queue_size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,8 +239,6 @@ Logger *Logger::instantiate(int argc, char *argv[])
|
|||||||
Logger::LogMode log_mode = Logger::LogMode::while_armed;
|
Logger::LogMode log_mode = Logger::LogMode::while_armed;
|
||||||
bool error_flag = false;
|
bool error_flag = false;
|
||||||
bool log_name_timestamp = false;
|
bool log_name_timestamp = false;
|
||||||
unsigned int queue_size = 14; //TODO: we might be able to reduce this if mavlink polled on the topic and/or
|
|
||||||
// topic sizes get reduced
|
|
||||||
LogWriter::Backend backend = LogWriter::BackendAll;
|
LogWriter::Backend backend = LogWriter::BackendAll;
|
||||||
const char *poll_topic = nullptr;
|
const char *poll_topic = nullptr;
|
||||||
|
|
||||||
@@ -248,7 +246,7 @@ Logger *Logger::instantiate(int argc, char *argv[])
|
|||||||
int ch;
|
int ch;
|
||||||
const char *myoptarg = nullptr;
|
const char *myoptarg = nullptr;
|
||||||
|
|
||||||
while ((ch = px4_getopt(argc, argv, "r:b:etfm:q:p:x", &myoptind, &myoptarg)) != EOF) {
|
while ((ch = px4_getopt(argc, argv, "r:b:etfm:p:x", &myoptind, &myoptarg)) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'r': {
|
case 'r': {
|
||||||
unsigned long r = strtoul(myoptarg, nullptr, 10);
|
unsigned long r = strtoul(myoptarg, nullptr, 10);
|
||||||
@@ -310,15 +308,6 @@ Logger *Logger::instantiate(int argc, char *argv[])
|
|||||||
poll_topic = myoptarg;
|
poll_topic = myoptarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'q':
|
|
||||||
queue_size = strtoul(myoptarg, nullptr, 10);
|
|
||||||
|
|
||||||
if (queue_size == 0) {
|
|
||||||
queue_size = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
error_flag = true;
|
error_flag = true;
|
||||||
break;
|
break;
|
||||||
@@ -343,8 +332,7 @@ Logger *Logger::instantiate(int argc, char *argv[])
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger *logger = new Logger(backend, log_buffer_size, log_interval, poll_topic, log_mode, log_name_timestamp,
|
Logger *logger = new Logger(backend, log_buffer_size, log_interval, poll_topic, log_mode, log_name_timestamp);
|
||||||
queue_size);
|
|
||||||
|
|
||||||
#if defined(DBGPRINT) && defined(__PX4_NUTTX)
|
#if defined(DBGPRINT) && defined(__PX4_NUTTX)
|
||||||
struct mallinfo alloc_info = mallinfo();
|
struct mallinfo alloc_info = mallinfo();
|
||||||
@@ -373,10 +361,10 @@ Logger *Logger::instantiate(int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
Logger::Logger(LogWriter::Backend backend, size_t buffer_size, uint32_t log_interval, const char *poll_topic_name,
|
Logger::Logger(LogWriter::Backend backend, size_t buffer_size, uint32_t log_interval, const char *poll_topic_name,
|
||||||
LogMode log_mode, bool log_name_timestamp, unsigned int queue_size) :
|
LogMode log_mode, bool log_name_timestamp) :
|
||||||
_log_mode(log_mode),
|
_log_mode(log_mode),
|
||||||
_log_name_timestamp(log_name_timestamp),
|
_log_name_timestamp(log_name_timestamp),
|
||||||
_writer(backend, buffer_size, queue_size),
|
_writer(backend, buffer_size),
|
||||||
_log_interval(log_interval)
|
_log_interval(log_interval)
|
||||||
{
|
{
|
||||||
_log_utc_offset = param_find("SDLOG_UTC_OFFSET");
|
_log_utc_offset = param_find("SDLOG_UTC_OFFSET");
|
||||||
@@ -2355,7 +2343,6 @@ $ logger on
|
|||||||
PRINT_MODULE_USAGE_PARAM_FLAG('t', "Use date/time for naming log directories and files", 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('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_INT('b', 12, 4, 10000, "Log buffer size in KiB", true);
|
||||||
PRINT_MODULE_USAGE_PARAM_INT('q', 14, 1, 100, "uORB queue size for mavlink mode", true);
|
|
||||||
PRINT_MODULE_USAGE_PARAM_STRING('p', nullptr, "<topic_name>",
|
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);
|
"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("on", "start logging now, override arming (logger must be running)");
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Logger(LogWriter::Backend backend, size_t buffer_size, uint32_t log_interval, const char *poll_topic_name,
|
Logger(LogWriter::Backend backend, size_t buffer_size, uint32_t log_interval, const char *poll_topic_name,
|
||||||
LogMode log_mode, bool log_name_timestamp, unsigned int queue_size);
|
LogMode log_mode, bool log_name_timestamp);
|
||||||
|
|
||||||
~Logger();
|
~Logger();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user