1、从文件register.h中重构出命令文件witcommand.h;

2、解析命令行参数;
3、修改串口类(继承基类SerialPortBase)的bug;
4、添加命令行选项--rlx1:任工想要的设置;
This commit is contained in:
tangchao0503
2022-07-15 22:09:06 +08:00
parent 3c0ba621ac
commit 14a4518e2e
10 changed files with 1006 additions and 189 deletions

649
commandlineparser.cpp Normal file
View File

@ -0,0 +1,649 @@
#include "commandlineparser.h"
CommandLineParseResult parseCommandLine2(QCommandLineParser &parser, TcQuery *query, QString *errorMessage)
{
//添加命令
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
QCommandLineOption helpOption = parser.addHelpOption();//Adds the help option (-h, --help and -? on Windows) This option is handled automatically by QCommandLineParser.
QCommandLineOption versionOption = parser.addVersionOption();//This option is handled automatically by QCommandLineParser.
QCommandLineOption serialPort("serialPort", "Serial port.", "serialPort");
parser.addOption(serialPort);
QCommandLineOption connectBaudrate("connectBaudrate", "ConnectBaudrate of wit motion.", "connectBaudrate");
parser.addOption(connectBaudrate);
QCommandLineOption algorithm("algorithm", "Algorithm of wit motion.", "algorithm");
parser.addOption(algorithm);
QCommandLineOption installationOrientation("installationOrientation", "InstallationOrientation of wit motion.", "installationOrientation");
parser.addOption(installationOrientation);
QCommandLineOption timeZone("timeZone", "TimeZone of wit motion.", "timeZone");
parser.addOption(timeZone);
// A boolean option with multiple names (-r, --record)
QCommandLineOption isSetDefaultReturnContent(QStringList() << "d" << "isSetDefaultReturnContent", "isSetDefaultReturnContent");
parser.addOption(isSetDefaultReturnContent);
QCommandLineOption baudrate("baudrate", "Baudrate of wit motion.", "baudrate");
parser.addOption(baudrate);
QCommandLineOption returnRate("returnRate", "ReturnRate of wit motion.", "returnRate");
parser.addOption(returnRate);
QCommandLineOption deviceAddress("deviceAddress", "DeviceAddress of wit motion.", "deviceAddress");
parser.addOption(deviceAddress);
QCommandLineOption modelForInterface_D0("modelForInterface_D0", "modelForInterface_D0 of interface number.", "modelForInterface_D0");
parser.addOption(modelForInterface_D0);
QCommandLineOption pulseWidth_D0("pulseWidth_D0", "PulseWidth_D0 of interface number.", "pulseWidth_D0");
pulseWidth_D0.setDefaultValue("0");//设置默认参数
parser.addOption(pulseWidth_D0);
QCommandLineOption period_D0("period_D0", "Period_D0 of wit interface number.", "period_D0");
period_D0.setDefaultValue("0");//设置默认参数
parser.addOption(period_D0);
QCommandLineOption modelForInterface_D1("modelForInterface_D1", "modelForInterface_D1 of interface number.", "modelForInterface_D1");
parser.addOption(modelForInterface_D1);
QCommandLineOption pulseWidth_D1("pulseWidth_D1", "PulseWidth_D1 of interface number.", "pulseWidth_D1");
pulseWidth_D1.setDefaultValue("0");//设置默认参数
parser.addOption(pulseWidth_D1);
QCommandLineOption period_D1("period_D1", "Period_D1 of wit interface number.", "period_D1");
period_D1.setDefaultValue("0");//设置默认参数
parser.addOption(period_D1);
QCommandLineOption modelForInterface_D2("modelForInterface_D2", "modelForInterface_D2 of interface number.", "modelForInterface_D2");
parser.addOption(modelForInterface_D2);
QCommandLineOption pulseWidth_D2("pulseWidth_D2", "PulseWidth_D2 of interface number.", "pulseWidth_D2");
pulseWidth_D2.setDefaultValue("0");//设置默认参数
parser.addOption(pulseWidth_D2);
QCommandLineOption period_D2("period_D2", "Period_D2 of wit interface number.", "period_D2");
period_D2.setDefaultValue("0");//设置默认参数
parser.addOption(period_D2);
QCommandLineOption modelForInterface_D3("modelForInterface_D3", "modelForInterface_D3 of interface number.", "modelForInterface_D3");
parser.addOption(modelForInterface_D3);
QCommandLineOption pulseWidth_D3("pulseWidth_D3", "PulseWidth_D3 of interface number.", "pulseWidth_D3");
pulseWidth_D3.setDefaultValue("0");//设置默认参数
parser.addOption(pulseWidth_D3);
QCommandLineOption period_D3("period_D3", "Period_D3 of wit interface number.", "period_D3");
period_D3.setDefaultValue("0");//设置默认参数
parser.addOption(period_D3);
// QCommandLineOption rlx1("rlx1", "rlx1 parm of wit motion.", "rlx1");
// parser.addOption(rlx1);
QCommandLineOption rlx1(QStringList() << "rlx1" << "rlx1 long", "rlx1 parm of wit motion.");
parser.addOption(rlx1);
//解析命令
if (!parser.parse(QCoreApplication::arguments()))//Process the actual command line arguments given by the user
{
*errorMessage = parser.errorText();
return CommandLineError;
}
if (parser.isSet(versionOption))
return CommandLineVersionRequested;
if (parser.isSet(helpOption))
return CommandLineHelpRequested;
if (parser.isSet(serialPort))
{
const QString serialPortTmp = parser.value(serialPort);
query->serialPort = serialPortTmp;
}
else//默认参数
{
*errorMessage = "No serialPort set.";
return CommandLineError;
}
if (parser.isSet(connectBaudrate))
{
const QString connectBaudrateTmp = parser.value(connectBaudrate);
query->connectBaudrate = connectBaudrateTmp.toInt();
}
else//默认参数
{
*errorMessage = "No connectBaudrate set.";
return CommandLineError;
}
if (parser.isSet(algorithm))
{
const QString algorithmTmp1 = parser.value(algorithm);
int algorithmTmp2 = algorithmTmp1.toInt();
switch (algorithmTmp2)
{
case 9:
query->algorithm = ALGROITHM9;
query->isSetAlgorithm = true;
break;
case 6:
query->algorithm = ALGROITHM6;
query->isSetAlgorithm = true;
break;
default:
*errorMessage = "Algorithm set error.";
return CommandLineError;
break;
}
}
else//默认参数
{
query->isSetAlgorithm = false;
}
if (parser.isSet(installationOrientation))
{
const QString installationOrientationTmp1 = parser.value(installationOrientation);
int installationOrientationTmp2 = installationOrientationTmp1.toInt();
switch (installationOrientationTmp2)
{
case 0:
query->installationOrientation = ORIENT_HORIZONTAL;
query->isSetInstallationOrientation = true;
break;
case 1:
query->installationOrientation = ORIENT_VERTICAL;
query->isSetInstallationOrientation = true;
break;
default:
*errorMessage = "InstallationOrientation set error.";
return CommandLineError;
break;
}
}
else//默认参数
{
query->isSetInstallationOrientation = false;
}
if (parser.isSet(timeZone))
{
const QString timeZoneTmp1 = parser.value(timeZone);
int timeZoneTmp2 = timeZoneTmp1.toInt();
switch (timeZoneTmp2)
{
case 0:
query->timeZone = UTC_N12;
query->isSetTimeZone = true;
break;
case 1:
query->timeZone = UTC_N11;
query->isSetTimeZone = true;
break;
case 2:
query->timeZone = UTC_N10;
query->isSetTimeZone = true;
break;
case 3:
query->timeZone = UTC_N9;
query->isSetTimeZone = true;
break;
case 4:
query->timeZone = UTC_N8;
query->isSetTimeZone = true;
break;
case 5:
query->timeZone = UTC_N7;
query->isSetTimeZone = true;
break;
case 6:
query->timeZone = UTC_N6;
query->isSetTimeZone = true;
break;
case 7:
query->timeZone = UTC_N5;
query->isSetTimeZone = true;
break;
case 8:
query->timeZone = UTC_N4;
query->isSetTimeZone = true;
break;
case 9:
query->timeZone = UTC_N3;
query->isSetTimeZone = true;
break;
case 10:
query->timeZone = UTC_N2;
query->isSetTimeZone = true;
break;
case 11:
query->timeZone = UTC_N1;
query->isSetTimeZone = true;
break;
case 12:
query->timeZone = UTC;
query->isSetTimeZone = true;
break;
case 13:
query->timeZone = UTC_N1;
query->isSetTimeZone = true;
break;
case 14:
query->timeZone = UTC_N2;
query->isSetTimeZone = true;
break;
case 15:
query->timeZone = UTC_N3;
query->isSetTimeZone = true;
break;
case 16:
query->timeZone = UTC_N4;
query->isSetTimeZone = true;
break;
case 17:
query->timeZone = UTC_N5;
query->isSetTimeZone = true;
break;
case 18:
query->timeZone = UTC_N6;
query->isSetTimeZone = true;
break;
case 19:
query->timeZone = UTC_N7;
query->isSetTimeZone = true;
break;
case 20:
query->timeZone = UTC_N8;
query->isSetTimeZone = true;
break;
case 21:
query->timeZone = UTC_N9;
query->isSetTimeZone = true;
break;
case 22:
query->timeZone = UTC_N10;
query->isSetTimeZone = true;
break;
case 23:
query->timeZone = UTC_N11;
query->isSetTimeZone = true;
break;
case 24:
query->timeZone = UTC_N12;
query->isSetTimeZone = true;
break;
default:
*errorMessage = "timeZone set error.";
return CommandLineError;
break;
}
}
else//默认参数
{
query->isSetTimeZone = false;
}
query->isSetDefaultReturnContent = parser.isSet(isSetDefaultReturnContent);
if (parser.isSet(baudrate))
{
const QString baudrateTmp1 = parser.value(baudrate);
int baudrateTmp2 = baudrateTmp1.toInt();
switch (baudrateTmp2)
{
case 2400:
query->baudrate = WIT_BAUD_2400;
query->isSetBaudrate = true;
break;
case 4800:
query->baudrate = WIT_BAUD_4800;
query->isSetBaudrate = true;
break;
case 9600:
query->baudrate = WIT_BAUD_9600;
query->isSetBaudrate = true;
break;
case 19200:
query->baudrate = WIT_BAUD_19200;
query->isSetBaudrate = true;
break;
case 38400:
query->baudrate = WIT_BAUD_38400;
query->isSetBaudrate = true;
break;
case 57600:
query->baudrate = WIT_BAUD_57600;
query->isSetBaudrate = true;
break;
case 115200:
query->baudrate = WIT_BAUD_115200;
query->isSetBaudrate = true;
break;
case 230400:
query->baudrate = WIT_BAUD_230400;
query->isSetBaudrate = true;
break;
case 460800:
query->baudrate = WIT_BAUD_460800;
query->isSetBaudrate = true;
break;
case 921600:
query->baudrate = WIT_BAUD_921600;
query->isSetBaudrate = true;
break;
default:
*errorMessage = "baudrate set error.";
return CommandLineError;
break;
}
}
else//默认参数
{
query->isSetBaudrate = false;
}
if (parser.isSet(returnRate))
{
const QString returnRateTmp1 = parser.value(returnRate);
int returnRateTmp2 = returnRateTmp1.toInt();
switch (returnRateTmp2)
{
// case 0.1:
// query->returnRate = RRATE_01HZ;
// query->isSetReturnRate = true;
// break;
// case 0.5:
// query->returnRate = RRATE_05HZ;
// query->isSetReturnRate = true;
// break;
case 1:
query->returnRate = RRATE_1HZ;
query->isSetReturnRate = true;
break;
case 2:
query->returnRate = RRATE_2HZ;
query->isSetReturnRate = true;
break;
case 5:
query->returnRate = RRATE_5HZ;
query->isSetReturnRate = true;
break;
case 10:
query->returnRate = RRATE_10HZ;
query->isSetReturnRate = true;
break;
case 20:
query->returnRate = RRATE_20HZ;
query->isSetReturnRate = true;
break;
case 50:
query->returnRate = RRATE_50HZ;
query->isSetReturnRate = true;
break;
case 100:
query->returnRate = RRATE_100HZ;
query->isSetReturnRate = true;
break;
// case "none":
// query->returnRate = RRATE_NONE;
// query->isSetReturnRate = true;
// break;
case 200:
query->returnRate = RRATE_200HZ;
query->isSetReturnRate = true;
break;
// case "once":
// query->returnRate = RRATE_ONCE;
// query->isSetReturnRate = true;
// break;
default:
*errorMessage = "timeZone set error.";
return CommandLineError;
break;
}
}
else//默认参数
{
query->isSetReturnRate = false;
}
if (parser.isSet(deviceAddress))
{
const QString deviceAddressTmp = parser.value(deviceAddress);
query->deviceAddress = deviceAddressTmp.toInt();
query->isSetDeviceAddress = true;
}
else//默认参数
{
query->isSetDeviceAddress = false;
}
bool ret;
ret=processModelParm(parser,modelForInterface_D0,query->modelForInterface_D0,query->isSetInterface_D0);
if(!ret)
{
*errorMessage = "modelForInterface_D0 set error.";
return CommandLineError;
}
ret=processPulseWidthParm(parser,pulseWidth_D0, query->pulseWidth_D0, query->isSetInterface_D0);
ret=processPeriodParm(parser,period_D0, query->period_D0, query->isSetInterface_D0);
ret=processModelParm_D1(parser,modelForInterface_D1,query->modelForInterface_D1,query->isSetInterface_D1);
if(!ret)
{
*errorMessage = "modelForInterface_D1 set error.";
return CommandLineError;
}
ret=processPulseWidthParm(parser,pulseWidth_D1, query->pulseWidth_D1, query->isSetInterface_D1);
ret=processPeriodParm(parser,period_D1, query->period_D1, query->isSetInterface_D1);
ret=processModelParm(parser,modelForInterface_D2,query->modelForInterface_D2,query->isSetInterface_D2);
if(!ret)
{
*errorMessage = "modelForInterface_D2 set error.";
return CommandLineError;
}
ret=processPulseWidthParm(parser,pulseWidth_D2, query->pulseWidth_D2, query->isSetInterface_D2);
ret=processPeriodParm(parser,period_D2, query->period_D2, query->isSetInterface_D2);
ret=processModelParm(parser,modelForInterface_D3,query->modelForInterface_D3,query->isSetInterface_D3);
if(!ret)
{
*errorMessage = "modelForInterface_D3 set error.";
return CommandLineError;
}
ret=processPulseWidthParm(parser,pulseWidth_D3, query->pulseWidth_D3, query->isSetInterface_D3);
ret=processPeriodParm(parser,period_D3, query->period_D3, query->isSetInterface_D3);
if (parser.isSet(rlx1))
{
query->isSetAlgorithm = true;
query->algorithm = ALGROITHM9;
query->isSetInstallationOrientation = true;
query->installationOrientation = ORIENT_HORIZONTAL;
query->isSetDefaultReturnContent = true;
query->isSetBaudrate = true;
query->baudrate = WIT_BAUD_115200;
query->isSetReturnRate = true;
query->returnRate = RRATE_10HZ;
query->isSetInterface_D1 = true;
query->modelForInterface_D1 = PWM_D1;
query->pulseWidth_D1 = 0;
query->period_D1 = 0;
query->isSetInterface_D2 = true;
query->modelForInterface_D2 = PWM;
query->pulseWidth_D2 = 1500;
query->period_D2 = 20000;
query->isSetInterface_D3 = true;
query->modelForInterface_D3 = PWM;
query->pulseWidth_D3 = 1500;
query->period_D3 = 20000;
}
return CommandLineOk;
}
bool getModel(int modelIndex, MODEL_D0_D2_D3_ENUM & model)
{
switch (modelIndex)
{
case 0:
model = AIN;
return true;
case 1:
model = DIN;
return true;
case 2:
model = DOH;
return true;
case 3:
model = DOL;
return true;
case 4:
model = PWM;
return true;
default:
return false;
}
}
bool getModel_D1(int modelIndex, MODEL_D1_ENUM & model)
{
switch (modelIndex)
{
case 0:
model = AIN_D1;
return true;
case 1:
model = DIN_D1;
return true;
case 2:
model = DOH_D1;
return true;
case 3:
model = DOL_D1;
return true;
case 4:
model = PWM_D1;
return true;
case 5:
model = CLR_D1;
return true;
default:
return false;
}
}
bool processModelParm(QCommandLineParser &parser, QCommandLineOption commandLineOption, MODEL_D0_D2_D3_ENUM & model, bool &isSetInterface)
{
if(parser.isSet(commandLineOption))
{
const QString modelForInterface_D0Tmp1 = parser.value(commandLineOption);
int modelForInterface_D0Tmp2 = modelForInterface_D0Tmp1.toInt();
bool ret = getModel(modelForInterface_D0Tmp2, model);
if(ret)
{
isSetInterface = true;
}
else
{
return false;
}
}
else
{
isSetInterface = false;
}
return true;
}
bool processModelParm_D1(QCommandLineParser &parser, QCommandLineOption commandLineOption, MODEL_D1_ENUM & model, bool &isSetInterface)
{
if(parser.isSet(commandLineOption))
{
const QString modelForInterface_D0Tmp1 = parser.value(commandLineOption);
int modelForInterface_D0Tmp2 = modelForInterface_D0Tmp1.toInt();
bool ret = getModel_D1(modelForInterface_D0Tmp2, model);
if(ret)
{
isSetInterface = true;
}
else
{
return false;
}
}
else
{
isSetInterface = false;
}
return true;
}
bool processPulseWidthParm(QCommandLineParser &parser, QCommandLineOption commandLineOption, int & pulseWidth, bool &isSetInterface)
{
if (isSetInterface && parser.isSet(commandLineOption))
{
const QString pulseWidth_D0Tmp = parser.value(commandLineOption);
pulseWidth = pulseWidth_D0Tmp.toInt();
isSetInterface = true;
}
else//默认参数
{
QStringList tmp = commandLineOption.defaultValues();
pulseWidth = tmp[0].toInt();
isSetInterface = false;
}
return true;
}
bool processPeriodParm(QCommandLineParser &parser, QCommandLineOption commandLineOption, int & period, bool &isSetInterface)
{
if (isSetInterface && parser.isSet(commandLineOption))
{
const QString period_Tmp = parser.value(commandLineOption);
period = period_Tmp.toInt();
}
else//默认参数
{
QStringList tmp = commandLineOption.defaultValues();
period = tmp[0].toInt();
isSetInterface = false;
}
return true;
}

