2023-09-05 10:08:30 -03:00
|
|
|
#include "AP_Logger_config.h"
|
|
|
|
|
|
|
|
#if HAL_LOGGING_ENABLED
|
|
|
|
|
2017-08-23 20:42:31 -03:00
|
|
|
#include "AP_Common/AP_FWVersion.h"
|
2019-01-18 00:23:42 -04:00
|
|
|
#include "LoggerMessageWriter.h"
|
2020-04-08 03:58:10 -03:00
|
|
|
#include <AP_Scheduler/AP_Scheduler.h>
|
2022-10-27 22:38:07 -03:00
|
|
|
#include <AP_Vehicle/AP_Vehicle_Type.h>
|
2023-06-23 21:16:04 -03:00
|
|
|
#include "AP_Logger.h"
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2023-06-23 21:03:25 -03:00
|
|
|
#if HAL_LOGGER_FENCE_ENABLED
|
|
|
|
#include <AC_Fence/AC_Fence.h>
|
|
|
|
#endif
|
|
|
|
|
2023-09-04 07:05:11 -03:00
|
|
|
#if HAL_LOGGER_RALLY_ENABLED
|
|
|
|
#include <AP_Rally/AP_Rally.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-21 19:35:31 -03:00
|
|
|
#define FORCE_VERSION_H_INCLUDE
|
|
|
|
#include "ap_version.h"
|
|
|
|
#undef FORCE_VERSION_H_INCLUDE
|
|
|
|
|
2020-05-05 14:00:54 -03:00
|
|
|
// the message writers are mainly called at the end of periodic_fullrate() with a budget of 300us
|
|
|
|
// until they are finished calls to Write() will fail so we want to take up as much of
|
|
|
|
// the budget as possible in order that logging can begin in earnest as early as possible
|
|
|
|
#define MIN_LOOP_TIME_REMAINING_FOR_MESSAGE_WRITE_US 50
|
2020-04-09 04:50:54 -03:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
/* LogStartup - these are simple state machines which allow us to
|
|
|
|
* trickle out messages to the log files
|
|
|
|
*/
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter::reset()
|
2015-08-06 09:18:28 -03:00
|
|
|
{
|
|
|
|
_finished = false;
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:28:26 -04:00
|
|
|
bool LoggerMessageWriter::out_of_time_for_writing_messages() const
|
|
|
|
{
|
2022-08-18 08:53:09 -03:00
|
|
|
#if AP_SCHEDULER_ENABLED
|
2020-11-05 19:28:26 -04:00
|
|
|
return AP::scheduler().time_available_usec() < MIN_LOOP_TIME_REMAINING_FOR_MESSAGE_WRITE_US;
|
2021-05-19 23:34:13 -03:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2020-11-05 19:28:26 -04:00
|
|
|
}
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter_DFLogStart::reset()
|
2015-08-06 09:18:28 -03:00
|
|
|
{
|
2019-01-18 00:23:42 -04:00
|
|
|
LoggerMessageWriter::reset();
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2015-09-17 07:28:50 -03:00
|
|
|
_fmt_done = false;
|
2020-11-05 19:28:26 -04:00
|
|
|
_params_done = false;
|
2015-08-06 09:18:28 -03:00
|
|
|
_writesysinfo.reset();
|
2022-08-14 20:08:16 -03:00
|
|
|
#if AP_MISSION_ENABLED
|
2015-08-06 09:18:28 -03:00
|
|
|
_writeentiremission.reset();
|
2021-05-19 23:34:13 -03:00
|
|
|
#endif
|
2023-09-04 07:05:11 -03:00
|
|
|
#if HAL_LOGGER_RALLY_ENABLED
|
2018-12-29 00:01:46 -04:00
|
|
|
_writeallrallypoints.reset();
|
2021-05-19 23:34:13 -03:00
|
|
|
#endif
|
2021-11-13 09:58:48 -04:00
|
|
|
#if HAL_LOGGER_FENCE_ENABLED
|
|
|
|
_writeallpolyfence.reset();
|
|
|
|
#endif
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::FORMATS;
|
2015-08-06 09:18:28 -03:00
|
|
|
next_format_to_send = 0;
|
2015-12-07 20:51:46 -04:00
|
|
|
_next_unit_to_send = 0;
|
|
|
|
_next_multiplier_to_send = 0;
|
|
|
|
_next_format_unit_to_send = 0;
|
2022-06-13 16:02:15 -03:00
|
|
|
param_default = AP::logger().quiet_nanf();
|
|
|
|
ap = AP_Param::first(&token, &type, ¶m_default);
|
2015-08-06 09:18:28 -03:00
|
|
|
}
|
|
|
|
|
2023-09-25 06:16:13 -03:00
|
|
|
bool LoggerMessageWriter_DFLogStart::out_of_time_for_writing_messages_df() const
|
2020-11-05 19:28:26 -04:00
|
|
|
{
|
|
|
|
if (stage == Stage::FORMATS) {
|
|
|
|
// write out the FMT messages as fast as we can
|
2022-08-18 08:53:09 -03:00
|
|
|
#if AP_SCHEDULER_ENABLED
|
2020-11-05 19:28:26 -04:00
|
|
|
return AP::scheduler().time_available_usec() == 0;
|
2021-05-19 23:34:13 -03:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2020-11-05 19:28:26 -04:00
|
|
|
}
|
|
|
|
return LoggerMessageWriter::out_of_time_for_writing_messages();
|
|
|
|
}
|
|
|
|
|
2022-12-03 18:55:23 -04:00
|
|
|
/*
|
|
|
|
check if we've taken too long in a process() stage
|
|
|
|
return true if we should stop processing now as we are out of time
|
|
|
|
*/
|
|
|
|
bool LoggerMessageWriter_DFLogStart::check_process_limit(uint32_t start_us)
|
|
|
|
{
|
|
|
|
const uint32_t limit_us = 1000U;
|
|
|
|
if (AP_HAL::micros() - start_us > limit_us) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter_DFLogStart::process()
|
2015-08-06 09:18:28 -03:00
|
|
|
{
|
2023-09-25 06:16:13 -03:00
|
|
|
if (out_of_time_for_writing_messages_df()) {
|
2020-11-05 19:28:26 -04:00
|
|
|
return;
|
|
|
|
}
|
2022-12-03 18:55:23 -04:00
|
|
|
// allow any stage to run for max 1ms, to prevent a long loop on arming
|
|
|
|
const uint32_t start_us = AP_HAL::micros();
|
2020-11-05 19:28:26 -04:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
switch(stage) {
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::FORMATS:
|
2015-08-06 09:18:28 -03:00
|
|
|
// write log formats so the log is self-describing
|
2019-02-11 04:38:01 -04:00
|
|
|
while (next_format_to_send < _logger_backend->num_types()) {
|
2024-06-14 09:56:42 -03:00
|
|
|
const auto &s { _logger_backend->structure(next_format_to_send) };
|
|
|
|
if (_logger_backend->have_emitted_format_for_type((LogMessages)s->msg_type)) {
|
|
|
|
next_format_to_send++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!_logger_backend->Write_Format(s)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
next_format_to_send++;
|
2023-01-16 22:35:14 -04:00
|
|
|
if (check_process_limit(start_us)) {
|
|
|
|
return; // call me again!
|
|
|
|
}
|
2015-08-06 09:18:28 -03:00
|
|
|
}
|
2015-09-17 07:28:50 -03:00
|
|
|
_fmt_done = true;
|
2020-11-05 19:28:26 -04:00
|
|
|
stage = Stage::PARMS;
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
2022-12-03 18:55:23 -04:00
|
|
|
case Stage::PARMS: {
|
2020-11-05 19:28:26 -04:00
|
|
|
while (ap) {
|
2023-01-16 22:35:14 -04:00
|
|
|
if (!_logger_backend->Write_Parameter(ap, token, type, param_default)) {
|
2020-11-05 19:28:26 -04:00
|
|
|
return;
|
|
|
|
}
|
2022-06-13 16:02:15 -03:00
|
|
|
param_default = AP::logger().quiet_nanf();
|
|
|
|
ap = AP_Param::next_scalar(&token, &type, ¶m_default);
|
2023-01-16 22:35:14 -04:00
|
|
|
if (check_process_limit(start_us)) {
|
|
|
|
return; // call me again!
|
|
|
|
}
|
2020-11-05 19:28:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_params_done = true;
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::UNITS;
|
2022-12-03 18:55:23 -04:00
|
|
|
}
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::UNITS:
|
2019-02-11 04:38:01 -04:00
|
|
|
while (_next_unit_to_send < _logger_backend->num_units()) {
|
2023-01-16 22:35:14 -04:00
|
|
|
if (!_logger_backend->Write_Unit(_logger_backend->unit(_next_unit_to_send))) {
|
2015-12-07 20:51:46 -04:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
_next_unit_to_send++;
|
2023-01-16 22:35:14 -04:00
|
|
|
if (check_process_limit(start_us)) {
|
|
|
|
return; // call me again!
|
|
|
|
}
|
2015-12-07 20:51:46 -04:00
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::MULTIPLIERS;
|
2018-01-10 22:46:46 -04:00
|
|
|
FALLTHROUGH;
|
2015-12-07 20:51:46 -04:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::MULTIPLIERS:
|
2019-02-11 04:38:01 -04:00
|
|
|
while (_next_multiplier_to_send < _logger_backend->num_multipliers()) {
|
2023-01-16 22:35:14 -04:00
|
|
|
if (!_logger_backend->Write_Multiplier(_logger_backend->multiplier(_next_multiplier_to_send))) {
|
2015-12-07 20:51:46 -04:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
_next_multiplier_to_send++;
|
2023-01-16 22:35:14 -04:00
|
|
|
if (check_process_limit(start_us)) {
|
|
|
|
return; // call me again!
|
|
|
|
}
|
2015-12-07 20:51:46 -04:00
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::UNITS;
|
2018-01-10 22:46:46 -04:00
|
|
|
FALLTHROUGH;
|
2015-12-07 20:51:46 -04:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::FORMAT_UNITS:
|
2019-02-11 04:38:01 -04:00
|
|
|
while (_next_format_unit_to_send < _logger_backend->num_types()) {
|
2023-01-16 22:35:14 -04:00
|
|
|
if (!_logger_backend->Write_Format_Units(_logger_backend->structure(_next_format_unit_to_send))) {
|
2015-12-07 20:51:46 -04:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
_next_format_unit_to_send++;
|
2023-01-16 22:35:14 -04:00
|
|
|
if (check_process_limit(start_us)) {
|
|
|
|
return; // call me again!
|
|
|
|
}
|
2015-12-07 20:51:46 -04:00
|
|
|
}
|
2020-04-13 01:20:30 -03:00
|
|
|
stage = Stage::RUNNING_SUBWRITERS;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2024-06-14 04:56:22 -03:00
|
|
|
case Stage::RUNNING_SUBWRITERS: {
|
|
|
|
LoggerMessageWriter *subwriters[] {
|
|
|
|
&_writesysinfo,
|
2022-08-14 20:08:16 -03:00
|
|
|
#if AP_MISSION_ENABLED
|
2024-06-14 04:56:22 -03:00
|
|
|
&_writeentiremission,
|
2021-05-19 23:34:13 -03:00
|
|
|
#endif
|
2023-09-04 07:05:11 -03:00
|
|
|
#if HAL_LOGGER_RALLY_ENABLED
|
2024-06-14 04:56:22 -03:00
|
|
|
&_writeallrallypoints,
|
2021-11-13 09:58:48 -04:00
|
|
|
#endif
|
|
|
|
#if HAL_LOGGER_FENCE_ENABLED
|
2024-06-14 04:56:22 -03:00
|
|
|
&_writeallpolyfence,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
for (auto *sw : subwriters) {
|
|
|
|
if (!sw->finished()) {
|
|
|
|
sw->process();
|
|
|
|
if (!sw->finished()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-13 09:58:48 -04:00
|
|
|
}
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::VEHICLE_MESSAGES;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2024-06-14 04:56:22 -03:00
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::VEHICLE_MESSAGES:
|
2015-08-06 09:18:28 -03:00
|
|
|
// we guarantee 200 bytes of space for the vehicle startup
|
|
|
|
// messages. This allows them to be simple functions rather
|
2019-01-18 00:23:42 -04:00
|
|
|
// than e.g. LoggerMessageWriter-based state machines
|
2019-02-11 04:38:01 -04:00
|
|
|
if (_logger_backend->vehicle_message_writer()) {
|
|
|
|
if (_logger_backend->bufferspace_available() < 200) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return;
|
|
|
|
}
|
2019-02-11 04:38:01 -04:00
|
|
|
(_logger_backend->vehicle_message_writer())();
|
2015-08-06 09:18:28 -03:00
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::DONE;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::DONE:
|
2015-08-06 09:18:28 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_finished = true;
|
|
|
|
}
|
|
|
|
|
2022-08-14 20:08:16 -03:00
|
|
|
#if AP_MISSION_ENABLED
|
2020-04-13 01:20:30 -03:00
|
|
|
bool LoggerMessageWriter_DFLogStart::writeentiremission()
|
|
|
|
{
|
|
|
|
if (stage != Stage::DONE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
stage = Stage::RUNNING_SUBWRITERS;
|
|
|
|
_finished = false;
|
|
|
|
_writeentiremission.reset();
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-19 23:34:13 -03:00
|
|
|
#endif
|
2020-04-13 01:20:30 -03:00
|
|
|
|
2023-09-04 07:05:11 -03:00
|
|
|
#if HAL_LOGGER_RALLY_ENABLED
|
2020-04-13 01:20:30 -03:00
|
|
|
bool LoggerMessageWriter_DFLogStart::writeallrallypoints()
|
|
|
|
{
|
|
|
|
if (stage != Stage::DONE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
stage = Stage::RUNNING_SUBWRITERS;
|
|
|
|
_finished = false;
|
|
|
|
_writeallrallypoints.reset();
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-19 23:34:13 -03:00
|
|
|
#endif
|
2020-04-13 01:20:30 -03:00
|
|
|
|
2021-11-13 09:58:48 -04:00
|
|
|
#if HAL_LOGGER_FENCE_ENABLED
|
|
|
|
bool LoggerMessageWriter_DFLogStart::writeallfence()
|
|
|
|
{
|
|
|
|
if (stage != Stage::DONE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
stage = Stage::RUNNING_SUBWRITERS;
|
|
|
|
_finished = false;
|
|
|
|
_writeallpolyfence.reset();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter_WriteSysInfo::reset()
|
2015-08-06 09:18:28 -03:00
|
|
|
{
|
2019-01-18 00:23:42 -04:00
|
|
|
LoggerMessageWriter::reset();
|
2020-04-12 23:26:12 -03:00
|
|
|
stage = Stage::FIRMWARE_STRING;
|
2015-08-06 09:18:28 -03:00
|
|
|
}
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter_WriteSysInfo::process() {
|
2018-06-12 00:34:00 -03:00
|
|
|
const AP_FWVersion &fwver = AP::fwversion();
|
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
switch(stage) {
|
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::FIRMWARE_STRING:
|
2022-01-17 18:38:19 -04:00
|
|
|
#ifdef AP_CUSTOM_FIRMWARE_STRING
|
|
|
|
// also log original firmware string if different
|
|
|
|
if (! _logger_backend->Write_MessageF("%s [%s]",
|
|
|
|
fwver.fw_string,
|
|
|
|
fwver.fw_string_original)) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
#else
|
2019-02-11 04:38:01 -04:00
|
|
|
if (! _logger_backend->Write_Message(fwver.fw_string)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
2022-01-17 18:38:19 -04:00
|
|
|
#endif
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::GIT_VERSIONS;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::GIT_VERSIONS:
|
2018-06-12 00:34:00 -03:00
|
|
|
if (fwver.middleware_name && fwver.os_name) {
|
2019-02-11 04:38:01 -04:00
|
|
|
if (! _logger_backend->Write_MessageF("%s: %s %s: %s",
|
2018-06-12 00:34:00 -03:00
|
|
|
fwver.middleware_name,
|
|
|
|
fwver.middleware_hash_str,
|
|
|
|
fwver.os_name,
|
|
|
|
fwver.os_hash_str)) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
} else if (fwver.os_name) {
|
2019-02-11 04:38:01 -04:00
|
|
|
if (! _logger_backend->Write_MessageF("%s: %s",
|
2018-06-12 00:34:00 -03:00
|
|
|
fwver.os_name,
|
|
|
|
fwver.os_hash_str)) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
2015-08-06 09:18:28 -03:00
|
|
|
}
|
2022-02-01 20:46:06 -04:00
|
|
|
stage = Stage::VER;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2022-02-01 20:46:06 -04:00
|
|
|
case Stage::VER: {
|
|
|
|
if (!_logger_backend->Write_VER()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stage = Stage::SYSTEM_ID;
|
|
|
|
FALLTHROUGH;
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::SYSTEM_ID:
|
2022-09-18 14:04:23 -03:00
|
|
|
char sysid[50];
|
2015-08-06 09:18:28 -03:00
|
|
|
if (hal.util->get_system_id(sysid)) {
|
2019-02-11 04:38:01 -04:00
|
|
|
if (! _logger_backend->Write_Message(sysid)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::PARAM_SPACE_USED;
|
2019-08-27 00:49:34 -03:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::PARAM_SPACE_USED:
|
2019-08-27 00:49:34 -03:00
|
|
|
if (! _logger_backend->Write_MessageF("Param space used: %u/%u", AP_Param::storage_used(), AP_Param::storage_size())) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::RC_PROTOCOL;
|
2019-06-17 09:09:23 -03:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
2022-10-17 09:53:20 -03:00
|
|
|
case Stage::RC_PROTOCOL: {
|
2019-06-17 09:09:23 -03:00
|
|
|
const char *prot = hal.rcin->protocol();
|
|
|
|
if (prot == nullptr) {
|
|
|
|
prot = "None";
|
|
|
|
}
|
|
|
|
if (! _logger_backend->Write_MessageF("RC Protocol: %s", prot)) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
2022-10-17 09:53:20 -03:00
|
|
|
stage = Stage::RC_OUTPUT;
|
|
|
|
FALLTHROUGH;
|
|
|
|
}
|
|
|
|
case Stage::RC_OUTPUT: {
|
|
|
|
char banner_msg[50];
|
|
|
|
if (hal.rcout->get_output_mode_banner(banner_msg, sizeof(banner_msg))) {
|
|
|
|
if (!_logger_backend->Write_Message(banner_msg)) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-08-06 09:18:28 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
_finished = true; // all done!
|
|
|
|
}
|
|
|
|
|
2023-09-04 07:05:11 -03:00
|
|
|
#if HAL_LOGGER_RALLY_ENABLED
|
2018-12-29 00:02:29 -04:00
|
|
|
void LoggerMessageWriter_WriteAllRallyPoints::process()
|
|
|
|
{
|
2018-12-29 00:01:46 -04:00
|
|
|
const AP_Rally *_rally = AP::rally();
|
|
|
|
if (_rally == nullptr) {
|
|
|
|
_finished = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(stage) {
|
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::WRITE_NEW_RALLY_MESSAGE:
|
2019-02-11 04:38:01 -04:00
|
|
|
if (! _logger_backend->Write_Message("New rally")) {
|
2018-12-29 00:01:46 -04:00
|
|
|
return; // call me again
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::WRITE_ALL_RALLY_POINTS;
|
2018-12-29 00:01:46 -04:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::WRITE_ALL_RALLY_POINTS:
|
2018-12-29 00:01:46 -04:00
|
|
|
while (_rally_number_to_send < _rally->get_rally_total()) {
|
2020-11-05 19:28:26 -04:00
|
|
|
if (out_of_time_for_writing_messages()) {
|
2020-04-13 01:20:30 -03:00
|
|
|
return;
|
|
|
|
}
|
2018-12-29 00:01:46 -04:00
|
|
|
RallyLocation rallypoint;
|
|
|
|
if (_rally->get_rally_point_with_index(_rally_number_to_send, rallypoint)) {
|
2019-02-11 04:38:01 -04:00
|
|
|
if (!_logger_backend->Write_RallyPoint(
|
2018-12-29 00:01:46 -04:00
|
|
|
_rally->get_rally_total(),
|
|
|
|
_rally_number_to_send,
|
|
|
|
rallypoint)) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_rally_number_to_send++;
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::DONE;
|
2018-12-29 00:01:46 -04:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::DONE:
|
2018-12-29 00:01:46 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_finished = true;
|
|
|
|
}
|
|
|
|
|
2018-12-29 00:02:29 -04:00
|
|
|
void LoggerMessageWriter_WriteAllRallyPoints::reset()
|
2018-12-29 00:01:46 -04:00
|
|
|
{
|
2018-12-29 00:02:29 -04:00
|
|
|
LoggerMessageWriter::reset();
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::WRITE_NEW_RALLY_MESSAGE;
|
2018-12-29 00:01:46 -04:00
|
|
|
_rally_number_to_send = 0;
|
|
|
|
}
|
2023-09-04 07:05:11 -03:00
|
|
|
#endif // HAL_LOGGER_RALLY_ENABLED
|
2018-12-29 00:01:46 -04:00
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter_WriteEntireMission::process() {
|
2018-12-12 21:36:18 -04:00
|
|
|
const AP_Mission *_mission = AP::mission();
|
|
|
|
if (_mission == nullptr) {
|
|
|
|
_finished = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
switch(stage) {
|
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::WRITE_NEW_MISSION_MESSAGE:
|
2019-02-11 04:38:01 -04:00
|
|
|
if (! _logger_backend->Write_Message("New mission")) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::WRITE_MISSION_ITEMS;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::WRITE_MISSION_ITEMS: {
|
2015-08-06 09:18:28 -03:00
|
|
|
AP_Mission::Mission_Command cmd;
|
|
|
|
while (_mission_number_to_send < _mission->num_commands()) {
|
2020-11-05 19:28:26 -04:00
|
|
|
if (out_of_time_for_writing_messages()) {
|
2020-04-13 01:20:30 -03:00
|
|
|
return;
|
|
|
|
}
|
2015-08-06 09:18:28 -03:00
|
|
|
// upon failure to write the mission we will re-read from
|
|
|
|
// storage; this could be improved.
|
|
|
|
if (_mission->read_cmd_from_storage(_mission_number_to_send,cmd)) {
|
2024-09-27 04:34:18 -03:00
|
|
|
if (!_logger_backend->Write_Mission_Cmd(*_mission, cmd, LOG_CMD_MSG)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_mission_number_to_send++;
|
|
|
|
}
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::DONE;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2019-01-01 23:13:54 -04:00
|
|
|
}
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2019-10-04 18:33:07 -03:00
|
|
|
case Stage::DONE:
|
2015-08-06 09:18:28 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_finished = true;
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter_WriteEntireMission::reset()
|
2015-08-06 09:18:28 -03:00
|
|
|
{
|
2019-01-18 00:23:42 -04:00
|
|
|
LoggerMessageWriter::reset();
|
2019-10-04 18:33:07 -03:00
|
|
|
stage = Stage::WRITE_NEW_MISSION_MESSAGE;
|
2015-08-06 09:18:28 -03:00
|
|
|
_mission_number_to_send = 0;
|
|
|
|
}
|
2021-11-13 09:58:48 -04:00
|
|
|
|
|
|
|
#if HAL_LOGGER_FENCE_ENABLED
|
|
|
|
#if APM_BUILD_TYPE(APM_BUILD_Replay)
|
|
|
|
// dummy methods to allow build with Replay
|
|
|
|
void LoggerMessageWriter_Write_Polyfence::process() { };
|
|
|
|
void LoggerMessageWriter_Write_Polyfence::reset() { };
|
|
|
|
#else
|
|
|
|
void LoggerMessageWriter_Write_Polyfence::process() {
|
|
|
|
|
|
|
|
AC_Fence *fence = AP::fence();
|
|
|
|
if (fence == nullptr) {
|
2022-11-01 12:02:03 -03:00
|
|
|
_finished = true;
|
2021-11-13 09:58:48 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(stage) {
|
|
|
|
|
|
|
|
case Stage::WRITE_NEW_FENCE_MESSAGE:
|
|
|
|
if (!_logger_backend->Write_Message("New fence")) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
stage = Stage::WRITE_FENCE_ITEMS;
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
|
|
|
case Stage::WRITE_FENCE_ITEMS: {
|
|
|
|
while (_fence_number_to_send < fence->polyfence().num_stored_items()) {
|
|
|
|
if (out_of_time_for_writing_messages()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// upon failure to write the fence we will re-read from
|
|
|
|
// storage; this could be improved.
|
|
|
|
AC_PolyFenceItem fenceitem {};
|
|
|
|
if (fence->polyfence().get_item(_fence_number_to_send, fenceitem)) {
|
|
|
|
if (!_logger_backend->Write_FencePoint(fence->polyfence().num_stored_items(), _fence_number_to_send, fenceitem)) {
|
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_fence_number_to_send++;
|
|
|
|
}
|
|
|
|
stage = Stage::DONE;
|
|
|
|
FALLTHROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stage::DONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_finished = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoggerMessageWriter_Write_Polyfence::reset()
|
|
|
|
{
|
|
|
|
LoggerMessageWriter::reset();
|
|
|
|
stage = Stage::WRITE_NEW_FENCE_MESSAGE;
|
|
|
|
_fence_number_to_send = 0;
|
|
|
|
}
|
|
|
|
#endif // !APM_BUILD_TYPE(APM_BUILD_Replay)
|
|
|
|
#endif // AP_FENCE_ENABLED
|
2023-09-05 10:08:30 -03:00
|
|
|
|
|
|
|
#endif // HAL_LOGGING_ENABLED
|