Browse Source

update

master
zhaohe 1 year ago
parent
commit
9b7f230962
  1. 3
      CMakeLists.txt
  2. 50
      src/basic/format_memory.cpp
  3. 6
      src/basic/format_memory.hpp
  4. 3
      src/mainwindow.cpp
  5. 96
      src/tab/id_card_read_tab.cpp
  6. 43
      src/tab/id_card_read_tab.hpp
  7. 60
      test/test.cpp

3
CMakeLists.txt

@ -62,6 +62,9 @@ set(PROJECT_SOURCES
src/tab/xyrobot_tab.cpp
src/tab/id_card_read_tab.cpp
src/basic/format_memory.cpp
app.rc
)

50
src/basic/format_memory.cpp

@ -0,0 +1,50 @@
#include "format_memory.hpp"
// 函数:格式化内存并存储到 string 中
std::string format_memory(const void* ptr, size_t size) {
std::ostringstream oss;
const unsigned char* buffer = static_cast<const unsigned char*>(ptr);
const size_t bytes_per_line = 16;
for (size_t i = 0; i < size; i += bytes_per_line) {
// 格式化地址
oss << std::hex << std::setw(8) << std::setfill('0') << i << ": ";
// 格式化每一行的内容
for (size_t j = 0; j < bytes_per_line; ++j) {
if (i + j < size) {
// 格式化字节的十六进制值
oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(buffer[i + j]) << " ";
} else {
// 对于填充空白处
oss << " ";
}
// 格式化可打印字符,非打印字符用'.'表示
if (j == (bytes_per_line / 2) - 1) {
oss << " ";
}
}
oss << " ";
// 格式化每一行的可打印字符
for (size_t j = 0; j < bytes_per_line; ++j) {
if (i + j < size) {
char c = buffer[i + j];
// 判断是否为可打印字符
if (c >= 32 && c <= 126) {
oss << c;
} else {
oss << ".";
}
} else {
// 对于填充空白处
oss << " ";
}
}
oss << std::endl;
}
return oss.str();
}

6
src/basic/format_memory.hpp

@ -0,0 +1,6 @@
#pragma once
#include <iomanip>
#include <iostream>
#include <sstream>
std::string format_memory(const void* ptr, size_t size);

3
src/mainwindow.cpp

@ -24,6 +24,7 @@
#include "tab/board_ext_tab.hpp"
#include "tab/code_scaner_tab.hpp"
#include "tab/fan_ctrl_tab.hpp"
#include "tab/id_card_read_tab.hpp"
#include "tab/mini_servo_tab.hpp"
#include "tab/module_opera_tab.hpp"
#include "tab/pipette_ctrl_tab.hpp"
@ -304,6 +305,8 @@ void MainWindow::constructAppUI() {
WaterCoolingTemperatureControlerTab::inst()->construct(ui->buttonTabWidget);
FanCtrlTab::inst()->construct(ui->buttonTabWidget);
XYRobotTab::inst()->construct(ui->buttonTabWidget);
IDCardReaderTab::inst()->construct(ui->buttonTabWidget);
}
void MainWindow::on_PublicState_ConfirmKey_clicked() {}

96
src/tab/id_card_read_tab.cpp

