blob: 1ac1b68ddd3c7bf461279d8267a15b1d8d9dd5c6 [file] [log] [blame]
b.liu4e243dc2023-11-27 11:20:00 +08001#include "lynq-qser-fota.h"
2#include "mbtk_type.h"
LUOJian9a2d3ba2024-01-05 17:14:41 +08003#include "mbtk_fota.h"
4
5
6char addr_buf[128]={0};
7int segment_size =0;
8
9
luojian778b0d92024-04-07 16:34:09 +080010int Process_flag = 0;
11
12
LUOJian9a2d3ba2024-01-05 17:14:41 +080013int fota_cb(int status, int percent)
14{
luojian600f8a72024-04-07 17:24:52 +080015// printf("%d: percent: %d%%\n", percent/10, percent);
16 Process_flag = percent/10;
luojian778b0d92024-04-07 16:34:09 +080017 return 0;
18}
19
20int lynq_read_process(void)
21{
luojian600f8a72024-04-07 17:24:52 +080022 return Process_flag;
LUOJian9a2d3ba2024-01-05 17:14:41 +080023}
b.liu5fa9e772023-11-23 18:00:55 +080024
25int lynq_rock_main(int first_run)
26{
27 UNUSED(first_run);
LUOJian9a2d3ba2024-01-05 17:14:41 +080028 printf("%s, %d", __FUNCTION__, __LINE__);
29 int ret = 0;
30
31 printf("addr_buf:%s, segment_size:%d\n", addr_buf, segment_size);
32 ret = mbtk_fota_init(fota_cb);
33 if(!strcmp(addr_buf, "http"))
34 {
35
36 ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
37 }
38 else
39 {
40 ret =mbtk_fota_fw_write(addr_buf, segment_size);
41 }
42
43 if(ret)
44 {
45 printf("lynq_rock_main fail\n");
46 return -1;
47 }
48
49 mbtk_fota_done1(1);
b.liu5fa9e772023-11-23 18:00:55 +080050
51
52 return 0;
53}
54
55int lynq_fota_set_addr_value(char *value,int size)
56{
57 UNUSED(value);
58 UNUSED(size);
LUOJian9a2d3ba2024-01-05 17:14:41 +080059 printf("111%s, %d", __FUNCTION__, __LINE__);
b.liu5fa9e772023-11-23 18:00:55 +080060
LUOJian9a2d3ba2024-01-05 17:14:41 +080061 if(value == NULL)
62 {
63 return -1;
64 }
65
66 memset(addr_buf, 0, sizeof(addr_buf));
67 memcpy(addr_buf, value, strlen(value));
68 segment_size = size;
69
70 printf("addr_buf:%s, value:%s\n", addr_buf, value);
71 printf("segment_size:%d, size:%d\n", segment_size, size);
b.liu5fa9e772023-11-23 18:00:55 +080072
73 return 0;
74}
75
76int lynq_fota_nrestart(void)
77{
LUOJian9a2d3ba2024-01-05 17:14:41 +080078 printf("%s, %d", __FUNCTION__, __LINE__);
79 int ret = 0;
80
81 ret = mbtk_fota_init(fota_cb);
82 if(!strcmp(addr_buf, "http"))
83 {
84 ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
85 }
86 else
87 {
88 ret =mbtk_fota_fw_write(addr_buf, segment_size);
89 }
90
91 if(ret)
92 {
93 printf("lynq_fota_nrestart fail\n");
94 return -1;
95 }
b.liu5fa9e772023-11-23 18:00:55 +080096
97 return 0;
98}
99
100int lynq_get_upgrade_status(void)
101{
LUOJian9a2d3ba2024-01-05 17:14:41 +0800102 printf("%s, %d", __FUNCTION__, __LINE__);
b.liu5fa9e772023-11-23 18:00:55 +0800103
LUOJian9a2d3ba2024-01-05 17:14:41 +0800104 return mbtk_fota_status();
b.liu5fa9e772023-11-23 18:00:55 +0800105}
106
luojian17de8c52024-05-31 09:46:11 +0800107int lynq_get_reboot_upgrade_status(void)
108{
109 return mbtk_fota_get_asr_reboot_cnt_flag();
110}
111