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
60class MessageHandler : public ulog_cpp::DataHandlerInterface {
61public:
66 explicit MessageHandler(const std::string &messageName,
67 const MessageCallback &callback,
68 QString &errorMsg);
69 virtual ~MessageHandler() = default;
70
71 // DataHandlerInterface overrides
72 void error(const std::string &msg, bool is_recoverable) override;
73 void messageFormat(const ulog_cpp::MessageFormat &message_format) override;
74 void addLoggedMessage(const ulog_cpp::AddLoggedMessage &add_logged_message) override;
75 void headerComplete() override;
76 void data(const ulog_cpp::Data &data) override;
77
79 bool hadFatalError() const { return _hadFatalError; }
80
82 bool isHeaderComplete() const { return _headerComplete; }
83
85 int messageCount() const { return _messageCount; }
86
88 bool hasMessageFormat() const { return _messageFormat != nullptr; }
89
90private:
91 std::string _targetMessageName;
92 MessageCallback _callback;
93 QString &_errorMessage;
94 std::shared_ptr<ulog_cpp::MessageFormat> _messageFormat;
95 std::set<uint16_t> _messageIds;
96 bool _hadFatalError = false;
97 bool _headerComplete = false;
98 int _messageCount = 0;
99};
100
108bool iterateMessages(const char *data, qint64 size,
109 const std::string &messageName,
110 const MessageCallback &callback,
111 QString &errorMessage);
112
113} // namespace PX4ULogUtility
Error error
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