添加类、函数注释

This commit is contained in:
Jingfan Ke 2024-07-29 14:29:33 +08:00
parent 4b8460f4ce
commit 26f9ff604e
12 changed files with 407 additions and 151 deletions

170
HF15693.h
View File

@ -76,115 +76,115 @@ extern HF15693_API char t15UID[UID_LEN], t15FirstBN[3], t15NumBl[3], t15Data[DAT
//////////////////////////////
//工具函数
/*********************************************
/* 描述:打开串口
/* 输入:串口号如若打开com1则参数为 1
/* 输出:无
/* 返回:true 打开成功false 打开失败
/* 其他:
/*********************************************/
/*
* :
* :com1 1
* :
* :true false
* :
*/
HF15693_API bool t15portOpen(int comno);
/*********************************************
/* 描述:关闭串口
/* 输入:无
/* 输出:无
/* 返回:true 关闭成功false 关闭失败
/* 其他:
/*********************************************/
/*
* :
* :
* :
* :true false
* :
*/
HF15693_API bool t15portClose();
/*********************************************
/* 描述:设置协议
/* 输入:无
/* 输出:无
/* 返回: 0 设置成功; ~0 设置失败
/* 其他:
/*********************************************/
/*
* :
* :
* :
* : 0 ~0
* :
*/
HF15693_API int t15setProtocol();
/*********************************************
/* 描述:执行命令
/* 输入:cmdno - 命令字
/* 输出:cmdstr - 向下发出的命令字段reply - 对命令回复的字段
/* 返回:(int) 命令回复字段中的有效字节数
/* 其他:
/*********************************************/
/*
* :
* :cmdno -
* :cmdstr - reply -
* :(int)
* :
*/
HF15693_API int t15execute(int cmdno, char *cmdstr,char *reply);
/////////////////////////////////////
/*********************************************
/* 描述:从一个字串中提取一个表示十六进制数字的子串,子串间以',' '[' 分隔
/* 输入: str - 原字串
/* 输出: str - 指向原串中提取到的子串的下一下字符, word - 提取到的子串
/* 返回: 0 - 成功 1 - 失败
/* 其他:
/*********************************************/
/*
* :',' '['
* : str -
* : str - word -
* : 0 - 1 -
* :
*/
HF15693_API int getXWord (char **str, char *word);
/*********************************************
/* 描述:从一个字串中提取一个表示十六进制数字的子串,子串间以',' '[' 分隔
/* 输入: str - 原字串
/* 输出: word - 提取到的子串
/* 返回:
/* 其他:
/*********************************************/
/*
* :',' '['
* : str -
* : word -
* :
* :
*/
HF15693_API int getXWord2 ( char *str, char *word);
/*********************************************
/* 描述:更改字节序
/* 输入:pin - 原字串 lenbytes - 字串数据长度
/* 输出:pout - 更改字节序后的字串
/* 返回:无
/* 其他:此函数会在pout后补0使用者须保证其长度。
/* 如,字串"123456" 更改字节序后变为 "563412"
/*********************************************/
/*
* :
* :pin - lenbytes -
* :pout -
* :
* :pout后补0使
* "123456" "563412"
*/
HF15693_API void t15changeByteOrder(char *pout,const char *pin,int lenbytes);
/*********************************************
/* 描述:更改带块安全状态信息(block security status)的字串的字节序
/* 输入:pin - 原字串 lenbytes - 字串数据长度,不包含'块安全状态信息'的长度
/* 输出:sbss - 原字串中的bss值 pout - 更改字节序后的字串
/* 返回:无
/* 其他:字串的存储空间由使用者保证会在pout后补0sbss是用字串表示的一个字节的十六进制数
/*********************************************/
/*
* :(block security status)
* :pin - lenbytes - ''
* :sbss - bss值 pout -
* :
* :使pout后补0sbss是用字串表示的一个字节的十六进制数
*/
HF15693_API void t15changeByteOrder2(char *sbss,char *pout, char *pin,int lenbytes);
/*********************************************
/* 描述:更改字串的字节序,字串包含多个块的数据
/* 输入:pin - 原字串 numblocks - 原字串中包含的块数目
/* 输出:pout - 更改字节序后的字串
/* 返回:无
/* 其他:每个块数据长度由pin长度和numblocks决定会在pout后补0
/*********************************************/
/*
* :,
* :pin - numblocks -
* :pout -
* :
* :pin长度和numblocks决定pout后补0
*/
HF15693_API void t15changeByteOrder_MB(char *pout, char *pin, int numblocks);
/*********************************************
/* 描述:更改带块安全状态信息(block security status)的字串的字节序,字串包含多个块的数据
/* 输入:pin - 原字串;lenbytes - 字串数据长度,不包含'块安全状态信息'的长度; numblocks - 原字串中包含的块数目
/* 输出:mbss - 原字串中的bss值 pout - 更改字节序后的字串
/* 返回:无
/* 其他:各个块的bss依次存放于mbss中多个块的数据依次存放于pout中
/*********************************************/
/*
* :(block security status),
* :pin - ;lenbytes - ''; numblocks -
* :mbss - bss值 pout -
* :
* :bss依次存放于mbss中pout中
*/
HF15693_API void t15changeByteOrder_MB2(char *mbss,char *pout, char *pin,int lenbytes, int numblocks);
/*********************************************
/* 描述:解析返回的RSSI值
/* 输入:字串表示的RSSI
/* 输出:无
/* 返回:指向解析过的RSSI信息的内存块
/* 其他:返回的指针指向的内存由函数分配管理
/*********************************************/
/*
* :RSSI值
* :RSSI
* :
* :RSSI信息的内存块
* :
*/
HF15693_API char* t15hex2rssi (char *str);
/*********************************************
/* 描述:解析标签信息字串
/* 输入:data - 原标签信息字串flag - 标签信息标志
/* 输出:(其他参数)
/* 返回:0
/* 其他:
/*********************************************/
/*
* :
* :data - flag -
* :()
* :0
* :
*/
HF15693_API int t15getTagSysInfo (char *data, const unsigned char flag,char *uid, char *dsfid, char *afi,
char *blSize, char *numBl, char *ic);

View File

@ -1,5 +1,13 @@
#include "databaseAPI.h"
/**
* @brief 使QSqlDatabase类初始化对象
* @param database QSqlDatabase对象
* @return void
* @author
* @date 2024-07-28
*/
Database::Database(QSqlDatabase database)
{
db = database;
@ -7,6 +15,17 @@ Database::Database(QSqlDatabase database)
db.setUserName(userName);
}
/**
* @brief 使QSqlDatabase类IP
* @param database QSqlDatabase对象
* @param hostName IP
* @param port
* @param password
* @return void
* @author
* @date 2024-07-28
*/
Database::Database(QSqlDatabase database, QString hostName, int port, QString password)
{
db = database;
@ -17,47 +36,124 @@ Database::Database(QSqlDatabase database, QString hostName, int port, QString pa
db.setPassword(password);
}
/**
* @brief database属性
* @param void
* @return QSqlDatabase类database属性
* @author
* @date 2024-07-28
*/
QSqlDatabase Database::getDatabase()
{
return db;
}
/**
* @brief hostName属性
* @param hostName IP
* @return void
* @author
* @date 2024-07-28
*/
void Database::setHostName(QString hostName)
{
db.setHostName(hostName);
}
/**
* @brief hostName属性
* @param void
* @return QString类hostName属性
* @author
* @date 2024-07-28
*/
QString Database::getHostName()
{
return db.hostName();
}
/**
* @brief port属性
* @param port
* @return void
* @author
* @date 2024-07-28
*/
void Database::setPort(int port)
{
db.setPort(port);
}
/**
* @brief port属性
* @param void
* @return int类port属性
* @author
* @date 2024-07-28
*/
int Database::getPort()
{
return db.port();
}
/**
* @brief password属性
* @param password
* @return void
* @author
* @date 2024-07-28
*/
void Database::setPassword(QString password)
{
db.setPassword(password);
}
/**
* @brief
* @param void
* @return
* - true
* - false
* @author
* @date 2024-07-28
*/
bool Database::is_connected()
{
return connected;
}
/**
* @brief
* connect属性上
* @param void
* @return
* - true
* - false
* @author
* @date 2024-07-28
*/
bool Database::open()
{
connected = db.open();
return connected;
}
/**
* @brief
*
* @param void
* @return void
* @author
* @date 2024-07-28
*/
Database::~Database()
{
db.close();

View File

@ -1,11 +1,18 @@
#ifndef DATABASEAPI_H
#define DATABASEAPI_H
#include <QSqlDatabase>
#include <QString>
/**
* @class Database
* @brief
* databaseName为"cardManageSystem"userName为"cardManageSystem"
*
* @author
* @date 2024-07-28
*/
class Database
{
private:
@ -17,15 +24,19 @@ private:
public:
Database(QSqlDatabase database);
Database(QSqlDatabase database, QString hostName, int port, QString password);
QSqlDatabase getDatabase();
void setHostName(QString hostName);
QString getHostName();
void setPort(int port);
int getPort();
void setPassword(QString password);
bool is_connected();
bool open();
~Database();
void setHostName(QString hostName);
void setPort(int port);
void setPassword(QString password);
QSqlDatabase getDatabase();
int getPort();
QString getHostName();
bool is_connected();
bool open();
};

View File

@ -1,39 +1,78 @@
#include "deviceAPI.h"
bool Device::is_connected()
/**
* @brief
* @param void
* @return
* - true
* - false
* @author
* @date 2024-07-28
*/
bool Device::is_verified()
{
return connected;
return verified;
}
/**
* @brief
* @param void
* @return
* - true
* - false
* @author
* @date 2024-07-29
*/
bool Device::is_depositAllowed()
{
return depositAllowed;
}
void Device::setDevice(QString name, Database *db)
/**
* @brief
*
* @param name
* @param db
* @return void
* @author
* @date 2024-07-28
*/
void Device::setDevice(QString name, Database* db)
{
QSqlQuery query(db->getDatabase());
QString sql = QString("select * from device where `name` = '%1';").arg(name);
query.exec(sql);
if (query.next())
{
connected = true;
verified = true;
this->name = name;
depositAllowed = query.value(2).toBool();
}
else
{
connected = false;
verified = false;
depositAllowed = false;
}
}
/**
* @brief
* @param void
* @return QString类name属性
* - "未指定设备名"
* -
* - "(可充值)"
* - "(仅可消费)
* @author
* @date 2024-07-28
*/
QString Device::getName()
{
if (connected) {
if (verified) {
if (depositAllowed) return name + QString("(可充值)");
else return name + QString("(仅可消费)");
}

View File

@ -5,18 +5,28 @@
#include <QSqlQuery>
#include <databaseAPI.h>
/**
* @class Device
* @brief
*
* @author
* @date 2024-07-28
*/
class Device
{
private:
bool connected = false;
bool verified = false;
bool depositAllowed = false;
QString name = QString("未指定设备名");
public:
bool is_connected();
bool is_depositAllowed();
void setDevice(QString name, Database *db);
QString getName();
bool is_verified();
bool is_depositAllowed();
};
#endif // DEVICEAPI_H

View File

@ -1,9 +1,11 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "settingPage.cpp"
#include "quitAppPage.cpp"
#include "newCardPage.cpp"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)

View File

@ -39,8 +39,6 @@ private slots:
void on_connectDatabaseButton_clicked();
void on_inventoryButton_clicked();
private:
Ui::MainWindow *ui;
Reader reader;

View File

@ -2,10 +2,16 @@
#include "ui_mainwindow.h"
/*
*
*
*/
/**
* @brief
*
* -
* -
* @param void
* @return void
* @author
* @date 2024-07-28
*/
void MainWindow::on_NewCardAction_triggered()
{
if (!ready())
@ -22,13 +28,17 @@ void MainWindow::on_NewCardAction_triggered()
}
/*
*
*
*/
/**
* @brief
* Inventory的查询结果10
* @param void
* @return void
* @author
* @date 2024-07-29
*/
void MainWindow::on_inventoryButton_clicked()
{
QStringList cardIdList = reader.inventory(10); // 最多显示10张卡
QStringList cardIdList = reader.inventory(10); // 最多显示10张卡
ui->cardIdBox->clear();
ui->cardIdBox->addItems(cardIdList);
}

View File

@ -2,20 +2,28 @@
#include "ui_mainwindow.h"
/*
* 退
* 退
*/
/**
* @brief 退
* 退
* @param void
* @return void
* @author
* @date 2024-07-27
*/
void MainWindow::on_quitAppAction_triggered()
{
ui->stackedWidget->setCurrentWidget(ui->quitAppPage);
}
/*
* 退
* 退
*/
/**
* @brief 退
* 退
* @param void
* @return void
* @author
* @date 2024-07-27
*/
void MainWindow::on_confirmQuitButton_clicked()
{
this->close();

View File

@ -1,12 +1,32 @@
#include "readerAPI.h"
/**
* @brief
* comNumber是否大于0判断
* @param void
* @return
* - true
* - false
* @author
* @date 2024-07-27
*/
/// \brief 判断读卡器是否已连接
/// \return 如果comNumber大于0表示已连接返回true否则返回false
bool Reader::is_connected()
{
return comNumber > 0;
}
/**
* @brief
* comNumber连接读卡器truefalse并重置comNumber为-1
* @param void
* @return truefalse
* @author
* @date 2024-07-27
*/
bool Reader::connect()
{
if (CVCDOurs::connectReaderByCOM(comNumber))
@ -20,27 +40,63 @@ bool Reader::connect()
}
}
/**
* @brief COM口号
* @param comNumber COM口号
* @return void
* @author
* @date 2024-07-27
*/
void Reader::setComNumber(int comNumber)
{
this->comNumber = comNumber;
}
/**
* @brief COM口号
* @param void
* @return COM口号
* - -1
* - >0
* @author
* @date 2024-07-27
*/
int Reader::getComNumber()
{
return comNumber;
}
/**
* @brief UID列表
* inventory方法获取最大数量为maxViccNum的卡片UIDQStringList返回
* @param maxViccNum
* @return UID的QStringList
* @author
* @date 2024-07-29
*/
QStringList Reader::inventory(int maxViccNum)
{
// 分配内存用于存储卡片的UID
uchar_t (*aucUID)[8] = (uchar_t (*)[8])malloc(maxViccNum * sizeof(*aucUID));;
// 调用CVCDOurs::inventory方法获取卡片数量
int receivedViccNum = CVCDOurs::inventory(false, '\0', maxViccNum, nullptr, aucUID);
// 用于存储UID的QStringList
QStringList uidList;
for (int i = 0; i < receivedViccNum; ++i)
{
char uidStr[8];
// 将UID从十六进制转换为字符串
CVCDOurs::HexToString(aucUID[i], 8, uidStr);
// 将字符串转换为QString并添加到uidList中
uidList.push_back(QString::fromStdString(uidStr));
}
// 释放分配的内存
free(aucUID);
return uidList;
}

View File

@ -2,24 +2,32 @@
#define READERAPI_H
#include <HF15693.h>
#include <cstdio>
#include <cstring>
#include <QString>
#include <QStringList>
#include <VCDOurs.h>
typedef unsigned char uchar_t;
/**
* @class Reader
* @brief
* RFID读卡器的连接和操作COM口号UID列表等功能
* @author
* @date 2024-07-27
*/
class Reader : private CVCDOurs
{
private:
int comNumber = -1; // com口号若未连接为-1
int comNumber = -1; ///< 硬件连接com口号若未连接为-1
public:
bool is_connected();
bool connect();
void setComNumber(int comNumber);
int getComNumber();
bool is_connected();
bool connect();
QStringList inventory(int maxViccNum);
};

View File

@ -2,21 +2,27 @@
#include "ui_mainwindow.h"
/*
*
*
*/
/**
* @brief
*
* @param void
* @return void
* @author
* @date 2024-07-27
*/
void MainWindow::on_settingAction_triggered()
{
ui->stackedWidget->setCurrentWidget(ui->settingPage);
}
/*
* COM口号并更新状态栏的相应内容
* COM口号
*
*/
/**
* @brief COM口号相关内容
* @param void
* @return void
* @author
* @date 2024-07-27
*/
void MainWindow::updateStatusBarComNumber()
{
if (reader.is_connected())
@ -34,10 +40,14 @@ void MainWindow::updateStatusBarComNumber()
}
/*
*
*
*/
/**
* @brief
*
* @param void
* @return void
* @author
* @date 2024-07-27
*/
void MainWindow::on_connectReaderButton_clicked()
{
int comNumber = ui->comNumberBox->value();
@ -54,10 +64,14 @@ void MainWindow::on_connectReaderButton_clicked()
}
/*
*
*
*/
/**
* @brief
*
* @param void
* @return void
* @author
* @date 2024-07-27
*/
void MainWindow::on_connectDatabaseButton_clicked()
{
if (db == nullptr)
@ -82,7 +96,7 @@ void MainWindow::on_connectDatabaseButton_clicked()
databaseLabel->setText(QString("数据库已连接:") + db->getHostName() + QString(":") + QString::number(db->getPort()));
device.setDevice(ui->deviceEdit->text(), db);
if (!device.is_connected())
if (!device.is_verified())
{
QMessageBox::warning(this, QString("设备名提示"), QString("该设备名无效,请重试。"));
}
@ -90,15 +104,19 @@ void MainWindow::on_connectDatabaseButton_clicked()
}
/*
*
*
* true - | false -
*/
/**
* @brief
* @param void
* @return
* - true
* - false
* @author
* @date 2024-07-27
*/
bool MainWindow::ready()
{
if (!reader.is_connected()) return false;
if (db == nullptr || !db->is_connected()) return false;
if (!device.is_connected()) return false;
if (!device.is_verified()) return false;
return true;
}