110 lines
3.3 KiB
C
110 lines
3.3 KiB
C
#ifndef APP_PARAM_MANAGE_H
|
||
#define APP_PARAM_MANAGE_H
|
||
|
||
#ifdef __cplusplus
|
||
extern "C"
|
||
{
|
||
#endif
|
||
|
||
#include "app_config.h"
|
||
|
||
|
||
// 定义参数列表宏
|
||
#define PARAM_LIST \
|
||
X(rem_ip1) \
|
||
X(rem_ip2) \
|
||
X(rem_ip3) \
|
||
X(rem_ip4) \
|
||
X(re_port) \
|
||
X(test)
|
||
|
||
// 定义一个包含所有参数名称的结构体
|
||
typedef struct {
|
||
#define X(name) const char* name;
|
||
PARAM_LIST
|
||
#undef X
|
||
} ParamNames;
|
||
|
||
// 参数结构体,不能使用位域,不要超过E2的大小, 1K byte
|
||
typedef struct
|
||
{
|
||
#define X(name) float name;
|
||
PARAM_LIST
|
||
#undef X
|
||
} ParamData;
|
||
|
||
typedef union
|
||
{
|
||
ParamData bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(ParamData)]; // 通过结构体类型确定大小
|
||
} UnParamManager;
|
||
|
||
// 定义信号操作类型
|
||
typedef enum
|
||
{
|
||
READ_OPERATION,
|
||
WRITE_OPERATION
|
||
} OperationType;
|
||
|
||
// 定义信号数据结构
|
||
typedef struct
|
||
{
|
||
void *param_ptr; // 参数数据的指针
|
||
OperationType type; // 操作类型
|
||
size_t offset; // 参数在结构体中的偏移
|
||
size_t size; // 参数大小
|
||
} ParamSignal;
|
||
|
||
#pragma pack(push, 1)
|
||
|
||
typedef struct _StrParamRequest {
|
||
//--------------------------------------------------
|
||
uint16_t frame_header; // 帧头 固定值0xFF80 (16位)
|
||
uint16_t frame_type; // 帧类型 固定值0x002A (16位)
|
||
uint16_t frame_length; // 帧长 根据参数数据的长度动态设置 (16位)
|
||
uint8_t accumulated; // 累加值 按帧累加 (8位)
|
||
uint16_t request_id; // 请求帧ID 请求ID 100表示读,101 表示写参数 (16位)
|
||
char param_name[256][8]; // 参数名称 标识要写入或读出的参数
|
||
uint8_t data[256][4]; // 数据 用于写入或读出的参数值,一个参数最大4字节 (8位*4)
|
||
uint8_t crc; // CRC 按字节累加之和 取低8位 (8位)
|
||
} StrParamRequest;
|
||
|
||
typedef union _UnParamRequest {
|
||
StrParamRequest bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrParamRequest)]; // 通过结构体类型确定大小
|
||
} UnParamRequest;
|
||
|
||
typedef struct {
|
||
UnParamRequest *param_request; // 指向 UnParamRequest 的指针
|
||
uint32_t sender_ip; // 发送方的 IP 地址(使用标准的32位整数表示)
|
||
uint16_t sender_port; // 发送方的端口号(使用标准的16位整数表示)
|
||
} RequestContext;
|
||
|
||
#pragma pack(pop)
|
||
|
||
extern UnParamRequest un_param_request;// 声明用于参数响应的帧实例
|
||
extern RequestContext request_context;
|
||
|
||
// 声明全局信号实例
|
||
extern ParamNames param_names;
|
||
extern UnParamManager param_manager; // 全局参数管理实例
|
||
extern ParamSignal param_signal;
|
||
extern uint8_t read_write_e2_finished;
|
||
extern RequestContext request_send;// 待发送的参数请求信号
|
||
|
||
uint8_t access_eeprom(size_t offset, void *data, size_t size, OperationType type);
|
||
void paramAppInit(void);
|
||
|
||
// 在适当的位置添加以下函数声明
|
||
float getParam(const char *param_name);
|
||
uint8_t setParam(const char *param_name, float value);
|
||
void printParams(void);
|
||
void handleParamOp(void *data);
|
||
void OnParamSignal(void *data);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // APP_PARAM_MANAGE_H
|