diff --git a/app_protocols b/app_protocols index 7c86a5d..5f6308f 160000 --- a/app_protocols +++ b/app_protocols @@ -1 +1 @@ -Subproject commit 7c86a5d3b430a0a02b78355035f18ed2ec9ee24d +Subproject commit 5f6308f9929809ffe5481b03d32488334f33c0e9 diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp index 454b53d..684a97e 100644 --- a/usrc/service/app_core.cpp +++ b/usrc/service/app_core.cpp @@ -81,7 +81,7 @@ void AppCore::processKeyEventFromRemoter(hand_acid_remoter_key_event_t keyEvent) void blelogdump(uint8_t* rx, int32_t len) { // zble_proto_packet_t* packet = (zble_proto_packet_t*)rx; - ZLOGI(TAG, "onEvent: index:[%d],from:%d,to:%d cmd:%d", packet->frameIndex, packet->from, packet->to, packet->cmd); + // ZLOGI(TAG, "onEvent: index:[%d],from:%d,to:%d cmd:%d", packet->frameIndex, packet->from, packet->to, packet->cmd); if (packet->cmd == kzble_report_connected_event) { zble_connected_event_t* event = (zble_connected_event_t*)packet->data; @@ -144,7 +144,7 @@ void AppCore::appsetup() { ***********************************************************************************************************************/ RCTRL->regOnReport([this](uint8_t* rx, int32_t len) { zble_proto_packet_t* packet = (zble_proto_packet_t*)rx; - ZLOGI(TAG, "[] rx event : %s", zhex2str(rx, len)); + // ZLOGI(TAG, "[] rx event : %s", zhex2str(rx, len)); blelogdump(rx, len); if (packet->cmd == kzble_app_report_key_event) { @@ -154,6 +154,8 @@ void AppCore::appsetup() { } }); + // AciDisp00000 + /*********************************************************************************************************************** * START * ***********************************************************************************************************************/ @@ -161,6 +163,7 @@ void AppCore::appsetup() { RCTRL->startSchedule(); RemoteControlerStateSyncService::ins()->startSync(); + // dim UIS->chpage(pg_login); } diff --git a/usrc/service/remote_controler.cpp b/usrc/service/remote_controler.cpp index 477078c..8e3a936 100644 --- a/usrc/service/remote_controler.cpp +++ b/usrc/service/remote_controler.cpp @@ -3,11 +3,11 @@ #include "app_protocols/ble_through/ble_proto_utils.h" using namespace iflytop; -#define UART_RX_OVERTIME 10 +#define UART_RX_OVERTIME 100 #define TAG "RemoteControler" #define CMD_OVERTIME 500 -#define DEBUG 1 +#define DEBUG 0 static ZQueue ackQueue; static ZQueue eventQueue; @@ -59,23 +59,41 @@ void RemoteControlerUpper::startSchedule() { while (1) { // static uint8_t processbuf[128]; static RemoteControlerReportPacket_t rxpacket; - rxpacket.datalen = 0; - if (m_uart->USR_UartITRxOff != 0 && zos_haspassedms(m_uart->USR_UartITLastRxTicket) > UART_RX_OVERTIME) { - vPortEnterCritical(); - if (m_uart->USR_UartITRxOff != 0 && zos_haspassedms(m_uart->USR_UartITLastRxTicket) > UART_RX_OVERTIME) { - memset(rxpacket.data, 0, sizeof(rxpacket.data)); - memcpy(rxpacket.data, m_uart->USR_UartITRxBuf, m_uart->USR_UartITRxOff); - rxpacket.datalen = m_uart->USR_UartITRxOff; - m_uart->USR_UartITRxOff = 0; + rxpacket.datalen = 0; + zble_proto_packet_t* rxblepacket = (zble_proto_packet_t*)m_uart->USR_UartITRxBuf; + uint8_t* rxblepacketu8 = (uint8_t*)m_uart->USR_UartITRxBuf; + int curPacketlen = rxblepacket->packetlen; + + if (m_uart->USR_UartITRxOff != 0) { + if ((m_uart->USR_UartITRxOff >= curPacketlen) && // + rxblepacket->h1 == 0xAA && // + rxblepacket->h2 == 0xBB && // + rxblepacketu8[curPacketlen - 1] == 0xCC) { + vPortEnterCritical(); + // copy data + memcpy(rxpacket.data, rxblepacketu8, curPacketlen); + rxpacket.datalen = curPacketlen; + // move data + memmove(m_uart->USR_UartITRxBuf, m_uart->USR_UartITRxBuf + curPacketlen, curPacketlen); + m_uart->USR_UartITRxOff = m_uart->USR_UartITRxOff - curPacketlen; + vPortExitCritical(); + } else { + if (zos_haspassedms(m_uart->USR_UartITLastRxTicket) > UART_RX_OVERTIME) { + // drop data + ZLOGI(TAG, "drop data %d %s", m_uart->USR_UartITRxOff, zhex2str(m_uart->USR_UartITRxBuf, m_uart->USR_UartITRxOff)); + + vPortEnterCritical(); + m_uart->USR_UartITRxOff = 0; + memset(rxbuf, 0, 128); + vPortExitCritical(); + } } - vPortExitCritical(); } - if (rxpacket.datalen != 0) { preProcessrxpacket(&rxpacket); } // ZLOGI(TAG,"."); - osDelay(3); + osDelay(2); } });