加了阀门控制指令和读取接收
This commit is contained in:
parent
c73af3b98e
commit
fafb2aff2f
|
@ -13,5 +13,6 @@ encoding//StdPeriphDriver/inc/CH58x_common.h=GBK
|
|||
encoding//StdPeriphDriver/inc/CH58x_gpio.h=GBK
|
||||
encoding//StdPeriphDriver/inc/CH58x_sys.h=GBK
|
||||
encoding//StdPeriphDriver/inc/ISP585.h=GBK
|
||||
encoding//bsp/inc/bsp_master.h=GBK
|
||||
encoding//bsp/inc/bsp_uart.h=UTF-8
|
||||
encoding//bsp/src/bsp_master.c=GBK
|
||||
|
|
|
@ -113,6 +113,8 @@ extern void Central_Init(void);
|
|||
*/
|
||||
extern uint16_t Central_ProcessEvent(uint8_t task_id, uint16_t events);
|
||||
extern centralConnItem_t centralConnList[CENTRAL_MAX_CONNECTION];
|
||||
|
||||
int BSP_Master_Send(centralConnItem_t *centralConnList, uint8_t id, uint8_t *Data, uint8_t Len);
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
|
|
|
@ -180,6 +180,7 @@ static void centralAddDeviceInfo(uint8_t *pAddr, uint8_t addrType);
|
|||
static void centralInitConnItem(uint8_t task_id, centralConnItem_t *centralConnList);
|
||||
static uint8_t centralAddrCmp(peerAddrDefItem_t *PeerAddrDef, uint8_t *addr);
|
||||
|
||||
int BSP_Master_Receive_Data(uint8_t task_id, uint8_t *data, uint16_t len);
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
*/
|
||||
|
@ -638,6 +639,10 @@ static void centralProcessGATTMsg(gattMsgEvent_t *pMsg)
|
|||
{
|
||||
logDebug("Noti: ");
|
||||
logHexDumpAll(pMsg->msg.handleValueNoti.pValue, pMsg->msg.handleValueNoti.len);
|
||||
if (connItem == CONNECT0_ITEM)
|
||||
{
|
||||
BSP_Master_Receive_Data(CONNECT0_ITEM, pMsg->msg.handleValueNoti.pValue, pMsg->msg.handleValueNoti.len);
|
||||
}
|
||||
}
|
||||
else if (centralConnList[connItem].discState != BLE_DISC_STATE_IDLE)
|
||||
{
|
||||
|
@ -1072,12 +1077,11 @@ static void centralGATTDiscoveryEvent(uint8_t connItem, gattMsgEvent_t *pMsg)
|
|||
{
|
||||
if (char_properties & (GATT_PROP_NOTIFY))
|
||||
{
|
||||
centralConnList[connItem].discState = BLE_DISC_STATE_IDLE;
|
||||
centralConnList[connItem].discState = BLE_DISC_STATE_IDLE;
|
||||
centralConnList[connItem].charHd4 = char_value_handle + 1;
|
||||
centralConnList[connItem].procedureInProgress = FALSE;
|
||||
logDebug("char4 Write handle\t:%04x\r\n", char_value_handle);
|
||||
tmos_start_task(centralConnList[CONNECT0_ITEM].taskID, CH4_NOTI_EVT, 1600);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1086,7 +1090,7 @@ static void centralGATTDiscoveryEvent(uint8_t connItem, gattMsgEvent_t *pMsg)
|
|||
// 连接1的枚举
|
||||
// else if (connItem == CONNECT1_ITEM)
|
||||
// {
|
||||
|
||||
|
||||
// }
|
||||
// 连接2的枚举
|
||||
// else if(connItem == CONNECT2_ITEM)
|
||||
|
@ -1160,45 +1164,56 @@ static uint8_t centralAddrCmp(peerAddrDefItem_t *PeerAddrDef, uint8_t *addr)
|
|||
/************************ endfile @ central **************************/
|
||||
|
||||
/*用户自定义文件*/
|
||||
void BSP_Master_Send(centralConnItem_t *centralConnList, uint8_t id, uint8_t *Data, uint8_t Len)
|
||||
int BSP_Master_Send(centralConnItem_t *centralConnList, uint8_t id, uint8_t *Data, uint8_t Len)
|
||||
{
|
||||
int ret = 0;
|
||||
attWriteReq_t req;
|
||||
uint8_t res;
|
||||
|
||||
if (centralConnList[id].state == BLE_STATE_CONNECTED) // 检查连接状态是否为连接状态
|
||||
{
|
||||
req.cmd = FALSE;
|
||||
req.sig = FALSE;
|
||||
req.handle = centralConnList[id].charHd3;
|
||||
req.len = Len;
|
||||
req.pValue = GATT_bm_alloc(centralConnList[id].connHandle, ATT_WRITE_REQ, req.len, NULL, 0);
|
||||
if (req.pValue != NULL)
|
||||
if (centralConnList[id].procedureInProgress == FALSE)
|
||||
{
|
||||
tmos_memcpy(req.pValue, Data, Len);
|
||||
res = GATT_WriteCharValue(centralConnList[id].connHandle, &req, centralTaskId);
|
||||
if (res == SUCCESS)
|
||||
req.cmd = FALSE;
|
||||
req.sig = FALSE;
|
||||
req.handle = centralConnList[id].charHd3;
|
||||
req.len = Len;
|
||||
req.pValue = GATT_bm_alloc(centralConnList[id].connHandle, ATT_WRITE_REQ, req.len, NULL, 0);
|
||||
if (req.pValue != NULL)
|
||||
{
|
||||
logDebug("\n Master Write ok");
|
||||
tmos_memcpy(req.pValue, Data, Len);
|
||||
res = GATT_WriteCharValue(centralConnList[id].connHandle, &req, centralTaskId);
|
||||
if (res == SUCCESS)
|
||||
{
|
||||
logDebug("\n Master Write ok");
|
||||
centralConnList[id].procedureInProgress == FALSE;
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("\n Master Write faild= %x", res);
|
||||
GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("\n Master Write faild= %x", res);
|
||||
GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
|
||||
logDebug("\n alloc Faild");
|
||||
ret = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logDebug("\n alloc Faild");
|
||||
}
|
||||
ret = 3;
|
||||
}
|
||||
ret = 4;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BSP_Master_Receive_Data(uint8_t *data, uint16_t len)
|
||||
int BSP_Master_Receive_Data(uint8_t task_id, uint8_t *data, uint16_t len)
|
||||
{
|
||||
int ret = 0;
|
||||
uint16_t index = 0;
|
||||
uint8_t data_buf[64] = {0};
|
||||
// 解析接收到的数据帧,先寻找AA开头,然后再找AA下一个字节,其代表了数据长度,然后找到代表长度的值的长度的下一位,其为校验码,校验码后为结束码0x55,
|
||||
// 解析接收到的数据帧,先寻找AA开头,然后再找AA下一个字节,其代表命令,然后找到代表长度的值的长度的下一位,其为校验码,校验码后为结束码0x55,
|
||||
// 如果数据正确,则提取数据,不正确,则不处理
|
||||
if (len < 4)
|
||||
{ // 至少需要 4 个字节:起始码、长度、校验码、结束码
|
||||
|
@ -1217,8 +1232,8 @@ int BSP_Master_Receive_Data(uint8_t *data, uint16_t len)
|
|||
return 2;
|
||||
}
|
||||
|
||||
uint16_t datalength = data[index + 1]; // 读取数据长度
|
||||
if (index + 2 + datalength + 1 >= len) // 检查数据长度是否合理 数据长度 + 校验码 + 结束码
|
||||
uint16_t datalength = data[index + 2]; // 读取数据长度
|
||||
if (index + 3 + datalength + 1 >= len) // 检查数据长度是否合理 数据长度 + 校验码 + 结束码
|
||||
{
|
||||
|
||||
logError("BT 数据帧长度错误");
|
||||
|
@ -1226,31 +1241,50 @@ int BSP_Master_Receive_Data(uint8_t *data, uint16_t len)
|
|||
return 3; //
|
||||
}
|
||||
|
||||
uint8_t rx_sum = data[index + 2 + datalength]; // 读取校验码
|
||||
uint8_t calculated_sum = XOR_CheckSum(&data[0], datalength + 2); // 计算校验码
|
||||
uint8_t rx_sum = data[index + 3 + datalength]; // 读取校验码
|
||||
uint8_t calculated_sum = _CheckSum(&data[index], datalength + 3); // 计算校验码
|
||||
|
||||
if (rx_sum != calculated_sum)
|
||||
{
|
||||
|
||||
logError("BT 数据帧校验码错误 rx_sum = %02X, calculated_sum = %02X", rx_sum, calculated_sum);
|
||||
logHexDumpAll(data, len);
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (data[index + 2 + datalength + 1] != 0x55) // 检查结束码
|
||||
if (data[index + 3 + datalength + 1] != 0x55) // 检查结束码
|
||||
{
|
||||
logError("BT 数据帧结束码错误");
|
||||
logHexDumpAll(data, len);
|
||||
|
||||
return 5;
|
||||
}
|
||||
// 到这一步说明数据没问题,将接收到的数据通过中心任务发送出去
|
||||
// uint8_t *p_data;
|
||||
// p_data = tmos_msg_allocate(length);
|
||||
// if (p_data)
|
||||
// {
|
||||
// tmos_memcpy(p_data, data, length);
|
||||
// tmos_msg_send(task_id, p_data);
|
||||
// }
|
||||
//
|
||||
// tmos_msg_send(task_id, data);
|
||||
logDebug("BT 数据帧校验通过");
|
||||
|
||||
// //有效数据长度
|
||||
size_t data_len = (datalength + 5);
|
||||
if (data[index + 1] == kCmdCfg) // 0x01 代表了其是控制阀门响应
|
||||
{
|
||||
logDebug("BT 控制阀门响应包");
|
||||
logHexDumpAll(&data[index], len);
|
||||
}
|
||||
else if (data[index + 1] == kCmdData) // 这个是代表了其是心跳数据包
|
||||
{
|
||||
logDebug("BT 心跳数据包");
|
||||
logHexDumpAll(&data[index], len);
|
||||
valve_list.valve_num = task_id + 1;
|
||||
valve_list.valve_data[task_id].valve_id = data[index + 4];
|
||||
// tmos_memcpy(valve_list.valve_data[task_id].valve_mac, &data[index + 5], 6); //将数据提取到结构体中
|
||||
}
|
||||
// //有效数据长度
|
||||
// size_t data_len = (datalength + 5);
|
||||
// //到这一步说明数据没问题,将接收到的数据通过中心任务发送出去
|
||||
// uint8_t *p_data;
|
||||
// p_data = tmos_msg_allocate(data_len);
|
||||
// if (p_data)
|
||||
// {
|
||||
// tmos_memcpy(p_data, data, data_len);
|
||||
// tmos_msg_send(BtRxTaskId, p_data);
|
||||
// tmos_start_task(BtRxTaskId, SYS_EVENT_MSG, 0);
|
||||
// }
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,84 +1,19 @@
|
|||
//#ifndef __BSP_MASTER_H__
|
||||
//#define __BSP_MASTER_H__
|
||||
//
|
||||
//
|
||||
//#include "CH58x_common.h"
|
||||
//#include "CH58xBLE_LIB.h"
|
||||
//
|
||||
//
|
||||
//
|
||||
//typedef enum
|
||||
//{
|
||||
// BLE_STATE_IDLE,
|
||||
// BLE_STATE_ADV,
|
||||
// BLE_STATE_CONNECT,
|
||||
// BLE_STATE_DISCONNECT,
|
||||
//} BleState;
|
||||
//
|
||||
//typedef enum
|
||||
//{
|
||||
// kValveClose,
|
||||
// kValveOpen,
|
||||
//}BtValveState;
|
||||
//
|
||||
//typedef struct
|
||||
//{
|
||||
// uint8_t buf[];
|
||||
//}BleValveData;
|
||||
//
|
||||
//struct __attribute__((packed)) valve_data
|
||||
//{
|
||||
// uint8_t header;
|
||||
// uint8_t valve_type; // 阀门类型
|
||||
// uint8_t valve_bat; // 1B 电池电压 30=3V,18=1.8V
|
||||
// uint8_t valve_status; // 1B 阀门工作状态 超欠压、过流
|
||||
// uint8_t valve_connct_status; // 1B 阀门连接状态 (电磁阀BLE控制盒) 0=未连接 1=已连接
|
||||
// uint8_t valve_switch_status; // 1B 阀门开关状态 0=未知 1=关闭 2=关闭过,未按按键恢复 3=关闭过,按下了恢复键 4=打开
|
||||
// int8_t valve_temp; // 1B 阀门温度 有符号整数 25 ℃
|
||||
// uint32_t valve_in_pressure; // 4B 阀门入口压力 Pa
|
||||
// uint32_t valve_out_pressure; // 4B 阀门出口压力 Pa
|
||||
// uint32_t valve_atm_pressure; // 4B 阀门大气压力 Pa
|
||||
// uint8_t check;
|
||||
// uint8_t tail;
|
||||
//};
|
||||
//
|
||||
//
|
||||
//
|
||||
//void BSP_Master_Send(centralConnItem_t *centralConnList, uint8_t id, uint8_t *Data, uint8_t Len);
|
||||
//int BSP_Master_Receive_Data(uint8_t *data, uint16_t len);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//#endif // ! __BSP_MASTER_H__
|
||||
#ifndef __BSP_MASTER_H__
|
||||
#define __BSP_MASTER_H__
|
||||
|
||||
#include "CH58x_common.h"
|
||||
#include "CH58xBLE_LIB.h"
|
||||
|
||||
// 0xAA CMD/DATA/ DATA_LEN (DATA) checksum 0x55
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
{
|
||||
uint8_t header;
|
||||
uint8_t cmd; // CMD/DATA
|
||||
uint8_t len; // DATA_LEN
|
||||
uint8_t *pData;
|
||||
uint8_t checksum;
|
||||
uint8_t tail;
|
||||
} TsFrameData;
|
||||
|
||||
#endif // ! __BSP_MASTER_H__
|
||||
|
|
|
@ -48,7 +48,7 @@ void BSP_UART3_Init(void);
|
|||
unsigned int BSP_Uart3_Receive_Data(void *buf, unsigned int len);
|
||||
unsigned int BSP_Uart3_Send_Data(const void *buf, unsigned int len);
|
||||
|
||||
uint8_t XOR_CheckSum(const uint8_t *data, size_t len);
|
||||
uint8_t _CheckSum(const uint8_t *data, size_t len);
|
||||
extern uint8_t BtRxTaskId;
|
||||
|
||||
#endif // !__BSP_UART_H__
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
#ifndef __BSP_VALVE_H__
|
||||
#define __BSP_VALVE_H__
|
||||
/***
|
||||
* @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 {
|
||||
typedef enum
|
||||
{
|
||||
kValveCmdCtr = 0X01,
|
||||
kValveCmdReg,
|
||||
kValveCmdRem,
|
||||
|
@ -16,10 +26,23 @@ typedef enum {
|
|||
|
||||
typedef enum
|
||||
{
|
||||
WirelessValveClose,
|
||||
WirelessValveOpen,
|
||||
WirelessValveClose = 0x01,
|
||||
WirelessValveOpen,
|
||||
} WireLessState;
|
||||
|
||||
// 阀门类型
|
||||
typedef enum
|
||||
{
|
||||
kTyq = 0X01,
|
||||
kZbf,
|
||||
kDcf,
|
||||
} TeVavleType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
kCmdCfg = 0X01,
|
||||
kCmdData,
|
||||
} TeFrameCmd;
|
||||
|
||||
typedef struct valve_data valve_data_t;
|
||||
|
||||
|
@ -37,21 +60,26 @@ 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;
|
||||
TeVavleType 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
|
||||
};
|
||||
|
||||
typedef struct valve_data_list
|
||||
{
|
||||
uint8_t valve_num;
|
||||
valve_data_t valve_data[MAX_VALVE_NUM];
|
||||
} valve_data_list_t ;
|
||||
|
||||
|
||||
} valve_data_list_t;
|
||||
|
||||
extern valve_data_list_t valve_list;
|
||||
|
||||
|
@ -61,25 +89,4 @@ 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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // ! __BSP_VALVE_H__
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-12-06 16:52:30
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2024-12-12 11:12:18
|
||||
* @LastEditTime: 2024-12-12 17:30:58
|
||||
* @FilePath: \ble_-tyq_-bjq_-ch584-m\bsp\src\bsp_uart.c
|
||||
* @Description:
|
||||
*
|
||||
|
@ -48,7 +48,7 @@ BTFrameData bt_frame = {0};
|
|||
* @param {uint16_t} len
|
||||
* @return {*}
|
||||
*/
|
||||
uint8_t XOR_CheckSum(const uint8_t *data, size_t len)
|
||||
uint8_t _CheckSum(const uint8_t *data, size_t len)
|
||||
{
|
||||
uint8_t sum = 0;
|
||||
|
||||
|
@ -142,8 +142,8 @@ int BSP_Bt_Process(uint8_t *data, uint16_t len)
|
|||
return 3; //
|
||||
}
|
||||
|
||||
uint8_t rx_sum = data[index + 2 + datalength]; // 读取校验码
|
||||
uint8_t calculated_sum = XOR_CheckSum(&data[0], datalength + 2); // 计算校验码
|
||||
uint8_t rx_sum = data[index + 2 + datalength]; // 读取校验码
|
||||
uint8_t calculated_sum = _CheckSum(&data[0], datalength + 2); // 计算校验码
|
||||
if (rx_sum != calculated_sum)
|
||||
{
|
||||
|
||||
|
@ -200,7 +200,7 @@ uint8_t BT_GenerateRawFrame(BTFrameData *pRawData, const uint8_t *p_src, uint8_t
|
|||
|
||||
// 从帧起始符开始到校验码之前所有字节的和的模256
|
||||
// ,即各字节不计超过255的溢出值的二进制算术和。
|
||||
pRawData->buf[pRawData->len - 2] = XOR_CheckSum(&pRawData->buf[0], pRawData->len - 2);
|
||||
pRawData->buf[pRawData->len - 2] = _CheckSum(&pRawData->buf[0], pRawData->len - 2);
|
||||
pRawData->buf[pRawData->len - 1] = 0X55;
|
||||
|
||||
logHexDumpAll(&pRawData->buf[0], pRawData->len);
|
||||
|
@ -231,13 +231,15 @@ uint16_t BT_ProcessEvent(uint8_t task_id, uint16_t events)
|
|||
if (events & SYS_EVENT_MSG)
|
||||
{
|
||||
uint8_t *pMsg;
|
||||
uint8_t master_buf[64] = {0};
|
||||
if ((pMsg = tmos_msg_receive(BtRxTaskId)) != NULL)
|
||||
{
|
||||
PRINT("revice data:");
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
PRINT("%02x ", pMsg[i]);
|
||||
}
|
||||
// for (uint8_t i = 0; i < 5; i++)
|
||||
// {
|
||||
// PRINT("%02x ", pMsg[i]);
|
||||
// }
|
||||
tmos_memcpy(master_buf, pMsg, sizeof(master_buf));
|
||||
PRINT("\r\n");
|
||||
// Release the TMOS message
|
||||
tmos_msg_deallocate(pMsg);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-12-09 11:40:10
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2024-12-11 15:43:47
|
||||
* @LastEditTime: 2024-12-12 18:34:45
|
||||
* @FilePath: \ble_-tyq_-bjq_-ch584-m\bsp\src\bsp_valve.c
|
||||
* @Description:
|
||||
*
|
||||
|
@ -16,8 +16,9 @@
|
|||
#include "multiCentral.h"
|
||||
|
||||
/*
|
||||
接收数据帧格式: 帧头 + 数据长度 + 命令 + id + mac + (状态)(只针对控制指令,其他指令不含) + 校验码 + 帧尾
|
||||
发送数据帧格式: 帧头 + 数据长度 + 命令 + id + mac + 响应码 + 校验码 + 帧尾
|
||||
接收的蓝牙从机info:
|
||||
接收数据帧格式: 帧头 + 命令 + 数据长度 + 心跳数据包 + 校验码 + 帧尾
|
||||
发送数据帧格式: 帧头 + 命令 + 数据长度 + 控制数据 + 校验码 + 帧尾
|
||||
*/
|
||||
|
||||
#undef LOG_ENABLE
|
||||
|
@ -26,24 +27,46 @@
|
|||
#include "log.h"
|
||||
|
||||
valve_data_list_t valve_list = {0};
|
||||
BTFrameData valve_frame_data = {0};
|
||||
|
||||
uint8_t Valve_GenerateRawFrame(BTFrameData *pRawData, const uint8_t cmd, const uint8_t *p_src, uint8_t src_len)
|
||||
{
|
||||
pRawData->len = src_len + 5;
|
||||
|
||||
tmos_memset(pRawData->buf, 0, sizeof(pRawData->buf));
|
||||
|
||||
pRawData->buf[0] = 0XAA;
|
||||
pRawData->buf[1] = cmd;
|
||||
pRawData->buf[2] = src_len;
|
||||
if (src_len > 0)
|
||||
{
|
||||
tmos_memcpy(&pRawData->buf[3], p_src, src_len);
|
||||
}
|
||||
pRawData->buf[pRawData->len - 2] = _CheckSum(&pRawData->buf[0], pRawData->len - 2);
|
||||
pRawData->buf[pRawData->len - 1] = 0X55;
|
||||
logHexDumpAll(pRawData->buf, pRawData->len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BSP_Valve_Close(uint8_t valve_id)
|
||||
{
|
||||
uint8_t num = Flash_Get_Valve_Num();
|
||||
|
||||
uint8_t num = Flash_Get_Valve_Num();
|
||||
uint8_t valve_ctr_valve = WirelessValveClose;
|
||||
if ((valve_id > 8) && (num == 0))
|
||||
{
|
||||
logError("BSP_Valve_Close: valve id error");
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
logDebug("BSP_Valve_Close: valve id: %d", valve_id);
|
||||
// TODO:检查是否连接, 如果连接,则发送数据,将关闭阀门指令发送过去,然后等待数据接收响应,如果接收到响应是关闭状态0x01,则返回成功,否则失败
|
||||
|
||||
// BSP_Master_Send(centralConnList, CONNECT0_ITEM, 0x01, 1);
|
||||
|
||||
return 0;
|
||||
|
||||
Valve_GenerateRawFrame(&valve_frame_data, kValveCmdCtr, &valve_ctr_valve, 1);
|
||||
|
||||
return BSP_Master_Send(centralConnList, CONNECT0_ITEM, &valve_frame_data.buf[0], valve_frame_data.len);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC),
|
||||
BSP_Valve_Close, BSP_Valve_Close, "valve_id:CONNECT0_ITEM = 0");
|
||||
|
||||
/*用于控制阀门的状态
|
||||
* id: 1-8
|
||||
|
@ -85,7 +108,7 @@ int BSP_Bt_Register_Valve(uint8_t *data, uint8_t len)
|
|||
else
|
||||
{
|
||||
logError("valve id error");
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
for (; i < FLASH_MAC_INFO_LEN; i++)
|
||||
|
@ -192,18 +215,18 @@ int BSP_Bt_Replace_Valve(uint8_t *data, uint8_t len)
|
|||
/*更新阀门信息*/
|
||||
void BSP_Bt_Valve_Updata(void)
|
||||
{
|
||||
uint8_t cnt = 0;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t mac[6] = {0};
|
||||
uint8_t num = Flash_Get_Valve_Num();
|
||||
uint8_t num = Flash_Get_Valve_Num();
|
||||
logInfo("BSP_Bt_Valve_Updata");
|
||||
tmos_memset(&valve_list, 0, sizeof(valve_data_list_t));
|
||||
for (int i = 0; i < MAX_VALVE_NUM; i++)//这个循环是为了将数据拷贝到valve_list中, 并且保证id号和flash对应起来
|
||||
for (int i = 0; i < MAX_VALVE_NUM; i++) // 这个循环是为了将数据拷贝到valve_list中, 并且保证id号和flash对应起来
|
||||
{
|
||||
if(Flash_Get_Mac_Addr(mac, i) == 0)
|
||||
if (Flash_Get_Mac_Addr(mac, i) == 0)
|
||||
{
|
||||
if (tmos_isbufset(mac, 0xFF, 6) == FALSE)//不是默认值
|
||||
if (tmos_isbufset(mac, 0xFF, 6) == FALSE) // 不是默认值
|
||||
{
|
||||
tmos_memcpy(valve_list.valve_data[cnt].valve_mac, mac, 6);//这样做的目的就是读取方便,只需要根据flash中读取到的数量进行读取前N个值
|
||||
tmos_memcpy(valve_list.valve_data[cnt].valve_mac, mac, 6); // 这样做的目的就是读取方便,只需要根据flash中读取到的数量进行读取前N个值
|
||||
valve_list.valve_data[cnt].valve_id = i + 1;
|
||||
cnt++;
|
||||
logDebug(" updata valve_id: %d, valve_mac: %02X %02X %02X %02X %02X %02X", i + 1, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
@ -239,5 +262,4 @@ void BSP_Valve_Init(void)
|
|||
}
|
||||
|
||||
logInfo("BSP_Valve_Init end");
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue