Compare commits

...

5 Commits

Author SHA1 Message Date
xin
277e347e56 构建新的cmakelist工程
修改了  delay_tc函数
修返回频率为20hz
修改波特率修改后先重新设置通讯波特率在保存
2023-02-13 09:15:17 +08:00
d870c42486 最新任工设置参数:
1. D1的参数:需要设置成gps,选择默认的模拟输入(AIN)就OK → AIN、0、0;
2. D2/D3的参数:pwm、1500、20000;
2022-09-08 10:01:44 +08:00
14a4518e2e 1、从文件register.h中重构出命令文件witcommand.h;
2、解析命令行参数;
3、修改串口类(继承基类SerialPortBase)的bug;
4、添加命令行选项--rlx1:任工想要的设置;
2022-07-15 22:09:06 +08:00
3c0ba621ac 1、将工程从动态库变为命令行程序:修改pro文件、删除文件witmotiondll_global.h;
2、继承串口基类SerialPortBase实现串口类QtSerialport;
3、写维特惯导设置示例程序main.cpp;
2022-06-20 15:30:16 +08:00
15580116d1 1、修改串口虚类的读数据的原型; 2、添加使用startUML绘制的类图; 2022-06-20 10:59:40 +08:00
16 changed files with 3648 additions and 102 deletions

42
project/CMakeLists.txt Normal file
View File

@ -0,0 +1,42 @@
# cmake_minimum_required(VERSION <specify CMake version here>)
cmake_minimum_required(VERSION 3.3)
project(Wintmotion)
SET(CMAKE_INSTALL_PREFIX < /home/pi/bin >)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
IF (WIN32)
include_directories(../../third/GpsSynchComputerTime)
include_directories(C:/Qt/Qt5.12.7/5.12.7/mingw73_64/include C:/Qt/Qt5.12.7/5.12.7/mingw73_64/include/QtCore C:/Qt/Qt5.12.7/5.12.7/mingw73_64/include/QtNetwork C:/Qt/Qt5.12.7/5.12.7/mingw73_64/include/QtNetwork/QtSerialPort )
include_directories(C:/Qt/Qt5.12.7/5.12.7/mingw73_64/include/QtWebSockets)
ENDIF ()
set(QT Core Network Gui WebSockets SerialPort)
set(TEMPLATE app)
set(TARGET Wintmotion)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#find_package(Qt5 REQUIRED ${QT})
IF (WIN32)
MESSAGE(STATUS "Now is windows")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} C:/Qt/Qt5.12.7/5.12.7/mingw73_64/ )
ENDIF ()
find_package(Qt5 REQUIRED ${QT})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
include_directories(../source)
add_executable(Wintmotion
../source/commandlineparser.cpp
../source/main.cpp
../source/qtserialport.cpp
../source/witmotionDll.pro
../source/witmotiondll.cpp
)
qt5_use_modules(Wintmotion ${QT})

View File

@ -1,3 +1,4 @@
wit_c_sdk问题 wit_c_sdk问题
1、WitWriteReg WitReadReg是读寄存器为啥代码中用的还是p_WitSerialWriteFunc 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

@ -0,0 +1,652 @@
#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 = AIN_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;
query->isSetReturnRate= true;
query->returnRate=RRATE_20HZ;
}
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;
}

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

142
source/main.cpp Normal file
View 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();
}

122
source/qtserialport.cpp Normal file
View File

