Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ The CLI, library, and default CLI tests build without external dependencies. Set
In the topic listing, `sensor_combined (0) - 1298` means instance 0 has 1,298 samples.
Parsing warnings go to standard error. A fatal parse error or an unreadable file produces a
nonzero exit status. The CLI keeps samples in memory while it builds the report. The C++
reader can process chunks incrementally for large logs. Logs with appended data segments
reader can process chunks incrementally for large logs. Call `Reader::finish()` after the last
chunk to report incomplete input. Logs with appended data segments
may yield partial results.

## C++ library
Expand Down
16 changes: 11 additions & 5 deletions include/flight_log/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ class Reader {
*/
void readChunk(const uint8_t* data, int length);

/**
* Signal the end of the input, reporting an incomplete file header or final message.
* Further reads and repeated calls to finish() are ignored.
*/
void finish();

private:
static constexpr int kBufferSizeInit = 2048;

static const std::set<ULogMessageType> kKnownMessageTypes;

int readMagic(const uint8_t* data, int length);
int readFlagBits(const uint8_t* data, int length);
void readMagic(const ulog_file_header_s& header);
void readFlagBits(const ulog_message_flag_bits_s& flag_bits);
void corruptionDetected();
int appendToPartialBuffer(const uint8_t* data, int length);
void tryToRecover(const uint8_t* data, int length);
void tryToRecover(const uint8_t*& data, int& length);

void readHeaderMessage(const uint8_t* message);
void readDataMessage(const uint8_t* message);
Expand All @@ -46,13 +52,13 @@ class Reader {
ReadHeader,
ReadData,
InvalidData,
Finished,
};

State _state{State::ReadMagic};
const std::shared_ptr<DataHandlerInterface> _data_handler_interface;

uint8_t* _partial_message_buffer{nullptr}; ///< contains at most one ULog message (unless
///< _need_recovery==true)
uint8_t* _partial_message_buffer{nullptr}; ///< buffers incomplete input and recovery bytes
int _partial_message_buffer_length_capacity{0};
int _partial_message_buffer_length{0};

Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ int inspectLog(const char* path)
return 1;
}
reader.readChunk(buffer.data(), static_cast<int>(file.gcount()));
if (file.eof()) {
reader.finish();
}
} while (file && !data_container->hadFatalError());

for (const auto& parsing_error : data_container->parsingErrors()) {
Expand Down
Loading
Loading