73
commandlineparser.h Normal file
View File

@ -0,0 +1,73 @@
#ifndef COMMANDLINEPARSER_H
#define COMMANDLINEPARSER_H
#include <QCommandLineParser>
#include <QDir>
#include <string>
#include "witcommand.h"
enum CommandLineParseResult
{
CommandLineOk,
CommandLineError,
CommandLineVersionRequested,
CommandLineHelpRequested
};
struct TcQuery
{
QString serialPort;
int connectBaudrate;
bool isSetAlgorithm;
ALGROITHM_ENUM algorithm;
bool isSetInstallationOrientation;
ORIENT_ENUM installationOrientation;
bool isSetTimeZone;
TIMEZONE_ENUM timeZone;
bool isSetDefaultReturnContent;//wit默认 + 经纬度
RETURN_CONTENT_STRUCT defaultReturnContent;
RETURN_CONTENT_STRUCT returnContent;
bool isSetBaudrate;
BAUD_ENUM baudrate;
bool isSetReturnRate;
RRATE_ENUM returnRate;
bool isSetDeviceAddress;
int deviceAddress;
bool isSetInterface_D0;
MODEL_D0_D2_D3_ENUM modelForInterface_D0;//模式
int pulseWidth_D0;//脉宽
int period_D0;//周期
bool isSetInterface_D1;
MODEL_D1_ENUM modelForInterface_D1;//模式
int pulseWidth_D1;//脉宽
int period_D1;//周期
bool isSetInterface_D2;
MODEL_D0_D2_D3_ENUM modelForInterface_D2;//模式
int pulseWidth_D2;//脉宽
int period_D2;//周期
bool isSetInterface_D3;
MODEL_D0_D2_D3_ENUM modelForInterface_D3;//模式
int pulseWidth_D3;//脉宽
int period_D3;//周期
};
CommandLineParseResult parseCommandLine2(QCommandLineParser &parser, TcQuery *query, QString *errorMessage);
bool getModel(int modelIndex, MODEL_D0_D2_D3_ENUM & model);
bool getModel_D1(int modelIndex, MODEL_D1_ENUM & model);
bool processModelParm(QCommandLineParser &parser, QCommandLineOption commandLineOption, MODEL_D0_D2_D3_ENUM & model, bool &isSetInterface);
bool processModelParm_D1(QCommandLineParser &parser, QCommandLineOption commandLineOption, MODEL_D1_ENUM & model, bool &isSetInterface);
bool processPulseWidthParm(QCommandLineParser &parser, QCommandLineOption commandLineOption, int & pulseWidth, bool &isSetInterface);
bool processPeriodParm(QCommandLineParser &parser, QCommandLineOption commandLineOption, int & period, bool &isSetInterface);
#endif // COMMANDLINEPARSER_H

