BLE_TYQ_CH584M/BSP/inc/bsp_valve.h

83 lines
2.0 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 : 2024-12-12 19:08:06
* @FilePath : \BLE_TYQ_CH592F\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"
#define FRAME_HEADER 0xAA
#define FRAME_TAIL 0x55
// 0xAA CMD/DATA/ DATA_LEN (DATA) checksum 0x55
typedef enum
{
kCmdCfg = 0X01,
kCmdCloseVavle,
kCmdOpenVavle,
kCmdData,
} TeFrameCmd;
// typedef enum
// {
// } TeCmdIndex;
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[128];
} TsRawFrameData;
// 阀门类型
typedef enum
{
kTyq = 0X01,
kZbf,
kDcf,
} TeVavleType;
typedef struct __attribute__((packed))
{
uint8_t type; // 阀门类型
uint8_t bat; // 1B 电池电压 30=3V,18=1.8V
int8_t temp; // 1B 阀门温度 有符号整数 25 ℃
uint8_t hum; // 1B 阀门湿度 %RH
// uint8_t status; // 1B 阀门工作状态 超欠压、过流
// uint8_t connct_status; // 1B 阀门连接状态 电磁阀BLE控制盒 0=未连接 1=已连接
// uint8_t switch_status; // 1B 阀门开关状态 0=未知 1=关闭 2=关闭过,未按按键恢复 3=关闭过,按下了恢复键 4=打开
// uint32_t in_pressure; // 4B 阀门入口压力 Pa
// uint32_t out_pressure; // 4B 阀门出口压力 Pa
// uint32_t atm_pressure; // 4B 阀门大气压力 Pa
} TsValveData;
uint8_t CheckSum(const uint8_t *data, size_t len);
void BSP_VAVLE_Init(void);
TsFrameData* BSP_VAVLE_GetFrameData(uint8_t *data, uint16_t len);
void BSP_VALVE_Generate_Data(TsRawFrameData *pRawData, uint8_t bat, int8_t temp, uint8_t hum);
void BSP_VALVE_Generate_ValveResponse(TsRawFrameData *pRawData, TeFrameCmd cmd, uint8_t status);
#endif // ! __BSP_VALVE_H__