mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-08 14:41:37 +08:00
WIP: px4log
This commit is contained in:
@@ -36,7 +36,6 @@ set(SRCS)
|
||||
if(NOT "${PX4_PLATFORM}" MATCHES "qurt" AND NOT "${PX4_BOARD}" MATCHES "io-v2" AND NOT "${PX4_BOARD_LABEL}" MATCHES "bootloader")
|
||||
list(APPEND SRCS
|
||||
px4_log.cpp
|
||||
px4_log_history.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -654,39 +654,28 @@ int I2CSPIDriverBase::module_start(const BusCLIArguments &cli, BusInstanceIterat
|
||||
#if defined(CONFIG_I2C)
|
||||
|
||||
case BOARD_I2C_BUS:
|
||||
PX4_INFO_RAW("%s #%i on I2C bus %d", instance->ItemName(), runtime_instance, iterator.bus());
|
||||
|
||||
if (iterator.external()) {
|
||||
PX4_INFO_RAW(" (external)");
|
||||
}
|
||||
PX4_INFO("%s #%i on I2C bus %d (external) address 0x%X, rotation %d", instance->ItemName(), runtime_instance,
|
||||
iterator.bus(), cli.i2c_address, cli.rotation);
|
||||
|
||||
if (cli.i2c_address != 0) {
|
||||
PX4_INFO_RAW(" address 0x%X", cli.i2c_address);
|
||||
} else {
|
||||
PX4_INFO("%s #%i on I2C bus %d address 0x%X, rotation %d", instance->ItemName(), runtime_instance, iterator.bus(),
|
||||
cli.i2c_address, cli.rotation);
|
||||
}
|
||||
|
||||
if (cli.rotation != 0) {
|
||||
PX4_INFO_RAW(" rotation %d", cli.rotation);
|
||||
}
|
||||
|
||||
PX4_INFO_RAW("\n");
|
||||
|
||||
break;
|
||||
#endif // CONFIG_I2C
|
||||
#if defined(CONFIG_SPI)
|
||||
|
||||
case BOARD_SPI_BUS:
|
||||
PX4_INFO_RAW("%s #%i on SPI bus %d", instance->ItemName(), runtime_instance, iterator.bus());
|
||||
|
||||
if (iterator.external()) {
|
||||
PX4_INFO_RAW(" (external, equal to '-b %i')", iterator.externalBusIndex());
|
||||
}
|
||||
PX4_INFO("%s #%i on SPI bus %d rotation %d (external, equal to '-b %i')", instance->ItemName(), runtime_instance,
|
||||
iterator.bus(), cli.rotation, iterator.externalBusIndex());
|
||||
|
||||
if (cli.rotation != 0) {
|
||||
PX4_INFO_RAW(" rotation %d", cli.rotation);
|
||||
} else {
|
||||
PX4_INFO("%s #%i on SPI bus %d rotation %d", instance->ItemName(), runtime_instance, iterator.bus(), cli.rotation);
|
||||
}
|
||||
|
||||
PX4_INFO_RAW("\n");
|
||||
|
||||
break;
|
||||
#endif // CONFIG_SPI
|
||||
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2019 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file console_buffer.h
|
||||
* This implements a simple console buffer to store the full bootup output.
|
||||
* It can be printed via the 'dmesg' utility.
|
||||
* The output of stdout is redirected to CONSOLE_BUFFER_DEVICE, which is stored
|
||||
* to a circular buffer and output to stderr, so that everything is still printed
|
||||
* to the original console.
|
||||
*/
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
|
||||
#define CONSOLE_BUFFER_DEVICE "/dev/console_buf"
|
||||
|
||||
#ifdef BOARD_ENABLE_CONSOLE_BUFFER
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* Initialize the console buffer: register the CONSOLE_BUFFER_DEVICE
|
||||
* @return 0 on success, <0 error otherwise
|
||||
*/
|
||||
int px4_console_buffer_init();
|
||||
|
||||
/**
|
||||
* Print content of the console buffer to stdout
|
||||
* @param follow if true keep waiting and print new content whenever the buffer
|
||||
* is updated
|
||||
*/
|
||||
void px4_console_buffer_print(bool follow);
|
||||
|
||||
/**
|
||||
* Get the current used buffer size
|
||||
*/
|
||||
int px4_console_buffer_size();
|
||||
|
||||
/**
|
||||
* Read (chunks) of the console buffer.
|
||||
* Note that no lock is held between reading multiple chunks, so the buffer could get
|
||||
* updated meanwhile. Use px4_console_buffer_size() to read no more than expected.
|
||||
* @param buffer output buffer
|
||||
* @param buffer_length output buffer length
|
||||
* @param offset input and output argument for the offset. Initially set this to -1.
|
||||
* @return number of bytes written to the buffer (or <0 on error)
|
||||
*/
|
||||
int px4_console_buffer_read(char *buffer, int buffer_length, int *offset);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#else
|
||||
|
||||
static inline int px4_console_buffer_init()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int px4_console_buffer_size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int px4_console_buffer_read(char *buffer, int buffer_length, int *offset)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* BOARD_ENABLE_CONSOLE_BUFFER */
|
||||
@@ -130,7 +130,6 @@ __EXPORT void px4_log_modulename(int level, const char *moduleName, const char *
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
__EXPORT void px4_log_raw(int level, const char *fmt, ...)
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
__EXPORT void px4_log_history(FILE *out);
|
||||
|
||||
#if __GNUC__
|
||||
// Allow empty format strings.
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2022 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#if defined(BOARD_ENABLE_LOG_HISTORY)
|
||||
#include <stdio.h>
|
||||
#include <px4_platform_common/sem.h>
|
||||
|
||||
#ifndef BOARD_LOG_HISTORY_SIZE
|
||||
#define BOARD_LOG_HISTORY_SIZE (1024*4) // default buffer size
|
||||
#endif
|
||||
|
||||
class LogHistory
|
||||
{
|
||||
public:
|
||||
LogHistory() { px4_sem_init(&_lock, 0, 1); }
|
||||
~LogHistory() { px4_sem_destroy(&_lock); }
|
||||
|
||||
void write(const char *buffer);
|
||||
void print(FILE *out);
|
||||
|
||||
private:
|
||||
void lock() { do {} while (px4_sem_wait(&_lock) != 0); }
|
||||
void unlock() { px4_sem_post(&_lock); }
|
||||
|
||||
int size();
|
||||
int read(char *buffer, int buffer_length, int *offset);
|
||||
|
||||
char _log_history[BOARD_LOG_HISTORY_SIZE];
|
||||
int _head{0};
|
||||
int _tail{0};
|
||||
px4_sem_t _lock;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -284,7 +284,7 @@ public:
|
||||
ret = object->print_status();
|
||||
|
||||
} else {
|
||||
PX4_INFO("not running");
|
||||
PX4_INFO_RAW("not running\n");
|
||||
}
|
||||
|
||||
unlock_module();
|
||||
@@ -298,7 +298,7 @@ public:
|
||||
*/
|
||||
virtual int print_status()
|
||||
{
|
||||
PX4_INFO("running");
|
||||
PX4_INFO_RAW("running\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#endif
|
||||
|
||||
#include <px4_platform_common/log.h>
|
||||
#include <px4_platform_common/log_history.h>
|
||||
#if defined(__PX4_POSIX)
|
||||
#include <px4_daemon/server_io.h>
|
||||
#endif
|
||||
@@ -51,10 +50,6 @@
|
||||
#include <uORB/topics/log_message.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
|
||||
#if defined(BOARD_ENABLE_LOG_HISTORY)
|
||||
static LogHistory g_log_history;
|
||||
#endif
|
||||
|
||||
static orb_advert_t orb_log_message_pub = nullptr;
|
||||
|
||||
__EXPORT const char *__px4_log_level_str[_PX4_LOG_LEVEL_PANIC + 1] = { "DEBUG", "INFO", "WARN", "ERROR", "PANIC" };
|
||||
@@ -81,104 +76,8 @@ __EXPORT void px4_log_modulename(int level, const char *module_name, const char
|
||||
{
|
||||
static constexpr ssize_t max_length = sizeof(log_message_s::text);
|
||||
|
||||
FILE *out = stdout;
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
bool use_color = true;
|
||||
#endif // PX4_LOG_COLORIZED_OUTPUT
|
||||
|
||||
#if defined(__PX4_POSIX)
|
||||
bool isatty_ = false;
|
||||
out = get_stdout(&isatty_);
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
use_color = isatty_;
|
||||
#endif // PX4_LOG_COLORIZED_OUTPUT
|
||||
#endif // PX4_POSIX
|
||||
|
||||
if (level >= _PX4_LOG_LEVEL_INFO) {
|
||||
char buf[max_length + 1]; // same length as log_message_s::text, but add newline
|
||||
ssize_t pos = 0;
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
|
||||
if (use_color) {
|
||||
pos += sprintf(buf + pos, "%s", __px4_log_level_color[level]);
|
||||
}
|
||||
|
||||
#endif // PX4_LOG_COLORIZED_OUTPUT
|
||||
|
||||
pos += snprintf(buf + pos, math::max(max_length - pos, (ssize_t)0), __px4__log_level_fmt, __px4_log_level_str[level]);
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
|
||||
if (use_color) {
|
||||
pos += snprintf(buf + pos, math::max(max_length - pos, (ssize_t)0), PX4_ANSI_COLOR_GRAY);
|
||||
}
|
||||
|
||||
#endif // PX4_LOG_COLORIZED_OUTPUT
|
||||
|
||||
pos += snprintf(buf + pos, math::max(max_length - pos, (ssize_t)0), __px4__log_modulename_pfmt, module_name);
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
|
||||
if (use_color) {
|
||||
pos += snprintf(buf + pos, math::max(max_length - pos, (ssize_t)0), "%s", __px4_log_level_color[level]);
|
||||
}
|
||||
|
||||
#endif // PX4_LOG_COLORIZED_OUTPUT
|
||||
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
pos += vsnprintf(buf + pos, math::max(max_length - pos, (ssize_t)0), fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
|
||||
if (use_color) {
|
||||
// alway reset color
|
||||
const ssize_t sz = math::min(pos, max_length - (ssize_t)strlen(PX4_ANSI_COLOR_RESET) - (ssize_t)1);
|
||||
pos += sprintf(buf + sz, "%s\n", PX4_ANSI_COLOR_RESET);
|
||||
|
||||
} else
|
||||
#endif // PX4_LOG_COLORIZED_OUTPUT
|
||||
{
|
||||
pos += sprintf(buf + math::min(pos, max_length - (ssize_t)1), "\n");
|
||||
}
|
||||
|
||||
// ensure NULL termination (buffer is max_length + 1)
|
||||
buf[max_length] = 0;
|
||||
|
||||
fputs(buf, out);
|
||||
|
||||
#if defined(BOARD_ENABLE_LOG_HISTORY)
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
|
||||
// No color formatting for log history
|
||||
if (use_color) {
|
||||
pos = snprintf(buf, max_length, __px4__log_level_fmt, __px4_log_level_str[level]);
|
||||
pos += snprintf(buf + pos, math::max(max_length - pos, (ssize_t)0), __px4__log_modulename_pfmt, module_name);
|
||||
va_start(argptr, fmt);
|
||||
pos += vsnprintf(buf + pos, math::max(max_length - pos, (ssize_t)0), fmt, argptr);
|
||||
va_end(argptr);
|
||||
pos += sprintf(buf + math::min(pos, max_length - (ssize_t)1), "\n");
|
||||
buf[max_length] = 0; // ensure NULL termination
|
||||
}
|
||||
|
||||
#endif
|
||||
g_log_history.write(buf);
|
||||
#endif // BOARD_ENABLE_LOG_HISTORY
|
||||
|
||||
#if defined(CONFIG_ARCH_BOARD_PX4_SITL)
|
||||
// Without flushing it's tricky to see stdout output when PX4 is started by
|
||||
// a script like for the MAVSDK tests.
|
||||
fflush(out);
|
||||
#endif // CONFIG_ARCH_BOARD_PX4_SITL
|
||||
}
|
||||
|
||||
/* publish an orb log message */
|
||||
if (level >= _PX4_LOG_LEVEL_INFO && orb_log_message_pub) { //publish all messages
|
||||
if (orb_log_message_pub) { //publish all messages
|
||||
|
||||
log_message_s log_message;
|
||||
|
||||
@@ -251,38 +150,5 @@ __EXPORT void px4_log_raw(int level, const char *fmt, ...)
|
||||
buf[max_length] = 0;
|
||||
|
||||
fputs(buf, out);
|
||||
|
||||
#if defined(BOARD_ENABLE_LOG_HISTORY)
|
||||
|
||||
#if defined(PX4_LOG_COLORIZED_OUTPUT)
|
||||
|
||||
// No color formatting for log history
|
||||
if (use_color) {
|
||||
va_start(argptr, fmt);
|
||||
pos = vsnprintf(buf, max_length, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if (pos > max_length) {
|
||||
// preserve newline if necessary
|
||||
if (fmt[strlen(fmt) - 1] == '\n') {
|
||||
buf[max_length - 1] = '\n';
|
||||
}
|
||||
}
|
||||
|
||||
buf[max_length] = 0; // ensure NULL termination
|
||||
}
|
||||
|
||||
#endif
|
||||
g_log_history.write(buf);
|
||||
#endif // BOARD_ENABLE_LOG_HISTORY
|
||||
}
|
||||
}
|
||||
|
||||
__EXPORT void px4_log_history(FILE *out)
|
||||
{
|
||||
|
||||
#if defined(BOARD_ENABLE_LOG_HISTORY)
|
||||
|
||||
g_log_history.print(out);
|
||||
#endif // BOARD_ENABLE_LOG_HISTORY
|
||||
}
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2022 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <px4_platform_common/log_history.h>
|
||||
|
||||
#if defined(BOARD_ENABLE_LOG_HISTORY)
|
||||
#include <string.h>
|
||||
|
||||
void LogHistory::print(FILE *out)
|
||||
{
|
||||
const int buffer_length = 512;
|
||||
char buffer[buffer_length];
|
||||
int offset = -1;
|
||||
|
||||
int total_size_read = 0;
|
||||
|
||||
do {
|
||||
int read_size = read(buffer, buffer_length, &offset);
|
||||
|
||||
if (read_size <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
fwrite(buffer, 1, read_size, out);
|
||||
|
||||
if (read_size < buffer_length) {
|
||||
break;
|
||||
}
|
||||
|
||||
total_size_read += read_size;
|
||||
} while (total_size_read < BOARD_LOG_HISTORY_SIZE);
|
||||
}
|
||||
|
||||
// Log a null terminated string to the circular history buffer.
|
||||
void LogHistory::write(const char *buffer)
|
||||
{
|
||||
lock(); // same rule as for printf: this cannot be used from IRQ handlers
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (buffer[i] != '\0') {
|
||||
|
||||
_log_history[_tail] = buffer[i++];
|
||||
_tail = (_tail + 1) % BOARD_LOG_HISTORY_SIZE;
|
||||
|
||||
if (_tail == _head) {
|
||||
_head = (_head + 1) % BOARD_LOG_HISTORY_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
int LogHistory::size()
|
||||
{
|
||||
lock();
|
||||
int size;
|
||||
|
||||
if (_head <= _tail) {
|
||||
size = _tail - _head;
|
||||
|
||||
} else {
|
||||
size = BOARD_LOG_HISTORY_SIZE - (_head - _tail);
|
||||
}
|
||||
|
||||
unlock();
|
||||
return size;
|
||||
}
|
||||
|
||||
int LogHistory::read(char *buffer, int buffer_length, int *offset)
|
||||
{
|
||||
lock();
|
||||
|
||||
if (*offset == -1) {
|
||||
*offset = _head;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
|
||||
if (*offset < _tail) {
|
||||
size = _tail - *offset;
|
||||
|
||||
if (size > buffer_length) {
|
||||
size = buffer_length;
|
||||
}
|
||||
|
||||
memcpy(buffer, _log_history + *offset, size);
|
||||
|
||||
} else if (_tail < *offset) {
|
||||
size = BOARD_LOG_HISTORY_SIZE - *offset;
|
||||
|
||||
if (size > buffer_length) {
|
||||
size = buffer_length;
|
||||
}
|
||||
|
||||
memcpy(buffer, _log_history + *offset, size);
|
||||
buffer += size;
|
||||
buffer_length -= size;
|
||||
|
||||
int size_secondary = _tail;
|
||||
|
||||
if (size_secondary > buffer_length) {
|
||||
size_secondary = buffer_length;
|
||||
}
|
||||
|
||||
if (size_secondary > 0) {
|
||||
memcpy(buffer, _log_history, size_secondary);
|
||||
size += size_secondary;
|
||||
}
|
||||
}
|
||||
|
||||
unlock();
|
||||
*offset = (*offset + size) % BOARD_LOG_HISTORY_SIZE;
|
||||
return size;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -174,7 +174,7 @@ static void shutdown_worker(void *arg)
|
||||
if (delay_elapsed && ((done && shutdown_lock_counter == 0) || (now > (shutdown_time_us + shutdown_timeout_us)))) {
|
||||
if (shutdown_args & SHUTDOWN_ARG_REBOOT) {
|
||||
#if defined(CONFIG_BOARDCTL_RESET)
|
||||
PX4_INFO_RAW("Reboot NOW.");
|
||||
PX4_INFO("Reboot NOW.");
|
||||
boardctl(BOARDIOC_RESET, (shutdown_args & SHUTDOWN_ARG_TO_BOOTLOADER) ? 1 : 0);
|
||||
#else
|
||||
PX4_PANIC("board reset not available");
|
||||
@@ -182,7 +182,7 @@ static void shutdown_worker(void *arg)
|
||||
|
||||
} else {
|
||||
#if defined(BOARD_HAS_POWER_CONTROL)
|
||||
PX4_INFO_RAW("Powering off NOW.");
|
||||
PX4_INFO("Powering off NOW.");
|
||||
#if defined(CONFIG_BOARDCTL_POWEROFF)
|
||||
boardctl(BOARDIOC_POWEROFF, 0);
|
||||
#else
|
||||
@@ -190,7 +190,7 @@ static void shutdown_worker(void *arg)
|
||||
#endif
|
||||
#elif defined(__PX4_POSIX)
|
||||
// simply exit on posix if real shutdown (poweroff) not available
|
||||
PX4_INFO_RAW("Exiting NOW.");
|
||||
PX4_INFO("Exiting NOW.");
|
||||
system_exit(0);
|
||||
#else
|
||||
PX4_PANIC("board shutdown not available");
|
||||
|
||||
@@ -183,6 +183,8 @@ public:
|
||||
|
||||
ORB_ID orb_id() const { return _orb_id; }
|
||||
|
||||
void reset() { _last_generation = 0; }
|
||||
|
||||
protected:
|
||||
|
||||
friend class SubscriptionCallback;
|
||||
|
||||
@@ -161,6 +161,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
void reset() { _subscription.reset(); }
|
||||
|
||||
private:
|
||||
|
||||
pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
Reference in New Issue
Block a user