@ -0,0 +1,122 @@
#include "qtserialport.h"
int QtSerialport::OpenSerialPort(string portName, int baudrate)
{
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
for (int i=0; i<infos.length();i++)
{
qDebug()<<infos[i].portName();
// std::cout<<infos[i].portName()<<std::endl;
}
//std::cout<<"number of availablePorts:"<<infos.size()<<std::endl;
//如果在构造函数中创建m_serial就会出现错误:
//QObject: Cannot create children for a parent that is in a different thread.
//(Parent is QSerialPort(0x2e31b20), parent's thread is QThread(0x2e2f130), current thread is QThread(0x2e31110)
m_serial = new QSerialPort();
if(m_serial->isOpen())//如果串口已经打开了 先给他关闭了
{
m_serial->clear();
m_serial->close();
}
m_serial->setPortName(QString::fromStdString(portName));
m_serial->open(QIODevice::ReadWrite);
int x=SetBaudrate(baudrate);
if(x == 0)
{
return 0;
}
else
{
return 1;
}
}
int QtSerialport::CloseSerialPort()
{
m_serial->close();
return 0;
}
int QtSerialport::SetBaudrate(int baudrate)
{
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);
int QtSerialport::SendData1(const char *data, const unsigned int len)
{
QByteArray tmp(data, len);
// QByteArray tmp2 = tmp.toHex();
//QIODevice::write(const char *data, qint64 maxSize)
int num = m_serial->write(tmp);
bool re = m_serial->waitForBytesWritten(1000);
if(re)
{
return num;
}
else
{
return -1;
}
}
int QtSerialport::SendData(const char chrSendBuffer[],const unsigned short usLen)
{
int num = m_serial->write(chrSendBuffer, usLen);
return num;
}
int QtSerialport::ReadData(char * receivedData)
{
FILE * fileHandle=fopen("D:\\cpp_qtcreator\\witmotionDll_use-build\\debug\\test.dat","w+b");
QByteArray requestData;
while (true)
{
//std::cout<<"SbgRecorder::startRecordSbg--------------:"<<std::endl;
if(m_serial->waitForReadyRead(1000))
{
//requestData.resize(m_serial->size());
requestData = m_serial->readAll();
std::cout<<"size: "<< requestData.size() <<std::endl;
fwrite(requestData.data(),requestData.size(),1,fileHandle);
// fflush(fileHandle);
// if(!m_bIsSbgReady)
// {
// parseSbgMessage(&requestData);
// }
// parseSbgMessage(&requestData);//边采集惯导数据边解析,并不会导致惯导漏帧
}
else
{
std::cout<<"SbgRecorder::startRecordSbg----:Wait write response timeout"<<std::endl;
}
}
return 0;
}

36
source/qtserialport.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef QTSERIALPORT_H
#define QTSERIALPORT_H
#include "serialportbase.h"
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <qdebug.h>
#include <QDebug>
#include <iostream>
class QtSerialport :public SerialPortBase
{
// Q_OBJECT
public:
// QtSerialport();
// ~QtSerialport();
int OpenSerialPort(string portName, int baudrate);
int CloseSerialPort();
int SetBaudrate(int baudrate);
int SendData(const char chrSendBuffer[],const unsigned short usLen);
int SendData1(const char *data, const unsigned int len);
int ReadData(char * receivedData);
protected:
private:
QSerialPort * m_serial;
};
#endif // QTSERIALPORT_H

58
source/register.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef REGISTER_H
#define REGISTER_H
#define SAVE 0x00
#define CALSW 0x01
#define RSW 0x02
#define RRATE 0x03
#define BAUD 0x04
#define AXOFFSET 0x05
#define AYOFFSET 0x06
#define AZOFFSET 0x07
#define GXOFFSET 0x08
#define GYOFFSET 0x09
#define GZOFFSET 0x0a
#define HXOFFSET 0x0b
#define HYOFFSET 0x0c
#define HZOFFSET 0x0d
#define D0MODE 0x0e
#define D1MODE 0x0f
#define D2MODE 0x10
#define D3MODE 0x11
#define D0PWMH 0x12
#define D1PWMH 0x13
#define D2PWMH 0x14
#define D3PWMH 0x15
#define D0PWMT 0x16
#define D1PWMT 0x17
#define D2PWMT 0x18
#define D3PWMT 0x19
#define IICADDR 0x1a
#define LEDOFF 0x1b
#define MAGRANGX 0x1c
#define MAGRANGY 0x1d
#define MAGRANGZ 0x1e
#define BANDWIDTH 0x1f
#define GYRORANGE 0x20
#define ACCRANGE 0x21
#define SLEEP 0x22
#define ORIENT 0x23
#define AXIS6 0x24
#define FILTK 0x25
#define GPSBAUD 0x26
#define READADDR 0x27
#define BWSCALE 0x28
#define MOVETHR 0x28
#define MOVESTA 0x29
#define ACCFILT 0x2A
#define GYROFILT 0x2b
#define MAGFILT 0x2c
#define POWONSEND 0x2d
#define VERSION 0x2e
#define KEY 0x69
#define TIMEZONE 0x6B
#endif // REGISTER_H

