public bool CheckIfStreaming() { SimulatorStateResult stateResult = (SimulatorStateResult)CallCommand(new GetSimulatorState()); if (stateResult.State == "Streaming RF") { return(true); } string errorMsg; if (stateResult.State == "Error") { errorMsg = "An error occured during simulation. Error message:\n" + stateResult.Error; } else { errorMsg = "Simulator is no more streaming. Current state is " + stateResult.State + "."; } if (IsExceptionOnError) { throw new Exception(errorMsg); } PrintLine(errorMsg); return(false); }
public bool WaitState(string state, string failureState = "") { PrintLine("Waiting for simulator state "); SimulatorStateResult stateResult = (SimulatorStateResult)CallCommand(new WaitSimulatorState(state, failureState)); string errorMsg; if (stateResult.State == state) { PrintLine("Simulator state is now to " + state); return(true); } else if (stateResult.State == "Error") { errorMsg = "An error occured during simulation. Error message:\n" + stateResult.Error; } else { errorMsg = "Wrong simulator state. Expected " + state + " but received " + stateResult.State; } if (IsExceptionOnError) { throw new Exception(errorMsg); } PrintLine(errorMsg); return(false); }
private void HandleException(CommandResult result) { if (IsExceptionOnError && !result.IsSuccess) { SimulatorStateResult stateResult = (SimulatorStateResult)Call(new GetSimulatorState()); string errorMsg = ""; if (stateResult.State == "Error") { errorMsg = "\nAn error occured during simulation. Error message:\n" + stateResult.Error; } throw new CommandException(result, errorMsg); } if (IsVerbose && !result.IsSuccess) { PrintLine(result.RelatedCommand.Name + " failed: " + result.Message); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Failure Handling Example // This example shows: // 1- How to verify command result // 2- How to get error messages from command failure //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static void RunExampleFailureHandling(string host, string target_type, string x300_ip) { Console.WriteLine(); Console.WriteLine("=== Failure handling Example ==="); Console.WriteLine("==> Connecting to the simulator"); //RemoteSimulator sim = new RemoteSimulator(true); // Stop the example with an exception if a command fail RemoteSimulator sim = new RemoteSimulator(false); // Does not stop the example with an exception if a command fail sim.IsVerbose = false; sim.Connect(host); Console.WriteLine("==> Create New Configuration, discarding current simulator settings"); sim.Call(new New(true)); Console.WriteLine("==> Modulation Settings"); string targetId = "MyTargetId"; sim.Call(new SetModulationTarget(target_type, "", x300_ip, true, targetId)); // Select signals to simulate sim.Call(new ChangeModulationTargetSignals(0, 12500000, 12500000, "UpperL", "L1CA", -1, false, targetId)); // Command Success Example: // Changing configuration before starting the simulation. CommandResult result1 = sim.Call(new ChangeModulationTargetSignals(0, 12500000, 50000000, "UpperL", "L1CA,G1", -1, false, targetId)); Console.WriteLine("SUCCESS MESSAGE EXAMPLE: " + result1.Message); // Will print Success // Command Failure Example: // The following command is not allowed before you start the simulation. CommandResult result2 = sim.Call(new SetPowerForSV("GPS", 12, -10, true)); Console.WriteLine("FAILURE MESSAGE EXAMPLE: " + result2.Message); Console.WriteLine("==> Starting Simulation"); if (sim.Start()) { // Change satellite 14 power to -15dB (relative to nominal power) sim.Call(new SetPowerForSV("GPS", 14, -15, false)); // Command Failure Example: // The following command (setting simulation start time) is not allowed once simulation is started. CommandResult result3 = sim.Call(new SetGpsStartTime(new DateTime(2021, 2, 15, 7, 0, 0))); Console.WriteLine("FAILURE MESSAGE EXAMPLE: " + result3.RelatedCommand.ToReadableCommand() + ": " + result3.Message); // Asynchronous Success command example // When simulation elapsed time is 9.567 sec, change satellite 31 power to -25 dB CommandBase cmd4 = sim.Post(new SetPowerForSV("GPS", 31, -25, false), 9.567); // Asynchronous Failure command example // When simulation elapsed time is 12.05 sec, change satellite 200 power to +10 dB CommandBase cmd5 = sim.Post(new SetPowerForSV("GPS", 200, 10, false), 12.05); // Wait for Asynchronous commands to complete CommandResult result4 = sim.Wait(cmd4); CommandResult result5 = sim.Wait(cmd5); Console.WriteLine("SUCCESS MESSAGE EXAMPLE: " + result4.RelatedCommand.ToReadableCommand() + ": " + result4.Message); Console.WriteLine("FAILURE MESSAGE EXAMPLE: " + result5.RelatedCommand.ToReadableCommand() + ": " + result5.Message); Console.WriteLine("==> Stop simulation when elapsed time is 20 sec"); sim.Stop(20); } SimulatorStateResult stateResult = (SimulatorStateResult)sim.Call(new GetSimulatorState()); if (stateResult.State == "Error") { Console.WriteLine("An error occured during simulation. Error message:\n" + stateResult.Error); } sim.Disconnect(); }