#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <signal.h> #include <sys/ptrace.h> #include <sys/user.h> #define DR7_ENABLE_MASK 0x1 #define DR7_LEN_4BYTE (0x2 << 16) #define DR7_TYPE_EXEC (0x0 << 20) // 断点处理函数 void signalHandler(int sig, siginfo_t* info, void* context) { ucontext_t* ucontext = (ucontext_t*)context; // 获取触发断点的地址 uintptr_t pc = (uintptr_t)ucontext->uc_mcontext.pc; printf("Breakpoint hit at 0x%lx\n", pc); // 恢复执行(实际应用中需处理寄存器/内存) ptrace(PTRACE_CONT, getpid(), NULL, 0); } void setHardwareBreakpoint(uintptr_t addr) { pid_t pid = getpid(); // 附加到当前进程 if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) { perror("ptrace attach"); return; } // 等待附加完成 wait(NULL); // 设置调试寄存器 struct user_hwdebug_state debug_state; debug_state.dbg_regs[0].addr = addr; debug_state.dbg_regs[0].ctrl = DR7_ENABLE_MASK | DR7_LEN_4BYTE | DR7_TYPE_EXEC; // 使用PTRACE_SETREGSET设置调试寄存器 struct iovec iov; iov.iov_base = &debug_state; iov.iov_len = sizeof(debug_state); if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == -1) { perror("ptrace setregset"); return; } // 分离进程 ptrace(PTRACE_DETACH, pid, NULL, NULL); // 设置信号处理 struct sigaction sa; sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = signalHandler; sigemptyset(&sa.sa_mask); if (sigaction(SIGTRAP, &sa, NULL) == -1) { perror("sigaction"); return; } printf("Hardware breakpoint set at 0x%lx\n", addr); } void setupBreakpoint() { std::ifstream addrFile("/sdcard/addr.txt"); if (!addrFile.is_open()) { perror("Failed to open address file"); return; } std::string line; if (std::getline(addrFile, line)) { uintptr_t addr = strtoull(line.c_str(), nullptr, 0); setHardwareBreakpoint(addr); } else { printf("No address found in file\n"); } addrFile.close(); }编写hook示例

时间: 2025-07-10 10:36:27 浏览: 12
<think>好的,我现在需要帮助用户理解他们提供的C++代码,并编写一个hook示例。首先,我要仔细阅读用户提供的代码,了解它的功能和结构。 看起来这段代码是关于在Linux环境下设置硬件断点的。代码中使用了ptrace系统调用和调试寄存器,这通常用于调试或监控程序执行。用户还提到这是一个hook示例,所以可能他们想了解如何利用这些技术来拦截函数调用或修改程序行为。 首先,我需要确认代码的结构。代码包含了几个头文件,比如stdio、stdint、stdlib,这些都是标准库。signal.h和sys/ptrace.h以及sys/user.h表明代码涉及信号处理和进程跟踪。结构体user_hwdebug_state可能用于设置调试寄存器的状态。 接下来,signalHandler函数是信号处理函数,当触发断点时会被调用。它接收信号信息,获取触发断点的地址,然后继续执行进程。这里需要注意,ucontext结构可能因平台而异,用户代码中的pc获取是否正确?例如,在ARM和x86架构下,寄存器的位置可能不同,但代码中的注释提到NT_ARM_HW_WATCH,可能这是针对ARM架构的代码。 setHardwareBreakpoint函数负责附加到当前进程,设置调试寄存器。这里使用了PTRACE_ATTACH和PTRACE_SETREGSET来配置硬件断点。调试寄存器0被设置为指定的地址,控制位包括启用、长度4字节和执行类型。这可能用于在指定地址执行时触发断点。 setupBreakpoint函数从文件中读取地址,并调用setHardwareBreakpoint。但这里有一个问题,代码中使用的是std::ifstream,这是C++的标准库,但原始代码中并没有包含<fstream>头文件,这可能导致编译错误。另外,在C程序中使用C++的文件操作可能不合适,用户可能需要确认这是C还是C++代码。 现在用户希望得到一个hook示例,而当前代码设置的是硬件执行断点,当执行到某个地址时触发信号处理函数。这可以视为一种hook方法,通过断点插入自定义处理逻辑。 可能的步骤是: 1. 设置硬件断点,在目标函数地址处。 2. 当执行到该地址时,触发SIGTRAP信号,进入信号处理函数。 3. 在信号处理函数中执行自定义代码,如修改参数、返回值等。 4. 恢复程序执行。 但用户的当前代码中,signalHandler只是打印信息并继续执行,没有修改任何寄存器或内存。因此,如果要实现hook,需要在信号处理函数中添加更多的逻辑,比如改变寄存器中的值,或者跳转到其他函数。 需要注意的问题包括: - 不同架构(x86 vs ARM)的寄存器访问方式不同,代码中的pc获取是否正确。 - 使用ptrace的正确性,特别是在附加和分离进程时的权限问题。 - 信号处理函数中的异步安全函数使用,例如printf可能不太安全,但在示例中可能可以接受。 可能的改进点: - 在信号处理函数中,通过修改ucontext中的寄存器值,改变程序流程,比如将PC指向替换的函数。 - 在处理完hook逻辑后,可能需要单步执行或调整断点,避免重复触发。 - 确保地址的正确性,特别是在ASLR启用的情况下,需要正确获取目标函数的地址。 现在,我需要将这些思考整理成一个结构化的回答,帮助用户理解代码的工作原理,并提供一个更完整的hook示例。可能需要分步骤解释代码,指出潜在的问题,并展示如何扩展信号处理函数以实现hook功能。同时,要注意用户提到的使用中文回答,以及LaTeX格式的要求,但在当前上下文中可能涉及代码较多,数学表达式较少,但如果有变量或技术术语,需按照规则处理。</think>以下是对您提供的硬件断点代码的分析及一个改进的Hook实现示例: $$ \text{Hook实现原理} = \begin{cases} \text{断点触发} & \rightarrow \text{SIGTRAP信号} \\ \text{信号处理} & \rightarrow \text{修改执行流/寄存器} \\ \text{恢复执行} & \rightarrow \text{继续原逻辑/跳转新逻辑} \end{cases} $$ 一、原代码分析 1. 架构问题:使用了`NT_ARM_HW_WATCH`,表明针对ARM架构设计,若在x86需改为`NT_X86_DR7` 2. 类型选择:`DR7_TYPE_EXEC`表示执行断点,对应$dr7[16:17]=0b00$ 3. 生命周期:`PTRACE_ATTACH`附加进程后应立即处理寄存器状态 二、增强版Hook示例 ```c #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <signal.h> #include <sys/ptrace.h> #include <sys/user.h> #include <ucontext.h> #define DR7_ENABLE_MASK (0x1 << 0) #define DR7_LEN_4BYTE (0x2 << 16) #define DR7_TYPE_EXEC (0x0 << 20) // 原始函数指针 typedef void (*TargetFunc)(const char*); volatile TargetFunc originalFunc = NULL; volatile uintptr_t hookTrampoline = 0; void signalHandler(int sig, siginfo_t* info, void* context) { ucontext_t* uctx = (ucontext_t*)context; // 获取触发地址 uintptr_t pc = (uintptr_t)uctx->uc_mcontext.gregs[REG_RIP]; // x86_64 if (pc == (uintptr_t)originalFunc) { printf("Hooked function called!\n"); // 修改第一个参数为"hooked message" uctx->uc_mcontext.gregs[REG_RDI] = (greg_t)"hooked message"; // 跳转到原始函数+2指令地址(跳过int3) uctx->uc_mcontext.gregs[REG_RIP] = hookTrampoline; } ptrace(PTRACE_CONT, getpid(), 0, 0); } void installHook(uintptr_t targetAddr, uintptr_t trampoline) { struct sigaction sa; sa.sa_flags = SA_SIGINFO | SA_NODEFER; sa.sa_sigaction = signalHandler; sigemptyset(&sa.sa_mask); sigaction(SIGTRAP, &sa, NULL); // 设置硬件断点 struct user_hwdebug_state debug_state = {0}; debug_state.dbg_regs[0].addr = targetAddr; debug_state.dbg_regs[0].ctrl = DR7_ENABLE_MASK | DR7_LEN_4BYTE | DR7_TYPE_EXEC; struct iovec iov = { &debug_state, sizeof(debug_state) }; ptrace(PTRACE_ATTACH, getpid(), NULL, NULL); wait(NULL); ptrace(PTRACE_SETREGSET, getpid(), NT_X86_DR7, &iov); // x86使用DR7 ptrace(PTRACE_DETACH, getpid(), NULL, NULL); originalFunc = (TargetFunc)targetAddr; hookTrampoline = trampoline; } // 使用示例 void myFunction(const char* msg) { printf("Original: %s\n", msg); } int main() { // 获取函数地址 uintptr_t funcAddr = (uintptr_t)myFunction; // 假设通过反汇编找到跳过断点的地址 installHook(funcAddr, funcAddr + 2); myFunction("test"); // 触发Hook return 0; } ``` 三、关键改进点 1. 寄存器操作:通过修改`gregs[REG_RDI]`实现参数篡改(x86_64调用约定) 2. 执行流控制:将`REG_RIP`设为trampoline地址跳过断点指令 3. 信号处理优化:增加`SA_NODEFER`标志允许嵌套处理 4. 架构适配:明确使用x86_64寄存器名称和`NT_X86_DR7` 四、技术指标对比 | 特性 | 原代码 | 改进版 | |---------------|--------------|--------------| | 架构支持 | ARM | x86_64 | | 参数修改 | 不支持 | 支持 | | 执行流控制 | 仅继续执行 | 可跳转目标地址 | | 线程安全 | 单线程 | SA_NODEFER | | 断点复用 | 单次触发 | 持久生效 | 五、注意事项 1. Trampoline地址需要通过反汇编确定,通常为原函数地址+指令长度 2. 在信号处理函数中应避免调用非异步安全函数 3. 多线程环境下需使用`ptrace(PTRACE_ATTACH)`附加所有线程 4. 硬件断点数量有限(x86最多4个),需合理分配调试寄存器 此方案相比纯软件断点(如`int3`)的优势在于: $$ \text{执行速度} \propto \frac{1}{\text{上下文切换次数}} $$ 硬件断点无需修改指令,适合高频调用函数的监控场景。
阅读全文

相关推荐

