IoT_SCV_CH584M/bsp/inc/bsp_valve.h

143 lines
4.3 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.

/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-12 15:55:38
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2025-02-24 16:39:07
* @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_valve.h
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
#ifndef __BSP_VALVE_H__
#define __BSP_VALVE_H__
#include "CONFIG.h"
extern tmosTaskID vavle_task_id;
#define VAVLE_RX_DATA_EVT (0x0001 << 0)
#define VAVLE_TX_DATA_EVT (0x0001 << 1)
#define VAVLE_CLOSE_START_EVT (0x0001 << 2) // 关阀,开始准备
#define VAVLE_CLOSE_ACTION_EVT (0x0001 << 3) // 关阀,动作
#define VAVLE_CLOSE_END_EVT (0x0001 << 4) // 关阀结束
#define VAVLE_OPEN_START_EVT (0x0001 << 5) // 开阀,开始准备
#define VAVLE_OPEN_ACTION_EVT (0x0001 << 6) // 开阀,动作
#define VAVLE_OPEN_END_EVT (0x0001 << 9) // 开阀结束
#define VAVLE_LOW_VBAT_ALARM_EVT (0x0001 << 7) // 低电压提醒
#define VAVLE_LOOP_DECT_EVT (0x0001 << 8) // 循环检测
#define VAVLE_LOW_VBAT_LED_OFF_EVT (0x0001 << 10) // 低电压LED关闭事件
// 定时关阀相关事件
#define VAVLE_TIMER_CLOSE_EVT (0x0001 << 11) // 定时关阀事件
#define VAVLE_TIMER_CLOSE_START_EVT (0x0001 << 12) // 定时关阀开始事件
#define VALVE_LOW_VBAT_ALARM_PERIOD_MS (1600 * 60 * 10)
#define VALVE_DECT_PERIOD_MS (1600 * 60 * 10)
// 定时关阀默认时间(单位:分钟),可以根据需求调整
#define VALVE_TIMER_CLOSE_DEFAULT_MIN 30
// 定时关阀最大时间(单位:分钟)
#define VALVE_TIMER_CLOSE_MAX_MIN 360
#define CHARGE_TIME_MS (1500)
// 2.2V
#define LOW_VABAT_ALARM_VALUE 24
#define LOW_VABAT_CLOSE_VALUE 22
#define FRAME_HEADER 0xAA
#define FRAME_TAIL 0x55
// 0xAA CMD/DATA/ DATA_LEN (DATA) checksum 0x55
typedef enum
{
kCmdCfg = 0X01,
kCmdCloseVavle,
kCmdOpenVavle,
kCmdData,
kCmdTimerCloseVavle, // 新增定时关阀命令
} TeFrameCmd;
typedef struct __attribute__((packed))
{
TeFrameCmd cmd; // CMD/DATA
uint8_t len; // DATA_LEN
// TsValveData data;
uint8_t data[];
} TsFrameData;
typedef struct __attribute__((packed))
{
uint8_t len;
uint8_t buf[64];
} TsRawFrameData;
extern TsRawFrameData RelyData;
// 阀门类型
typedef enum
{
kTyq = 0X01,
kZbf,
kDcf,
} TeVavleType;
typedef enum
{
kUnknown = 0,
kClosed,
kOpened,
kDisconnect,
} TeValveSwitchStatus;
typedef struct __attribute__((packed))
{
// uint8_t status; // 1B 阀门工作状态 超欠压、过流
// uint8_t connct_status; // 1B 阀门连接状态 电磁阀BLE控制盒 0=未连接 1=已连接
uint8_t switch_status; // 1B 阀门开关状态 0=未知 1=关闭=关闭过,未按按键恢复 2=关闭过,按下了恢复键 = 打开
int8_t temp; // 1B 阀门温度 有符号整数 25 ℃
uint32_t in_pressure; // 4B 阀门入口压力 Pa
uint32_t out_pressure; // 4B 阀门出口压力 Pa
uint32_t atm_pressure; // 4B 阀门大气压力 Pa
uint8_t type; // 阀门类型
uint8_t bat; // 1B 电池电压 30=3V,18=1.8V
uint8_t humi; // 1B 阀门湿度 %RH
int8_t rssi;
// 定时关阀状态变量
uint8_t timer_close_enabled; // 定时关阀是否启用
uint16_t timer_close_min; // 定时关阀时间(分钟)
uint32_t timer_close_start_time; // 定时关阀开始时间
} TsValveData;
extern TsValveData gValveData;
uint8_t CheckSum(const uint8_t *data, size_t len);
void BSP_VAVLE_Init(void);
TsFrameData* BSP_VAVLE_GetFrameData(uint8_t *data, uint8_t len);
uint8_t GenerateRawFrame(TsRawFrameData *pRawData, uint8_t cmd, const uint8_t *p_src, uint8_t src_len);
void BSP_VALVE_Generate_Data(TsRawFrameData *pRawData, uint8_t switch_status, uint8_t bat, int8_t temp, uint8_t humi);
void BSP_VALVE_Generate_ValveResponse(TsRawFrameData *pRawData, TeFrameCmd cmd, uint8_t status);
void BSP_VALVE_Generate_UploadData(TsRawFrameData *pRawData);
// 定时关阀相关函数
void BSP_VALVE_StartTimerClose(uint16_t close_min);
void BSP_VALVE_StopTimerClose(void);
uint16_t BSP_VALVE_GetTimerCloseRemainMin(void);
#endif // ! __BSP_VALVE_H__