添加参数的相关函数,添加参数进程
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
#include "parameterprocess.h"
|
||||
|
||||
ParameterProcess::ParameterProcess(QObject *parent) : QObject(parent)
|
||||
{
|
||||
setRunFrq(200);
|
||||
}
|
||||
|
||||
void ParameterProcess::setRunFrq(uint32_t frq)
|
||||
{
|
||||
if((frq != 0)||(frq <= 1000))
|
||||
{
|
||||
running_frq = frq;
|
||||
qDebug() << "set thread running frquency:" <<frq <<"Hz";
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterProcess::start()
|
||||
{
|
||||
if(thread == nullptr)
|
||||
{
|
||||
thread = new QThread();
|
||||
this->moveToThread(thread);
|
||||
connect(thread, &QThread::started, this, &ParameterProcess::process);
|
||||
}
|
||||
|
||||
if(!thread->isRunning())
|
||||
{
|
||||
running_flag = true;
|
||||
thread->start();
|
||||
qDebug() << "thread start" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread has started";
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterProcess::stop()
|
||||
{
|
||||
if(thread->isRunning())
|
||||
{
|
||||
running_flag = false;
|
||||
qDebug() << "thread stop" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread is not running";
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterProcess::process()//线程函数
|
||||
{
|
||||
uint8_t count = 0;
|
||||
while (running_flag)
|
||||
{
|
||||
count ++;
|
||||
QThread::msleep(1000/running_frq);
|
||||
|
||||
|
||||
|
||||
}
|
||||
//退出线程
|
||||
thread->quit();
|
||||
thread->wait(200);//等待结束
|
||||
thread->deleteLater();
|
||||
thread = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void ParameterProcess::SendMessage(mavlink_message_t msg)
|
||||
{
|
||||
uint8_t buff[256+20];
|
||||
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
|
||||
emit SendMessageTo(0,buff, len);//使用信号和槽
|
||||
}
|
||||
|
||||
|
||||
|
||||
//这个函数类似中断,专门处理接收到的状态
|
||||
void ParameterProcess::ParameterParse(mavlink_message_t msg)
|
||||
{
|
||||
switch (msg.msgid) {
|
||||
case MAVLINK_MSG_ID_PARAM_SET:{
|
||||
mavlink_msg_param_set_decode(&msg,¶m_set);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_VALUE:{//
|
||||
mavlink_msg_param_value_decode(&msg,¶m_value);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_EXT_ACK:{
|
||||
mavlink_msg_param_ext_ack_decode(&msg,¶m_ext_ack);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_EXT_SET:{
|
||||
mavlink_msg_param_ext_set_decode(&msg,¶m_ext_set);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_EXT_VALUE:{
|
||||
mavlink_msg_param_ext_value_decode(&msg,¶m_ext_value);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_REQUEST_LIST:{
|
||||
mavlink_msg_param_request_list_decode(&msg,¶m_request_list);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_REQUEST_READ:{
|
||||
mavlink_msg_param_request_read_decode(&msg,¶m_request_read);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_EXT_REQUEST_LIST:{
|
||||
mavlink_msg_param_ext_request_list_decode(&msg,¶m_ext_request_list);
|
||||
}break;
|
||||
case MAVLINK_MSG_ID_PARAM_EXT_REQUEST_READ:{
|
||||
mavlink_msg_param_ext_request_read_decode(&msg,¶m_ext_request_read);
|
||||
}break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*all msg
|
||||
MAVLINK_MSG_ID_PARAM_SET
|
||||
MAVLINK_MSG_ID_PARAM_VALUE
|
||||
MAVLINK_MSG_ID_PARAM_EXT_ACK
|
||||
MAVLINK_MSG_ID_PARAM_EXT_SET
|
||||
MAVLINK_MSG_ID_PARAM_EXT_VALUE
|
||||
MAVLINK_MSG_ID_PARAM_REQUEST_LIST
|
||||
MAVLINK_MSG_ID_PARAM_REQUEST_READ
|
||||
MAVLINK_MSG_ID_PARAM_EXT_REQUEST_LIST
|
||||
MAVLINK_MSG_ID_PARAM_EXT_REQUEST_READ
|
||||
*/
|
||||
|
||||
void ParameterProcess::set(char id[16],uint8_t type,float value)//
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_param_set_t param_set;
|
||||
|
||||
memcpy(param_set.param_id,id,16);
|
||||
param_set.param_type = type;
|
||||
param_set.param_value = value;
|
||||
param_set.target_system = sysid;
|
||||
param_set.target_component = compid;
|
||||
|
||||
mavlink_msg_param_set_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,¶m_set);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
void ParameterProcess::value(float value)//一般只接收不发送
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_param_value_t param_value;
|
||||
|
||||
|
||||
//param_value.param_count
|
||||
//param_value.param_id
|
||||
//param_value.param_index
|
||||
//param_value.param_type
|
||||
param_value.param_value = value;
|
||||
//param_value. = sysid;
|
||||
//param_value.target_component = compid;
|
||||
|
||||
mavlink_msg_param_value_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,¶m_value);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
void ParameterProcess::ext_ack(float value)
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_param_ext_ack_t param_ext_ack;
|
||||
|
||||
Q_UNUSED(value);
|
||||
|
||||
//param_ext_ack.param_id
|
||||
//param_ext_ack.param_result
|
||||
//param_ext_ack.param_type
|
||||
|
||||
//param_ext_ack.param_value = value;
|
||||
//param_ext_ack.target_system = sysid;
|
||||
//param_ext_ack.target_component = compid;
|
||||
|
||||
mavlink_msg_param_ext_ack_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,¶m_ext_ack);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
void ParameterProcess::ext_set(char id[16],uint8_t type,float value)
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_param_ext_set_t param_ext_set;
|
||||
|
||||
Q_UNUSED(value);
|
||||
|
||||
memcpy(param_ext_set.param_id,id,16);
|
||||
param_ext_set.param_type = type;
|
||||
//param_ext_set.param_value = value;
|
||||
param_ext_set.target_system = sysid;
|
||||
param_ext_set.target_component = compid;
|
||||
|
||||
mavlink_msg_param_ext_set_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,¶m_ext_set);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
void ParameterProcess::ext_value(float value)
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_param_ext_value_t param_ext_value;
|
||||
|
||||
Q_UNUSED(value);
|
||||
|
||||
//param_ext_value.param_value = value;
|
||||
|
||||
|
||||
//param_ext_value.target_system = sysid;
|
||||
//param_ext_value.target_component = compid;
|
||||
|
||||
mavlink_msg_param_ext_value_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,¶m_ext_value);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
void ParameterProcess::request_list(void)//
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_param_request_list_t param_request_list;
|
||||
|
||||
param_request_list.target_system = sysid;
|
||||
param_request_list.target_component = compid;
|
||||
|
||||
mavlink_msg_param_request_list_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,¶m_request_list);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
void ParameterProcess::request_read(const char id[16],int16_t index)//
|
||||
{
|
||||
static mavlink_message_t msg;
|
||||
static mavlink_param_request_read_t param_request_read;
|
||||
|
||||
memcpy(param_request_read.param_id,id,16);
|
||||
param_request_read.param_index = index;
|
||||
param_request_read.target_system = sysid;
|
||||
param_request_read.target_component = compid;
|
||||
|
||||
mavlink_msg_param_request_read_encode(2,MAV_COMP_ID_MISSIONPLANNER, &msg,¶m_request_read);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user