From 033f90abf9b9c9f3296a0057b401af17f38a2633 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Fri, 9 Aug 2024 12:42:13 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=965133=E5=BA=95=E5=B1=82?= =?utf8?q?=E9=A9=B1=E5=8A=A8=E3=80=81=E5=8D=8F=E8=AE=AE=E3=80=81=E4=BB=A5?= =?utf8?q?=E5=8F=8AUI=E7=95=8C=E9=9D=A2=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?utf8?q?=E4=BA=A7=E6=B5=8B=E9=A9=AC=E8=BE=BE=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../obumessage/include/OBUMessageView.h | 11 +- .../obumessage/src/OBUMessageView.cpp | 136 +++++- .../brandy_evb/board_config/board_evb.h | 13 + .../drivers/peripheral/a5133/A5133Config.h | 10 +- code/sdk/drivers/peripheral/a5133/A5133Main.c | 428 ++++++++++++++---- code/sdk/drivers/peripheral/a5133/A5133Uti.c | 17 +- code/sdk/drivers/peripheral/a5133/A5133main.h | 5 +- .../a5133/service/a5133_service.cpp | 11 +- .../peripheral/a5133/service/a5133_service.h | 7 +- .../drivers/peripheral/utils/custom_utils.c | 73 ++- .../drivers/peripheral/utils/custom_utils.h | 3 +- .../peripheral/utils/custom_utils_at_cmd.c | 24 + .../vibrator/service/vibrator_service.cpp | 17 + .../vibrator/service/vibrator_service.h | 1 + 14 files changed, 634 insertions(+), 122 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h index 7677ee4b7..362de1611 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h @@ -1,9 +1,9 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-27 10:58:43 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-27 12:02:16 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView..h + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-08-08 19:16:46 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/include/OBUMessageView.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -41,7 +41,10 @@ namespace OHOS UIViewGroup *group = nullptr; UILabel *title = nullptr; UILabel *displayTimeLabel = nullptr; - UILabel *obuMessageLabel = nullptr; + UILabel *obuMessageLabel1 = nullptr; + UILabel *obuMessageLabel2 = nullptr; + UILabel *MessageNumLabel1 = nullptr; + UILabel *MessageNumLabel2 = nullptr; bool viewInitStatus{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp index a9b27d249..c833ad70c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-27 14:06:08 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-08-09 10:25:01 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/obumessage/src/OBUMessageView.cpp */ #include "obumessage/include/OBUMessagePresenter.h" @@ -55,10 +55,25 @@ namespace OHOS delete displayTimeLabel; displayTimeLabel = nullptr; } - if (obuMessageLabel != nullptr) + if (obuMessageLabel1 != nullptr) { - delete obuMessageLabel; - obuMessageLabel = nullptr; + delete obuMessageLabel1; + obuMessageLabel1 = nullptr; + } + if (obuMessageLabel2 != nullptr) + { + delete obuMessageLabel2; + obuMessageLabel2 = nullptr; + } + if (MessageNumLabel1 != nullptr) + { + delete MessageNumLabel1; + MessageNumLabel1 = nullptr; + } + if (MessageNumLabel2 != nullptr) + { + delete MessageNumLabel2; + MessageNumLabel2 = nullptr; } delete group; group = nullptr; @@ -137,25 +152,87 @@ namespace OHOS displayTimeLabel->SetRollSpeed(70); displayTimeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); group->Add(displayTimeLabel); - /* ----------------------------- obuMessageLabel ---------------------------- */ - if (obuMessageLabel == nullptr) + /* ----------------------------- obuMessageLabel1 ---------------------------- */ + if (obuMessageLabel1 == nullptr) { - obuMessageLabel = new UILabel(); - if (obuMessageLabel == nullptr) + obuMessageLabel1 = new UILabel(); + if (obuMessageLabel1 == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "obuMessageLabel fail!!"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "obuMessageLabel1 fail!!"); return; } } - obuMessageLabel->SetPosition(53, 30, 360, 250); - obuMessageLabel->SetStyle(STYLE_BORDER_RADIUS, 33); - obuMessageLabel->SetStyle(STYLE_TEXT_FONT, 40); - obuMessageLabel->SetStyle(STYLE_LINE_HEIGHT, 45); - obuMessageLabel->SetText(""); - obuMessageLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - obuMessageLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - obuMessageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); - group->Add(obuMessageLabel); + obuMessageLabel1->SetPosition(68, 10, 360, 250); + obuMessageLabel1->SetStyle(STYLE_BORDER_RADIUS, 33); + obuMessageLabel1->SetStyle(STYLE_TEXT_FONT, 40); + obuMessageLabel1->SetStyle(STYLE_LINE_HEIGHT, 45); + obuMessageLabel1->SetText(""); + obuMessageLabel1->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + obuMessageLabel1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + obuMessageLabel1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(obuMessageLabel1); + + /* ----------------------------- obuMessageLabel2 ---------------------------- */ + if (obuMessageLabel2 == nullptr) + { + obuMessageLabel2 = new UILabel(); + if (obuMessageLabel2 == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "obuMessageLabel2 fail!!"); + return; + } + } + obuMessageLabel2->SetPosition(53, 70, 360, 250); + obuMessageLabel2->SetStyle(STYLE_BORDER_RADIUS, 33); + obuMessageLabel2->SetStyle(STYLE_TEXT_FONT, 40); + obuMessageLabel2->SetStyle(STYLE_LINE_HEIGHT, 45); + obuMessageLabel2->SetText(""); + obuMessageLabel2->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + obuMessageLabel2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + obuMessageLabel2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(obuMessageLabel2); + + /* ----------------------------- MessageNumLabel1 ---------------------------- */ + if (MessageNumLabel1 == nullptr) + { + MessageNumLabel1 = new UILabel(); + if (MessageNumLabel1 == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageNumLabel1 fail!!"); + return; + } + } + MessageNumLabel1->SetPosition(28, 10, 360, 250); + MessageNumLabel1->SetStyle(STYLE_BORDER_RADIUS, 33); + MessageNumLabel1->SetStyle(STYLE_TEXT_FONT, 40); + MessageNumLabel1->SetStyle(STYLE_LINE_HEIGHT, 45); + MessageNumLabel1->SetText(""); + MessageNumLabel1->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + MessageNumLabel1->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + MessageNumLabel1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(MessageNumLabel1); + + + /* ----------------------------- MessageNumLabel2 ---------------------------- */ + if (MessageNumLabel2 == nullptr) + { + MessageNumLabel2 = new UILabel(); + if (MessageNumLabel2 == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageNumLabel2 fail!!"); + return; + } + } + MessageNumLabel2->SetPosition(28, 70, 360, 250); + MessageNumLabel2->SetStyle(STYLE_BORDER_RADIUS, 33); + MessageNumLabel2->SetStyle(STYLE_TEXT_FONT, 40); + MessageNumLabel2->SetStyle(STYLE_LINE_HEIGHT, 45); + MessageNumLabel2->SetText(""); + MessageNumLabel2->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + MessageNumLabel2->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + MessageNumLabel2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(MessageNumLabel2); + viewInitStatus = true; } @@ -217,12 +294,13 @@ namespace OHOS static std::string labelTimeStr; static std::string rxdataStr; - + static int num1 = 0; + static int num2 = 0; void OBUMessageView::UpdateOBUMessageViewDisplayData(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OBUMessageView::UpdateOBUMessageViewDisplayDate"); - - if (uapi_get_a5133_update_state()) + int flag = uapi_get_a5133_update_state(); + if (flag) { uint8_t rxdata[80] = {0}; uint32_t rxdata_timestamp = 0; @@ -239,7 +317,19 @@ namespace OHOS labelTimeStr = std::string(labelTime); } } + if(flag == 1) + { + num1++; + obuMessageLabel1->SetText(rxdataStr.c_str()); /*数据更新*/ + MessageNumLabel1->SetText(std::to_string(num1).c_str()); + } + else if(flag == 2) + { + num2++; + obuMessageLabel2->SetText(rxdataStr.c_str()); + MessageNumLabel2->SetText(std::to_string(num2).c_str()); + } displayTimeLabel->SetText(labelTimeStr.c_str()); /*时间更新:时:分:秒*/ - obuMessageLabel->SetText(rxdataStr.c_str()); /*数据更新*/ + } } \ No newline at end of file diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h index ce0f4758a..77fec1773 100755 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h @@ -12,9 +12,14 @@ #include "platform_types.h" #ifdef SUPPORT_CAT1_SERVICE +//#include "service/a5133_service.h" #include "cat1_ctl.h" #endif +#ifdef SUPPORT_A5133_SERVICE +//#include "service/a5133_service.h" +#endif + #ifdef ENABLE_CYWEE extern void cywee_int_callback(pin_t pin, uintptr_t param); #endif @@ -194,7 +199,11 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L25 //////////// audio pa reset { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L26 心率复位 PPG reset { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L27 LCM reset +#ifdef SUPPORT_A5133_SERVICE + //{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_AGPIO_L28 CAT_1复位 CAT1_RESET_N 拉低有效 +#else { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L28 CAT_1复位 CAT1_RESET_N 拉低有效 +#endif { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L29 charge done info 检测是否充满电 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L30 KP_MKIN1 唤醒 CAT1 ,输出 #ifdef SUPPORT_A5133_SERVICE @@ -316,6 +325,10 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { /**cat1 ring input key*/ // { S_AGPIO_L31, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_DEDGE, cat1_ring_isr_callback}, { S_AGPIO_L31, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, cat1_ring_isr_callback}, + +#endif +#ifdef SUPPORT_A5133_SERVICE + //{ S_AGPIO_L28, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, a5133_cko_isr_callback}, #endif }; /** diff --git a/code/sdk/drivers/peripheral/a5133/A5133Config.h b/code/sdk/drivers/peripheral/a5133/A5133Config.h index c5e54d2cb..e1516b4b1 100644 --- a/code/sdk/drivers/peripheral/a5133/A5133Config.h +++ b/code/sdk/drivers/peripheral/a5133/A5133Config.h @@ -62,7 +62,7 @@ const Uint8 A5133_RFConfigTab_Main[]= 0xFF, //VCO Modulation delay register, 0x40, //BATTERY register, 0xA7, //TXTEST register, - 0x57, //RXDEM1 register, + 0x37, //RXDEM1 register, 0x74, //RXDEM2 register, 0xF3, //CPC1 register, 0x33, //CPC2 register, @@ -101,7 +101,7 @@ const Uint8 A5133_RFConfigTab_Addr0x20[]= const Uint8 A5133_RFConfigTab_Addr0x21[]= { - 0x09, //page0, + 0x00, //page0, 0x00, //page1, 0x00, //Page2, 0x00, //page3, @@ -528,7 +528,7 @@ const Uint8 A5133_RFConfigTab_Main[]= 0x40, //VCO Modulation delay register, 0x40, //BATTERY register, 0xE7, //TXTEST register, - 0x57, //RXDEM1 register, + 0x37, //RXDEM1 register, 0x74, //RXDEM2 register, 0xF3, //CPC1 register, 0x33, //CPC2 register, @@ -550,7 +550,7 @@ const Uint8 A5133_RFConfigTab_Main[]= const Uint8 A5133_RFConfigTab_Addr0x20[]= { - 0x0E, //page0, + 0x0C, //page0, 0x00, //page1, 0x00, //Page2, 0x00, //page3, @@ -567,7 +567,7 @@ const Uint8 A5133_RFConfigTab_Addr0x20[]= const Uint8 A5133_RFConfigTab_Addr0x21[]= { - 0x09, //page0, + 0x00, //page0, 0x00, //page1, 0x00, //Page2, 0x00, //page3, diff --git a/code/sdk/drivers/peripheral/a5133/A5133Main.c b/code/sdk/drivers/peripheral/a5133/A5133Main.c index eb988cd61..678c87278 100644 --- a/code/sdk/drivers/peripheral/a5133/A5133Main.c +++ b/code/sdk/drivers/peripheral/a5133/A5133Main.c @@ -56,12 +56,25 @@ Uint16 RxCnt; Uint8 *Uartptr; Uint8 CmdBuf[25]; +//#define A5133_FIFO_EXT_MODE +#ifdef A5133_FIFO_EXT_MODE +#define HEXSTR_LEN 600 +#define FIFO_LEN 256 +Uint8 tmpbuf[256]; +Uint8 tmpbuf_rx1[256]; +#else +#define HEXSTR_LEN 256 +#define FIFO_LEN 64 Uint8 tmpbuf[80]; -Uint8 tmpbuf_rx[80]; +Uint8 tmpbuf_rx1[80]; +Uint8 tmpbuf_rx2[80]; +#endif + uint8_t tmpbuf_len=0; uint32_t tmpbuf_rx_timestamp = 0; Uint16 Err_Loss; -Uint16 Err_Frame; +Uint16 Err_Frame; +Uint16 SUCC_Frame = 0; Uint32 Err_BitCnt; Uint8 Mem_RH; @@ -70,9 +83,10 @@ Uint8 Mem_RL; const Uint8 BitCount_Tab[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}; // const Uint8 code ID_Tab[8]={0xC3,0x3C,0x95,0x6A,0x36,0x75,0xC5,0x2A};//ID code // const Uint8 code ID_Tab[8]={0xAA,0xAA,0xAA,0xAA,0xCC,0xCC,0xAA,0xAA}; -const Uint8 ID_Tab[8]={0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55}; + const Uint8 ID_Tab[8]={0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55}; +//const Uint8 ID_Tab[8]={0x55,0x55,0x55,0x55,0x55,0x55,0x55,0xAB}; //const Uint8 //code ID_Tab[8]={0x34,0x75,0xC5,0x2A,0xC7,0x33,0x45,0xEA};//ID code -//const Uint8 code ID_Tab[8]={0x55,0x55,0x55,0x55,0x34,0x75,0xC5,0x6A}; //ID2 code +//const Uint8 code ID_Tab[8]={0x55,0x55,0x55,0x55,0x34,0x75,0xC5,0x6A}; //ID2 codec //const Uint8 code ID_Tab[8]={0xFF,0xFF,0xFF,0xFF,0x36,0x75,0xC5,0xBA}; //ID2 code //const Uint8 code ID_Tab[8]={0x34,0x75,0xC5,0x2A,0x34,0x75,0xC5,0x2A}; //ID2 code const Uint8 KeyData_Tab[16]={0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //keyData code @@ -94,46 +108,85 @@ const Uint8 PN9_Tab[]= static uint8_t send_data[2][64] = {0}; static uint8_t send_data_index = 0; -static bool update_flag = false; +static uint8_t update_flag = 0; static uint32_t history_timestamp = 0; + errcode_t a5133_set_send_data(uint8_t *senddata,uint8_t datalen) { // total(64) , header(4), timestamp(4), len(1), data(n-11) , crc(2) + // total(64) , header(1), len(2), 目标地址(4), 设备地址(4),MAC 控制域(4), 帧序号(2),data(n) , crc(4) if ( datalen == 0 || senddata == NULL) { PRINT("a5133_set_send_data data error!\n"); return ERRCODE_FAIL; } - if (datalen > (64 - 1 - 4 - 4 - 2 )) + //if (datalen > (64 - 1 - 4 - 4 - 2 )) + if (datalen > (64-1-2-4-4-4-2-4)) { - datalen = 64 - 1- 4-4-2 ; + //datalen = 64 - 1- 4-4-2 ; + datalen = 64-1-2-4-4-4-2-4; senddata[datalen -1 ]= 0; PRINT("datalen is too large cut to %d!\n",datalen); } - uint32_t current_time = 0; - uapi_get_timestampe_ss(¤t_time); + uint8_t frame_header = 0xAB; + uint16_t frame_len = 4 + 4 + 4 + 2 + 4 + datalen; + uint32_t frame_target_addr = 0XFFFFFFFF; + uint32_t frame_device_addr = 0XA1A81E3F; + uint32_t frame_mac_field = 0X10800200; + uint16_t frame_number = 0XEFDC; + uint32_t farme_timestampe = 0; + uapi_get_timestampe_ss(&farme_timestampe); if (send_data_index == 0) { + // uint8_t* p_senddata=send_data[1]; + // memset(p_senddata,0,sizeof(send_data[0])); + // memcpy(p_senddata,¤t_time,sizeof(current_time)); + // p_senddata[4]=datalen; + // memcpy(p_senddata+1+4,senddata,datalen); + // uint16_t crc = CRC16_XMODEM(p_senddata+1+4,datalen); + // p_senddata[datalen+1+4] = ((uint8_t*)&crc)[0]; + // p_senddata[datalen+1+1+4] = ((uint8_t*)&crc)[1]; + // send_data_index = 1; + // PRINT("send_data_index 1 datalen %d , crc %X\n",datalen,crc); uint8_t* p_senddata=send_data[1]; memset(p_senddata,0,sizeof(send_data[0])); - memcpy(p_senddata,¤t_time,sizeof(current_time)); - p_senddata[4]=datalen; - memcpy(p_senddata+1+4,senddata,datalen); - uint16_t crc = CRC16_XMODEM(p_senddata+1+4,datalen); - p_senddata[datalen+1+4] = ((uint8_t*)&crc)[0]; - p_senddata[datalen+1+1+4] = ((uint8_t*)&crc)[1]; + memcpy(p_senddata,&frame_header,sizeof(frame_header)); + memcpy(p_senddata+1,&frame_len,sizeof(frame_len)); + memcpy(p_senddata+1+2,&frame_target_addr,sizeof(frame_target_addr)); + memcpy(p_senddata+1+2+4,&frame_device_addr,sizeof(frame_device_addr)); + memcpy(p_senddata+1+2+4+4,&frame_mac_field,sizeof(frame_mac_field)); + memcpy(p_senddata+1+2+4+4+4,&frame_number,sizeof(frame_number)); + memcpy(p_senddata+1+2+4+4+4+2,&farme_timestampe,sizeof(farme_timestampe)); + memcpy(p_senddata+1+2+4+4+4+2+4,senddata,datalen); + uint16_t crc = CRC16_X25(p_senddata+1+2,frame_len); + p_senddata[frame_len+1+2] = ((uint8_t*)&crc)[0]; + p_senddata[frame_len+1+1+2] = ((uint8_t*)&crc)[1]; send_data_index = 1; PRINT("send_data_index 1 datalen %d , crc %X\n",datalen,crc); }else{ - uint8_t * p_senddata=send_data[0]; + uint8_t* p_senddata=send_data[0]; memset(p_senddata,0,sizeof(send_data[0])); - memcpy(p_senddata,¤t_time,sizeof(current_time)); - p_senddata[4]=datalen; - memcpy(p_senddata+1+4,senddata,datalen); - uint16_t crc = CRC16_XMODEM(p_senddata+1+4,datalen); - p_senddata[datalen+1+4] = ((uint8_t*)&crc)[0]; - p_senddata[datalen+1+1+4] = ((uint8_t*)&crc)[1]; + memcpy(p_senddata,&frame_header,sizeof(frame_header)); + memcpy(p_senddata+1,&frame_len,sizeof(frame_len)); + memcpy(p_senddata+1+2,&frame_target_addr,sizeof(frame_target_addr)); + memcpy(p_senddata+1+2+4,&frame_device_addr,sizeof(frame_device_addr)); + memcpy(p_senddata+1+2+4+4,&frame_mac_field,sizeof(frame_mac_field)); + memcpy(p_senddata+1+2+4+4+4,&frame_number,sizeof(frame_number)); + memcpy(p_senddata+1+2+4+4+4+2,&farme_timestampe,sizeof(farme_timestampe)); + memcpy(p_senddata+1+2+4+4+4+2+4,senddata,datalen); + uint16_t crc = CRC16_X25(p_senddata+1+2,frame_len); + p_senddata[frame_len+1+2] = ((uint8_t*)&crc)[0]; + p_senddata[frame_len+1+1+2] = ((uint8_t*)&crc)[1]; send_data_index = 0; + // uint8_t * p_senddata=send_data[0]; + // memset(p_senddata,0,sizeof(send_data[0])); + // memcpy(p_senddata,¤t_time,sizeof(current_time)); + // p_senddata[4]=datalen; + // memcpy(p_senddata+1+4,senddata,datalen); + // uint16_t crc = CRC16_XMODEM(p_senddata+1+4,datalen); + // p_senddata[datalen+1+4] = ((uint8_t*)&crc)[0]; + // p_senddata[datalen+1+1+4] = ((uint8_t*)&crc)[1]; + // send_data_index = 0; PRINT("send_data_index 0 datalen %d , crc %X\n",datalen,crc); } @@ -141,10 +194,31 @@ errcode_t a5133_set_send_data(uint8_t *senddata,uint8_t datalen) return ERRCODE_SUCC; } + +static int cko_flag = 0; +static int cko_irq_count = 0; +void a5133_cko_state_update(void) +{ + cko_flag = 1; + cko_irq_count++; +} +uint8_t get_cko_flag(void) +{ + uint8_t ret = cko_flag; + if(cko_flag) + cko_flag = 0; + return ret; +} +// F2F6FAFF03070B0F13171B1F23272B2F32363A3E42464A4E52565A5E62666A6E72767A7E82868A8E92969A9EA2A6AAAEB2B6BABEC2C6CACED2D6DADEE2E6EAEE +// F2F6FAFF03070B0F13171B1F23272B2F32363A3E42464A4E52565A5E62666A6E72767A7E82868A8E92969A9EA2A6AAAEB2B6BABEC2C6CACED2D6DADEE2E6EAEE +// F2F6FAFF03070B0F13171B1F23272B2F32363A3E42464A4E52565A5E62666A6E72767A7E82868A8E92969A9EA2A6AAAEB2B6BABEC2C6CACED2D6DADEE2E6EAEE +// F2F6FAFF03070B0F13171B1F23272B2F32363A3E42464A4E52565A5E62666A6E72767A7E82868A8E92969A9EA2A6AAAEB2B6BABEC2C6CACED2D6DADEE2E6EAEE +// Err_Frame:175 +// SUCC_Frame:0 void a5133_main(Uint8 Flag_MASTER,uint8_t channel) { - a5133_power_on(); + LOS_Msleep(10); while(RF_Init())/* init RF */ { @@ -152,19 +226,28 @@ void a5133_main(Uint8 Flag_MASTER,uint8_t channel) PRINT("RF_Init Failed retry!\n"); LOS_Msleep(1000); - } - - - if (Flag_MASTER) + } +#ifdef A5133_FIFO_EXT_MODE + Uint8 i,j,n,data; + //RF_WriteReg(DATARATECLOCK, 9);/* 100kbps */ + RF_WriteReg(FIFO2_REG, 0xC0);/* FPM=16/48 Bytes */ + RF_FIFOLength(256-1);/* fifo length 256 bytes */ +#endif + + if (Flag_MASTER) //发送 { PRINT("Flag_MASTER\n"); while(1) { RF_WriteReg(GIO1_REG,0x01);/* gio1-wtr */ RF_WriteReg(GIO2_REG,0x1D);/* gio2-trxd */ +#ifdef A5133_FIFO_EXT_MODE + RF_WriteReg(CKO_REG,0x16);/* cko-fpf */ +#else RF_WriteReg(CKO_REG,0x02);/* cko-dck */ - RF_FIFOLength(64-1);/* fifo length 64 bytes */ +#endif + RF_StrobeCmd(CMD_PLL); RF_SetCH(channel);/* ch=80, freq=5805.001MHz */ /* To set RF channel */ @@ -180,9 +263,72 @@ void a5133_main(Uint8 Flag_MASTER,uint8_t channel) timer=0; // TR0=1; // EA=1; - + int timeout = 0; while(1) { +#ifdef A5133_FIFO_EXT_MODE + printf("111cko_irq_count : %d \n",cko_irq_count); + RF_StrobeCmd(CMD_TFR);/* TX FIFO address pointer reset */ + + n=0; + int cko_flag_tmp = cko_flag; + a5133_gpio_scs_set_value(0);/* Write 64Bytes data */ + ByteSend(FIFO_REG); + for(i=0; i<64; i++) + ByteSend(i++); + RF_StrobeCmd(CMD_TX);/* entry TX mode */ + //a5133_gpio_scs_set_value(1); + //LOS_Msleep(1000); + + //printf("111a5133_gpio_get_cko_value : %d \n",a5133_gpio_get_cko_value()); + //Delay10us(1); + //printf("111cko_flag : %d \n",cko_flag); + + for(j=0; j<4; j++)/* Write 48 Byte x 4 */ + { + //printf("444a5133_gpio_get_cko_value : %d \n",a5133_gpio_get_cko_value()); + //while(a5133_gpio_get_cko_value() == 0)/* wait FPF go high */ + timeout = 0xFFFFFFFF; + + // data = RF_ReadReg(FIFO1_REG); + // printf("FIFO1_REG : 0x%X \n",data); + // data = RF_ReadReg(FIFO2_REG); + // printf("FIFO2_REG : 0x%X \n",data); + while(get_cko_flag()==0) + { + //printf("222a5133_gpio_get_cko_value : %d \n",a5133_gpio_get_cko_value()); + //LOS_Msleep(1); + timeout--; + if(timeout <= 0) + { + printf("timeout !!!!\n"); + break; + } + } + printf("timeout : %d \n",timeout); + //printf("333a5133_gpio_get_cko_value : %d \n",a5133_gpio_get_cko_value()); + + //a5133_gpio_scs_set_value(0);/* Write 48 Bytes */ + ByteSend(FIFO_REG); + for(i=0; i<48; i++) + ByteSend(i++); + RF_StrobeCmd(CMD_TX);/* entry TX mode */ + //LOS_Msleep(2); + + + } + //printf("cko_flag_tmp 222cko_flag : %d - %d \n",cko_flag_tmp,cko_flag); + while(a5133_gpio_get_gio1_value())/* wait transmit completed */ + { + LOS_Msleep(1); + } + a5133_gpio_scs_set_value(1); + printf("222cko_irq_count : %d \n",cko_irq_count); + //printf("666a5133_gpio_get_cko_value : %d \n",a5133_gpio_get_cko_value()); + // Delay10ms(200); + // Delay10ms(200); + LOS_Msleep(4000); +#else RF_FIFOWrite(send_data[send_data_index],64);/* write data to tx fifo */ if(RF_LVR_Check())/* check if BOD reset has occurred */ break;/* exit loop & re-RF init */ @@ -216,19 +362,24 @@ void a5133_main(Uint8 Flag_MASTER,uint8_t channel) RxPacket(); Delay10ms(1); } +#endif } - } + } } - else + else//接收 { PRINT("Flag_Slave\n"); + while(1) { RF_WriteReg(GIO1_REG,0x01);/* gio1-wtr */ RF_WriteReg(GIO2_REG,0x1D);/* gio2-trxd */ +#ifdef A5133_FIFO_EXT_MODE + RF_WriteReg(CKO_REG,0x12);/* cko-fpf */ +#else RF_WriteReg(CKO_REG,0x02);/* cko-dck */ - RF_FIFOLength(64-1);/* write data to tx fifo */ +#endif RF_StrobeCmd(CMD_PLL); RF_SetCH(channel);/* ch=80, freq=5805.001MHz */ printf("slave channel %d , freq %d\n",channel,5725+channel); @@ -240,9 +391,80 @@ void a5133_main(Uint8 Flag_MASTER,uint8_t channel) timer=0; // TR0=1; // EA=1; - + //memset(tmpbuf, 0, 256);/* clear tmpbuf */ + //printf("111cko_irq_count : %d \n",cko_irq_count); while(1) { +#ifdef A5133_FIFO_EXT_MODE + n=0; + //cko_flag = 0; + RF_StrobeCmd(CMD_RX);/* entry RX mode */ + //printf("111a5133_gpio_get_cko_value : %d \n",a5133_gpio_get_cko_value()); + Delay10us(1); + // while(get_cko_flag() ==0 )/* wait FPF go high */ + // { + // LOS_Msleep(1); + // } + + //int read_timeout = 0xFFFFFFFF; + while(get_cko_flag() == 0) + { + // // read_timeout--; + // // if(read_timeout <= 0) + // // break; + //LOS_Msleep(1); + } + for(j=0; j<5; j++)/* Read 48 Byte x 5 */ + { + + //while(get_cko_flag() ==0);/* wait FPF go high */ + + + + // printf("888a5133_gpio_get_cko_value \n"); + a5133_gpio_scs_set_value(0); + ByteSend(FIFO_REG | 0x40); + for(i=0; i<48; i++)/* Read 48 Bytes */ + tmpbuf[n++]=ByteRead(); + //RF_StrobeCmd(CMD_RX); + a5133_gpio_scs_set_value(1); + + //read_timeout = 0xFFFFFFFF; + // while(a5133_gpio_get_cko_value())/* wait receive completed */ + // { + // //LOS_Msleep(1); + // } + //printf("888a5133_gpio_get_cko_value \n"); + // while(get_cko_flag() == 0) + // { + // read_timeout--; + // if(read_timeout <= 0) + // { + // printf("read_timeout !!!\n"); + // break; + // } + + // //LOS_Msleep(1); + // } + //RF_StrobeCmd(CMD_RX); + } + + while(a5133_gpio_get_gio1_value())/* wait receive completed */ + { + //LOS_Msleep(1); + } + //printf("read_timeout : %d \n",read_timeout); + //printf("888a5133_gpio_get_cko_value \n"); + a5133_gpio_scs_set_value(0);/* Read 16 Bytes */ + ByteSend(FIFO_REG | 0x40); + for(i=0; i<16; i++) + tmpbuf[n++]=ByteRead(); + a5133_gpio_scs_set_value(1); + RxPacket();/* check data */ + LOS_Msleep(300); + //Delay10ms(30); + printf("222cko_irq_count : %d \n",cko_irq_count); +#else if(RF_LVR_Check())/* check if BOD reset has occurred */ break;/* exit loop & re-RF init */ else @@ -266,9 +488,10 @@ void a5133_main(Uint8 Flag_MASTER,uint8_t channel) //sleep LOS_Msleep(10); }; - } - } - } +#endif + } + } + } } /************************************************************************ @@ -512,30 +735,32 @@ void RF_StrobeCmd(Uint8 cmd) } #include "wearable_log.h" +static uint8_t hexstr[HEXSTR_LEN]={0}; static void dump_tmpbuf(void) { - uint8_t hexstr[256]={0}; - for (int i=0 ;i < 64;i++) + + + for (int i=0 ;i < FIFO_LEN;i++) { sprintf( (char*)&hexstr[i*2],"%02X",tmpbuf[i]); } // printf((char*)&hexstr[0]); // printf("\n"); - printf("rx %s\n",(char*)&hexstr[0]); + printf("rx %s\n Err_Frame:%d\n SUCC_Frame:%d \n",(char*)&hexstr[0],Err_Frame,SUCC_Frame); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rx %s\n",hexstr); } -bool a5133_get_update_state(void) +Uint8 a5133_get_update_state(void) { return update_flag; } void a5133_get_rxdata(uint8_t *databuf,uint8_t len) { - memcpy_s(databuf,len,tmpbuf_rx,sizeof(tmpbuf_rx)); - update_flag = false; + memcpy_s(databuf,len,tmpbuf_rx1,sizeof(tmpbuf_rx1)); + update_flag = 0; } void a5133_get_rxdata_timestamp(uint32_t *timestamp) @@ -544,18 +769,48 @@ void a5133_get_rxdata_timestamp(uint32_t *timestamp) } /********************************************************************* -** RxPacket +** RxPacket(控制帧示例) *********************************************************************/ +Uint8 tmp_data[64]={ + 0xab,0x00,0x24,0xff,0xff,0xff,0xff,0xa1, + 0xa8,0x1f,0x3f,0x10,0x80,0x02,0x00,0x4a, + 0x8f,0x64,0xe0,0x6b,0xfa,0x01,0x12,0xff, + 0xff,0xff,0xff,0x03,0xf2,0x04,0x00,0xff, + 0xff,0xff,0xff,0x70,0xf6,0x1d,0x0a,0x8b, + 0x9e + //0x0a,0x00,0x24,0xff,0xff,0xff +}; + void RxPacket(void) { - Uint8 i,recv,tmp,err; - - RxCnt++; + Uint16 i; + Uint8 recv,tmp,err; err=0; + RxCnt++; + +#ifdef A5133_FIFO_EXT_MODE + for(i=0; i < 256; i++) + { + if(tmpbuf[i] != i) + { + err=1; + tmp = tmpbuf[i] ^ i; + Err_BitCnt += (BitCount_Tab[tmp>>4] + BitCount_Tab[tmp & 0x0F]); + } + } + + if(err) + Err_Frame++; +#else RF_StrobeCmd(CMD_RFR);//RX fifo pointer reset a5133_gpio_scs_set_value(0); ByteSend(FIFO_REG | 0x40);//address 0x05, bit7 cmd=0, bit6 r/w=1 + // tmpbuf[0] = 0x55; + // tmpbuf[1] = 0x55; + // tmpbuf[2] = 0x55; + // tmpbuf[3] = 0x55; + // tmpbuf[4] = 0xAB; for(i=0; i <64; i++) { recv = ByteRead(); @@ -568,37 +823,54 @@ void RxPacket(void) // } } //crccheck - + //memcpy(tmpbuf,&tmp_data[1],63); a5133_gpio_scs_set_value(1); - uint32_t msg_timestamp = *(uint32_t*)&tmpbuf[4]; - uint8_t datalen = tmpbuf[4+4]; - // total(64) , header(4), timestamp(4), len(1), data(n-11) , crc(2) - if (datalen >0 && datalen <= (64-4 -4 -1 -2 )) + +#endif + if(tmpbuf[0] == 0XAB) { - uint16_t crc = CRC16_XMODEM(&tmpbuf[1+4+4],datalen); - uint16_t recv_crc = *(uint16_t*)&tmpbuf[1+4+datalen+4]; - PRINT("crc[%X] , recv_crc %X\n",crc,recv_crc); - if (crc != recv_crc) - { - err = 1; - } - else + uint8_t msg_type = *(uint8_t*)&tmpbuf[1+2+4+4+2]; + //1 控制帧,2 数据帧 + // if(msg_type != 2) + // { + // return; + // } + uint32_t msg_timestamp = *(uint32_t*)&tmpbuf[1+2+4+4+4+2]; + uint16_t datalen = *(uint16_t*)&tmpbuf[1]; + // total(64) , header(4), timestamp(4), len(1), data(n-11) , crc(2) + // frame_start_flag(1),len(2) + if (datalen >0 && datalen <= (FIFO_LEN-1-2)) { - tmpbuf_len = datalen; - tmpbuf_rx_timestamp = msg_timestamp; - if(history_timestamp != tmpbuf_rx_timestamp) + uint16_t crc = CRC16_X25(&tmpbuf[3],datalen); + uint16_t recv_crc = *(uint16_t*)&tmpbuf[datalen+2+1]; + PRINT("datalen:%d crc[%X] , recv_crc %X\n",datalen,crc,recv_crc); + SUCC_Frame++; + if (crc != recv_crc) + { + err = 1; + } + else { - history_timestamp = tmpbuf_rx_timestamp; - update_flag = true; + tmpbuf_len = datalen-4-4-4-2-4; + tmpbuf_rx_timestamp = msg_timestamp; + if(history_timestamp != tmpbuf_rx_timestamp) + { + history_timestamp = tmpbuf_rx_timestamp; + if(datalen == 0X33) + update_flag = 1; + else + update_flag = 2; + } + memset(tmpbuf_rx1, 0 ,sizeof(tmpbuf_rx1)); + //帧起始(1)、帧长度(2)、目标地址(4)、设备地址(4)、MAC控制域(4)、帧序号、(2) + memcpy(tmpbuf_rx1, &tmpbuf[1+2+4+4+4+2+4],tmpbuf_len); } - memset(tmpbuf_rx, 0 ,sizeof(tmpbuf_rx)); - memcpy(tmpbuf_rx, &tmpbuf[1+4+4],datalen); + printf("=====RxPacket timestamp %d ,tmpbuf_rx1:%s\n",tmpbuf_rx_timestamp,tmpbuf_rx1); + + }else{ + err = 1 ; + printf("=====RxPacket failed datalen[%d]\n",datalen); } - printf("=====RxPacket timestamp %d , %s\n",tmpbuf_rx_timestamp,tmpbuf_rx); - - }else{ - err = 1 ; - printf("=====RxPacket failed datalen[%d]\n",datalen); } dump_tmpbuf(); if (err)//packet error @@ -928,7 +1200,7 @@ void RF_WOR_En(void) while(1) { RF_WriteReg(MODECTRL_REG, A5133_RFConfigTab_Main[1] | (1<<3)); //WOR enable - // while(~GIO2);//waitting to wakeup until packet is received + while(~a5133_gpio_get_gio2_value());//waitting to wakeup until packet is received RF_StrobeCmd(CMD_PLL); //Wakeup process... @@ -1014,11 +1286,11 @@ void main_prog_ACK(Uint8 Flag_MASTER) // P3 = P3 ^ 0x04;/* transmit completed, toggle I/O */ PRINT("transmit complete!\n"); else - nop();/* resend fail */ + _nop_();/* resend fail */ Delay10ms(5); } - } + } } else { @@ -1062,12 +1334,12 @@ void main_prog_ACK(Uint8 Flag_MASTER) RxPacket(); } else - nop();/* invalid packet */ + _nop_();/* invalid packet */ Delay10ms(4); - } - } - } + } + } + } } /********************************************************************* diff --git a/code/sdk/drivers/peripheral/a5133/A5133Uti.c b/code/sdk/drivers/peripheral/a5133/A5133Uti.c index d52c7a6a9..a11c87148 100644 --- a/code/sdk/drivers/peripheral/a5133/A5133Uti.c +++ b/code/sdk/drivers/peripheral/a5133/A5133Uti.c @@ -187,12 +187,18 @@ uint8_t a5133_gpio_get_value(pin_t pin) #define SCK_OUT S_MGPIO8 //spi SCK #define SDIO_IN_OUT S_MGPIO6 //spi SDIO #define GIO1_IN S_MGPIO7 //GPIO1 +#define CKO_IN S_AGPIO_L28 uint8_t a5133_gpio_get_gio1_value(void) { return a5133_gpio_get_value(GIO1_IN); } +uint8_t a5133_gpio_get_cko_value(void) +{ + return a5133_gpio_get_value(CKO_IN); +} + errcode_t a5133_gpio_scs_set_value(uint8_t value) { if(value) @@ -246,12 +252,16 @@ errcode_t a5133_gpio_init(void) return ERRCODE_FAIL; } + // ret = uapi_pin_set_mode(CKO_IN, HAL_PIO_FUNC_GPIO); + // if (ret != ERRCODE_SUCC) { + // return ERRCODE_FAIL; + // } + ret = a5133_gpio_set_direction(SCS_OUT,1); if (ret != ERRCODE_SUCC) { return ERRCODE_FAIL; } - ret = a5133_gpio_set_direction(SCK_OUT,1); if (ret != ERRCODE_SUCC) { return ERRCODE_FAIL; @@ -264,6 +274,11 @@ errcode_t a5133_gpio_init(void) if (ret != ERRCODE_SUCC) { return ERRCODE_FAIL; } + + // ret = a5133_gpio_set_direction(CKO_IN,0); + // if (ret != ERRCODE_SUCC) { + // return ERRCODE_FAIL; + // } #endif return ret; } diff --git a/code/sdk/drivers/peripheral/a5133/A5133main.h b/code/sdk/drivers/peripheral/a5133/A5133main.h index 1674ee21f..4fffddee4 100644 --- a/code/sdk/drivers/peripheral/a5133/A5133main.h +++ b/code/sdk/drivers/peripheral/a5133/A5133main.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-07-20 10:36:21 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-07-27 13:07:06 + * @LastEditTime: 2024-08-08 20:11:46 * @FilePath: /FD230/code/sdk/drivers/peripheral/a5133/A5133main.h * @Description: * @@ -75,6 +75,7 @@ void RF_TXPower(Uint8 tbf, Uint8 tpa); void a5133_main(Uint8 Flag_MASTER,uint8_t channel); void a5133_get_rxdata(uint8_t *databuf,uint8_t len); errcode_t a5133_set_send_data(uint8_t *senddata,uint8_t datalen); -bool a5133_get_update_state(void); +Uint8 a5133_get_update_state(void); void a5133_get_rxdata_timestamp(uint32_t *timestamp); +void a5133_cko_state_update(void); #endif \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp b/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp index d0e116245..47d251b41 100644 --- a/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp +++ b/code/sdk/drivers/peripheral/a5133/service/a5133_service.cpp @@ -189,7 +189,7 @@ errcode_t uapi_a5133_service_init(void) app_task_definition_t taskcfg={0}; taskcfg.create_queue_handle = create_a5133_queue; taskcfg.attr.name="a5133_service"; - taskcfg.attr.priority = osPriorityBelowNormal; + taskcfg.attr.priority = osPriorityHigh; taskcfg.attr.stack_size = A5133_SERVICE_TASK_SIZE; taskcfg.func = a5133_service_check_task; taskcfg.use_mem = USE_EXTEND_MEM; @@ -204,6 +204,15 @@ errcode_t uapi_a5133_service_init(void) return ERRCODE_SUCC; } +void a5133_cko_isr_callback(pin_t pin, uintptr_t param) +{ + // WEARABLE_LOGW(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1_ring_isr_callback %d 0x%X\n",pin,param); + uapi_gpio_clear_interrupt(pin); + //send_a5133_cmd_msg(A5133_SERVICE_CMD_TYPE_CKO_UPDATE); + a5133_cko_state_update(); + //printf("A5133_SERVICE_CMD_TYPE_CKO_UPDATE \n"); +} + #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/drivers/peripheral/a5133/service/a5133_service.h b/code/sdk/drivers/peripheral/a5133/service/a5133_service.h index 9eea44310..26854a6e3 100644 --- a/code/sdk/drivers/peripheral/a5133/service/a5133_service.h +++ b/code/sdk/drivers/peripheral/a5133/service/a5133_service.h @@ -1,9 +1,9 @@ /* * @Author: penglei 1624952103@qq.com * @Date: 2024-03-27 09:07:00 - * @LastEditors: SnickerSun snickersun@163.com - * @LastEditTime: 2024-07-20 08:16:02 - * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/service/a5133_service.h + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-08-08 11:25:15 + * @FilePath: /FD230/code/sdk/drivers/peripheral/a5133/service/a5133_service.h * @Description: * * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. @@ -34,6 +34,7 @@ typedef uint32_t A5133_CMD_TYPE_T ; #define A5133_SERVICE_CMD_TYPE_TIMER_CHECK 0X0B errcode_t uapi_a5133_service_init(void); void uapi_a5133_service_deinit(void); +void a5133_cko_isr_callback(pin_t pin, uintptr_t param); /** * 测试指令 参数cmd 选项: A5133_SERVICE_CMD_START_CHECK,A5133_SERVICE_CMD_STOP_CHECK */ diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index b1247b5be..c7564cd20 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -306,9 +306,12 @@ bool stop_alipay_ble_service(void) } uint8_t a5133_demo_msg_send[2][64]={ - "前方路段发生塌方,请紧急制动!", - "前方道路拥堵,请减速慢行!" + // "前方路段发生塌方,请紧急制动!", + // "前方道路拥堵,请减速慢行!" + "您已进入北斗收费路段", + "您已超速,请减速慢行!" }; + static uint8_t a5133_demo_msg_send_index=0; void a5133_demo_msg_unbind_callback(void) { @@ -2520,7 +2523,7 @@ void uapi_aging_test(uint32_t test_time) for(cmd = 0; cmd < 6 ; cmd++) { - // uapi_vibrationModeSet(3); + // ui_api_vibrate_once_func(3); ui_api_vibrate_once_func(); LOS_Msleep(1000); } @@ -2572,6 +2575,26 @@ void uapi_aging_test(uint32_t test_time) } } +void uapi_vibrator_test(uint32_t test_time) +{ + uint32_t total_time = test_time; + uint32_t enter_time = 0; + uint32_t age_time = 0; + while(total_time) + { + uapi_get_timestampe_ss(&enter_time); + custom_VibratorFunc_int(4); + LOS_Msleep(4000); + uapi_get_timestampe_ss(&age_time); + total_time -= (age_time - enter_time); + PRINT("total_time[%d]\n",total_time); + if(total_time <= 0) + return; + } +} + + + uint8_t uapi_get_cywee_static_state(void) { return cywee_get_static_state(); @@ -2602,6 +2625,48 @@ uint16_t CRC16_XMODEM(uint8_t *bytes,uint16_t length) return crc; } +uint16_t CRC16_X25(uint8_t *di, uint32_t len) +{ + uint16_t crc_poly = 0x1021; //X^16+X^12+X^5+1 total 16 effective bits without X^16. Computed total data shall be compensated 16-bit '0' before CRC computing. + + uint32_t clen = len+2; + uint8_t cdata[clen] ; + for(uint32_t j=0;j>(7-m) ) & 1 ) << m; + } + } + cdata[len]=0; cdata[len+1]=0; + + cdata[0] ^= 0xff; cdata[1] ^= 0xff; + + uint16_t data_t = (((uint16_t)cdata[0]) << 8) + cdata[1]; //CRC register + + for (uint32_t i = 2; i < clen; i++) + { + for (uint8_t j = 0; j <= 7; j++) + { + if(data_t&0x8000) + data_t = ( (data_t<<1) | ( (cdata[i]>>(7-j))&0x01) ) ^ crc_poly; + else + data_t = ( (data_t<<1) | ( (cdata[i]>>(7-j))&0x01) ) ; + } + } + + uint16_t i_data_t = 0; + + for(uint8_t n=0; n<=15; n++) + { + i_data_t |= ( ( data_t>>(15-n) ) & 1 ) << n; + } + + return i_data_t ^ 0xFFFF; +} + errcode_t uapi_a5133_set_send_data(uint8_t *senddata,uint8_t datalen) { #ifdef SUPPORT_A5133_SERVICE @@ -2611,7 +2676,7 @@ errcode_t uapi_a5133_set_send_data(uint8_t *senddata,uint8_t datalen) #endif } -bool uapi_get_a5133_update_state(void) +uint8_t uapi_get_a5133_update_state(void) { #ifdef SUPPORT_A5133_SERVICE return a5133_get_update_state(); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 1cab1bb62..31d557a86 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -240,10 +240,11 @@ void uapi_save_file_data(char *path,uint8_t *data,uint8_t len); uint8_t uapi_get_cywee_static_state(void); void uapi_get_a5133_rxdata(uint8_t *databuf,uint8_t len); uint16_t CRC16_XMODEM(uint8_t *bytes,uint16_t length); +uint16_t CRC16_X25(uint8_t *di, uint32_t len); errcode_t uapi_a5133_set_send_data(uint8_t *senddata,uint8_t datalen); void a5133_demo_msg_change_callback(void); void uapi_get_a5133_rxdata_timestamp(uint32_t *timestamp); -bool uapi_get_a5133_update_state(void); +uint8_t uapi_get_a5133_update_state(void); #include "custom_utilscpp.h" diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 9753f7497..e6baaf963 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -877,6 +877,29 @@ static uint32_t custom_aging_test(uint8_t *para, uint32_t paraLen, char *strComm return ERRCODE_SUCC; } +static uint32_t custom_vibrator_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 1) { + wstp_print("CUSTOM_UTILSTEST power_test ATCMD Set Parameter Failed argc %d\r\n"); + return ERRCODE_FAIL; + } + uint8_t test_time = atol((char*)argv[0]); + + uapi_vibrator_test(test_time * 60 * 60); + return ERRCODE_SUCC; +} + static uint32_t custom_get_aging_data(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { UNUSED(strCommonCmd); @@ -987,6 +1010,7 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { {(char *)"AT^GETCYWEEACTIVE", custom_get_cywee_active_state, (char *)" "}, {(char *)"AT^AGINGTEST", custom_aging_test, (char *)" "}, {(char *)"AT^GETAGING", custom_get_aging_data, (char *)" "}, + {(char *)"AT^VIBTEST", custom_vibrator_test, (char *)" "}, #ifdef SUPPORT_A5133_SERVICE {(char *)"AT^A5133SENDDATA", custom_a5133_send_msg, (char *)" "}, {(char *)"AT^A5133RSSI", custom_a5133_rssi, (char *)" "}, diff --git a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp index 8e425abe8..d56932631 100644 --- a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp +++ b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp @@ -1,3 +1,13 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-08-08 16:33:23 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-08-08 16:43:33 + * @FilePath: /FD230/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ /** * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n * @@ -56,8 +66,15 @@ void custom_VibratorFunc_int(int vibratorType) //忽略系统调用参数,只按照configmodel里保存的值来震动 uint8_t vibmod=uapi_dev_runtime_get_vibmod(); vibrator_cmd_t mail = {0}; + if(vibratorType == 4) + vibmod = 4; switch (vibmod) { + case 4: + mail.cycle_time_ms = 235; + mail.duty = 65; + mail.duration_time_ms = 2000; + break; case 3: mail.cycle_time_ms = 235; mail.duty = 65; diff --git a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.h b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.h index f23339cec..d9612bf9a 100644 --- a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.h +++ b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.h @@ -33,6 +33,7 @@ extern void do_vibrator_cmd(vibrator_cmd_t cmd); // UI 界面震动一次接口 void ui_api_vibrate_once_func(void); +void custom_VibratorFunc_int(int vibratorType); #ifdef __cplusplus #if __cplusplus -- 2.17.1