#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <signal.h> #include <sys/ptrace.h> #include <sys/user.h> #include <ucontext.h> #define DR7_ENABLE_MASK (0x1 << 0) #define DR7_LEN_4BYTE (0x2 << 16) #define DR7_TYPE_EXEC (0x0 << 20) // 原始函数指针 typedef void (*TargetFunc)(const char*); volatile TargetFunc originalFunc = NULL; volatile uintptr_t hookTrampoline = 0; void signalHandler(int sig, siginfo_t* info, void* context) { ucontext_t* uctx = (ucontext_t*)context; // 获取触发地址 uintptr_t pc = (uintptr_t)uctx->uc_mcontext.gregs[REG_RIP]; // x86_64 if (pc == (uintptr_t)originalFunc) { printf("Hooked function called!\n"); // 修改第一个参数为"hooked message" uctx->uc_mcontext.gregs[REG_RDI] = (greg_t)"hooked message"; // 跳转到原始函数+2指令地址(跳过int3) uctx->uc_mcontext.gregs[REG_RIP] = hookTrampoline; } ptrace(PTRACE_CONT, getpid(), 0, 0); } void installHook(uintptr_t targetAddr, uintptr_t trampoline) { struct sigaction sa; sa.sa_flags = SA_SIGINFO | SA_NODEFER; sa.sa_sigaction = signalHandler; sigemptyset(&sa.sa_mask); sigaction(SIGTRAP, &sa, NULL); // 设置硬件断点 struct user_hwdebug_state debug_state = {0}; debug_state.dbg_regs[0].addr = targetAddr; debug_state.dbg_regs[0].ctrl = DR7_ENABLE_MASK | DR7_LEN_4BYTE | DR7_TYPE_EXEC; struct iovec iov = { &debug_state, sizeof(debug_state) }; ptrace(PTRACE_ATTACH, getpid(), NULL, NULL); wait(NULL); ptrace(PTRACE_SETREGSET, getpid(), NT_X86_DR7, &iov); // x86使用DR7 ptrace(PTRACE_DETACH, getpid(), NULL, NULL); originalFunc = (TargetFunc)targetAddr; hookTrampoline = trampoline; } // 使用示例 void myFunction(const char* msg) { printf("Original: %s\n", msg); } int main() { // 获取函数地址 uintptr_t funcAddr = (uintptr_t)myFunction; // 假设通过反汇编找到跳过断点的地址 installHook(funcAddr, funcAddr + 2); myFunction("test"); // 触发Hook return 0; }编写arm64hook示例

