IoT_SCV_CH584M/bsp/inc/bsp_valve.h

142 lines
4.1 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 VALVE_LOW_VBAT_ALARM_PERIOD_MS (1600 * 60 * 10)
#define VALVE_DECT_PERIOD_MS (1600 * 60 * 10)
#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,
kCmdTimerClose = 0x05, // 设置定时关阀
kCmdCancelTimer = 0x06, // 取消定时关阀
kCmdQueryTimer = 0x07, // 查询定时器状态
} 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;
} TsValveData;
extern TsValveData gValveData;
typedef struct __attribute__((packed))
{
uint32_t timer_minutes; // 设置的定时分钟数0表示未激活
uint32_t start_time; // 定时器启动时的时间戳
uint8_t is_active; // 定时器是否激活 0=未激活 1=激活
} TsTimerCloseState;
extern TsTimerCloseState gTimerCloseState;
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);
static uint8_t BSP_VALVE_SetTimerClose(uint32_t minutes);
static uint8_t BSP_VALVE_CancelTimerClose(void);
static uint32_t BSP_VALVE_GetRemainingMinutes(void);
#endif // ! __BSP_VALVE_H__