@ -0,0 +1,96 @@
#include "id_card_read_tab.hpp"
#include "iflytop_canbus/iflytop_canbus_master.hpp"
#include "logger.hpp"
#include "qt_serial_datachannel.hpp"
#include "zexception.hpp"
#include "zui/z_function_list_box.hpp"
#include "zui/z_reg_table_list_box.hpp"
#include "zui/zq_vtab_page.hpp"
//
#include "../basic/format_memory.hpp"
#include "../basic/stm32_pin.hpp"
#include "./mainwindow.h"
#include "zui\zqui.hpp"
//
using namespace iflytop;
using namespace std;
extern Ui::MainWindow *main_ui;
extern int getDeviceId();
IDCardReaderTab *IDCardReaderTab::inst() {
static IDCardReaderTab *ins = new IDCardReaderTab();
return ins;
}
static inline const char *hex2binstr(int32_t hex) {
static char buf[32];
sprintf(buf, "%d%d%d%d_%d%d%d%d", (hex >> 7) & 1, (hex >> 6) & 1, (hex >> 5) & 1, (hex >> 4) & 1, (hex >> 3) & 1, (hex >> 2) & 1, (hex >> 1) & 1, (hex >> 0) & 1);
return buf;
}
/**
* @brief
* format_memery
*
* 00 01 02 03 04 05 06 07 08 09 A B C D E F
* 12 34 57 90 AA XX XX XX XX XX XX XX XX XX ...dsfa..
* 12 34 57 90 AA XX XX XX XX XX XX XX XX XX ...dsfa..
* 12 34 57 90 AA XX XX XX XX XX XX XX XX XX ...dsfa..
* 12 34 57 90 AA XX XX XX XX XX XX XX XX XX ...dsfa..
*
*/
string format_memery(uint8_t *mem, int len) {
string result = "";
char buf[128];
}
void IDCardReaderTab::construct(QTabWidget *fathertab) {
ZQVTabPage *tab = new ZQVTabPage(fathertab, "A8K读卡器");
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
{
ZQFunctionListBox *box = new ZQFunctionListBox(tab, "方法", 4);
box->newFunc("读卡", {"sector_index"}, [this](int argn, const char **args) {
int32_t sector_index = atoi(args[0]);
ICM->callcmd1(getDeviceId(), ka8000_idcard_reader_read_raw, sector_index);
uint8_t *resultbuf = ICM->getAckBuf();
int32_t resultlen = ICM->getAckBufLen();
if (resultlen > 0) {
QString result = QString(format_memory(resultbuf, resultlen).c_str());
ZQUI::ins()->ishow("读卡结果: %s", result.toStdString().c_str());
} else {
ZQUI::ins()->ishow("读卡失败");
}
});
}
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
{
ZRegTableList *tableBox = new ZRegTableList(tab, "寄存器操作");
tableBox->initializeRegOperation(
[this](int32_t add, int32_t val) { //
ICM->writereg(getDeviceId(), add, val);
return true;
},
[this](int32_t add, int32_t *val) { //
ICM->readreg(getDeviceId(), add, val);
return true;
});
tableBox->addReg("reg_id_card_reader_raw_sector_size", kreg_id_card_reader_raw_sector_size, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_id_card_reader_raw_sector_num", kreg_id_card_reader_raw_sector_num, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_id_card_reader_is_online", kreg_id_card_reader_is_online, ZRegItem::krw | ZRegItem::kdec);
tableBox->addSpacer();
}
tab->addSpacer();
}

43
src/tab/id_card_read_tab.hpp

@ -0,0 +1,43 @@
#pragma once
#include <QDateTime>
#include <QMainWindow>
#include <QMessageBox>
#include <QObject>
#include <QtConcurrent>
#include <QtCore/QVariant>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QTextBrowser>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
//
#include <functional>
namespace iflytop {
using namespace std;
class IDCardReaderTab {
public:
static IDCardReaderTab *inst();
void construct(QTabWidget *fathertab);
};
} // namespace iflytop

60
test/test.cpp

@ -0,0 +1,60 @@
#include <iostream>
#include <iomanip>
#include <sstream>
// 函数:格式化内存并存储到 string 中
std::string format_memory(const void* ptr, size_t size) {
std::ostringstream oss;
const unsigned char* buffer = static_cast<const unsigned char*>(ptr);
const size_t bytes_per_line = 16;
for (size_t i = 0; i < size; i += bytes_per_line) {
// 格式化地址
oss << std::hex << std::setw(8) << std::setfill('0') << i << ": ";
// 格式化每一行的内容
for (size_t j = 0; j < bytes_per_line; ++j) {
if (i + j < size) {
// 格式化字节的十六进制值
oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(buffer[i + j]) << " ";
} else {
// 对于填充空白处
oss << " ";
}
// 格式化可打印字符,非打印字符用'.'表示
if (j == (bytes_per_line / 2) - 1) {
oss << " ";
}
}
oss << " ";
// 格式化每一行的可打印字符
for (size_t j = 0; j < bytes_per_line; ++j) {
if (i + j < size) {
char c = buffer[i + j];
// 判断是否为可打印字符
if (c >= 32 && c <= 126) {
oss << c;
} else {
oss << ".";
}
} else {
// 对于填充空白处
oss << " ";
}
}
oss << std::endl;
}
return oss.str();
}
int main() {
int array[] = {1, 2, 3, 4, 5};
std::string formatted_memory = format_memory(array, sizeof(array));
std::cout << formatted_memory << std::endl;
return 0;
}
Loading…
Cancel
Save