#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H ----------------------------------------------- #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } 以上两个是.h和.cpp代码 --------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <rect> <x>0</x> <y>0</y> <width>932</width> <height>628</height> </rect> <string>MainWindow</string> <widget class="QWidget" name="centralwidget"> <widget class="QPushButton" name="pb_connect"> <rect> <x>40</x> <y>20</y> <width>89</width> <height>25</height> </rect> <string>连接</string> </widget> <widget class="QPushButton" name="pb_led0"> <rect> <x>40</x> <y>70</y> <width>89</width> <height>25</height> </rect> <string>led0_on</string> </widget> <widget class="QPushButton" name="pb_led1"> <rect> <x>40</x> <y>110</y> <width>89</width> <height>25</height> </rect> <string>led1_on</string> </widget> <widget class="QPushButton" name="pb_led2"> <rect> <x>40</x> <y>150</y> <width>89</width> <height>25</height> </rect> <string>led2_on</string> </widget> <widget class="QPushButton" name="pb_feng"> <rect> <x>40</x> <y>190</y> <width>89</width> <height>25</height> </rect> <string>feng_on</string> </widget> <widget class="QPushButton" name="pb_buzzer"> <rect> <x>140</x> <y>20</y> <width>89</width> <height>25</height> </rect> <string>蜂鸣器_on</string> </widget> <widget class="QPushButton" name="pb_humiture"> <rect> <x>140</x> <y>70</y> <width>89</width> <height>25</height> </rect> <string>温湿度_on</string> </widget> <widget class="QPushButton" name="pb_photosensitive"> <rect> <x>140</x> <y>110</y> <width>89</width> <height>25</height> </rect> <string>光敏_on</string> </widget> <widget class="QPushButton" name="pb_infrared"> <rect> <x>140</x> <y>150</y> <width>89</width> <height>25</height> </rect> <string>人体红外_on</string> </widget> <widget class="QPushButton" name="pb_camera"> <rect> <x>140</x> <y>190</y> <width>89</width> <height>25</height> </rect> <string>摄像头_on</string> </widget> <widget class="QTextBrowser" name="textBrowser"> <rect> <x>350</x> <y>10</y> <width>421</width> <height>211</height> </rect> </widget> </widget> <widget class="QMenuBar" name="menubar"> <rect> <x>0</x> <y>0</y> <width>932</width> <height>28</height> </rect> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/> </ui> 以上是.ui代码 --------------------------------------------------------- 目前项目进度: 当前项目结构如下: DXM1txst: DXM1txst.pro Headers: fsmpBeeper.h fsmpElectric.h fsmpEvents.h fsmpFan.h fsmpLed.h fsmpLight.h fsmpProximity.h fsmpsevensegLed.h fsmpTempHum.h fsmpvibrator.h mainwindow.h Sources: main.cpp mainwindow.cpp Forms: mainwindow.ui qtcreator内:ui界面中已经有组件:pb_connect(连接按钮)、pb_led0(电灯1开关按钮)、pb_led1(电灯2开关按钮)、pb_led2(电灯3开关按钮)、pb_feng(风扇开关按钮)、pb_buzzer(蜂鸣器开关按钮)、pb_humiture(温湿度传感器开关按钮)、pb_photosensitive(光敏传感器开关按钮)、pb_infrared(人体红外传感器开关按钮)、pb_camera(摄像头开关按钮)、textBrowser(用于接收和发布的消息显示)。 华清远见元宇宙实验中心物联网仿真系统内:所需的所以硬件的3D场景设计完毕,M4网关单元的Mqtt配置为: 地址:mqtt.yyzlab.com.cn 端口:1883 与应用层、云端交互的Topic: 订阅:1752365375766/APP2AIOTSIM 发布:1752365375766/AIOTSIM2APP 与硬件交互的Topic: 订阅:1752365382482/Device2AIOTSIM 发布:1752365382482/AIOTSIM2Device 与华清远见元宇宙实验中心物联网仿真系统内硬件开关发布的控制码为:电灯0开:{"lamp":true,"id":0},电灯0关:{"lamp":false,"id":0},电灯1开:{"lamp":true,"id":1},电灯1关:{"lamp":false,"id":1},电灯2开:{"lamp":true,"id":2},电灯2关:{"lamp":false,"id":2},风扇开:{"fan":true,"id":0},风扇关:{"fan":false,"id":0},人体红外传感器开:{"infrared ":true,"id":0},人体红外传感器关:{"infrarrared ":false,"id":0},温湿度传感器:{"tem":38.8,"hum":65.7,"id":0},光敏传感器:{"light":43037.0,"id":0} Stm32mp157开发板:所有需要的硬件部署完毕,硬件的.h代码如下(硬件的.h代码已经放入qtcreator项目下的Headers文件夹下,且硬件的所有.h文件内代码都不能再进行修改): fsmpBeeper.h: #ifndef FSMPBEEPER_H #define FSMPBEEPER_H /*************************************************************************** * * 类名:fsmpBeeper * 功能说明:扩展板 蜂鸣器 * 公有函数: * fsmpBeeper() * bool setRate(uint32_t rate) 设置频率 * bool start(void) 启动蜂鸣器 * bool stop(void) 关闭蜂鸣器 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> /* FSMP开发板(linux)蜂鸣器操作类 v0 2023/1/9 by 张城 */ class fsmpBeeper:public QObject{ Q_OBJECT public: explicit fsmpBeeper(const char *device = "/dev/input/event0", QObject *parent = nullptr) :QObject(parent) { event.type = EV_SND; time.tv_sec = 1; time.tv_usec = 0; event.time = time; beeper_fd = ::open(device,O_RDWR); if(beeper_fd < 0) { perror("open_beeper"); return; } }; ~fsmpBeeper() { ::close(beeper_fd); } /* * Description: 设置频率值 * input: rate 频率 * output: null * return: 成功true/失败false */ bool setRate(uint32_t rate = 1000) { if(rate > 0) { event.code = SND_TONE; event.value = rate; return true; } return false; } /* * Description: start设备 * input: null * output: null * return: 成功true/失败false */ bool start(void) { int ret = write(beeper_fd, &event, sizeof(struct input_event)); if(ret < 0) { perror("write"); return false; } return true; } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ bool stop(void) { struct input_event event; event.type = EV_SND; event.code = SND_BELL; event.value = 0000; time.tv_sec = 1; time.tv_usec = 0; event.time = time; int ret = write(beeper_fd, &event, sizeof(struct input_event)); if(ret < 0) { perror("write"); return false; } return true; } private: int beeper_fd; //设备文件描述符 struct input_event event; struct timeval time; }; #endif // FSMPBEEPER_H ------------------------------------------------------- fsmpElectric.h: #ifndef ELC_H #define ELC_H /*************************************************************************** * * 类名:fsmpElectric * 功能说明:扩展板 电气信息检测 * 公有函数: * fsmpElectric() * float voltagemV(void) 获取电压mv(旋钮控制) * float currentmA(void) 获取电流ma(板载设备真实电流) * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <stdint.h> #include <QDebug> class fsmpElectric:public QObject{ Q_OBJECT public: explicit fsmpElectric(QObject *parent = nullptr) :QObject(parent) { } ~fsmpElectric(){ } float voltagemV(void) { electric_fd1 = open("/sys/bus/iio/devices/iio:device3/in_voltage1_raw",O_RDONLY|O_NONBLOCK); if(electric_fd1 < 0) { perror("open"); return -1; } char buf[10] = {0}; int ret = read(electric_fd1,buf,sizeof(buf)); if(ret < 0) { perror("read"); return -1; } int val = 0; sscanf(buf,"%d",&val); ::close(electric_fd1); return (float)3300 * val / 65536; } float currentmA(void) { electric_fd0 = open("/sys/bus/iio/devices/iio:device3/in_voltage0_raw",O_RDONLY|O_NONBLOCK); if(electric_fd0 < 0) { perror("open"); return -1; } char buf[10] = {0}; int ret = read(electric_fd0,buf,sizeof(buf)); if(ret < 0) { perror("read"); return -1; } int val = 0; sscanf(buf,"%d",&val); ::close(electric_fd0); return ((((float)3300 * val) /65536)/(10 + 100*1000 + 1000)) * 1000 / 0.1; } private: int electric_fd0; //设备文件描述符 int electric_fd1; //设备文件描述符 }; #endif // ELC_H ------------------------------------------------------- fsmpEvents.h: #ifndef ENV_H #define ENV_H /*************************************************************************** * * 类名:fsmpEvents * 功能说明:扩展板 按钮、人体红外、光闸管、火焰 * 公有函数: * fsmpEvents() * 信号: * void lightTriggered(); 光闸管阻隔 * void flameDetected(); 火焰检测 * void peopleDetected(bool); 人体红外发现true/离开false * void keyPressed(int keynum); 按键按下 keynum: 1、2、3 * void keyRelessed(int keynum); 按键释放 keynum: 1、2、3 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <QTimer> #include #include <sys/ioctl.h> #include <QDebug> #include <QProcess> #include <QThread> #include <stdio.h> #include <stdlib.h> class fsmpEvents:public QObject{ Q_OBJECT signals: /* edge trigle !!!*/ void lightTriggered();//光电开关 void flameDetected();//火焰检测 void peopleDetected(bool);//人体红外 void keyPressed(int keynum); void keyRelessed(int keynum); public: explicit fsmpEvents(QObject *parent = nullptr):QObject(parent) { this->gpio_F_open(); this->gpio_E_open(); fs_timer = new QTimer(this); connect(fs_timer,SIGNAL(timeout()),this,SLOT(time_out())); fs_timer->start(10); }; private: bool gpio_F_open(const char *device = "/dev/gpiochip5") { int ret; int fd = open(device,O_RDONLY|O_NONBLOCK); if(fd < 0) { fprintf(stderr,"open"); return false; } event_req.lineoffset = 9; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_FALLING_EDGE|GPIOEVENT_REQUEST_RISING_EDGE; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } key_1_fd = event_req.fd; int flags = fcntl(key_1_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(key_1_fd,F_SETFL,flags); event_req.lineoffset = 8; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } key_3_fd = event_req.fd; flags = fcntl(key_3_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(key_3_fd,F_SETFL,flags); #if 0 event_req.lineoffset = 5; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } fire_fd = event_req.fd; flags = fcntl(fire_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(fire_fd,F_SETFL,flags); #endif // fire req.lineoffsets[0] = 5; req.flags = GPIOHANDLE_REQUEST_INPUT; // strcpy(req.consumer_label, "fire"); req.lines = 1; memcpy(req.default_values, &data, sizeof(req.default_values)); ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); if (ret == -1) { fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); } fire_fd = req.fd; // key2 req.lineoffsets[0] = 7; req.flags = GPIOHANDLE_REQUEST_INPUT; // strcpy(req.consumer_label, "key2"); req.lines = 1; memcpy(req.default_values, &data, sizeof(req.default_values)); ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); if (ret == -1) { fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); } key_2_fd = req.fd; // people req.lineoffsets[0] = 12; req.flags = GPIOHANDLE_REQUEST_INPUT; // strcpy(req.consumer_label, "key2"); req.lines = 1; memcpy(req.default_values, &data, sizeof(req.default_values)); ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); if (ret == -1) { fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); } people_fd = req.fd; return true; } bool gpio_E_open(const char *device = "/dev/gpiochip4") { int ret; int fd = open(device,O_RDONLY|O_NONBLOCK); if(fd < 0) { fprintf(stderr,"open"); return false; } event_req.lineoffset = 15; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } light_trigger_fd = event_req.fd; int flags = fcntl(light_trigger_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(light_trigger_fd,F_SETFL,flags); return true; } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ bool close(void); public slots: void time_out() { static int key_1_flag = 0; static int key_2_flag = 0; static int key_3_flag = 0; static int light_trigger_flag = 0; static int people_flag = 0; static int flame_flag = 0; //捕获key_1按下 read(key_1_fd,&event_data,sizeof (event_data)); if(event_data.id == 2) { key_1_flag = 1; emit(this->keyPressed(1)); //qDebug()<<"key_1 pressed"; event_data.id = 0; } else if(event_data.id == 1 && key_1_flag==1) { key_1_flag = 0; emit keyRelessed(1); //qDebug()<<"key_1 relessed"; } event_data.id = 0; //捕获key_2按下 int ret = ioctl(key_2_fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret, strerror(errno)); exit(ret); } //qDebug() << "==========" << data.values[0]; if(data.values[0] ==0&&key_2_flag==0) { emit(this->keyPressed(2)); key_2_flag = 1; //qDebug()<<"key_2 pressed"; } else if(data.values[0] ==1&&key_2_flag==1) { key_2_flag = 0; emit keyRelessed(2); //qDebug()<<"key_2 relessed"; } //event_data.id = 0; //捕获key_3按下 read(key_3_fd,&event_data,sizeof (event_data)); //qDebug() << "key3 "<< event_data.id; if(event_data.id == 2 && key_3_flag==0) { key_3_flag = 1; emit(this->keyPressed(3)); //qDebug()<<"key_3 pressed"; event_data.id = 0; } else if(event_data.id == 1 && key_3_flag==1) { key_3_flag = 0; emit keyRelessed(3); //qDebug()<<"key_3 relessed"; } event_data.id = 0; //捕获光电开关 read(light_trigger_fd,&event_data,sizeof (event_data)); if(event_data.id == 1 && light_trigger_flag==0) { //qDebug()<<"light triggered"; light_trigger_flag = 1; emit(this->lightTriggered()); } else light_trigger_flag = 0; event_data.id = 0; //捕获people coming ret = ioctl(people_fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret, strerror(errno)); exit(ret); } if(data.values[0] ==1&&people_flag==0) { emit(this->peopleDetected(true)); people_flag = 1; //qDebug()<<"people coming"; } else if(data.values[0] ==0&&people_flag==1) { people_flag = 0; emit(this->peopleDetected(false)); //qDebug()<<"people leave"; } #if 0 //捕获火焰检测 read(fire_fd,&event_data,sizeof (event_data)); qDebug() << "------------------"<<event_data.id; if(event_data.id == 2 && flame_flag == 0) { qDebug()<<"flamedetection on"; flame_flag = 1; emit(this->flameDetected(true)); event_data.id = 0; } else if(event_data.id == 0 && flame_flag == 1) { qDebug()<<"flamedetection off"; flame_flag = 0; emit(this->flameDetected(false)); event_data.id = 0; } #endif //捕获key_2按下 ret = ioctl(fire_fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret, strerror(errno)); exit(ret); } //qDebug() << data.values[0]; if(data.values[0] ==1&&flame_flag==0) { emit(this->flameDetected()); flame_flag = 1; //qDebug()<<"flame on"; } else flame_flag = 0; } private: struct gpiohandle_request req; struct gpiohandle_data data; struct gpiochip_info chip_info; struct gpioevent_request event_req; struct gpioevent_data event_data; struct gpiod_chip *gpiochip5; struct gpiod_line *gpioline5_7; int key_1_fd; //设备文件描述符 int key_2_fd; int key_3_fd; int light_trigger_fd; int people_fd; int fire_fd; QTimer * fs_timer; }; #endif //ENV_H ------------------------------------------------------- fsmpFan.h: #ifndef FAN_H #define FAN_H /*************************************************************************** * * 类名:fsmpFan * 功能说明:扩展板 风扇控制 * 公有函数: * fsmpFan() * void start(void) 开启风扇) * void stop(void) 关闭风扇 * void setSpeed(int speed) 设置风扇速度(0-255) * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> class fsmpFan:public QObject{ Q_OBJECT public: explicit fsmpFan(QObject *parent = nullptr):QObject(parent) { const char *device = "/sys/class/hwmon/hwmon1/pwm1"; fan_fd = ::open(device,O_WRONLY|O_TRUNC); if(fan_fd < 0) { perror("open fan"); return; } fan_speed = 0; }; ~fsmpFan(){ ::close(fan_fd); } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ void stop(void) { write(fan_fd,"0",strlen("0")); } /* * Description: start设备 * input: null * output: null * return: 成功true/失败false */ void start(void) { char speedstr[100] = {0}; sprintf(speedstr, "%d", fan_speed); write(fan_fd, speedstr, strlen(speedstr)); } /* * Description: 控制风扇转速 * intput: speed 转速 * output: null * return: null */ void setSpeed(int speed) { fan_speed = speed%255; } private: int fan_fd; //设备文件描述符 int fan_speed; }; #endif // FAN_H ------------------------------------------------------- fsmpLeds.h: #ifndef LED_H #define LED_H /*************************************************************************** * * 类名:fsmpLeds * 功能说明:扩展板 3颗灯泡 * 公有函数: * fsmpLeds() * bool on(lednum x) 开灯 lednum: fsmpLeds::LED1/fsmpLeds::LED2/fsmpLeds::LED3 * bool off(lednum x) 关灯 lednum: fsmpLeds::LED1/fsmpLeds::LED2/fsmpLeds::LED3 * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> class fsmpLeds:public QObject{ Q_OBJECT public: enum lednum{ LED1, LED2, LED3 }; explicit fsmpLeds(QObject *parent = nullptr) :QObject(parent) { led_fd1 = ::open("/sys/class/leds/led1/brightness",O_WRONLY|O_TRUNC); if(led_fd1 < 0) { perror("open led1"); return ; } led_fd2 = ::open("/sys/class/leds/led2/brightness",O_WRONLY|O_TRUNC); if(led_fd2 < 0) { perror("open led2"); return ; } led_fd3 = ::open("/sys/class/leds/led3/brightness",O_WRONLY|O_TRUNC); if(led_fd3 < 0) { perror("open led3"); return ; } } ~fsmpLeds() { ::close(led_fd1); ::close(led_fd2); ::close(led_fd3); } /* * Description: 开启设备,默认/sys/class/leds/led1/brightness * input: lednum * output: null * return: 成功true/失败false */ bool on(lednum x) { int fd; if(x == LED1) fd = led_fd1; else if(x == LED2) fd = led_fd2; else if(x == LED3){ fd = led_fd3; } int ret = write(fd,"1",1); if(ret < 0) { return false; } return true; } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ bool off(lednum x) { int fd; if(x == LED1) fd = led_fd1; else if(x == LED2) fd = led_fd2; else if(x == LED3){ fd = led_fd3; } int ret = write(fd,"0",1); if(ret < 0) { return false; } return true; } private: int led_fd1; //设备文件描述符 int led_fd2; //设备文件描述符 int led_fd3; //设备文件描述符 }; #endif // LED_H ------------------------------------------------------- fsmpLight.h: #ifndef LIGHT_H #define LIGHT_H /*************************************************************************** * * 类名:fsmpLight * 功能说明:扩展板 光照强度检测 * 公有函数: * fsmpLight() * double getValue(void) 获取光照强度 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <QDebug> class fsmpLight:public QObject{ Q_OBJECT public: explicit fsmpLight(QObject *parent = nullptr) :QObject(parent) { light_fd = ::open("/sys/bus/iio/devices/iio:device1/in_illuminance_input",O_RDONLY|O_NONBLOCK); if(light_fd < 0) { perror("open"); return; } } ~fsmpLight() { ::close(light_fd); } /* * Description: 获取光照强度 * input: null * output: null * return: current light */ double getValue(void) { char buf[10] = {0}; int ret = read(light_fd,buf,10); if(ret < 0) { perror("read"); return false; } double num; sscanf(buf, "%lf", &num); lseek(light_fd, 0, SEEK_SET); return num; } private: int light_fd; //设备文件描述符 }; #endif // LIGHT_H ------------------------------------------------------- fsmpProximity.h: #ifndef FSMPPROXIMITY_H #define FSMPPROXIMITY_H /*************************************************************************** * * 类名:fsmpProximity * 功能说明:扩展板 红外接近传感器(和光照传感器一起) * 公有函数: * fsmpProximity() * double getValue(void) 获取接近情况(0-2048越接近数据越大) * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <QDebug> class fsmpProximity:public QObject{ Q_OBJECT public: explicit fsmpProximity(QObject *parent = nullptr) :QObject(parent) { proximity_fd = ::open("/sys/bus/iio/devices/iio:device1/in_proximity_raw",O_RDONLY|O_NONBLOCK); if(proximity_fd < 0) { perror("open"); return; } } ~fsmpProximity() { ::close(proximity_fd); } /* * Description: 获取distence * input: null * output: null * return: current light */ int getValue(void) { char buf[10] = {0}; int ret = read(proximity_fd,buf,10); if(ret < 0) { perror("read"); return false; } int num; sscanf(buf, "%d", &num); lseek(proximity_fd, 0, SEEK_SET); return num; } private: int proximity_fd; //设备文件描述符 }; #endif // FSMPPROXIMITY_H ------------------------------------------------------- fsmpSevensegLed.h: #ifndef FSMPSEVENSEGLED_H #define FSMPSEVENSEGLED_H /*************************************************************************** * * 类名:fsmpSevensegLed * 功能说明:扩展板 七段数码管 * 公有函数: * fsmpSevensegLed() * void display(int value) 显示4位以内整数 * void display(const char *str) 显示4位字符,注:仅支持 a、b、c、d、e * * 信号: * 无 * * *************************************************************************/ #include <stdint.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <fcntl.h> #include <sys/ioctl.h> #include #include #include <QThread> #include <stdlib.h> #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) class fsmpSevensegLed:public QThread{ Q_OBJECT public: explicit fsmpSevensegLed(QObject *parent = nullptr) :QThread(parent) { memset(data, 0, sizeof(data)); device = "/dev/spidev0.0"; bits = 8; speed = 400000; delay = 0; } void display(int value) { data[3] = value%10; data[2] = value/10%10; data[1] = value/100%10; data[0] = value/1000%10; } //"abcde" void display(const char *str) { data[3] = (strlen(str)-1 >= 0)?(str[strlen(str)-1] - 'a')+10:0; data[2] = (strlen(str)-2 >= 0)?(str[strlen(str)-2] - 'a')+10:0; data[1] = (strlen(str)-3 >= 0)?(str[strlen(str)-3] - 'a')+10:0; data[0] = (strlen(str)-4 >= 0)?(str[strlen(str)-4] - 'a')+10:0; } private: void run() { int ret = 0; int fd; fd = open(device, O_RDWR); //打开设备文件 if (fd < 0) pabort("can't open device"); /* * spi mode //设置spi设备模式 */ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); //写模式 if (ret == -1) pabort("can't set spi mode"); /* * bits per word //设置每个字含多少位 */ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); //写每个字含多少位 if (ret == -1) pabort("can't set bits per word"); /* * max speed hz //设置速率 */ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); //写速率 if (ret == -1) pabort("can't set max speed hz"); //打印模式,每字多少位和速率信息 printf("spi mode: %d\n", mode); printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); //transfer(fd); //传输测试 int i = 0; int pos = 0; unsigned char buf[2]; while(1) { pos = 1 << (i % 4); buf[0] = pos; buf[1] = num[data[i]]; if (write(fd, buf, 2) < 0) perror("write"); i++; if (i == 4) { i = 0; } usleep(3500); } } static void pabort(const char *s) { perror(s); abort(); } const char *device; uint8_t mode; uint8_t bits; uint32_t speed; uint16_t delay; int data[4]; unsigned char num[20] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; }; #endif // FSMPSEVENSEGLED_H ------------------------------------------------------- fsmpTempHum.h: #ifndef TEMPHUM_H #define TEMPHUM_H /*************************************************************************** * * 类名:fsmpTempHum * 功能说明:扩展板 温度湿度 * 公有函数: * fsmpTempHum() * double temperature(void) 提取温度 * double humidity(void) 提取湿度 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <stdint.h> #include <QDebug> class fsmpTempHum:public QObject{ Q_OBJECT public: explicit fsmpTempHum(QObject *parent = nullptr) :QObject(parent) { } double temperature(void) { int temp_raw = 0; int temp_offset = 0; float temp_scale = 0; open_device_int("iio:device0","in_temp_raw",&temp_raw); open_device_int("iio:device0","in_temp_offset",&temp_offset); open_device_float("iio:device0","in_temp_scale",&temp_scale); return (temp_raw + temp_offset) * temp_scale / 1000; } double humidity(void) { int hum_raw = 0; int hum_offset = 0; float hum_scale = 0; open_device_int("iio:device0","in_humidityrelative_raw",&hum_raw); open_device_int("iio:device0","in_humidityrelative_offset",&hum_offset); open_device_float("iio:device0","in_humidityrelative_scale",&hum_scale); return (hum_raw + hum_offset) * hum_scale / 1000; } private: bool open_device_int(const char *device, const char *filename, int *val) { int ret = 0; int fd; char temp[128] = {0}; sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename); fd = open(temp,O_RDONLY|O_NONBLOCK); if(fd < 0) { perror("open"); return false; } char buf[10] = {0}; ret = read(fd,buf,sizeof(buf)); if(ret < 0) { perror("read"); return false; } sscanf(buf,"%d",val); ::close(fd); return true; } bool open_device_float(const char *device, const char *filename, float *val) { int ret = 0; int fd; char temp[128] = {0}; sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename); fd = open(temp,O_RDONLY|O_NONBLOCK); if(fd < 0) { perror("open"); return false; } char buf[10] = {0}; ret = read(fd,buf,sizeof(buf)); if(ret < 0) { perror("read"); return false; } sscanf(buf,"%f",val); ::close(fd); return true; } private: int temp_hum_fd;; //设备文件描述符 }; #endif // TEMPHUM_H ------------------------------------------------------- fsmpVibrator.h: #ifndef VIBRATOR_H #define VIBRATOR_H /*************************************************************************** * * 类名:fsmpVibrator * 功能说明:扩展板 振动马达 * 公有函数: * fsmpVibrator() * bool setParameter(int strong_magnitude, int timems) 设置振动强度(0-0xffff)及时长(ms) * bool start(void) 启动马达 * bool stop(void) 停止马达 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <sys/ioctl.h> #include <QDebug> class fsmpVibrator:public QObject{ Q_OBJECT public: explicit fsmpVibrator(QObject *parent = nullptr) :QObject(parent) { vibrator_fd = ::open("/dev/input/event1", O_RDWR|O_NONBLOCK); if(vibrator_fd < 0) { perror("open vibrator"); } } ~fsmpVibrator() { ::close(vibrator_fd); } /* * Description:设置 * input:频率 * output:null * return:成功true/失败false */ bool setParameter(int strong_magnitude = 0xFFFF, int timems = 5000) { //qDebug()<<strong_magnitude<<timems; effect.type = FF_RUMBLE, effect.id = -1, effect.u.rumble.strong_magnitude = strong_magnitude; effect.u.rumble.weak_magnitude = 0; effect.replay.length = timems; effect.replay.delay = 0; if (ioctl(vibrator_fd, EVIOCSFF, &effect) < 0) { printf("Error creating new effect: %s\n", strerror(errno)); return false; } return true; } bool start(void) { struct input_event play = { .type = EV_FF, .code = (__U16_TYPE)effect.id, .value = 1 }; int ret = write(vibrator_fd, (const void*) &play, sizeof(play)); if(ret < 0) { perror("vibrator on"); return false; } //qDebug()<<"start"; return true; } bool stop(void) { struct input_event play = { .type = EV_FF, .code = (__U16_TYPE)effect.id, .value = 0 }; int ret = write(vibrator_fd, (const void*) &play, sizeof(play)); if(ret < 0) { perror("vibrator off"); return false; } //qDebug()<<"stop"; return true; } private: int vibrator_fd;//设备文件描述符 struct ff_effect effect; }; #endif // VIBRATOR_H ------------------------------------------------------- 项目目的: 在Linux下通过qtcreator编写后通过st-mp1构建部署到远程Linux主机后,在Stm32mp157开发板上能够控制本身的硬件同时也能同步控制华清远见元宇宙实验中心物联网仿真系统内的模拟硬件。并且通过Desktop Qt5.12.12 GCC64bit构建部署到Deploy Configuration时,能够控制Stm32mp157开发板上的硬件同时也能同步控制华清远见元宇宙实验中心物联网仿真系统内的模拟硬件。 设计要求: 1. 通过点击pb_connect(连接按钮)按钮可以连接到云端mqtt,连接成功则弹出小窗提示连接成功并自动绑定订阅与发布功能、连接失败则弹出小窗提示连接失败,弹出的小窗有一个确定键,点击确定关闭小窗。 2. 点击按钮pb_led0打开Stm32mp157开发板上的LD1灯且同步打开华清远见元宇宙实验中心物联网仿真系统内的电灯0,此时按钮pb_led0上的文本(初始化为led0_on)变更为led0_off。再次点击按钮pb_led0时关闭Stm32mp157开发板上的LD1灯且同步关闭华清远见元宇宙实验中心物联网仿真系统内的电灯0,此时按钮pb_led0上的文本(此时为led0_off)变更为led0_on。按钮pb_led1和pb_led2也是相同理论。 3. 点击按钮pb_feng打开Stm32mp157开发板上的风扇且同步打开华清远见元宇宙实验中心物联网仿真系统内的风扇,此时按钮pb_feng上的文本(初始化为feng_on)变更为feng_off。再次点击按钮pb_feng时关闭Stm32mp157开发板上的风扇且同步关闭华清远见元宇宙实验中心物联网仿真系统内的风扇,此时按钮pb_feng上的文本(此时为feng_off)变更为feng_on。 4. 点击按钮pb_buzzer打开Stm32mp157开发板上的蜂鸣器,此时按钮pb_buzzer上的文本(初始化为:蜂鸣器_on)变更为蜂鸣器_off。再次点击按钮pb_buzzer时关闭Stm32mp157开发板上的蜂鸣器,此时按钮pb_buzzer上的文本(此时为:蜂鸣器_off)变更为蜂鸣器_on。 5. 点击按钮pb_humiture时,打开Stm32mp157开发板上的温湿度传感器并将数据显示在textBrowser组件上。此时按钮pb_humiture上的文本(初始化为:温湿度_on)变更为温湿度_off。再次点击按钮pb_humiture时关闭Stm32mp157开发板上的温湿度传感器,此时按钮pb_humiture上的文本(此时为:温湿度_off)变更为温湿度_on。(需添加功能:打开Stm32mp157开发板上的温湿度传感器后,当温度超过30度时蜂鸣器会立即开启,低于30度或者直接点击按钮pb_buzzer都可关闭蜂鸣器) 6. 点击按钮pb_photosensitive时,打开Stm32mp157开发板上的光敏传感器并将数据显示在textBrowser组件上。此时按钮pb_photosensitive上的文本(初始化为:光敏_on)变更为光敏_off。再次点击按钮pb_photosensitive时关闭Stm32mp157开发板上的光敏传感器,此时按钮pb_photosensitive上的文本(此时为:光敏_off)变更为光敏_on。 7. 点击按钮pb_infrared时,打开Stm32mp157开发板上的人体红外传感器并将数据显示在textBrowser组件上。此时按钮pb_infrared上的文本(初始化为:人体红外_on)变更为人体红外_off。再次点击按钮pb_infrared时关闭Stm32mp157开发板上的人体红外传感器,此时按钮pb_infrared上的文本(此时为:人体红外_off)变更为人体红外_on。 8. 点击按钮pb_camera时打开Stm32mp157开发板上的摄像头并将采集到的图像在屏幕界面的右侧显示出来(目前项目中没有设计用于显示摄像头采集图像显示的组件,需要添加)。此时按钮pb_camera上的文本(初始化为:摄像头_on)变更为摄像头off。再次点击按钮pb_camera时关闭Stm32mp157开发板上的摄像头,此时按钮pb_camera上的文本(此时为:摄像头_off)摄像头_on,并关闭摄像头采集的图像显示界面。 结合以上代码及要求,进行完整详细的项目开发,如有需要可以添加项目结构内缺失的文件(项目结构内缺失硬件的.cpp文件),硬件.h文件不可进行修改。整合后将项目的所有文件发我,让我复制粘贴就能直接使用

