From 6337bafb99540d0b101dd7570f84065001ca352f Mon Sep 17 00:00:00 2001 From: gaoyang3513 Date: Fri, 2 Aug 2024 10:42:56 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=E8=A7=A3=E5=86=B3=E4=B8=B2=E5=8F=A3?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 待优化:使用snprintf格式化,但长度限定为32,与128有差距; 2. 开启Timer; 3. 解决字符串的串口打印错误; --- .../Uart_PingPong/ebyte/ebyte_callback.c | 125 +++++++----------- .../2_Ebyte_Board_Support/E15-EVB02/board.c | 6 +- .../E48xMx/ebyte_e48x.c | 2 +- 3 files changed, 54 insertions(+), 79 deletions(-) diff --git a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c index d7510c0..ba203b2 100755 --- a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c +++ b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c @@ -23,6 +23,8 @@ /*= !!!ĿӲƽ̨ͷļ =======================================*/ #include "board.h" //E15-EVB02 #include "ebyte_debug.h" //E15-EVB02 +#include +#include /*= !!!ĿӲ =======================================*/ extern uint8_t RxBuffer[64]; extern uint8_t BufferPing[5]; @@ -69,87 +71,60 @@ void Ebyte_Port_TransmitCallback( uint16e_t state ) */ void Ebyte_Port_ReceiveCallback( uint16_t state, uint8_t *buffer, uint8_t length ) { - uint8_t j, pcEchoLength; - uint8_t *p; - /* : */ - if( state &= 0x0002 ) - { - //To-do ʵԼ߼ + uint8_t j, pcEchoLength; + uint8_t *p; + int8_t rx_data[32] = {0}; - /* ͨжǷping pongָ */ - if( length == 4 || length == 5 ) - { + /* : */ + if( state &= 0x0002 ) { + //To-do ʵԼ߼ - p = buffer; - for( j = 0; j < 4; j++ ) - { - if( BufferPing[j] != *p++ ) - { - break; - } + /* ͨжǷping pongָ */ + if( length == 4 || length == 5 ) { + p = buffer; + for( j = 0; j < 4; j++ ) { + if( BufferPing[j] != *p++ ) + break; + } + if( j == 4 ) { //Ƚϵĩβʾȫƥping + Callback_isPingCheckReady = 1;//֪ͨظPong + if( length == 5 && PC_isConnected ) + BufferPong[4] = buffer[4];//5ֽΪʶ + } - } - //Ƚϵĩβʾȫƥping - if( j == 4 ) - { - Callback_isPingCheckReady = 1;//֪ͨظPong - if( length == 5 && PC_isConnected ) - { - BufferPong[4] = buffer[4];//5ֽΪʶ - } + if( j!=4 && length == 5 && PC_isConnected ) { + p = buffer; - } + for( j = 0; j < 4; j++ ) { + if( BufferPong[j] != *p++ ) + break; + } - if( j!=4 && length == 5 && PC_isConnected ) - { - p = buffer; + if( j == 4 ) {//ȫƥpong + if( 0x01 == buffer[4] ) + Ebyte_DEBUG_CommandEcho( ( uint8_t* )SimulatedCommandsWireless1, EBYTE_CMD_PACKAGE_LENGTH, PcEchoBuffer, &pcEchoLength ); + else + Ebyte_DEBUG_CommandEcho( ( uint8_t* )SimulatedCommandsWireless2, EBYTE_CMD_PACKAGE_LENGTH, PcEchoBuffer, &pcEchoLength ); + Ebyte_BSP_UartTransmit( PcEchoBuffer, pcEchoLength ); + } + } + } - for( j = 0; j < 4; j++ ) - { - if( BufferPong[j] != *p++ ) - { - break; - } + Ebyte_BSP_LedControl( BSP_LED_1, ON ); - } + if( ! PC_isConnected ) { + snprintf(rx_data, sizeof(rx_data), "%s", buffer); + EBYTE_LOG("\r\n Receive Data: %s", rx_data); + } - if( j == 4 )//ȫƥpong - { - if( 0x01 == buffer[4] ) - { - Ebyte_DEBUG_CommandEcho( ( uint8_t* )SimulatedCommandsWireless1, EBYTE_CMD_PACKAGE_LENGTH, PcEchoBuffer, &pcEchoLength ); - } - else - { - Ebyte_DEBUG_CommandEcho( ( uint8_t* )SimulatedCommandsWireless2, EBYTE_CMD_PACKAGE_LENGTH, PcEchoBuffer, &pcEchoLength ); - } - Ebyte_BSP_UartTransmit( PcEchoBuffer, pcEchoLength ); - } - - } - } - - Ebyte_BSP_LedControl( BSP_LED_1, ON ); - - if( ! PC_isConnected ) - { - - EBYTE_LOG("\r\n Receive Data:"); - Ebyte_BSP_UartTransmit ( buffer, length ); - } - - Ebyte_BSP_LedControl( BSP_LED_1, OFF ); - } - /* : 쳣ʱ */ - else if ( state &= 0x0200 ) - { - //To-do ʵԼ߼ - } - /* : δ֪ */ - else - { - /* ״̬ʶȷӲ - 1:SPIͨŲȷ 2:ģ鹩粻 */ - while(1); - } + Ebyte_BSP_LedControl( BSP_LED_1, OFF ); + } + else if ( state &= 0x0200 ) { /* : 쳣ʱ */ + //To-do ʵԼ߼ + } + else { /* : δ֪ */ + /* ״̬ʶȷӲ + 1:SPIͨŲȷ 2:ģ鹩粻 */ + while(1); + } } \ No newline at end of file diff --git a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c index 4241325..e57b2c9 100755 --- a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c +++ b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c @@ -235,10 +235,10 @@ void Ebyte_BSP_Init( void ) Ebyte_BSP_SPI_Init(); /* ʱ ʼ */ -// Ebyte_BSP_TIMER_Init(); + Ebyte_BSP_TIMER_Init(); /* ¼ ʼ */ -// Ebyte_BTN_FIFO_Init( &BSP_BTN_FIFO ); + Ebyte_BTN_FIFO_Init( &BSP_BTN_FIFO ); } /* ! @@ -334,7 +334,7 @@ void Ebyte_BSP_UartTransmit( uint8_t *buffer , uint16_t length ) for( i = 0; i < length; i++ ) { while(RESET == usart_flag_get(LOG_UART, USART_FLAG_TBE)); - usart_data_transmit(LOG_UART, *buffer); + usart_data_transmit(LOG_UART, buffer[i]); } } diff --git a/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c b/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c index f7d7999..12a806d 100755 --- a/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c +++ b/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c @@ -75,7 +75,7 @@ void Ebyte_E48x_IntOrPollTask( void ) radio_rece_data_flag = gpio_input_bit_get( BSP_GPIO_PORT_E48_GP4 , BSP_GPIO_PIN_E48_GP4); /* н */ if( radio_rece_data_flag != RESET ) { - vRadioGetPacket(rf_rxbuffer,&rf_rxsize); + vRadioGetPacket(rf_rxbuffer, &rf_rxsize); Ebyte_Port_ReceiveCallback(0x0002,rf_rxbuffer,rf_rxsize); } }