blob: f490c22cf04933e4c2d063a9937525798a59cc71 [file] [log] [blame]
xjde81d1d2021-11-25 15:01:52 +08001
2/* gets example */
3#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6#include <libtel/lib_tele.h>
7#include "ril_test.h"
8#include "gpio_test.h"
9#include "fota_test.h"
10#include "audio_test.h"
11#include "system_test.h"
12//#include "service_test.h"
13#include "function_common.h"
14//#include "conti_plugin_test.h"
15//#include "exception_multicast.h"
16
17
18#include<unistd.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23#include "liblynq-broadcast/broadcast_send.h"
24#include <gio/gio.h>
25#include <glib.h>
26#include "liblynq-driver/libdriver.h"
27
28#ifdef __cplusplus
29}
30#endif
31
32#define BUFFER_SIZE 8192
33#define USER_LOG_TAG "FUNCTION_TEST"
34#define MAX_ARGS 5
35typedef enum {
36 API_MENU = 1,
37 DEMO_MENU,
38}TEST_MAIN_ITEM;
39typedef enum{
40 API_RIL=0,
41 API_GPIO,
42 API_MQTT,
43 API_HTTP,
44 API_WIFI,
45 API_GNSS,
46 API_SERVICE,
47 API_AUDIO,
48 API_DHCP,
49 API_SYSTEM,
50 API_FOTA,
51} API_MOUDLE;
52
53
54void lynq_incoming_call_cb(RIL_SOCKET_ID soc_id,int index, char * addr, RIL_CallState state, int toa)
55{
56 // printf("[SIM%d]index is %d,addr is %s,state is %d,toa is %d\n",soc_id,index,addr,state,toa);
57 LYVERBLOG("[SIM%d]index is %d,addr is %s,state is %d,toa is %d\n",soc_id,index,addr,state,toa);
58}
59
60void lynq_recive_new_sms_cb(RIL_SOCKET_ID soc_id,char * num, char * smsc, char * msg, int charset)
61{
62 // printf("[SIM%d]num is %s,smsc is %s,msg is %s,charset is %d\n",soc_id,num,smsc,msg,charset);
63 LYVERBLOG("[SIM%d]num is %s,smsc is %s,msg is %s,charset is %d\n",soc_id,num,smsc,msg,charset);
64}
65
66static user_cb mytest={
67 lynq_recive_new_sms_cb,
68 lynq_incoming_call_cb
69};
70
71
72static void getCallback(const char* str_arg, int int_arg )
73{
74 //printf("SignalCallback,str_arg:%s,int_arg:%d\n", str_arg,int_arg);
75 LYVERBLOG("SignalCallback,str_arg:%s,int_arg:%d\n", str_arg,int_arg);
76
77 return;
78}
79
80void hold_on(){
81 char any[5]={ 0 };
82 printf("Press any key to return\n");
83 fgets(any, 5, stdin);
84}
85
86int parse_param(char *cmd, char *argv[], int max_args){
87 char *pos, *pos2;
88 int argc = 0;
89
90 pos = cmd;
91 while (1) {
92 // Trim the space characters.
93 while (*pos == ' ') {
94 pos++;
95 }
96
97 if (*pos == '\0') {
98 break;
99 }
100
101 // One token may start with '"' or other characters.
102 if (*pos == '"' && (pos2 = strchr(pos + 1, '"'))) {
103 argv[argc++] = pos + 1;
104 *pos2 = '\0';
105 pos = pos2 + 1;
106 if (*pos == '\n'){
107 *pos = '\0';
108 pos = pos + 1;
109 }
110 }
111 else {
112 argv[argc++] = pos;
113 while (*pos != '\0' && *pos != ' '&& *pos != '\n')
114 {
115 if (*pos == '"' && (pos2 = strchr(pos + 1, '"')))
116 {
117 pos = pos2 ;
118 }
119 else
120 pos++;
121 }
122 *pos++ = '\0';
123 }
124
125 // Check if the maximum of arguments is reached.
126 if (argc == max_args) {
127 break;
128 }
129 }
130
131 return argc;
132}
133int getRilModule(char *module)
134{
135 if (module==NULL)
136 {
137 //printf("[ERROR] Please input module,and try again!");
138 // LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
139 return -1;
140 }
141 if(!strcmp(module,"ril"))
142 {
143 return API_RIL;
144 }
145 else if(!strcmp(module,"gpio"))
146 {
147 return API_GPIO;
148 }
149 else if(!strcmp(module,"MQTT"))
150 {
151 return API_MQTT;
152 }
153 else if(!strcmp(module,"HTTP"))
154 {
155 return API_HTTP;
156 }
157 else if(!strcmp(module,"WIFI"))
158 {
159 return API_WIFI;
160 }
161 else if(!strcmp(module,"GNSS"))
162 {
163 return API_GNSS;
164 }
165 // else if(!strcmp(module, "SERVICE"))
166 // {
167 // return API_SERVICE;
168 // }
169 else if(!strcmp(module, "AUDIO"))
170 {
171 return API_AUDIO;
172 }
173 else if(!strcmp(module,"DHCP"))
174 {
175 return API_DHCP;
176 }
177 else if(!strcmp(module,"SYSTEM"))
178 {
179 return API_SYSTEM;
180 }
181 else if(!strcmp(module, "fota"))
182 {
183 return API_FOTA;
184 }
185 else
186 {
187 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
188 // printf("can not find %s API module ",module);
189 return -1;
190 }
191 return -1;
192}
193
194int api_start(int argc, char *argv[]){
195 LYDBGLOG("api_start,argc:%d\n",argc);
196 char *menu[2] = {0};// menu[0] is the "moudle",menu[1] is the "API"
197 char* argvHead=NULL;
198 int module = -1;
199 argvHead = getMenu(argv[2],menu);//find the "module" and the "API"
200 module = getRilModule(menu[0]);
201 // if(argvHead == NULL)
202 // {
203 // printf("pram api error\n");
204 // return 0;
205 // }
206 switch(module)
207 {
208 case API_RIL:
209 {
210 if(argvHead)
211 {
212 ril_test(menu[1],argvHead);
213 break;
214 }
215 }
216 /* Add the code of the owner modules below*/
217 case API_GPIO:
218 {
219 gpio_test(menu[1],argvHead);
220 break;
221 }
222 // case API_SERVICE:
223 // {
224 // service_test(menu[1],argvHead);
225 // break;
226 // }
227 case API_AUDIO:
228 {
229 audio_test(menu[1],argvHead);
230 break;
231 }
232 case API_DHCP:
233 {
234 //dhcp_test(menu[1],argvHead);
235 break;
236 }
237 case API_SYSTEM:
238 {
239 system_test(menu[1],argvHead);
240 break;
241 }
242 case API_FOTA:
243 {
244 fota_test(menu[1],argvHead);
245 break;
246 }
247
248 case API_MQTT:
249 case API_HTTP:
250 case API_WIFI:
251 case API_GNSS:
252 break;
253 default:
254 // printf("pram module error\n");
255 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
256
257 break;
258 }
259 // hold_on(); //add by zhouqunchao delete help message
260 return 1;
261}
262
263int function_start(int argc, char *argv[])
264{
265 int select_menu = atoi(argv[0]);
266 int thread = atoi(argv[1]);
267 // printf("select_menu:%d,thread:%d\n",select_menu,thread);
268 switch(select_menu)
269 {
270 case API_MENU:
271 {
272 if (thread == 1)//rita add @2021.6.21 for threadhandle test
273 {
274 LYDBGLOG("[%s-%d] argv[2] = [%s]\n", __FUNCTION__, __LINE__, argv[2]);
275 if(strlen(argv[2])){//rita add @2021.6.21 for data error
276 LYDBGLOG("[%s-%d] argv[2] = [%s]\n", __FUNCTION__, __LINE__, argv[2]);
277 send_broadcast_by_name("function", strlen(argv[2]), argv[2]);
278 }
279 else{
280 LYVERBLOG("+[thhandle]: error num = %d\n", INVALID_CMD);
281 return INVALID_CMD;
282 }
283 }
284 else if(thread ==2){//rita add @2021.6.21 for local test
285 api_start(argc,argv);
286 }
287 else{
288 //printf("thread 1,local 2\n");
289 LYDBGLOG("thread 1,local 2\n");
290 }
291 break;
292 }
293 case DEMO_MENU:
294 {
295 //printf("DEMO_MENU\n");
296 LYDBGLOG("DEMO_MENU\n");
297 break;
298 }
299 default:
300 break;
301 }
302 return 0;
303}
304
305
306void help_display(){
307 printf("\n");
308 printf("*****************************************************************************\n");
309 printf("0:help ------- help\n");
310 printf("*****************************************************************************\n");
311 printf("1:API TEST\n" );
312 printf(" 1-1:Async api-\n" );
313 printf(" --MQTT\n" );
314 printf("\n");
315 printf(" --HTTP\n" );
316 printf(" 1-2:Sync api-\n" );
317 printf(" --GPIO\n" );
318 printf("\n");
319 printf(" --RIL\n" );
320 printf("\n");
321 printf(" --WIFI\n" );
322 printf("\n");
323 printf(" --GNSS\n" );
324 printf("\n");
325 printf(" --SERVICE\n" );
326 printf("*****************************************************************************\n");
327 printf("2:DEMO TEST:Subsequent updates\n" );
328 printf("*****************************************************************************\n");
329 printf("\n");
330 printf("1:API TEST The format is as follows :\n" );
331 printf("{menu}-{mode selection} moudle=\"{moudle}\"&API=\"{api interface}\"&session=\"{session id}\"\"&parameterA=\"{parameter A}\"\n" );
332 /*
333 printf("The main parameters are as follows:\n");
334 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
335 printf("menu:1--API TEST,2--DEMO TEST\n" );
336 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
337 printf("mode selection:1--async api,2--sync api\n" );
338 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
339 printf("moudle:Test module--includes the following modules\n" );
340 printf("RIL, GPIO,MQTT,HTTP,WIFI,GNSS\n" );
341 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
342 printf("api interface:--Interface corresponding to module\n" );
343 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
344 printf("session id:--Used to distinguish different session groups of the same module\n" );
345 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
346 printf("parameter A:--API parameter,Add format {\"&parameter_name=\"{parameter}\"} \n" );
347 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
348 */
349 printf("Select menu:\n");
350}
351void menu_display(){
352 printf("\n");
353 printf("**********************\n");
354 printf("0:help menu\n");
355 printf("1:API TEST\n");
356 printf("2:DEMO TEST\n");
357 printf("**********************\n");
358 printf("\n");
359 printf("Select menu:\n");
360}
361int main()
362{
363
364 LYLOGEINIT(USER_LOG_TAG);
365 LYLOGSET(4);
366 registerTriggerCallback(getCallback);
367 register_key_info();
368 lynqRegisterUnsolicitedResponse(&mytest);
369
370 /*Check whether the modem works correctly and start the corresponding service*/ //add by liulei
371 char buf[1024]={0};
372 int fd[2];
373 int backfd;
374 pipe(fd);
375 backfd=dup(STDOUT_FILENO);//备份标准输出,用于恢复
376 dup2(fd[1],STDOUT_FILENO); //将标准输出重定向到fd[1]
377 system("cat /sys/kernel/ccci/boot");
378 read(fd[0],buf,1024);
379 dup2(backfd,STDOUT_FILENO); //恢复标准输出
380 LYVERBLOG("this is a test :\n%s",buf); //上面不恢复,则此处的执行结果无法再屏幕上打印
381 if(!strncmp(buf, "md1:4", 5)){
382 lynq_ril_init();
383 }
384 else{
385 printf("\033[40;31mmodem go wrong, May cause problems with your subsequent use of the service\033[0m\n");
386 printf("\033[40;31mmodem go wrong, May cause problems with your subsequent use of the service\033[0m\n");
387 printf("\033[40;31mmodem go wrong, May cause problems with your subsequent use of the service\033[0m\n");
388 }
389 /*Check whether the modem works correctly and start the corresponding service*/
390 sleep_with_restart(1);
391 register_broadcast_send();
392
393 while (1) {
394 char *argv[MAX_ARGS];
395 char str[BUFFER_SIZE]={ 0 };
396 menu_display();
397 fgets(str, BUFFER_SIZE, stdin);
398 LYDBGLOG("[%s-%d] str= [%s]\n", __FUNCTION__, __LINE__, str);
399 str[strlen(str)-1]='\0';
400 if(!strcmp(str, "0")){
401 help_display();
402 //hold_on(); //add by zhouqunchao delete help message
403 continue;
404 }
405 if(!strcmp(str,"quit"))
406 {
407 //system("killall lynq-framework-service");
408 break;
409 }
410 if ((strncmp(str,"1-",2) == 0)||
411 (strncmp(str,"2-",2)== 0))
412 {
413 char* at_cmd = strstr(str, "-");
414 strncpy(at_cmd, " ", 1);
415 LYDBGLOG("[%s-%d] at_cmd = [%s]\n", __FUNCTION__, __LINE__, at_cmd);
416
417
418 int argc = parse_param(str, argv, MAX_ARGS);
419 //add by zqc Format error judgment start
420 if(argv[2] == NULL)
421 {
422 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
423 continue;
424 }
425 //add by zqc Format error judgment end
426 function_start(argc,argv);
427 continue;
428 }
429 else{
430 // printf("pram error\n");
431 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
432 continue;
433 }
434 }
435return 0;
436}
437