134 lines
3.4 KiB
C++
134 lines
3.4 KiB
C++
#include <QCoreApplication>
|
||
#include <QThread>
|
||
|
||
#include "witmotiondll.h"
|
||
#include "qtserialport.h"
|
||
|
||
#include "commandlineparser.h"
|
||
|
||
void delay_tc(uint32_t millisecond)
|
||
{
|
||
QThread::sleep(millisecond/1000);
|
||
// 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(1000);
|
||
|
||
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.isSetBaudrate)//设置witMotion的通讯速率要放在最后,它后面的设置都会失败
|
||
{
|
||
witmotion->SetBaudrate(query.baudrate);
|
||
}
|
||
|
||
// witmotion->recordData();
|
||
|
||
serialPort->CloseSerialPort();
|
||
|
||
// return a.exec();
|
||
}
|