blob: 048861c3bec625bdba007f8934e1bb67ae1c06f5 [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>
rita6ce3aa22022-03-03 06:58:44 -05006//#include "fota_test.h"
xjde81d1d2021-11-25 15:01:52 +08007#include "function_common.h"
xjde81d1d2021-11-25 15:01:52 +08008#include<unistd.h>
9
10#ifdef __cplusplus
11extern "C" {
12#endif
rita6ce3aa22022-03-03 06:58:44 -050013//#include "liblynq-broadcast/broadcast_send.h"
xjde81d1d2021-11-25 15:01:52 +080014#include <gio/gio.h>
15#include <glib.h>
rita6ce3aa22022-03-03 06:58:44 -050016//#include "liblynq-driver/libdriver.h"
xjde81d1d2021-11-25 15:01:52 +080017
18#ifdef __cplusplus
19}
20#endif
21
22#define BUFFER_SIZE 8192
23#define USER_LOG_TAG "FUNCTION_TEST"
24#define MAX_ARGS 5
25typedef enum {
26 API_MENU = 1,
27 DEMO_MENU,
28}TEST_MAIN_ITEM;
29typedef enum{
rita6ce3aa22022-03-03 06:58:44 -050030 API_WIFI=0,
31 API_AUDIO,
xjde81d1d2021-11-25 15:01:52 +080032 API_FOTA,
33} API_MOUDLE;
34
35
xjde81d1d2021-11-25 15:01:52 +080036
37static void getCallback(const char* str_arg, int int_arg )
38{
39 //printf("SignalCallback,str_arg:%s,int_arg:%d\n", str_arg,int_arg);
40 LYVERBLOG("SignalCallback,str_arg:%s,int_arg:%d\n", str_arg,int_arg);
41
42 return;
43}
44
45void hold_on(){
46 char any[5]={ 0 };
47 printf("Press any key to return\n");
48 fgets(any, 5, stdin);
49}
50
51int parse_param(char *cmd, char *argv[], int max_args){
52 char *pos, *pos2;
53 int argc = 0;
54
55 pos = cmd;
56 while (1) {
57 // Trim the space characters.
58 while (*pos == ' ') {
59 pos++;
60 }
61
62 if (*pos == '\0') {
63 break;
64 }
65
66 // One token may start with '"' or other characters.
67 if (*pos == '"' && (pos2 = strchr(pos + 1, '"'))) {
68 argv[argc++] = pos + 1;
69 *pos2 = '\0';
70 pos = pos2 + 1;
71 if (*pos == '\n'){
72 *pos = '\0';
73 pos = pos + 1;
74 }
75 }
76 else {
77 argv[argc++] = pos;
78 while (*pos != '\0' && *pos != ' '&& *pos != '\n')
79 {
80 if (*pos == '"' && (pos2 = strchr(pos + 1, '"')))
81 {
82 pos = pos2 ;
83 }
84 else
85 pos++;
86 }
87 *pos++ = '\0';
88 }
89
90 // Check if the maximum of arguments is reached.
91 if (argc == max_args) {
92 break;
93 }
94 }
95
96 return argc;
97}
98int getRilModule(char *module)
99{
100 if (module==NULL)
101 {
102 //printf("[ERROR] Please input module,and try again!");
103 // LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
104 return -1;
105 }
rita6ce3aa22022-03-03 06:58:44 -0500106 if(!strcmp(module,"WIFI"))
xjde81d1d2021-11-25 15:01:52 +0800107 {
108 return API_WIFI;
109 }
rita6ce3aa22022-03-03 06:58:44 -0500110/*
111 else if(!strcmp(module, "AUDIO"))
xjde81d1d2021-11-25 15:01:52 +0800112 {
113 return API_AUDIO;
114 }
rita6ce3aa22022-03-03 06:58:44 -0500115
xjde81d1d2021-11-25 15:01:52 +0800116 else if(!strcmp(module, "fota"))
117 {
118 return API_FOTA;
119 }
rita6ce3aa22022-03-03 06:58:44 -0500120*/
xjde81d1d2021-11-25 15:01:52 +0800121 else
122 {
123 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
124 // printf("can not find %s API module ",module);
125 return -1;
126 }
127 return -1;
128}
129
130int api_start(int argc, char *argv[]){
131 LYDBGLOG("api_start,argc:%d\n",argc);
132 char *menu[2] = {0};// menu[0] is the "moudle",menu[1] is the "API"
133 char* argvHead=NULL;
134 int module = -1;
135 argvHead = getMenu(argv[2],menu);//find the "module" and the "API"
136 module = getRilModule(menu[0]);
137 // if(argvHead == NULL)
138 // {
139 // printf("pram api error\n");
140 // return 0;
141 // }
142 switch(module)
143 {
xjde81d1d2021-11-25 15:01:52 +0800144 /* Add the code of the owner modules below*/
xjde81d1d2021-11-25 15:01:52 +0800145 case API_AUDIO:
146 {
rita6ce3aa22022-03-03 06:58:44 -0500147 //audio_test(menu[1],argvHead);
xjde81d1d2021-11-25 15:01:52 +0800148 break;
149 }
xjde81d1d2021-11-25 15:01:52 +0800150
rita6ce3aa22022-03-03 06:58:44 -0500151 case API_FOTA:
152 {
153 //fota_test(menu[1],argvHead);
154 break;
155 }
xjde81d1d2021-11-25 15:01:52 +0800156 case API_WIFI:
xjde81d1d2021-11-25 15:01:52 +0800157 break;
158 default:
159 // printf("pram module error\n");
160 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
161
162 break;
163 }
164 // hold_on(); //add by zhouqunchao delete help message
165 return 1;
166}
167
168int function_start(int argc, char *argv[])
169{
170 int select_menu = atoi(argv[0]);
171 int thread = atoi(argv[1]);
172 // printf("select_menu:%d,thread:%d\n",select_menu,thread);
173 switch(select_menu)
174 {
175 case API_MENU:
176 {
177 if (thread == 1)//rita add @2021.6.21 for threadhandle test
178 {
179 LYDBGLOG("[%s-%d] argv[2] = [%s]\n", __FUNCTION__, __LINE__, argv[2]);
180 if(strlen(argv[2])){//rita add @2021.6.21 for data error
181 LYDBGLOG("[%s-%d] argv[2] = [%s]\n", __FUNCTION__, __LINE__, argv[2]);
rita6ce3aa22022-03-03 06:58:44 -0500182 //send_broadcast_by_name("function", strlen(argv[2]), argv[2]);
xjde81d1d2021-11-25 15:01:52 +0800183 }
184 else{
185 LYVERBLOG("+[thhandle]: error num = %d\n", INVALID_CMD);
186 return INVALID_CMD;
187 }
188 }
189 else if(thread ==2){//rita add @2021.6.21 for local test
190 api_start(argc,argv);
191 }
192 else{
193 //printf("thread 1,local 2\n");
194 LYDBGLOG("thread 1,local 2\n");
195 }
196 break;
197 }
198 case DEMO_MENU:
199 {
200 //printf("DEMO_MENU\n");
201 LYDBGLOG("DEMO_MENU\n");
202 break;
203 }
204 default:
205 break;
206 }
207 return 0;
208}
209
210
211void help_display(){
212 printf("\n");
213 printf("*****************************************************************************\n");
214 printf("0:help ------- help\n");
215 printf("*****************************************************************************\n");
216 printf("1:API TEST\n" );
217 printf(" 1-1:Async api-\n" );
218 printf(" --MQTT\n" );
219 printf("\n");
220 printf(" --HTTP\n" );
221 printf(" 1-2:Sync api-\n" );
222 printf(" --GPIO\n" );
223 printf("\n");
224 printf(" --RIL\n" );
225 printf("\n");
226 printf(" --WIFI\n" );
227 printf("\n");
228 printf(" --GNSS\n" );
229 printf("\n");
230 printf(" --SERVICE\n" );
231 printf("*****************************************************************************\n");
232 printf("2:DEMO TEST:Subsequent updates\n" );
233 printf("*****************************************************************************\n");
234 printf("\n");
235 printf("1:API TEST The format is as follows :\n" );
236 printf("{menu}-{mode selection} moudle=\"{moudle}\"&API=\"{api interface}\"&session=\"{session id}\"\"&parameterA=\"{parameter A}\"\n" );
237 /*
238 printf("The main parameters are as follows:\n");
239 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
240 printf("menu:1--API TEST,2--DEMO TEST\n" );
241 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
242 printf("mode selection:1--async api,2--sync api\n" );
243 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
244 printf("moudle:Test module--includes the following modules\n" );
245 printf("RIL, GPIO,MQTT,HTTP,WIFI,GNSS\n" );
246 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
247 printf("api interface:--Interface corresponding to module\n" );
248 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
249 printf("session id:--Used to distinguish different session groups of the same module\n" );
250 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
251 printf("parameter A:--API parameter,Add format {\"&parameter_name=\"{parameter}\"} \n" );
252 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
253 */
254 printf("Select menu:\n");
255}
256void menu_display(){
257 printf("\n");
258 printf("**********************\n");
259 printf("0:help menu\n");
260 printf("1:API TEST\n");
261 printf("2:DEMO TEST\n");
262 printf("**********************\n");
263 printf("\n");
264 printf("Select menu:\n");
265}
266int main()
267{
xjde81d1d2021-11-25 15:01:52 +0800268 LYLOGEINIT(USER_LOG_TAG);
rita6ce3aa22022-03-03 06:58:44 -0500269 // LYLOGSET(4);
xjde81d1d2021-11-25 15:01:52 +0800270
271 /*Check whether the modem works correctly and start the corresponding service*/ //add by liulei
272 char buf[1024]={0};
xjde81d1d2021-11-25 15:01:52 +0800273
274 while (1) {
275 char *argv[MAX_ARGS];
276 char str[BUFFER_SIZE]={ 0 };
277 menu_display();
278 fgets(str, BUFFER_SIZE, stdin);
279 LYDBGLOG("[%s-%d] str= [%s]\n", __FUNCTION__, __LINE__, str);
280 str[strlen(str)-1]='\0';
281 if(!strcmp(str, "0")){
282 help_display();
283 //hold_on(); //add by zhouqunchao delete help message
284 continue;
285 }
286 if(!strcmp(str,"quit"))
287 {
288 //system("killall lynq-framework-service");
289 break;
290 }
291 if ((strncmp(str,"1-",2) == 0)||
292 (strncmp(str,"2-",2)== 0))
293 {
294 char* at_cmd = strstr(str, "-");
295 strncpy(at_cmd, " ", 1);
296 LYDBGLOG("[%s-%d] at_cmd = [%s]\n", __FUNCTION__, __LINE__, at_cmd);
297
298
299 int argc = parse_param(str, argv, MAX_ARGS);
300 //add by zqc Format error judgment start
301 if(argv[2] == NULL)
302 {
303 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
304 continue;
305 }
306 //add by zqc Format error judgment end
307 function_start(argc,argv);
308 continue;
309 }
310 else{
311 // printf("pram error\n");
312 LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR);
313 continue;
314 }
315 }
316return 0;
317}
318