5#include <QtCore/QSharedPointer>
6#include <QtCore/QTimer>
7#include <QtCore/QVector>
24 auto error_cb = [
this](
int num_events_lost) {
26 qCWarning(EventHandlerLog) <<
"Events got lost:" << num_events_lost
30 auto timeout_cb = [
this](
int timeout_ms) {
34 timer.setSingleShot(
true);
35 timer.start(timeout_ms);
39 parser.setProfile(profile.toStdString());
40 parser.formatters().url = [](
const std::string &content,
const std::string &link) {
41 return
"<a href=\"" + link +
"\">" + content +
"</a>";
43 parser.formatters().param = [](
const std::string &content) {
44 return
"<a href=\"param://" + content +
"\">" + content +
"</a>";
46 parser.formatters().escape = [](
const std::string &str) {
47 return QString::fromStdString(str).toHtmlEscaped().toStdString();
50 events::ReceiveProtocol::Callbacks callbacks{
53 std::bind(&Impl::gotEvent, this, std::placeholders::_1),
55 protocol =
new events::ReceiveProtocol(callbacks, ourSystemId, ourComponentId,
56 systemId, componentId);
58 QObject::connect(&
timer, &QTimer::timeout,
q, [
this]() { protocol->timerEvent(); });
79 if (!
parser.hasDefinitions()) {
83 qCDebug(EventHandlerLog) <<
"No metadata, queuing event, ID:" <<
event.id
89 std::unique_ptr<events::parser::ParsedEvent> parsed_event =
parser.parse(events::EventType(event));
90 if (parsed_event ==
nullptr) {
91 qCWarning(EventHandlerLog) <<
"Got Event w/o known metadata: ID:" <<
event.id
96 qCDebug(EventHandlerLog) <<
"Got Event: ID:" << parsed_event->id()
97 <<
"namespace:" << parsed_event->eventNamespace().c_str()
98 <<
"name:" << parsed_event->name().c_str()
99 <<
"msg:" << parsed_event->message().c_str();
103 emit
q->healthAndArmingChecksUpdated();
112 quint32 systemId, uint8_t componentId)
114 , _impl(std::make_unique<
Impl>(this, profile, std::move(handleEventCB), std::move(sendRequestCB), ourSystemId,
115 ourComponentId, systemId, componentId))
123 _impl->protocol->processMessage(message);
128 if (_impl->parser.loadDefinitionsFile(metadataJsonFileName.toStdString())) {
129 if (_impl->parser.hasDefinitions()) {
131 for (
const auto &event : _impl->pendingEvents) {
132 _impl->gotEvent(event);
134 _impl->pendingEvents.clear();
137 qCWarning(EventHandlerLog) <<
"Failed to load events JSON metadata file";
143 return &_impl->healthAndArmingChecks;
148 return _impl->healthAndArmingChecksValid;
153 events::parser::Parser::NavigationModeGroups groups = _impl->parser.navigationModeGroups(_impl->compid);
154 for (
const auto &groupIter : groups.groups) {
155 if (groupIter.second.find(customMode) != groupIter.second.end()) {
156 return groupIter.first;
164 const auto &protocols = _impl->parser.supportedProtocols(_impl->compid);
165 return protocols.find(
"health_and_arming_check") != protocols.end();
struct __mavlink_message mavlink_message_t
#define QGC_LOGGING_CATEGORY(name, categoryStr)
struct __mavlink_event_t mavlink_event_t
EventHandler(QObject *parent, const QString &profile, handle_event_f handleEventCB, send_request_event_message_f sendRequestCB, quint32 ourSystemId, uint8_t ourComponentId, quint32 systemId, uint8_t componentId)
void handleEvents(const mavlink_message_t &message)
void setMetadata(const QString &metadataJsonFileName)
const events::HealthAndArmingChecks * healthAndArmingChecks() const
std::function< void(const mavlink_request_event_t &msg, uint32_t targetSystemId)> send_request_event_message_f
std::function< void(std::unique_ptr< events::parser::ParsedEvent >)> handle_event_f
int getModeGroup(int32_t customMode) const
bool healthAndArmingChecksSupported() const
bool healthAndArmingCheckResultsValid() const
events::HealthAndArmingChecks healthAndArmingChecks
events::ReceiveProtocol * protocol
events::parser::Parser parser
bool healthAndArmingChecksValid
void gotEvent(const mavlink_event_t &event)
QVector< mavlink_event_t > pendingEvents
stores incoming events until we have the metadata loaded
Impl(EventHandler *q_, const QString &profile, handle_event_f handleEventCB_, send_request_event_message_f sendRequestCB_, quint32 ourSystemId, uint8_t ourComponentId, quint32 systemId, uint8_t componentId)
handle_event_f handleEventCB
send_request_event_message_f sendRequestCB