125
main.cpp
View File

@ -4,10 +4,12 @@
#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;
// std::cout<<"This is delay_tc!!!!!!!!!!"<<std::endl;
}
void printf_tc(const char* text)
@ -19,38 +21,111 @@ 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();
// SerialPortBase * serialPort = new windowsSerialPort();
int ret = serialPort->OpenSerialPort(query.serialPort.toStdString(), query.connectBaudrate);//"COM15"
if(ret)
{
std::cout<<"Serial port open failed!!"<<std::endl;
return 1;
}
serialPort->OpenSerialPort("COM15", 9600);
WitmotionDll * witmotion = new WitmotionDll(serialPort);
witmotion->delayMsRegister(delay_tc);
witmotion->printfRegister(printf_tc);
witmotion->setDelayTimeMs(1000);
WitmotionDll * tmp = new WitmotionDll(serialPort);
tmp->delayMsRegister(delay_tc);
tmp->printfRegister(printf_tc);
tmp->setDelayTimeMs(1000);
if(query.isSetAlgorithm)
{
witmotion->algorithm(query.algorithm);
}
tmp->installationOrientation(ORIENT_VERTICAL);
// tmp->algorithm(ALGROITHM9);
// tmp->setTimeZone(UTC_P12);
// tmp->SetBaudrate(WIT_BAUD_115200);
// tmp->SetReturnRate(RRATE_20HZ);
if(query.isSetInstallationOrientation)
{
witmotion->installationOrientation(query.installationOrientation);
}
// tmp->SetDeviceAddress(124);
if(query.isSetTimeZone)
{
witmotion->setTimeZone(query.timeZone);
}
// tmp->setD0Model(DOL);
// tmp->setD0HighLevelPulseWidth(20);
// tmp->setD0Period(5);
// RETURN_CONTENT_STRUCT content;
// content.time = true;
// content.angular_velocity = true;
// content.euler_angle = true;
// content.ground_velocity = true;
// content.quaternion = true;
// tmp->setContent(content);
if(query.isSetDefaultReturnContent)
{
witmotion->setContent(query.defaultReturnContent);
}
// tmp->recordData();
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();

