b.liu | 86b7ff2 | 2024-04-03 14:25:55 +0800 | [diff] [blame^] | 1 | #include <stdio.h>
|
| 2 | #include <string.h>
|
| 3 | #include <stdlib.h>
|
| 4 | #include <fcntl.h>
|
| 5 | #include "lynq-qser-fota.h"
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 | int fota_cb(int status, int percent)
|
| 10 | {
|
| 11 | printf("status: %d, percent: %d%%\n", status, percent);
|
| 12 | return 0;
|
| 13 | }
|
| 14 |
|
| 15 | int main(void)
|
| 16 | {
|
| 17 | int cmdIdx = 0,i=0;
|
| 18 | int ret = 0;
|
| 19 | int type_path = 0;
|
| 20 | char path[256] = {0};
|
| 21 | char operator[10];
|
| 22 | int opt = 0;
|
| 23 |
|
| 24 |
|
| 25 | while(1)
|
| 26 | {
|
| 27 | printf("=========fota========2\n"
|
| 28 | "\t 0 lynq_fota_set_addr_value\n"
|
| 29 | "\t 1 lynq_rock_main\n"
|
| 30 | "\t 2 lynq_fota_nrestart\n"
|
| 31 | "\t 3 lynq_get_upgrade_status\n"
|
| 32 | "\t 4 Close \n"
|
| 33 | "=========================\n");
|
| 34 |
|
| 35 | fflush(stdin);
|
| 36 | fgets(operator, sizeof(operator), stdin);
|
| 37 | opt = atoi(operator);
|
| 38 |
|
| 39 | switch(opt)
|
| 40 | {
|
| 41 | case 0://"ql_fota_start"
|
| 42 | {
|
| 43 | ret = lynq_fota_set_addr_value("/tmp/updata.bin", 26976256);
|
| 44 | if(ret)
|
| 45 | {
|
| 46 | printf("lynq_fota_set_addr_value failed, ret=%d\n", ret);
|
| 47 | }
|
| 48 |
|
| 49 | break;
|
| 50 | }
|
| 51 | case 1://"ql_fota_start"
|
| 52 | {
|
| 53 | ret = lynq_rock_main(1);
|
| 54 | printf("lynq_rock_main() ret:%d!\n", ret);
|
| 55 |
|
| 56 | break;
|
| 57 | }
|
| 58 | case 2://"ql_fota_start"
|
| 59 | {
|
| 60 | ret = lynq_fota_nrestart();
|
| 61 | printf("lynq_fota_nrestart() ret:%d!\n", ret);
|
| 62 |
|
| 63 | break;
|
| 64 | }
|
| 65 | case 3://"ql_fota_start"
|
| 66 | {
|
| 67 | ret = lynq_get_upgrade_status();
|
| 68 |
|
| 69 | printf("lynq_get_upgrade_status() ret:%d!\n", ret);
|
| 70 |
|
| 71 | break;
|
| 72 | }
|
| 73 | default://"ql_fota_start"
|
| 74 | {
|
| 75 | printf("break\n");
|
| 76 | return 0;
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 | return 0;
|
| 81 | }
|
| 82 |
|
| 83 |
|
| 84 | int main_1(void)
|
| 85 | {
|
| 86 | int cmdIdx = 0,i=0;
|
| 87 | int ret = 0;
|
| 88 | int type_path = 0;
|
| 89 | char path[256] = {0};
|
| 90 | char operator[10];
|
| 91 | int opt = 0;
|
| 92 |
|
| 93 |
|
| 94 | while(1)
|
| 95 | {
|
| 96 | printf("=========fota========2\n"
|
| 97 | "\t 0 ql_fota_init\n"
|
| 98 | "\t 1 ql_fota_fw_write_by_url\n"
|
| 99 | "\t 2 ql_fota_fw_write\n"
|
| 100 | "\t 3 ql_fota_done\n"
|
| 101 | "\t 4 Close \n"
|
| 102 | "=========================\n");
|
| 103 |
|
| 104 | fflush(stdin);
|
| 105 | fgets(operator, sizeof(operator), stdin);
|
| 106 | opt = atoi(operator);
|
| 107 |
|
| 108 | switch(opt)
|
| 109 | {
|
| 110 | case 0://"ql_fota_start"
|
| 111 | {
|
| 112 | ret = ql_fota_init(fota_cb);
|
| 113 | if(ret)
|
| 114 | {
|
| 115 | printf("ql_fota_init failed, ret=%d\n", ret);
|
| 116 | }
|
| 117 |
|
| 118 | break;
|
| 119 | }
|
| 120 | case 1://"ql_fota_start"
|
| 121 | {
|
| 122 | printf("<** please input url path(http://118.114.239.159:30119/update.bin)**!>\n");
|
| 123 |
|
| 124 | memcpy(path, "http://118.114.239.159:30119/update.bin", strlen("http://118.114.239.159:30119/update.bin"));
|
| 125 | if(!strncasecmp(path, "ftp://", 6) || !strncasecmp(path, "http://", 7) || !strncasecmp(path, "https://", 8)) //url
|
| 126 | {
|
| 127 | ret = ql_fota_fw_write_by_url(path, 3*1024*1024, 10, 600);
|
| 128 | if(ret)
|
| 129 | {
|
| 130 | printf("ql_fota_fw_write_by_url failed, ret=%d\n", ret);
|
| 131 | break;
|
| 132 | }
|
| 133 | }
|
| 134 |
|
| 135 | break;
|
| 136 | }
|
| 137 | case 2://"ql_fota_start"
|
| 138 | {
|
| 139 | printf("<** please input local path( /NVM/updata.bin)>\n");
|
| 140 | ret = ql_fota_fw_write("/NVM/updata.bin", 3*1024*1024);
|
| 141 | if(ret)
|
| 142 | {
|
| 143 | printf("ql_fota_fw_write failed, ret=%d\n", ret);
|
| 144 | }else{
|
| 145 | printf("ql_fota_fw_write success ret £º%\n", ret);
|
| 146 | }
|
| 147 |
|
| 148 | break;
|
| 149 | }
|
| 150 | case 3://"ql_fota_start"
|
| 151 | {
|
| 152 | ret = ql_fota_done(1);
|
| 153 | if(ret)
|
| 154 | {
|
| 155 | printf("ql_fota_done failed, ret=%d\n", ret);
|
| 156 | break;
|
| 157 | }
|
| 158 | else
|
| 159 | {
|
| 160 | printf("download firmware success!\n");
|
| 161 | }
|
| 162 | break;
|
| 163 | }
|
| 164 | default://"ql_fota_start"
|
| 165 | {
|
| 166 | printf("break\n");
|
| 167 | return 0;
|
| 168 | }
|
| 169 | }
|
| 170 | }
|
| 171 | return 0;
|
| 172 | }
|
| 173 |
|
| 174 |
|
| 175 |
|