blob: 9b1265629d95c9ba957bfd671a21dc14f864891d [file] [log] [blame]
b.liu68a94c92025-05-24 12:53:41 +08001#include "lynq-qser-fota.h"
2#include "mbtk_type.h"
3#include "mbtk_fota.h"
4#include "mbtk_log.h"
5
6
7char addr_buf[128]={0};
8int segment_size =0;
9
10
11int Process_flag = 0;
12
13
14int fota_cb(int status, int percent)
15{
16 LOGE("%d: percent: %d%%\n", percent/10, percent);
17 Process_flag = percent/10;
18 return 0;
19}
20
21int lynq_read_process(void)
22{
23 return Process_flag;
24}
25
26int lynq_rock_main(int first_run)
27{
28 UNUSED(first_run);
29 LOGE("%s, %d", __FUNCTION__, __LINE__);
30 int ret = 0;
31
32 LOGE("addr_buf:%s, segment_size:%d\n", addr_buf, segment_size);
33 ret = mbtk_fota_init(fota_cb);
34 if(strncmp(addr_buf, "http", 4) == 0)
35 {
36
37 ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
38 }
39 else
40 {
41 ret =mbtk_fota_fw_write(addr_buf, segment_size);
42 }
43
44 if(ret)
45 {
46 LOGE("lynq_rock_main fail\n");
47 return -1;
48 }
49
50 mbtk_fota_done1(1);
51
52
53 return 0;
54}
55
56int lynq_fota_set_addr_value(char *value,int size)
57{
58 UNUSED(value);
59 UNUSED(size);
60 LOGE("%s, %d", __FUNCTION__, __LINE__);
61
62 if(value == NULL)
63 {
64 return -1;
65 }
66
67 memset(addr_buf, 0, sizeof(addr_buf));
68 memcpy(addr_buf, value, strlen(value));
69 segment_size = size;
70
71 LOGE("addr_buf:%s, value:%s\n", addr_buf, value);
72 LOGE("segment_size:%d, size:%d\n", segment_size, size);
73
74 return 0;
75}
76
77int lynq_fota_nrestart(void)
78{
79 LOGE("%s, %d", __FUNCTION__, __LINE__);
80 int ret = 0;
81
82 LOGE("addr_buf:%s", addr_buf);
83 ret = mbtk_fota_init(fota_cb);
84 if(strncmp(addr_buf, "http", 4) == 0)
85 {
86 ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
87 }
88 else
89 {
90 ret =mbtk_fota_fw_write(addr_buf, segment_size);
91 }
92
93 if(ret)
94 {
95 LOGE("lynq_fota_nrestart fail\n");
96 return -1;
97 }
98
99 return 0;
100}
101
102int lynq_get_upgrade_status(void)
103{
104 LOGE("%s, %d", __FUNCTION__, __LINE__);
105
106 return mbtk_fota_status();
107}
108
109int lynq_get_reboot_upgrade_status(void)
110{
111 return mbtk_fota_get_asr_reboot_cnt_flag();
112}
113