View File

@ -27,15 +27,13 @@ int QtSerialport::OpenSerialPort(string portName, int baudrate)
m_serial->open(QIODevice::ReadWrite);
bool x=SetBaudrate(baudrate);
if(x)
int x=SetBaudrate(baudrate);
if(x == 0)
{
std::cout<<"波特率被成功设置为:"<<m_serial->baudRate()<<std::endl;
return 0;
}
else
{
std::cout<<"波特率设置失败!"<<std::endl;
return 1;
}
}
@ -48,8 +46,17 @@ int QtSerialport::CloseSerialPort()
int QtSerialport::SetBaudrate(int baudrate)
{
bool x=m_serial->setBaudRate(baudrate);
return 0;
bool x=m_serial->setBaudRate(baudrate);//qt的串口类设置波特率时任何数字都能成功这是什么鬼
int tmp = m_serial->baudRate();
if(x)
{
return 0;//成功
}
else
{
return 1;//失败
}
}
//qint64 write(const char *data, qint64 len);

View File

@ -1,3 +1,4 @@
wit_c_sdk问题
1、WitWriteReg WitReadReg是读寄存器为啥代码中用的还是p_WitSerialWriteFunc
2、打开串口相关代码有问题 → 解决;
3、qt的串口类设置波特率时任何数字都能成功这是什么鬼

