This commit is contained in:
parent
a0d38bd0a3
commit
41cbba1759
|
|
@ -0,0 +1,106 @@
|
||||||
|
cmake_minimum_required(VERSION 3.25)
|
||||||
|
set(PROJECT_NAME Train_RFID)
|
||||||
|
project(${PROJECT_NAME} VERSION 1.0 DESCRIPTION "火车车号识别 RFID版")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
|
set(CMAKE_PREFIX_PATH "D:/Qt/5.15.2/mingw81_64")
|
||||||
|
|
||||||
|
link_libraries(ws2_32 wsock32)
|
||||||
|
|
||||||
|
find_package(Qt5 COMPONENTS
|
||||||
|
Core
|
||||||
|
Gui
|
||||||
|
Widgets
|
||||||
|
Network
|
||||||
|
SerialPort
|
||||||
|
REQUIRED)
|
||||||
|
|
||||||
|
#导入Qt的Network配置和在pro文件里面添加QT+=network是一样的
|
||||||
|
#find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Network SerialPort )
|
||||||
|
#find_package(Qt${QT_VERSION_MAJOR} REQUIRED Network COMPONENTS Core)
|
||||||
|
#find_package(Qt5Core COMPONENTS Qt5SerialPort REQUIRED)
|
||||||
|
|
||||||
|
#moc编译在这里进行,请把含有Q_OBJECT宏定义的头文件放到这里来
|
||||||
|
QT5_WRAP_CPP(MOC_Files
|
||||||
|
${PROJECT_SOURCE_DIR}/source/mainwindow.h
|
||||||
|
${PROJECT_SOURCE_DIR}/interface/TcpClient.h
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${PROJECT_SOURCE_DIR}/common
|
||||||
|
# source source
|
||||||
|
${PROJECT_SOURCE_DIR}/source
|
||||||
|
# json库
|
||||||
|
${PROJECT_SOURCE_DIR}/util/json
|
||||||
|
# http库
|
||||||
|
${PROJECT_SOURCE_DIR}/util/http
|
||||||
|
# com口工具
|
||||||
|
${PROJECT_SOURCE_DIR}/util/comPort
|
||||||
|
# interface
|
||||||
|
${PROJECT_SOURCE_DIR}/interface
|
||||||
|
)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE COMMON_SRCS_LISTS
|
||||||
|
# UI
|
||||||
|
${PROJECT_SOURCE_DIR}/source/mainwindow.ui
|
||||||
|
# 公共数据
|
||||||
|
${PROJECT_SOURCE_DIR}/common/common.cpp
|
||||||
|
# source source
|
||||||
|
${PROJECT_SOURCE_DIR}/source/mainwindow.cpp
|
||||||
|
# JSON库
|
||||||
|
${PROJECT_SOURCE_DIR}/util/json/jsoncpp.cpp
|
||||||
|
# http库
|
||||||
|
${PROJECT_SOURCE_DIR}/util/http/httplib.cc
|
||||||
|
# com口工具
|
||||||
|
${PROJECT_SOURCE_DIR}/util/comPort/ComPortTool.cpp
|
||||||
|
# interface
|
||||||
|
${PROJECT_SOURCE_DIR}/interface/TcpClient.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(Train_RFID
|
||||||
|
main.cpp
|
||||||
|
${COMMON_SRCS_LISTS}
|
||||||
|
${MOC_Files}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(Train_RFID
|
||||||
|
-pthread
|
||||||
|
Qt5::Core
|
||||||
|
Qt5::Gui
|
||||||
|
Qt5::Widgets
|
||||||
|
Qt5::Network
|
||||||
|
Qt5::SerialPort
|
||||||
|
)
|
||||||
|
|
||||||
|
if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||||
|
set(DEBUG_SUFFIX)
|
||||||
|
if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||||
|
set(DEBUG_SUFFIX "d")
|
||||||
|
endif ()
|
||||||
|
set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
|
||||||
|
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
|
||||||
|
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
|
||||||
|
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
|
||||||
|
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||||
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
|
||||||
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
|
||||||
|
endif ()
|
||||||
|
foreach (QT_LIB Core Gui Widgets Network SerialPort)
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
"${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
|
||||||
|
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
|
||||||
|
endforeach (QT_LIB)
|
||||||
|
endif ()
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
//
|
||||||
|
// Created by Mr.V on 2023/8/16.
|
||||||
|
//
|
||||||
|
#include "common.h"
|
||||||
|
QString io_car = "";
|
||||||
|
QString direction = "";
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// Created by Mr.V on 2023/8/16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TRAIN_RFID_COMMON_H
|
||||||
|
#define TRAIN_RFID_COMMON_H
|
||||||
|
#include <QDir>
|
||||||
|
#include <QPair>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QSharedMemory>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QString>
|
||||||
|
extern QString io_car;
|
||||||
|
extern QString direction;
|
||||||
|
|
||||||
|
#endif //TRAIN_RFID_COMMON_H
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
#include "TcpClient.h"
|
||||||
|
//#include "mainWindow.h"
|
||||||
|
TcpClient::TcpClient(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
m_heartbeatTimer = new QTimer(this); //心跳包定时器
|
||||||
|
connect(&m_tcpSocket, &QTcpSocket::readyRead, this, &TcpClient::onReadyRead);
|
||||||
|
connect(m_heartbeatTimer, &QTimer::timeout, this, &TcpClient::sendHeartbeat);//心跳包
|
||||||
|
connect(&m_tcpSocket, &QTcpSocket::connected, this, &TcpClient::handleConnected);
|
||||||
|
connect(&m_tcpSocket, &QTcpSocket::disconnected, this, &TcpClient::handleDisconnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::connectToServer(const QString &host, int port)
|
||||||
|
{
|
||||||
|
m_host = host;
|
||||||
|
m_port = port;
|
||||||
|
m_tcpSocket.connectToHost(host,port); // Replace with actual server IP and port
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::onReadyRead()
|
||||||
|
{
|
||||||
|
|
||||||
|
QByteArray jsonData = m_tcpSocket.readAll();
|
||||||
|
// qDebug()<< jsonData <<Qt::endl;
|
||||||
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonData);
|
||||||
|
if ( jsonDocument.isObject()) {
|
||||||
|
QJsonObject jsonObject = jsonDocument.object();
|
||||||
|
QString t = jsonObject["cometime"].toString();
|
||||||
|
io_car = jsonObject["type"].toString();
|
||||||
|
direction = jsonObject["direction"].toString();
|
||||||
|
qDebug() << "direction" << direction << "\n";
|
||||||
|
if((io_car !="0" && io_car!="1") ||(direction != "0" && direction !="1" && direction !="2") )
|
||||||
|
{
|
||||||
|
QJsonObject jsonObject;
|
||||||
|
jsonObject["success"] ="false";
|
||||||
|
jsonObject["err_msg"] = "type or direction value is err...";
|
||||||
|
QJsonDocument jsonDocument(jsonObject);
|
||||||
|
QByteArray jsonData = jsonDocument.toJson();
|
||||||
|
|
||||||
|
m_tcpSocket.write(jsonData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QJsonObject jsonObject;
|
||||||
|
jsonObject["success"] = "true";
|
||||||
|
jsonObject["err_msg"] = "";
|
||||||
|
QJsonDocument jsonDocument(jsonObject);
|
||||||
|
QByteArray jsonData = jsonDocument.toJson();
|
||||||
|
m_tcpSocket.write(jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Process received JSON data
|
||||||
|
// // ...
|
||||||
|
qDebug()<< jsonData <<" "<< io_car<<" "<< direction<<" "<< t << "\n"<<Qt::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TcpClient::sendHeartbeat()
|
||||||
|
{
|
||||||
|
if (m_tcpSocket.state() == QAbstractSocket::ConnectedState) {
|
||||||
|
// 发送心跳包
|
||||||
|
|
||||||
|
//QByteArray heartbeatData = "matrixai";
|
||||||
|
// std::string head = "matrixai";
|
||||||
|
m_tcpSocket.write("matrixai");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TcpClient::reconnect()
|
||||||
|
{
|
||||||
|
if (m_tcpSocket.state() != QAbstractSocket::ConnectedState) {
|
||||||
|
// 断线重连
|
||||||
|
m_tcpSocket.connectToHost("127.0.0.1",7000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TcpClient::handleConnected()
|
||||||
|
{
|
||||||
|
if (!m_heartbeatTimer->isActive()) {
|
||||||
|
// 心跳包定时器启动
|
||||||
|
m_heartbeatTimer->start(3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::handleDisconnected()
|
||||||
|
{
|
||||||
|
if (m_heartbeatTimer->isActive()) {
|
||||||
|
// 停止发送心跳包
|
||||||
|
m_heartbeatTimer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5秒后尝试重新连接
|
||||||
|
QTimer::singleShot(5000, this, &TcpClient::reconnect);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef TCPCLIENT_H
|
||||||
|
#define TCPCLIENT_H
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QTimer>
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
class TcpClient : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TcpClient(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void connectToServer(const QString &host, int port);
|
||||||
|
void onReadyRead();
|
||||||
|
void sendHeartbeat();
|
||||||
|
void reconnect();
|
||||||
|
void handleConnected();
|
||||||
|
void handleDisconnected();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTcpSocket m_tcpSocket;
|
||||||
|
QTimer *m_heartbeatTimer;
|
||||||
|
QString m_host;
|
||||||
|
int m_port;
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif // TCPCLIENT_H
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
#include "TcpClient.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
QDir dir("shared_key.txt");
|
||||||
|
QByteArray line;
|
||||||
|
QFile file("shared_key.txt");
|
||||||
|
while(!file.exists())
|
||||||
|
{
|
||||||
|
dir.mkdir("shared_key.txt");//只创建一级子目录,即必须保证上级目录存在
|
||||||
|
file.open(QIODevice::WriteOnly|QIODevice::Text);
|
||||||
|
QDateTime current_date_time =QDateTime::currentDateTime();
|
||||||
|
QString current_date =current_date_time.toString("hh:mm:ss.zzz");//将时间做为key值写入文件一次
|
||||||
|
file.write(current_date.toUtf8());
|
||||||
|
file.close();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
file.open(QIODevice::ReadOnly);
|
||||||
|
line=file.readLine();
|
||||||
|
file.close();
|
||||||
|
QString const key=line;
|
||||||
|
QSharedMemory shared_memory;
|
||||||
|
shared_memory.setKey(key);//设置固定共享内存段的key值
|
||||||
|
if(shared_memory.attach()) //尝试将进程附加到该共享内存段
|
||||||
|
{
|
||||||
|
QMessageBox messageBox(QMessageBox::Warning,QString::fromUtf8("提示"),QString::QString::fromUtf8("当前程序正在运行中..."));
|
||||||
|
messageBox.setButtonText(QMessageBox::Ok,QString::QString::fromUtf8("确认!"));
|
||||||
|
messageBox.exec();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shared_memory.create(1)) //创建1byte的共享内存段
|
||||||
|
{
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
QApplication::setWindowIcon(QIcon("./logo.ico"));
|
||||||
|
MainWindow w;
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
// TcpClient tcpClient;
|
||||||
|
// tcpClient.connectToServer("127.0.0.1",7000); //与视频车号通信ip端口
|
||||||
|
return QApplication::exec();
|
||||||
|
}
|
||||||
|
return QApplication::exec();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,855 @@
|
||||||
|
|
||||||
|
#include "MainWindow.h"
|
||||||
|
#include "ui_MainWindow.h"
|
||||||
|
|
||||||
|
#define DEBUG_HTTP 1
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, ui(new Ui::MainWindow)
|
||||||
|
{
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
|
this->setWindowTitle("Matrix");
|
||||||
|
|
||||||
|
btrainLeave = true;
|
||||||
|
baccredit = false;
|
||||||
|
m_sendHttpSign = false;
|
||||||
|
m_icarriageOrder = 0;
|
||||||
|
m_icot = 0;
|
||||||
|
bdir = false;
|
||||||
|
szHavdcarTime = "";
|
||||||
|
if (_access("Logs", 0) == -1) { //判断是否存在日志的文件夹,没有则创建
|
||||||
|
std::string folderPath = "Logs";
|
||||||
|
if (0 != _mkdir(folderPath.c_str()))
|
||||||
|
{
|
||||||
|
_mkdir(folderPath.c_str()); // 返回 0 表示创建成功,-1 表示失败
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
serial = new QSerialPort;
|
||||||
|
|
||||||
|
m_pSystemTray=new QSystemTrayIcon(this);
|
||||||
|
|
||||||
|
//读取配置文件
|
||||||
|
read_configure_file();
|
||||||
|
|
||||||
|
//设置并打开串口
|
||||||
|
// set_uart_parameter();
|
||||||
|
//串口接收数据信号槽
|
||||||
|
//connect(serial,&QSerialPort::readyRead,this,&MainWindow::rece_data_slots);
|
||||||
|
QTimer* timer = new QTimer(this);
|
||||||
|
// connect(timer, &QTimer::timeout, this, &MainWindow::rece_data_slots);
|
||||||
|
|
||||||
|
// 设置定时器的时间间隔,例如50毫秒
|
||||||
|
// timer->start(10);
|
||||||
|
//最小化信号槽
|
||||||
|
connect(m_pSystemTray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason)));
|
||||||
|
//获取系统时间
|
||||||
|
get_system_time();
|
||||||
|
|
||||||
|
QString logName = "Logs/ceshi.txt";
|
||||||
|
logtest.setFileName(logName);
|
||||||
|
logtest.open(QIODevice::ReadWrite | QIODevice::Append);
|
||||||
|
|
||||||
|
QString logNamerecv = "Logs/recv.txt";
|
||||||
|
logrecv.setFileName(logNamerecv);
|
||||||
|
logrecv.open(QIODevice::ReadWrite | QIODevice::Append);
|
||||||
|
|
||||||
|
//初始最小化
|
||||||
|
//this->showMinimized();//最小化
|
||||||
|
// 设置最大展示数据行数
|
||||||
|
this->ui->textBrowser->document()->setMaximumBlockCount(1000);
|
||||||
|
|
||||||
|
tid = std::thread(&MainWindow::get_queue_data,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
serial->close();
|
||||||
|
logOut.close();
|
||||||
|
|
||||||
|
// if(tid.joinable()){
|
||||||
|
// tid.join();
|
||||||
|
// }
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:从queue中获取数据
|
||||||
|
* @param:空
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::get_queue_data(){
|
||||||
|
std::string szData = "";
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
bool bData = false;
|
||||||
|
|
||||||
|
while(queData.size() > 0)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(mtx_sync_);
|
||||||
|
|
||||||
|
std::string str_temp = queData.front();
|
||||||
|
queData.pop();
|
||||||
|
szData.append(str_temp);
|
||||||
|
if(szData.size() >= 8 && szData.front() == '@' && szData.back() == '&')
|
||||||
|
{
|
||||||
|
bData = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bData){
|
||||||
|
deal_str_data(szData);
|
||||||
|
szData.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::microseconds(20));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:解析数据
|
||||||
|
* @param:szStr:从queue中取到的字符串
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::deal_str_data(const std::string &szStr)
|
||||||
|
{
|
||||||
|
std::string szcarModel = "";
|
||||||
|
std::string szcarNumber = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
get_system_time();
|
||||||
|
|
||||||
|
std::string logstr = "长度:" + std::to_string(szStr.size()) + " 数据:" + szStr;
|
||||||
|
print_log(logstr);
|
||||||
|
|
||||||
|
int apos = 0,spos = 0;
|
||||||
|
int cout = std::count(szStr.begin(),szStr.end(),'@');
|
||||||
|
if(cout > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0;i < cout;i++)
|
||||||
|
{
|
||||||
|
apos = szStr.find('@',apos);
|
||||||
|
spos = szStr.find('&',spos);
|
||||||
|
|
||||||
|
if(apos == std::string::npos || spos == std::string::npos){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string szdata = szStr.substr(apos,spos - apos + 1);
|
||||||
|
ui->textBrowser->append(QString::fromStdString(szdata));
|
||||||
|
|
||||||
|
apos++;
|
||||||
|
spos++;
|
||||||
|
|
||||||
|
if (szdata.size() == 9)
|
||||||
|
{
|
||||||
|
if(szdata.at(1) == '0' && bdir==true && ((c_carnum == "" || zhcarNumber == c_carnum)|| io_car=="0"))
|
||||||
|
{//火车离开了关功放
|
||||||
|
std::string logstr = "火车离开了 ... ...总共车节数 " + std::to_string(m_icarriageOrder) + " 方向:" + m_direction +" 进车完成" + io_car.toStdString();
|
||||||
|
btrainLeave = true;
|
||||||
|
m_icot =0;
|
||||||
|
m_icot2=0;
|
||||||
|
m_flag=false;
|
||||||
|
m_icarriageOrder = 0;
|
||||||
|
m_direction.clear();
|
||||||
|
m_veclabel.clear();
|
||||||
|
m_sendHttpSign = false;
|
||||||
|
judget = false;
|
||||||
|
bdir = false ;
|
||||||
|
io_car ="";
|
||||||
|
//std::string logstr = "火车离开了 ... ...总共车节数 " + std::to_string(m_icarriageOrder) + " 方向:" + m_direction;
|
||||||
|
print_log(logstr);
|
||||||
|
|
||||||
|
ui->textBrowser->append(QString::fromStdString(logstr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(szdata.at(1) == '0' && bdir==false && ((zhcarNumber == c_carnum && m_direction.compare("1") && m_direction.compare("14"))||io_car=="0"))
|
||||||
|
{
|
||||||
|
std::string logstr = "火车离开了 ... ...总共车节数 " + std::to_string(m_icarriageOrder) + " 方向:" + m_direction+" 装车完成" + io_car.toStdString();
|
||||||
|
btrainLeave = true;
|
||||||
|
m_icot =0;
|
||||||
|
m_icot2=0;
|
||||||
|
m_flag=false;
|
||||||
|
m_icarriageOrder = 0;
|
||||||
|
io_car ="";
|
||||||
|
m_direction.clear();
|
||||||
|
m_veclabel.clear();
|
||||||
|
m_sendHttpSign = false;
|
||||||
|
judget = false;
|
||||||
|
|
||||||
|
|
||||||
|
print_log(logstr);
|
||||||
|
ui->textBrowser->append(QString::fromStdString(logstr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(szdata.at(1) == '0' && (m_direction.size()==1) && m_icot == 1)
|
||||||
|
{
|
||||||
|
std::string logstr = " 触碰磁钢关闭 ";
|
||||||
|
btrainLeave = true;
|
||||||
|
//m_icot =0;
|
||||||
|
m_icot2=0;
|
||||||
|
m_flag=false;
|
||||||
|
m_icarriageOrder = 0;
|
||||||
|
m_direction.clear();
|
||||||
|
m_veclabel.clear();
|
||||||
|
m_sendHttpSign = false;
|
||||||
|
judget = false;
|
||||||
|
|
||||||
|
print_log(logstr);
|
||||||
|
ui->textBrowser->append(QString::fromStdString(logstr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(szdata.at(1) == '8'||szdata.at(1) == '2'||szdata.at(1) == '1'||szdata.at(1) == '4')
|
||||||
|
{//磁钢数据处理
|
||||||
|
m_icot++;
|
||||||
|
if(m_flag==true)
|
||||||
|
{
|
||||||
|
m_icot2++;
|
||||||
|
}
|
||||||
|
if(judget == false)
|
||||||
|
{
|
||||||
|
auto itmp = m_direction.find(szdata.at(1));
|
||||||
|
if(itmp == std::string::npos){
|
||||||
|
m_direction.append(szdata.substr(1,1));
|
||||||
|
}
|
||||||
|
if(m_icot > 3){
|
||||||
|
bdir = Judge_direction();
|
||||||
|
if(m_direction == "8") //识别的单磁钢号为存储的最后一位时方向为false
|
||||||
|
{
|
||||||
|
bdir = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(direction == "2")
|
||||||
|
{
|
||||||
|
bdir = true;
|
||||||
|
}
|
||||||
|
QString logs = "识别到的方向" + QString::number(bdir)+ " dir:" + QString::fromStdString(m_direction);
|
||||||
|
ui->textBrowser->append(logs);
|
||||||
|
print_log(logs.toStdString());
|
||||||
|
judget = true;
|
||||||
|
}
|
||||||
|
szHavdcarTime = szcurrentTime.substr(0, 19);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString logs = QString::fromStdString("------------------------dir:" + m_direction + " 方向:" + std::to_string(bdir) + " 次数:" + std::to_string(m_icot) + " 车号:" + c_carnum+"io_car:"+io_car.toStdString()+"mv方向:"+direction.toStdString());
|
||||||
|
ui->textBrowser->append(logs);
|
||||||
|
print_log(logs.toStdString());
|
||||||
|
|
||||||
|
if(m_icot > 25 && bdir==true)
|
||||||
|
{
|
||||||
|
m_flag=true;
|
||||||
|
c_carnum = szcarNumber; //获取车号
|
||||||
|
m_icarriageOrder++;
|
||||||
|
lc_carnum = m_icarriageOrder;
|
||||||
|
m_sendHttpSign = true;
|
||||||
|
m_icot = 0; //不在发送时清空 是防止装车方向最后一个为空
|
||||||
|
m_icot2= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_icot > 25 && bdir == false)
|
||||||
|
{
|
||||||
|
|
||||||
|
c_carnum = szcarNumber;
|
||||||
|
m_icot = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//连续两节车丢标签逻辑
|
||||||
|
if(m_icot2 > 15 && bdir==true)
|
||||||
|
{
|
||||||
|
m_icarriageOrder++;
|
||||||
|
int k= m_icarriageOrder - 1 ;
|
||||||
|
|
||||||
|
if(lc_carnum == k) //连续
|
||||||
|
{
|
||||||
|
c_carnum = szcarNumber;
|
||||||
|
|
||||||
|
lc_carnum = m_icarriageOrder;
|
||||||
|
m_sendHttpSign = true;
|
||||||
|
m_icot = 0 ;
|
||||||
|
m_icot2 = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(lc_carnum != k) //bu连续
|
||||||
|
{
|
||||||
|
m_icarriageOrder--;
|
||||||
|
m_sendHttpSign = false;
|
||||||
|
m_icot2 = 0;
|
||||||
|
m_flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString log = QString::fromStdString(szcurrentTime + szdata + " 次:" + std::to_string(m_icot) + " 方向:" + m_direction +"io_car:"+io_car.toStdString()+"mv方向:"+direction.toStdString()+"\r\n");
|
||||||
|
logtest.write(log.toUtf8());
|
||||||
|
logtest.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (szdata.size() == 28)
|
||||||
|
{//车厢信息处理
|
||||||
|
btrainLeave = false; //火车没有离开
|
||||||
|
std::string logstr = "车厢数据:" + szdata;
|
||||||
|
print_log(logstr);
|
||||||
|
|
||||||
|
szcarModel = szdata.substr(2, 5); //车型
|
||||||
|
szcarModel.erase(std::remove(szcarModel.begin(), szcarModel.end(), ' '), szcarModel.end()); //删除其中的空格
|
||||||
|
szcarNumber = szdata.substr(8, 7); //车厢号
|
||||||
|
|
||||||
|
c_carnum = szcarNumber;
|
||||||
|
std::cout << "szcarModel" << szcarModel << " szcarNumber" << szcarNumber << std::endl;
|
||||||
|
|
||||||
|
bool bret = label_compare(szcarNumber); //判断车厢号是否存在
|
||||||
|
if(bret == false){
|
||||||
|
m_icot = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
m_veclabel.push_back(szcarNumber);
|
||||||
|
|
||||||
|
m_icarriageOrder++;
|
||||||
|
|
||||||
|
if(m_icarriageOrder==1 && bdir == true)
|
||||||
|
{
|
||||||
|
zhcarNumber = szcarNumber;
|
||||||
|
c_carnum ="1";
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sendHttpSign = true; //有车厢信息一定上传
|
||||||
|
if(szcarModel.at(0) != 'C' && szcarModel != "")
|
||||||
|
{
|
||||||
|
m_sendHttpSign = false;
|
||||||
|
m_icarriageOrder--;
|
||||||
|
|
||||||
|
c_carnum = "";
|
||||||
|
szcarModel = "";
|
||||||
|
szcarNumber = "";
|
||||||
|
}
|
||||||
|
QString log = QString::fromStdString(szcurrentTime + "------------------------------收到车厢数据\r\n");
|
||||||
|
m_icot = 0;
|
||||||
|
m_icot2= 0;
|
||||||
|
logtest.write(log.toUtf8());
|
||||||
|
logtest.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_sendHttpSign == true && bdir == true)
|
||||||
|
{
|
||||||
|
QString log = QString::fromStdString(szcurrentTime + "发送车厢数据------------------------------方向:" + m_direction + " 车节号" + std::to_string(m_icarriageOrder) +"\r\n\r\n\r\n");
|
||||||
|
logtest.write(log.toUtf8());
|
||||||
|
logtest.flush();
|
||||||
|
m_sendHttpSign = false;
|
||||||
|
itime = 0;
|
||||||
|
|
||||||
|
deal_uart_data(szcarModel,szcarNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 函数名:Logs()
|
||||||
|
* 功能:打印日志
|
||||||
|
* 参数:
|
||||||
|
* (空)
|
||||||
|
* 返回值:
|
||||||
|
* (预留)
|
||||||
|
*/
|
||||||
|
int MainWindow::debug_log_printf(std::string daystime)
|
||||||
|
{
|
||||||
|
logOut.close();
|
||||||
|
QString logName = "Logs/" + QString::fromStdString(daystime) + ".txt";
|
||||||
|
logOut.setFileName(logName);
|
||||||
|
if(!logOut.open(QIODevice::ReadWrite | QIODevice::Append))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:打印加输出日志
|
||||||
|
* @param:time:时间
|
||||||
|
* @param:logstr:打印字符串
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::print_log(std::string logstr)
|
||||||
|
{
|
||||||
|
//检查是否需要创建日志
|
||||||
|
if (szlastTime.compare(szcurrentTime.substr(0, 10))) // && btrainLeave == true
|
||||||
|
{
|
||||||
|
szlastTime = szcurrentTime.substr(0, 10);
|
||||||
|
int ret = debug_log_printf(szlastTime);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
std::cout << "Log file creat error" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString log = QString::fromStdString(szcurrentTime + logstr + "\r\n");
|
||||||
|
logOut.write(log.toUtf8());
|
||||||
|
logOut.flush();
|
||||||
|
qDebug() << log;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:获取系统时间
|
||||||
|
* @param:
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::get_system_time()
|
||||||
|
{
|
||||||
|
szcurrentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz").toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:放倒车
|
||||||
|
* @param:label:车型
|
||||||
|
* @return:false 存在;true 不存在
|
||||||
|
*/
|
||||||
|
bool MainWindow::label_compare(std::string &label)
|
||||||
|
{
|
||||||
|
if (m_veclabel.size() == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
std::vector <std::string>::const_iterator itr = std::find(m_veclabel.begin(), m_veclabel.end(),label);
|
||||||
|
if (itr != m_veclabel.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//false 和配置方向相反
|
||||||
|
//true 和配置方向相同
|
||||||
|
bool MainWindow::Judge_direction()
|
||||||
|
{
|
||||||
|
if(!m_direction.compare(configureInfo_T.configDirection) || m_direction.at(0) == configureInfo_T.configDirection.at(0)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = configureInfo_T.configDirection.find(m_direction.at(0));
|
||||||
|
for(int i = 0; i < pos;i++){
|
||||||
|
auto dirpos = m_direction.find(configureInfo_T.configDirection.at(pos - 1));
|
||||||
|
if(dirpos != std::string::npos){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::rece_data_slots()
|
||||||
|
{
|
||||||
|
QByteArray data = serial->readAll(); // 读取数据
|
||||||
|
if(!data.isEmpty())
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(mtx_sync_);
|
||||||
|
queData.push(QString(data).toStdString());
|
||||||
|
|
||||||
|
QString log = QString::fromStdString(szcurrentTime) + QString(data);
|
||||||
|
logrecv.write(log.toUtf8());
|
||||||
|
logrecv.flush();
|
||||||
|
}
|
||||||
|
data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:解析协议1的串口数据。
|
||||||
|
* @param:szcarModel: 车型
|
||||||
|
* @param:szcarNumber:车厢号
|
||||||
|
* @return: 成功:true
|
||||||
|
* 失败:false
|
||||||
|
*/
|
||||||
|
bool MainWindow::deal_uart_data(std::string &szcarModel,std::string &szcarNumber)
|
||||||
|
{
|
||||||
|
print_log("进入数据发送流程");
|
||||||
|
|
||||||
|
std::string sztime = szHavdcarTime;
|
||||||
|
#if DEBUG_HTTP
|
||||||
|
int ix = 0;
|
||||||
|
do{
|
||||||
|
ix++;
|
||||||
|
std::string ord = std::to_string(m_icarriageOrder);
|
||||||
|
int ret = http_send(szcarModel, szcarNumber,ord,sztime);
|
||||||
|
if(ret == -2){
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}else{
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}while(ix < 3);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string str = "***************************车型:" + szcarModel + " 车号:" + szcarNumber + " 车节号:" + std::to_string(m_icarriageOrder);
|
||||||
|
ui->textBrowser->append(QString::fromStdString(str));
|
||||||
|
print_log(str);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:Http发送RFID数据
|
||||||
|
* @param:carModel:车型
|
||||||
|
* @param:carNum:车号
|
||||||
|
* @param:catFrequency:车节号
|
||||||
|
* @param:time:当前时间
|
||||||
|
* @return: 成功:true
|
||||||
|
* 失败:false
|
||||||
|
*/
|
||||||
|
int MainWindow::http_send(std::string &carriageType, std::string &carriageNumber, std::string &carriageOrder, std::string &time)
|
||||||
|
{
|
||||||
|
httplib::Client cli(configureInfo_T.ip, std::atoi(configureInfo_T.port.c_str()));
|
||||||
|
httplib::Headers header;
|
||||||
|
httplib::Params params;
|
||||||
|
Json::Value arrayObj; //构建对象
|
||||||
|
|
||||||
|
if (baccredit)
|
||||||
|
{
|
||||||
|
header.emplace("blade-auth", accreditInformation);
|
||||||
|
//header.emplace("Content-Type", "application/json");
|
||||||
|
|
||||||
|
arrayObj["comeTime"] = time;
|
||||||
|
arrayObj["carriageNumber"] = carriageNumber;
|
||||||
|
arrayObj["carriageType"] = carriageType;
|
||||||
|
arrayObj["carriageOrder"] = carriageOrder;
|
||||||
|
|
||||||
|
Json::Value trainParams;
|
||||||
|
trainParams["poundNo"] = configureInfo_T.stationTrack;
|
||||||
|
arrayObj["trainParams"] = trainParams;
|
||||||
|
Json::StreamWriterBuilder writer;
|
||||||
|
std::cout << " http send:" << arrayObj << std::endl;
|
||||||
|
std::string str = Json::writeString(writer, arrayObj);
|
||||||
|
print_log(str);
|
||||||
|
auto res = cli.Post(configureInfo_T.urlPath, header, str, "application/json");
|
||||||
|
if (res)
|
||||||
|
{
|
||||||
|
print_log(res->body.c_str());
|
||||||
|
if (res->status == 200)
|
||||||
|
{
|
||||||
|
Json::CharReaderBuilder readerBuilder;
|
||||||
|
std::istringstream iss(res->body);
|
||||||
|
Json::Value root;
|
||||||
|
std::string errs;
|
||||||
|
bool parsingSuccessful = Json::parseFromStream(readerBuilder, iss, &root, &errs);
|
||||||
|
if (parsingSuccessful)
|
||||||
|
{
|
||||||
|
if (!root["success"].asString().compare("true"))
|
||||||
|
{
|
||||||
|
print_log("已经成功发送数据到Web ...");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!root["msg"].asString().compare("请求未授权")) {
|
||||||
|
print_log("error : 发送数据到Web error 请求没有得到授权 需要请求授权.");
|
||||||
|
obtain_accredit();
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:Http获取授权
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
*/
|
||||||
|
void MainWindow::obtain_accredit()
|
||||||
|
{
|
||||||
|
|
||||||
|
httplib::Client cli(configureInfo_T.ip, std::atoi(configureInfo_T.port.c_str()));
|
||||||
|
httplib::Headers header;
|
||||||
|
httplib::Params params;
|
||||||
|
|
||||||
|
if (!baccredit) {
|
||||||
|
header.emplace("Authorization", "Basic Y2xpZW50X2VudGVycHJpc2U6Y2xpZW50X2VudGVycHJpc2Vfc2VjcmV0");
|
||||||
|
|
||||||
|
params.emplace("username", "guest_01");
|
||||||
|
params.emplace("password", "d55b0f642e817eea24725d2f2a31dd08");
|
||||||
|
params.emplace("tenantId", "000000");
|
||||||
|
params.emplace("grant_type", "password");
|
||||||
|
auto res = cli.Post("/api/blade-auth/oauth/token", header, params);
|
||||||
|
if (res)
|
||||||
|
{
|
||||||
|
if (res->status == 200)
|
||||||
|
{
|
||||||
|
Json::CharReaderBuilder readerBuilder;
|
||||||
|
std::istringstream iss(res->body);
|
||||||
|
Json::Value root;
|
||||||
|
std::string errs;
|
||||||
|
bool parsingSuccessful = Json::parseFromStream(readerBuilder, iss, &root, &errs);
|
||||||
|
|
||||||
|
if (parsingSuccessful)
|
||||||
|
{
|
||||||
|
if (root["success"].asString().compare("true"))
|
||||||
|
{
|
||||||
|
baccredit = true;
|
||||||
|
accreditInformation = root["token_type"].asString();
|
||||||
|
accreditInformation.append(" ");
|
||||||
|
accreditInformation.append(root["access_token"].asString());
|
||||||
|
std::string logs = "已经成功得到授权,授权信息为:" + accreditInformation + '\n';
|
||||||
|
std::cout << logs << std::endl;
|
||||||
|
ui->textBrowser->setText(QString::fromStdString(logs));
|
||||||
|
print_log("已经成功得到授权.");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto err = res.error();
|
||||||
|
if (err == httplib::Error::Connection) {
|
||||||
|
std::cout << " (连接出错)" << std::endl;
|
||||||
|
}
|
||||||
|
print_log("请求授权出错 error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************串口初始化*************************************/
|
||||||
|
/**
|
||||||
|
* @brief:设置串口
|
||||||
|
* @param:
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::set_uart_parameter()
|
||||||
|
{
|
||||||
|
serial->setPortName(QString::fromStdString(configureInfo_T.uartName));
|
||||||
|
|
||||||
|
if(!configureInfo_T.uartBaud.compare("9600")){
|
||||||
|
serial->setBaudRate(QSerialPort::Baud9600);
|
||||||
|
}else if(!configureInfo_T.uartBaud.compare("19200")){
|
||||||
|
serial->setBaudRate(QSerialPort::Baud19200);
|
||||||
|
}else if(!configureInfo_T.uartBaud.compare("115200")){
|
||||||
|
serial->setBaudRate(QSerialPort::Baud115200);
|
||||||
|
}
|
||||||
|
|
||||||
|
serial->setParity(QSerialPort::NoParity);// 校验
|
||||||
|
serial->setDataBits(QSerialPort::Data8); //数据位
|
||||||
|
serial->setStopBits(QSerialPort::OneStop);//停止位,停止位默认选择1位
|
||||||
|
serial->setFlowControl(QSerialPort::NoFlowControl);// 控制流,默认选择无
|
||||||
|
if(serial->open(QSerialPort::ReadWrite)){
|
||||||
|
#if DEBUG_HTTP
|
||||||
|
obtain_accredit(); //获取http授权
|
||||||
|
#endif
|
||||||
|
std::string logs;
|
||||||
|
logs.append("串口打开成功\n");
|
||||||
|
logs.append(" 串口号:" + configureInfo_T.uartName + "\r\n");
|
||||||
|
logs.append(" 波特率:" + configureInfo_T.uartBaud + "\r\n");
|
||||||
|
logs.append(" IP :" + configureInfo_T.ip + "\r\n");
|
||||||
|
logs.append(" 端口号:" + configureInfo_T.port + "\r\n");
|
||||||
|
logs.append(" URL :" + configureInfo_T.urlPath + "\r\n");
|
||||||
|
logs.append(" 股道号:" + configureInfo_T.stationTrack + "\r\n");
|
||||||
|
logs.append(" 方向编号:" + configureInfo_T.configDirection + "\r\n");
|
||||||
|
|
||||||
|
ui->textBrowser->append(QString::fromStdString(logs));
|
||||||
|
print_log(logs);
|
||||||
|
}else{
|
||||||
|
std::string logs;
|
||||||
|
logs.append("打开串口失败,请确认!!!");
|
||||||
|
ui->textBrowser->append(QString::fromStdString(logs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************读写配置文件****************************************/
|
||||||
|
/**
|
||||||
|
* @brief:读取配置文件,并显示在相应的位置
|
||||||
|
* @param:
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::read_configure_file(){
|
||||||
|
std::string str;
|
||||||
|
int pos;
|
||||||
|
std::ifstream file("laneConfig.txt");
|
||||||
|
if (file.good()) {
|
||||||
|
while (std::getline(file, str)) {
|
||||||
|
pos = str.find("uartName:");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pos = str.find(":");
|
||||||
|
configureInfo_T.uartName = str.substr(pos + 1);
|
||||||
|
if(std::atoi(configureInfo_T.uartName.substr(3).c_str())>=10){
|
||||||
|
configureInfo_T.uartName.insert(3,"\\\\.\\");
|
||||||
|
}
|
||||||
|
std::cout<< "configureInfo_T.uartName:" << configureInfo_T.uartName << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = str.find("uartBaud:");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pos = str.find(":");
|
||||||
|
configureInfo_T.uartBaud = str.substr(pos + 1);
|
||||||
|
std::cout<< "m_uartBaud:" << configureInfo_T.uartBaud << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = str.find("IP:");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pos = str.find(":");
|
||||||
|
configureInfo_T.ip = str.substr(pos + 1);
|
||||||
|
std::cout<< "m_szip:" << configureInfo_T.ip << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = str.find("Port:");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pos = str.find(":");
|
||||||
|
configureInfo_T.port = str.substr(pos + 1);
|
||||||
|
std::cout<< "m_iport:" << configureInfo_T.port << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = str.find("Path:");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pos = str.find(":");
|
||||||
|
configureInfo_T.urlPath = str.substr(pos + 1);
|
||||||
|
std::cout<< "m_szurlPath:" << configureInfo_T.urlPath << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = str.find("Station");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pos = str.find(":");
|
||||||
|
configureInfo_T.stationTrack = str.substr(pos + 1);
|
||||||
|
std::cout<< "m_szstationTrack:" << configureInfo_T.stationTrack << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = str.find("Direction");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pos = str.find(":");
|
||||||
|
configureInfo_T.configDirection = str.substr(pos + 1);
|
||||||
|
std::cout<< "m_configDirection:" << configureInfo_T.configDirection << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:将新的内容写入到配置文件中
|
||||||
|
* @param:
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::write_configure_file(){
|
||||||
|
ofswrite.open("laneConfig.txt", std::ios::out|std::ios::binary); // append,追加
|
||||||
|
ofswrite << "uartName:" << configureInfo_T.uartName << std::endl;
|
||||||
|
ofswrite << "uartBaud:" << configureInfo_T.uartBaud << std::endl;
|
||||||
|
ofswrite << "IP:" << configureInfo_T.ip << std::endl;
|
||||||
|
ofswrite << "Port:" << configureInfo_T.port << std::endl;
|
||||||
|
ofswrite << "Path:" << configureInfo_T.urlPath << std::endl;
|
||||||
|
ofswrite << "Station:" << configureInfo_T.stationTrack << std::endl;
|
||||||
|
ofswrite.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************最小化相关****************************************/
|
||||||
|
/**
|
||||||
|
* @brief:接收最小化信号
|
||||||
|
* @param:
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::changeEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if((event->type()==QEvent::WindowStateChange)&&isMinimized())
|
||||||
|
{
|
||||||
|
hide();
|
||||||
|
m_pSystemTray->setIcon(QIcon("./logo.ico")); // 托盘时显示的图片
|
||||||
|
m_pSystemTray->setToolTip("rfid车号识别"); // 鼠标在托盘图片时的提示
|
||||||
|
m_pSystemTray->showMessage("SystemTrayIcon","",QSystemTrayIcon::Information,10000);
|
||||||
|
event->ignore();
|
||||||
|
//建立托盘操作的菜单
|
||||||
|
creat_action();
|
||||||
|
creat_menu();
|
||||||
|
m_pSystemTray->show(); // 显示图片图标
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
// QMessageBox::StandardButton button = QMessageBox::information(NULL, "提示", "确定关闭软件?",QMessageBox::Yes, QMessageBox::No);;
|
||||||
|
// if(QMessageBox::Yes == button)
|
||||||
|
// {
|
||||||
|
// close();
|
||||||
|
// }else{
|
||||||
|
// event->ignore();
|
||||||
|
// }
|
||||||
|
// 弹出对话框要求用户输入账号和密码
|
||||||
|
QString username = QInputDialog::getText(this, "关闭账号密码验证", "请输入账号:");
|
||||||
|
QString password = QInputDialog::getText(this, "关闭账号密码验证", "请输入密码:", QLineEdit::Password);
|
||||||
|
|
||||||
|
// 验证账号和密码是否正确
|
||||||
|
if (username == "admin" && password == "brt123") {
|
||||||
|
event->accept(); // 关闭窗口
|
||||||
|
} else {
|
||||||
|
QMessageBox::warning(this, "验证失败", "账号或密码不正确!");
|
||||||
|
event->ignore(); // 阻止关闭窗口
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::creat_action()
|
||||||
|
{
|
||||||
|
m_pActionShow = new QAction("show", this);
|
||||||
|
connect(m_pActionShow, &QAction::triggered, this,&MainWindow::on_ShowMainAction);
|
||||||
|
m_pActionQuit = new QAction("exit", this);
|
||||||
|
connect(m_pActionQuit, &QAction::triggered, this, &MainWindow::on_ExitAppAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::creat_menu()
|
||||||
|
{
|
||||||
|
m_pTrayMennu = new QMenu(this);
|
||||||
|
//新增菜单项---显示主界面
|
||||||
|
m_pTrayMennu->addAction(m_pActionShow);
|
||||||
|
//增加分隔符
|
||||||
|
m_pTrayMennu->addSeparator();
|
||||||
|
//新增菜单项---退出程序
|
||||||
|
m_pTrayMennu->addAction(m_pActionQuit);
|
||||||
|
//把QMenu赋给QSystemTrayIcon对象
|
||||||
|
m_pSystemTray->setContextMenu(m_pTrayMennu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:显示
|
||||||
|
* @param:
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::on_ShowMainAction()
|
||||||
|
{
|
||||||
|
this->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief:最小化
|
||||||
|
* @param:
|
||||||
|
* @return:空
|
||||||
|
*/
|
||||||
|
void MainWindow::on_ExitAppAction()
|
||||||
|
{
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
|
||||||
|
{
|
||||||
|
switch(reason){
|
||||||
|
case QSystemTrayIcon::Trigger:
|
||||||
|
//单击托盘图标
|
||||||
|
this->showNormal();
|
||||||
|
break;
|
||||||
|
case QSystemTrayIcon::DoubleClick:
|
||||||
|
//双击托盘图标
|
||||||
|
//双击后显示主程序窗口
|
||||||
|
this->showNormal();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,154 @@
|
||||||
|
#ifndef MainWindow_H
|
||||||
|
#define MainWindow_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QtSerialPort/QSerialPortInfo>
|
||||||
|
#include <QtSerialPort/QSerialPort>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QString>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <WinSock2.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <cstring>
|
||||||
|
#include <QWaitCondition>
|
||||||
|
#include <ctime>
|
||||||
|
#include <codecvt>
|
||||||
|
#include <Iphlpapi.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTcpsocket>
|
||||||
|
#include <direct.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include "httplib.h"
|
||||||
|
#include "json.h"
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QCloseEvent>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QCloseEvent>
|
||||||
|
#include <qmenu.h>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <thread>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <queue>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace Ui { class MainWindow; }
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class MainWindow : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWindow(QWidget *parent = nullptr);
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
|
void set_uart_parameter();
|
||||||
|
int debug_log_printf(std::string daystime);
|
||||||
|
void get_system_time();
|
||||||
|
void print_log(std::string logstr);
|
||||||
|
bool deal_uart_data(std::string &szcarModel,std::string &szcarNumber);
|
||||||
|
bool label_compare(std::string &label);
|
||||||
|
int http_send(std::string &carriageType, std::string &carriageNumber, std::string &carriageOrder, std::string &time);
|
||||||
|
void obtain_accredit();
|
||||||
|
void read_configure_file();
|
||||||
|
void write_configure_file();
|
||||||
|
void creat_menu();
|
||||||
|
void creat_action();
|
||||||
|
int compare_string(const std::string &recv_str);
|
||||||
|
bool Judge_direction();
|
||||||
|
// bool Data_time(int icon);
|
||||||
|
void add_order(int count);
|
||||||
|
void serial_timerstart();
|
||||||
|
typedef struct _CONFIGURE_INFO_{
|
||||||
|
std::string uartName; //串口名
|
||||||
|
std::string uartBaud; //波特率
|
||||||
|
std::string ip; //web IP
|
||||||
|
std::string port; //web 端口号
|
||||||
|
std::string urlPath; //web URL
|
||||||
|
std::string stationTrack; //股道号
|
||||||
|
std::string configDirection; //配置的磁钢方向
|
||||||
|
|
||||||
|
}CONFIGURE_INFO_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CONFIGURE_INFO_ configureInfo_T;
|
||||||
|
std::string szcurrentTime; //当前时间
|
||||||
|
std::string szlastTime; //上一次时间
|
||||||
|
std::string zhcarNumber = "";
|
||||||
|
|
||||||
|
bool btrainLeave; //火车离开标志 当前火车已经离开:true 没有离开:false
|
||||||
|
std::vector <std::string> m_veclabel; //倒车防重扫
|
||||||
|
bool baccredit; //是否获取授权
|
||||||
|
std::string accreditInformation; //授权信息
|
||||||
|
// std::string m_recvData; //接收到的数据
|
||||||
|
//std::string f_time; //第一个磁钢时间
|
||||||
|
// std::string t_tine; //第二个磁钢时间
|
||||||
|
std::string m_direction; //磁钢号存储
|
||||||
|
bool m_sendHttpSign; //发送给http标志
|
||||||
|
int m_icarriageOrder; //车节号
|
||||||
|
int m_icot;
|
||||||
|
bool m_flag = false; //是否丢车节
|
||||||
|
int m_icot2=0; //丢车节计数防止丢两节
|
||||||
|
int itime = 0;
|
||||||
|
bool bdir = true; //和配置方向是否相同
|
||||||
|
int m_lastCarriagrOrder = 0;
|
||||||
|
int lc_carnum; //漏车的车节号
|
||||||
|
|
||||||
|
QByteArray buffer; //串口接收数据缓存区
|
||||||
|
QTimer* timer;
|
||||||
|
bool judget = false;
|
||||||
|
std::string c_carnum;
|
||||||
|
std::string szHavdcarTime;
|
||||||
|
std::vector<std::string> vec_configureDir;
|
||||||
|
private:
|
||||||
|
void changeEvent(QEvent *event);
|
||||||
|
void on_ShowMainAction();
|
||||||
|
void on_ExitAppAction();
|
||||||
|
void closeEvent(QCloseEvent *event);
|
||||||
|
void get_queue_data();
|
||||||
|
void deal_str_data(const std::string &szStr);
|
||||||
|
|
||||||
|
QMenu* m_pTrayMennu; //系统托盘右键菜单项
|
||||||
|
QSystemTrayIcon* m_pSystemTray; //系统托盘图标
|
||||||
|
QFile logOut;
|
||||||
|
QFile logrecv;
|
||||||
|
QFile logtest;
|
||||||
|
std::ofstream ofswrite;
|
||||||
|
|
||||||
|
//右键菜单栏选项
|
||||||
|
QAction* m_pActionShow;
|
||||||
|
QAction* m_pActionQuit;
|
||||||
|
|
||||||
|
QSerialPort *serial; //串口
|
||||||
|
/****************************xl*****************************/
|
||||||
|
std::queue<std::string> queData;
|
||||||
|
std::thread tid;
|
||||||
|
std::mutex mtx_sync_;
|
||||||
|
private slots:
|
||||||
|
void rece_data_slots();
|
||||||
|
void on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::MainWindow *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MainWindow_H
|
||||||
|
|
@ -0,0 +1,198 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QWidget" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1000</width>
|
||||||
|
<height>815</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>1000</width>
|
||||||
|
<height>815</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>1000</width>
|
||||||
|
<height>815</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>串口号:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comBox">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>波特率:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="BTBox">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>股道名:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="truckEdit">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Maximum</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="openComButton">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>120</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>打开串口</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Minimum</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>识别结果:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="resultTable"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>日志:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="textBrowser">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Arial</family>
|
||||||
|
<pointsize>11</pointsize>
|
||||||
|
<weight>50</weight>
|
||||||
|
<bold>false</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
|
|
@ -0,0 +1,181 @@
|
||||||
|
/********************************************************************************
|
||||||
|
** Form generated from reading UI file 'mainwindow.ui'
|
||||||
|
**
|
||||||
|
** Created by: Qt User Interface Compiler version 5.15.2
|
||||||
|
**
|
||||||
|
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||||
|
********************************************************************************/
|
||||||
|
|
||||||
|
#ifndef UI_MAINWINDOW_H
|
||||||
|
#define UI_MAINWINDOW_H
|
||||||
|
|
||||||
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <QtWidgets/QComboBox>
|
||||||
|
#include <QtWidgets/QHBoxLayout>
|
||||||
|
#include <QtWidgets/QHeaderView>
|
||||||
|
#include <QtWidgets/QLabel>
|
||||||
|
#include <QtWidgets/QLineEdit>
|
||||||
|
#include <QtWidgets/QPushButton>
|
||||||
|
#include <QtWidgets/QSpacerItem>
|
||||||
|
#include <QtWidgets/QTableView>
|
||||||
|
#include <QtWidgets/QTextBrowser>
|
||||||
|
#include <QtWidgets/QVBoxLayout>
|
||||||
|
#include <QtWidgets/QWidget>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class Ui_MainWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QVBoxLayout *verticalLayout_3;
|
||||||
|
QHBoxLayout *horizontalLayout;
|
||||||
|
QLabel *label;
|
||||||
|
QComboBox *comboBox;
|
||||||
|
QLabel *label_2;
|
||||||
|
QComboBox *comboBox_2;
|
||||||
|
QLabel *label_3;
|
||||||
|
QLineEdit *lineEdit;
|
||||||
|
QSpacerItem *horizontalSpacer;
|
||||||
|
QPushButton *pushButton;
|
||||||
|
QSpacerItem *horizontalSpacer_2;
|
||||||
|
QHBoxLayout *horizontalLayout_2;
|
||||||
|
QVBoxLayout *verticalLayout;
|
||||||
|
QLabel *label_4;
|
||||||
|
QTableView *tableView;
|
||||||
|
QVBoxLayout *verticalLayout_2;
|
||||||
|
QLabel *label_5;
|
||||||
|
QTextBrowser *textBrowser;
|
||||||
|
|
||||||
|
void setupUi(QWidget *MainWindow)
|
||||||
|
{
|
||||||
|
if (MainWindow->objectName().isEmpty())
|
||||||
|
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
|
||||||
|
MainWindow->resize(1000, 815);
|
||||||
|
MainWindow->setMinimumSize(QSize(1000, 815));
|
||||||
|
MainWindow->setMaximumSize(QSize(1000, 815));
|
||||||
|
verticalLayout_3 = new QVBoxLayout(MainWindow);
|
||||||
|
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
|
||||||
|
horizontalLayout = new QHBoxLayout();
|
||||||
|
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
|
||||||
|
label = new QLabel(MainWindow);
|
||||||
|
label->setObjectName(QString::fromUtf8("label"));
|
||||||
|
|
||||||
|
horizontalLayout->addWidget(label);
|
||||||
|
|
||||||
|
comboBox = new QComboBox(MainWindow);
|
||||||
|
comboBox->setObjectName(QString::fromUtf8("comboBox"));
|
||||||
|
comboBox->setMinimumSize(QSize(120, 40));
|
||||||
|
comboBox->setMaximumSize(QSize(120, 40));
|
||||||
|
|
||||||
|
horizontalLayout->addWidget(comboBox);
|
||||||
|
|
||||||
|
label_2 = new QLabel(MainWindow);
|
||||||
|
label_2->setObjectName(QString::fromUtf8("label_2"));
|
||||||
|
|
||||||
|
horizontalLayout->addWidget(label_2);
|
||||||
|
|
||||||
|
comboBox_2 = new QComboBox(MainWindow);
|
||||||
|
comboBox_2->setObjectName(QString::fromUtf8("comboBox_2"));
|
||||||
|
comboBox_2->setMinimumSize(QSize(120, 40));
|
||||||
|
comboBox_2->setMaximumSize(QSize(120, 40));
|
||||||
|
|
||||||
|
horizontalLayout->addWidget(comboBox_2);
|
||||||
|
|
||||||
|
label_3 = new QLabel(MainWindow);
|
||||||
|
label_3->setObjectName(QString::fromUtf8("label_3"));
|
||||||
|
|
||||||
|
horizontalLayout->addWidget(label_3);
|
||||||
|
|
||||||
|
lineEdit = new QLineEdit(MainWindow);
|
||||||
|
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
|
||||||
|
lineEdit->setMinimumSize(QSize(120, 40));
|
||||||
|
lineEdit->setMaximumSize(QSize(120, 40));
|
||||||
|
|
||||||
|
horizontalLayout->addWidget(lineEdit);
|
||||||
|
|
||||||
|
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Maximum, QSizePolicy::Minimum);
|
||||||
|
|
||||||
|
horizontalLayout->addItem(horizontalSpacer);
|
||||||
|
|
||||||
|
pushButton = new QPushButton(MainWindow);
|
||||||
|
pushButton->setObjectName(QString::fromUtf8("pushButton"));
|
||||||
|
pushButton->setMinimumSize(QSize(120, 50));
|
||||||
|
pushButton->setMaximumSize(QSize(120, 50));
|
||||||
|
|
||||||
|
horizontalLayout->addWidget(pushButton);
|
||||||
|
|
||||||
|
horizontalSpacer_2 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
|
|
||||||
|
horizontalLayout->addItem(horizontalSpacer_2);
|
||||||
|
|
||||||
|
|
||||||
|
verticalLayout_3->addLayout(horizontalLayout);
|
||||||
|
|
||||||
|
horizontalLayout_2 = new QHBoxLayout();
|
||||||
|
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
|
||||||
|
verticalLayout = new QVBoxLayout();
|
||||||
|
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||||
|
label_4 = new QLabel(MainWindow);
|
||||||
|
label_4->setObjectName(QString::fromUtf8("label_4"));
|
||||||
|
|
||||||
|
verticalLayout->addWidget(label_4);
|
||||||
|
|
||||||
|
tableView = new QTableView(MainWindow);
|
||||||
|
tableView->setObjectName(QString::fromUtf8("tableView"));
|
||||||
|
|
||||||
|
verticalLayout->addWidget(tableView);
|
||||||
|
|
||||||
|
|
||||||
|
horizontalLayout_2->addLayout(verticalLayout);
|
||||||
|
|
||||||
|
verticalLayout_2 = new QVBoxLayout();
|
||||||
|
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
|
||||||
|
label_5 = new QLabel(MainWindow);
|
||||||
|
label_5->setObjectName(QString::fromUtf8("label_5"));
|
||||||
|
|
||||||
|
verticalLayout_2->addWidget(label_5);
|
||||||
|
|
||||||
|
textBrowser = new QTextBrowser(MainWindow);
|
||||||
|
textBrowser->setObjectName(QString::fromUtf8("textBrowser"));
|
||||||
|
QFont font;
|
||||||
|
font.setFamily(QString::fromUtf8("Arial"));
|
||||||
|
font.setPointSize(11);
|
||||||
|
font.setBold(false);
|
||||||
|
font.setWeight(50);
|
||||||
|
textBrowser->setFont(font);
|
||||||
|
|
||||||
|
verticalLayout_2->addWidget(textBrowser);
|
||||||
|
|
||||||
|
|
||||||
|
horizontalLayout_2->addLayout(verticalLayout_2);
|
||||||
|
|
||||||
|
|
||||||
|
verticalLayout_3->addLayout(horizontalLayout_2);
|
||||||
|
|
||||||
|
|
||||||
|
retranslateUi(MainWindow);
|
||||||
|
|
||||||
|
QMetaObject::connectSlotsByName(MainWindow);
|
||||||
|
} // setupUi
|
||||||
|
|
||||||
|
void retranslateUi(QWidget *MainWindow)
|
||||||
|
{
|
||||||
|
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
|
||||||
|
label->setText(QCoreApplication::translate("MainWindow", "\344\270\262\345\217\243\345\217\267:", nullptr));
|
||||||
|
label_2->setText(QCoreApplication::translate("MainWindow", "\346\263\242\347\211\271\347\216\207:", nullptr));
|
||||||
|
label_3->setText(QCoreApplication::translate("MainWindow", "\350\202\241\351\201\223\345\220\215:", nullptr));
|
||||||
|
pushButton->setText(QCoreApplication::translate("MainWindow", "\346\211\223\345\274\200\344\270\262\345\217\243", nullptr));
|
||||||
|
label_4->setText(QCoreApplication::translate("MainWindow", "\350\257\206\345\210\253\347\273\223\346\236\234:", nullptr));
|
||||||
|
label_5->setText(QCoreApplication::translate("MainWindow", "\346\227\245\345\277\227:", nullptr));
|
||||||
|
} // retranslateUi
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class MainWindow: public Ui_MainWindow {};
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // UI_MAINWINDOW_H
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
//
|
||||||
|
// Created by Mr.V on 2024/1/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ComPortTool.h"
|
||||||
|
|
||||||
|
// 字符串转换
|
||||||
|
char* ComPortTool::wideCharToMultiByte(wchar_t* pWCStrKey)
|
||||||
|
{
|
||||||
|
//第一次调用确认转换后单字节字符串的长度,用于开辟空间
|
||||||
|
int pSize = WideCharToMultiByte(CP_OEMCP, 0, pWCStrKey, wcslen(pWCStrKey), NULL, 0, NULL, NULL);
|
||||||
|
char* pCStrKey = new char[pSize + 1];
|
||||||
|
//第二次调用将双字节字符串转换成单字节字符串
|
||||||
|
WideCharToMultiByte(CP_OEMCP, 0, pWCStrKey, wcslen(pWCStrKey), pCStrKey, pSize, NULL, NULL);
|
||||||
|
pCStrKey[pSize] = '\0';
|
||||||
|
return pCStrKey;
|
||||||
|
|
||||||
|
//如果想要转换成string,直接赋值即可
|
||||||
|
//string pKey = pCStrKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ComPortTool::getComPort()
|
||||||
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
wchar_t portName[256], w_commName[256];
|
||||||
|
std::vector<std::string> comName;
|
||||||
|
//打开串口注册表对应的键值
|
||||||
|
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Hardware\\DeviceMap\\SerialComm"), NULL, KEY_READ, &hKey))
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int mm = 0;
|
||||||
|
DWORD dwLong, dwSize;
|
||||||
|
while (TRUE)
|
||||||
|
{
|
||||||
|
dwLong = dwSize = sizeof(portName);
|
||||||
|
//枚举串口
|
||||||
|
if (ERROR_NO_MORE_ITEMS == ::RegEnumValue(hKey, i, portName, &dwLong, NULL, NULL, (PUCHAR)w_commName, &dwSize))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
char* commName = wideCharToMultiByte(w_commName);
|
||||||
|
comName.push_back(commName);
|
||||||
|
delete[] commName;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
//关闭注册表
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
//返回串口号
|
||||||
|
return comName;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
//
|
||||||
|
// Created by Mr.V on 2024/1/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TRAIN_RFID_COMPORTTOOL_H
|
||||||
|
#define TRAIN_RFID_COMPORTTOOL_H
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class ComPortTool {
|
||||||
|
public:
|
||||||
|
ComPortTool();
|
||||||
|
|
||||||
|
~ComPortTool();
|
||||||
|
|
||||||
|
char* wideCharToMultiByte(wchar_t* pWCStrKey);
|
||||||
|
|
||||||
|
std::vector<std::string> getComPort();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //TRAIN_RFID_COMPORTTOOL_H
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,446 @@
|
||||||
|
/// Json-cpp amalgamated forward header (http://jsoncpp.sourceforge.net/).
|
||||||
|
/// It is intended to be used with #include "json/json-forwards.h"
|
||||||
|
/// This header provides forward declaration for all JsonCpp types.
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// Beginning of content of file: LICENSE
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/*
|
||||||
|
The JsonCpp library's source code, including accompanying documentation,
|
||||||
|
tests and demonstration applications, are licensed under the following
|
||||||
|
conditions...
|
||||||
|
|
||||||
|
Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
|
||||||
|
jurisdictions which recognize such a disclaimer. In such jurisdictions,
|
||||||
|
this software is released into the Public Domain.
|
||||||
|
|
||||||
|
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
|
||||||
|
2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
|
||||||
|
The JsonCpp Authors, and is released under the terms of the MIT License (see below).
|
||||||
|
|
||||||
|
In jurisdictions which recognize Public Domain property, the user of this
|
||||||
|
software may choose to accept it either as 1) Public Domain, 2) under the
|
||||||
|
conditions of the MIT License (see below), or 3) under the terms of dual
|
||||||
|
Public Domain/MIT License conditions described here, as they choose.
|
||||||
|
|
||||||
|
The MIT License is about as close to Public Domain as a license can get, and is
|
||||||
|
described in clear, concise terms at:
|
||||||
|
|
||||||
|
http://en.wikipedia.org/wiki/MIT_License
|
||||||
|
|
||||||
|
The full text of the MIT License follows:
|
||||||
|
|
||||||
|
========================================================================
|
||||||
|
Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use, copy,
|
||||||
|
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
========================================================================
|
||||||
|
(END LICENSE TEXT)
|
||||||
|
|
||||||
|
The MIT license is compatible with both the GPL and commercial
|
||||||
|
software, affording one all of the rights of Public Domain with the
|
||||||
|
minor nuisance of being required to keep the above copyright notice
|
||||||
|
and license text in the source code. Note also that by accepting the
|
||||||
|
Public Domain "license" you can re-license your copy using whatever
|
||||||
|
license you like.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// End of content of file: LICENSE
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED
|
||||||
|
# define JSON_FORWARD_AMALGAMATED_H_INCLUDED
|
||||||
|
/// If defined, indicates that the source file is amalgamated
|
||||||
|
/// to prevent private header inclusion.
|
||||||
|
#define JSON_IS_AMALGAMATION
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// Beginning of content of file: include/json/version.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef JSON_VERSION_H_INCLUDED
|
||||||
|
#define JSON_VERSION_H_INCLUDED
|
||||||
|
|
||||||
|
// Note: version must be updated in three places when doing a release. This
|
||||||
|
// annoying process ensures that amalgamate, CMake, and meson all report the
|
||||||
|
// correct version.
|
||||||
|
// 1. /meson.build
|
||||||
|
// 2. /include/json/version.h
|
||||||
|
// 3. /CMakeLists.txt
|
||||||
|
// IMPORTANT: also update the SOVERSION!!
|
||||||
|
|
||||||
|
#define JSONCPP_VERSION_STRING "1.9.4"
|
||||||
|
#define JSONCPP_VERSION_MAJOR 1
|
||||||
|
#define JSONCPP_VERSION_MINOR 9
|
||||||
|
#define JSONCPP_VERSION_PATCH 4
|
||||||
|
#define JSONCPP_VERSION_QUALIFIER
|
||||||
|
#define JSONCPP_VERSION_HEXA \
|
||||||
|
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \
|
||||||
|
(JSONCPP_VERSION_PATCH << 8))
|
||||||
|
|
||||||
|
#ifdef JSONCPP_USING_SECURE_MEMORY
|
||||||
|
#undef JSONCPP_USING_SECURE_MEMORY
|
||||||
|
#endif
|
||||||
|
#define JSONCPP_USING_SECURE_MEMORY 0
|
||||||
|
// If non-zero, the library zeroes any memory that it has allocated before
|
||||||
|
// it frees its memory.
|
||||||
|
|
||||||
|
#endif // JSON_VERSION_H_INCLUDED
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// End of content of file: include/json/version.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// Beginning of content of file: include/json/allocator.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
||||||
|
// Distributed under MIT license, or public domain if desired and
|
||||||
|
// recognized in your jurisdiction.
|
||||||
|
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
||||||
|
|
||||||
|
#ifndef JSON_ALLOCATOR_H_INCLUDED
|
||||||
|
#define JSON_ALLOCATOR_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#pragma pack(push, 8)
|
||||||
|
|
||||||
|
namespace Json {
|
||||||
|
template <typename T> class SecureAllocator {
|
||||||
|
public:
|
||||||
|
// Type definitions
|
||||||
|
using value_type = T;
|
||||||
|
using pointer = T*;
|
||||||
|
using const_pointer = const T*;
|
||||||
|
using reference = T&;
|
||||||
|
using const_reference = const T&;
|
||||||
|
using size_type = std::size_t;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate memory for N items using the standard allocator.
|
||||||
|
*/
|
||||||
|
pointer allocate(size_type n) {
|
||||||
|
// allocate using "global operator new"
|
||||||
|
return static_cast<pointer>(::operator new(n * sizeof(T)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release memory which was allocated for N items at pointer P.
|
||||||
|
*
|
||||||
|
* The memory block is filled with zeroes before being released.
|
||||||
|
*/
|
||||||
|
void deallocate(pointer p, size_type n) {
|
||||||
|
// memset_s is used because memset may be optimized away by the compiler
|
||||||
|
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
|
||||||
|
// free using "global operator delete"
|
||||||
|
::operator delete(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an item in-place at pointer P.
|
||||||
|
*/
|
||||||
|
template <typename... Args> void construct(pointer p, Args&&... args) {
|
||||||
|
// construct using "placement new" and "perfect forwarding"
|
||||||
|
::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_type max_size() const { return size_t(-1) / sizeof(T); }
|
||||||
|
|
||||||
|
pointer address(reference x) const { return std::addressof(x); }
|
||||||
|
|
||||||
|
const_pointer address(const_reference x) const { return std::addressof(x); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy an item in-place at pointer P.
|
||||||
|
*/
|
||||||
|
void destroy(pointer p) {
|
||||||
|
// destroy using "explicit destructor"
|
||||||
|
p->~T();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Boilerplate
|
||||||
|
SecureAllocator() {}
|
||||||
|
template <typename U> SecureAllocator(const SecureAllocator<U>&) {}
|
||||||
|
template <typename U> struct rebind { using other = SecureAllocator<U>; };
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, typename U>
|
||||||
|
bool operator==(const SecureAllocator<T>&, const SecureAllocator<U>&) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename U>
|
||||||
|
bool operator!=(const SecureAllocator<T>&, const SecureAllocator<U>&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Json
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
#endif // JSON_ALLOCATOR_H_INCLUDED
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// End of content of file: include/json/allocator.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// Beginning of content of file: include/json/config.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
||||||
|
// Distributed under MIT license, or public domain if desired and
|
||||||
|
// recognized in your jurisdiction.
|
||||||
|
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
||||||
|
|
||||||
|
#ifndef JSON_CONFIG_H_INCLUDED
|
||||||
|
#define JSON_CONFIG_H_INCLUDED
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <istream>
|
||||||
|
#include <memory>
|
||||||
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
// If non-zero, the library uses exceptions to report bad input instead of C
|
||||||
|
// assertion macros. The default is to use exceptions.
|
||||||
|
#ifndef JSON_USE_EXCEPTION
|
||||||
|
#define JSON_USE_EXCEPTION 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Temporary, tracked for removal with issue #982.
|
||||||
|
#ifndef JSON_USE_NULLREF
|
||||||
|
#define JSON_USE_NULLREF 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// If defined, indicates that the source file is amalgamated
|
||||||
|
/// to prevent private header inclusion.
|
||||||
|
/// Remarks: it is automatically defined in the generated amalgamated header.
|
||||||
|
// #define JSON_IS_AMALGAMATION
|
||||||
|
|
||||||
|
// Export macros for DLL visibility
|
||||||
|
#if defined(JSON_DLL_BUILD)
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
#define JSON_API __declspec(dllexport)
|
||||||
|
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
|
||||||
|
#elif defined(__GNUC__) || defined(__clang__)
|
||||||
|
#define JSON_API __attribute__((visibility("default")))
|
||||||
|
#endif // if defined(_MSC_VER)
|
||||||
|
|
||||||
|
#elif defined(JSON_DLL)
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
#define JSON_API __declspec(dllimport)
|
||||||
|
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
|
||||||
|
#endif // if defined(_MSC_VER)
|
||||||
|
#endif // ifdef JSON_DLL_BUILD
|
||||||
|
|
||||||
|
#if !defined(JSON_API)
|
||||||
|
#define JSON_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||||
|
#error \
|
||||||
|
"ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||||
|
// As recommended at
|
||||||
|
// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
|
||||||
|
extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
|
||||||
|
const char* format, ...);
|
||||||
|
#define jsoncpp_snprintf msvc_pre1900_c99_snprintf
|
||||||
|
#else
|
||||||
|
#define jsoncpp_snprintf std::snprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
|
||||||
|
// integer
|
||||||
|
// Storages, and 64 bits integer support is disabled.
|
||||||
|
// #define JSON_NO_INT64 1
|
||||||
|
|
||||||
|
// JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools.
|
||||||
|
// C++11 should be used directly in JSONCPP.
|
||||||
|
#define JSONCPP_OVERRIDE override
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#if __has_extension(attribute_deprecated_with_message)
|
||||||
|
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||||
|
#endif
|
||||||
|
#elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc)
|
||||||
|
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
|
||||||
|
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||||
|
#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
|
||||||
|
#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
|
||||||
|
#endif // GNUC version
|
||||||
|
#elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates
|
||||||
|
// MSVC)
|
||||||
|
#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
|
||||||
|
#endif // __clang__ || __GNUC__ || _MSC_VER
|
||||||
|
|
||||||
|
#if !defined(JSONCPP_DEPRECATED)
|
||||||
|
#define JSONCPP_DEPRECATED(message)
|
||||||
|
#endif // if !defined(JSONCPP_DEPRECATED)
|
||||||
|
|
||||||
|
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6))
|
||||||
|
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(JSON_IS_AMALGAMATION)
|
||||||
|
|
||||||
|
#include "allocator.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
#endif // if !defined(JSON_IS_AMALGAMATION)
|
||||||
|
|
||||||
|
namespace Json {
|
||||||
|
using Int = int;
|
||||||
|
using UInt = unsigned int;
|
||||||
|
#if defined(JSON_NO_INT64)
|
||||||
|
using LargestInt = int;
|
||||||
|
using LargestUInt = unsigned int;
|
||||||
|
#undef JSON_HAS_INT64
|
||||||
|
#else // if defined(JSON_NO_INT64)
|
||||||
|
// For Microsoft Visual use specific types as long long is not supported
|
||||||
|
#if defined(_MSC_VER) // Microsoft Visual Studio
|
||||||
|
using Int64 = __int64;
|
||||||
|
using UInt64 = unsigned __int64;
|
||||||
|
#else // if defined(_MSC_VER) // Other platforms, use long long
|
||||||
|
using Int64 = int64_t;
|
||||||
|
using UInt64 = uint64_t;
|
||||||
|
#endif // if defined(_MSC_VER)
|
||||||
|
using LargestInt = Int64;
|
||||||
|
using LargestUInt = UInt64;
|
||||||
|
#define JSON_HAS_INT64
|
||||||
|
#endif // if defined(JSON_NO_INT64)
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using Allocator =
|
||||||
|
typename std::conditional<JSONCPP_USING_SECURE_MEMORY, SecureAllocator<T>,
|
||||||
|
std::allocator<T>>::type;
|
||||||
|
using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
|
||||||
|
using IStringStream =
|
||||||
|
std::basic_istringstream<String::value_type, String::traits_type,
|
||||||
|
String::allocator_type>;
|
||||||
|
using OStringStream =
|
||||||
|
std::basic_ostringstream<String::value_type, String::traits_type,
|
||||||
|
String::allocator_type>;
|
||||||
|
using IStream = std::istream;
|
||||||
|
using OStream = std::ostream;
|
||||||
|
} // namespace Json
|
||||||
|
|
||||||
|
// Legacy names (formerly macros).
|
||||||
|
using JSONCPP_STRING = Json::String;
|
||||||
|
using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
|
||||||
|
using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
|
||||||
|
using JSONCPP_ISTREAM = Json::IStream;
|
||||||
|
using JSONCPP_OSTREAM = Json::OStream;
|
||||||
|
|
||||||
|
#endif // JSON_CONFIG_H_INCLUDED
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// End of content of file: include/json/config.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// Beginning of content of file: include/json/forwards.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
||||||
|
// Distributed under MIT license, or public domain if desired and
|
||||||
|
// recognized in your jurisdiction.
|
||||||
|
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
||||||
|
|
||||||
|
#ifndef JSON_FORWARDS_H_INCLUDED
|
||||||
|
#define JSON_FORWARDS_H_INCLUDED
|
||||||
|
|
||||||
|
#if !defined(JSON_IS_AMALGAMATION)
|
||||||
|
#include "config.h"
|
||||||
|
#endif // if !defined(JSON_IS_AMALGAMATION)
|
||||||
|
|
||||||
|
namespace Json {
|
||||||
|
|
||||||
|
// writer.h
|
||||||
|
class StreamWriter;
|
||||||
|
class StreamWriterBuilder;
|
||||||
|
class Writer;
|
||||||
|
class FastWriter;
|
||||||
|
class StyledWriter;
|
||||||
|
class StyledStreamWriter;
|
||||||
|
|
||||||
|
// reader.h
|
||||||
|
class Reader;
|
||||||
|
class CharReader;
|
||||||
|
class CharReaderBuilder;
|
||||||
|
|
||||||
|
// json_features.h
|
||||||
|
class Features;
|
||||||
|
|
||||||
|
// value.h
|
||||||
|
using ArrayIndex = unsigned int;
|
||||||
|
class StaticString;
|
||||||
|
class Path;
|
||||||
|
class PathArgument;
|
||||||
|
class Value;
|
||||||
|
class ValueIteratorBase;
|
||||||
|
class ValueIterator;
|
||||||
|
class ValueConstIterator;
|
||||||
|
|
||||||
|
} // namespace Json
|
||||||
|
|
||||||
|
#endif // JSON_FORWARDS_H_INCLUDED
|
||||||
|
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
// End of content of file: include/json/forwards.h
|
||||||
|
// //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue