QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4ULogUtility.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QString>
4
5#include <cstdint>
6#include <functional>
7#include <memory>
8#include <set>
9#include <string>
10
11#include <ulog_cpp/data_handler_interface.hpp>
12#include <ulog_cpp/messages.hpp>
13#include <ulog_cpp/subscription.hpp>
14
15namespace PX4ULogUtility
16{
17
18// ============================================================================
19// Constants
20// ============================================================================
21
23constexpr char kMagicBytes[] = {'U', 'L', 'o', 'g'};
24constexpr int kMagicSize = 4;
25constexpr int kHeaderSize = 16; // Full header size
26
27// ============================================================================
28// Header Validation
29// ============================================================================
30
35bool isValidHeader(const char *data, qint64 size);
36
41int getVersion(const char *data, qint64 size);
42
47uint64_t getHeaderTimestamp(const char *data, qint64 size);
48
49// ============================================================================
50// Message Iteration
51// ============================================================================
52
56using MessageCallback = std::function<bool(const ulog_cpp::TypedDataView &sample)>;
57
62class MessageHandler : public ulog_cpp::DataHandlerInterface {
63public:
68 explicit MessageHandler(const std::string &messageName,
69 const MessageCallback &callback,
70 QString &errorMsg);
71 virtual ~MessageHandler() = default;
72
73 // DataHandlerInterface overrides
74 void error(const std::string &msg, bool is_recoverable) override;
75 void messageFormat(const ulog_cpp::MessageFormat &message_format) override;
76 void addLoggedMessage(const ulog_cpp::AddLoggedMessage &add_logged_message) override;
77 void headerComplete() override;
78 void data(const ulog_cpp::Data &data) override;
79
81 bool hadFatalError() const { return _hadFatalError; }
82
84 bool isHeaderComplete() const { return _headerComplete; }
85
87 int messageCount() const { return _messageCount; }
88
90 bool hasMessageFormat() const { return _messageFormat != nullptr; }
91
92private:
93 std::string _targetMessageName;
94 MessageCallback _callback;
95 QString &_errorMessage;
96 std::shared_ptr<ulog_cpp::MessageFormat> _messageFormat;
97 std::set<uint16_t> _messageIds;
98 bool _hadFatalError = false;
99 bool _headerComplete = false;
100 int _messageCount = 0;
101};
102
110bool iterateMessages(const char *data, qint64 size,
111 const std::string &messageName,
112 const MessageCallback &callback,
113 QString &errorMessage);
114
115} // namespace PX4ULogUtility
Error error
Generic streaming handler for ULog messages by name.
int messageCount() const
Get the number of messages processed.
bool hadFatalError() const
Check if a fatal error occurred during parsing.
virtual ~MessageHandler()=default
void messageFormat(const ulog_cpp::MessageFormat &message_format) override
void addLoggedMessage(const ulog_cpp::AddLoggedMessage &add_logged_message) override
bool isHeaderComplete() const
Check if the ULog header was successfully parsed.
bool hasMessageFormat() const
Check if the target message format was found.
void data(const ulog_cpp::Data &data) override
uint64_t getHeaderTimestamp(const char *data, qint64 size)
int getVersion(const char *data, qint64 size)
bool isValidHeader(const char *data, qint64 size)
std::function< bool(const ulog_cpp::TypedDataView &sample)> MessageCallback
constexpr int kMagicSize
bool iterateMessages(const char *data, qint64 size, const std::string &messageName, const MessageCallback &callback, QString &errorMessage)
constexpr char kMagicBytes[]
ULog file magic bytes: "ULog" followed by 0x01 (version 1) followed by 0x12 (file compat)
constexpr int kHeaderSize