mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-14 13:21:36 +08:00
mavlink: STATUSTEXT directly use mavlink_log subscription
- ORB_ID(mavlink_log) increase queue depth now that mavlink ringbuffer is gone
This commit is contained in:
@@ -51,7 +51,6 @@
|
||||
#include <lib/mathlib/mathlib.h>
|
||||
#include <lib/matrix/matrix/math.hpp>
|
||||
#include <px4_platform_common/time.h>
|
||||
#include <systemlib/mavlink_log.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <uORB/Subscription.hpp>
|
||||
@@ -74,7 +73,6 @@
|
||||
#include <uORB/topics/home_position.h>
|
||||
#include <uORB/topics/input_rc.h>
|
||||
#include <uORB/topics/manual_control_setpoint.h>
|
||||
#include <uORB/topics/mavlink_log.h>
|
||||
#include <uORB/topics/optical_flow.h>
|
||||
#include <uORB/topics/position_controller_status.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
@@ -124,6 +122,7 @@ using matrix::wrap_2pi;
|
||||
#include "streams/PING.hpp"
|
||||
#include "streams/PROTOCOL_VERSION.hpp"
|
||||
#include "streams/RAW_RPM.hpp"
|
||||
#include "streams/STATUSTEXT.hpp"
|
||||
#include "streams/STORAGE_INFORMATION.hpp"
|
||||
#include "streams/WIND_COV.hpp"
|
||||
|
||||
@@ -464,98 +463,6 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
class MavlinkStreamStatustext : public MavlinkStream
|
||||
{
|
||||
public:
|
||||
const char *get_name() const override
|
||||
{
|
||||
return MavlinkStreamStatustext::get_name_static();
|
||||
}
|
||||
|
||||
static constexpr const char *get_name_static()
|
||||
{
|
||||
return "STATUSTEXT";
|
||||
}
|
||||
|
||||
static constexpr uint16_t get_id_static()
|
||||
{
|
||||
return MAVLINK_MSG_ID_STATUSTEXT;
|
||||
}
|
||||
|
||||
uint16_t get_id() override
|
||||
{
|
||||
return get_id_static();
|
||||
}
|
||||
|
||||
static MavlinkStream *new_instance(Mavlink *mavlink)
|
||||
{
|
||||
return new MavlinkStreamStatustext(mavlink);
|
||||
}
|
||||
|
||||
unsigned get_size() override
|
||||
{
|
||||
return _mavlink->get_logbuffer()->empty() ? 0 : (MAVLINK_MSG_ID_STATUSTEXT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES);
|
||||
}
|
||||
|
||||
private:
|
||||
/* do not allow top copying this class */
|
||||
MavlinkStreamStatustext(MavlinkStreamStatustext &) = delete;
|
||||
MavlinkStreamStatustext &operator = (const MavlinkStreamStatustext &) = delete;
|
||||
|
||||
protected:
|
||||
int _id{0};
|
||||
|
||||
explicit MavlinkStreamStatustext(Mavlink *mavlink) : MavlinkStream(mavlink)
|
||||
{}
|
||||
|
||||
bool send() override
|
||||
{
|
||||
if (!_mavlink->get_logbuffer()->empty() && _mavlink->is_connected() && _mavlink->get_free_tx_buf() >= get_size()) {
|
||||
|
||||
mavlink_log_s mavlink_log;
|
||||
|
||||
if (_mavlink->get_logbuffer()->get(&mavlink_log)) {
|
||||
|
||||
mavlink_statustext_t msg{};
|
||||
const char *text = mavlink_log.text;
|
||||
constexpr unsigned max_chunk_size = sizeof(msg.text);
|
||||
msg.severity = mavlink_log.severity;
|
||||
msg.chunk_seq = 0;
|
||||
msg.id = _id++;
|
||||
unsigned text_size;
|
||||
|
||||
while ((text_size = strlen(text)) > 0) {
|
||||
unsigned chunk_size = math::min(text_size, max_chunk_size);
|
||||
|
||||
if (chunk_size < max_chunk_size) {
|
||||
memcpy(&msg.text[0], &text[0], chunk_size);
|
||||
// pad with zeros
|
||||
memset(&msg.text[0] + chunk_size, 0, max_chunk_size - chunk_size);
|
||||
|
||||
} else {
|
||||
memcpy(&msg.text[0], &text[0], chunk_size);
|
||||
}
|
||||
|
||||
mavlink_msg_statustext_send_struct(_mavlink->get_channel(), &msg);
|
||||
|
||||
if (text_size <= max_chunk_size) {
|
||||
break;
|
||||
|
||||
} else {
|
||||
text += max_chunk_size;
|
||||
}
|
||||
|
||||
msg.chunk_seq += 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class MavlinkStreamCommandLong : public MavlinkStream
|
||||
{
|
||||
public:
|
||||
@@ -4377,7 +4284,9 @@ protected:
|
||||
|
||||
static const StreamListItem streams_list[] = {
|
||||
create_stream_list_item<MavlinkStreamHeartbeat>(),
|
||||
#if defined(STATUSTEXT_HPP)
|
||||
create_stream_list_item<MavlinkStreamStatustext>(),
|
||||
#endif // STATUSTEXT_HPP
|
||||
create_stream_list_item<MavlinkStreamCommandLong>(),
|
||||
create_stream_list_item<MavlinkStreamSysStatus>(),
|
||||
create_stream_list_item<MavlinkStreamBatteryStatus>(),
|
||||
|
||||
Reference in New Issue
Block a user