b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 1 | #include <stdlib.h>
|
| 2 | #include <stdio.h>
|
| 3 | #include <string.h>
|
| 4 | #include <sys/types.h>
|
| 5 | #include <unistd.h>
|
| 6 | #include <dlfcn.h>
|
| 7 | #include <stdint.h>
|
| 8 | #include <pthread.h>
|
| 9 |
|
| 10 | int (*lynq_get_upgrade_status)(void);
|
| 11 | int (*lynq_fota_set_addr_value)(char *value,int size);
|
| 12 | int (*lynq_fota_nrestart)(void);
|
| 13 | int (*lynq_rock_main)(int first_run);
|
| 14 | int (*lynq_read_process)(void);
|
| 15 | void *dlHandle_fota = NULL;
|
| 16 |
|
| 17 | void *thread_function_noreboot(void *arg)
|
| 18 | {
|
| 19 |
|
| 20 | lynq_fota_nrestart();
|
| 21 | return NULL;
|
| 22 | }
|
| 23 |
|
| 24 | void *thread_function_reboot(void *arg)
|
| 25 | {
|
| 26 |
|
| 27 | lynq_rock_main(1);
|
| 28 | return NULL;
|
| 29 | }
|
| 30 |
|
| 31 |
|
| 32 | int main(int argc,char *argv[])
|
| 33 | {
|
| 34 | int ret = 0;
|
| 35 | int reboot_flag;
|
| 36 | char *value = argv[1];
|
| 37 | printf("Enter main function\n");
|
| 38 |
|
| 39 | const char *lynqLibPath_fota = "/lib/liblynq-fota.so";
|
| 40 | dlHandle_fota = dlopen(lynqLibPath_fota, RTLD_NOW);
|
| 41 | if (dlHandle_fota == NULL)
|
| 42 | {
|
| 43 | printf("dlopen dlHandle_fota failed: %s\n", dlerror());
|
| 44 | return -1;
|
| 45 | }
|
| 46 |
|
| 47 | lynq_fota_set_addr_value = (int (*)(char *value,int size))dlsym(dlHandle_fota, "lynq_fota_set_addr_value");
|
| 48 | if(lynq_fota_set_addr_value == NULL)
|
| 49 | {
|
| 50 | printf("lynq fota ser addr value is null\n");
|
| 51 | return -1;
|
| 52 | }
|
| 53 |
|
| 54 | lynq_get_upgrade_status = (int (*)(void))dlsym(dlHandle_fota,"lynq_get_upgrade_status");
|
| 55 | if(lynq_get_upgrade_status == NULL)
|
| 56 | {
|
| 57 | printf("lynq_get_upgrade_status is null\n");
|
| 58 | return -1;
|
| 59 | }
|
| 60 | lynq_fota_nrestart = (int (*)())dlsym(dlHandle_fota,"lynq_fota_nrestart");
|
| 61 | if(lynq_fota_nrestart == NULL)
|
| 62 | {
|
| 63 | printf("lynq_fota_nrestart is null\n");
|
| 64 | return -1;
|
| 65 | }
|
| 66 | lynq_rock_main = (int (*)(int first_run))dlsym(dlHandle_fota,"lynq_rock_main");
|
| 67 | if(lynq_rock_main == NULL)
|
| 68 | {
|
| 69 | printf("lynq_rock_main is null\n");
|
| 70 | return -1;
|
| 71 | }
|
| 72 |
|
| 73 | lynq_read_process = (int (*)(void))dlsym(dlHandle_fota,"lynq_read_process");
|
| 74 | if(lynq_read_process == NULL)
|
| 75 | {
|
| 76 | printf("lynq_read_process is null\n");
|
| 77 | return -1;
|
| 78 | }
|
| 79 |
|
| 80 | ret = lynq_fota_set_addr_value(value,(int )strlen(value));
|
| 81 | if(ret != 0)
|
| 82 | {
|
| 83 | printf("set upgrade package addr failed\n");
|
| 84 | return -1;
|
| 85 | }
|
| 86 | while(1)
|
| 87 | {
|
| 88 | printf("Please chose action 0: upgrade done ,not reboot 1: upgrade done ,reboot 2:get upgrade status 3:read fota process \n");
|
| 89 | scanf("%d",&reboot_flag);
|
| 90 |
|
| 91 | switch(reboot_flag)
|
| 92 | {
|
| 93 | case 0:
|
| 94 | {
|
| 95 | pthread_t thread_id_noreboot;
|
| 96 | int result = pthread_create(&thread_id_noreboot, NULL, thread_function_noreboot, NULL);
|
| 97 | if (result != 0)
|
| 98 | {
|
| 99 | printf("pthread_create failed \n");
|
| 100 | return -1;;
|
| 101 | }
|
| 102 | }
|
| 103 | break;
|
| 104 |
|
| 105 | case 1:
|
| 106 | {
|
| 107 | pthread_t thread_id_reboot;
|
| 108 | int result = pthread_create(&thread_id_reboot, NULL, thread_function_reboot, NULL);
|
| 109 | if (result != 0)
|
| 110 | {
|
| 111 | printf("pthread_create failed \n");
|
| 112 | return -1;;
|
| 113 | }
|
| 114 | }
|
| 115 | break;
|
| 116 | case 2:
|
| 117 | printf("Get fota upgrade status \n");
|
| 118 | ret = lynq_get_upgrade_status();
|
| 119 | printf("lynq_get_upgrade_status ret is %d\n",ret);
|
| 120 | break;
|
| 121 | case 3:
|
| 122 | printf("get fota upgrade process\n");
|
| 123 | ret = lynq_read_process();
|
| 124 | printf("Now upgrade process is %d\n",ret);
|
| 125 | break;
|
| 126 | default:
|
| 127 | printf("please input right flag 0 or 1 or 2 or 3\n");
|
| 128 | break;
|
| 129 |
|
| 130 | }
|
| 131 |
|
| 132 | }
|
| 133 | return 0;
|
| 134 |
|
| 135 | }
|
| 136 |
|