// >>> common include #include <iostream> #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> // >>> verilator #include <memory> #include <verilated.h> #include <verilated_vcd_c.h> #include "VA_top.h" #include "sdm_config.h" #include "Sdm_node_A.h" using HW =VA_top; uint64_t GlobalMainTime = 0; int main(int argc, char** argv, char**env) { const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext}; const std::unique_ptr<HW> hw {new HW{contextp.get(), "TOP"}}; Sdm_config * shuncfg_ptr = new Sdm_config (sub_node_A_node_name); shuncfg_ptr->arg_parse (argc, argv); Sdm_node_A shunobj (shuncfg_ptr, hw.get(), contextp.get()); Verilated::mkdir("node_node_A_logs"); contextp->debug(0); contextp->randReset(2); contextp->commandArgs(argc, argv); #if VM_TRACE == 1 VerilatedVcdC* tgp = NULL; const char* flag = Verilated::commandArgsPlusMatch("trace"); if (flag && 0 ==strcmp(flag, "+trace")) { Info("Enter Trace!"); contextp->traceEverOn(true); tfp = new VerilatedVcdC; hw->trace(tfp,99); shunobj.fulleval(); std::string filename = shuncfg_ptr->dumpfile(); tfp->open(filename.c_str()); }; #endif shunobj.setup(); bool retmp; int loop = 0; while(1) { //Info("loop %d", loop); shunobj.update(); if (shunobj.finish()) break; do { shunobj.eval(); shunobj.sync(); } while(!shunobj.converge()); #if VM_TRACE == 1 if (flag && 0 == strcmp(flag, "+trace")) { tfp->dump(contextp->time()); } #endif loop++; } hw->final(); return 0; #if VM_TRACE == 1 if (flag && 0 == strcmp(flag, "+trace")){ tfp->close(); } #endif #if VM_COVERAGE Verilated::mkdir("node_node_A_logs"); contextp->coverageep()->write("node_node_A_logs/coverage.dat"); #endif }

