reapir ota save bin process
This commit is contained in:
parent
224201ba55
commit
8b2eee0aa0
|
@ -73,14 +73,16 @@ uint32_t OtaCrc16(uint8_t * data, uint8_t length)
|
|||
return reg_crc;
|
||||
}
|
||||
|
||||
static int SaveAppBin(char* buf, int len)
|
||||
static int SaveAppBin(int fd, char* buf, int len)
|
||||
{
|
||||
int fd = 0;
|
||||
fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT );
|
||||
lseek(fd, 0, SEEK_END);
|
||||
// int fd = 0;
|
||||
// fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT );
|
||||
write(fd, buf, len);
|
||||
close(fd);
|
||||
lseek(fd, len, SEEK_CUR);
|
||||
|
||||
// close(fd);
|
||||
}
|
||||
|
||||
static int CrcFileCheck(uint32 crc_check, unsigned long total_len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -121,6 +123,9 @@ static int OtaDataRecv(struct Adapter* adapter)
|
|||
char reply[16] = {0};
|
||||
int ret = 0;
|
||||
int try_times = 5;
|
||||
int fd = 0;
|
||||
|
||||
fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT | O_TRUNC);
|
||||
|
||||
while(1) {
|
||||
memset(&recv_msg, 0, sizeof(struct ota_data));
|
||||
|
@ -140,7 +145,7 @@ static int OtaDataRecv(struct Adapter* adapter)
|
|||
|
||||
if (recv_msg.frame.crc == OtaCrc16(recv_msg.frame.frame_data,recv_msg.frame.frame_len))
|
||||
{
|
||||
SaveAppBin(recv_msg.frame.frame_data, recv_msg.frame.frame_len);
|
||||
SaveAppBin(fd, recv_msg.frame.frame_data, recv_msg.frame.frame_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -166,6 +171,7 @@ try_again:
|
|||
continue;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -218,6 +224,7 @@ static void *OtaKTaskEntry(void *parameter)
|
|||
PrivTaskDelay(3000); /* check ota signal every 3s */
|
||||
}
|
||||
AdapterDeviceClose(adapter);
|
||||
|
||||
}
|
||||
|
||||
void ApplicationOtaTaskInit(void)
|
||||
|
|
|
@ -153,6 +153,10 @@ int OtaFileSend(int fd)
|
|||
char * file_buf = NULL;
|
||||
|
||||
file_fd = fopen("/tmp/xiuos_app.bin", "r");
|
||||
if (NULL == file_fd){
|
||||
printf("open file failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while((ch = fgetc(file_fd)) != EOF)
|
||||
{
|
||||
|
@ -166,12 +170,13 @@ int OtaFileSend(int fd)
|
|||
data.frame.crc = OtaCrc16(data.frame.frame_data, len);
|
||||
file_length += len;
|
||||
}
|
||||
memcpy(data.frame.frame_data[len], "!@", strlen("!@")); /* add '!@' as ending flag */
|
||||
lseek(file_fd, len, SEEK_CUR);
|
||||
|
||||
try_again:
|
||||
send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
||||
len = recv(fd, buf, sizeof(buf), 0);
|
||||
if(0 == strncmp(buf, "ok", len))
|
||||
if(0 == strncmp(buf, "ok!@", len))
|
||||
{
|
||||
frame_cnt++;
|
||||
continue;
|
||||
|
@ -219,6 +224,7 @@ void* server_thread(void* p)
|
|||
int fd = *(int*)p;
|
||||
unsigned char buf[32] = { 0 };
|
||||
struct ota_data data;
|
||||
int ret = 0;
|
||||
|
||||
printf("pthread = %d\n",fd);
|
||||
|
||||
|
@ -231,19 +237,26 @@ void* server_thread(void* p)
|
|||
|
||||
send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
||||
|
||||
len = recv(fd, buf, sizeof(buf),0);
|
||||
len = recv(fd, buf, sizeof(buf), 0);
|
||||
if (len <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(0 == strncmp(buf, "ok", len))
|
||||
if(0 == strncmp(buf, "ok!@", len))
|
||||
{
|
||||
OtaFileSend(fd);
|
||||
ret = OtaFileSend(fd);
|
||||
if (ret == 0) {
|
||||
printf("ota file send successful.\n");
|
||||
break;
|
||||
} else { /* ota failed then restart the ota process */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void server(void)
|
||||
|
|
|
@ -51,7 +51,7 @@ int Adapter4GInit(void)
|
|||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
free(adapter);
|
||||
Privfree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ int Adapter4GInit(void)
|
|||
ret = Adapter4GRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("Adapter4GInit register 4G adapter error\n");
|
||||
free(adapter);
|
||||
Privfree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ int Adapter4GInit(void)
|
|||
AdapterProductInfoType product_info = Ec200tAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("Adapter4GInit ec200t attach error\n");
|
||||
free(adapter);
|
||||
Privfree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -112,4 +112,4 @@ int Adapter4GTest(void)
|
|||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, Adapter4GTest, Adapter4GTest, show adapter 4G information);
|
||||
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, Adapter4GTest, Adapter4GTest, show adapter 4G information);
|
||||
|
|
Loading…
Reference in New Issue