构建新的cmakelist工程
修改了 delay_tc函数 修返回频率为20hz 修改波特率修改后先重新设置通讯波特率在保存
This commit is contained in:
142
source/main.cpp
Normal file
142
source/main.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
|
||||
#include "witmotiondll.h"
|
||||
#include "qtserialport.h"
|
||||
|
||||
#include "commandlineparser.h"
|
||||
|
||||
void delay_tc(uint32_t millisecond)
|
||||
{
|
||||
QThread::msleep(millisecond);
|
||||
// std::cout<<"This is delay_tc!!!!!!!!!!"<<std::endl;
|
||||
}
|
||||
|
||||
void printf_tc(const char* text)
|
||||
{
|
||||
printf(text);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
// 解析命令行参数
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("This software is used for config parameter for wit inertial navigation.");
|
||||
TcQuery query;
|
||||
QString errorMessage;
|
||||
|
||||
switch (parseCommandLine2(parser, &query, &errorMessage))
|
||||
{
|
||||
case CommandLineOk:
|
||||
break;
|
||||
case CommandLineError:
|
||||
fputs(qPrintable(errorMessage), stderr);
|
||||
fputs("\n\n", stderr);
|
||||
fputs(qPrintable(parser.helpText()), stderr);
|
||||
return 1;
|
||||
case CommandLineVersionRequested:
|
||||
printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
|
||||
qPrintable(QCoreApplication::applicationVersion()));
|
||||
return 0;
|
||||
case CommandLineHelpRequested:
|
||||
parser.showHelp();
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
SerialPortBase * serialPort = new QtSerialport();
|
||||
int ret = serialPort->OpenSerialPort(query.serialPort.toStdString(), query.connectBaudrate);//"COM15"
|
||||
if(ret)
|
||||
{
|
||||
std::cout<<"Serial port open failed!!"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
WitmotionDll * witmotion = new WitmotionDll(serialPort);
|
||||
witmotion->delayMsRegister(delay_tc);
|
||||
witmotion->printfRegister(printf_tc);
|
||||
witmotion->setDelayTimeMs(200);
|
||||
|
||||
|
||||
if(query.isSetAlgorithm)
|
||||
{
|
||||
witmotion->algorithm(query.algorithm);
|
||||
}
|
||||
|
||||
if(query.isSetInstallationOrientation)
|
||||
{
|
||||
witmotion->installationOrientation(query.installationOrientation);
|
||||
}
|
||||
|
||||
if(query.isSetTimeZone)
|
||||
{
|
||||
witmotion->setTimeZone(query.timeZone);
|
||||
}
|
||||
|
||||
if(query.isSetDefaultReturnContent)
|
||||
{
|
||||
witmotion->setContent(query.defaultReturnContent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(query.isSetReturnRate)
|
||||
{
|
||||
witmotion->SetReturnRate(query.returnRate);
|
||||
}
|
||||
if(query.isSetDeviceAddress)
|
||||
{
|
||||
witmotion->SetDeviceAddress(query.deviceAddress);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(query.isSetInterface_D0)
|
||||
{
|
||||
witmotion->setD0Model(query.modelForInterface_D0);
|
||||
witmotion->setD0HighLevelPulseWidth(query.pulseWidth_D0);
|
||||
witmotion->setD0Period(query.period_D0);
|
||||
}
|
||||
|
||||
if(query.isSetInterface_D1)
|
||||
{
|
||||
witmotion->setD1Model(query.modelForInterface_D1);
|
||||
witmotion->setD1HighLevelPulseWidth(query.pulseWidth_D1);
|
||||
witmotion->setD1Period(query.period_D1);
|
||||
}
|
||||
|
||||
if(query.isSetInterface_D2)
|
||||
{
|
||||
witmotion->setD2Model(query.modelForInterface_D2);
|
||||
witmotion->setD2HighLevelPulseWidth(query.pulseWidth_D2);
|
||||
witmotion->setD2Period(query.period_D2);
|
||||
}
|
||||
|
||||
if(query.isSetInterface_D3)
|
||||
{
|
||||
witmotion->setD3Model(query.modelForInterface_D3);
|
||||
witmotion->setD3HighLevelPulseWidth(query.pulseWidth_D3);
|
||||
witmotion->setD3Period(query.period_D3);
|
||||
}
|
||||
if(query.isSetReturnRate)//设置witMotion的通讯速率要放在最后,它后面的设置都会失败
|
||||
{
|
||||
witmotion->SetReturnRate(query.returnRate);
|
||||
}
|
||||
if(query.isSetBaudrate)//设置witMotion的通讯速率要放在最后,它后面的设置都会失败
|
||||
{
|
||||
witmotion->SetBaudrate(query.baudrate);
|
||||
// serialPort->CloseSerialPort();//设置完波特率 已经无法通讯 需要重新简历连接
|
||||
serialPort->SetBaudrate(115200);
|
||||
//ret = serialPort->OpenSerialPort(query.serialPort.toStdString(), query.baudrate);//重新建立连接
|
||||
witmotion->saveInstruction();
|
||||
}
|
||||
|
||||
|
||||
// witmotion->recordData();
|
||||
std::cout<<"Set IMU OK"<<std::flush;
|
||||
serialPort->CloseSerialPort();
|
||||
|
||||
// return a.exec();
|
||||
}
|
Reference in New Issue
Block a user