/*** 
 * @Author: mbw
 * @Date: 2024-12-09 11:40:04
 * @LastEditors: mbw && 1600520629@qq.com
 * @LastEditTime: 2025-04-22 13:19:22
 * @FilePath: \ble_-tyq_-bjq_-ch584-m\bsp\inc\bsp_valve.h
 * @Description: 
 * @
 * @Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
 */
/***
 * @Author: mbw
 * @Date: 2024-12-09 11:40:04
 * @LastEditors: mbw && 1600520629@qq.com
 * @LastEditTime: 2024-12-12 17:50:12
 * @FilePath: \ble_-tyq_-bjq_-ch584-m\bsp\inc\bsp_valve.h
 * @Description:
 * @
 * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
#ifndef __BSP_VALVE_H__
#define __BSP_VALVE_H__

#include "CH58x_common.h"

#define MAX_VALVE_NUM 8

typedef enum
{
    kValveCmdCtr = 0X01,
    kValveCmdReg,
    kValveCmdRem,
    kValveCmdRep,
    kValveCmdRemAll,//移除所有的阀门地址
    kValveEventStatus,//阀门状态包
    kValveConncetStatus,//阀门状态包
    kValveCmdMax,
} ValveCmdType;

typedef enum
{
    WirelessValveClose = 0x01,
    WirelessValveOpen,
} WireLessState;

// 阀门类型
typedef enum
{
    kTyq = 0X01,
    kZbf,
    kDcf,
} TeVavleType;

typedef enum
{
    kCmdCfg = 0X01,
    kCmdCloseVavle,
    kCmdOpenVavle,
    kCmdData,
} TeFrameCmd;

/*
无线调压阀编号
无线调压阀 MAC 地址
无线调压阀连接状态
无线调压阀开关状态
无线调压阀温度
无线调压阀进口压力
无线调压阀出口压力
无线调压阀大气压
*/
struct __attribute__((packed)) valve_data
{
    uint8_t valve_id;
    uint8_t valve_mac[6];
    uint8_t valve_connct_status;
    uint8_t valve_switch_status;
    uint8_t valve_temp;
    uint32_t valve_in_pressure;
    uint32_t valve_out_pressure;
    uint32_t valve_atm_pressure;
    uint8_t valve_voltage;//阀门电池电压
};

typedef struct valve_data_list
{
    uint8_t valve_num;
    struct valve_data valve_data[MAX_VALVE_NUM];
} valve_data_list_t;

extern valve_data_list_t valve_list;

void BSP_Valve_Init(void);
int BSP_Bt_Valve_Ctr(uint8_t *data, uint8_t len);
int BSP_Bt_Register_Valve(uint8_t *data, uint8_t len);
int BSP_Bt_Remove_Valve(uint8_t *data, uint8_t len);
int BSP_Bt_Replace_Valve(uint8_t *data, uint8_t len);
void BSP_Bt_Valve_Updata(void);
int BSP_Bt_Remove_All_Valve(void);
int BSP_Bt_Valve_Resp(uint8_t cmd, uint8_t id, uint8_t *mac_addr, uint8_t state);

#endif // ! __BSP_VALVE_H__
