From 7ba883affe6ff286b65d8028e3a380bae29c281b Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 29 May 2023 10:04:45 +0800 Subject: [PATCH] modify data length for 4g translation --- .../Framework/connection/4g/ec200t/Kconfig | 2 +- APP_Framework/Framework/connection/at_agent.h | 7 +- .../XiZi_IIoT/board/xidatong-arm32/.defconfig | 8 +- Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig | 2 + .../XiZi_IIoT/tool/bootloader/ota/ota.h | 2 +- .../tool/bootloader/ota/server_tcp.c | 97 ++++++++++++------- 6 files changed, 81 insertions(+), 37 deletions(-) diff --git a/APP_Framework/Framework/connection/4g/ec200t/Kconfig b/APP_Framework/Framework/connection/4g/ec200t/Kconfig index 01ecea76e..f97268782 100644 --- a/APP_Framework/Framework/connection/4g/ec200t/Kconfig +++ b/APP_Framework/Framework/connection/4g/ec200t/Kconfig @@ -23,7 +23,7 @@ if ADD_XIZI_FETURES config ADAPTER_EC200T_DRIVER string "EC200T device uart driver path" - default "/dev/usart2_dev2" + default "/dev/uart8_dev8" depends on !ADAPTER_EC200T_DRIVER_EXTUART if ADAPTER_EC200T_DRIVER_EXTUART diff --git a/APP_Framework/Framework/connection/at_agent.h b/APP_Framework/Framework/connection/at_agent.h index 42d589a0c..573ed1f9c 100755 --- a/APP_Framework/Framework/connection/at_agent.h +++ b/APP_Framework/Framework/connection/at_agent.h @@ -26,6 +26,12 @@ #include #include +#if defined(CONNECTION_ADAPTER_4G) && defined(TOOL_USING_OTA) +#define ENTM_RECV_MAX 1024 +#else +#define ENTM_RECV_MAX 256 +#endif + #define REPLY_TIME_OUT 10 enum ReceiveMode @@ -70,7 +76,6 @@ struct ATAgent #endif pthread_t at_handler; - #define ENTM_RECV_MAX 256 char entm_recv_buf[ENTM_RECV_MAX]; uint32 entm_recv_len; enum ReceiveMode receive_mode; diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/.defconfig b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/.defconfig index ad4f5b2b4..95c11b65a 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/.defconfig +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/.defconfig @@ -21,8 +21,12 @@ CONFIG_BSP_USING_LPUART3=y CONFIG_SERIAL_BUS_NAME_3="uart3" CONFIG_SERIAL_DRV_NAME_3="uart3_drv" CONFIG_SERIAL_3_DEVICE_NAME_0="uart3_dev3" + # CONFIG_BSP_USING_LPUART4 is not set -# CONFIG_BSP_USING_LPUART8 is not set +CONFIG_BSP_USING_LPUART8=y +CONFIG_SERIAL_BUS_NAME_8="uart8" +CONFIG_SERIAL_DRV_NAME_8="uart8_drv" +CONFIG_SERIAL_8_DEVICE_NAME_0="uart8_dev8" # CONFIG_BSP_USING_CH438 is not set CONFIG_BSP_USING_GPIO=y CONFIG_PIN_BUS_NAME="pin" @@ -230,6 +234,8 @@ CONFIG_ADD_XIZI_FETURES=y # CONFIG_SUPPORT_CONNECTION_FRAMEWORK is not set # CONFIG_SUPPORT_KNOWING_FRAMEWORK is not set # CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set +CONFIG_CONNECTION_FRAMEWORK_DEBUG=n + # # Security diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig b/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig index f5213d718..cb66fafd6 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig @@ -14,6 +14,8 @@ menu "OTA function" config MCUBOOT_APPLICATION bool "Config as application." + select SUPPORT_CONNECTION_FRAMEWORK + select CONNECTION_ADAPTER_4G endchoice diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h index 4303b0bf7..b257dd3ae 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h @@ -25,7 +25,7 @@ #define JUMP_FAILED_FLAG 0XABABABAB #define JUMP_SUCCESS_FLAG 0XCDCDCDCD -#define LENGTH 64 //每帧数据的数据包长度 +#define LENGTH 256 //每帧数据的数据包长度 typedef enum { OTA_STATUS_IDLE = 0, // 空闲状态,没有进行OTA升级 diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/server_tcp.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/server_tcp.c index 56534ec73..d74701723 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/server_tcp.c +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/server_tcp.c @@ -40,7 +40,7 @@ #define PORT 7777 //socket端口号 #define SIZE 100 //socket链接限制为100 -#define LENGTH 64 //每帧数据的数据包长度 +#define LENGTH 256 //每帧数据的数据包长度 #define BIN_PATH "/home/aep05/wgz/XiZi-xidatong-arm32-app.bin" //bin包的路径 struct ota_header_t @@ -155,6 +155,50 @@ void sockt_init(void) } +/******************************************************************************* +* 函 数 名: ota_start_signal +* 功能描述: 发送开始信号,等待接收端回应ready +* 形 参: fd:监听的客户端连接的fd +* 返 回 值: 0:成功,-1:失败 +*******************************************************************************/ +void ota_start_signal(int fd) +{ + struct ota_data data; + uint8_t buf[32]; + int ret; + int length = 0; + + while(1) + { + memset(&data, 0x0 , sizeof(struct ota_data)); + data.header.frame_flag = 0x5A5A; + memcpy(data.frame.frame_data,"aiit_ota_start",strlen("aiit_ota_start")); + data.frame.frame_len = strlen("aiit_ota_start"); + + printf("send start signal.\n"); + ret = send(fd, &data, sizeof(data), MSG_NOSIGNAL); + if (ret > 0){ + printf("send %s[%d] Bytes\n",data.frame.frame_data,ret); + } + + memset(buf, 0, 32); + length = recv(fd, buf, sizeof(buf), 0); + if (length > 0 && (0 == strncmp(buf, "ready", length))) + { + printf("recv buf %s length %d\n",buf,length); + break; + } + + else + { + continue; + } + + } + +} + + /******************************************************************************* * 函 数 名: ota_file_send * 功能描述: 用于在TCP Server发送bin文件 @@ -165,15 +209,25 @@ int ota_file_send(int fd) { unsigned char buf[32] = { 0 }; struct ota_data data; + struct stat st; FILE *file_fd; int length = 0; int try_times; int recv_end_times = 3; int ret = 0; - int frame_cnt = 0; + int file_frame_cnt, frame_cnt = 0; int file_length = 0; char * file_buf = NULL; + if (stat(BIN_PATH, &st) == 0) { + //获取文件大小(以字节为单位) + file_frame_cnt = (st.st_size%LENGTH != 0)? (st.st_size/LENGTH + 1):(st.st_size/LENGTH); + printf("File size is %ld bytes,file frame count is %d!\n", st.st_size, file_frame_cnt); + }else{ + printf("get file size failed.\n"); + return -1; + } + file_fd = fopen(BIN_PATH, "r"); if (NULL == file_fd){ printf("open file failed.\n"); @@ -320,41 +374,18 @@ void* server_thread(void* p) int length = 0; printf("pthread = %d\n",fd); - sleep(8); + sleep(5); + ota_start_signal(fd); while(1) { - memset(&data, 0x0 , sizeof(struct ota_data)); - data.header.frame_flag = 0x5A5A; - memcpy(data.frame.frame_data,"aiit_ota_start",strlen("aiit_ota_start")); - data.frame.frame_len = strlen("aiit_ota_start"); - - printf("send start signal.\n"); - ret = send(fd, &data, sizeof(data), MSG_NOSIGNAL); - if (ret > 0){ - printf("send %s[%d] Bytes\n",data.frame.frame_data,ret); - } - - memset(buf, 0, 32); - length = recv(fd, buf, sizeof(buf), 0); - if (length <= 0) - { + ret = ota_file_send(fd); + if (ret == 0) { + printf("ota file send successful.\n"); + break; + } else { + /* ota failed then restart the ota process */ continue; } - else - { - printf("recv buf %s length %d\n",buf,length); - if(0 == strncmp(buf, "ready", length)) - { - ret = ota_file_send(fd); - if (ret == 0) { - printf("ota file send successful.\n"); - break; - } else { - /* ota failed then restart the ota process */ - continue; - } - } - } } printf("exit fd = %d\n",fd); close(fd);