bool CommandReciever::DispatchCommand( const StringVector & args ) { // Look for default commands first. CommandMap::iterator cit = mCommandMap.find( args[ 0 ] ); if ( cit != mCommandMap.end() ) { ( *cit->second.second )( args ); return true; } // Look for the command in the script command table. gmMachine * mMachine = ScriptManager::GetInstance()->GetMachine(); gmTableObject *pCommandsTable = ScriptManager::GetInstance()->GetGlobalCommandsTable(); if ( pCommandsTable ) { ScriptCommandExecutor cmdExec( mMachine, pCommandsTable ); if ( cmdExec.Exec( args ) ) return true; } // iterate all com for ( RecieverList::iterator it = mRecieverList.begin(); it != mRecieverList.end(); ++it ) { if ( ( *it )->UnhandledCommand( args ) ) return true; } EngineFuncs::ConsoleError( "Unrecognized command. Use /bot help for a list of commands." ); return false; }
void AgentF::exec(const QStringList& parm) { if(mFilu->hasError()) return; // mCmd->regCmds("this...") is done in ctor ! // mCmd->regOpts("verbose"); if(mCmd->cmdLineLooksBad(parm)) return; if(mCmd->has("verbose")) setVerboseLevel(FUNC, mCmd->cmdLine()); if(mCmd->wantHelp()) { mCmd->inCmdBrief("full", tr("Download eod bars of all FIs")); mCmd->inCmdBrief("info", tr("Print some settings and more")); CmdClass::allBriefIn(mCmd); Depots::briefIn(mCmd); Scanner::briefIn(mCmd); Exporter::briefIn(mCmd); mCmd->inOptBrief("verbose", "<Level>" , tr("How talkative has it to be. Level can be 0-3 or " "Quiet Info Ample Max")); } else { QStringList cmd = parm; cmd.removeAt(0); record(FUNC, tr("Exec: %1").arg(cmd.join(" "))); } if(mCmd->needHelp(1)) { if(mCmd->printThisWay("<Command> [<ParmList>] [<SubCommand> [<ParmList>]]..")) return; mCmd->printComment(tr("Calling a command without any parameter may give a hint like --help.")); mCmd->printComment(tr("But of cause not if no parameter is needed e.g at 'full'.")); mCmd->aided(); return; } // Look for each known command and call the related function if(mKnownCmds.contains(mCmd->cmd())) cmdExec(mCmd->cmd()); else if(mCmd->hasCmd("full")) updateAllBars(); else if(mCmd->hasCmd("exp")) exxport(); else if(mCmd->hasCmd("scan")) scan(); else if(mCmd->hasCmd("depots")) depots(); else if(mCmd->hasCmd("info")) printSettings(); else { fatal(FUNC, QString("Unsupported command: %1").arg(mCmd->cmd())); } }
// Parse a packet and print info about it void ICACHE_FLASH_ATTR cmdParsePacket(uint8_t *buf, short len) { // minimum command length if (len < sizeof(CmdPacket)) return; // init pointers into buffer CmdPacket *packet = (CmdPacket*)buf; uint8_t *data_ptr = (uint8_t*)&packet->args; uint8_t *data_limit = data_ptr+len; DBG("cmdParsePacket: cmd=%d argc=%d value=%u\n", packet->cmd, packet->argc, packet->value ); #if 0 // print out arguments uint16_t argn = 0; uint16_t argc = packet->argc; while (data_ptr+2 < data_limit && argc--) { short l = *(uint16_t*)data_ptr; os_printf("cmdParsePacket: arg[%d] len=%d:", argn++, l); data_ptr += 2; while (data_ptr < data_limit && l--) { os_printf(" %02X", *data_ptr++); } os_printf("\n"); } #endif if (!cmdInSync && packet->cmd != CMD_SYNC) { // we have not received a sync, perhaps we reset? Tell MCU to do a sync cmdResponseStart(CMD_SYNC, 0, 0); cmdResponseEnd(); } else if (data_ptr <= data_limit) { cmdExec(commands, packet); } else { DBG("cmdParsePacket: packet length overrun, parsing arg %d\n", packet->argc); } }
void cmd(const void* _userData) { cmdExec( (const char*)_userData); }