b.liu | 1c74d69 | 2024-08-14 17:43:59 +0800 | [diff] [blame] | 1 | #include "lynq-qser-fota.h" |
| 2 | #include "mbtk_type.h" |
| 3 | #include "mbtk_fota.h" |
| 4 | |
| 5 | |
| 6 | char addr_buf[128]={0}; |
| 7 | int segment_size =0; |
| 8 | |
| 9 | |
| 10 | int Process_flag = 0; |
| 11 | |
| 12 | |
| 13 | int fota_cb(int status, int percent) |
| 14 | { |
| 15 | // printf("%d: percent: %d%%\n", percent/10, percent); |
| 16 | Process_flag = percent/10; |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | int lynq_read_process(void) |
| 21 | { |
| 22 | return Process_flag; |
| 23 | } |
| 24 | |
| 25 | int lynq_rock_main(int first_run) |
| 26 | { |
| 27 | UNUSED(first_run); |
| 28 | 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); |
| 50 | |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | int lynq_fota_set_addr_value(char *value,int size) |
| 56 | { |
| 57 | UNUSED(value); |
| 58 | UNUSED(size); |
| 59 | printf("111%s, %d", __FUNCTION__, __LINE__); |
| 60 | |
| 61 | 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); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | int lynq_fota_nrestart(void) |
| 77 | { |
| 78 | 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 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | int lynq_get_upgrade_status(void) |
| 101 | { |
| 102 | printf("%s, %d", __FUNCTION__, __LINE__); |
| 103 | |
| 104 | return mbtk_fota_status(); |
| 105 | } |
| 106 | |
| 107 | int lynq_get_reboot_upgrade_status(void) |
| 108 | { |
| 109 | return mbtk_fota_get_asr_reboot_cnt_flag(); |
| 110 | } |
| 111 | |