42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
|
|
#ifndef COMMON_MSG_H
|
|||
|
|
#define COMMON_MSG_H
|
|||
|
|
|
|||
|
|
#include "freertos/FreeRTOS.h"
|
|||
|
|
#include "freertos/queue.h"
|
|||
|
|
#include "esp_mac.h"
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 1. 声明消息类型枚举(全局可见)
|
|||
|
|
typedef enum
|
|||
|
|
{
|
|||
|
|
MSG_TYPE_POWER_BRIGHT, // 电源管理-亮度调节
|
|||
|
|
MSG_TYPE_POWER_OFF, // 电源管理-开关机
|
|||
|
|
// 扩展其他消息类型...
|
|||
|
|
} MsgType_t;
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 2. 声明数据联合体(全局可见)
|
|||
|
|
typedef union
|
|||
|
|
{
|
|||
|
|
int brightness; // 亮度值(电源管理)
|
|||
|
|
bool power_state; // 开关机状态(true=开机,false=关机)
|
|||
|
|
int button_id; // UI按钮ID(UI任务)
|
|||
|
|
float sensor_value; // 传感器数值(传感器任务)
|
|||
|
|
// 扩展其他数据类型...
|
|||
|
|
} MsgData_t;
|
|||
|
|
|
|||
|
|
// 3. 声明通用消息结构体(全局可见)
|
|||
|
|
typedef struct {
|
|||
|
|
MsgType_t type; // 消息类型(区分业务)
|
|||
|
|
uint32_t src_task; // 消息来源(可选,标记发送任务)
|
|||
|
|
MsgData_t data; // 消息数据(联合体按需使用)
|
|||
|
|
} GeneralMsg_t;
|
|||
|
|
|
|||
|
|
// 4. 声明全局队列句柄(extern 让其他组件可见)
|
|||
|
|
extern QueueHandle_t xGlobalMsgQueue;
|
|||
|
|
extern QueueHandle_t xPowerTaskQueue;
|
|||
|
|
|
|||
|
|
void msg_dispatch_task(void* arg);
|
|||
|
|
|
|||
|
|
#endif // COMMON_MSG_H
|