2
readme.txt Normal file
View File

@ -0,0 +1,2 @@
1、任工需要的设置用法
--serialPort COM15 --connectBaudrate 9600 --rlx1

View File

@ -53,161 +53,6 @@
#define KEY 0x69
#define TIMEZONE 0x6B
/* KEY */
#define KEY_UNLOCK 0xB588
/* SAVE */
#define SAVE_PARAM 0x00
#define SAVE_SWRST 0xFF
/* algorithm */
enum ALGROITHM_ENUM {
ALGROITHM9 = 0,
ALGROITHM6 = 1
};
/* ORIENT */
enum ORIENT_ENUM {
ORIENT_HORIZONTAL = 0,
ORIENT_VERTICAL
};
/* ORIENT */
enum POWONSEND_ENUM {
CLOSE = 0,
OPEN
};
/* CALSW */
enum CAL_ENUM {
EXIT = 0,
GYROACC,
MAGNETIC,
ALTITUDE,
ALANGLEZ
};
#define EXITCAL 0x00
#define CALGYROACC 0x01
#define CALMAG 0x02
#define CALALTITUDE 0x03
#define CALANGLEZ 0x04
/* time zone */
enum TIMEZONE_ENUM {
UTC_N12 = 0,
UTC_N11,
UTC_N10,
UTC_N9,
UTC_N8,
UTC_N7,
UTC_N6,
UTC_N5,
UTC_N4,
UTC_N3,
UTC_N2,
UTC_N1,
UTC,
UTC_P1,
UTC_P2,
UTC_P3,
UTC_P4,
UTC_P5,
UTC_P6,
UTC_P7,
UTC_P8,//default
UTC_P9,
UTC_P10,
UTC_P11,
UTC_P12
};
/* RETURN CONTENT */
#define SetBit(VAR, Place) (VAR |= (1 << Place))
#define ClrBit(VAR, Place) (VAR &= ((1 << Place) ^ 255))
enum RETURN_CONTENT_ENUM {
//低位
TIME = 0,
ACCELERATION,
ANGULAR_VELOCITY,
EULER_ANGLE,
MAGNETIC_FIELD,
PORT_STATUS,
ATMOSPHERIC_PRESSURE_ALTITUDE,
LATITUDE_LONGITUDE,
//高位
GROUND_VELOCITY,
QUATERNION,//四元数
SATELLITE_ACCURACY
};
struct RETURN_CONTENT_STRUCT
{
//低位
bool time = false;
bool acceleration = false;
bool angular_velocity = false;
bool euler_angle = false;
bool magnetic_field = false;
bool port_status = false;
bool atmospheric_pressure_altitude = false;
bool latitude_longitude = false;
//高位
bool ground_velocity = false;
bool quaternion = false;
bool satellite_accuracy = false;
};
/* BAUD */
enum BAUD_ENUM {
WIT_BAUD_2400 = 0,
WIT_BAUD_4800,
WIT_BAUD_9600,//default
WIT_BAUD_19200,
WIT_BAUD_38400,
WIT_BAUD_57600,
WIT_BAUD_115200,
WIT_BAUD_230400,
WIT_BAUD_460800,
WIT_BAUD_921600
};
/**RRATE*****/
enum RRATE_ENUM {
RRATE_01HZ = 1,
RRATE_05HZ,
RRATE_1HZ,
RRATE_2HZ,
RRATE_5HZ,
RRATE_10HZ,//default
RRATE_20HZ,
RRATE_50HZ,
RRATE_100HZ,
RRATE_NONE,//保留
RRATE_200HZ,
RRATE_ONCE
};
/* 端口模式 */
enum MODEL_D0_D2_D3_ENUM {
AIN = 0,//default
DIN,
DOH,
DOL,
PWM
};
enum MODEL_D1_ENUM {
AIN_D1 = 0,//default
DIN_D1,
DOH_D1,
DOL_D1,
PWM_D1,
CLR_D1
};
#endif // REGISTER_H

