lh | e3922f9 | 2024-11-05 02:40:56 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <unistd.h> |
| 3 | #include <dlfcn.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <stdint.h> |
| 6 | #include <string.h> |
| 7 | #include "lynq_sdk_ready.h" |
| 8 | |
| 9 | int (*sdk_ready_register)(const int uToken,const lynq_sdk_check_param_t* param,lynq_sdk_status_cb sdk_status_cb); |
| 10 | int (*get_sdk_ready_status)(int *status); |
| 11 | |
| 12 | |
| 13 | int demo_sdk_status_cb(const lynq_sdk_ready_t *sdk_ready, void *reserve) |
| 14 | { |
| 15 | printf("sdk_ready_status:%d,ref_action:%d\n",sdk_ready->sdk_ready_status,sdk_ready->ref_action); |
| 16 | return 0; |
| 17 | } |
| 18 | |
| 19 | void help() |
| 20 | { |
| 21 | printf("help:\n\ |
| 22 | argv[1]:isvalid(0/1)\n\ |
| 23 | argv[2]:boot\n\ |
| 24 | argv[3]:GNSS-MIN:60\n\ |
| 25 | argv[4]:MD-MIN:30\n\ |
| 26 | argv[5]:PTN-MIN:120\n\ |
| 27 | argv[6]:RIL-MIN:10\n\ |
| 28 | argv[7]:SYS-MIN:120\n\ |
| 29 | argv[8]:INTR\n\ |
| 30 | argv[9]:LOAD_AVG\n"); |
| 31 | return; |
| 32 | } |
| 33 | void print_binary(int num) { |
| 34 | int i; |
| 35 | for (i = sizeof(num) * 8 - 1; i >= 0; i--) { |
| 36 | printf("%d", (num >> i) & 1); |
| 37 | } |
| 38 | printf("\n"); |
| 39 | } |
| 40 | int main(int argc, char **argv) |
| 41 | { |
| 42 | printf("lynq-sdk-ready begin"); |
| 43 | lynq_sdk_check_param_t param; |
| 44 | void *dlHandle; |
| 45 | int bit_sdk_ready_status = 0; |
| 46 | memset(¶m,0,sizeof(lynq_sdk_check_param_t)); |
| 47 | const char *lynqLibPath = "/lib64/liblynq-sdk-ready.so"; |
| 48 | dlHandle = dlopen(lynqLibPath, RTLD_NOW); |
| 49 | if (dlHandle == NULL) |
| 50 | { |
| 51 | printf("dlopen dlHandle_call failed: %s", dlerror()); |
| 52 | exit(EXIT_FAILURE); |
| 53 | } |
| 54 | sdk_ready_register = (int(*)(const int uToken,const lynq_sdk_check_param_t* param,lynq_sdk_status_cb sdk_status_cb))dlsym(dlHandle, "lynq_sdk_ready_register"); |
| 55 | if (sdk_ready_register == NULL) { |
| 56 | printf("lynq_init_call not defined or exported in %s", lynqLibPath); |
| 57 | exit(EXIT_FAILURE); |
| 58 | } |
| 59 | get_sdk_ready_status = (int(*)(int *status))dlsym(dlHandle, "lynq_get_sdk_ready_status"); |
| 60 | if (get_sdk_ready_status == NULL) { |
| 61 | printf("lynq_init_call not defined or exported in %s", lynqLibPath); |
| 62 | exit(EXIT_FAILURE); |
| 63 | } |
| 64 | help(); |
| 65 | if(argc >= 2) |
| 66 | { |
| 67 | if(atoi(argv[1])==1 && argc >=10) |
| 68 | { |
| 69 | param.isvalid = atoi(argv[1]); |
| 70 | param.period.BOOT = atoi(argv[2]); |
| 71 | param.period.GNSS = atoi(argv[3]); |
| 72 | param.period.MD = atoi(argv[4]); |
| 73 | param.period.PTN = atoi(argv[5]); |
| 74 | param.period.RIL = atoi(argv[6]); |
| 75 | param.period.SYS = atoi(argv[7]); |
| 76 | param.threshold.interrupts = atoi(argv[8]); |
| 77 | param.threshold.load_average = atoi(argv[9]); |
| 78 | } |
| 79 | } |
| 80 | printf("You input param:\n\ |
| 81 | param.isvalid:%d\n\ |
| 82 | param.period.BOOT:%d\n\ |
| 83 | param.period.GNSS:%d\n\ |
| 84 | param.period.MD:%d\n\ |
| 85 | param.period.PTN:%d\n\ |
| 86 | param.period.RIL:%d\n\ |
| 87 | param.period.SYS:%d\n\ |
| 88 | param.threshold.interrupts:%llu\n\ |
| 89 | param.threshold.load_average:%d\n",param.isvalid, |
| 90 | param.period.BOOT, |
| 91 | param.period.GNSS, |
| 92 | param.period.MD, |
| 93 | param.period.PTN, |
| 94 | param.period.RIL, |
| 95 | param.period.SYS, |
| 96 | param.threshold.interrupts, |
| 97 | param.threshold.load_average); |
| 98 | sdk_ready_register(1024,¶m,demo_sdk_status_cb); |
| 99 | while (1) |
| 100 | { |
| 101 | sleep(30); |
| 102 | get_sdk_ready_status(&bit_sdk_ready_status);//需要的时候调用,不是必选项 |
| 103 | print_binary(bit_sdk_ready_status); |
| 104 | } |
| 105 | return 0; |
| 106 | } |