current_v/Inc/fm33lg0xx_queue.h
2025-12-31 08:21:43 +08:00

237 lines
6.7 KiB
C
Raw Permalink 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.

/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : fm33lg0xx_queue.h
* @brief : 消息队列头文件
* @version : 1.0
* @changelog : version 1.0 初始版本 2025.11.13
******************************************************************************
* @attention
*
* Copyright (c) 2025 Yuwell Software Danyang.Jiangsu.China
* THIS SOFTWARE is licensed under the Mulan PSL v1.
* can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FM33_QUEUE_H
#define __FM33_QUEUE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "fm33lg0xx_fl.h"
/* 增加对Malloc函数的支持 */
#include "stdlib.h"
#define NETCODE_E1_CALIB (0x0B)
#define NETCODE_E2_CALIB (0x0C)
#define NETCODE_E4_CALIB (0x05)
#define NETCODE_E7_CALIB (0x0D)
#define NETCODE_PRESS (0x01)
#define NETCODE_O2 (0x02)
#define NETCODE_TEMP_PRESS (0x03)
#define NETCODE_ELEC (0x06)
#define QUEUE_LEN_MAX (20)
#define PROGREMA_DEBUG_MODE (1)
/************************** 结构体定义 *************************/
// 标识当前传输的数据种类
typedef enum
{
MSG_TYPE_OXYGEN_SENSOR, // 氧传感器数据(浓度、流量)
MSG_TYPE_HOUR_SAVE, // 累时数据存储消息(小时)
MSG_TYPE_MINUTE_SAVE, // 累时数据存储消息(分钟)
MSG_TYPE_CURRENT_TIME, // 本次开机的累时数据
MSG_TYPE_TIME_SEND, // 累时数据公布
MSG_TYPE_AD_SAMPLING, // AD采样数据压缩机电流、NTC、储气罐压、网电压等
MSG_TYPE_AD_BOUNDARY_SEND, // EEPROM上电后取出当前记录的
MSG_TYPE_AD_BOUNDARY_SAVE, // 标定时将边界值储存到EEPROM
MSG_TYPE_OXG_STM, // 用于记录当前系统状态的状态机
MSG_TYPE_CARLIB_SAVE, // 用于记录当前报警边界值
MSG_TYPE_FILTER_SERVER, // 过滤器更换及清洁相关数据
MSG_TYPE_FILTER_TIME_SAVE, // 对过滤器更换时间进行存储
MSG_TYPE_MAX // 消息类型总数(用于边界检查)
} MsgType;
//
// 需要传输的氧传感器数据
typedef struct
{
uint16_t concentration; // 氧气浓度例如210 表示21%
uint16_t flow_rate; // 氧气流量例如50 表示5L/min
} OxygenSensorData;
// 累时数据存储消息:当前小时、分钟(用于记录设备运行时间)
typedef struct
{
uint32_t hour; // 当前小时0-19999
uint32_t minute; // 当前分钟0-59
uint32_t second; // (自开机运行的秒数)
} HourMeterData;
typedef struct
{
uint16_t adc_elec_value;
uint16_t adc_ntc_value;
uint16_t adc_press_value;
uint16_t adc_220v_value;
uint32_t voltage_elec;
uint32_t voltage_ntc;
uint32_t voltage_press;
uint32_t voltage_220v;
uint16_t real_press; // 压力真实值单位kpa
uint16_t real_ntc; // 温度真实值,单位℃
uint16_t real_220V; // 网电压真实值单位VAC
uint16_t real_elec; // 当前电流真实值 单位mA
} ADSampleData;
typedef struct
{
uint16_t elec_low_boundary;
uint16_t elec_high_boundary;
uint16_t ntc_low_boundary;
uint16_t ntc_high_boundary;
uint16_t press_low_boundary;
uint16_t press_high_boundary;
uint16_t net220v_low_boundary;
uint16_t net220v_high_boundary;
uint8_t save_index; // 选择当前往EEPROM写入哪个边界
} ADBoundary;
/* 定义制氧机的状态机 */
typedef enum
{
STM_INIT,
STM_NOM,
STM_ERROR_SHOUNTDOWN, // 机器发生报警并停机 E1-E5,LL
STM_ERROR_NONE_STOP, // 机器发生报警但是不停机状态 E7与浓度低于83.5时
STM_CARLIB, // 检测到进入到标定状态
STM_DEBUG, // 调试模式
}OXG_STM;
typedef struct
{
OXG_STM oxg_stm;
uint16_t data; // 用于枚举状态机当前处于的子状态
} StateMachine;
typedef struct
{
uint8_t netcode;
uint16_t boundary;
} CarlibSaveData;
typedef struct
{
uint32_t last_clean_filter_hours;
uint32_t last_replace_filter_hours;
bool clean_filter_time_need_stored; // 标记是否需要存储当前的清理滤芯时间
bool replace_filter_time_need_stored; // 标记当前是否需要存储更换滤芯时间
} FilterServer;
typedef union
{
OxygenSensorData oxygen; // 氧传感器数据
HourMeterData hour_meter; // 累时数据
ADSampleData adc_data;
ADBoundary adc_boundary; // AD采样阈值数据 初始上电时从EEPROM中取出 存入到故障检测任务中
StateMachine state_machine; // 记录当前系统状态机
CarlibSaveData carlib_data; // 用于保存的校准数据
FilterServer filter_server; // 用于记录是否需要更换/清洁滤芯
// 等等。。。。
}MsgData;
typedef struct
{
MsgType type; // 消息类型必须优先设置用于解析MsgData
MsgData data; // 消息具体数据根据type解析对应字段
} MsgQueueItem;
/* 消息队列节点结构体 */
typedef struct QueueNode {
MsgQueueItem item; // 消息帧子项 用于存储接收到的消息
struct QueueNode* next; // 结构体节点指针 用于指向下一个节点位置
} QueueNode;
/* 消息队列结构 */
typedef struct {
QueueNode* front; // 队头指针 用于指向消息队列的头部
QueueNode* rear; // 队尾指针 用于指向消息队列的尾部
uint32_t length; // 队列当前长度 记录当前队列中消息节点数量方便调试
} MessageQueue;
/* 外部数据导出 */
extern MessageQueue global_queue;
// 供外部使用的函数
void init_queue(MessageQueue *queue); // 消息队列初始化
bool is_queue_empty(MessageQueue* queue);
void insert_queue_node_in_head(MessageQueue* queue, MsgQueueItem frame);
bool remove_queue_node_in_head(MessageQueue* queue, MsgQueueItem* out_item);
bool remove_queue_node_by_type(MessageQueue* queue, MsgType target_type, MsgQueueItem* out_item);
bool peek_queue_node_by_type(MessageQueue* queue, MsgType target_type, MsgQueueItem* out_item);
bool modify_or_add_queue_node_by_type(MessageQueue* queue, MsgType target_type, MsgQueueItem new_data);
bool has_queue_node_of_type(MessageQueue* queue, MsgType target_type);
uint32_t count_queue_node_by_type(MessageQueue* queue, MsgType target_type);
void clear_queue(MessageQueue* queue);
#ifdef __cplusplus
}
#endif
#endif /* __FM33_QUEUE_H */
/************************ (C) COPYRIGHT Yuwell *****END OF FILE****/