2022-06-20 15:30:16 +08:00
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
|
|
#include "witmotiondll.h"
|
|
|
|
|
#include "qtserialport.h"
|
|
|
|
|
|
2022-07-15 22:09:06 +08:00
|
|
|
|
#include "commandlineparser.h"
|
|
|
|
|
|
2022-06-20 15:30:16 +08:00
|
|
|
|
void delay_tc(uint32_t millisecond)
|
|
|
|
|
{
|
2023-02-13 09:15:17 +08:00
|
|
|
|
QThread::msleep(millisecond);
|
2022-07-15 22:09:06 +08:00
|
|
|
|
// std::cout<<"This is delay_tc!!!!!!!!!!"<<std::endl;
|
2022-06-20 15:30:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printf_tc(const char* text)
|
|
|
|
|
{
|
|
|
|
|
printf(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
QCoreApplication a(argc, argv);
|
|
|
|
|
|
2022-07-15 22:09:06 +08:00
|
|
|
|
// 解析命令行参数
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 15:30:16 +08:00
|
|
|
|
SerialPortBase * serialPort = new QtSerialport();
|
2022-07-15 22:09:06 +08:00
|
|
|
|
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);
|
2023-02-13 09:15:17 +08:00
|
|
|
|
witmotion->setDelayTimeMs(200);
|
|
|
|
|
|
2022-07-15 22:09:06 +08:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2022-06-20 15:30:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-15 22:09:06 +08:00
|
|
|
|
if(query.isSetInterface_D0)
|
|
|
|
|
{
|
|
|
|
|
witmotion->setD0Model(query.modelForInterface_D0);
|
|
|
|
|
witmotion->setD0HighLevelPulseWidth(query.pulseWidth_D0);
|
|
|
|
|
witmotion->setD0Period(query.period_D0);
|
|
|
|
|
}
|
2022-06-20 15:30:16 +08:00
|
|
|
|
|
2022-07-15 22:09:06 +08:00
|
|
|
|
if(query.isSetInterface_D1)
|
|
|
|
|
{
|
|
|
|
|
witmotion->setD1Model(query.modelForInterface_D1);
|
|
|
|
|
witmotion->setD1HighLevelPulseWidth(query.pulseWidth_D1);
|
|
|
|
|
witmotion->setD1Period(query.period_D1);
|
|
|
|
|
}
|
2022-06-20 15:30:16 +08:00
|
|
|
|
|
2022-07-15 22:09:06 +08:00
|
|
|
|
if(query.isSetInterface_D2)
|
|
|
|
|
{
|
|
|
|
|
witmotion->setD2Model(query.modelForInterface_D2);
|
|
|
|
|
witmotion->setD2HighLevelPulseWidth(query.pulseWidth_D2);
|
|
|
|
|
witmotion->setD2Period(query.period_D2);
|
|
|
|
|
}
|
2022-06-20 15:30:16 +08:00
|
|
|
|
|
2022-07-15 22:09:06 +08:00
|
|
|
|
if(query.isSetInterface_D3)
|
|
|
|
|
{
|
|
|
|
|
witmotion->setD3Model(query.modelForInterface_D3);
|
|
|
|
|
witmotion->setD3HighLevelPulseWidth(query.pulseWidth_D3);
|
|
|
|
|
witmotion->setD3Period(query.period_D3);
|
|
|
|
|
}
|
2023-02-13 09:15:17 +08:00
|
|
|
|
if(query.isSetReturnRate)//设置witMotion的通讯速率要放在最后,它后面的设置都会失败
|
|
|
|
|
{
|
|
|
|
|
witmotion->SetReturnRate(query.returnRate);
|
|
|
|
|
}
|
2022-07-15 22:09:06 +08:00
|
|
|
|
if(query.isSetBaudrate)//设置witMotion的通讯速率要放在最后,它后面的设置都会失败
|
|
|
|
|
{
|
|
|
|
|
witmotion->SetBaudrate(query.baudrate);
|
2023-02-13 09:15:17 +08:00
|
|
|
|
// serialPort->CloseSerialPort();//设置完波特率 已经无法通讯 需要重新简历连接
|
|
|
|
|
serialPort->SetBaudrate(115200);
|
|
|
|
|
//ret = serialPort->OpenSerialPort(query.serialPort.toStdString(), query.baudrate);//重新建立连接
|
|
|
|
|
witmotion->saveInstruction();
|
2022-07-15 22:09:06 +08:00
|
|
|
|
}
|
2022-06-20 15:30:16 +08:00
|
|
|
|
|
|
|
|
|
|
2023-02-13 09:15:17 +08:00
|
|
|
|
// witmotion->recordData();
|
|
|
|
|
std::cout<<"Set IMU OK"<<std::flush;
|
2022-06-20 15:30:16 +08:00
|
|
|
|
serialPort->CloseSerialPort();
|
|
|
|
|
|
|
|
|
|
// return a.exec();
|
|
|
|
|
}
|