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