#include <stdio.h> #include <stdlib.h> #include <string.h> #include #include <sys/time.h> #include <unistd.h> #include #include <signal.h> #include #include <algorithm> #include <iostream> #include <map> #include <string> #include <queue> #include <vector> #include <sstream> #define LOG_BRASERO_NUM 15 using namespace std; static char *g_cpBrasero[] = { (char *) "ID", (char *) "刻录时间", (char *) "刻录机型号", (char *) "光盘属性", (char *) "刻录状态", (char *) "计算机帐户", (char *) "文件名称", (char *) "文件大小", (char *) "文件类型", (char *) "测试1", (char *) "测试2", (char *) "测试3", (char *) "测试4", (char *) "测试5", (char *) "测试6", }; typedef struct _tagBraseroLog { char cpValue[1024]; } BRASEROLOG; int uosaarch_line_parse(char *pBuffer) { int index, len,lastLen; int ret = 0; char *begin = NULL; char *end = NULL; char *lastEnd = NULL; //debug printf("进入了扫描"); BRASEROLOG BraseroLog[LOG_BRASERO_NUM]; memset(&BraseroLog, 0, LOG_BRASERO_NUM * sizeof(BRASEROLOG)); for (index = 0; index < LOG_BRASERO_NUM; index++) { begin = strstr(pBuffer, g_cpBrasero[index]); if(NULL == begin) continue; begin=strstr(begin,"="); end = strstr(pBuffer, g_cpBrasero[index + 1]); //end--; if (begin != NULL) { len = strlen("="); unsigned long strSize = end - begin - len ; printf("BraseroLOg[%d]=%s\n",index,BraseroLog[index].cpValue); //strncpy(BraseroLog[index].cpValue, begin + len, std::min(strSize, sizeof(BraseroLog[index].cpValue) - 1)); // printf("PrintLog[%d] = %s\n",index,BraseroLog[index].cpValue); } return 0; } return 1; } int main(){ char a[500] = "ID=1689309873, 刻录时间=2023-07-14 12:44:34, 刻录机型号=TSSTcorp-CDDVDW-SE-218CB-R95M6YMDA00008, 光盘属性=DVD+R, 刻录状态=成功, 计算机帐户=hba, 文件名称=/home/hba/Desktop/刻录测试文件.txt, 文件大小=66 B, 文件类型=文档"; uosaarch_line_parse(a); return 0; }

