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"
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2017-09-21 19:35:31 -03:00
|
|
|
#define FORCE_VERSION_H_INCLUDE
|
|
|
|
#include "ap_version.h"
|
|
|
|
#undef FORCE_VERSION_H_INCLUDE
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
2015-08-06 09:18:28 -03:00
|
|
|
_writesysinfo.reset();
|
|
|
|
_writeentiremission.reset();
|
2018-12-29 00:01:46 -04:00
|
|
|
_writeallrallypoints.reset();
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
stage = ls_blockwriter_stage_init;
|
|
|
|
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;
|
2015-08-06 09:18:28 -03:00
|
|
|
ap = AP_Param::first(&token, &type);
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void LoggerMessageWriter_DFLogStart::process()
|
2015-08-06 09:18:28 -03:00
|
|
|
{
|
|
|
|
switch(stage) {
|
|
|
|
case ls_blockwriter_stage_init:
|
|
|
|
stage = ls_blockwriter_stage_formats;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ls_blockwriter_stage_formats:
|
|
|
|
// write log formats so the log is self-describing
|
2015-11-09 18:14:22 -04:00
|
|
|
while (next_format_to_send < _dataflash_backend->num_types()) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (!_dataflash_backend->Write_Format(_dataflash_backend->structure(next_format_to_send))) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
next_format_to_send++;
|
|
|
|
}
|
2015-09-17 07:28:50 -03:00
|
|
|
_fmt_done = true;
|
2015-08-06 09:18:28 -03:00
|
|
|
stage = ls_blockwriter_stage_parms;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2015-12-07 20:51:46 -04:00
|
|
|
case ls_blockwriter_stage_units:
|
|
|
|
while (_next_unit_to_send < _dataflash_backend->num_units()) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (!_dataflash_backend->Write_Unit(_dataflash_backend->unit(_next_unit_to_send))) {
|
2015-12-07 20:51:46 -04:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
_next_unit_to_send++;
|
|
|
|
}
|
|
|
|
stage = ls_blockwriter_stage_multipliers;
|
2018-01-10 22:46:46 -04:00
|
|
|
FALLTHROUGH;
|
2015-12-07 20:51:46 -04:00
|
|
|
|
|
|
|
case ls_blockwriter_stage_multipliers:
|
|
|
|
while (_next_multiplier_to_send < _dataflash_backend->num_multipliers()) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (!_dataflash_backend->Write_Multiplier(_dataflash_backend->multiplier(_next_multiplier_to_send))) {
|
2015-12-07 20:51:46 -04:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
_next_multiplier_to_send++;
|
|
|
|
}
|
|
|
|
stage = ls_blockwriter_stage_units;
|
2018-01-10 22:46:46 -04:00
|
|
|
FALLTHROUGH;
|
2015-12-07 20:51:46 -04:00
|
|
|
|
|
|
|
case ls_blockwriter_stage_format_units:
|
|
|
|
while (_next_format_unit_to_send < _dataflash_backend->num_types()) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (!_dataflash_backend->Write_Format_Units(_dataflash_backend->structure(_next_format_unit_to_send))) {
|
2015-12-07 20:51:46 -04:00
|
|
|
return; // call me again!
|
|
|
|
}
|
|
|
|
_next_format_unit_to_send++;
|
|
|
|
}
|
|
|
|
stage = ls_blockwriter_stage_parms;
|
2018-01-10 22:46:46 -04:00
|
|
|
FALLTHROUGH;
|
2015-12-07 20:51:46 -04:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
case ls_blockwriter_stage_parms:
|
|
|
|
while (ap) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (!_dataflash_backend->Write_Parameter(ap, token, type)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ap = AP_Param::next_scalar(&token, &type);
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = ls_blockwriter_stage_sysinfo;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ls_blockwriter_stage_sysinfo:
|
|
|
|
_writesysinfo.process();
|
|
|
|
if (!_writesysinfo.finished()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stage = ls_blockwriter_stage_write_entire_mission;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ls_blockwriter_stage_write_entire_mission:
|
|
|
|
_writeentiremission.process();
|
|
|
|
if (!_writeentiremission.finished()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-29 00:01:46 -04:00
|
|
|
stage = ls_blockwriter_stage_write_all_rally_points;
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
|
|
|
case ls_blockwriter_stage_write_all_rally_points:
|
|
|
|
_writeallrallypoints.process();
|
|
|
|
if (!_writeallrallypoints.finished()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-06 09:18:28 -03:00
|
|
|
stage = ls_blockwriter_stage_vehicle_messages;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ls_blockwriter_stage_vehicle_messages:
|
|
|
|
// 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
|
2015-11-09 18:14:22 -04:00
|
|
|
if (_dataflash_backend->vehicle_message_writer()) {
|
|
|
|
if (_dataflash_backend->bufferspace_available() < 200) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return;
|
|
|
|
}
|
2015-11-09 18:14:22 -04:00
|
|
|
(_dataflash_backend->vehicle_message_writer())();
|
2015-08-06 09:18:28 -03:00
|
|
|
}
|
|
|
|
stage = ls_blockwriter_stage_done;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ls_blockwriter_stage_done:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_finished = true;
|
|
|
|
}
|
|
|
|
|
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();
|
2015-08-06 09:18:28 -03:00
|
|
|
stage = ws_blockwriter_stage_init;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
case ws_blockwriter_stage_init:
|
|
|
|
stage = ws_blockwriter_stage_firmware_string;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ws_blockwriter_stage_firmware_string:
|
2019-01-18 00:24:08 -04:00
|
|
|
if (! _dataflash_backend->Write_Message(fwver.fw_string)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
stage = ws_blockwriter_stage_git_versions;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ws_blockwriter_stage_git_versions:
|
2018-06-12 00:34:00 -03:00
|
|
|
if (fwver.middleware_name && fwver.os_name) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (! _dataflash_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-01-18 00:24:08 -04:00
|
|
|
if (! _dataflash_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
|
|
|
}
|
|
|
|
stage = ws_blockwriter_stage_system_id;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case ws_blockwriter_stage_system_id:
|
|
|
|
char sysid[40];
|
|
|
|
if (hal.util->get_system_id(sysid)) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (! _dataflash_backend->Write_Message(sysid)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_finished = true; // all done!
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
case ar_blockwriter_stage_init:
|
|
|
|
if (_rally == nullptr) {
|
|
|
|
stage = ar_blockwriter_stage_done;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stage = ar_blockwriter_stage_write_new_rally_message;
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
|
|
|
case ar_blockwriter_stage_write_new_rally_message:
|
2018-12-29 00:02:29 -04:00
|
|
|
if (! _dataflash_backend->Write_Message("New rally")) {
|
2018-12-29 00:01:46 -04:00
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
stage = ar_blockwriter_stage_write_all_rally_points;
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
|
|
|
case ar_blockwriter_stage_write_all_rally_points:
|
|
|
|
while (_rally_number_to_send < _rally->get_rally_total()) {
|
|
|
|
RallyLocation rallypoint;
|
|
|
|
if (_rally->get_rally_point_with_index(_rally_number_to_send, rallypoint)) {
|
2018-12-29 00:02:29 -04:00
|
|
|
if (!_dataflash_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++;
|
|
|
|
}
|
|
|
|
stage = ar_blockwriter_stage_done;
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
|
|
|
case ar_blockwriter_stage_done:
|
|
|
|
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();
|
2018-12-29 00:01:46 -04:00
|
|
|
stage = ar_blockwriter_stage_init;
|
|
|
|
_rally_number_to_send = 0;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
case em_blockwriter_stage_init:
|
2016-10-30 02:24:21 -03:00
|
|
|
if (_mission == nullptr) {
|
2015-08-06 09:18:28 -03:00
|
|
|
stage = em_blockwriter_stage_done;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
stage = em_blockwriter_stage_write_new_mission_message;
|
|
|
|
}
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
|
|
|
case em_blockwriter_stage_write_new_mission_message:
|
2019-01-18 00:24:08 -04:00
|
|
|
if (! _dataflash_backend->Write_Message("New mission")) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
stage = em_blockwriter_stage_write_mission_items;
|
2017-08-22 14:28:10 -03:00
|
|
|
FALLTHROUGH;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2019-01-01 23:13:54 -04:00
|
|
|
case em_blockwriter_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()) {
|
|
|
|
// 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)) {
|
2019-01-18 00:24:08 -04:00
|
|
|
if (!_dataflash_backend->Write_Mission_Cmd(*_mission, cmd)) {
|
2015-08-06 09:18:28 -03:00
|
|
|
return; // call me again
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_mission_number_to_send++;
|
|
|
|
}
|
|
|
|
stage = em_blockwriter_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
|
|
|
|
|
|
|
case em_blockwriter_stage_done:
|
|
|
|
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();
|
2015-08-06 09:18:28 -03:00
|
|
|
stage = em_blockwriter_stage_init;
|
|
|
|
_mission_number_to_send = 0;
|
|
|
|
}
|