161
witcommand.h Normal file
View File

@ -0,0 +1,161 @@
#ifndef WITCOMMAND_H
#define WITCOMMAND_H
/* KEY */
#define KEY_UNLOCK 0xB588
/* SAVE */
#define SAVE_PARAM 0x00
#define SAVE_SWRST 0xFF
/* algorithm */
enum ALGROITHM_ENUM {
ALGROITHM9 = 0,
ALGROITHM6 = 1
};
/* ORIENT */
enum ORIENT_ENUM {
ORIENT_HORIZONTAL = 0,
ORIENT_VERTICAL
};
/* ORIENT */
enum POWONSEND_ENUM {
CLOSE = 0,
OPEN
};
/* CALSW */
enum CAL_ENUM {
EXIT = 0,
GYROACC,
MAGNETIC,
ALTITUDE,
ALANGLEZ
};
#define EXITCAL 0x00
#define CALGYROACC 0x01
#define CALMAG 0x02
#define CALALTITUDE 0x03
#define CALANGLEZ 0x04
/* time zone */
enum TIMEZONE_ENUM {
UTC_N12 = 0,
UTC_N11,
UTC_N10,
UTC_N9,
UTC_N8,
UTC_N7,
UTC_N6,
UTC_N5,
UTC_N4,
UTC_N3,
UTC_N2,
UTC_N1,
UTC,
UTC_P1,
UTC_P2,
UTC_P3,
UTC_P4,
UTC_P5,
UTC_P6,
UTC_P7,
UTC_P8,//default
UTC_P9,
UTC_P10,
UTC_P11,
UTC_P12
};
/* RETURN CONTENT */
#define SetBit(VAR, Place) (VAR |= (1 << Place))
#define ClrBit(VAR, Place) (VAR &= ((1 << Place) ^ 255))
enum RETURN_CONTENT_ENUM {
//低位
TIME = 0,
ACCELERATION,
ANGULAR_VELOCITY,
EULER_ANGLE,
MAGNETIC_FIELD,
PORT_STATUS,
ATMOSPHERIC_PRESSURE_ALTITUDE,
LATITUDE_LONGITUDE,
//高位
GROUND_VELOCITY,
QUATERNION,//四元数
SATELLITE_ACCURACY
};
struct RETURN_CONTENT_STRUCT
{
//低位
bool time = false;
bool acceleration = true;
bool angular_velocity = true;
bool euler_angle = true;
bool magnetic_field = true;
bool port_status = false;
bool atmospheric_pressure_altitude = false;
bool latitude_longitude = true;
//高位
bool ground_velocity = false;
bool quaternion = false;
bool satellite_accuracy = false;
};
/* BAUD */
enum BAUD_ENUM {
WIT_BAUD_2400 = 0,
WIT_BAUD_4800,
WIT_BAUD_9600,//default
WIT_BAUD_19200,
WIT_BAUD_38400,
WIT_BAUD_57600,
WIT_BAUD_115200,
WIT_BAUD_230400,
WIT_BAUD_460800,
WIT_BAUD_921600
};
/**RRATE*****/
enum RRATE_ENUM {
RRATE_01HZ = 1,
RRATE_05HZ,
RRATE_1HZ,
RRATE_2HZ,
RRATE_5HZ,
RRATE_10HZ,//default
RRATE_20HZ,
RRATE_50HZ,
RRATE_100HZ,
RRATE_NONE,//保留
RRATE_200HZ,
RRATE_ONCE
};
/* 端口模式 */
enum MODEL_D0_D2_D3_ENUM {
AIN = 0,//default
DIN,
DOH,
DOL,
PWM
};
enum MODEL_D1_ENUM {
AIN_D1 = 0,//default
DIN_D1,
DOH_D1,
DOL_D1,
PWM_D1,
CLR_D1
};
#endif // WITCOMMAND_H

View File

@ -12,7 +12,8 @@ TEMPLATE = app
SOURCES += main.cpp \
witmotiondll.cpp \
qtserialport.cpp
qtserialport.cpp \
commandlineparser.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
@ -29,4 +30,6 @@ HEADERS += \
register.h \
serialportbase.h \
witmotiondll.h \
qtserialport.h
qtserialport.h \
commandlineparser.h \
witcommand.h

View File

@ -7,6 +7,7 @@
#include "serialportbase.h"
#include "register.h"
#include "witcommand.h"
typedef void (*delay)(uint32_t millisecond);
typedef void (*witPrintf)(const char* text);