Sdm_so_node_A.cpp #include <iostream> #include <unordered_map> #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> #include <memory> #include <verilated_vcs_c.h> #include "VA_top.h" #include "sdm_config.h" #include "Sdm_node_A.cpp" using HW = VA_top; extern "C" { __attribute__((visibility("default"))) void* create_obj(int argc, char* argv[]) { VerilatedContext* context{new VerilatedContext}; HW* hw {new HW{contextp, "TOP"}}; Sdm_config * shuncfg_ptr = new Sdm_config (sub_node_A_node_name); //shuncfg_ptr->arg_parse(plargv); Sdm_node_A* shunobj = new Sdm_node_A(shuncfg_ptr, hw, contextp); return shunobj; } __attribute__((visibility("default"))) int get_fanin_size(void* obj) { return 2; } __attribute__((visibility("default"))) int get_fanout_size(void* obj) { return 2; } __attribute__((visibility("default"))) int get_data_size_from_node(void* obj, int32_t node) { static std::unordered_map<int,int> data_size = { {0, sizeof(MATSTER_TO_NODE_node_A_CLK)}, {1, sizeof(NODE_node_tb_TO_NODE_node_A_DATA)}, }; return data_size[node]; } __attribute__((visibility("default"))) int get_data_size_to_node(void* obj, int32_t node) { static std::unordered_map<int,int> data_size = { {0, sizeof(NODE_node_A_TO_MASTER_CLK)}, {1, sizeof(NODE_node_A_TO_NODE_node_tb_DATA)}, }; return data_size[node]; } __attribute__((visibility("default"))) void drive_clk_from_master(void* obj, int32_t node, const uint8_t *buf, size_t_size) { assert(size == sizeof(MASTER_TO_NODE_node_A_CLK)); ((Sdm_node_A*)obj)->m_impl->drive_by_clk_from_master(((Sdm_node_A*)obj)->m_impl->hw, (MASTER_TO_NODE_node_A_CLK*)buf); } __attribute__((visibility("default"))) void prepare_clk_from_master(void* obj, int32_t node, const uint8_t *buf, size_t_size) { assert(size == sizeof(NODE_node_A_TO_MASTER_CLK)); } __attribute__((visibility("default"))) void drive_data_from_node_node_tb_1(void* obj, int32_t node, const uint8_t *buf, size_t_size) { assert(node ==1); assert(size == sizeof(NODE_node_A_CLK)); ((Sdm_node_A*)obj)->m_impl->drive_by_data_from_node_node_tb(((Sdm_node_A*)obj)->m_impl->hw, (NODE_node_A_TO_NODE_node_tb_DATA*)buf); } __attribute__((visibility("default"))) void prepare_data_to_node_node_tb_1(void* obj, int32_t node, const uint8_t *buf, size_t_size) { assert(node == 1); assert(size == sizeof(NODE_node_A_TO_NODE_node_tb_DATA)); ((Sdm_node_A*)obj)->m_impl->prepare_data_out_to_node_node_tb(((Sdm_node_A*)obj)->m_impl->hw, (NODE_node_A_TO_NODE_node_tb_DATA*)buf); } __attribute__((visibility("default"))) void eval(void* obj) { ((Sdm_node_A*)obj)->eval(); } __attribute__((visibility("default"))) void setup(void* obj) { ((Sdm_node_A*)obj)->setup(); } } 能帮我画出这段代码的流程图吗?

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/mman.h> #include <sys/uio.h> #include <signal.h> #include <fcntl.h> #include <errno.h> #include <dirent.h> #include <ctype.h> #include <sys/types.h> #include <stdint.h> #include <sys/syscall.h> #include <sys/ptrace.h> #include <sys/wait.h> // ARM64缓存类型定义 #ifndef CACHE_TYPE_INSTRUCTION #define CACHE_TYPE_INSTRUCTION 0 #endif #ifndef CACHE_TYPE_DATA #define CACHE_TYPE_DATA 1 #endif // 系统调用号数组(适配Linux 5系列内核) #if defined(__aarch64__) const int cache_flush_syscalls[] = {118, 123, 124, 125, 126, 0}; #endif typedef uint64_t ADDRESS; // 全局变量(存储目标进程信息) struct ProcessInfo { int pid; uint64_t so_base; } processInfo = {-1, 0}; typedef struct { uint64_t start_addr; uint64_t end_addr; char permissions[5]; } ModuleRange; typedef struct { ModuleRange ranges[200]; int count; } ModuleInfo; // 获取目标进程PID int getPID(const char *packageName) { int id = -1; DIR *dir = opendir("/proc"); if (!dir) { perror("打开/proc目录失败"); return -1; } struct dirent *entry; while ((entry = readdir(dir)) != NULL) { if (entry->d_type == DT_DIR) { id = atoi(entry->d_name); if (id > 0) { char filename[64], cmdline[64]; snprintf(filename, sizeof(filename), "/proc/%d/cmdline", id); FILE *fp = fopen(filename, "r"); if (fp) { if (fgets(cmdline, sizeof(cmdline), fp)) { cmdline[strcspn(cmdline, "\n")] = '\0'; if (strcmp(packageName, cmdline) == 0) { fclose(fp); closedir(dir); return id; } } fclose(fp); } } } } closedir(dir); return -1; } // 获取模块内存信息(增强权限检查) ModuleInfo get_module_info(int pid, const char *module_name) { ModuleInfo info = {0}; FILE *fp; char line[8192]; char filename[32]; snprintf(filename, sizeof(filename), "/proc/%d/maps", pid); if ((fp = fopen(filename, "r")) == NULL) { perror("打开maps文件失败"); return info; } while (fgets(line, sizeof(line), fp)) { if (strstr(line, module_name)) { uint64_t start, end; char perms[5], offset[17], dev[6], inode[11], pathname[256]; // 增强解析逻辑 if (sscanf(line, "%lx-%lx %4s %16s %5s %10s %255[^\n]", &start, &end, perms, offset, dev, inode, pathname) >= 6) { if (start < end) { if (info.count < 200) { info.ranges[info.count].start_addr = start; info.ranges[info.count].end_addr = end; strncpy(info.ranges[info.count].permissions, perms, 4); info.ranges[info.count].permissions[4] = '\0'; info.count++; } else { printf("警告:模块映射段过多(超过200段),部分段未记录\n"); break; } } } } } fclose(fp); return info; } // 使用ptrace安全写入DWORD int SafeWriteDword(int pid, uint64_t addr, uint32_t value) { // 附加到目标进程 if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) { perror("ptrace附加失败"); return -1; } // 等待进程暂停 int status; waitpid(pid, &status, 0); if (!WIFSTOPPED(status)) { perror("进程未暂停"); ptrace(PTRACE_DETACH, pid, NULL, NULL); return -1; } // 逐字写入(避免对齐问题) for (int i = 0; i < sizeof(uint32_t); i++) { uint8_t byte = (value >> (i * 8)) & 0xFF; long data = ptrace(PTRACE_PEEKTEXT, pid, addr + i, NULL); if (data == -1 && errno) { perror("ptrace读取失败"); ptrace(PTRACE_DETACH, pid, NULL, NULL); return -1; } // 修改单个字节 long new_data = (data & ~0xFF) | byte; if (ptrace(PTRACE_POKETEXT, pid, addr + i, new_data) == -1) { perror("ptrace写入失败"); ptrace(PTRACE_DETACH, pid, NULL, NULL); return -1; } } // 分离目标进程 if (ptrace(PTRACE_DETACH, pid, NULL, NULL) == -1) { perror("ptrace分离失败"); return -1; } return 0; } // 使用ptrace安全读取DWORD int SafeReadDword(int pid, uint64_t addr, uint32_t *value) { *value = 0; // 附加到目标进程 if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) { perror("ptrace附加失败"); return -1; } // 等待进程暂停 int status; waitpid(pid, &status, 0); if (!WIFSTOPPED(status)) { perror("进程未暂停"); ptrace(PTRACE_DETACH, pid, NULL, NULL); return -1; } // 逐字读取(避免对齐问题) for (int i = 0; i < sizeof(uint32_t); i++) { long data = ptrace(PTRACE_PEEKTEXT, pid, addr + i, NULL); if (data == -1 && errno) { perror("ptrace读取失败"); ptrace(PTRACE_DETACH, pid, NULL, NULL); return -1; } *value |= ((uint32_t)(data & 0xFF)) << (i * 8); } // 分离目标进程 if (ptrace(PTRACE_DETACH, pid, NULL, NULL) == -1) { perror("ptrace分离失败"); return -1; } return 0; } // 使用__builtin___clear_cache刷新缓存 int flush_with_builtin(uint64_t addr, size_t size) { char *start = (char *)(addr & ~(4095ULL)); char *end = start + size; __builtin___clear_cache(start, end); printf("成功: 使用__builtin___clear_cache刷新指令缓存\n"); return 0; } // 五级强刷新机制 int enhanced_flush_cache(uint64_t addr, size_t size) { uint64_t aligned_addr = addr & ~(4095ULL); size_t aligned_size = ((addr + size - aligned_addr + 4095) / 4096) * 4096; #ifdef __aarch64__ // 1. 优先使用__builtin___clear_cache if (flush_with_builtin(aligned_addr, aligned_size) == 0) { return 0; } // 2. 尝试系统调用刷新 const int *syscall_num = cache_flush_syscalls; while (*syscall_num != 0) { int ret_instr = syscall(*syscall_num, aligned_addr, aligned_size, CACHE_TYPE_INSTRUCTION); if (ret_instr == 0) { printf("成功: 使用syscall %d 刷新缓存\n", *syscall_num); return 0; } syscall_num++; } // 3. mprotect内存属性修改方案 void *page_start = (void *)aligned_addr; int pagesize = sysconf(_SC_PAGESIZE); unsigned long page_count = (aligned_size + pagesize - 1) / pagesize; int protection = PROT_READ | PROT_WRITE | PROT_EXEC; if (mprotect(page_start, page_count * pagesize, protection) == 0) { printf("成功: 通过mprotect修改内存保护属性刷新缓存\n"); return 0; } // 4. msync强制同步方案 if (msync((void *)aligned_addr, aligned_size, MS_SYNC | MS_INVALIDATE) == 0) { printf("成功: 使用msync同步刷新缓存\n"); return 0; } // 5. 终极方案:重建内存映射 void *tmp = mmap(NULL, aligned_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (tmp) { memcpy(tmp, (void *)aligned_addr, aligned_size); munmap((void *)aligned_addr, aligned_size); mmap((void *)aligned_addr, aligned_size, PROT_READ | PROT_EXEC, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0); memcpy((void *)aligned_addr, tmp, aligned_size); munmap(tmp, aligned_size); printf("成功: 通过重建内存映射刷新缓存\n"); return 0; } #endif perror("所有缓存刷新方法均失败"); return -1; } // 暂停目标进程 int pause_process(int pid) { if (kill(pid, SIGSTOP) == -1) { perror("发送SIGSTOP失败"); return -1; } // 等待进程真正停止 int status; waitpid(pid, &status, WUNTRACED); if (!WIFSTOPPED(status)) { perror("进程未正确停止"); return -1; } printf("进程已暂停(PID: %d)\n", pid); return 0; } // 恢复目标进程 int resume_process(int pid) { if (kill(pid, SIGCONT) == -1) { perror("发送SIGCONT失败"); return -1; } printf("进程已恢复运行(PID: %d)\n", pid); return 0; } // 主Hook函数 void hook_il2cpp() { const char *packageName = "com.tencent.tmgp.cf"; const uint64_t HOOK_OFFSET = 0x7EFD168; const uint32_t HOOK_VALUE = 505416143; const uint32_t ORIGINAL_VALUE = 505416142; processInfo.pid = getPID(packageName); if (processInfo.pid <= 0) { printf("获取PID失败\n"); return; } printf("获取到目标进程PID: %d\n", processInfo.pid); ModuleInfo module_info = get_module_info(processInfo.pid, "libil2cpp.so"); if (module_info.count == 0) { printf("获取SO模块地址失败(可能无权限或模块未加载)\n"); return; } // 使用第一个可执行段的起始地址作为模块基址 uint64_t module_base = 0; for (int i = 0; i < module_info.count; i++) { if (strstr(module_info.ranges[i].permissions, "x")) { module_base = module_info.ranges[i].start_addr; break; } } if (module_base == 0) { printf("未找到可执行段,使用第一个段作为基址\n"); module_base = module_info.ranges[0].start_addr; } uint64_t target_addr = module_base + HOOK_OFFSET; printf("\nlibil2cpp.so 模块基址: 0x%016lx\n", module_base); printf("目标Hook地址: 0x%016lx (基址 + 0x%lx)\n", target_addr, HOOK_OFFSET); // 验证目标地址是否在模块范围内且具有写权限 int in_range = 0; int has_write_permission = 0; for (int i = 0; i < module_info.count; i++) { if (target_addr >= module_info.ranges[i].start_addr && target_addr <= module_info.ranges[i].end_addr) { in_range = 1; if (strstr(module_info.ranges[i].permissions, "w")) { has_write_permission = 1; } break; } } if (!in_range) { printf("\n目标地址0x%016lx超出模块范围,退出操作\n", target_addr); return; } if (!has_write_permission) { printf("\n警告:目标地址无写权限,尝试修改内存保护属性\n"); } // 暂停进程进行内存操作 if (pause_process(processInfo.pid) != 0) { printf("暂停进程失败,退出Hook流程\n"); return; } // 读取原始值并验证 uint32_t original_val; if (SafeReadDword(processInfo.pid, target_addr, &original_val) != 0) { printf("读取原始值失败,恢复进程并退出\n"); resume_process(processInfo.pid); return; } printf("原始值: %u (预期: %u)\n", original_val, ORIGINAL_VALUE); if (original_val != ORIGINAL_VALUE) { printf("警告:原始值(%u)与预期值(%u)不匹配,继续操作但结果可能异常\n", original_val, ORIGINAL_VALUE); } // 写入新值 if (SafeWriteDword(processInfo.pid, target_addr, HOOK_VALUE) != 0) { printf("修改失败(可能因内存保护或权限问题),恢复进程并退出\n"); resume_process(processInfo.pid); return; } printf("成功写入新值: %u\n", HOOK_VALUE); // 刷新指令缓存 if (enhanced_flush_cache(target_addr & ~(4095), 4096) != 0) { printf("警告:缓存刷新失败,可能存在执行风险\n"); } // 验证新值 uint32_t new_val; if (SafeReadDword(processInfo.pid, target_addr, &new_val) == 0) { printf("验证修改: 新值 = %u (预期: %u)\n", new_val, HOOK_VALUE); if (new_val == HOOK_VALUE) { printf("\033[32m验证成功:值已修改为预期值\033[0m\n"); } else { printf("\033[31m验证失败:新值(%u)与预期值(%u)不匹配\033[0m\n", new_val, HOOK_VALUE); } } else { printf("验证修改失败(无法读取新值)\n"); } // 恢复进程运行 if (resume_process(processInfo.pid) != 0) { printf("恢复进程失败\n"); return; } printf("进程已恢复运行\n"); // 等待进程稳定 sleep(2); // 验证恢复后的值 uint32_t restored_val; if (SafeReadDword(processInfo.pid, target_addr, &restored_val) == 0) { printf("恢复后的值: %u (预期: %u)\n", restored_val, ORIGINAL_VALUE); if (restored_val == ORIGINAL_VALUE) { printf("\033[32m验证成功:值已恢复为原始值\033[0m\n"); } else { printf("\033[31m验证失败:恢复后的值(%u)与原始值(%u)不匹配\033[0m\n", restored_val, ORIGINAL_VALUE); } } else { printf("验证恢复值失败(可能无权限或地址不可读)\n"); } } int main() { if (getuid() != 0) { printf("需要root权限运行!\n"); return 1; } hook_il2cpp(); return 0; }获取到目标进程PID: 24442 libil2cpp.so 模块基址: 0x0000006f46366000 目标Hook地址: 0x0000006f4e263168 (基址 + 0x7efd168) 警告:目标地址无写权限,尝试修改内存保护属性 进程未正确停止: No child processes 暂停进程失败,退出Hook流程 [进程已结束 - 按回车关闭]修复好完整发给我 确认无任何报错后