View File

@ -17,7 +17,7 @@ public:
virtual int SetBaudrate(int baudrate) = 0; virtual int SetBaudrate(int baudrate) = 0;
virtual int SendData1(const char *data, const unsigned int len) = 0; virtual int SendData1(const char *data, const unsigned int len) = 0;
virtual int SendData(const char chrSendBuffer[],const unsigned short usLen) = 0; virtual int SendData(const char chrSendBuffer[],const unsigned short usLen) = 0;
virtual int ReadData() = 0; virtual int ReadData(char * receivedData) = 0;
protected: protected:
private: private:
}; };

View File

@ -1,57 +1,5 @@
#ifndef REGISTER_H #ifndef WITCOMMAND_H
#define REGISTER_H #define WITCOMMAND_H
#define SAVE 0x00
#define CALSW 0x01
#define RSW 0x02
#define RRATE 0x03
#define BAUD 0x04
#define AXOFFSET 0x05
#define AYOFFSET 0x06
#define AZOFFSET 0x07
#define GXOFFSET 0x08
#define GYOFFSET 0x09
#define GZOFFSET 0x0a
#define HXOFFSET 0x0b
#define HYOFFSET 0x0c
#define HZOFFSET 0x0d
#define D0MODE 0x0e
#define D1MODE 0x0f
#define D2MODE 0x10
#define D3MODE 0x11
#define D0PWMH 0x12
#define D1PWMH 0x13
#define D2PWMH 0x14
#define D3PWMH 0x15
#define D0PWMT 0x16
#define D1PWMT 0x17
#define D2PWMT 0x18
#define D3PWMT 0x19
#define IICADDR 0x1a
#define LEDOFF 0x1b
#define MAGRANGX 0x1c
#define MAGRANGY 0x1d
#define MAGRANGZ 0x1e
#define BANDWIDTH 0x1f
#define GYRORANGE 0x20
#define ACCRANGE 0x21
#define SLEEP 0x22
#define ORIENT 0x23
#define AXIS6 0x24
#define FILTK 0x25
#define GPSBAUD 0x26
#define READADDR 0x27
#define BWSCALE 0x28
#define MOVETHR 0x28
#define MOVESTA 0x29
#define ACCFILT 0x2A
#define GYROFILT 0x2b
#define MAGFILT 0x2c
#define POWONSEND 0x2d
#define VERSION 0x2e
#define KEY 0x69
#define TIMEZONE 0x6B
/* KEY */ /* KEY */
#define KEY_UNLOCK 0xB588 #define KEY_UNLOCK 0xB588
@ -147,13 +95,13 @@ struct RETURN_CONTENT_STRUCT
{ {
//低位 //低位
bool time = false; bool time = false;
bool acceleration = false; bool acceleration = true;
bool angular_velocity = false; bool angular_velocity = true;
bool euler_angle = false; bool euler_angle = true;
bool magnetic_field = false; bool magnetic_field = true;
bool port_status = false; bool port_status = false;
bool atmospheric_pressure_altitude = false; bool atmospheric_pressure_altitude = false;
bool latitude_longitude = false; bool latitude_longitude = true;
//高位 //高位
bool ground_velocity = false; bool ground_velocity = false;
@ -210,4 +158,4 @@ enum MODEL_D1_ENUM {
CLR_D1 CLR_D1
}; };
#endif // REGISTER_H #endif // WITCOMMAND_H

View File

@ -1,16 +1,22 @@
#------------------------------------------------- QT += core
# QT -= gui
# Project created by QtCreator 2022-05-25T15:16:09 QT += serialport
#
#------------------------------------------------- CONFIG += c++11
TARGET = witmotionDll TARGET = witmotionDll
TEMPLATE = lib CONFIG += console
CONFIG -= app_bundle
DEFINES += WITMOTIONDLL_LIBRARY TEMPLATE = app
SOURCES += main.cpp \
witmotiondll.cpp \
qtserialport.cpp \
commandlineparser.cpp
# The following define makes your compiler emit warnings if you use # The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings # any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the # depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it. # deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QT_DEPRECATED_WARNINGS
@ -20,16 +26,10 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt. # You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
witmotiondll.cpp
HEADERS += \ HEADERS += \
witmotiondll.h \ register.h \
witmotiondll_global.h \
serialportbase.h \ serialportbase.h \
register.h witmotiondll.h \
qtserialport.h \
unix { commandlineparser.h \
target.path = /usr/lib witcommand.h
INSTALLS += target
}

View File

@ -2,12 +2,12 @@
//当没有注册 延时函数m_delayFunction运行会停止在调用延时函数m_delayFunction //当没有注册 延时函数m_delayFunction运行会停止在调用延时函数m_delayFunction
//此函数就是为了解决上面说的问题 //此函数就是为了解决上面说的问题
void delay_tc(uint32_t millisecond) void delay_default(uint32_t millisecond)
{ {
; ;
} }
void printf_tc(const char* text) void printf_default(const char* text)
{ {
; ;
} }
@ -16,9 +16,9 @@ WitmotionDll::WitmotionDll(SerialPortBase * serialPort)
{ {
m_SerialPort = serialPort; m_SerialPort = serialPort;
m_delayFunction = delay_tc; m_delayFunction = delay_default;
m_witPrintf = printf_tc; m_witPrintf = printf_default;
} }
int WitmotionDll::delayMsRegister(delay delayFunction) int WitmotionDll::delayMsRegister(delay delayFunction)
@ -168,7 +168,8 @@ int WitmotionDll::setAngleReference()
void WitmotionDll::recordData() void WitmotionDll::recordData()
{ {
m_SerialPort->ReadData(); char * receivedData;
m_SerialPort->ReadData(receivedData);
} }
int WitmotionDll::setTimeZone(TIMEZONE_ENUM timeZone) int WitmotionDll::setTimeZone(TIMEZONE_ENUM timeZone)
@ -232,7 +233,7 @@ int WitmotionDll::SetBaudrate(BAUD_ENUM baudrate)
int numOfSend = constructAndSendInstruction(BAUD, baudrate); int numOfSend = constructAndSendInstruction(BAUD, baudrate);
m_witPrintf("WitmotionDll::SetBaudrate: \n"); m_witPrintf("WitmotionDll::SetBaudrate: \n");
saveInstruction(); // saveInstruction(); //设置完波特率 已经无法通讯 需要重新简历连接
return 0; return 0;
} }

View File

@ -1,19 +1,18 @@
#ifndef WITMOTIONDLL_H #ifndef WITMOTIONDLL_H
#define WITMOTIONDLL_H #define WITMOTIONDLL_H
#include "witmotiondll_global.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <thread> #include <thread>
#include "serialportbase.h" #include "serialportbase.h"
#include "register.h" #include "register.h"
#include "witcommand.h"
typedef void (*delay)(uint32_t millisecond); typedef void (*delay)(uint32_t millisecond);
typedef void (*witPrintf)(const char* text); typedef void (*witPrintf)(const char* text);
class WITMOTIONDLLSHARED_EXPORT WitmotionDll class WitmotionDll
{ {
public: public:

2482
uml.mdj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +0,0 @@
#ifndef WITMOTIONDLL_GLOBAL_H
#define WITMOTIONDLL_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(WITMOTIONDLL_LIBRARY)
# define WITMOTIONDLLSHARED_EXPORT Q_DECL_EXPORT
#else
# define WITMOTIONDLLSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // WITMOTIONDLL_GLOBAL_H