smart-home/firefly_esp32/main/2410库(Arduino)/HLKModuleConfig.h
2026-02-26 09:16:34 +08:00

124 lines
6.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef HLKModuleConfig_h
#define HLKModuleConfig_h
#include <Arduino.h> // 包括Arduino核心库以便使用Arduino函数
#include <SoftwareSerial.h> // 包括软件串口库
#define BUFFER_SIZE 256 // 串口缓冲区大小
class HLKModuleConfig
{
public:
HLKModuleConfig(HardwareSerial &serial); // 直接与模块通信的构造函数
HLKModuleConfig(HardwareSerial &serial, SoftwareSerial &debugSerial); // 增加调试口的构造函数
int enterATMode(); // 让模块进入at模式成功1 失败0
int exitATMode(); // 让模块退出at模式,成功1 失败0
int getVer(); // 获取版本号
int setNetwork(String ssid, String password); // 设置模块联网作为STA成功1 失败0
// 2410
struct RadarMovePower_2410 // 每个运动距离门的能量值
{
int moveGate[9] = {-1, -1, -1, -1, -1, -1, -1, -1, -1};
};
struct RadarStaticPower_2410 // 每个静止距离门的能量值
{
int staticGate[9] = {-1, -1, -1, -1, -1, -1, -1, -1, -1};
};
// 定义TargetStatus枚举类
enum class AskStatus_2410 : byte
{
Success = 0x00, // 成功
Error = 0x01, // 失败
};
// 定义TargetStatus枚举类
enum class TargetStatus_2410 : byte
{
NoTarget = 0x00, // 没有目标
MovingTarget = 0x01, // 移动目标
StaticTarget = 0x02, // 静止目标
BothTargets = 0x03,
ErrorFrame = 0x04 // 状态获取失败
};
// 定义RadarStatus结构体
struct RadarStatus_2410
{
HLKModuleConfig::TargetStatus_2410 targetStatus = HLKModuleConfig::TargetStatus_2410::ErrorFrame; // 雷达的目标状态
int distance = -1; // 雷达的目标距离单位mm
int moveSetDistance = -1; // 雷达的运动探测距离门数量,一般不用配置
int staticSetDistance = -1; // 雷达的静止探测距离门数量,一般不用配置
int detectionDistance = -1; // 雷达的最远探测距离门
int resolution = -1; // 雷达的距离门分辨率
int noTargrtduration = -1; // 无人持续时间
int radarMode_2410 = -1; // 用来区分模块处于基本上报模式2还是工程上报模式1
HLKModuleConfig::RadarMovePower_2410 radarMovePower; // 运动能量值
HLKModuleConfig::RadarStaticPower_2410 radarStaticPower; // 静止能量值
int photosensitive = -1; // 光敏 0-255
};
// 用来返回下发指令的结果
struct DataResult_2410
{
byte *resultBuffer; // 指向动态分配的数组
int length; // 数组的长度
};
// 获取雷达感应状态
RadarStatus_2410 getStatus_2410();
// 发送指令
HLKModuleConfig::DataResult_2410 HLKModuleConfig::sendCommand_2410(const byte* sendData, int sendDataLength);
// 使能配置指令
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::enableConfigMode_2410();
// 结束使能配置指令
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::disableConfigMode_2410();
// 读取雷达固件版本
String HLKModuleConfig::getVersion_2410();
// 配置最大距离门和无人持续时间
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::setDetectionDistance_2410(int distance,int times);
// 配置距离门灵敏度
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::setGatePower_2410(int gate,int movePower, int staticPower);
// 读取参数命令
HLKModuleConfig::RadarStatus_2410 HLKModuleConfig::getConfig_2410();
// 设置距离门分辨率,1为0.25M0为0.75M。默认0.75M
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::setResolution_2410(int resolution);
// 获取距离门分辨率,1为0.25M0为0.75M。默认0.75M
HLKModuleConfig::RadarStatus_2410 HLKModuleConfig::getResolution_2410();
// 重启指令
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::rebootRadar();
// 回复出厂指令
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::refactoryRadar();
// 使能工程模式
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::enableEngineeringModel();
// 退出工程模式
HLKModuleConfig::AskStatus_2410 HLKModuleConfig::disableEngineeringModel();
private:
// 可以在这里定义私有变量或方法
HardwareSerial &_serial; // 成员变量用于在库中引用Serial对象
SoftwareSerial &_debugSerial;
char buffer[BUFFER_SIZE]; // 将 buffer 定义为成员变量
unsigned long receiveStartTime;
const unsigned long RECEIVE_TIMEOUT = 100; // 接收超时时间,单位毫秒
int bufferIndex;
int isInATMode; // 用来确认是不是在AT模式下
int checkBuffer();
int sendATCommand(String command);
int sendATCommandWithExit(String command);
// 2410
byte buffer_2410[BUFFER_SIZE];
int bufferIndex_2410;
static const byte frameStart_2410[];
static const byte frameEnd_2410[];
static const byte frameAskStart_2410[];
static const byte frameAskEnd_2410[];
static const int FRAME_START_SIZE_2410 = 4;
static const int FRAME_END_SIZE_2410 = 4;
int findSequence(byte *arr, int arrLen, const byte *seq, int seqLen);
};
#endif