AP_HAL_ChibiOS: and `uart_log` method and stats struct

This commit is contained in:
Iampete1 2024-04-06 17:11:57 +01:00 committed by Andrew Tridgell
parent e82502a4a4
commit 73f4a47496
2 changed files with 40 additions and 6 deletions

View File

@ -684,8 +684,8 @@ void Util::uart_info(ExpandingString &str)
{
// Calculate time since last call
const uint32_t now_ms = AP_HAL::millis();
const uint32_t dt_ms = now_ms - uart_stats.last_ms;
uart_stats.last_ms = now_ms;
const uint32_t dt_ms = now_ms - sys_uart_stats.last_ms;
sys_uart_stats.last_ms = now_ms;
// a header to allow for machine parsers to determine format
str.printf("UARTV1\n");
@ -693,15 +693,38 @@ void Util::uart_info(ExpandingString &str)
auto *uart = hal.serial(i);
if (uart) {
str.printf("SERIAL%u ", i);
uart->uart_info(str, uart_stats.serial[i], dt_ms);
uart->uart_info(str, sys_uart_stats.serial[i], dt_ms);
}
}
#if HAL_WITH_IO_MCU
str.printf("IOMCU ");
uart_io.uart_info(str, uart_stats.io, dt_ms);
uart_io.uart_info(str, sys_uart_stats.io, dt_ms);
#endif
}
// Log UART message for each serial port
#if HAL_LOGGING_ENABLED
void Util::uart_log()
{
// Calculate time since last call
const uint32_t now_ms = AP_HAL::millis();
const uint32_t dt_ms = now_ms - log_uart_stats.last_ms;
log_uart_stats.last_ms = now_ms;
// Loop over all numbered ports
for (uint8_t i = 0; i < HAL_UART_NUM_SERIAL_PORTS; i++) {
auto *uart = hal.serial(i);
if (uart) {
uart->log_stats(i, log_uart_stats.serial[i], dt_ms);
}
}
#if HAL_WITH_IO_MCU
// Use magic instance 100 for IOMCU
uart_io.log_stats(100, log_uart_stats.io, dt_ms);
#endif
}
#endif // HAL_LOGGING_ENABLED
#endif // HAL_UART_STATS_ENABLED
// request information on uart I/O
#if HAL_USE_PWM == TRUE

View File

@ -20,6 +20,7 @@
#include "AP_HAL_ChibiOS_Namespace.h"
#include "AP_HAL_ChibiOS.h"
#include <ch.h>
#include <AP_Logger/AP_Logger_config.h>
class ExpandingString;
@ -99,7 +100,13 @@ public:
#if HAL_UART_STATS_ENABLED
// request information on uart I/O
void uart_info(ExpandingString &str) override;
#if HAL_LOGGING_ENABLED
// Log UART message for each serial port
void uart_log() override;
#endif
#endif // HAL_UART_STATS_ENABLED
#if HAL_USE_PWM == TRUE
void timer_info(ExpandingString &str) override;
#endif
@ -163,12 +170,16 @@ private:
#endif
#if HAL_UART_STATS_ENABLED
struct {
struct uart_stats {
AP_HAL::UARTDriver::StatsTracker serial[HAL_UART_NUM_SERIAL_PORTS];
#if HAL_WITH_IO_MCU
AP_HAL::UARTDriver::StatsTracker io;
#endif
uint32_t last_ms;
} uart_stats;
};
uart_stats sys_uart_stats;
#if HAL_LOGGING_ENABLED
uart_stats log_uart_stats;
#endif
#endif
};