大家在看

recommend-type

HDD Regenerator

HDD Regenerator
recommend-type

yolov5_weights.zip

此文件是yolov5权重文件,包含5种不同的权重模型(yolov5s.pt、yolov5m.pt、yolov5l.pt、yolov5-spp.pt、yolov5x.pt) 但是此文件为旧版本的权重文件,所以要下载最新的详见本人另一篇博客
recommend-type

UDS ISO 14229-1中英文翻译.rar

汽车行业标准,UDS诊断,ISO14229-1中英文翻译,一共800多页
recommend-type

基于PCB的测试探针及相关材料在测试治具中的选用.zip

【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。【项目质量】:所有源码都经过严格测试,可以直接运行。功能在确认正常工作后才上传。【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。
recommend-type

PyRHEED:RHEED分析和模拟

派瑞德 表中的内容 描述 该项目用于反射高能电子衍射(RHEED)数据分析和理论模拟。 RHEED是一种电子衍射技术,使用相对高能量(5〜30 keV)的电子束具有掠入射角。 它对表面非常敏感,穿透深度仅为几纳米。 由于电子的散射因子比X射线的散射因子高约四倍,因此RHEED特别适合表征难以用XRD检测到的2D材料,例如石墨烯。 RHEED的另一个优点是光点尺寸非常大(约1厘米),这使它能够测量材料特性的晶圆级平均值,包括晶格常数,晶粒取向分布甚至缺陷密度。 它是使用Python 3.6.6(64位)编写和测试的。 GUI是使用PyQt5创建的。 该simulate_RHEED模块利用图书馆阅读CIF文件并创建结构。 主要功能包括: RHEED原始图像处理使用和强度轮廓提取,通过 vecterization加快了速度。 二维相互空间图和极图的构建是自动的。 3D数据可以另存为* .vt

最新推荐

recommend-type

langchain4j-0.8.0.jar中文文档.zip

1、压缩文件中包含: 中文文档、jar包下载地址、Maven依赖、Gradle依赖、源代码下载地址。 2、使用方法: 解压最外层zip,再解压其中的zip包,双击 【index.html】 文件,即可用浏览器打开、进行查看。 3、特殊说明: (1)本文档为人性化翻译,精心制作,请放心使用; (2)只翻译了该翻译的内容,如:注释、说明、描述、用法讲解 等; (3)不该翻译的内容保持原样,如:类名、方法名、包名、类型、关键字、代码 等。 4、温馨提示: (1)为了防止解压后路径太长导致浏览器无法打开,推荐在解压时选择“解压到当前文件夹”(放心,自带文件夹,文件不会散落一地); (2)有时,一套Java组件会有多个jar,所以在下载前,请仔细阅读本篇描述,以确保这就是你需要的文件。 5、本文件关键字: jar中文文档.zip,java,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,中文API文档,手册,开发手册,使用手册,参考手册。
recommend-type

Wamp5: 一键配置ASP/PHP/HTML服务器工具

根据提供的文件信息,以下是关于标题、描述和文件列表中所涉及知识点的详细阐述。 ### 标题知识点 标题中提到的是"PHP集成版工具wamp5.rar",这里面包含了以下几个重要知识点: 1. **PHP**: PHP是一种广泛使用的开源服务器端脚本语言,主要用于网站开发。它可以嵌入到HTML中,从而让网页具有动态内容。PHP因其开源、跨平台、面向对象、安全性高等特点,成为最流行的网站开发语言之一。 2. **集成版工具**: 集成版工具通常指的是将多个功能组合在一起的软件包,目的是为了简化安装和配置流程。在PHP开发环境中,这样的集成工具通常包括了PHP解释器、Web服务器以及数据库管理系统等关键组件。 3. **Wamp5**: Wamp5是这类集成版工具的一种,它基于Windows操作系统。Wamp5的名称来源于它包含的主要组件的首字母缩写,即Windows、Apache、MySQL和PHP。这种工具允许开发者快速搭建本地Web开发环境,无需分别安装和配置各个组件。 4. **RAR压缩文件**: RAR是一种常见的文件压缩格式,它以较小的体积存储数据,便于传输和存储。RAR文件通常需要特定的解压缩软件进行解压缩操作。 ### 描述知识点 描述中提到了工具的一个重要功能:“可以自动配置asp/php/html等的服务器, 不用辛辛苦苦的为怎么配置服务器而烦恼”。这里面涵盖了以下知识点: 1. **自动配置**: 自动配置功能意味着该工具能够简化服务器的搭建过程,用户不需要手动进行繁琐的配置步骤,如修改配置文件、启动服务等。这是集成版工具的一项重要功能,极大地降低了初学者的技术门槛。 2. **ASP/PHP/HTML**: 这三种技术是Web开发中常用的组件。ASP (Active Server Pages) 是微软开发的服务器端脚本环境;HTML (HyperText Markup Language) 是用于创建网页的标准标记语言;PHP是服务器端脚本语言。在Wamp5这类集成环境中,可以很容易地对这些技术进行测试和开发,因为它们已经预配置在一起。 3. **服务器**: 在Web开发中,服务器是一个运行Web应用程序并响应客户端请求的软件或硬件系统。常见的服务器软件包括Apache、Nginx等。集成版工具提供了一个本地服务器环境,使得开发者可以在本地测试他们的应用程序。 ### 标签知识点 标签中仅出现了“PHP”一个关键词,这意味着该工具专注于与PHP相关的开发环境配置。 ### 压缩包子文件的文件名称列表知识点 1. **wamp.exe**: 这是Wamp5集成版工具的可执行文件,用户通过运行这个文件,即可启动Wamp5环境,开始进行PHP等相关开发。 2. **使用说明文档.txt**: 通常这样的文本文件包含了软件的安装指南、功能介绍、常见问题解答以及操作教程等内容。它是用户了解和使用软件的重要辅助资料,可以帮助用户快速上手。 ### 总结 Wamp5作为一个PHP集成版工具,为PHP开发者提供了一个便捷的本地开发环境。它通过自动化配置减少了开发者在搭建环境时的麻烦,整合了Web开发的关键组件,从而使得开发者能够专注于代码的编写,而不是环境配置。此外,它还提供了详尽的使用文档,帮助用户理解和运用这一工具,有效地提高了开发效率。对于希望快速入门PHP或需要一个简单易用的本地开发环境的开发者来说,Wamp5是一个非常好的选择。
recommend-type

【数据融合技术】:甘肃土壤类型空间分析中的专业性应用

# 摘要 数据融合技术作为一种集成多源数据信息的方法,在土壤类型空间分析中发挥着关键作用。本文介绍了数据融合技术的基本概念及其理论基础,阐述了数据预处理、同步整合及冲突解决等关键技术,并详细描述了甘肃土壤类型数据准备的流程,包括数据采集、质量评估、空间化处理及融合实践准备。通过具体案例分析,展示了数据融合在土壤类型空间分布分析、土壤质量评估及土壤保护规划中的应用。同时,文
recommend-type

sht20温湿度传感器使用什么将上拉电阻和滤波电容引出

<think>好的,我需要解决用户关于SHT20温湿度传感器的上拉电阻和滤波电容的引出方法问题。首先,我得回忆一下SHT20的基本特性和常见电路设计。SHT20是数字传感器,通常使用I2C接口,所以上拉电阻是必须的,用于确保数据线和时钟线的稳定。根据引用[2],SHT10是通过SCK和DATA线与单片机通信,而SHT30在引用[3]中使用I2C协议,需要上拉电阻。虽然用户问的是SHT20,但SHT系列通常设计类似,所以可以推断SHT20也需要类似的上拉电阻配置。通常I2C总线的上拉电阻值在4.7kΩ到10kΩ之间,但具体值可能取决于总线速度和电源电压。需要确认数据手册中的推荐值,但用户可能没有
recommend-type

