diff --git a/APP/multiCentral.c b/APP/multiCentral.c index d3f7528..5db6d32 100644 --- a/APP/multiCentral.c +++ b/APP/multiCentral.c @@ -715,8 +715,8 @@ static void centralEventCB(gapRoleEvent_t *pEvent) case GAP_DEVICE_INIT_DONE_EVENT: { GAPRole_CentralCancelDiscovery(); - logDebug("停止扫描,发起直连\r\n"); - tmos_start_task(MasterCtrTaskId, MASTER_CONNECT_EVT, 800); + // logDebug("停止扫描,发起直连\r\n"); + // tmos_start_task(MasterCtrTaskId, MASTER_CONNECT_EVT, 800); } break; case GAP_DEVICE_INFO_EVENT: @@ -1188,7 +1188,7 @@ int BSP_Master_Send(centralConnItem_t *centralConnList, uint8_t id, uint8_t *Dat } else { - logError("no BLE_STATE_CONNECTED"); + logError("没有连接成功"); ret = 4; } return ret; @@ -1263,7 +1263,7 @@ int BSP_Master_Receive_Data(uint8_t task_id, uint8_t *data, uint16_t len) } else if (data[index + 1] == kValveCmdRep) // 这个是代表了其是心跳数据包 { - logDebug("BT 心跳数据包:"); + logDebug("蓝牙从机心跳数据包:"); logHexDumpAll(data, data_len); } // 到这一步说明数据没问题,将接收到的数据通过中心任务发送出去 @@ -1284,23 +1284,23 @@ void Master_Connect(void) uint8_t def_mac[6] = {0xFF}; uint8_t cnt = Flash_Get_Valve_Num(); logDebug("cnt:%d\r\n", cnt); - if (cnt == 0) - { - GAPRole_CentralEstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE, - DEFAULT_LINK_WHITE_LIST, - ADDRTYPE_PUBLIC, - def_mac); - tmos_start_task(centralTaskId, ESTABLISH_LINK_TIMEOUT_EVT, ESTABLISH_LINK_TIMEOUT); + // if (cnt == 0) + // { + // GAPRole_CentralEstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE, + // DEFAULT_LINK_WHITE_LIST, + // ADDRTYPE_PUBLIC, + // def_mac); + // tmos_start_task(centralTaskId, ESTABLISH_LINK_TIMEOUT_EVT, ESTABLISH_LINK_TIMEOUT); - // uint8_t mac_addr[6] = {0x93, 0xB4, 0x8F, 0x10, 0x53, 0x5C}; - // logHexDumpAll(mac_addr, 6); - // GAPRole_CentralEstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE, - // DEFAULT_LINK_WHITE_LIST, - // ADDRTYPE_PUBLIC, - // mac_addr); - // tmos_start_task(centralTaskId, ESTABLISH_LINK_TIMEOUT_EVT, ESTABLISH_LINK_TIMEOUT); - return; - } + // // uint8_t mac_addr[6] = {0x93, 0xB4, 0x8F, 0x10, 0x53, 0x5C}; + // // logHexDumpAll(mac_addr, 6); + // // GAPRole_CentralEstablishLink(DEFAULT_LINK_HIGH_DUTY_CYCLE, + // // DEFAULT_LINK_WHITE_LIST, + // // ADDRTYPE_PUBLIC, + // // mac_addr); + // // tmos_start_task(centralTaskId, ESTABLISH_LINK_TIMEOUT_EVT, ESTABLISH_LINK_TIMEOUT); + // return; + // } for (uint8_t i = 0; i < cnt; i++) { @@ -1321,6 +1321,7 @@ void Master_Connect(void) void Master_DisConnect(void) { GAPRole_TerminateLink(centralConnList[0].connHandle); + // centralConnList[0].state = BLE_STATE_IDLE; logDebug("主动断开连接\r\n"); } @@ -1333,10 +1334,15 @@ uint16_t Master_ProcessEvent(uint8_t task_id, uint16_t events) { if (centralConnList[0].state != BLE_STATE_CONNECTED) { - if (Flash_Get_Valve_Num()) + if (Flash_Get_Valve_Num())//如果有设备,发起连接 { tmos_start_task(task_id, MASTER_CONNECT_EVT, 2400); } + else//没有则开启定时检测 + { + logDebug("没有设备,开启定时检测\r\n"); + tmos_start_task(task_id, MASTER_DETECT_EVT, 2400); + } } return (events ^ MASTER_START_EVT); } @@ -1344,23 +1350,21 @@ uint16_t Master_ProcessEvent(uint8_t task_id, uint16_t events) { if (centralConnList[0].state != BLE_STATE_CONNECTED) { - - tmos_start_task(task_id, MASTER_CONNECT_EVT, 2400); - } - else - { - tmos_start_task(task_id, MASTER_DETECT_EVT, 2400); + if (Flash_Get_Valve_Num()) + { + logDebug("有设备,尝试连接\r\n"); + tmos_start_task(task_id, MASTER_CONNECT_EVT, 2400); + } } + tmos_start_task(task_id, MASTER_DETECT_EVT, 2400); return (events ^ MASTER_DETECT_EVT); } - else if (events & MASTER_CONNECT_EVT) { if (centralConnList[0].state != BLE_STATE_CONNECTED) { Master_Connect(); - tmos_start_task(task_id, MASTER_DETECT_EVT, 2400); } return (events ^ MASTER_CONNECT_EVT); } diff --git a/bsp/src/bsp_uart.c b/bsp/src/bsp_uart.c index 899142a..c7e4d33 100644 --- a/bsp/src/bsp_uart.c +++ b/bsp/src/bsp_uart.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-12-06 16:52:30 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-16 16:01:21 + * @LastEditTime: 2024-12-16 20:03:21 * @FilePath: \ble_-tyq_-bjq_-ch584-m\bsp\src\bsp_uart.c * @Description: * @@ -227,7 +227,7 @@ uint8_t BT_GenerateRawFrame(BTFrameData *pRawData, const uint8_t *p_src, uint8_t pRawData->buf[pRawData->len - 2] = _CheckSum(&pRawData->buf[0], pRawData->len - 2); pRawData->buf[pRawData->len - 1] = 0X55; - logInfo("BT_GenerateRawFrame"); + logInfo("蓝牙主机发送数据给报警器:"); logHexDumpAll(&pRawData->buf[0], pRawData->len); return 0; @@ -324,7 +324,6 @@ uint16_t BT_ProcessEvent(uint8_t task_id, uint16_t events) { lwrb_reset(&uart1_rx_t); lwrb_reset(&uart1_tx_t); - tmos_start_task(task_id, BT_INFO_UPDATA_EVT, 0); tmos_start_task(task_id, BT_REC_EVT, 800); return (events ^ BT_START_EVT); diff --git a/bsp/src/bsp_valve.c b/bsp/src/bsp_valve.c index 4e6233e..a9e559d 100644 --- a/bsp/src/bsp_valve.c +++ b/bsp/src/bsp_valve.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-12-09 11:40:10 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-16 19:11:35 + * @LastEditTime: 2024-12-16 20:35:38 * @FilePath: \ble_-tyq_-bjq_-ch584-m\bsp\src\bsp_valve.c * @Description: * @@ -114,6 +114,11 @@ int BSP_Bt_Register_Valve(uint8_t *data, uint8_t len) return 1; } + if (tmos_isbufset(&data[1], 0, FLASH_MAC_INFO_LEN) == TRUE) + { + logError("阀门写值错误为0"); + return 1; + } logDebug("注册阀门信息:"); if (tmos_memcmp(&data[1], mac_addr, FLASH_MAC_INFO_LEN) == TRUE) { @@ -136,6 +141,7 @@ int BSP_Bt_Register_Valve(uint8_t *data, uint8_t len) uint8_t num = Flash_Get_Valve_Num(); Flash_Set_Valve_Num(num + 1); BSP_Bt_Valve_Updata(); // 更新阀门信息 + } } else @@ -231,7 +237,11 @@ void BSP_Bt_Valve_Updata(void) uint8_t num = Flash_Get_Valve_Num(); logInfo("BSP_Bt_Valve_Updata num: %d ", num); - + if (num == 0) + { + return; + } + tmos_memset(&valve_list, 0, sizeof(valve_data_list_t)); for (int i = 0; i < MAX_VALVE_NUM; i++) // 这个循环是为了将数据拷贝到valve_list中, 并且保证id号和flash对应起来