void cmd_parse(char *cmd) { uint8_t argc, i = 0; char *argv[30]; char buf[50]; cmd_t *cmd_entry; fflush(stdout); // parse the command line statement and break it up into space-delimited // strings. the array of strings will be saved in the argv array. argv[i] = strtok(cmd, " "); do { argv[++i] = strtok(NULL, " "); } while ((i < 30) && (argv[i] != NULL)); // save off the number of arguments for the particular command. argc = i; // parse the command table for valid command. used argv[0] which is the // actual command name typed in at the prompt for (cmd_entry = cmd_tbl; cmd_entry != NULL; cmd_entry = cmd_entry->next) { if (!strcmp(argv[0], cmd_entry->cmd)) { cmd_entry->func(argc, argv); cmd_display(); return; } } // command not recognized. print message and re-generate prompt. strcpy_P(buf, cmd_unrecog); Serial.println(buf); cmd_display(); }
void command_parse(const u08 *cmd, u08 len) { u08 result = 0; switch(cmd[0]) { case 'c': result = cmd_color(cmd,len); break; case 'f': result = cmd_flags(cmd, len); break; case 'd': result = cmd_draw(cmd, len); break; case 'g': result = cmd_goto(cmd, len); break; case 'e': result = cmd_erase(cmd, len); break; case 's': /* do nothing - only return status */ result = CMD_OK; break; case 'q': result = cmd_query(cmd, len); break; case 'i': result = cmd_input(cmd, len); break; case 'p': result = cmd_picture(cmd, len); break; case 'y': result = cmd_display(cmd, len); break; default: result = CMD_UNKNOWN_ERR; break; } // report status back if(result != CMD_NO_REPLY) { cmd_status(result); } }
void init_cmdline_interface(){ cmdInit(115200); cmdAdd("help", help); cmdAdd("h", help); cmdAdd("?", help); cmdAdd("", Nop); cmdAdd("hello", hello); cmdAdd("BackToNoHost", BackToNoHost_cmd); cmdAdd("InitDevInfo", InitDevInfo_cmd); cmdAdd("SEState", SE_state_cmd); cmdAdd("BindReg", BindReg_cmd); cmdAdd("BindLogin", BindLogin_cmd); cmdAdd("BindLogout", BindLogout_cmd); cmdAdd("BackToNoHost", BackToNoHost_cmd); cmdAdd("BackToInit",BackToInit_cmd); cmdAdd("InitWallet", InitWallet_cmd); cmdAdd("PINAuth", PIN_Auth_cmd); cmdAdd("QueryWalletInfo", hdw_query_wallet_info_cmd); cmdAdd("QueryAllAccount", hdw_query_all_account_info_cmd); cmdAdd("QueryAccountKey", hdw_query_account_key_info_cmd); cmdAdd("CreateAccount", hdw_create_account_cmd); cmdAdd("QueryAccountInfo", hdw_query_account_info_cmd); cmdAdd("CreateNextAddr", hdw_generate_next_trx_addr_cmd); //cmdAdd("SetSecurityPolicy", SetSecurityPolicy_cmd); cmdAdd("Transaction", Transaction_cmd); cmdAdd("Voltage", ReadVoltage_cmd); cmdAdd("ReinitBLE", ReinitBLE_cmd); cmdAdd("AddVcard", AddVcard_cmd); cmdAdd("ResetHitconTokenDisplay", ResetHitconTokenDisplay); Serial.println("**************************************************************************"); for (int i = 0; i < 10; ++i) { Serial.print("*");Serial.print(HitconBanner[i]);Serial.println("*"); } Serial.println("**************************************************************************"); Serial.println("Hitcon Badge 2018 Cmdline interface\r\nVersion:1.0.12\r\nenter help to see the cmd list"); cmd_display(); }