forked from xuos/xiuos
modify data length for 4g translation
This commit is contained in:
parent
f59139f78e
commit
7ba883affe
|
@ -23,7 +23,7 @@ if ADD_XIZI_FETURES
|
||||||
|
|
||||||
config ADAPTER_EC200T_DRIVER
|
config ADAPTER_EC200T_DRIVER
|
||||||
string "EC200T device uart driver path"
|
string "EC200T device uart driver path"
|
||||||
default "/dev/usart2_dev2"
|
default "/dev/uart8_dev8"
|
||||||
depends on !ADAPTER_EC200T_DRIVER_EXTUART
|
depends on !ADAPTER_EC200T_DRIVER_EXTUART
|
||||||
|
|
||||||
if ADAPTER_EC200T_DRIVER_EXTUART
|
if ADAPTER_EC200T_DRIVER_EXTUART
|
||||||
|
|
|
@ -26,6 +26,12 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#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
|
#define REPLY_TIME_OUT 10
|
||||||
|
|
||||||
enum ReceiveMode
|
enum ReceiveMode
|
||||||
|
@ -70,7 +76,6 @@ struct ATAgent
|
||||||
#endif
|
#endif
|
||||||
pthread_t at_handler;
|
pthread_t at_handler;
|
||||||
|
|
||||||
#define ENTM_RECV_MAX 256
|
|
||||||
char entm_recv_buf[ENTM_RECV_MAX];
|
char entm_recv_buf[ENTM_RECV_MAX];
|
||||||
uint32 entm_recv_len;
|
uint32 entm_recv_len;
|
||||||
enum ReceiveMode receive_mode;
|
enum ReceiveMode receive_mode;
|
||||||
|
|
|
@ -21,8 +21,12 @@ CONFIG_BSP_USING_LPUART3=y
|
||||||
CONFIG_SERIAL_BUS_NAME_3="uart3"
|
CONFIG_SERIAL_BUS_NAME_3="uart3"
|
||||||
CONFIG_SERIAL_DRV_NAME_3="uart3_drv"
|
CONFIG_SERIAL_DRV_NAME_3="uart3_drv"
|
||||||
CONFIG_SERIAL_3_DEVICE_NAME_0="uart3_dev3"
|
CONFIG_SERIAL_3_DEVICE_NAME_0="uart3_dev3"
|
||||||
|
|
||||||
# CONFIG_BSP_USING_LPUART4 is not set
|
# 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_CH438 is not set
|
||||||
CONFIG_BSP_USING_GPIO=y
|
CONFIG_BSP_USING_GPIO=y
|
||||||
CONFIG_PIN_BUS_NAME="pin"
|
CONFIG_PIN_BUS_NAME="pin"
|
||||||
|
@ -230,6 +234,8 @@ CONFIG_ADD_XIZI_FETURES=y
|
||||||
# CONFIG_SUPPORT_CONNECTION_FRAMEWORK is not set
|
# CONFIG_SUPPORT_CONNECTION_FRAMEWORK is not set
|
||||||
# CONFIG_SUPPORT_KNOWING_FRAMEWORK is not set
|
# CONFIG_SUPPORT_KNOWING_FRAMEWORK is not set
|
||||||
# CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set
|
# CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set
|
||||||
|
CONFIG_CONNECTION_FRAMEWORK_DEBUG=n
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Security
|
# Security
|
||||||
|
|
|
@ -14,6 +14,8 @@ menu "OTA function"
|
||||||
|
|
||||||
config MCUBOOT_APPLICATION
|
config MCUBOOT_APPLICATION
|
||||||
bool "Config as application."
|
bool "Config as application."
|
||||||
|
select SUPPORT_CONNECTION_FRAMEWORK
|
||||||
|
select CONNECTION_ADAPTER_4G
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#define JUMP_FAILED_FLAG 0XABABABAB
|
#define JUMP_FAILED_FLAG 0XABABABAB
|
||||||
#define JUMP_SUCCESS_FLAG 0XCDCDCDCD
|
#define JUMP_SUCCESS_FLAG 0XCDCDCDCD
|
||||||
#define LENGTH 64 //每帧数据的数据包长度
|
#define LENGTH 256 //每帧数据的数据包长度
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OTA_STATUS_IDLE = 0, // 空闲状态,没有进行OTA升级
|
OTA_STATUS_IDLE = 0, // 空闲状态,没有进行OTA升级
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
#define PORT 7777 //socket端口号
|
#define PORT 7777 //socket端口号
|
||||||
#define SIZE 100 //socket链接限制为100
|
#define SIZE 100 //socket链接限制为100
|
||||||
#define LENGTH 64 //每帧数据的数据包长度
|
#define LENGTH 256 //每帧数据的数据包长度
|
||||||
#define BIN_PATH "/home/aep05/wgz/XiZi-xidatong-arm32-app.bin" //bin包的路径
|
#define BIN_PATH "/home/aep05/wgz/XiZi-xidatong-arm32-app.bin" //bin包的路径
|
||||||
|
|
||||||
struct ota_header_t
|
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
|
* 函 数 名: ota_file_send
|
||||||
* 功能描述: 用于在TCP Server发送bin文件
|
* 功能描述: 用于在TCP Server发送bin文件
|
||||||
|
@ -165,15 +209,25 @@ int ota_file_send(int fd)
|
||||||
{
|
{
|
||||||
unsigned char buf[32] = { 0 };
|
unsigned char buf[32] = { 0 };
|
||||||
struct ota_data data;
|
struct ota_data data;
|
||||||
|
struct stat st;
|
||||||
FILE *file_fd;
|
FILE *file_fd;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
int try_times;
|
int try_times;
|
||||||
int recv_end_times = 3;
|
int recv_end_times = 3;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int frame_cnt = 0;
|
int file_frame_cnt, frame_cnt = 0;
|
||||||
int file_length = 0;
|
int file_length = 0;
|
||||||
char * file_buf = NULL;
|
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");
|
file_fd = fopen(BIN_PATH, "r");
|
||||||
if (NULL == file_fd){
|
if (NULL == file_fd){
|
||||||
printf("open file failed.\n");
|
printf("open file failed.\n");
|
||||||
|
@ -320,41 +374,18 @@ void* server_thread(void* p)
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
|
||||||
printf("pthread = %d\n",fd);
|
printf("pthread = %d\n",fd);
|
||||||
sleep(8);
|
sleep(5);
|
||||||
|
ota_start_signal(fd);
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
memset(&data, 0x0 , sizeof(struct ota_data));
|
ret = ota_file_send(fd);
|
||||||
data.header.frame_flag = 0x5A5A;
|
if (ret == 0) {
|
||||||
memcpy(data.frame.frame_data,"aiit_ota_start",strlen("aiit_ota_start"));
|
printf("ota file send successful.\n");
|
||||||
data.frame.frame_len = strlen("aiit_ota_start");
|
break;
|
||||||
|
} else {
|
||||||
printf("send start signal.\n");
|
/* ota failed then restart the ota process */
|
||||||
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)
|
|
||||||
{
|
|
||||||
continue;
|
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);
|
printf("exit fd = %d\n",fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
Loading…
Reference in New Issue