mavlink: name existing stream headers consistently and add include guards

This commit is contained in:
Daniel Agar
2020-10-07 15:44:28 -04:00
parent 674cd1e3b5
commit b51322e160
6 changed files with 69 additions and 173 deletions
+13 -5
View File
@@ -118,11 +118,11 @@
using matrix::Vector3f;
using matrix::wrap_2pi;
#include "streams/autopilot_version.h"
#include "streams/flight_information.h"
#include "streams/protocol_version.h"
#include "streams/storage_information.h"
#include "streams/AUTOPILOT_VERSION.hpp"
#include "streams/EXTENDED_SYS_STATE.hpp"
#include "streams/FLIGHT_INFORMATION.hpp"
#include "streams/PROTOCOL_VERSION.hpp"
#include "streams/STORAGE_INFORMATION.hpp"
// ensure PX4 rotation enum and MAV_SENSOR_ROTATION align
static_assert(MAV_SENSOR_ROTATION_NONE == static_cast<MAV_SENSOR_ORIENTATION>(ROTATION_NONE),
@@ -5516,7 +5516,7 @@ static const StreamListItem streams_list[] = {
create_stream_list_item<MavlinkStreamCameraTrigger>(),
create_stream_list_item<MavlinkStreamCameraImageCaptured>(),
create_stream_list_item<MavlinkStreamDistanceSensor>(),
#ifdef EXTENDED_SYS_STATE_HPP
#if defined(EXTENDED_SYS_STATE_HPP)
create_stream_list_item<MavlinkStreamExtendedSysState>(),
#endif // EXTENDED_SYS_STATE_HPP
create_stream_list_item<MavlinkStreamAltitude>(),
@@ -5532,10 +5532,18 @@ static const StreamListItem streams_list[] = {
create_stream_list_item<MavlinkStreamObstacleDistance>(),
create_stream_list_item<MavlinkStreamESCInfo>(),
create_stream_list_item<MavlinkStreamESCStatus>(),
#if defined(AUTOPILOT_VERSION_HPP)
create_stream_list_item<MavlinkStreamAutopilotVersion>(),
#endif // AUTOPILOT_VERSION_HPP
#if defined(PROTOCOL_VERSION_HPP)
create_stream_list_item<MavlinkStreamProtocolVersion>(),
#endif // PROTOCOL_VERSION_HPP
#if defined(FLIGHT_INFORMATION_HPP)
create_stream_list_item<MavlinkStreamFlightInformation>(),
#endif // FLIGHT_INFORMATION_HPP
#if defined(STORAGE_INFORMATION_HPP)
create_stream_list_item<MavlinkStreamStorageInformation>(),
#endif // STORAGE_INFORMATION_HPP
create_stream_list_item<MavlinkStreamRawRpm>()
};
@@ -31,37 +31,19 @@
*
****************************************************************************/
#pragma once
#include "../mavlink_messages.h"
#ifndef AUTOPILOT_VERSION_HPP
#define AUTOPILOT_VERSION_HPP
class MavlinkStreamAutopilotVersion : public MavlinkStream
{
public:
const char *get_name() const override
{
return MavlinkStreamAutopilotVersion::get_name_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamAutopilotVersion(mavlink); }
static constexpr const char *get_name_static()
{
return "AUTOPILOT_VERSION";
}
static constexpr const char *get_name_static() { return "AUTOPILOT_VERSION"; }
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_AUTOPILOT_VERSION; }
static constexpr uint16_t get_id_static()
{
return MAVLINK_MSG_ID_AUTOPILOT_VERSION;
}
uint16_t get_id() override
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamAutopilotVersion(mavlink);
}
const char *get_name() const override { return get_name_static(); }
uint16_t get_id() override { return get_id_static(); }
unsigned get_size() override
{
@@ -69,17 +51,12 @@ public:
}
private:
/* do not allow top copying this class */
MavlinkStreamAutopilotVersion(MavlinkStreamAutopilotVersion &) = delete;
MavlinkStreamAutopilotVersion &operator = (const MavlinkStreamAutopilotVersion &) = delete;
protected:
explicit MavlinkStreamAutopilotVersion(Mavlink *mavlink) : MavlinkStream(mavlink)
{}
explicit MavlinkStreamAutopilotVersion(Mavlink *mavlink) : MavlinkStream(mavlink) {}
bool send(const hrt_abstime t) override
{
return _mavlink->send_autopilot_capabilities();
}
};
#endif // AUTOPILOT_VERSION_HPP
@@ -37,30 +37,13 @@
class MavlinkStreamExtendedSysState : public MavlinkStream
{
public:
const char *get_name() const override
{
return MavlinkStreamExtendedSysState::get_name_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamExtendedSysState(mavlink); }
static constexpr const char *get_name_static()
{
return "EXTENDED_SYS_STATE";
}
static constexpr const char *get_name_static() { return "EXTENDED_SYS_STATE"; }
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_EXTENDED_SYS_STATE; }
static constexpr uint16_t get_id_static()
{
return MAVLINK_MSG_ID_EXTENDED_SYS_STATE;
}
uint16_t get_id() override
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamExtendedSysState(mavlink);
}
const char *get_name() const override { return get_name_static(); }
uint16_t get_id() override { return get_id_static(); }
unsigned get_size() override
{
@@ -68,24 +51,18 @@ public:
}
private:
uORB::Subscription _status_sub{ORB_ID(vehicle_status)};
uORB::Subscription _landed_sub{ORB_ID(vehicle_land_detected)};
uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)};
uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)};
mavlink_extended_sys_state_t _msg;
/* do not allow top copying this class */
MavlinkStreamExtendedSysState(MavlinkStreamExtendedSysState &) = delete;
MavlinkStreamExtendedSysState &operator = (const MavlinkStreamExtendedSysState &) = delete;
protected:
explicit MavlinkStreamExtendedSysState(Mavlink *mavlink) : MavlinkStream(mavlink),
_msg()
explicit MavlinkStreamExtendedSysState(Mavlink *mavlink) : MavlinkStream(mavlink)
{
_msg.vtol_state = MAV_VTOL_STATE_UNDEFINED;
_msg.landed_state = MAV_LANDED_STATE_ON_GROUND;
}
uORB::Subscription _status_sub{ORB_ID(vehicle_status)};
uORB::Subscription _landed_sub{ORB_ID(vehicle_land_detected)};
uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)};
uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)};
mavlink_extended_sys_state_t _msg{};
bool send(const hrt_abstime t) override
{
bool updated = false;
@@ -31,58 +31,36 @@
*
****************************************************************************/
#pragma once
#include "../mavlink_messages.h"
#ifndef FLIGHT_INFORMATION_HPP
#define FLIGHT_INFORMATION_HPP
#include <uORB/topics/actuator_armed.h>
class MavlinkStreamFlightInformation : public MavlinkStream
{
public:
const char *get_name() const override
{
return MavlinkStreamFlightInformation::get_name_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamFlightInformation(mavlink); }
static constexpr const char *get_name_static()
{
return "FLIGHT_INFORMATION";
}
static constexpr const char *get_name_static() { return "FLIGHT_INFORMATION"; }
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_FLIGHT_INFORMATION; }
static constexpr uint16_t get_id_static()
{
return MAVLINK_MSG_ID_FLIGHT_INFORMATION;
}
uint16_t get_id() override
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamFlightInformation(mavlink);
}
const char *get_name() const override { return get_name_static(); }
uint16_t get_id() override { return get_id_static(); }
unsigned get_size() override
{
return MAVLINK_MSG_ID_FLIGHT_INFORMATION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
}
private:
uORB::Subscription _armed_sub{ORB_ID(actuator_armed)};
param_t _param_com_flight_uuid;
/* do not allow top copying this class */
MavlinkStreamFlightInformation(MavlinkStreamFlightInformation &) = delete;
MavlinkStreamFlightInformation &operator = (const MavlinkStreamFlightInformation &) = delete;
protected:
private:
explicit MavlinkStreamFlightInformation(Mavlink *mavlink) : MavlinkStream(mavlink)
{
_param_com_flight_uuid = param_find("COM_FLIGHT_UUID");
}
uORB::Subscription _armed_sub{ORB_ID(actuator_armed)};
param_t _param_com_flight_uuid;
bool send(const hrt_abstime t) override
{
actuator_armed_s actuator_armed{};
@@ -102,3 +80,5 @@ protected:
return ret;
}
};
#endif // FLIGHT_INFORMATION_HPP
@@ -31,37 +31,19 @@
*
****************************************************************************/
#pragma once
#include "../mavlink_messages.h"
#ifndef PROTOCOL_VERSION_HPP
#define PROTOCOL_VERSION_HPP
class MavlinkStreamProtocolVersion : public MavlinkStream
{
public:
const char *get_name() const override
{
return MavlinkStreamProtocolVersion::get_name_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamProtocolVersion(mavlink); }
static constexpr const char *get_name_static()
{
return "PROTOCOL_VERSION";
}
static constexpr const char *get_name_static() { return "PROTOCOL_VERSION"; }
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_PROTOCOL_VERSION; }
static constexpr uint16_t get_id_static()
{
return MAVLINK_MSG_ID_PROTOCOL_VERSION;
}
uint16_t get_id() override
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamProtocolVersion(mavlink);
}
const char *get_name() const override { return get_name_static(); }
uint16_t get_id() override { return get_id_static(); }
unsigned get_size() override
{
@@ -69,14 +51,7 @@ public:
}
private:
/* do not allow top copying this class */
MavlinkStreamProtocolVersion(MavlinkStreamProtocolVersion &) = delete;
MavlinkStreamProtocolVersion &operator = (const MavlinkStreamProtocolVersion &) = delete;
protected:
explicit MavlinkStreamProtocolVersion(Mavlink *mavlink) : MavlinkStream(mavlink)
{}
explicit MavlinkStreamProtocolVersion(Mavlink *mavlink) : MavlinkStream(mavlink) {}
bool send(const hrt_abstime t) override
{
@@ -84,3 +59,5 @@ protected:
return true;
}
};
#endif // PROTOCOL_VERSION_HPP
@@ -31,9 +31,8 @@
*
****************************************************************************/
#pragma once
#include "../mavlink_messages.h"
#ifndef STORAGE_INFORMATION_HPP
#define STORAGE_INFORMATION_HPP
#ifdef __PX4_DARWIN
#include <sys/param.h>
@@ -47,30 +46,13 @@
class MavlinkStreamStorageInformation : public MavlinkStream
{
public:
const char *get_name() const override
{
return MavlinkStreamStorageInformation::get_name_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamStorageInformation(mavlink); }
static constexpr const char *get_name_static()
{
return "STORAGE_INFORMATION";
}
static constexpr const char *get_name_static() { return "STORAGE_INFORMATION"; }
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_STORAGE_INFORMATION; }
static constexpr uint16_t get_id_static()
{
return MAVLINK_MSG_ID_STORAGE_INFORMATION;
}
uint16_t get_id() override
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamStorageInformation(mavlink);
}
const char *get_name() const override { return get_name_static(); }
uint16_t get_id() override { return get_id_static(); }
unsigned get_size() override
{
@@ -84,16 +66,9 @@ public:
return send(hrt_absolute_time());
}
private:
int _storage_id = 0;
explicit MavlinkStreamStorageInformation(Mavlink *mavlink) : MavlinkStream(mavlink) {}
/* do not allow top copying this class */
MavlinkStreamStorageInformation(MavlinkStreamStorageInformation &) = delete;
MavlinkStreamStorageInformation &operator = (const MavlinkStreamStorageInformation &) = delete;
protected:
explicit MavlinkStreamStorageInformation(Mavlink *mavlink) : MavlinkStream(mavlink)
{}
int _storage_id{0};
bool send(const hrt_abstime t) override
{
@@ -133,3 +108,5 @@ protected:
return true;
}
};
#endif // STORAGE_INFORMATION_HPP