xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | |
| 2 | /* gets example */ |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <stdlib.h> |
tao.liu | 651bab6 | 2022-03-09 04:03:39 -0500 | [diff] [blame] | 6 | #include "fota_test.h" |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 7 | #include "function_common.h" |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 8 | #include<unistd.h> |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 13 | //#include "liblynq-broadcast/broadcast_send.h" |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 14 | #include <gio/gio.h> |
| 15 | #include <glib.h> |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 16 | //#include "liblynq-driver/libdriver.h" |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 17 | |
| 18 | #ifdef __cplusplus |
| 19 | } |
| 20 | #endif |
| 21 | |
| 22 | #define BUFFER_SIZE 8192 |
| 23 | #define USER_LOG_TAG "FUNCTION_TEST" |
| 24 | #define MAX_ARGS 5 |
| 25 | typedef enum { |
| 26 | API_MENU = 1, |
| 27 | DEMO_MENU, |
| 28 | }TEST_MAIN_ITEM; |
| 29 | typedef enum{ |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 30 | API_WIFI=0, |
| 31 | API_AUDIO, |
tao.liu | 651bab6 | 2022-03-09 04:03:39 -0500 | [diff] [blame] | 32 | API_FOTA, |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 33 | } API_MOUDLE; |
| 34 | |
| 35 | |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 36 | |
| 37 | static 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 | |
| 45 | void hold_on(){ |
| 46 | char any[5]={ 0 }; |
| 47 | printf("Press any key to return\n"); |
| 48 | fgets(any, 5, stdin); |
| 49 | } |
| 50 | |
| 51 | int 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 | } |
| 98 | int 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 | } |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 106 | if(!strcmp(module,"WIFI")) |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 107 | { |
| 108 | return API_WIFI; |
| 109 | } |
tao.liu | 651bab6 | 2022-03-09 04:03:39 -0500 | [diff] [blame] | 110 | else if(!strcmp(module, "fota")) |
| 111 | { |
| 112 | return API_FOTA; |
| 113 | } |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 114 | /* |
| 115 | else if(!strcmp(module, "AUDIO")) |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 116 | { |
| 117 | return API_AUDIO; |
| 118 | } |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 119 | */ |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 120 | else |
| 121 | { |
| 122 | LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR); |
| 123 | // printf("can not find %s API module ",module); |
| 124 | return -1; |
| 125 | } |
| 126 | return -1; |
| 127 | } |
| 128 | |
| 129 | int api_start(int argc, char *argv[]){ |
| 130 | LYDBGLOG("api_start,argc:%d\n",argc); |
| 131 | char *menu[2] = {0};// menu[0] is the "moudle",menu[1] is the "API" |
| 132 | char* argvHead=NULL; |
| 133 | int module = -1; |
| 134 | argvHead = getMenu(argv[2],menu);//find the "module" and the "API" |
| 135 | module = getRilModule(menu[0]); |
| 136 | // if(argvHead == NULL) |
| 137 | // { |
| 138 | // printf("pram api error\n"); |
| 139 | // return 0; |
| 140 | // } |
| 141 | switch(module) |
| 142 | { |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 143 | /* Add the code of the owner modules below*/ |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 144 | case API_AUDIO: |
| 145 | { |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 146 | //audio_test(menu[1],argvHead); |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 147 | break; |
| 148 | } |
tao.liu | 651bab6 | 2022-03-09 04:03:39 -0500 | [diff] [blame] | 149 | case API_FOTA: |
| 150 | { |
| 151 | fota_test(menu[1],argvHead); |
| 152 | break; |
| 153 | } |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 154 | case API_WIFI: |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 155 | break; |
| 156 | default: |
| 157 | // printf("pram module error\n"); |
| 158 | LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR); |
| 159 | |
| 160 | break; |
| 161 | } |
| 162 | // hold_on(); //add by zhouqunchao delete help message |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | int function_start(int argc, char *argv[]) |
| 167 | { |
| 168 | int select_menu = atoi(argv[0]); |
| 169 | int thread = atoi(argv[1]); |
| 170 | // printf("select_menu:%d,thread:%d\n",select_menu,thread); |
| 171 | switch(select_menu) |
| 172 | { |
| 173 | case API_MENU: |
| 174 | { |
| 175 | if (thread == 1)//rita add @2021.6.21 for threadhandle test |
| 176 | { |
| 177 | LYDBGLOG("[%s-%d] argv[2] = [%s]\n", __FUNCTION__, __LINE__, argv[2]); |
| 178 | if(strlen(argv[2])){//rita add @2021.6.21 for data error |
| 179 | LYDBGLOG("[%s-%d] argv[2] = [%s]\n", __FUNCTION__, __LINE__, argv[2]); |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 180 | //send_broadcast_by_name("function", strlen(argv[2]), argv[2]); |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 181 | } |
| 182 | else{ |
| 183 | LYVERBLOG("+[thhandle]: error num = %d\n", INVALID_CMD); |
| 184 | return INVALID_CMD; |
| 185 | } |
| 186 | } |
| 187 | else if(thread ==2){//rita add @2021.6.21 for local test |
| 188 | api_start(argc,argv); |
| 189 | } |
| 190 | else{ |
| 191 | //printf("thread 1,local 2\n"); |
| 192 | LYDBGLOG("thread 1,local 2\n"); |
| 193 | } |
| 194 | break; |
| 195 | } |
| 196 | case DEMO_MENU: |
| 197 | { |
| 198 | //printf("DEMO_MENU\n"); |
| 199 | LYDBGLOG("DEMO_MENU\n"); |
| 200 | break; |
| 201 | } |
| 202 | default: |
| 203 | break; |
| 204 | } |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | void help_display(){ |
| 210 | printf("\n"); |
| 211 | printf("*****************************************************************************\n"); |
| 212 | printf("0:help ------- help\n"); |
| 213 | printf("*****************************************************************************\n"); |
| 214 | printf("1:API TEST\n" ); |
| 215 | printf(" 1-1:Async api-\n" ); |
| 216 | printf(" --MQTT\n" ); |
| 217 | printf("\n"); |
| 218 | printf(" --HTTP\n" ); |
| 219 | printf(" 1-2:Sync api-\n" ); |
| 220 | printf(" --GPIO\n" ); |
| 221 | printf("\n"); |
| 222 | printf(" --RIL\n" ); |
| 223 | printf("\n"); |
| 224 | printf(" --WIFI\n" ); |
| 225 | printf("\n"); |
| 226 | printf(" --GNSS\n" ); |
| 227 | printf("\n"); |
| 228 | printf(" --SERVICE\n" ); |
| 229 | printf("*****************************************************************************\n"); |
| 230 | printf("2:DEMO TEST:Subsequent updates\n" ); |
| 231 | printf("*****************************************************************************\n"); |
| 232 | printf("\n"); |
| 233 | printf("1:API TEST The format is as follows :\n" ); |
| 234 | printf("{menu}-{mode selection} moudle=\"{moudle}\"&API=\"{api interface}\"&session=\"{session id}\"\"¶meterA=\"{parameter A}\"\n" ); |
| 235 | /* |
| 236 | printf("The main parameters are as follows:\n"); |
| 237 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
| 238 | printf("menu:1--API TEST,2--DEMO TEST\n" ); |
| 239 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
| 240 | printf("mode selection:1--async api,2--sync api\n" ); |
| 241 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
| 242 | printf("moudle:Test module--includes the following modules\n" ); |
| 243 | printf("RIL, GPIO,MQTT,HTTP,WIFI,GNSS\n" ); |
| 244 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
| 245 | printf("api interface:--Interface corresponding to module\n" ); |
| 246 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
| 247 | printf("session id:--Used to distinguish different session groups of the same module\n" ); |
| 248 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
| 249 | printf("parameter A:--API parameter,Add format {\"¶meter_name=\"{parameter}\"} \n" ); |
| 250 | printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
| 251 | */ |
| 252 | printf("Select menu:\n"); |
| 253 | } |
| 254 | void menu_display(){ |
| 255 | printf("\n"); |
| 256 | printf("**********************\n"); |
| 257 | printf("0:help menu\n"); |
| 258 | printf("1:API TEST\n"); |
| 259 | printf("2:DEMO TEST\n"); |
| 260 | printf("**********************\n"); |
| 261 | printf("\n"); |
| 262 | printf("Select menu:\n"); |
| 263 | } |
| 264 | int main() |
| 265 | { |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 266 | LYLOGEINIT(USER_LOG_TAG); |
rita | 6ce3aa2 | 2022-03-03 06:58:44 -0500 | [diff] [blame] | 267 | // LYLOGSET(4); |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 268 | |
| 269 | /*Check whether the modem works correctly and start the corresponding service*/ //add by liulei |
| 270 | char buf[1024]={0}; |
xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 271 | |
| 272 | while (1) { |
| 273 | char *argv[MAX_ARGS]; |
| 274 | char str[BUFFER_SIZE]={ 0 }; |
| 275 | menu_display(); |
| 276 | fgets(str, BUFFER_SIZE, stdin); |
| 277 | LYDBGLOG("[%s-%d] str= [%s]\n", __FUNCTION__, __LINE__, str); |
| 278 | str[strlen(str)-1]='\0'; |
| 279 | if(!strcmp(str, "0")){ |
| 280 | help_display(); |
| 281 | //hold_on(); //add by zhouqunchao delete help message |
| 282 | continue; |
| 283 | } |
| 284 | if(!strcmp(str,"quit")) |
| 285 | { |
| 286 | //system("killall lynq-framework-service"); |
| 287 | break; |
| 288 | } |
| 289 | if ((strncmp(str,"1-",2) == 0)|| |
| 290 | (strncmp(str,"2-",2)== 0)) |
| 291 | { |
| 292 | char* at_cmd = strstr(str, "-"); |
| 293 | strncpy(at_cmd, " ", 1); |
| 294 | LYDBGLOG("[%s-%d] at_cmd = [%s]\n", __FUNCTION__, __LINE__, at_cmd); |
| 295 | |
| 296 | |
| 297 | int argc = parse_param(str, argv, MAX_ARGS); |
| 298 | //add by zqc Format error judgment start |
| 299 | if(argv[2] == NULL) |
| 300 | { |
| 301 | LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR); |
| 302 | continue; |
| 303 | } |
| 304 | //add by zqc Format error judgment end |
| 305 | function_start(argc,argv); |
| 306 | continue; |
| 307 | } |
| 308 | else{ |
| 309 | // printf("pram error\n"); |
| 310 | LYVERBLOG("+[command error]:error num = %d\n",MENU_INPUT_ERROR); |
| 311 | continue; |
| 312 | } |
| 313 | } |
| 314 | return 0; |
| 315 | } |
| 316 | |