Delphi仿速达财务软件导航条组件开发教程

Delphi作为一款历史悠久的集成开发环境(IDE),由Embarcadero Technologies公司开发,它使用Object Pascal语言,被广泛应用于Windows平台下的桌面应用程序开发。在Delphi中开发组件是一项核心技术,它允许开发者创建可复用的代码单元,提高开发效率和软件模块化水平。本文将详细介绍如何在Delphi环境下仿制速达财务软件中的导航条组件,这不仅涉及到组件的创建和使用,还会涉及界面设计和事件处理等技术点。 首先,需要了解Delphi组件的基本概念。在Delphi中,组件是一种特殊的对象,它们被放置在窗体(Form)上,可以响应用户操作并进行交互。组件可以是可视的,也可以是不可视的,可视组件在设计时就能在窗体上看到,如按钮、编辑框等;不可视组件则主要用于后台服务,如定时器、数据库连接等。组件的源码可以分为接口部分和实现部分,接口部分描述组件的属性和方法,实现部分包含方法的具体代码。 在开发仿速达财务软件的导航条组件时,我们需要关注以下几个方面的知识点: 1. 组件的继承体系 仿制组件首先需要确定继承体系。在Delphi中,大多数可视组件都继承自TControl或其子类,如TPanel、TButton等。导航条组件通常会继承自TPanel或者TWinControl,这取决于导航条是否需要支持子组件的放置。如果导航条只是单纯的一个显示区域,TPanel即可满足需求;如果导航条上有多个按钮或其他控件,可能需要继承自TWinControl以提供对子组件的支持。 2. 界面设计与绘制 组件的外观和交互是用户的第一印象。在Delphi中,可视组件的界面主要通过重写OnPaint事件来完成。Delphi提供了丰富的绘图工具,如Canvas对象,使用它可以绘制各种图形,如直线、矩形、椭圆等,并且可以对字体、颜色进行设置。对于导航条,可能需要绘制背景图案、分隔线条、选中状态的高亮等。 3. 事件处理 导航条组件需要响应用户的交互操作,例如鼠标点击事件。在Delphi中,可以通过重写组件的OnClick事件来响应用户的点击操作,进而实现导航条的导航功能。如果导航条上的项目较多,还可能需要考虑使用滚动条,让更多的导航项能够显示在窗体上。 4. 用户自定义属性和方法 为了使组件更加灵活和强大,开发者通常会为组件添加自定义的属性和方法。在导航条组件中,开发者可能会添加属性来定义按钮个数、按钮文本、按钮位置等;同时可能会添加方法来处理特定的事件,如自动调整按钮位置以适应不同的显示尺寸等。 5. 数据绑定和状态同步 在财务软件中,导航条往往需要与软件其他部分的状态进行同步。例如,用户当前所处的功能模块会影响导航条上相应项目的选中状态。这通常涉及到数据绑定技术,Delphi支持组件间的属性绑定,通过数据绑定可以轻松实现组件状态的同步。 6. 导航条组件的封装和发布 开发完毕后,组件需要被封装成独立的单元供其他项目使用。封装通常涉及将组件源码保存为pas文件,并在设计时能够在组件面板中找到。发布组件可能还需要编写相应的安装包和使用文档,方便其他开发者安装和使用。 7. Delphi IDE的支持 Delphi IDE提供了组件面板编辑器(Component Palette),允许开发者将开发好的组件添加到组件面板中。在组件面板编辑器中,可以自定义组件的图标和分类,使得组件在Delphi中的使用更为便捷。 通过以上的知识点梳理,可以看出Delphi仿速达导航条组件的开发涉及到的不仅仅是简单的代码编写,还涉及到用户界面设计、事件驱动编程、组件封装等多个方面。掌握这些知识点,对于一名Delphi开发者而言,是十分重要的。
recommend-type

【空间分布规律】:甘肃土壤类型与农业生产的关联性研究

# 摘要 本文对甘肃土壤类型及其在农业生产中的作用进行了系统性研究。首先概述了甘肃土壤类型的基础理论,并探讨了土壤类型与农业生产的理论联系。通过GIS技术分析,本文详细阐述了甘肃土壤的空间分布规律,并对其特征和影响因素进行了深入分析。此外,本文还研究了甘肃土壤类型对农业生产实际影响,包括不同区域土壤改良和作物种植案例,以及土壤养分、水分管理对作物生长周期和产量的具体影响。最后,提出了促进甘肃土壤与农业可持续发展的策略,包括土壤保护、退化防治对策以及土壤类型优化与农业创新的结合。本文旨在为
recommend-type

常见运放电路的基本结构和基本原理

<think>首先,用户的问题是关于运算放大器电路的基本结构和工作原理。我需要根据系统级指令来构建回答。系统级指令:-所有行内数学表达式必须使用$...$格式。-独立公式必须使用$$...$$格式并单独成段。-LaTeX语法正确。-使用中文回答。-生成相关问题。-回答中引用的段落末尾自然地添加引用标识,例如[^1]。-回答结构清晰,帮助用户逐步解决问题,尽量保证回答真实可靠。参考站内引用:-引用[1]:关于运算放大器基本电路用法,特别是反相放大器电路。-引用[2]:关于uA741运算放大器电路的基本原理,包括输入级、输出级等。用户的问题:"我想了解运放电路的基本结构和工作原理请问运算放大器电路
recommend-type

ASP.NET2.0初学者个人网站实例分享

标题:“ASP.NET 2.0个人网站”指向了一个网站开发项目,这个项目是使用ASP.NET 2.0框架构建的。ASP.NET 2.0是微软公司推出的一种用于Web开发的服务器端技术,它是.NET Framework的一部分。这个框架允许开发者构建动态网站、网络应用程序和网络服务。开发者可以使用C#或VB.NET等编程语言来编写应用程序。由于这被标签为“2.0”,我们可以假设这是一个较早版本的ASP.NET,相较于后来的版本,它可能没有那么先进的特性,但对于初学者来说,它提供了基础并且易于上手的工具和控件来学习Web开发。 描述:“个人练习所做,适合ASP.NET初学者参考啊,有兴趣的可以前来下载去看看,同时帮小弟我赚些积分”提供了关于该项目的背景信息。它是某个个人开发者或学习者为了实践和学习ASP.NET 2.0而创建的个人网站项目。这个项目被描述为适合初学者作为学习参考。开发者可能是为了积累积分或网络声誉,鼓励他人下载该项目。这样的描述说明了该项目可以被其他人获取,进行学习和参考,或许还能给予原作者一些社区积分或其他形式的回报。 标签:“2.0”表明这个项目专门针对ASP.NET的2.0版本,可能意味着它不是最新的项目,但是它可以帮助初学者理解早期ASP.NET版本的设计和开发模式。这个标签对于那些寻找具体版本教程或资料的人来说是有用的。 压缩包子文件的文件名称列表:“MySelf”表示在分享的压缩文件中,可能包含了与“ASP.NET 2.0个人网站”项目相关的所有文件。文件名“我的”是中文,可能是指创建者以“我”为中心构建了这个个人网站。虽然文件名本身没有提供太多的信息,但我们可以推测它包含的是网站源代码、相关资源文件、数据库文件(如果有的话)、配置文件和可能的文档说明等。 知识点总结: 1. ASP.NET 2.0是.NET Framework下的一个用于构建Web应用程序的服务器端框架。 2. 它支持使用C#和VB.NET等.NET支持的编程语言进行开发。 3. ASP.NET 2.0提供了一组丰富的控件,可帮助开发者快速构建Web表单、用户界面以及实现后台逻辑。 4. 它还提供了一种称作“Web站点”项目模板,使得初学者能够方便地开始Web开发项目。 5. ASP.NET 2.0是微软.NET历史上一个重要的里程碑,引入了许多创新特性,如成员资格和角色管理、主题和皮肤、网站导航和个性化设置等。 6. 在学习ASP.NET 2.0的过程中,初学者可以了解到如HTTP请求和响应、服务器控件、状态管理、数据绑定、缓存策略等基础概念。 7. 本项目可作为ASP.NET初学者的实践平台,帮助他们理解框架的基本结构和工作流程,从而为学习更高版本的ASP.NET打下坚实基础。 8. 个人网站项目的构建可以涵盖前端设计(HTML, CSS, JavaScript)和后端逻辑(C#或VB.NET)的综合应用。 9. 在学习过程中,初学者应该学会如何配置和使用IIS(Internet Information Services)来部署ASP.NET网站。 10. “赚取积分”可能指的是在某个在线社区、论坛或代码托管平台上,通过分享项目来获得一定的积分或奖励,这通常是用来衡量用户对社区贡献大小的一种方式。 综上所述,该“ASP.NET 2.0个人网站”项目不仅为初学者提供了一个实用的学习资源,同时体现了开发者对于开源共享精神的实践,对社区贡献出自己的力量。通过这样的实践,初学者能够更好地理解ASP.NET框架的运作,逐步建立起自己的Web开发技能。
recommend-type

【制图技术】:甘肃高质量土壤分布TIF图件的成图策略

# 摘要 本文针对甘肃土壤分布数据的TIF图件制作进行了系统研究。首先概述了甘肃土壤的分布情况,接着介绍了TIF图件的基础知识,包括其格式特点、空间数据表达以及质量控制方法。随后,文中构建了成图策略的理论框架,分析了土壤分布图的信息需求与数据处理流程,并探讨了成图原则与标准。在实践操作部分,详细阐述了制图软
recommend-type

代码解释 ```c char* image_data = (char*)malloc(width * height * channels); ```

<think>我们正在分析C语言中的一行代码:char* image_data = (char*)malloc(width * height * channels); 这行代码位于一个完整的代码片段中,该片段还包括检查内存分配是否成功。 代码功能分析: 这行代码的主要功能是动态分配一块内存,并将分配的内存地址赋值给指针变量image_data。 详细解析: 1. malloc函数:malloc是C语言中用于动态内存分配的函数,它从堆上分配指定字节数的内存,并返回一个指向这块内存起始地址的void指针(void*)。如果分配失败,则返回NULL。 2. 参数:malloc的参数