Skip to content

Commit

Permalink
AP_Logger: entirely remove twin paths for writing FMT messages
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Jul 5, 2024
1 parent a7d2d9a commit b0b62e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
9 changes: 8 additions & 1 deletion libraries/AP_Logger/AP_Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,15 @@ int16_t AP_Logger::find_free_msg_type() const
* It is assumed that logstruct's char* variables are valid strings of
* maximum lengths for those fields (given in LogStructure.h e.g. LS_NAME_SIZE)
*/
bool AP_Logger::fill_log_write_logstructure(struct LogStructure &logstruct, const uint8_t msg_type) const
bool AP_Logger::fill_logstructure(struct LogStructure &logstruct, const uint8_t msg_type) const
{
// check the static lists first...
const LogStructure *found = structure_for_msg_type(msg_type);
if (found != nullptr) {
logstruct = *found;
return true;
}

// find log structure information corresponding to msg_type:
struct log_write_fmt *f;
for (f = log_write_fmts; f; f=f->next) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Logger/AP_Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class AP_Logger
int16_t find_free_msg_type() const;

// fill LogStructure with information about msg_type
bool fill_log_write_logstructure(struct LogStructure &logstruct, const uint8_t msg_type) const;
bool fill_logstructure(struct LogStructure &logstruct, const uint8_t msg_type) const;

bool _armed;

Expand Down
34 changes: 3 additions & 31 deletions libraries/AP_Logger/AP_Logger_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ bool AP_Logger_Backend::Write_Emit_FMT(uint8_t msg_type)
ls.units,
ls.multipliers
};
if (!_front.fill_log_write_logstructure(logstruct, msg_type)) {
if (!_front.fill_logstructure(logstruct, msg_type)) {
// this is a bug; we've been asked to write out the FMT
// message for a msg_type, but the frontend can't supply the
// required information
Expand All @@ -195,12 +195,6 @@ bool AP_Logger_Backend::Write_Emit_FMT(uint8_t msg_type)

bool AP_Logger_Backend::Write(const uint8_t msg_type, va_list arg_list, bool is_critical, bool is_streaming)
{
if (!have_emitted_format_for_type(LogMessages(msg_type))) {
if (!Write_Emit_FMT(msg_type)) {
return false;
}
}

// stack-allocate a buffer so we can WriteBlock(); this could be
// 255 bytes! If we were willing to lose the WriteBlock
// abstraction we could do WriteBytes() here instead?
Expand Down Expand Up @@ -408,28 +402,6 @@ void AP_Logger_Backend::validate_WritePrioritisedBlock(const void *pBuffer,
}
#endif

bool AP_Logger_Backend::emit_format_for_type(LogMessages a_type)
{
// linearly scan the formats structure to find the format for the type:
for (uint8_t i=0; i< num_types(); i++) {
const auto &s { structure(i) };
if (s == nullptr) {
continue;
}
if (s->msg_type != a_type) {
continue;
}
// found the relevant structure. Attempt to write it:
if (!Write_Format(s)) {
return false;
}
return true;
}
// didn't find the structure. That's probably bad...
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);
return false;
}

bool AP_Logger_Backend::ensure_format_emitted(const void *pBuffer, uint16_t size)
{
#if APM_BUILD_TYPE(APM_BUILD_Replay)
Expand All @@ -452,11 +424,11 @@ bool AP_Logger_Backend::ensure_format_emitted(const void *pBuffer, uint16_t size
return true;
}
if (!have_emitted_format_for_type(LOG_FORMAT_MSG) &&
!emit_format_for_type(LOG_FORMAT_MSG)) {
!Write_Emit_FMT(LOG_FORMAT_MSG)) {
return false;
}

return emit_format_for_type(type);
return Write_Emit_FMT(type);
}

bool AP_Logger_Backend::WritePrioritisedBlock(const void *pBuffer, uint16_t size, bool is_critical, bool writev_streaming)
Expand Down

0 comments on commit b0b62e1

Please sign in to comment.