diff --git a/src/modules/mavlink/mavlink_main.cpp b/src/modules/mavlink/mavlink_main.cpp index b004f549aa..852351f46f 100644 --- a/src/modules/mavlink/mavlink_main.cpp +++ b/src/modules/mavlink/mavlink_main.cpp @@ -1716,6 +1716,7 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream) configure_stream_local("EXTENDED_SYS_STATE", 1.0f); configure_stream_local("GLOBAL_POSITION_INT", 5.0f); configure_stream_local("GPS_RAW_INT", 1.0f); + configure_stream_local("GPS2_RAW", 1.0f); configure_stream_local("HIGHRES_IMU", 1.5f); configure_stream_local("HOME_POSITION", 0.5f); configure_stream_local("LOCAL_POSITION_NED", 1.0f); @@ -1752,6 +1753,7 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream) configure_stream_local("EXTENDED_SYS_STATE", 5.0f); configure_stream_local("GLOBAL_POSITION_INT", 50.0f); configure_stream_local("GPS_RAW_INT", unlimited_rate); + configure_stream_local("GPS2_RAW", unlimited_rate); configure_stream_local("HIGHRES_IMU", 50.0f); configure_stream_local("HOME_POSITION", 0.5f); configure_stream_local("LOCAL_POSITION_NED", 30.0f); @@ -1812,6 +1814,7 @@ Mavlink::configure_streams_to_default(const char *configure_single_stream) configure_stream_local("DEBUG_VECT", 50.0f); configure_stream_local("DISTANCE_SENSOR", 10.0f); configure_stream_local("GPS_RAW_INT", unlimited_rate); + configure_stream_local("GPS2_RAW", unlimited_rate); configure_stream_local("ESTIMATOR_STATUS", 5.0f); configure_stream_local("EXTENDED_SYS_STATE", 2.0f); configure_stream_local("GLOBAL_POSITION_INT", 10.0f); diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp index 00596fa401..81286c13c7 100644 --- a/src/modules/mavlink/mavlink_messages.cpp +++ b/src/modules/mavlink/mavlink_messages.cpp @@ -1388,6 +1388,82 @@ protected: } }; +class MavlinkStreamGPS2Raw : public MavlinkStream +{ +public: + const char *get_name() const + { + return MavlinkStreamGPS2Raw::get_name_static(); + } + + static const char *get_name_static() + { + return "GPS2_RAW"; + } + + static uint16_t get_id_static() + { + return MAVLINK_MSG_ID_GPS2_RAW; + } + + uint16_t get_id() + { + return get_id_static(); + } + + static MavlinkStream *new_instance(Mavlink *mavlink) + { + return new MavlinkStreamGPS2Raw(mavlink); + } + + unsigned get_size() + { + return (_gps_time > 0) ? (MAVLINK_MSG_ID_GPS2_RAW_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; + } + +private: + MavlinkOrbSubscription *_gps_sub; + uint64_t _gps_time; + + /* do not allow top copying this class */ + MavlinkStreamGPS2Raw(MavlinkStreamGPS2Raw &) = delete; + MavlinkStreamGPS2Raw &operator = (const MavlinkStreamGPS2Raw &) = delete; + +protected: + explicit MavlinkStreamGPS2Raw(Mavlink *mavlink) : MavlinkStream(mavlink), + _gps_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_gps_position), 1)), + _gps_time(0) + {} + + bool send(const hrt_abstime t) + { + vehicle_gps_position_s gps; + + if (_gps_sub->update(&_gps_time, &gps)) { + mavlink_gps2_raw_t msg = {}; + + msg.time_usec = gps.timestamp; + msg.fix_type = gps.fix_type; + msg.lat = gps.lat; + msg.lon = gps.lon; + msg.alt = gps.alt; + msg.eph = gps.eph * 1e3f; + msg.epv = gps.epv * 1e3f; + msg.vel = cm_uint16_from_m_float(gps.vel_m_s); + msg.cog = math::degrees(wrap_2pi(gps.cog_rad)) * 1e2f; + msg.satellites_visible = gps.satellites_used; + //msg.dgps_numch = // Number of DGPS satellites + //msg.dgps_age = // Age of DGPS info + + mavlink_msg_gps2_raw_send_struct(_mavlink->get_channel(), &msg); + + return true; + } + + return false; + } +}; + class MavlinkStreamSystemTime : public MavlinkStream { public: @@ -4447,6 +4523,7 @@ static const StreamListItem streams_list[] = { StreamListItem(&MavlinkStreamAttitudeQuaternion::new_instance, &MavlinkStreamAttitudeQuaternion::get_name_static, &MavlinkStreamAttitudeQuaternion::get_id_static), StreamListItem(&MavlinkStreamVFRHUD::new_instance, &MavlinkStreamVFRHUD::get_name_static, &MavlinkStreamVFRHUD::get_id_static), StreamListItem(&MavlinkStreamGPSRawInt::new_instance, &MavlinkStreamGPSRawInt::get_name_static, &MavlinkStreamGPSRawInt::get_id_static), + StreamListItem(&MavlinkStreamGPS2Raw::new_instance, &MavlinkStreamGPS2Raw::get_name_static, &MavlinkStreamGPS2Raw::get_id_static), StreamListItem(&MavlinkStreamSystemTime::new_instance, &MavlinkStreamSystemTime::get_name_static, &MavlinkStreamSystemTime::get_id_static), StreamListItem(&MavlinkStreamTimesync::new_instance, &MavlinkStreamTimesync::get_name_static, &MavlinkStreamTimesync::get_id_static), StreamListItem(&MavlinkStreamGlobalPositionInt::new_instance, &MavlinkStreamGlobalPositionInt::get_name_static, &MavlinkStreamGlobalPositionInt::get_id_static),