打包保存数据
This commit is contained in:
@@ -9,6 +9,9 @@ ThreadTemplet::ThreadTemplet(QObject *parent) : QObject(parent)
|
||||
|
||||
initbuff();
|
||||
start();
|
||||
|
||||
Parser2_init(&parser);
|
||||
Packer2_init(&packer);
|
||||
}
|
||||
|
||||
ThreadTemplet::~ThreadTemplet()
|
||||
@@ -115,10 +118,60 @@ void ThreadTemplet::Send(mavlink_message_t msg)
|
||||
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
|
||||
uint16_t len = mavlink_msg_to_send_buffer(buff, &msg);
|
||||
|
||||
if(plogFileName.size() > 0)
|
||||
{
|
||||
setLogData(plogFileName,1,msg);
|
||||
}
|
||||
|
||||
emit SendMessageTo(0,buff, len);//使用信号和槽
|
||||
}
|
||||
}
|
||||
|
||||
bool ThreadTemplet::setLogData(QString name,uint8_t type,mavlink_message_t msg)
|
||||
{
|
||||
mutex.lock();
|
||||
QFile file(name);
|
||||
if(file.open(QIODevice::Append))
|
||||
{
|
||||
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
|
||||
qToLittleEndian(type, buff);
|
||||
|
||||
|
||||
quint64 currentTimestamp = (quint64)QDateTime::currentMSecsSinceEpoch();
|
||||
qToLittleEndian(currentTimestamp, buff+1);
|
||||
uint16_t len = mavlink_msg_to_send_buffer(buff+1+sizeof(quint64), &msg);
|
||||
|
||||
auto size = Packer2_pack(&packer,1,buff,len+1+sizeof(quint64));
|
||||
|
||||
|
||||
QByteArray data;
|
||||
data.clear();
|
||||
data.append((const char *)packer.buff,size);
|
||||
|
||||
|
||||
QDataStream stream(&file);
|
||||
|
||||
stream << data;
|
||||
|
||||
/*
|
||||
if (file.write((const char *)packer.buff, size) == size)
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
file.flush();
|
||||
file.close();
|
||||
mutex.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ThreadTemplet::initbuff(void)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,12 @@
|
||||
#include "QFile"
|
||||
#include "QDebug"
|
||||
#include "mavlink.h"
|
||||
|
||||
#include "QtEndian"
|
||||
#include "QDataStream"
|
||||
#include "QFile"
|
||||
#include "QDateTime"
|
||||
#include "ParsePack.h"
|
||||
#include "QMutex"
|
||||
|
||||
#ifdef QtMavlinkNode
|
||||
#include <mavlinknodeglobal.h>
|
||||
@@ -57,6 +62,10 @@ public slots:
|
||||
return running_frq;
|
||||
}
|
||||
|
||||
void setPlogName(QString name)
|
||||
{
|
||||
plogFileName = name;
|
||||
}
|
||||
|
||||
//缓存对外接口
|
||||
Q_INVOKABLE void setbuff(quint32 src,QByteArray data);
|
||||
@@ -66,6 +75,8 @@ public slots:
|
||||
|
||||
void Send(mavlink_message_t msg);
|
||||
|
||||
bool setLogData(QString name, uint8_t type, mavlink_message_t msg);
|
||||
|
||||
private slots:
|
||||
//线程私有接口
|
||||
virtual void process();
|
||||
@@ -127,5 +138,12 @@ protected:
|
||||
uint8_t sysid;
|
||||
uint8_t compid;
|
||||
|
||||
Parser2_t parser;
|
||||
Packer2_t packer;
|
||||
|
||||
QString plogFileName;
|
||||
|
||||
QMutex mutex;
|
||||
|
||||
};
|
||||
#endif // THREADTEMPLET_H
|
||||
|
||||
@@ -85,6 +85,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
|
||||
Mission = new MissionProcess();
|
||||
Mission->setGCSID(Current_sysID,Current_CompID);
|
||||
Mission->setPlogName(plogFileName);
|
||||
connect(Mission,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
@@ -96,6 +97,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
|
||||
Parameter = new ParameterProcess();
|
||||
Parameter->setGCSID(Current_sysID,Current_CompID);
|
||||
Parameter->setPlogName(plogFileName);
|
||||
connect(Parameter,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
@@ -104,6 +106,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
|
||||
Commander = new commandprocess();
|
||||
Commander->setGCSID(Current_sysID,Current_CompID);
|
||||
Commander->setPlogName(plogFileName);
|
||||
connect(Commander,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
@@ -115,6 +118,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
|
||||
Status = new statusprocess();
|
||||
Status->setGCSID(Current_sysID,Current_CompID);
|
||||
Status->setPlogName(plogFileName);
|
||||
connect(Status,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
@@ -127,6 +131,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
|
||||
Terminal = new terminal();
|
||||
Terminal->setGCSID(Current_sysID,Current_CompID);
|
||||
Terminal->setPlogName(plogFileName);
|
||||
connect(Terminal,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
|
||||
@@ -138,7 +143,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
|
||||
RC = new rcprocess();
|
||||
RC->setGCSID(Current_sysID,Current_CompID);
|
||||
|
||||
RC->setPlogName(plogFileName);
|
||||
connect(RC,&rcprocess::SendMessageTo,
|
||||
this,&MavLinkNode::SendMessageTo,Qt::DirectConnection);
|
||||
|
||||
@@ -152,7 +157,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
|
||||
rtk = new rtkprocess();
|
||||
rtk->setGCSID(Current_sysID,Current_CompID);
|
||||
|
||||
rtk->setPlogName(plogFileName);
|
||||
connect(rtk,&rtkprocess::SendMessageTo,
|
||||
this,&MavLinkNode::SendMessageTo,Qt::DirectConnection);
|
||||
|
||||
@@ -167,8 +172,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : ThreadTemplet(parent)
|
||||
qDebug() << "mavlink" << QThread::currentThreadId();
|
||||
|
||||
|
||||
Parser2_init(&parser);
|
||||
Packer2_init(&packer);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -567,36 +571,6 @@ void MavLinkNode::LogTimerOut(void)
|
||||
*/
|
||||
}
|
||||
|
||||
bool MavLinkNode::setLogData(QString name,uint8_t type,mavlink_message_t msg)
|
||||
{
|
||||
QFile file(name);
|
||||
if(file.open(QIODevice::Append))
|
||||
{
|
||||
uint8_t buff[MAVLINK_MAX_PACKET_LEN+sizeof(quint64)];
|
||||
qToLittleEndian(type, buff);
|
||||
|
||||
|
||||
quint64 currentTimestamp = (quint64)QDateTime::currentMSecsSinceEpoch();
|
||||
qToLittleEndian(currentTimestamp, buff+1);
|
||||
uint16_t len = mavlink_msg_to_send_buffer(buff+1+sizeof(quint64), &msg);
|
||||
|
||||
auto size = Packer2_pack(&packer,1,buff,len+1+sizeof(quint64));
|
||||
|
||||
QByteArray data;
|
||||
data.clear();
|
||||
data.append((const char *)packer.buff,size);
|
||||
|
||||
QDataStream stream(&file);
|
||||
|
||||
stream << data;
|
||||
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MavLinkNode::timer_1s_Out(void)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "ThreadTemplet.h"
|
||||
|
||||
#include "ParsePack.h"
|
||||
|
||||
#ifdef QtMavlinkNode
|
||||
#include <mavlinknodeglobal.h>
|
||||
@@ -273,7 +272,7 @@ private slots:
|
||||
void timer_1s_Out(void);
|
||||
|
||||
|
||||
bool setLogData(QString name, uint8_t type, mavlink_message_t msg);
|
||||
|
||||
|
||||
//解析
|
||||
void Mavlinkparse(quint32 src,QByteArray datagram);
|
||||
@@ -320,12 +319,9 @@ protected:
|
||||
QString mavlogFileName;
|
||||
QFile *mavLogFile = NULL;
|
||||
|
||||
QString plogFileName;
|
||||
|
||||
QTimer *logTimer = nullptr;
|
||||
|
||||
Parser2_t parser;
|
||||
Packer2_t packer;
|
||||
|
||||
|
||||
QTimer *timer_1s = nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user