protected override Response SyncTask(Command command) { bool success; success = false; try { if (command.Parameters.StartsWith("enable")) { spRec.Enabled = true; success = true; } else if (command.Parameters.StartsWith("disable")) { spRec.Enabled = false; success = true; } else if (command.Parameters == "toggle") { spRec.Enabled = !spRec.Enabled; success = true; } } catch { success = false; } return Response.CreateFromCommand(command, success); }
public Command GetCommand(ConnectionManager cnnMan) { if (!Match(cnnMan)) return null; Command cmd = new Command(cnnMan, commandName, parameters, currentId); if (id < -1) ++currentId; return cmd; }
public Response GetResponse(Command command) { bool success; if (!Match(command)) return null; success = failureRate < rnd.Next(1, 100); Response response = Response.CreateFromCommand(command, success); if(parameters.Length != 0) response.Parameters = parameters; return response; }
protected override Response AsyncTask(Command command) { bool result; string pName; if (engine.Busy) return Response.CreateFromCommand(command, false); engine.SleepCapture = false; pName = command.Parameters; result = engine.RememberHuman(pName, 3); return Response.CreateFromCommand(command, result); }
protected override Response SyncTask(Command command) { bool result = true; if (String.IsNullOrEmpty(command.Parameters)) command.Parameters = engine.Enabled ? "enabled" : "disabled"; else if (command.Parameters == "enabled") engine.Start(); else if (command.Parameters == "enabled") engine.Stop(); else result = false; return Response.CreateFromCommand(command, result); }
protected override Response SyncTask(Command command) { SpeechRecognizer53 reco = spRec as SpeechRecognizer53; if (spRec == null) return Response.CreateFromCommand(command, false); AutoSaveMode mode; string p = String.IsNullOrEmpty(command.Parameters) ? String.Empty : command.Parameters.ToLower(); Response r = Response.CreateFromCommand(command, true); if (TryParse(p, out mode)) reco.AutoSaveMode = mode; r.Parameters = AutoSaveModeToString(reco.AutoSaveMode); return r; }
/// <summary> /// Executes the play command /// </summary> /// <param name="command">Command object which contains the command to be executed</param> /// <returns>The Response object result of provided command execution. If no response is required, must return null</returns> /// <remarks>If the command execution is aborted the execution of this method is /// canceled and a failure response is sent if required</remarks> protected override Response AsyncTask(Command command) { bool result; result = false; try { if (File.Exists(command.Parameters)) result = audioPlayer.PlayLoop(command.Parameters); } catch { result = false; } return Response.CreateFromCommand(command, result); }
protected override Response SyncTask(Command command) { string param = command.Parameters; bool success = false; try { switch (param) { case "enable": case "enabled": spRec.Enabled = true; success = true; break; case "disable": case "disabled": spRec.Enabled = false; success = true; break; case "get": case "": param = spRec.Enabled ? "enable" : "disable"; success = true; break; case "toggle": spRec.Enabled = !spRec.Enabled; param = spRec.Enabled ? "enable" : "disable"; success = true; break; default: success = false; break; } } catch { success = false; } return Response.CreateFromCommand(command, success); }
/// <summary> /// Executes the voice command /// </summary> /// <param name="command">Command object which contains the command to be executed</param> /// <returns>The Response object result of provided command execution. If no response is required, must return null</returns> /// <remarks>If the command execution is aborted the execution of this method is /// canceled and a failure response is sent if required</remarks> protected override Response SyncTask(Command command) { if((!command.HasParams) || (command.Parameters.ToLower() == "get")) { command.Parameters = spGen.SelectedVoiceName; return Response.CreateFromCommand(command, true); } if (!spGen.VoiceNames.Contains(command.Parameters)) return Response.CreateFromCommand(command, false); try { spGen.SelectedVoiceName = command.Parameters; return Response.CreateFromCommand(command, true); } catch { return Response.CreateFromCommand(command, false); } }
protected override Response SyncTask(Command command) { TextBoxStreamWriter.DefaultLog.WriteLine("CmdStart: Received: " + command.StringToSend); bool success = true; if (command.HasParams) { /*if (command.Parameters.Contains("followme")) this.hal9000Brain.StartFollowHumanTest(); else if (command.Parameters.Contains("robozoo")) this.hal9000Brain.StartRoboZooTest(); else if (command.Parameters.Contains("openchallenge")) this.hal9000Brain.StartOpenChallengeTest(); else if (command.Parameters.Contains("restaurant")) this.hal9000Brain.StartRestaurant(); else success = false;*/ } else success = false; return Response.CreateFromCommand(command, success); }
/// <summary> /// Executes the play command /// </summary> /// <param name="command">Command object which contains the command to be executed</param> /// <returns>The Response object result of provided command execution. If no response is required, must return null</returns> /// <remarks>If the command execution is aborted the execution of this method is /// canceled and a failure response is sent if required</remarks> protected override Response AsyncTask(Command command) { bool result; result = false; try { if (File.Exists(command.Parameters)) { if (audioPlayer.IsPlaying || (audioPlayer.Pending > 0)) result = false; else result = audioPlayer.PlaySync(command.Parameters); } } catch { result = false; } return Response.CreateFromCommand(command, result); }
protected override Response SyncTask(Command command) { Response response; string param = command.Parameters; this.CommandManager.Busy = true; if ((param == "") || (param == "get")) { command.Parameters = spRec.HasGrammar ? spRec.GrammarFile : "none"; response = Response.CreateFromCommand(command, true); } else { bool result; try { result = spRec.LoadGrammar(param); } catch { result = false; } response = Response.CreateFromCommand(command, result); } this.CommandManager.Busy = false; return response; }
protected override Response SyncTask(Command command) { return Response.CreateFromCommand(command, false); /* Match m; bool result; string[] words; int timeOut; m = rxWordExtractor.Match(command.Parameters); if (!m.Success) return Response.CreateFromCommand(command, false); try { words = m.Result("${words}").Split(','); timeOut = Int32.Parse(m.Result("${timeOut}")); frmSpRec.AddToExpectedPhraseList(words, timeOut); result = true; } catch { result = false; } return Response.CreateFromCommand(command, result); */ }
/// <summary> /// Request arm to open the grip /// </summary> /// <param name="percentage">Percentage aperture of the grip</param> /// <param name="timeOut">Amout of time to wait for an arm response in milliseconds</param> /// <returns>true if arm opened the grip. false otherwise</returns> public virtual bool OpenGrip(int percentage, int timeOut) { // Stores the command to be sent to arm Command cmdOpenGrip; // Stores the response from arm and the candidate while moving Response rspOpenGrip = null; // 1. Prepare the command if (!GetResource()) return false; if ((percentage >= 0) && (percentage <= 100)) cmdOpenGrip = new Command(sgnArmOpenGrip.CommandName, percentage.ToString(), CmdMan.AutoId++); else { cmdOpenGrip = new Command(sgnArmOpenGrip.CommandName, "", CmdMan.AutoId++); percentage = -1; } // 2. Send the armOpenGrip command CmdMan.Console("\tOpening arm grip to [" + percentage.ToString() + "%]"); if (!CmdMan.SendAndWait(cmdOpenGrip, timeOut, out rspOpenGrip)) { // 2.1. Cant send socket. Operation canceled. CmdMan.Console("\tCan't send command. Operation canceled"); FreeResource(); return false; } // 3. End of move FreeResource(); // 3.2. Parse head response if (!rspOpenGrip.Success) { // 3.2. Failed response CmdMan.Console("\tArm did not move"); return false; } CmdMan.Console("\tOpen arm grip complete"); return true; }
/// <summary> /// Request arm to move to the specified position relative to its current position /// </summary> /// <param name="x">Relative x coordinate position of the actuator of the arm.</param> /// <param name="y">Relative y coordinate position of the actuator of the arm.</param> /// <param name="z">Relative z coordinate position of the actuator of the arm.</param> /// <param name="timeOut">Amout of time to wait for an arm response in milliseconds</param> /// <returns>true if arm moved to specified position. false otherwise</returns> public virtual bool SetRelativePosition(ref double x, ref double y, ref double z, int timeOut) { // Stores the command to be sent to arm Command cmdArmRelPos; // Stores the response from arm and the candidate while moving Response rspArmRelPos = null; // 1. Prepare the command if (!GetResource()) return false; string parameters = x.ToString("0.00") + " " + y.ToString("0.00") + " " + z.ToString("0.00"); cmdArmRelPos = new Command(sgnArmSetRelPos.CommandName, parameters, CmdMan.AutoId++); // 2. Send the armSetRelPos command CmdMan.Console("\tMoving arm to relative position " + parameters); if (!CmdMan.SendAndWait(cmdArmRelPos, timeOut, out rspArmRelPos)) { // 2.1. Cant send socket. Operation canceled. CmdMan.Console("\tCan't send command. Operation canceled"); FreeResource(); return false; } // 3. End of move FreeResource(); // 3.1. Parse arm response if (!rspArmRelPos.Success) { // 3.2. Failed response CmdMan.Console("\tArm did not move"); return false; } // 4.0 Recover values from response SignatureAnalysisResult saResult = sgnArmSetRelPos.Analyze(rspArmRelPos); if (saResult.Success) { saResult.Update<double>(0, ref x); saResult.Update<double>(1, ref y); saResult.Update<double>(2, ref z); } CmdMan.Console("\tMoving arm to position complete"); return true; }
/// <summary> /// Request arm to move to the specified orientation /// </summary> /// <param name="roll">Angle of rotation about the X-axis of the actuator of the arm.</param> /// <param name="pitch">Angle of rotation about the Y-axis of the actuator of the arm.</param> /// <param name="yaw">Angle of rotation about the Z-axis of the actuator of the arm.</param> /// <param name="timeOut">Amout of time to wait for an arm response in milliseconds</param> /// <returns>true if arm moved to the specified orientation. false otherwise</returns> public virtual bool GetOrientation(out double roll, out double pitch, out double yaw, int timeOut) { // Stores the command to be sent to arm Command cmdArmOrientation; // Stores the response from arm and the candidate while moving Response rspArmOrientation = null; bool result; roll = 0; pitch = 0; yaw = 0; // 1. Prepare the command if (!GetResource()) return false; string parameters = ""; cmdArmOrientation = new Command(sgnArmGetOrientation.CommandName, parameters, CmdMan.AutoId++); // 2. Send the armAbsPos command CmdMan.Console("\tReading arm orientation " + parameters); if (!CmdMan.SendAndWait(cmdArmOrientation, timeOut, out rspArmOrientation)) { // 2.1. Cant send socket. Operation canceled. CmdMan.Console("\tCan't send command. Operation canceled"); FreeResource(); return false; } // 3. End of move FreeResource(); // 3.1. Parse arm response if (!rspArmOrientation.Success) { // 3.2. Failed response CmdMan.Console("\tArm did not respond"); return false; } // 4.0 Recover values from response SignatureAnalysisResult saResult = sgnArmGetAbsPos.Analyze(rspArmOrientation); result = saResult.Success && (saResult.ParameterCount == 3) && (saResult.Update<double>(0, ref roll) & saResult.Update<double>(1, ref pitch) & saResult.Update<double>(2, ref yaw)); if (!result) CmdMan.Console("\tInvalid response"); else CmdMan.Console("\tGet arm position complete"); return result; }
/// <summary> /// Moves the arm through a secuence of positions /// </summary> /// <param name="movement">The name of the movement to perform</param> /// <param name="timeOut">Amout of time to wait for an arm response in milliseconds</param> /// <returns>true if arm executed the specified movement. false otherwise</returns> public virtual bool Move(string movement, int timeOut) { // Stores the command to be sent to arm Command cmdMoveArm; // Stores the response from arm and the candidate while moving Response rspMoveArm = null; // 1. Prepare the command if (!GetResource()) return false; cmdMoveArm = new Command(sgnArmMove.CommandName, movement, CmdMan.AutoId++); // 2. Send the armGoto command CmdMan.Console("\tMoving arm to position [" + movement + "]"); if (!CmdMan.SendAndWait(cmdMoveArm, timeOut, out rspMoveArm)) { // 2.1. Cant send socket. Operation canceled. CmdMan.Console("\tCan't send command. Operation canceled"); FreeResource(); return false; } // 3. End of move FreeResource(); // 3.1. Parse head response if (!rspMoveArm.Success) { // 3.2. Failed response CmdMan.Console("\tArm did not move"); return false; } CmdMan.Console("\tMoving arm to position complete"); return true; }
public bool Match(Command command) { if(command == null) return false; return (((module == "[ANY]") || (module == command.SourceModule)) && (commandName == command.CommandName)); }
public JustinaCmdAndResp(string cmdName) { this.command = new Command(cmdName, ""); this.response = Response.CreateFromCommand(this.command, false); this.isResposeReceived = false; }
private void commandManager_CommandReceived(Command command) { Console.WriteLine("Received command: " + command.ToString()); }
/// <summary> /// Request the manipulator aperture pecentage and tilt angle /// </summary> /// <param name="aperturePercentage">Percentage aperture of the gripper of the manipulator.</param> /// <param name="tilt">Tilt angle of the manipulator.</param> /// <param name="timeOut">Amout of time to wait for an man response in milliseconds</param> /// <returns>true if data fetch was successfully. false otherwise</returns> public virtual bool Status(out int aperturePercentage, out double tilt, int timeOut) { // Stores the command to be sent to man Command cmdStatus; // Stores the response from man and the candidate while moving Response rspStatus = null; bool result; aperturePercentage = 0; tilt = 0; // 1. Prepare the command if (!GetResource()) return false; string parameters = ""; cmdStatus = new Command(sgnStatus.CommandName, parameters, CmdMan.AutoId++); // 2. Send the manAbsPos command CmdMan.Console("\tReading man orientation " + parameters); if (!CmdMan.SendAndWait(cmdStatus, timeOut, out rspStatus)) { // 2.1. Cant send socket. Operation canceled. CmdMan.Console("\tCan't send command. Operation canceled"); FreeResource(); return false; } // 3. End of move FreeResource(); // 3.1. Parse man response if (!rspStatus.Success) { // 3.2. Failed response CmdMan.Console("\tManipulator did not respond"); return false; } // 4.0 Recover values from response SignatureAnalysisResult saResult = sgnStatus.Analyze(rspStatus); result = saResult.Success && (saResult.ParameterCount == 2) && (saResult.Update<int>(0, ref aperturePercentage) & saResult.Update<double>(1, ref tilt)); if (!result) CmdMan.Console("\tInvalid response"); else CmdMan.Console("\tGet man position complete"); return result; }
/// <summary> /// Executes the provided command /// </summary> /// <param name="command">Command object which contains the command to be executed</param> /// <remarks>If the command execution is aborted a failure response is sent if required</remarks> public override sealed void Execute(Command command) { // 1. Check busy state and parameters #region Busy check if (Busy) { if (ResponseRequired) SendResponse(false, command); return; } #endregion #region No params provided if (ParametersRequired && !command.HasParams) { SendResponse(false, command); return; } #endregion // 2. Set execution flags busy = true; running = true; // 3. Create default failed response Response response = Response.CreateFromCommand(command, false); // 4. Raise ExecutionStarted event OnExecutionStarted(command); // 5. Perform command execution response = SyncTask(command); // 6. If a null response is provided (and required), generate failure response if (ResponseRequired && (response == null)) response = Response.CreateFromCommand(command, false); // 7. Send the result of command execution (if any) if (response != null) SendResponse(response); // 8. Reset execution flags busy = false; running = false; // 9. Raise ExecutionFinished event OnExecutionFinished(command, response); }
/// <summary> /// When overriden executes the provided command /// </summary> /// <param name="command">Command object which contains the command to be executed</param> /// <returns>The Response object result of provided command execution. If no response is required, must return null</returns> /// <remarks>If the command execution is aborted the execution of this method is /// canceled and a failure response is sent if required</remarks> protected abstract Response SyncTask(Command command);
/// <summary> /// Sends a command through the asociated ConnectionManager of the CommandExecuter object that this instance of CommandExecuter is bound to /// </summary> /// <param name="command">Command to be sent</param> /// <returns>true if command was sent and its response received. false otherwise</returns> protected bool SendCommand(Command command) { if (cmdMan == null) return false; return cmdMan.SendCommand(command); }
/// <summary> /// Converts the string representation of a command to a Command object. /// A return value indicates whether the conversion succeded or not. /// <param name="source">The IMessageSource object source of the command parsed</param> /// <param name="s">A string containing the command to convert</param> /// <param name="result">When this method returns, contains the Command equivalent to the command /// contained in s, if the conversion succeeded, or null if the conversion failed. /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format. /// This parameter is passed uninitialized</param> /// </summary> /// <returns>true if conversion was successfull, false otherwise</returns> public static bool TryParse(IMessageSource source, string s, out Command result) { result = null; Regex rx; Match m; //ModuleClient source; //ModuleClient destination; string sCommand; string sParams; string sSrc; string sDest; string sId; int id; // Regular Expresion Generation rx = rxParse; m = rx.Match(s); // Check if input string matchs Regular Expression if (!m.Success) return false; // Extract Data sCommand = m.Result("${cmd}").ToLower(); sParams = m.Result("${params}"); sId = m.Result("${id}"); sSrc = m.Result("${src}"); if ((source != null) && ((sSrc == null) || (sSrc == ""))) sSrc = source.ModuleName; sDest = ""; // m.Result("${dest}"); if ((sId == null) || (sId.Length < 1)) id = -1; else id = Int32.Parse(sId); // Check if command matchs a prototype sParams = sParams.Replace("\\\"", "\""); result = new Command(sSrc, sDest, sCommand, sParams, id); result.MessageSource = source; //cmd.sentTime = DateTime.Now; return true; }
protected override Response SyncTask(Command command) { TextBoxStreamWriter.DefaultLog.WriteLine("CmdRecognized: Received but no enqueued: " + command.StringToSend); //this.hal9000Brain.RecognizedSentences.Enqueue(command.Parameters); return Response.CreateFromCommand(command, true); }
protected override Response SyncTask(Command command) { // TODO: Close the application return null; }
/// <summary> /// Initializes a new CommandResponsePair /// </summary> /// <param name="command">Asociated Command object</param> /// <param name="response">Asociated Response object</param> public CommandResponsePair(Command command, Response response) { this.command = command; this.response = response; }
/// <summary> /// Request manipulator to move to the specified tilt angle in radians /// </summary> /// <param name="tilt">The specified tilt angle in radians</param> /// <param name="timeOut">Amout of time to wait for an man response in milliseconds</param> /// <returns>true if manipulator moved to specified tilt. false otherwise</returns> public virtual bool Tilt(ref double tilt, int timeOut) { // Stores the command to be sent to man Command cmdTilt; // Stores the response from man and the candidate while moving Response rspTilt = null; bool result; // 1. Prepare the command if (!GetResource()) return false; cmdTilt = new Command(sgnTilt.CommandName, tilt.ToString("0.00"), CmdMan.AutoId++); // 2. Send the manGoto command CmdMan.Console("\tSetting manipulator tilt [" + tilt + "]"); if (!CmdMan.SendAndWait(cmdTilt, timeOut, out rspTilt)) { // 2.1. Cant send socket. Operation canceled. CmdMan.Console("\tCan't send command. Operation canceled"); FreeResource(); return false; } // 3. End of move FreeResource(); // 3.1. Parse manipulator response if (!rspTilt.Success) { // 3.2. Failed response CmdMan.Console("\tManipulator did not move"); return false; } // 4.0 Recover values from response SignatureAnalysisResult saResult = sgnTilt.Analyze(rspTilt); result = saResult.Success && (saResult.ParameterCount == 1) && (saResult.Update<double>(0, ref tilt)); if (!result) CmdMan.Console("\tInvalid response"); else CmdMan.Console("\tSet manipulator tilt complete"); return result; }
/// <summary> /// Request manipulator to open the grip /// </summary> /// <param name="percentage">Percentage aperture of the grip</param> /// <param name="timeOut">Amout of time to wait for an man response in milliseconds</param> /// <returns>true if manipulator opend the grip. false otherwise</returns> public virtual bool OpenGrip(ref int percentage, int timeOut) { // Stores the command to be sent to man Command cmdOpenGrip; // Stores the response from man and the candidate while moving Response rspOpenGrip = null; bool result; // 1. Prepare the command if (!GetResource()) return false; if ((percentage >= 0) || (percentage <= 100)) cmdOpenGrip = new Command(sgnOpenGrip.CommandName, percentage.ToString(), CmdMan.AutoId++); else { cmdOpenGrip = new Command(sgnOpenGrip.CommandName, "", CmdMan.AutoId++); percentage = 50; } // 2. Send the manOpenGrip command CmdMan.Console("\tClosing manipulator grip to [" + percentage.ToString() + "%]"); if (!CmdMan.SendAndWait(cmdOpenGrip, timeOut, out rspOpenGrip)) { // 2.1. Cant send socket. Operation canceled. CmdMan.Console("\tCan't send command. Operation canceled"); FreeResource(); return false; } // 3. End of move FreeResource(); // 3.1. Parse manipulator response if (!rspOpenGrip.Success) { // 3.2. Failed response CmdMan.Console("\tManipulator did not move"); return false; } // 4.0 Recover values from response SignatureAnalysisResult saResult = sgnOpenGrip.Analyze(rspOpenGrip); result = saResult.Success && (saResult.ParameterCount == 1) && (saResult.Update<int>(0, ref percentage)); if (!result) CmdMan.Console("\tInvalid response"); else CmdMan.Console("\tOpen manipulator grip complete"); return result; }