| #include <stdio.h> | |
| #include <string.h> | |
| #include <strings.h> | |
| #include <stdlib.h> | |
| #include <errno.h> | |
| #include <fcntl.h> | |
| #include <signal.h> | |
| #include <sys/types.h> | |
| #include <unistd.h> | |
| #include <pthread.h> | |
| #include <termios.h> | |
| #include <time.h> | |
| #include <sys/ioctl.h> | |
| #include <dlfcn.h> | |
| #include <stdint.h> | |
| #include <stdbool.h> | |
| typedef void (*GSW_PM_WAKEUPCALLBACK)(int32_t wakeup_in); | |
| void tmp_callback(int32_t wakeup_in) | |
| { | |
| printf("wackout value %d\n",wakeup_in); | |
| } | |
| int32_t (*gsw_autosleep_enable)(void); | |
| int32_t (*gsw_autosleep_disenable)(void); | |
| int32_t (*gsw_pm_sdk_init)(GSW_PM_WAKEUPCALLBACK ); | |
| int32_t (*gsw_pm_enter_sleep)(const char *gsw_wakelock_name); | |
| int32_t (*gsw_pm_exit_sleep)(const char *gsw_wakelock_name); | |
| int32_t (*gsw_get_modem_reset_reason)(int32_t *reset_reason); | |
| void (*gsw_modem_log_sync)(void); | |
| const char *tmp_name = "pm_test_lock"; | |
| void *dlHandle_pm; | |
| char *lynqLib_pm = "/lib/libgsw_lib.so"; | |
| const char *reset_reason_str[] = { | |
| "Normal", | |
| "Download", | |
| "Power Off", | |
| "Hardware", | |
| "Command", | |
| "Abnormal", | |
| "Unknown" | |
| }; | |
| void user_help(void) { | |
| printf("\t1 autosleep_enable\n" | |
| "\t2 autosleep_disenable \n" | |
| "\t3 pm_sdk_init\n" | |
| "\t4 pm_enter_sleep\n" | |
| "\t5 pm_exit_sleep\n" | |
| "\t6 modem_log_sync\n" | |
| "\t7 get_modem_reset_reason\n" | |
| "please input operator: >> "); | |
| } | |
| int main(void) | |
| { | |
| int ret; | |
| int opt = 0; | |
| int32_t reset_reason = 0; | |
| dlHandle_pm = dlopen(lynqLib_pm, RTLD_NOW); | |
| while(1) | |
| { | |
| printf("=========PM main=========\n"); | |
| user_help(); | |
| if (scanf("%d", &opt) != 1) | |
| printf("input error,please check it"); | |
| while(getchar()!='\n'); | |
| switch (opt) | |
| { | |
| case 1: | |
| { | |
| gsw_autosleep_enable=(int32_t(*)())dlsym(dlHandle_pm, "gsw_autosleep_enable"); | |
| ret = gsw_autosleep_enable(); | |
| if(ret < 0) | |
| { | |
| printf("gsw_autosleep_enable FAIL.\n"); | |
| return -1; | |
| } | |
| printf("gsw_autosleep_enable success.\n"); | |
| return 0; | |
| } | |
| case 2: | |
| { | |
| gsw_autosleep_disenable=(int32_t(*)())dlsym(dlHandle_pm, "gsw_autosleep_disenable"); | |
| ret = gsw_autosleep_disenable(); | |
| if(ret < 0) | |
| { | |
| printf("gsw_autosleep_disenable FAIL.\n"); | |
| return -1; | |
| } | |
| printf("gsw_autosleep_disenable success.\n"); | |
| return 0; | |
| } | |
| case 3: | |
| { | |
| gsw_pm_sdk_init=(int32_t(*)(GSW_PM_WAKEUPCALLBACK ))dlsym(dlHandle_pm, "gsw_pm_sdk_init"); | |
| ret = gsw_pm_sdk_init(tmp_callback); | |
| if(ret < 0) | |
| { | |
| printf("gsw_pm_sdk_init FAIL.\n"); | |
| return -1; | |
| } | |
| printf("gsw_pm_sdk_init success.\n"); | |
| break; | |
| } | |
| case 4: | |
| { | |
| gsw_pm_enter_sleep=(int32_t(*)(const char *gsw_wakelock_name))dlsym(dlHandle_pm, "gsw_pm_enter_sleep"); | |
| ret = gsw_pm_enter_sleep(tmp_name); | |
| if(ret < 0) | |
| { | |
| printf("gsw_pm_enter_sleep FAIL.\n"); | |
| return -1; | |
| } | |
| printf("gsw_pm_enter_sleep success.\n"); | |
| return 0; | |
| } | |
| case 5: | |
| { | |
| gsw_pm_exit_sleep=(int32_t(*)(const char *gsw_wakelock_name))dlsym(dlHandle_pm, "gsw_pm_exit_sleep"); | |
| ret = gsw_pm_exit_sleep(tmp_name); | |
| if(ret < 0) | |
| { | |
| printf("gsw_pm_exit_sleep FAIL.\n"); | |
| return -1; | |
| } | |
| printf("gsw_pm_exit_sleep success.\n"); | |
| break; | |
| } | |
| case 6: | |
| { | |
| gsw_modem_log_sync=(void(*)())dlsym(dlHandle_pm, "gsw_modem_log_sync"); | |
| gsw_modem_log_sync(); | |
| printf("gsw_modem_log_sync success.\n"); | |
| return 0; | |
| } | |
| case 7: | |
| { | |
| gsw_get_modem_reset_reason = (int32_t(*)(int32_t*))dlsym(dlHandle_pm, "gsw_get_modem_reset_reason"); | |
| if (!gsw_get_modem_reset_reason) | |
| { | |
| fprintf(stderr, "dlsym error: %s\n", dlerror()); | |
| break; | |
| } | |
| ret = gsw_get_modem_reset_reason(&reset_reason); | |
| if (ret == 0) | |
| { | |
| const char *reason = "Invalid Reason"; | |
| if (reset_reason >= 0 && reset_reason <= 6) | |
| { | |
| reason = reset_reason_str[reset_reason]; | |
| } | |
| printf("Modem reset reason: %d (%s)\n", reset_reason, reason); | |
| } else { | |
| printf("Failed to get reset reason (error: %d)\n", ret); | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| return 0; | |
| } |