blob: 49e69d211a56b48b9949f13a9cf05f614cf8043c [file] [log] [blame]
b.liu68a94c92025-05-24 12:53:41 +08001#include <stdio.h>
2#include <string.h>
3#include <strings.h>
4#include <stdlib.h>
5#include <errno.h>
6#include <fcntl.h>
7#include <signal.h>
8#include <sys/types.h>
9#include <unistd.h>
10#include <pthread.h>
11#include <termios.h>
12#include <time.h>
13#include <sys/ioctl.h>
14#include <dlfcn.h>
15#include <stdint.h>
16#include <stdbool.h>
17
18typedef void (*GSW_PM_WAKEUPCALLBACK)(int32_t wakeup_in);
19
20void tmp_callback(int32_t wakeup_in)
21{
22 printf("wackout value %d\n",wakeup_in);
23}
24
25int32_t (*gsw_autosleep_enable)(void);
26int32_t (*gsw_autosleep_disenable)(void);
27int32_t (*gsw_pm_sdk_init)(GSW_PM_WAKEUPCALLBACK );
28int32_t (*gsw_pm_enter_sleep)(const char *gsw_wakelock_name);
29int32_t (*gsw_pm_exit_sleep)(const char *gsw_wakelock_name);
rx.xiee12806a2025-07-16 06:17:08 -070030int32_t (*gsw_get_modem_reset_reason)(int32_t *reset_reason);
b.liu68a94c92025-05-24 12:53:41 +080031void (*gsw_modem_log_sync)(void);
32
33const char *tmp_name = "pm_test_lock";
b.liu68a94c92025-05-24 12:53:41 +080034void *dlHandle_pm;
35char *lynqLib_pm = "/lib/libgsw_lib.so";
36
rx.xiee12806a2025-07-16 06:17:08 -070037const char *reset_reason_str[] = {
38 "Normal",
39 "Download",
40 "Power Off",
41 "Hardware",
42 "Command",
43 "Abnormal",
44 "Unknown"
45};
46
47void user_help(void) {
b.liu68a94c92025-05-24 12:53:41 +080048 printf("\t1 autosleep_enable\n"
49 "\t2 autosleep_disenable \n"
50 "\t3 pm_sdk_init\n"
51 "\t4 pm_enter_sleep\n"
52 "\t5 pm_exit_sleep\n"
53 "\t6 modem_log_sync\n"
rx.xiee12806a2025-07-16 06:17:08 -070054 "\t7 get_modem_reset_reason\n"
b.liu68a94c92025-05-24 12:53:41 +080055 "please input operator: >> ");
56}
57
58int main(void)
59{
60 int ret;
61 int opt = 0;
rx.xiee12806a2025-07-16 06:17:08 -070062 int32_t reset_reason = 0;
b.liu68a94c92025-05-24 12:53:41 +080063 dlHandle_pm = dlopen(lynqLib_pm, RTLD_NOW);
64 while(1)
65 {
66 printf("=========PM main=========\n");
67 user_help();
68 if (scanf("%d", &opt) != 1)
69 printf("input error,please check it");
70 while(getchar()!='\n');
71 switch (opt)
72 {
73 case 1:
74 {
75 gsw_autosleep_enable=(int32_t(*)())dlsym(dlHandle_pm, "gsw_autosleep_enable");
76 ret = gsw_autosleep_enable();
77 if(ret < 0)
78 {
79 printf("gsw_autosleep_enable FAIL.\n");
80 return -1;
81 }
82 printf("gsw_autosleep_enable success.\n");
83 return 0;
84 }
85 case 2:
86 {
87 gsw_autosleep_disenable=(int32_t(*)())dlsym(dlHandle_pm, "gsw_autosleep_disenable");
88 ret = gsw_autosleep_disenable();
89 if(ret < 0)
90 {
91 printf("gsw_autosleep_disenable FAIL.\n");
92 return -1;
93 }
94 printf("gsw_autosleep_disenable success.\n");
95 return 0;
96 }
97 case 3:
98 {
99 gsw_pm_sdk_init=(int32_t(*)(GSW_PM_WAKEUPCALLBACK ))dlsym(dlHandle_pm, "gsw_pm_sdk_init");
100 ret = gsw_pm_sdk_init(tmp_callback);
101 if(ret < 0)
102 {
103 printf("gsw_pm_sdk_init FAIL.\n");
104 return -1;
105 }
106 printf("gsw_pm_sdk_init success.\n");
107 break;
108 }
109 case 4:
110 {
111 gsw_pm_enter_sleep=(int32_t(*)(const char *gsw_wakelock_name))dlsym(dlHandle_pm, "gsw_pm_enter_sleep");
112 ret = gsw_pm_enter_sleep(tmp_name);
113 if(ret < 0)
114 {
115 printf("gsw_pm_enter_sleep FAIL.\n");
116 return -1;
117 }
118 printf("gsw_pm_enter_sleep success.\n");
119 return 0;
120 }
121 case 5:
122 {
123 gsw_pm_exit_sleep=(int32_t(*)(const char *gsw_wakelock_name))dlsym(dlHandle_pm, "gsw_pm_exit_sleep");
124 ret = gsw_pm_exit_sleep(tmp_name);
125 if(ret < 0)
126 {
127 printf("gsw_pm_exit_sleep FAIL.\n");
128 return -1;
129 }
130 printf("gsw_pm_exit_sleep success.\n");
131 break;
132 }
133 case 6:
134 {
135 gsw_modem_log_sync=(void(*)())dlsym(dlHandle_pm, "gsw_modem_log_sync");
136 gsw_modem_log_sync();
137 printf("gsw_modem_log_sync success.\n");
138 return 0;
139 }
rx.xiee12806a2025-07-16 06:17:08 -0700140 case 7:
141 {
142 gsw_get_modem_reset_reason = (int32_t(*)(int32_t*))dlsym(dlHandle_pm, "gsw_get_modem_reset_reason");
143 if (!gsw_get_modem_reset_reason)
144 {
145 fprintf(stderr, "dlsym error: %s\n", dlerror());
146 break;
147 }
148 ret = gsw_get_modem_reset_reason(&reset_reason);
149
150 if (ret == 0)
151 {
152 const char *reason = "Invalid Reason";
153 if (reset_reason >= 0 && reset_reason <= 6)
154 {
155 reason = reset_reason_str[reset_reason];
156 }
157 printf("Modem reset reason: %d (%s)\n", reset_reason, reason);
158 } else {
159 printf("Failed to get reset reason (error: %d)\n", ret);
160 }
161 break;
162 }
b.liu68a94c92025-05-24 12:53:41 +0800163 }
164 }
165 return 0;
rx.xiee12806a2025-07-16 06:17:08 -0700166}