Firmware/FFBoard/UserExtensions/Src/FFBoardMainCommandThread.cpp
/*
 * Executes parsed commands and calls other command handlers.
 * Not global so it can be overridden by main classes to change behaviour or suppress outputs.
 */
Executes parsed commands and calls other command handlers.
Not global so it can be overridden by main classes to change behaviour or suppress outputs.
Executes parsed commands and calls other command handlers . Not global so it can be overridden by main classes to change behaviour or suppress outputs .
void FFBoardMainCommandThread::executeCommands(std::vector<ParsedCommand> commands){
	if(clearReply)
		this->cmd_reply.clear();
	for(ParsedCommand cmd : commands){
		ParseStatus status = ParseStatus::NOT_FOUND;
		if(cmd.cmd.empty())
			continue; 
		this->cmd_reply+= ">" + cmd.rawcmd + ":"; 
		std::string reply; 
		status = executeSysCommand(&cmd,&reply);
		if(status == ParseStatus::NOT_FOUND || status == ParseStatus::OK_CONTINUE){ 
			for(CommandHandler* handler : CommandHandler::cmdHandlers){
				if(handler->hasCommands()){
					ParseStatus newstatus = handler->command(&cmd,&reply);
					if(!(status == ParseStatus::OK_CONTINUE && newstatus == ParseStatus::NOT_FOUND)){
						status = newstatus;
					}
					if(status == ParseStatus::ERR || status == ParseStatus::OK || status == ParseStatus::NO_REPLY)
						break; 
				}
			}
		}
		if(status == ParseStatus::NO_REPLY){
			cmd_reply.clear();
			continue; 
		}
		if(reply.empty() && status == ParseStatus::OK){
			reply = "OK";
		}
		if(!reply.empty() && reply.back()!='\n'){
			reply+='\n';
		}
		if(status == ParseStatus::NOT_FOUND){ 
			Error err = cmdNotFoundError;
			reply = "Err. invalid";
			err.info = cmd.rawcmd + " not found";
			ErrorHandler::addError(err);
		}else if(status == ParseStatus::ERR){ 
			reply = "Err. exec error";
			Error err = cmdExecError;
			err.info = "Error executing" + cmd.rawcmd;
			ErrorHandler::addError(err);
		}
		this->cmd_reply+=reply;
	}
	if(this->cmd_reply.length()>0){ 
		this->main->parserDone(&cmd_reply, this);
	}
}
void FFBoardMainCommandThread :: executeCommands ( std :: vector < ParsedCommand > commands ) { if ( clearReply ) this -> cmd_reply . clear ( ) ; for ( ParsedCommand cmd : commands ) { ParseStatus status = ParseStatus :: NOT_FOUND ; if ( cmd . cmd . empty ( ) ) continue ; this -> cmd_reply += " " + cmd . rawcmd + " " ; std :: string reply ; status = executeSysCommand ( & cmd , & reply ) ; if ( status == ParseStatus :: NOT_FOUND || status == ParseStatus :: OK_CONTINUE ) { for ( CommandHandler * handler : CommandHandler :: cmdHandlers ) { if ( handler -> hasCommands ( ) ) { ParseStatus newstatus = handler -> command ( & cmd , & reply ) ; if ( ! ( status == ParseStatus :: OK_CONTINUE && newstatus == ParseStatus :: NOT_FOUND ) ) { status = newstatus ; } if ( status == ParseStatus :: ERR || status == ParseStatus :: OK || status == ParseStatus :: NO_REPLY ) break ; } } } if ( status == ParseStatus :: NO_REPLY ) { cmd_reply . clear ( ) ; continue ; } if ( reply . empty ( ) && status == ParseStatus :: OK ) { reply = " " ; } if ( ! reply . empty ( ) && reply . back ( ) != ' \n ' ) { reply += ' \n ' ; } if ( status == ParseStatus :: NOT_FOUND ) { Error err = cmdNotFoundError ; reply = " " ; err . info = cmd . rawcmd + " " ; ErrorHandler :: addError ( err ) ; } else if ( status == ParseStatus :: ERR ) { reply = " " ; Error err = cmdExecError ; err . info = " " + cmd . rawcmd ; ErrorHandler :: addError ( err ) ; } this -> cmd_reply += reply ; } if ( this -> cmd_reply . length ( ) > 0 ) { this -> main -> parserDone ( & cmd_reply , this ) ; } }
Executes parsed commands and calls other command handlers.
Executes parsed commands and calls other command handlers .
// Empty command // Start marker. Echo command // Reply of current command // Not a system command // Call all command handlers // Prevent other threads from running while we call all command handlers // TODO monitor if this causes problems or is really needed. //cpp_freertos::CriticalSection::SuspendScheduler(); // If last class did not have commands but a previous one asked to continue keep continue status // Stop after this class if finished flag is returned // Resume scheduler //cpp_freertos::CriticalSection::ResumeScheduler(); // don't send reply. Just continue // Append newline if reply is not empty // Errors //No class reported success. Show error //Error reported in command // Check if cdc busy