From ec9f1ef91cb9a2e7a89246a9fcb8d7a275292eca Mon Sep 17 00:00:00 2001 From: SnickerSun Date: Fri, 26 Jul 2024 22:04:53 +0800 Subject: [PATCH] =?utf8?q?A5133=20=E6=94=B6=E5=8F=91=E4=B8=B4=E6=97=B6?= =?utf8?q?=E5=8D=8F=E8=AE=AE=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/drivers/peripheral/a5133/A5133Main.c | 60 ++++++++++++------- .../a5133/service/a5133_service.cpp | 29 +++++---- 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/code/sdk/drivers/peripheral/a5133/A5133Main.c b/code/sdk/drivers/peripheral/a5133/A5133Main.c index b7a43aa04..39fa3a8ff 100644 --- a/code/sdk/drivers/peripheral/a5133/A5133Main.c +++ b/code/sdk/drivers/peripheral/a5133/A5133Main.c @@ -56,6 +56,8 @@ Uint8 *Uartptr; Uint8 CmdBuf[25]; Uint8 tmpbuf[80]; +Uint8 tmpbuf_rx[80]; +uint8_t tmpbuf_len=0; Uint16 Err_Loss; Uint16 Err_Frame; Uint32 Err_BitCnt; @@ -93,23 +95,27 @@ static uint8_t send_data_index = 0; errcode_t a5133_set_send_data(uint8_t *senddata,uint8_t datalen) { - if ( datalen > 62 || datalen == 0 || senddata == NULL) + if ( datalen > (64-1-8) || datalen == 0 || senddata == NULL) return ERRCODE_FAIL; if (send_data_index == 0) { - memset(send_data[1],0,64); - memcpy(send_data,senddata,datalen); - uint16_t crc = CRC16_XMODEM(send_data[1],62); - send_data[1][62] = ((uint8_t*)&crc)[0]; - send_data[1][63] = ((uint8_t*)&crc)[1]; + uint8_t* p_senddata=send_data[1]; + memset(p_senddata,0,sizeof(send_data[0])); + p_senddata[0]=datalen; + memcpy(p_senddata+1,senddata,datalen); + uint16_t crc = CRC16_XMODEM(p_senddata,datalen); + p_senddata[datalen+1] = ((uint8_t*)&crc)[0]; + p_senddata[datalen+1+1] = ((uint8_t*)&crc)[1]; send_data_index = 1; }else{ - memset(send_data[0],0,64); - memcpy(send_data,senddata,datalen); - uint16_t crc = CRC16_XMODEM(send_data[0],62); - send_data[0][62] = ((uint8_t*)&crc)[0]; - send_data[0][63] = ((uint8_t*)&crc)[1]; + uint8_t * p_senddata=send_data[0]; + memset(p_senddata,0,sizeof(send_data[0])); + p_senddata[0]=datalen; + memcpy(p_senddata+1,senddata,datalen); + uint16_t crc = CRC16_XMODEM(p_senddata,datalen); + p_senddata[datalen+1] = ((uint8_t*)&crc)[0]; + p_senddata[datalen+1+1] = ((uint8_t*)&crc)[1]; send_data_index = 0; } @@ -121,12 +127,12 @@ void a5133_main(Uint8 Flag_MASTER,uint8_t channel) a5133_power_on(); LOS_Msleep(10); - if(RF_Init())/* init RF */ + while(RF_Init())/* init RF */ { // Err_State(); - PRINT("RF_Init Failed\n"); + PRINT("RF_Init Failed retry!\n"); - return; + LOS_Msleep(1000); } @@ -493,7 +499,7 @@ static void dump_tmpbuf(void) void a5133_get_rxdata(uint8_t *databuf,uint8_t len) { - memcpy_s(databuf,len,tmpbuf,strlen((const char*)tmpbuf)); + memcpy_s(databuf,len,tmpbuf_rx,sizeof(tmpbuf_rx)); } /********************************************************************* @@ -523,14 +529,26 @@ void RxPacket(void) //crccheck a5133_gpio_scs_set_value(1); - uint16_t crc = CRC16_XMODEM(tmpbuf,62); - uint16_t recv_crc = *(uint16_t*)&tmpbuf[62]; - PRINT("crc[%X] , recv_crc %X\n",crc,recv_crc); - if (crc != recv_crc) + uint8_t datalen = tmpbuf[8]; + if (datalen >0 && datalen <= (64-8-1)) { - err = 1; + uint16_t crc = CRC16_XMODEM(&tmpbuf[1+8],datalen); + uint16_t recv_crc = *(uint16_t*)&tmpbuf[1+datalen+8]; + PRINT("crc[%X] , recv_crc %X\n",crc,recv_crc); + if (crc != recv_crc) + { + err = 1; + }else{ + tmpbuf_len = datalen; + memset(tmpbuf_rx, 0 ,sizeof(tmpbuf_rx)); + memcpy(tmpbuf_rx, &tmpbuf[1+8],datalen); + } + printf("=====RxPacket \n"); + + }else{ + err = 1 ; + printf("=====RxPacket failed \n"); } - printf("=====RxPacket \n"); dump_tmpbuf(); if (err)//packet error Err_Frame++; diff --git a/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp b/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp index 4829f95fe..d0e116245 100644 --- a/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp +++ b/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp @@ -121,14 +121,12 @@ void send_a5133_cmd_msg(int cmd) } } - static void a5133_service_check_task(void *arg) { unused(arg); int32_t ret; uint32_t mail; uint32_t msgsize = (uint32_t)sizeof(A5133_CMD_TYPE_T); - a5133_service_running_stat = true; a5133_gpio_init(); PRINT("a5133_service_check_task !\r\n"); @@ -147,22 +145,33 @@ static void a5133_service_check_task(void *arg) if (mail == A5133_SERVICE_CMD_TYPE_RUN_MASTER) { - PRINT("A5133_SERVICE_CMD_TYPE_RUN_MASTER \n"); - a5133_service_timer_start_check(50); - a5133_main(MASTER,80); + if (a5133_service_running_stat == false) + { + a5133_service_running_stat = true; + a5133_service_timer_start_check(50); + a5133_main(MASTER,80); + PRINT("A5133_SERVICE_CMD_TYPE_RUN_MASTER \n"); + }else{ + PRINT("A5133_SERVICE_CMD_TYPE_RUN_MASTER already Started \n"); + } + }else if (mail == A5133_SERVICE_CMD_TYPE_RUN_SLAVE) { - - PRINT("A5133_SERVICE_CMD_TYPE_RUN_SLAVE \n"); - a5133_service_timer_start_check(50); - a5133_main(SLAVE,80); + if (a5133_service_running_stat == false) + { + a5133_service_running_stat = true; + a5133_service_timer_start_check(50); + a5133_main(SLAVE,80); + PRINT("A5133_SERVICE_CMD_TYPE_RUN_SLAVE \n"); + }else{ + PRINT("A5133_SERVICE_CMD_TYPE_RUN_SLAVE already Started \n"); + } }else if (mail == A5133_SERVICE_CMD_TYPE_TIMER_CHECK) { } } a5133_server_break_flag = 0; - a5133_service_running_stat = false; } void create_a5133_queue(void) { -- 2.17.1