彻底改版2.0
This commit is contained in:
11
tool/comtool/api/api.pri
Normal file
11
tool/comtool/api/api.pri
Normal file
@@ -0,0 +1,11 @@
|
||||
HEADERS += \
|
||||
$$PWD/appconfig.h \
|
||||
$$PWD/appdata.h \
|
||||
$$PWD/quihelper.h \
|
||||
$$PWD/quihelperdata.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/appconfig.cpp \
|
||||
$$PWD/appdata.cpp \
|
||||
$$PWD/quihelper.cpp \
|
||||
$$PWD/quihelperdata.cpp
|
||||
99
tool/comtool/api/appconfig.cpp
Normal file
99
tool/comtool/api/appconfig.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "appconfig.h"
|
||||
#include "quihelper.h"
|
||||
|
||||
QString AppConfig::ConfigFile = "config.ini";
|
||||
QString AppConfig::SendFileName = "send.txt";
|
||||
QString AppConfig::DeviceFileName = "device.txt";
|
||||
|
||||
QString AppConfig::PortName = "COM1";
|
||||
int AppConfig::BaudRate = 9600;
|
||||
int AppConfig::DataBit = 8;
|
||||
QString AppConfig::Parity = QString::fromUtf8("无");
|
||||
double AppConfig::StopBit = 1;
|
||||
|
||||
bool AppConfig::HexSend = false;
|
||||
bool AppConfig::HexReceive = false;
|
||||
bool AppConfig::Debug = false;
|
||||
bool AppConfig::AutoClear = false;
|
||||
|
||||
bool AppConfig::AutoSend = false;
|
||||
int AppConfig::SendInterval = 1000;
|
||||
bool AppConfig::AutoSave = false;
|
||||
int AppConfig::SaveInterval = 5000;
|
||||
|
||||
QString AppConfig::Mode = "Tcp_Client";
|
||||
QString AppConfig::ServerIP = "127.0.0.1";
|
||||
int AppConfig::ServerPort = 6000;
|
||||
int AppConfig::ListenPort = 6000;
|
||||
int AppConfig::SleepTime = 100;
|
||||
bool AppConfig::AutoConnect = false;
|
||||
|
||||
void AppConfig::readConfig()
|
||||
{
|
||||
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
|
||||
|
||||
set.beginGroup("ComConfig");
|
||||
AppConfig::PortName = set.value("PortName", AppConfig::PortName).toString();
|
||||
AppConfig::BaudRate = set.value("BaudRate", AppConfig::BaudRate).toInt();
|
||||
AppConfig::DataBit = set.value("DataBit", AppConfig::DataBit).toInt();
|
||||
AppConfig::Parity = set.value("Parity", AppConfig::Parity).toString();
|
||||
AppConfig::StopBit = set.value("StopBit", AppConfig::StopBit).toInt();
|
||||
|
||||
AppConfig::HexSend = set.value("HexSend", AppConfig::HexSend).toBool();
|
||||
AppConfig::HexReceive = set.value("HexReceive", AppConfig::HexReceive).toBool();
|
||||
AppConfig::Debug = set.value("Debug", AppConfig::Debug).toBool();
|
||||
AppConfig::AutoClear = set.value("AutoClear", AppConfig::AutoClear).toBool();
|
||||
|
||||
AppConfig::AutoSend = set.value("AutoSend", AppConfig::AutoSend).toBool();
|
||||
AppConfig::SendInterval = set.value("SendInterval", AppConfig::SendInterval).toInt();
|
||||
AppConfig::AutoSave = set.value("AutoSave", AppConfig::AutoSave).toBool();
|
||||
AppConfig::SaveInterval = set.value("SaveInterval", AppConfig::SaveInterval).toInt();
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("NetConfig");
|
||||
AppConfig::Mode = set.value("Mode", AppConfig::Mode).toString();
|
||||
AppConfig::ServerIP = set.value("ServerIP", AppConfig::ServerIP).toString();
|
||||
AppConfig::ServerPort = set.value("ServerPort", AppConfig::ServerPort).toInt();
|
||||
AppConfig::ListenPort = set.value("ListenPort", AppConfig::ListenPort).toInt();
|
||||
AppConfig::SleepTime = set.value("SleepTime", AppConfig::SleepTime).toInt();
|
||||
AppConfig::AutoConnect = set.value("AutoConnect", AppConfig::AutoConnect).toBool();
|
||||
set.endGroup();
|
||||
|
||||
//配置文件不存在或者不全则重新生成
|
||||
if (!QUIHelper::checkIniFile(AppConfig::ConfigFile)) {
|
||||
writeConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AppConfig::writeConfig()
|
||||
{
|
||||
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
|
||||
|
||||
set.beginGroup("ComConfig");
|
||||
set.setValue("PortName", AppConfig::PortName);
|
||||
set.setValue("BaudRate", AppConfig::BaudRate);
|
||||
set.setValue("DataBit", AppConfig::DataBit);
|
||||
set.setValue("Parity", AppConfig::Parity);
|
||||
set.setValue("StopBit", AppConfig::StopBit);
|
||||
|
||||
set.setValue("HexSend", AppConfig::HexSend);
|
||||
set.setValue("HexReceive", AppConfig::HexReceive);
|
||||
set.setValue("Debug", AppConfig::Debug);
|
||||
set.setValue("AutoClear", AppConfig::AutoClear);
|
||||
|
||||
set.setValue("AutoSend", AppConfig::AutoSend);
|
||||
set.setValue("SendInterval", AppConfig::SendInterval);
|
||||
set.setValue("AutoSave", AppConfig::AutoSave);
|
||||
set.setValue("SaveInterval", AppConfig::SaveInterval);
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("NetConfig");
|
||||
set.setValue("Mode", AppConfig::Mode);
|
||||
set.setValue("ServerIP", AppConfig::ServerIP);
|
||||
set.setValue("ServerPort", AppConfig::ServerPort);
|
||||
set.setValue("ListenPort", AppConfig::ListenPort);
|
||||
set.setValue("SleepTime", AppConfig::SleepTime);
|
||||
set.setValue("AutoConnect", AppConfig::AutoConnect);
|
||||
set.endGroup();
|
||||
}
|
||||
41
tool/comtool/api/appconfig.h
Normal file
41
tool/comtool/api/appconfig.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef APPCONFIG_H
|
||||
#define APPCONFIG_H
|
||||
|
||||
#include "head.h"
|
||||
|
||||
class AppConfig
|
||||
{
|
||||
public:
|
||||
static QString ConfigFile; //配置文件路径
|
||||
static QString SendFileName; //发送配置文件名
|
||||
static QString DeviceFileName; //模拟设备数据文件名
|
||||
|
||||
static QString PortName; //串口号
|
||||
static int BaudRate; //波特率
|
||||
static int DataBit; //数据位
|
||||
static QString Parity; //校验位
|
||||
static double StopBit; //停止位
|
||||
|
||||
static bool HexSend; //16进制发送
|
||||
static bool HexReceive; //16进制接收
|
||||
static bool Debug; //模拟设备
|
||||
static bool AutoClear; //自动清空
|
||||
|
||||
static bool AutoSend; //自动发送
|
||||
static int SendInterval; //自动发送间隔
|
||||
static bool AutoSave; //自动保存
|
||||
static int SaveInterval; //自动保存间隔
|
||||
|
||||
static QString Mode; //转换模式
|
||||
static QString ServerIP; //服务器IP
|
||||
static int ServerPort; //服务器端口
|
||||
static int ListenPort; //监听端口
|
||||
static int SleepTime; //延时时间
|
||||
static bool AutoConnect; //自动重连
|
||||
|
||||
//读写配置参数
|
||||
static void readConfig(); //读取配置参数
|
||||
static void writeConfig(); //写入配置参数
|
||||
};
|
||||
|
||||
#endif // APPCONFIG_H
|
||||
122
tool/comtool/api/appdata.cpp
Normal file
122
tool/comtool/api/appdata.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#include "appdata.h"
|
||||
#include "quihelper.h"
|
||||
|
||||
QStringList AppData::Intervals = QStringList();
|
||||
QStringList AppData::Datas = QStringList();
|
||||
QStringList AppData::Keys = QStringList();
|
||||
QStringList AppData::Values = QStringList();
|
||||
|
||||
QString AppData::SendFileName = "send.txt";
|
||||
void AppData::readSendData()
|
||||
{
|
||||
//读取发送数据列表
|
||||
AppData::Datas.clear();
|
||||
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(AppData::SendFileName);
|
||||
QFile file(fileName);
|
||||
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line = line.trimmed();
|
||||
line = line.replace("\r", "");
|
||||
line = line.replace("\n", "");
|
||||
if (!line.isEmpty()) {
|
||||
AppData::Datas.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
//没有的时候主动添加点免得太空
|
||||
if (AppData::Datas.count() == 0) {
|
||||
AppData::Datas << "16 FF 01 01 E0 E1" << "16 FF 01 01 E1 E2";
|
||||
}
|
||||
}
|
||||
|
||||
QString AppData::DeviceFileName = "device.txt";
|
||||
void AppData::readDeviceData()
|
||||
{
|
||||
//读取转发数据列表
|
||||
AppData::Keys.clear();
|
||||
AppData::Values.clear();
|
||||
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(AppData::DeviceFileName);
|
||||
QFile file(fileName);
|
||||
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line = line.trimmed();
|
||||
line = line.replace("\r", "");
|
||||
line = line.replace("\n", "");
|
||||
if (!line.isEmpty()) {
|
||||
QStringList list = line.split(";");
|
||||
QString key = list.at(0);
|
||||
QString value;
|
||||
for (int i = 1; i < list.count(); i++) {
|
||||
value += QString("%1;").arg(list.at(i));
|
||||
}
|
||||
|
||||
//去掉末尾分号
|
||||
value = value.mid(0, value.length() - 1);
|
||||
AppData::Keys.append(key);
|
||||
AppData::Values.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void AppData::saveData(const QString &data)
|
||||
{
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString fileName = QString("%1/%2.txt").arg(QUIHelper::appPath()).arg(STRDATETIME);
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
file.write(data.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void AppData::loadIP(QComboBox *cbox)
|
||||
{
|
||||
//获取本机所有IP
|
||||
static QStringList ips;
|
||||
if (ips.count() == 0) {
|
||||
#ifdef emsdk
|
||||
ips << "127.0.0.1";
|
||||
#else
|
||||
QList<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces();
|
||||
foreach (const QNetworkInterface &netInterface, netInterfaces) {
|
||||
//移除虚拟机和抓包工具的虚拟网卡
|
||||
QString humanReadableName = netInterface.humanReadableName().toLower();
|
||||
if (humanReadableName.startsWith("vmware network adapter") || humanReadableName.startsWith("npcap loopback adapter")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//过滤当前网络接口
|
||||
bool flag = (netInterface.flags() == (QNetworkInterface::IsUp | QNetworkInterface::IsRunning | QNetworkInterface::CanBroadcast | QNetworkInterface::CanMulticast));
|
||||
if (flag) {
|
||||
QList<QNetworkAddressEntry> addrs = netInterface.addressEntries();
|
||||
foreach (QNetworkAddressEntry addr, addrs) {
|
||||
//只取出IPV4的地址
|
||||
if (addr.ip().protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
QString ip4 = addr.ip().toString();
|
||||
if (ip4 != "127.0.0.1") {
|
||||
ips << ip4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
cbox->clear();
|
||||
cbox->addItems(ips);
|
||||
if (!ips.contains("127.0.0.1")) {
|
||||
cbox->addItem("127.0.0.1");
|
||||
}
|
||||
}
|
||||
30
tool/comtool/api/appdata.h
Normal file
30
tool/comtool/api/appdata.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef APPDATA_H
|
||||
#define APPDATA_H
|
||||
|
||||
#include "head.h"
|
||||
|
||||
class AppData
|
||||
{
|
||||
public:
|
||||
//全局变量
|
||||
static QStringList Intervals;
|
||||
static QStringList Datas;
|
||||
static QStringList Keys;
|
||||
static QStringList Values;
|
||||
|
||||
//读取发送数据列表
|
||||
static QString SendFileName;
|
||||
static void readSendData();
|
||||
|
||||
//读取转发数据列表
|
||||
static QString DeviceFileName;
|
||||
static void readDeviceData();
|
||||
|
||||
//保存数据到文件
|
||||
static void saveData(const QString &data);
|
||||
|
||||
//添加网卡IP地址到下拉框
|
||||
static void loadIP(QComboBox *cbox);
|
||||
};
|
||||
|
||||
#endif // APPDATA_H
|
||||
420
tool/comtool/api/quihelper.cpp
Normal file
420
tool/comtool/api/quihelper.cpp
Normal file
@@ -0,0 +1,420 @@
|
||||
#include "quihelper.h"
|
||||
|
||||
int QUIHelper::getScreenIndex()
|
||||
{
|
||||
//需要对多个屏幕进行处理
|
||||
int screenIndex = 0;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
int screenCount = qApp->screens().count();
|
||||
#else
|
||||
int screenCount = qApp->desktop()->screenCount();
|
||||
#endif
|
||||
|
||||
if (screenCount > 1) {
|
||||
//找到当前鼠标所在屏幕
|
||||
QPoint pos = QCursor::pos();
|
||||
for (int i = 0; i < screenCount; ++i) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
if (qApp->screens().at(i)->geometry().contains(pos)) {
|
||||
#else
|
||||
if (qApp->desktop()->screenGeometry(i).contains(pos)) {
|
||||
#endif
|
||||
screenIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return screenIndex;
|
||||
}
|
||||
|
||||
QRect QUIHelper::getScreenRect(bool available)
|
||||
{
|
||||
QRect rect;
|
||||
int screenIndex = QUIHelper::getScreenIndex();
|
||||
if (available) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
rect = qApp->screens().at(screenIndex)->availableGeometry();
|
||||
#else
|
||||
rect = qApp->desktop()->availableGeometry(screenIndex);
|
||||
#endif
|
||||
} else {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
rect = qApp->screens().at(screenIndex)->geometry();
|
||||
#else
|
||||
rect = qApp->desktop()->screenGeometry(screenIndex);
|
||||
#endif
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
int QUIHelper::deskWidth()
|
||||
{
|
||||
return getScreenRect().width();
|
||||
}
|
||||
|
||||
int QUIHelper::deskHeight()
|
||||
{
|
||||
return getScreenRect().height();
|
||||
}
|
||||
|
||||
QWidget *QUIHelper::centerBaseForm = 0;
|
||||
void QUIHelper::setFormInCenter(QWidget *form)
|
||||
{
|
||||
int formWidth = form->width();
|
||||
int formHeight = form->height();
|
||||
|
||||
//如果=0表示采用系统桌面屏幕为参照
|
||||
QRect rect;
|
||||
if (centerBaseForm == 0) {
|
||||
rect = getScreenRect();
|
||||
} else {
|
||||
rect = centerBaseForm->geometry();
|
||||
}
|
||||
|
||||
int deskWidth = rect.width();
|
||||
int deskHeight = rect.height();
|
||||
QPoint movePoint(deskWidth / 2 - formWidth / 2 + rect.x(), deskHeight / 2 - formHeight / 2 + rect.y());
|
||||
form->move(movePoint);
|
||||
}
|
||||
|
||||
QString QUIHelper::appName()
|
||||
{
|
||||
//没有必要每次都获取,只有当变量为空时才去获取一次
|
||||
static QString name;
|
||||
if (name.isEmpty()) {
|
||||
name = qApp->applicationFilePath();
|
||||
//下面的方法主要为了过滤安卓的路径 lib程序名_armeabi-v7a
|
||||
QStringList list = name.split("/");
|
||||
name = list.at(list.count() - 1).split(".").at(0);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
QString QUIHelper::appPath()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
//return QString("/sdcard/Android/%1").arg(appName());
|
||||
return QString("/storage/emulated/0/%1").arg(appName());
|
||||
#else
|
||||
return qApp->applicationDirPath();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString QUIHelper::getUuid()
|
||||
{
|
||||
QString uuid = QUuid::createUuid().toString();
|
||||
uuid.replace("{", "");
|
||||
uuid.replace("}", "");
|
||||
return uuid;
|
||||
}
|
||||
|
||||
void QUIHelper::initRand()
|
||||
{
|
||||
//初始化随机数种子
|
||||
QTime t = QTime::currentTime();
|
||||
srand(t.msec() + t.second() * 1000);
|
||||
}
|
||||
|
||||
void QUIHelper::newDir(const QString &dirName)
|
||||
{
|
||||
QString strDir = dirName;
|
||||
|
||||
//如果路径中包含斜杠字符则说明是绝对路径
|
||||
//linux系统路径字符带有 / windows系统 路径字符带有 :/
|
||||
if (!strDir.startsWith("/") && !strDir.contains(":/")) {
|
||||
strDir = QString("%1/%2").arg(QUIHelper::appPath()).arg(strDir);
|
||||
}
|
||||
|
||||
QDir dir(strDir);
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(strDir);
|
||||
}
|
||||
}
|
||||
|
||||
void QUIHelper::sleep(int msec)
|
||||
{
|
||||
if (msec <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
QThread::msleep(msec);
|
||||
#else
|
||||
QTime endTime = QTime::currentTime().addMSecs(msec);
|
||||
while (QTime::currentTime() < endTime) {
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void QUIHelper::setStyle()
|
||||
{
|
||||
//打印下所有内置风格的名字
|
||||
qDebug() << "Qt内置的样式" << QStyleFactory::keys();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
qApp->setStyle(QStyleFactory::create("Fusion"));
|
||||
#else
|
||||
qApp->setStyle(QStyleFactory::create("Cleanlooks"));
|
||||
#endif
|
||||
//qApp->setPalette(QPalette("#FFFFFF"));
|
||||
}
|
||||
|
||||
void QUIHelper::setFont(int fontSize)
|
||||
{
|
||||
QFont font;
|
||||
font.setFamily("MicroSoft Yahei");
|
||||
#ifdef Q_OS_ANDROID
|
||||
font.setPixelSize(15);
|
||||
#elif __arm__
|
||||
font.setPixelSize(25);
|
||||
#else
|
||||
font.setPixelSize(fontSize);
|
||||
#endif
|
||||
|
||||
#ifndef rk3399
|
||||
qApp->setFont(font);
|
||||
#endif
|
||||
}
|
||||
|
||||
void QUIHelper::setCode(bool utf8)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
//如果想要控制台打印信息中文正常就注释掉这个设置
|
||||
if (utf8) {
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
}
|
||||
#else
|
||||
#if _MSC_VER
|
||||
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
||||
#else
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
#endif
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
QTextCodec::setCodecForCStrings(codec);
|
||||
QTextCodec::setCodecForTr(codec);
|
||||
#endif
|
||||
}
|
||||
|
||||
void QUIHelper::setTranslator(const QString &qmFile)
|
||||
{
|
||||
//过滤下不存在的就不用设置了
|
||||
if (!QFile(qmFile).exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QTranslator *translator = new QTranslator(qApp);
|
||||
translator->load(qmFile);
|
||||
qApp->installTranslator(translator);
|
||||
}
|
||||
|
||||
void QUIHelper::initAll()
|
||||
{
|
||||
//初始化随机数种子
|
||||
QUIHelper::initRand();
|
||||
//设置样式风格
|
||||
QUIHelper::setStyle();
|
||||
//设置字体
|
||||
QUIHelper::setFont(13);
|
||||
//设置编码
|
||||
QUIHelper::setCode();
|
||||
//设置翻译文件支持多个
|
||||
QUIHelper::setTranslator(":/qm/widgets.qm");
|
||||
QUIHelper::setTranslator(":/qm/qt_zh_CN.qm");
|
||||
QUIHelper::setTranslator(":/qm/designer_zh_CN.qm");
|
||||
}
|
||||
|
||||
void QUIHelper::setFramelessForm(QWidget *widgetMain, bool tool, bool top, bool menu)
|
||||
{
|
||||
widgetMain->setProperty("form", true);
|
||||
widgetMain->setProperty("canMove", true);
|
||||
|
||||
//根据设定逐个追加属性
|
||||
#ifdef __arm__
|
||||
widgetMain->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
|
||||
#else
|
||||
widgetMain->setWindowFlags(Qt::FramelessWindowHint);
|
||||
#endif
|
||||
if (tool) {
|
||||
widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::Tool);
|
||||
}
|
||||
if (top) {
|
||||
widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::WindowStaysOnTopHint);
|
||||
}
|
||||
if (menu) {
|
||||
//如果是其他系统比如neokylin会产生系统边框
|
||||
#ifdef Q_OS_WIN
|
||||
widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int QUIHelper::showMessageBox(const QString &info, int type, int closeSec, bool exec)
|
||||
{
|
||||
int result = 0;
|
||||
if (type == 0) {
|
||||
showMessageBoxInfo(info, closeSec, exec);
|
||||
} else if (type == 1) {
|
||||
showMessageBoxError(info, closeSec, exec);
|
||||
} else if (type == 2) {
|
||||
result = showMessageBoxQuestion(info);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void QUIHelper::showMessageBoxInfo(const QString &info, int closeSec, bool exec)
|
||||
{
|
||||
QMessageBox box(QMessageBox::Information, "提示", info);
|
||||
box.setStandardButtons(QMessageBox::Yes);
|
||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
||||
box.exec();
|
||||
//QMessageBox::information(0, "提示", info, QMessageBox::Yes);
|
||||
}
|
||||
|
||||
void QUIHelper::showMessageBoxError(const QString &info, int closeSec, bool exec)
|
||||
{
|
||||
QMessageBox box(QMessageBox::Critical, "错误", info);
|
||||
box.setStandardButtons(QMessageBox::Yes);
|
||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
||||
box.exec();
|
||||
//QMessageBox::critical(0, "错误", info, QMessageBox::Yes);
|
||||
}
|
||||
|
||||
int QUIHelper::showMessageBoxQuestion(const QString &info)
|
||||
{
|
||||
QMessageBox box(QMessageBox::Question, "询问", info);
|
||||
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
box.setButtonText(QMessageBox::Yes, QString("确 定"));
|
||||
box.setButtonText(QMessageBox::No, QString("取 消"));
|
||||
return box.exec();
|
||||
//return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No);
|
||||
}
|
||||
|
||||
QString QUIHelper::getXorEncryptDecrypt(const QString &value, char key)
|
||||
{
|
||||
//矫正范围外的数据
|
||||
if (key < 0 || key >= 127) {
|
||||
key = 127;
|
||||
}
|
||||
|
||||
QString result = value;
|
||||
int count = result.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
result[i] = QChar(result.at(i).toLatin1() ^ key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uchar QUIHelper::getOrCode(const QByteArray &data)
|
||||
{
|
||||
int len = data.length();
|
||||
uchar result = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
result ^= data.at(i);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uchar QUIHelper::getCheckCode(const QByteArray &data)
|
||||
{
|
||||
int len = data.length();
|
||||
uchar temp = 0;
|
||||
for (uchar i = 0; i < len; i++) {
|
||||
temp += data.at(i);
|
||||
}
|
||||
|
||||
return temp % 256;
|
||||
}
|
||||
|
||||
void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast)
|
||||
{
|
||||
//取消自动换行
|
||||
tableView->setWordWrap(false);
|
||||
//超出文本不显示省略号
|
||||
tableView->setTextElideMode(Qt::ElideNone);
|
||||
//奇数偶数行颜色交替
|
||||
tableView->setAlternatingRowColors(false);
|
||||
//垂直表头是否可见
|
||||
tableView->verticalHeader()->setVisible(headVisible);
|
||||
//选中一行表头是否加粗
|
||||
tableView->horizontalHeader()->setHighlightSections(false);
|
||||
//最后一行拉伸填充
|
||||
tableView->horizontalHeader()->setStretchLastSection(stretchLast);
|
||||
//行标题最小宽度尺寸
|
||||
tableView->horizontalHeader()->setMinimumSectionSize(0);
|
||||
//行标题最小高度,等同于和默认行高一致
|
||||
tableView->horizontalHeader()->setFixedHeight(rowHeight);
|
||||
//默认行高
|
||||
tableView->verticalHeader()->setDefaultSectionSize(rowHeight);
|
||||
//选中时一行整体选中
|
||||
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
//只允许选择单个
|
||||
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
//表头不可单击
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
tableView->horizontalHeader()->setSectionsClickable(false);
|
||||
#else
|
||||
tableView->horizontalHeader()->setClickable(false);
|
||||
#endif
|
||||
|
||||
//鼠标按下即进入编辑模式
|
||||
if (edit) {
|
||||
tableView->setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::DoubleClicked);
|
||||
} else {
|
||||
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
}
|
||||
}
|
||||
|
||||
void QUIHelper::openFile(const QString &fileName, const QString &msg)
|
||||
{
|
||||
#ifdef __arm__
|
||||
return;
|
||||
#endif
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (QUIHelper::showMessageBoxQuestion(msg + "成功!确定现在就打开吗?") == QMessageBox::Yes) {
|
||||
QString url = QString("file:///%1").arg(fileName);
|
||||
QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
|
||||
}
|
||||
}
|
||||
|
||||
bool QUIHelper::checkIniFile(const QString &iniFile)
|
||||
{
|
||||
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
||||
QFile file(iniFile);
|
||||
if (file.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
bool ok = true;
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line.replace("\r", "");
|
||||
line.replace("\n", "");
|
||||
QStringList list = line.split("=");
|
||||
|
||||
if (list.count() == 2) {
|
||||
if (list.at(1) == "") {
|
||||
qDebug() << "ini node no value" << list.at(0);
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
70
tool/comtool/api/quihelper.h
Normal file
70
tool/comtool/api/quihelper.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef QUIHELPER2_H
|
||||
#define QUIHELPER2_H
|
||||
|
||||
#include "head.h"
|
||||
|
||||
class QUIHelper
|
||||
{
|
||||
public:
|
||||
//获取当前鼠标所在屏幕索引+尺寸
|
||||
static int getScreenIndex();
|
||||
static QRect getScreenRect(bool available = true);
|
||||
|
||||
//获取桌面宽度高度+居中显示
|
||||
static int deskWidth();
|
||||
static int deskHeight();
|
||||
|
||||
//居中显示窗体
|
||||
//定义标志位指定是以桌面为参照还是主程序界面为参照
|
||||
static QWidget *centerBaseForm;
|
||||
static void setFormInCenter(QWidget *form);
|
||||
|
||||
//程序文件名称+当前所在路径
|
||||
static QString appName();
|
||||
static QString appPath();
|
||||
|
||||
//获取uuid+初始化随机数种子+新建目录+延时
|
||||
static QString getUuid();
|
||||
static void initRand();
|
||||
static void newDir(const QString &dirName);
|
||||
static void sleep(int msec);
|
||||
|
||||
//设置样式+字体+编码+居中+翻译
|
||||
static void setStyle();
|
||||
static void setFont(int fontSize = 12);
|
||||
static void setCode(bool utf8 = true);
|
||||
static void setTranslator(const QString &qmFile);
|
||||
//一次性设置所有
|
||||
static void initAll();
|
||||
|
||||
//设置无边框
|
||||
static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true);
|
||||
|
||||
//弹出框
|
||||
static int showMessageBox(const QString &info, int type = 0, int closeSec = 0, bool exec = false);
|
||||
//弹出消息框
|
||||
static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出错误框
|
||||
static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出询问框
|
||||
static int showMessageBoxQuestion(const QString &info);
|
||||
|
||||
//异或加密-只支持字符,如果是中文需要将其转换base64编码
|
||||
static QString getXorEncryptDecrypt(const QString &value, char key);
|
||||
//异或校验
|
||||
static uchar getOrCode(const QByteArray &data);
|
||||
//计算校验码
|
||||
static uchar getCheckCode(const QByteArray &data);
|
||||
|
||||
//初始化表格
|
||||
static void initTableView(QTableView *tableView, int rowHeight = 25,
|
||||
bool headVisible = false, bool edit = false,
|
||||
bool stretchLast = true);
|
||||
//打开文件带提示框
|
||||
static void openFile(const QString &fileName, const QString &msg);
|
||||
|
||||
//检查ini配置文件
|
||||
static bool checkIniFile(const QString &iniFile);
|
||||
};
|
||||
|
||||
#endif // QUIHELPER2_H
|
||||
450
tool/comtool/api/quihelperdata.cpp
Normal file
450
tool/comtool/api/quihelperdata.cpp
Normal file
@@ -0,0 +1,450 @@
|
||||
#include "quihelperdata.h"
|
||||
#include "quihelper.h"
|
||||
|
||||
int QUIHelperData::strHexToDecimal(const QString &strHex)
|
||||
{
|
||||
bool ok;
|
||||
return strHex.toInt(&ok, 16);
|
||||
}
|
||||
|
||||
int QUIHelperData::strDecimalToDecimal(const QString &strDecimal)
|
||||
{
|
||||
bool ok;
|
||||
return strDecimal.toInt(&ok, 10);
|
||||
}
|
||||
|
||||
int QUIHelperData::strBinToDecimal(const QString &strBin)
|
||||
{
|
||||
bool ok;
|
||||
return strBin.toInt(&ok, 2);
|
||||
}
|
||||
|
||||
QString QUIHelperData::strHexToStrBin(const QString &strHex)
|
||||
{
|
||||
uchar decimal = strHexToDecimal(strHex);
|
||||
QString bin = QString::number(decimal, 2);
|
||||
uchar len = bin.length();
|
||||
|
||||
if (len < 8) {
|
||||
for (int i = 0; i < 8 - len; i++) {
|
||||
bin = "0" + bin;
|
||||
}
|
||||
}
|
||||
|
||||
return bin;
|
||||
}
|
||||
|
||||
QString QUIHelperData::decimalToStrBin1(int decimal)
|
||||
{
|
||||
QString bin = QString::number(decimal, 2);
|
||||
uchar len = bin.length();
|
||||
if (len <= 8) {
|
||||
for (int i = 0; i < 8 - len; i++) {
|
||||
bin = "0" + bin;
|
||||
}
|
||||
}
|
||||
|
||||
return bin;
|
||||
}
|
||||
|
||||
QString QUIHelperData::decimalToStrBin2(int decimal)
|
||||
{
|
||||
QString bin = QString::number(decimal, 2);
|
||||
uchar len = bin.length();
|
||||
if (len <= 16) {
|
||||
for (int i = 0; i < 16 - len; i++) {
|
||||
bin = "0" + bin;
|
||||
}
|
||||
}
|
||||
|
||||
return bin;
|
||||
}
|
||||
|
||||
QString QUIHelperData::decimalToStrHex(int decimal)
|
||||
{
|
||||
QString temp = QString::number(decimal, 16);
|
||||
if (temp.length() == 1) {
|
||||
temp = "0" + temp;
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
QByteArray QUIHelperData::intToByte(int data)
|
||||
{
|
||||
QByteArray result;
|
||||
result.resize(4);
|
||||
result[3] = (uchar)(0x000000ff & data);
|
||||
result[2] = (uchar)((0x0000ff00 & data) >> 8);
|
||||
result[1] = (uchar)((0x00ff0000 & data) >> 16);
|
||||
result[0] = (uchar)((0xff000000 & data) >> 24);
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray QUIHelperData::intToByteRec(int data)
|
||||
{
|
||||
QByteArray result;
|
||||
result.resize(4);
|
||||
result[0] = (uchar)(0x000000ff & data);
|
||||
result[1] = (uchar)((0x0000ff00 & data) >> 8);
|
||||
result[2] = (uchar)((0x00ff0000 & data) >> 16);
|
||||
result[3] = (uchar)((0xff000000 & data) >> 24);
|
||||
return result;
|
||||
}
|
||||
|
||||
int QUIHelperData::byteToInt(const QByteArray &data)
|
||||
{
|
||||
int i = data.at(3) & 0x000000ff;
|
||||
i |= ((data.at(2) << 8) & 0x0000ff00);
|
||||
i |= ((data.at(1) << 16) & 0x00ff0000);
|
||||
i |= ((data.at(0) << 24) & 0xff000000);
|
||||
return i;
|
||||
}
|
||||
|
||||
int QUIHelperData::byteToIntRec(const QByteArray &data)
|
||||
{
|
||||
int i = data.at(0) & 0x000000ff;
|
||||
i |= ((data.at(1) << 8) & 0x0000ff00);
|
||||
i |= ((data.at(2) << 16) & 0x00ff0000);
|
||||
i |= ((data.at(3) << 24) & 0xff000000);
|
||||
return i;
|
||||
}
|
||||
|
||||
quint32 QUIHelperData::byteToUInt(const QByteArray &data)
|
||||
{
|
||||
quint32 i = data.at(3) & 0x000000ff;
|
||||
i |= ((data.at(2) << 8) & 0x0000ff00);
|
||||
i |= ((data.at(1) << 16) & 0x00ff0000);
|
||||
i |= ((data.at(0) << 24) & 0xff000000);
|
||||
return i;
|
||||
}
|
||||
|
||||
quint32 QUIHelperData::byteToUIntRec(const QByteArray &data)
|
||||
{
|
||||
quint32 i = data.at(0) & 0x000000ff;
|
||||
i |= ((data.at(1) << 8) & 0x0000ff00);
|
||||
i |= ((data.at(2) << 16) & 0x00ff0000);
|
||||
i |= ((data.at(3) << 24) & 0xff000000);
|
||||
return i;
|
||||
}
|
||||
|
||||
QByteArray QUIHelperData::ushortToByte(ushort data)
|
||||
{
|
||||
QByteArray result;
|
||||
result.resize(2);
|
||||
result[1] = (uchar)(0x000000ff & data);
|
||||
result[0] = (uchar)((0x0000ff00 & data) >> 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray QUIHelperData::ushortToByteRec(ushort data)
|
||||
{
|
||||
QByteArray result;
|
||||
result.resize(2);
|
||||
result[0] = (uchar)(0x000000ff & data);
|
||||
result[1] = (uchar)((0x0000ff00 & data) >> 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
int QUIHelperData::byteToUShort(const QByteArray &data)
|
||||
{
|
||||
int i = data.at(1) & 0x000000FF;
|
||||
i |= ((data.at(0) << 8) & 0x0000FF00);
|
||||
if (i >= 32768) {
|
||||
i = i - 65536;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int QUIHelperData::byteToUShortRec(const QByteArray &data)
|
||||
{
|
||||
int i = data.at(0) & 0x000000FF;
|
||||
i |= ((data.at(1) << 8) & 0x0000FF00);
|
||||
if (i >= 32768) {
|
||||
i = i - 65536;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
QString QUIHelperData::getValue(quint8 value)
|
||||
{
|
||||
QString result = QString::number(value);
|
||||
if (result.length() <= 1) {
|
||||
result = QString("0%1").arg(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString QUIHelperData::getXorEncryptDecrypt(const QString &value, char key)
|
||||
{
|
||||
//矫正范围外的数据
|
||||
if (key < 0 || key >= 127) {
|
||||
key = 127;
|
||||
}
|
||||
|
||||
QString result = value;
|
||||
int count = result.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
result[i] = QChar(result.at(i).toLatin1() ^ key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uchar QUIHelperData::getOrCode(const QByteArray &data)
|
||||
{
|
||||
int len = data.length();
|
||||
uchar result = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
result ^= data.at(i);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uchar QUIHelperData::getCheckCode(const QByteArray &data)
|
||||
{
|
||||
int len = data.length();
|
||||
uchar temp = 0;
|
||||
for (uchar i = 0; i < len; i++) {
|
||||
temp += data.at(i);
|
||||
}
|
||||
|
||||
return temp % 256;
|
||||
}
|
||||
|
||||
//函数功能:计算CRC16
|
||||
//参数1:*data 16位CRC校验数据,
|
||||
//参数2:len 数据流长度
|
||||
//参数3:init 初始化值
|
||||
//参数4:table 16位CRC查找表
|
||||
|
||||
//正序CRC计算
|
||||
quint16 QUIHelperData::getCrc16(quint8 *data, int len, quint16 init, const quint16 *table)
|
||||
{
|
||||
quint16 crc_16 = init;
|
||||
quint8 temp;
|
||||
while (len-- > 0) {
|
||||
temp = crc_16 & 0xff;
|
||||
crc_16 = (crc_16 >> 8) ^ table[(temp ^ *data++) & 0xff];
|
||||
}
|
||||
|
||||
return crc_16;
|
||||
}
|
||||
|
||||
//逆序CRC计算
|
||||
quint16 QUIHelperData::getCrc16Rec(quint8 *data, int len, quint16 init, const quint16 *table)
|
||||
{
|
||||
quint16 crc_16 = init;
|
||||
quint8 temp;
|
||||
while (len-- > 0) {
|
||||
temp = crc_16 >> 8;
|
||||
crc_16 = (crc_16 << 8) ^ table[(temp ^ *data++) & 0xff];
|
||||
}
|
||||
|
||||
return crc_16;
|
||||
}
|
||||
|
||||
//Modbus CRC16校验
|
||||
quint16 QUIHelperData::getModbus16(quint8 *data, int len)
|
||||
{
|
||||
//MODBUS CRC-16表 8005 逆序
|
||||
const quint16 table_16[256] = {
|
||||
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
|
||||
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
|
||||
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
|
||||
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
|
||||
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
|
||||
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
|
||||
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
|
||||
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
|
||||
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
|
||||
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
|
||||
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
|
||||
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
|
||||
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
|
||||
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
|
||||
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
|
||||
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
|
||||
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
|
||||
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
|
||||
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
|
||||
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
|
||||
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
|
||||
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
|
||||
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
|
||||
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
|
||||
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
|
||||
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
|
||||
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
|
||||
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
|
||||
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
|
||||
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
|
||||
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
|
||||
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
|
||||
};
|
||||
|
||||
return getCrc16(data, len, 0xFFFF, table_16);
|
||||
}
|
||||
|
||||
//CRC16校验
|
||||
QByteArray QUIHelperData::getCrcCode(const QByteArray &data)
|
||||
{
|
||||
quint16 result = getModbus16((quint8 *)data.data(), data.length());
|
||||
return QUIHelperData::ushortToByteRec(result);
|
||||
}
|
||||
|
||||
static QMap<char, QString> listChar;
|
||||
void QUIHelperData::initAscii()
|
||||
{
|
||||
//0x20为空格,空格以下都是不可见字符
|
||||
if (listChar.count() == 0) {
|
||||
listChar.insert(0, "\\NUL");
|
||||
listChar.insert(1, "\\SOH");
|
||||
listChar.insert(2, "\\STX");
|
||||
listChar.insert(3, "\\ETX");
|
||||
listChar.insert(4, "\\EOT");
|
||||
listChar.insert(5, "\\ENQ");
|
||||
listChar.insert(6, "\\ACK");
|
||||
listChar.insert(7, "\\BEL");
|
||||
listChar.insert(8, "\\BS");
|
||||
listChar.insert(9, "\\HT");
|
||||
listChar.insert(10, "\\LF");
|
||||
listChar.insert(11, "\\VT");
|
||||
listChar.insert(12, "\\FF");
|
||||
listChar.insert(13, "\\CR");
|
||||
listChar.insert(14, "\\SO");
|
||||
listChar.insert(15, "\\SI");
|
||||
listChar.insert(16, "\\DLE");
|
||||
listChar.insert(17, "\\DC1");
|
||||
listChar.insert(18, "\\DC2");
|
||||
listChar.insert(19, "\\DC3");
|
||||
listChar.insert(20, "\\DC4");
|
||||
listChar.insert(21, "\\NAK");
|
||||
listChar.insert(22, "\\SYN");
|
||||
listChar.insert(23, "\\ETB");
|
||||
listChar.insert(24, "\\CAN");
|
||||
listChar.insert(25, "\\EM");
|
||||
listChar.insert(26, "\\SUB");
|
||||
listChar.insert(27, "\\ESC");
|
||||
listChar.insert(28, "\\FS");
|
||||
listChar.insert(29, "\\GS");
|
||||
listChar.insert(30, "\\RS");
|
||||
listChar.insert(31, "\\US");
|
||||
listChar.insert(0x5C, "\\");
|
||||
listChar.insert(0x7F, "\\DEL");
|
||||
}
|
||||
}
|
||||
|
||||
QString QUIHelperData::byteArrayToAsciiStr(const QByteArray &data)
|
||||
{
|
||||
//先初始化字符表
|
||||
initAscii();
|
||||
|
||||
QString temp;
|
||||
int len = data.size();
|
||||
for (int i = 0; i < len; i++) {
|
||||
char byte = data.at(i);
|
||||
QString value = listChar.value(byte);
|
||||
if (!value.isEmpty()) {
|
||||
} else if (byte >= 0 && byte <= 0x7F) {
|
||||
value = QString("%1").arg(byte);
|
||||
} else {
|
||||
value = decimalToStrHex((quint8)byte);
|
||||
value = QString("\\x%1").arg(value.toUpper());
|
||||
}
|
||||
|
||||
temp += value;
|
||||
}
|
||||
|
||||
return temp.trimmed();
|
||||
}
|
||||
|
||||
QByteArray QUIHelperData::asciiStrToByteArray(const QString &data)
|
||||
{
|
||||
//先初始化字符表
|
||||
initAscii();
|
||||
|
||||
QByteArray buffer;
|
||||
QStringList list = data.split("\\");
|
||||
|
||||
int count = list.count();
|
||||
for (int i = 1; i < count; i++) {
|
||||
QString str = list.at(i);
|
||||
int key = 0;
|
||||
if (str.contains("x")) {
|
||||
key = strHexToDecimal(str.mid(1, 2));
|
||||
} else {
|
||||
key = listChar.key("\\" + str);
|
||||
}
|
||||
|
||||
buffer.append(key);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char QUIHelperData::hexStrToChar(char data)
|
||||
{
|
||||
if ((data >= '0') && (data <= '9')) {
|
||||
return data - 0x30;
|
||||
} else if ((data >= 'A') && (data <= 'F')) {
|
||||
return data - 'A' + 10;
|
||||
} else if ((data >= 'a') && (data <= 'f')) {
|
||||
return data - 'a' + 10;
|
||||
} else {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray QUIHelperData::hexStrToByteArray(const QString &data)
|
||||
{
|
||||
QByteArray senddata;
|
||||
int hexdata, lowhexdata;
|
||||
int hexdatalen = 0;
|
||||
int len = data.length();
|
||||
senddata.resize(len / 2);
|
||||
char lstr, hstr;
|
||||
|
||||
for (int i = 0; i < len;) {
|
||||
hstr = data.at(i).toLatin1();
|
||||
if (hstr == ' ') {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
i++;
|
||||
if (i >= len) {
|
||||
break;
|
||||
}
|
||||
|
||||
lstr = data.at(i).toLatin1();
|
||||
hexdata = hexStrToChar(hstr);
|
||||
lowhexdata = hexStrToChar(lstr);
|
||||
|
||||
if ((hexdata == 16) || (lowhexdata == 16)) {
|
||||
break;
|
||||
} else {
|
||||
hexdata = hexdata * 16 + lowhexdata;
|
||||
}
|
||||
|
||||
i++;
|
||||
senddata[hexdatalen] = (char)hexdata;
|
||||
hexdatalen++;
|
||||
}
|
||||
|
||||
senddata.resize(hexdatalen);
|
||||
return senddata;
|
||||
}
|
||||
|
||||
QString QUIHelperData::byteArrayToHexStr(const QByteArray &data)
|
||||
{
|
||||
QString temp = "";
|
||||
QString hex = data.toHex();
|
||||
for (int i = 0; i < hex.length(); i = i + 2) {
|
||||
temp += hex.mid(i, 2) + " ";
|
||||
}
|
||||
|
||||
return temp.trimmed().toUpper();
|
||||
}
|
||||
70
tool/comtool/api/quihelperdata.h
Normal file
70
tool/comtool/api/quihelperdata.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef QUIHELPERDATA_H
|
||||
#define QUIHELPERDATA_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QUIHelperData
|
||||
{
|
||||
public:
|
||||
//16进制字符串转10进制
|
||||
static int strHexToDecimal(const QString &strHex);
|
||||
//10进制字符串转10进制
|
||||
static int strDecimalToDecimal(const QString &strDecimal);
|
||||
//2进制字符串转10进制
|
||||
static int strBinToDecimal(const QString &strBin);
|
||||
|
||||
//16进制字符串转2进制字符串
|
||||
static QString strHexToStrBin(const QString &strHex);
|
||||
//10进制转2进制字符串一个字节
|
||||
static QString decimalToStrBin1(int decimal);
|
||||
//10进制转2进制字符串两个字节
|
||||
static QString decimalToStrBin2(int decimal);
|
||||
//10进制转16进制字符串,补零.
|
||||
static QString decimalToStrHex(int decimal);
|
||||
|
||||
//int转字节数组
|
||||
static QByteArray intToByte(int data);
|
||||
static QByteArray intToByteRec(int data);
|
||||
|
||||
//字节数组转int
|
||||
static int byteToInt(const QByteArray &data);
|
||||
static int byteToIntRec(const QByteArray &data);
|
||||
static quint32 byteToUInt(const QByteArray &data);
|
||||
static quint32 byteToUIntRec(const QByteArray &data);
|
||||
|
||||
//ushort转字节数组
|
||||
static QByteArray ushortToByte(ushort data);
|
||||
static QByteArray ushortToByteRec(ushort data);
|
||||
|
||||
//字节数组转ushort
|
||||
static int byteToUShort(const QByteArray &data);
|
||||
static int byteToUShortRec(const QByteArray &data);
|
||||
|
||||
//字符串补全
|
||||
static QString getValue(quint8 value);
|
||||
|
||||
//异或加密-只支持字符,如果是中文需要将其转换base64编码
|
||||
static QString getXorEncryptDecrypt(const QString &value, char key);
|
||||
//异或校验
|
||||
static uchar getOrCode(const QByteArray &data);
|
||||
//计算校验码
|
||||
static uchar getCheckCode(const QByteArray &data);
|
||||
|
||||
//CRC校验
|
||||
static quint16 getCrc16Rec(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getCrc16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getModbus16(quint8 *data, int len);
|
||||
static QByteArray getCrcCode(const QByteArray &data);
|
||||
|
||||
//字节数组与Ascii字符串互转
|
||||
static void initAscii();
|
||||
static QString byteArrayToAsciiStr(const QByteArray &data);
|
||||
static QByteArray asciiStrToByteArray(const QString &data);
|
||||
|
||||
//16进制字符串与字节数组互转
|
||||
static char hexStrToChar(char data);
|
||||
static QByteArray hexStrToByteArray(const QString &data);
|
||||
static QString byteArrayToHexStr(const QByteArray &data);
|
||||
};
|
||||
|
||||
#endif // QUIHELPERDATA_H
|
||||
23
tool/comtool/comtool.pro
Normal file
23
tool/comtool/comtool.pro
Normal file
@@ -0,0 +1,23 @@
|
||||
QT += core gui network
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
|
||||
|
||||
TARGET = comtool
|
||||
TEMPLATE = app
|
||||
DESTDIR = $$PWD/../bin
|
||||
RC_FILE = qrc/main.rc
|
||||
|
||||
HEADERS += head.h
|
||||
SOURCES += main.cpp
|
||||
RESOURCES += qrc/main.qrc
|
||||
CONFIG += warn_off
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += $$PWD/api
|
||||
INCLUDEPATH += $$PWD/form
|
||||
|
||||
include ($$PWD/api/api.pri)
|
||||
include ($$PWD/form/form.pri)
|
||||
|
||||
INCLUDEPATH += $$PWD/../3rd_qextserialport
|
||||
include ($$PWD/../3rd_qextserialport/3rd_qextserialport.pri)
|
||||
1
tool/comtool/file/device.txt
Normal file
1
tool/comtool/file/device.txt
Normal file
@@ -0,0 +1 @@
|
||||
01 03 00 00 00 06 C5 C8;01 03 0C 00 01 00 01 00 00 00 01 00 01 00 01 37 DC
|
||||
17
tool/comtool/file/send.txt
Normal file
17
tool/comtool/file/send.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
16 FF 01 01 E0 E1
|
||||
16 FF 01 01 E1 E2
|
||||
16 01 02 DF BC 16 01 02 DF BC 16 01 02 DF BC 12 13 14 15
|
||||
16 00 00 04 D0 F0 F1 65 C4
|
||||
16 00 00 04 D0 05 AB 5A C4
|
||||
16 01 10 02 F0 03 06 16 01 11 02 F0 03 06 16 01 12 02 F0 03 06 16 01 13 02 F0 03 06 16 01
|
||||
14 02 F0 03 06 16 01 15 02 F0 03 06 16 01 16 02 F0 03 06
|
||||
16 11 01 03 E8 01 10 0E
|
||||
16 11 01 03 E8 01 12 10
|
||||
16 11 01 03 E8 01 14 12
|
||||
16 11 01 03 E8 01 15 13
|
||||
DISARMEDALL
|
||||
BURGLARY 012
|
||||
BYPASS 012
|
||||
DISARMED 012
|
||||
16 00 01 01 D1 D3
|
||||
16 01 11 11
|
||||
8
tool/comtool/form/form.pri
Normal file
8
tool/comtool/form/form.pri
Normal file
@@ -0,0 +1,8 @@
|
||||
FORMS += \
|
||||
$$PWD/frmcomtool.ui
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/frmcomtool.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/frmcomtool.cpp
|
||||
588
tool/comtool/form/frmcomtool.cpp
Normal file
588
tool/comtool/form/frmcomtool.cpp
Normal file
@@ -0,0 +1,588 @@
|
||||
#include "frmcomtool.h"
|
||||
#include "ui_frmcomtool.h"
|
||||
#include "quihelper.h"
|
||||
#include "quihelperdata.h"
|
||||
|
||||
frmComTool::frmComTool(QWidget *parent) : QWidget(parent), ui(new Ui::frmComTool)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
this->initConfig();
|
||||
QUIHelper::setFormInCenter(this);
|
||||
}
|
||||
|
||||
frmComTool::~frmComTool()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void frmComTool::initForm()
|
||||
{
|
||||
comOk = false;
|
||||
com = 0;
|
||||
sleepTime = 10;
|
||||
receiveCount = 0;
|
||||
sendCount = 0;
|
||||
isShow = true;
|
||||
|
||||
ui->cboxSendInterval->addItems(AppData::Intervals);
|
||||
ui->cboxData->addItems(AppData::Datas);
|
||||
|
||||
//读取数据
|
||||
timerRead = new QTimer(this);
|
||||
timerRead->setInterval(100);
|
||||
connect(timerRead, SIGNAL(timeout()), this, SLOT(readData()));
|
||||
|
||||
//发送数据
|
||||
timerSend = new QTimer(this);
|
||||
connect(timerSend, SIGNAL(timeout()), this, SLOT(sendData()));
|
||||
connect(ui->btnSend, SIGNAL(clicked()), this, SLOT(sendData()));
|
||||
|
||||
//保存数据
|
||||
timerSave = new QTimer(this);
|
||||
connect(timerSave, SIGNAL(timeout()), this, SLOT(saveData()));
|
||||
connect(ui->btnSave, SIGNAL(clicked()), this, SLOT(saveData()));
|
||||
|
||||
ui->tabWidget->setCurrentIndex(0);
|
||||
changeEnable(false);
|
||||
|
||||
tcpOk = false;
|
||||
socket = new QTcpSocket(this);
|
||||
socket->abort();
|
||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readDataNet()));
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(readErrorNet()));
|
||||
#else
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(readErrorNet()));
|
||||
#endif
|
||||
|
||||
timerConnect = new QTimer(this);
|
||||
connect(timerConnect, SIGNAL(timeout()), this, SLOT(connectNet()));
|
||||
timerConnect->setInterval(3000);
|
||||
timerConnect->start();
|
||||
|
||||
#ifdef __arm__
|
||||
ui->widgetRight->setFixedWidth(280);
|
||||
#endif
|
||||
}
|
||||
|
||||
void frmComTool::initConfig()
|
||||
{
|
||||
QStringList comList;
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
comList << QString("COM%1").arg(i);
|
||||
}
|
||||
|
||||
comList << "ttyUSB0" << "ttyS0" << "ttyS1" << "ttyS2" << "ttyS3" << "ttyS4";
|
||||
comList << "ttymxc1" << "ttymxc2" << "ttymxc3" << "ttymxc4";
|
||||
comList << "ttySAC1" << "ttySAC2" << "ttySAC3" << "ttySAC4";
|
||||
ui->cboxPortName->addItems(comList);
|
||||
ui->cboxPortName->setCurrentIndex(ui->cboxPortName->findText(AppConfig::PortName));
|
||||
connect(ui->cboxPortName, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
QStringList baudList;
|
||||
baudList << "50" << "75" << "100" << "134" << "150" << "200" << "300" << "600" << "1200"
|
||||
<< "1800" << "2400" << "4800" << "9600" << "14400" << "19200" << "38400"
|
||||
<< "56000" << "57600" << "76800" << "115200" << "128000" << "256000";
|
||||
|
||||
ui->cboxBaudRate->addItems(baudList);
|
||||
ui->cboxBaudRate->setCurrentIndex(ui->cboxBaudRate->findText(QString::number(AppConfig::BaudRate)));
|
||||
connect(ui->cboxBaudRate, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
QStringList dataBitsList;
|
||||
dataBitsList << "5" << "6" << "7" << "8";
|
||||
|
||||
ui->cboxDataBit->addItems(dataBitsList);
|
||||
ui->cboxDataBit->setCurrentIndex(ui->cboxDataBit->findText(QString::number(AppConfig::DataBit)));
|
||||
connect(ui->cboxDataBit, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
QStringList parityList;
|
||||
parityList << "无" << "奇" << "偶";
|
||||
#ifdef Q_OS_WIN
|
||||
parityList << "标志";
|
||||
#endif
|
||||
parityList << "空格";
|
||||
|
||||
ui->cboxParity->addItems(parityList);
|
||||
ui->cboxParity->setCurrentIndex(ui->cboxParity->findText(AppConfig::Parity));
|
||||
connect(ui->cboxParity, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
QStringList stopBitsList;
|
||||
stopBitsList << "1";
|
||||
#ifdef Q_OS_WIN
|
||||
stopBitsList << "1.5";
|
||||
#endif
|
||||
stopBitsList << "2";
|
||||
|
||||
ui->cboxStopBit->addItems(stopBitsList);
|
||||
ui->cboxStopBit->setCurrentIndex(ui->cboxStopBit->findText(QString::number(AppConfig::StopBit)));
|
||||
connect(ui->cboxStopBit, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckHexSend->setChecked(AppConfig::HexSend);
|
||||
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckHexReceive->setChecked(AppConfig::HexReceive);
|
||||
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckDebug->setChecked(AppConfig::Debug);
|
||||
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAutoClear->setChecked(AppConfig::AutoClear);
|
||||
connect(ui->ckAutoClear, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAutoSend->setChecked(AppConfig::AutoSend);
|
||||
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAutoSave->setChecked(AppConfig::AutoSave);
|
||||
connect(ui->ckAutoSave, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
QStringList sendInterval;
|
||||
QStringList saveInterval;
|
||||
sendInterval << "100" << "300" << "500";
|
||||
|
||||
for (int i = 1000; i <= 10000; i = i + 1000) {
|
||||
sendInterval << QString::number(i);
|
||||
saveInterval << QString::number(i);
|
||||
}
|
||||
|
||||
ui->cboxSendInterval->addItems(sendInterval);
|
||||
ui->cboxSaveInterval->addItems(saveInterval);
|
||||
|
||||
ui->cboxSendInterval->setCurrentIndex(ui->cboxSendInterval->findText(QString::number(AppConfig::SendInterval)));
|
||||
connect(ui->cboxSendInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
ui->cboxSaveInterval->setCurrentIndex(ui->cboxSaveInterval->findText(QString::number(AppConfig::SaveInterval)));
|
||||
connect(ui->cboxSaveInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
timerSend->setInterval(AppConfig::SendInterval);
|
||||
timerSave->setInterval(AppConfig::SaveInterval);
|
||||
|
||||
if (AppConfig::AutoSend) {
|
||||
timerSend->start();
|
||||
}
|
||||
|
||||
if (AppConfig::AutoSave) {
|
||||
timerSave->start();
|
||||
}
|
||||
|
||||
//串口转网络部分
|
||||
ui->cboxMode->setCurrentIndex(ui->cboxMode->findText(AppConfig::Mode));
|
||||
connect(ui->cboxMode, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerIP->setText(AppConfig::ServerIP);
|
||||
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerPort->setText(QString::number(AppConfig::ServerPort));
|
||||
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtListenPort->setText(QString::number(AppConfig::ListenPort));
|
||||
connect(ui->txtListenPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
QStringList values;
|
||||
values << "0" << "10" << "50";
|
||||
|
||||
for (int i = 100; i < 1000; i = i + 100) {
|
||||
values << QString("%1").arg(i);
|
||||
}
|
||||
|
||||
ui->cboxSleepTime->addItems(values);
|
||||
|
||||
ui->cboxSleepTime->setCurrentIndex(ui->cboxSleepTime->findText(QString::number(AppConfig::SleepTime)));
|
||||
connect(ui->cboxSleepTime, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAutoConnect->setChecked(AppConfig::AutoConnect);
|
||||
connect(ui->ckAutoConnect, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
}
|
||||
|
||||
void frmComTool::saveConfig()
|
||||
{
|
||||
AppConfig::PortName = ui->cboxPortName->currentText();
|
||||
AppConfig::BaudRate = ui->cboxBaudRate->currentText().toInt();
|
||||
AppConfig::DataBit = ui->cboxDataBit->currentText().toInt();
|
||||
AppConfig::Parity = ui->cboxParity->currentText();
|
||||
AppConfig::StopBit = ui->cboxStopBit->currentText().toDouble();
|
||||
|
||||
AppConfig::HexSend = ui->ckHexSend->isChecked();
|
||||
AppConfig::HexReceive = ui->ckHexReceive->isChecked();
|
||||
AppConfig::Debug = ui->ckDebug->isChecked();
|
||||
AppConfig::AutoClear = ui->ckAutoClear->isChecked();
|
||||
|
||||
AppConfig::AutoSend = ui->ckAutoSend->isChecked();
|
||||
AppConfig::AutoSave = ui->ckAutoSave->isChecked();
|
||||
|
||||
int sendInterval = ui->cboxSendInterval->currentText().toInt();
|
||||
if (sendInterval != AppConfig::SendInterval) {
|
||||
AppConfig::SendInterval = sendInterval;
|
||||
timerSend->setInterval(AppConfig::SendInterval);
|
||||
}
|
||||
|
||||
int saveInterval = ui->cboxSaveInterval->currentText().toInt();
|
||||
if (saveInterval != AppConfig::SaveInterval) {
|
||||
AppConfig::SaveInterval = saveInterval;
|
||||
timerSave->setInterval(AppConfig::SaveInterval);
|
||||
}
|
||||
|
||||
AppConfig::Mode = ui->cboxMode->currentText();
|
||||
AppConfig::ServerIP = ui->txtServerIP->text().trimmed();
|
||||
AppConfig::ServerPort = ui->txtServerPort->text().toInt();
|
||||
AppConfig::ListenPort = ui->txtListenPort->text().toInt();
|
||||
AppConfig::SleepTime = ui->cboxSleepTime->currentText().toInt();
|
||||
AppConfig::AutoConnect = ui->ckAutoConnect->isChecked();
|
||||
|
||||
AppConfig::writeConfig();
|
||||
}
|
||||
|
||||
void frmComTool::changeEnable(bool b)
|
||||
{
|
||||
ui->cboxBaudRate->setEnabled(!b);
|
||||
ui->cboxDataBit->setEnabled(!b);
|
||||
ui->cboxParity->setEnabled(!b);
|
||||
ui->cboxPortName->setEnabled(!b);
|
||||
ui->cboxStopBit->setEnabled(!b);
|
||||
ui->btnSend->setEnabled(b);
|
||||
ui->ckAutoSend->setEnabled(b);
|
||||
ui->ckAutoSave->setEnabled(b);
|
||||
}
|
||||
|
||||
void frmComTool::append(int type, const QString &data, bool clear)
|
||||
{
|
||||
static int currentCount = 0;
|
||||
static int maxCount = 100;
|
||||
|
||||
if (clear) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentCount >= maxCount) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
}
|
||||
|
||||
if (!isShow) {
|
||||
return;
|
||||
}
|
||||
|
||||
//过滤回车换行符
|
||||
QString strData = data;
|
||||
strData = strData.replace("\r", "");
|
||||
strData = strData.replace("\n", "");
|
||||
|
||||
//不同类型不同颜色显示
|
||||
QString strType;
|
||||
if (type == 0) {
|
||||
strType = "串口发送 >>";
|
||||
ui->txtMain->setTextColor(QColor("dodgerblue"));
|
||||
} else if (type == 1) {
|
||||
strType = "串口接收 <<";
|
||||
ui->txtMain->setTextColor(QColor("red"));
|
||||
} else if (type == 2) {
|
||||
strType = "处理延时 >>";
|
||||
ui->txtMain->setTextColor(QColor("gray"));
|
||||
} else if (type == 3) {
|
||||
strType = "正在校验 >>";
|
||||
ui->txtMain->setTextColor(QColor("green"));
|
||||
} else if (type == 4) {
|
||||
strType = "网络发送 >>";
|
||||
ui->txtMain->setTextColor(QColor(24, 189, 155));
|
||||
} else if (type == 5) {
|
||||
strType = "网络接收 <<";
|
||||
ui->txtMain->setTextColor(QColor(255, 107, 107));
|
||||
} else if (type == 6) {
|
||||
strType = "提示信息 >>";
|
||||
ui->txtMain->setTextColor(QColor(100, 184, 255));
|
||||
}
|
||||
|
||||
strData = QString("时间[%1] %2 %3").arg(TIMEMS).arg(strType).arg(strData);
|
||||
ui->txtMain->append(strData);
|
||||
currentCount++;
|
||||
}
|
||||
|
||||
void frmComTool::readData()
|
||||
{
|
||||
if (com->bytesAvailable() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QUIHelper::sleep(sleepTime);
|
||||
QByteArray data = com->readAll();
|
||||
int dataLen = data.length();
|
||||
if (dataLen <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isShow) {
|
||||
QString buffer;
|
||||
if (ui->ckHexReceive->isChecked()) {
|
||||
buffer = QUIHelperData::byteArrayToHexStr(data);
|
||||
} else {
|
||||
//buffer = QUIHelperData::byteArrayToAsciiStr(data);
|
||||
buffer = QString::fromLocal8Bit(data);
|
||||
}
|
||||
|
||||
//启用调试则模拟调试数据
|
||||
if (ui->ckDebug->isChecked()) {
|
||||
int count = AppData::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (buffer.startsWith(AppData::Keys.at(i))) {
|
||||
sendData(AppData::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
append(1, buffer);
|
||||
receiveCount = receiveCount + data.size();
|
||||
ui->btnReceiveCount->setText(QString("接收 : %1 字节").arg(receiveCount));
|
||||
|
||||
//启用网络转发则调用网络发送数据
|
||||
if (tcpOk) {
|
||||
socket->write(data);
|
||||
append(4, QString(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::sendData()
|
||||
{
|
||||
QString str = ui->cboxData->currentText();
|
||||
if (str.isEmpty()) {
|
||||
ui->cboxData->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
sendData(str);
|
||||
|
||||
if (ui->ckAutoClear->isChecked()) {
|
||||
ui->cboxData->setCurrentIndex(-1);
|
||||
ui->cboxData->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::sendData(QString data)
|
||||
{
|
||||
if (com == 0 || !com->isOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//短信猫调试
|
||||
if (data.startsWith("AT")) {
|
||||
data += "\r";
|
||||
}
|
||||
|
||||
QByteArray buffer;
|
||||
if (ui->ckHexSend->isChecked()) {
|
||||
buffer = QUIHelperData::hexStrToByteArray(data);
|
||||
} else {
|
||||
buffer = QUIHelperData::asciiStrToByteArray(data);
|
||||
}
|
||||
|
||||
com->write(buffer);
|
||||
append(0, data);
|
||||
sendCount = sendCount + buffer.size();
|
||||
ui->btnSendCount->setText(QString("发送 : %1 字节").arg(sendCount));
|
||||
}
|
||||
|
||||
void frmComTool::saveData()
|
||||
{
|
||||
QString tempData = ui->txtMain->toPlainText();
|
||||
|
||||
if (tempData == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QString name = now.toString("yyyy-MM-dd-HH-mm-ss");
|
||||
QString fileName = QString("%1/%2.txt").arg(QUIHelper::appPath()).arg(name);
|
||||
|
||||
QFile file(fileName);
|
||||
file.open(QFile::WriteOnly | QIODevice::Text);
|
||||
QTextStream out(&file);
|
||||
out << tempData;
|
||||
file.close();
|
||||
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
void frmComTool::on_btnOpen_clicked()
|
||||
{
|
||||
if (ui->btnOpen->text() == "打开串口") {
|
||||
com = new QextSerialPort(ui->cboxPortName->currentText(), QextSerialPort::Polling);
|
||||
comOk = com->open(QIODevice::ReadWrite);
|
||||
|
||||
if (comOk) {
|
||||
//清空缓冲区
|
||||
com->flush();
|
||||
//设置波特率
|
||||
com->setBaudRate((BaudRateType)ui->cboxBaudRate->currentText().toInt());
|
||||
//设置数据位
|
||||
com->setDataBits((DataBitsType)ui->cboxDataBit->currentText().toInt());
|
||||
//设置校验位
|
||||
com->setParity((ParityType)ui->cboxParity->currentIndex());
|
||||
//设置停止位
|
||||
com->setStopBits((StopBitsType)ui->cboxStopBit->currentIndex());
|
||||
com->setFlowControl(FLOW_OFF);
|
||||
com->setTimeout(10);
|
||||
|
||||
changeEnable(true);
|
||||
ui->btnOpen->setText("关闭串口");
|
||||
timerRead->start();
|
||||
}
|
||||
} else {
|
||||
timerRead->stop();
|
||||
com->close();
|
||||
com->deleteLater();
|
||||
|
||||
changeEnable(false);
|
||||
ui->btnOpen->setText("打开串口");
|
||||
on_btnClear_clicked();
|
||||
comOk = false;
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::on_btnSendCount_clicked()
|
||||
{
|
||||
sendCount = 0;
|
||||
ui->btnSendCount->setText("发送 : 0 字节");
|
||||
}
|
||||
|
||||
void frmComTool::on_btnReceiveCount_clicked()
|
||||
{
|
||||
receiveCount = 0;
|
||||
ui->btnReceiveCount->setText("接收 : 0 字节");
|
||||
}
|
||||
|
||||
void frmComTool::on_btnStopShow_clicked()
|
||||
{
|
||||
if (ui->btnStopShow->text() == "停止显示") {
|
||||
isShow = false;
|
||||
ui->btnStopShow->setText("开始显示");
|
||||
} else {
|
||||
isShow = true;
|
||||
ui->btnStopShow->setText("停止显示");
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::on_btnData_clicked()
|
||||
{
|
||||
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg("send.txt");
|
||||
QFile file(fileName);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ui->btnData->text() == "管理数据") {
|
||||
ui->txtMain->setReadOnly(false);
|
||||
ui->txtMain->clear();
|
||||
file.open(QFile::ReadOnly | QIODevice::Text);
|
||||
QTextStream in(&file);
|
||||
ui->txtMain->setText(in.readAll());
|
||||
file.close();
|
||||
ui->btnData->setText("保存数据");
|
||||
} else {
|
||||
ui->txtMain->setReadOnly(true);
|
||||
file.open(QFile::WriteOnly | QIODevice::Text);
|
||||
QTextStream out(&file);
|
||||
out << ui->txtMain->toPlainText();
|
||||
file.close();
|
||||
ui->txtMain->clear();
|
||||
ui->btnData->setText("管理数据");
|
||||
AppData::readSendData();
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::on_btnClear_clicked()
|
||||
{
|
||||
append(0, "", true);
|
||||
}
|
||||
|
||||
void frmComTool::on_btnStart_clicked()
|
||||
{
|
||||
if (ui->btnStart->text() == "启动") {
|
||||
if (AppConfig::ServerIP == "" || AppConfig::ServerPort == 0) {
|
||||
append(6, "IP地址和远程端口不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
socket->connectToHost(AppConfig::ServerIP, AppConfig::ServerPort);
|
||||
if (socket->waitForConnected(100)) {
|
||||
ui->btnStart->setText("停止");
|
||||
append(6, "连接服务器成功");
|
||||
tcpOk = true;
|
||||
}
|
||||
} else {
|
||||
socket->disconnectFromHost();
|
||||
if (socket->state() == QAbstractSocket::UnconnectedState || socket->waitForDisconnected(100)) {
|
||||
ui->btnStart->setText("启动");
|
||||
append(6, "断开服务器成功");
|
||||
tcpOk = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::on_ckAutoSend_stateChanged(int arg1)
|
||||
{
|
||||
if (arg1 == 0) {
|
||||
ui->cboxSendInterval->setEnabled(false);
|
||||
timerSend->stop();
|
||||
} else {
|
||||
ui->cboxSendInterval->setEnabled(true);
|
||||
timerSend->start();
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::on_ckAutoSave_stateChanged(int arg1)
|
||||
{
|
||||
if (arg1 == 0) {
|
||||
ui->cboxSaveInterval->setEnabled(false);
|
||||
timerSave->stop();
|
||||
} else {
|
||||
ui->cboxSaveInterval->setEnabled(true);
|
||||
timerSave->start();
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::connectNet()
|
||||
{
|
||||
if (!tcpOk && AppConfig::AutoConnect && ui->btnStart->text() == "启动") {
|
||||
if (AppConfig::ServerIP != "" && AppConfig::ServerPort != 0) {
|
||||
socket->connectToHost(AppConfig::ServerIP, AppConfig::ServerPort);
|
||||
if (socket->waitForConnected(100)) {
|
||||
ui->btnStart->setText("停止");
|
||||
append(6, "连接服务器成功");
|
||||
tcpOk = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::readDataNet()
|
||||
{
|
||||
if (socket->bytesAvailable() > 0) {
|
||||
QUIHelper::sleep(AppConfig::SleepTime);
|
||||
QByteArray data = socket->readAll();
|
||||
|
||||
QString buffer;
|
||||
if (ui->ckHexReceive->isChecked()) {
|
||||
buffer = QUIHelperData::byteArrayToHexStr(data);
|
||||
} else {
|
||||
buffer = QUIHelperData::byteArrayToAsciiStr(data);
|
||||
}
|
||||
|
||||
append(5, buffer);
|
||||
|
||||
//将收到的网络数据转发给串口
|
||||
if (comOk) {
|
||||
com->write(data);
|
||||
append(0, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmComTool::readErrorNet()
|
||||
{
|
||||
ui->btnStart->setText("启动");
|
||||
append(6, QString("连接服务器失败,%1").arg(socket->errorString()));
|
||||
socket->disconnectFromHost();
|
||||
tcpOk = false;
|
||||
}
|
||||
68
tool/comtool/form/frmcomtool.h
Normal file
68
tool/comtool/form/frmcomtool.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef FRMCOMTOOL_H
|
||||
#define FRMCOMTOOL_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qtcpsocket.h"
|
||||
#include "qextserialport.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class frmComTool;
|
||||
}
|
||||
|
||||
class frmComTool : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmComTool(QWidget *parent = 0);
|
||||
~frmComTool();
|
||||
|
||||
private:
|
||||
Ui::frmComTool *ui;
|
||||
|
||||
bool comOk; //串口是否打开
|
||||
QextSerialPort *com; //串口通信对象
|
||||
QTimer *timerRead; //定时读取串口数据
|
||||
QTimer *timerSend; //定时发送串口数据
|
||||
QTimer *timerSave; //定时保存串口数据
|
||||
|
||||
int sleepTime; //接收延时时间
|
||||
int sendCount; //发送数据计数
|
||||
int receiveCount; //接收数据计数
|
||||
bool isShow; //是否显示数据
|
||||
|
||||
bool tcpOk; //网络是否正常
|
||||
QTcpSocket *socket; //网络连接对象
|
||||
QTimer *timerConnect; //定时器重连
|
||||
|
||||
private slots:
|
||||
void initForm(); //初始化窗体数据
|
||||
void initConfig(); //初始化配置文件
|
||||
void saveConfig(); //保存配置文件
|
||||
void readData(); //读取串口数据
|
||||
void sendData(); //发送串口数据
|
||||
void sendData(QString data);//发送串口数据带参数
|
||||
void saveData(); //保存串口数据
|
||||
|
||||
void changeEnable(bool b); //改变状态
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
void connectNet();
|
||||
void readDataNet();
|
||||
void readErrorNet();
|
||||
|
||||
private slots:
|
||||
void on_btnOpen_clicked();
|
||||
void on_btnStopShow_clicked();
|
||||
void on_btnSendCount_clicked();
|
||||
void on_btnReceiveCount_clicked();
|
||||
void on_btnClear_clicked();
|
||||
void on_btnData_clicked();
|
||||
void on_btnStart_clicked();
|
||||
void on_ckAutoSend_stateChanged(int arg1);
|
||||
void on_ckAutoSave_stateChanged(int arg1);
|
||||
};
|
||||
|
||||
#endif // FRMCOMTOOL_H
|
||||
533
tool/comtool/form/frmcomtool.ui
Normal file
533
tool/comtool/form/frmcomtool.ui
Normal file
@@ -0,0 +1,533 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmComTool</class>
|
||||
<widget class="QWidget" name="frmComTool">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="txtMain">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="QWidget" name="widgetRight" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="frameTop">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labPortName">
|
||||
<property name="text">
|
||||
<string>串口号</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="cboxPortName">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labBaudRate">
|
||||
<property name="text">
|
||||
<string>波特率</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cboxBaudRate">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labDataBit">
|
||||
<property name="text">
|
||||
<string>数据位</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="cboxDataBit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labParity">
|
||||
<property name="text">
|
||||
<string>校验位</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="cboxParity">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="labStopBit">
|
||||
<property name="text">
|
||||
<string>停止位</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="cboxStopBit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnOpen">
|
||||
<property name="text">
|
||||
<string>打开串口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::South</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>串口配置</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="ckHexSend">
|
||||
<property name="text">
|
||||
<string>Hex发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="ckHexReceive">
|
||||
<property name="text">
|
||||
<string>Hex接收</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="ckDebug">
|
||||
<property name="text">
|
||||
<string>模拟设备</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="ckAutoClear">
|
||||
<property name="text">
|
||||
<string>自动清空</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="ckAutoSend">
|
||||
<property name="text">
|
||||
<string>自动发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="cboxSendInterval">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="ckAutoSave">
|
||||
<property name="text">
|
||||
<string>自动保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cboxSaveInterval">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnSendCount">
|
||||
<property name="text">
|
||||
<string>发送 : 0 字节</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnReceiveCount">
|
||||
<property name="text">
|
||||
<string>接收 : 0 字节</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnStopShow">
|
||||
<property name="text">
|
||||
<string>停止显示</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnSave">
|
||||
<property name="text">
|
||||
<string>保存数据</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnData">
|
||||
<property name="text">
|
||||
<string>管理数据</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnClear">
|
||||
<property name="text">
|
||||
<string>清空数据</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>2</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>网络配置</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labListenPort">
|
||||
<property name="text">
|
||||
<string>监听端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labServerIP">
|
||||
<property name="text">
|
||||
<string>远程地址</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="cboxSleepTime"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="txtServerIP">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labServerPort">
|
||||
<property name="text">
|
||||
<string>远程端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="txtServerPort">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="labSleepTime">
|
||||
<property name="text">
|
||||
<string>延时时间</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="txtListenPort"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labMode">
|
||||
<property name="text">
|
||||
<string>转换模式</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="cboxMode">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Tcp_Client</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Tcp_Server</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Udp_Client</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Udp_Server</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="btnStart">
|
||||
<property name="text">
|
||||
<string>启动</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>59</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="ckAutoConnect">
|
||||
<property name="text">
|
||||
<string>自动重连网络</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxData">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="duplicatesEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSend">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
18
tool/comtool/head.h
Normal file
18
tool/comtool/head.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#include <QtNetwork>
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
||||
#include <QtWidgets>
|
||||
#endif
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
#include <QtCore5Compat>
|
||||
#endif
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||
#define STRDATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
|
||||
|
||||
#include "appconfig.h"
|
||||
#include "appdata.h"
|
||||
26
tool/comtool/main.cpp
Normal file
26
tool/comtool/main.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "frmcomtool.h"
|
||||
#include "quihelper.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setWindowIcon(QIcon(":/main.ico"));
|
||||
|
||||
//设置编码以及加载中文翻译文件
|
||||
QUIHelper::initAll();
|
||||
//读取配置文件
|
||||
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||
AppConfig::readConfig();
|
||||
|
||||
AppData::Intervals << "1" << "10" << "20" << "50" << "100" << "200" << "300" << "500" << "1000" << "1500" << "2000" << "3000" << "5000" << "10000";
|
||||
AppData::readSendData();
|
||||
AppData::readDeviceData();
|
||||
|
||||
frmComTool w;
|
||||
w.setWindowTitle("串口调试助手 V2022 (QQ: 517216493 WX: feiyangqingyun)");
|
||||
w.resize(900, 650);
|
||||
QUIHelper::setFormInCenter(&w);
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
BIN
tool/comtool/qrc/main.ico
Normal file
BIN
tool/comtool/qrc/main.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
7
tool/comtool/qrc/main.qrc
Normal file
7
tool/comtool/qrc/main.qrc
Normal file
@@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.ico</file>
|
||||
<file>qm/qt_zh_CN.qm</file>
|
||||
<file>qm/widgets.qm</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
1
tool/comtool/qrc/main.rc
Normal file
1
tool/comtool/qrc/main.rc
Normal file
@@ -0,0 +1 @@
|
||||
IDI_ICON1 ICON DISCARDABLE "main.ico"
|
||||
BIN
tool/comtool/qrc/qm/qt_zh_CN.qm
Normal file
BIN
tool/comtool/qrc/qm/qt_zh_CN.qm
Normal file
Binary file not shown.
BIN
tool/comtool/qrc/qm/widgets.qm
Normal file
BIN
tool/comtool/qrc/qm/widgets.qm
Normal file
Binary file not shown.
18
tool/comtool/readme.md
Normal file
18
tool/comtool/readme.md
Normal file
@@ -0,0 +1,18 @@
|
||||
**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
|
||||
1. ֧<><D6A7>16<31><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ա<EFBFBD>
|
||||
2. ֧<><D6A7>windows<77><73>COM9<4D><39><EFBFBD>ϵĴ<CFB5><C4B4><EFBFBD>ͨ<EFBFBD>š<EFBFBD>
|
||||
3. ʵʱ<CAB5><CAB1>ʾ<EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڴ<D6BD>С<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>
|
||||
4. ֧<><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>qt<71>汾<EFBFBD><E6B1BE><EFBFBD>ײ<EFBFBD>4.7.0 <20><> 6.1<EFBFBD><EFBFBD>
|
||||
5. ֧<>ִ<EFBFBD><D6B4><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><D5B7><EFBFBD>
|
||||
|
||||
**<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
|
||||
1. <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݣ<EFBFBD>ÿ<EFBFBD><C3BF>ֻҪ<D6BB><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
||||
2. <20><>ģ<EFBFBD><C4A3><EFBFBD>豸<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>濪<EFBFBD><E6BFAA>ģ<EFBFBD><C4A3><EFBFBD>豸<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>ݡ<EFBFBD><DDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>úõ<C3BA>ָ<EFBFBD><D6B8>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>õĻظ<C4BB>ָ<EFBFBD><EFBFBD><EEA1A3><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>յ<EFBFBD>0x16 0x00 0xFF 0x01<30><31>Ҫ<EFBFBD>ظ<EFBFBD>0x16 0x00 0xFE 0x01<30><31><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD><D2AA>SendData.txt<78><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16 00 FF 01:16 00 FE 01<30><31><EFBFBD>ɡ<EFBFBD>
|
||||
3. <20>ɶ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺͱ<DDBA><CDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ı<EFBFBD><C4B1>ļ<EFBFBD>:<3A><>Ĭ<EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>5<EFBFBD><35><EFBFBD>ӣ<EFBFBD><D3A3>ɸ<EFBFBD><C9B8>ļ<EFBFBD><C4BC><EFBFBD>ʱ<EFBFBD>䡣
|
||||
4. <20>ڲ<EFBFBD><DAB2>Ͻ<EFBFBD><CFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鿴<EFBFBD><E9BFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>̨<EFBFBD><CCA8>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رմ<D8B1><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鿴<EFBFBD>ѽ<EFBFBD><D1BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
||||
5. ÿ<><C3BF><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѽڵģ<DAB5><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
6. һ<><D2BB>Դ<EFBFBD><D4B4><EFBFBD>洦<EFBFBD><E6B4A6><EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>࣬<EFBFBD><E0A3AC><EFBFBD><EFBFBD>XP/WIN7/UBUNTU/ARMLINUXϵͳ<CFB5>³ɹ<C2B3><C9B9><EFBFBD><EFBFBD>벢<EFBFBD><EBB2A2><EFBFBD>С<EFBFBD>
|
||||
|
||||
**<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD>**
|
||||
1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뽫Դ<EBBDAB><D4B4><EFBFBD>µ<EFBFBD>fileĿ¼<C4BF>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>ļ<EFBFBD>ͬһĿ¼<C4BF><C2BC>
|
||||
2. <20><><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8>õĽ<C3B5><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>лл<D0BB><D0BB>
|
||||
Reference in New Issue
Block a user