hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <stdio.h>
#include "update.h"
#include <unistd.h>
#include <string.h>
#include <sys/reboot.h>
#include "download.h"
 
bool update_ok = false;
void handle_upgrade_callback(void *user_data, RK_Upgrade_Status_t status){
    if(status == RK_UPGRADE_FINISHED)
        update_ok = true;
}
 
void handle_upgrade_callback_reboot(void *user_data, RK_Upgrade_Status_t status){
    if(status == RK_UPGRADE_FINISHED){
        update_ok = true;
        reboot(RB_AUTOBOOT);
    }
}
 
int main(int argc, char *argv[]){
    //char url[256] = "http://148.70.52.169:8080/update.img";
    printf("version 1.0.0\n");
    if(argc >= 2){
        if(strcmp(argv[1], "check") == 0){
            if(RK_ota_check_version(argv[2])){
                printf("version check ok, need update..\n");
                return 0;
            }
            else{
                return -1;
            }
        }else if(strcmp(argv[1], "update") == 0){
            if(argc == 3){
                RK_ota_set_url(argv[2]);
                RK_ota_start(handle_upgrade_callback);
                RK_ota_get_progress();
                if(update_ok)
                    return 0;
                else
                    return -1;
            }else if(argc == 4){
                RK_ota_set_url(argv[2]);
                RK_ota_start(handle_upgrade_callback_reboot);
                RK_ota_get_progress();
            }
        }
    }else{
        printf("============useage===============\n");
        printf("1. update_engine check url\n");
        printf("2. update_engine update url\n");
        printf("3. update_engine update url reboot\n");
    }
    return 0;
}