forked from xuos/xiuos
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;
|
return reg_crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int SaveAppBin(char* buf, int len)
|
static int SaveAppBin(int fd, char* buf, int len)
|
||||||
{
|
{
|
||||||
int fd = 0;
|
// int fd = 0;
|
||||||
fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT );
|
// fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT );
|
||||||
lseek(fd, 0, SEEK_END);
|
|
||||||
write(fd, buf, len);
|
write(fd, buf, len);
|
||||||
close(fd);
|
lseek(fd, len, SEEK_CUR);
|
||||||
|
|
||||||
|
// close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CrcFileCheck(uint32 crc_check, unsigned long total_len)
|
static int CrcFileCheck(uint32 crc_check, unsigned long total_len)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -121,6 +123,9 @@ static int OtaDataRecv(struct Adapter* adapter)
|
||||||
char reply[16] = {0};
|
char reply[16] = {0};
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int try_times = 5;
|
int try_times = 5;
|
||||||
|
int fd = 0;
|
||||||
|
|
||||||
|
fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
memset(&recv_msg, 0, sizeof(struct ota_data));
|
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))
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -166,6 +171,7 @@ try_again:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(fd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +224,7 @@ static void *OtaKTaskEntry(void *parameter)
|
||||||
PrivTaskDelay(3000); /* check ota signal every 3s */
|
PrivTaskDelay(3000); /* check ota signal every 3s */
|
||||||
}
|
}
|
||||||
AdapterDeviceClose(adapter);
|
AdapterDeviceClose(adapter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationOtaTaskInit(void)
|
void ApplicationOtaTaskInit(void)
|
||||||
|
|
|
@ -153,6 +153,10 @@ int OtaFileSend(int fd)
|
||||||
char * file_buf = NULL;
|
char * file_buf = NULL;
|
||||||
|
|
||||||
file_fd = fopen("/tmp/xiuos_app.bin", "r");
|
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)
|
while((ch = fgetc(file_fd)) != EOF)
|
||||||
{
|
{
|
||||||
|
@ -166,12 +170,13 @@ int OtaFileSend(int fd)
|
||||||
data.frame.crc = OtaCrc16(data.frame.frame_data, len);
|
data.frame.crc = OtaCrc16(data.frame.frame_data, len);
|
||||||
file_length += len;
|
file_length += len;
|
||||||
}
|
}
|
||||||
|
memcpy(data.frame.frame_data[len], "!@", strlen("!@")); /* add '!@' as ending flag */
|
||||||
lseek(file_fd, len, SEEK_CUR);
|
lseek(file_fd, len, SEEK_CUR);
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
||||||
len = recv(fd, buf, sizeof(buf), 0);
|
len = recv(fd, buf, sizeof(buf), 0);
|
||||||
if(0 == strncmp(buf, "ok", len))
|
if(0 == strncmp(buf, "ok!@", len))
|
||||||
{
|
{
|
||||||
frame_cnt++;
|
frame_cnt++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -219,6 +224,7 @@ void* server_thread(void* p)
|
||||||
int fd = *(int*)p;
|
int fd = *(int*)p;
|
||||||
unsigned char buf[32] = { 0 };
|
unsigned char buf[32] = { 0 };
|
||||||
struct ota_data data;
|
struct ota_data data;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
printf("pthread = %d\n",fd);
|
printf("pthread = %d\n",fd);
|
||||||
|
|
||||||
|
@ -231,19 +237,26 @@ void* server_thread(void* p)
|
||||||
|
|
||||||
send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
||||||
|
|
||||||
len = recv(fd, buf, sizeof(buf),0);
|
len = recv(fd, buf, sizeof(buf), 0);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
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)
|
void server(void)
|
||||||
|
|
|
@ -51,7 +51,7 @@ int Adapter4GInit(void)
|
||||||
|
|
||||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||||
if (!adapter) {
|
if (!adapter) {
|
||||||
free(adapter);
|
Privfree(adapter);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ int Adapter4GInit(void)
|
||||||
ret = Adapter4GRegister(adapter);
|
ret = Adapter4GRegister(adapter);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("Adapter4GInit register 4G adapter error\n");
|
printf("Adapter4GInit register 4G adapter error\n");
|
||||||
free(adapter);
|
Privfree(adapter);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ int Adapter4GInit(void)
|
||||||
AdapterProductInfoType product_info = Ec200tAttach(adapter);
|
AdapterProductInfoType product_info = Ec200tAttach(adapter);
|
||||||
if (!product_info) {
|
if (!product_info) {
|
||||||
printf("Adapter4GInit ec200t attach error\n");
|
printf("Adapter4GInit ec200t attach error\n");
|
||||||
free(adapter);
|
Privfree(adapter);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,4 +112,4 @@ int Adapter4GTest(void)
|
||||||
|
|
||||||
return 0;
|
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