diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp index 5db7f93455..2651a628f1 100644 --- a/src/modules/mavlink/mavlink_messages.cpp +++ b/src/modules/mavlink/mavlink_messages.cpp @@ -85,7 +85,6 @@ #include #include #include -#include #include #include #include @@ -123,6 +122,7 @@ using matrix::wrap_2pi; #include "streams/EXTENDED_SYS_STATE.hpp" #include "streams/FLIGHT_INFORMATION.hpp" #include "streams/PROTOCOL_VERSION.hpp" +#include "streams/RAW_RPM.hpp" #include "streams/STORAGE_INFORMATION.hpp" // ensure PX4 rotation enum and MAV_SENSOR_ROTATION align @@ -5229,70 +5229,6 @@ protected: } }; - - -class MavlinkStreamRawRpm : public MavlinkStream -{ -public: - const char *get_name() const override - { - return MavlinkStreamRawRpm::get_name_static(); - } - - static constexpr const char *get_name_static() - { - return "RAW_RPM"; - } - - static constexpr uint16_t get_id_static() - { - return MAVLINK_MSG_ID_RAW_RPM; - } - - uint16_t get_id() override - { - return get_id_static(); - } - - static MavlinkStream *new_instance(Mavlink *mavlink) - { - return new MavlinkStreamRawRpm(mavlink); - } - - unsigned get_size() override - { - return _rpm_sub.advertised() ? MAVLINK_MSG_ID_RAW_RPM + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; - } - -private: - uORB::Subscription _rpm_sub{ORB_ID(rpm)}; - - /* do not allow top copying this class */ - MavlinkStreamRawRpm(MavlinkStreamRawRpm &) = delete; - MavlinkStreamRawRpm &operator = (const MavlinkStreamRawRpm &) = delete; - -protected: - explicit MavlinkStreamRawRpm(Mavlink *mavlink) : MavlinkStream(mavlink) - {} - - bool send(const hrt_abstime t) override - { - rpm_s rpm; - - if (_rpm_sub.update(&rpm)) { - mavlink_raw_rpm_t msg{}; - - msg.frequency = rpm.indicated_frequency_rpm; - - mavlink_msg_raw_rpm_send_struct(_mavlink->get_channel(), &msg); - - return true; - } - - return false; - } -}; - static const StreamListItem streams_list[] = { create_stream_list_item(), create_stream_list_item(), @@ -5374,7 +5310,9 @@ static const StreamListItem streams_list[] = { #if defined(STORAGE_INFORMATION_HPP) create_stream_list_item(), #endif // STORAGE_INFORMATION_HPP +#if defined(RAW_RPM_HPP) create_stream_list_item() +#endif // RAW_RPM_HPP }; const char *get_stream_name(const uint16_t msg_id) diff --git a/src/modules/mavlink/streams/RAW_RPM.hpp b/src/modules/mavlink/streams/RAW_RPM.hpp new file mode 100644 index 0000000000..eb3802c383 --- /dev/null +++ b/src/modules/mavlink/streams/RAW_RPM.hpp @@ -0,0 +1,78 @@ +/**************************************************************************** + * + * Copyright (c) 2020 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef RAW_RPM_HPP +#define RAW_RPM_HPP + +#include + +class MavlinkStreamRawRpm : public MavlinkStream +{ +public: + static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamRawRpm(mavlink); } + + static constexpr const char *get_name_static() { return "RAW_RPM"; } + static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_RAW_RPM; } + + const char *get_name() const override { return get_name_static(); } + uint16_t get_id() override { return get_id_static(); } + + unsigned get_size() override + { + return _rpm_sub.advertised() ? MAVLINK_MSG_ID_RAW_RPM + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; + } + +private: + explicit MavlinkStreamRawRpm(Mavlink *mavlink) : MavlinkStream(mavlink) {} + + uORB::Subscription _rpm_sub{ORB_ID(rpm)}; + + bool send(const hrt_abstime t) override + { + rpm_s rpm; + + if (_rpm_sub.update(&rpm)) { + mavlink_raw_rpm_t msg{}; + + msg.frequency = rpm.indicated_frequency_rpm; + + mavlink_msg_raw_rpm_send_struct(_mavlink->get_channel(), &msg); + + return true; + } + + return false; + } +}; + +#endif // RAW_RPM_HPP