/// <summary> /// Async authorization in UCS server /// </summary> /// <param name="login">Login</param> /// <param name="password">Password</param> /// <param name="onConnect">on connection callback without paramaters</param> /// <returns></returns> public async Task ConnectUgcs(String login, String password, System.Action onConnect) { var task = Task <TheadExceptionModel> .Factory.StartNew(() => { LoginRequest loginRequest = new LoginRequest(); loginRequest.UserLogin = login; loginRequest.UserPassword = password; _request.ClientId = -1; var future = _executor.Submit <AuthorizeHciResponse>(_request); if (future.Exception != null) { return(new TheadExceptionModel() { Message = future.Exception.Message, Status = 400 }); } AuthorizeHciResponse = future.Value; loginRequest.ClientId = AuthorizeHciResponse.ClientId; LoginResponce = (LoginResponse)_executor.Submit <LoginResponse>(loginRequest).Value; if (LoginResponce == null || LoginResponce.User == null) { return(new TheadExceptionModel() { Message = "Invalid login or password", Status = 300 }); } return(new TheadExceptionModel() { Message = "OK", Status = 200 }); }); await task.ContinueWith((result) => { if (result.Exception != null) { result.Exception.Data.Clear(); logger.LogException(result.Exception); throw new ConnectionException(result.Exception.Message); } if (result.Result.Status == 200) { onConnect(); } else if (result.Result.Status == 300) { logger.LogError(result.Result.Message); throw new ConnectionException(result.Result.Message); } else if (result.Result.Status == 400) { logger.LogError("Exception occured: " + result.Result.Message); throw new ConnectionException(result.Result.Message); } }).ConfigureAwait(continueOnCapturedContext: false); }
public TResponse Execute <TResponse>(IExtensible request) where TResponse : IExtensible { var future = _executor.Submit <TResponse>(request); future.Wait(); if (future.Exception != null) { throw new ApplicationException("Ucs request execution exception.", future.Exception); } return(future.Value); }
public static UcsFacade connectToUcs(string host, int port, string login, string password) { var ucsConnection = new TcpClient(); ucsConnection.Connect(host, port); var executor = new MessageExecutor(ucsConnection.Session, new InstantTaskScheduler()); int clientId; try { //auth AuthorizeHciRequest request = new AuthorizeHciRequest(); request.ClientId = -1; request.Locale = "en-US"; var future = executor.Submit <AuthorizeHciResponse>(request); future.Wait(); AuthorizeHciResponse AuthorizeHciResponse = future.Value; clientId = AuthorizeHciResponse.ClientId; //login LoginRequest loginRequest = new LoginRequest(); loginRequest.UserLogin = login; loginRequest.UserPassword = password; loginRequest.ClientId = clientId; var loginResponcetask = executor.Submit <LoginResponse>(loginRequest); loginResponcetask.Wait(); } catch { executor.Close(); ucsConnection.Close(); ucsConnection.Dispose(); throw; } return(new UcsFacade(ucsConnection, executor, clientId)); }
static void Main(string[] args) { //Connect TcpClient tcpClient = new TcpClient(); tcpClient.Connect("localhost", 3334); MessageSender messageSender = new MessageSender(tcpClient.Session); MessageReceiver messageReceiver = new MessageReceiver(tcpClient.Session); MessageExecutor messageExecutor = new MessageExecutor(messageSender, messageReceiver, new InstantTaskScheduler()); messageExecutor.Configuration.DefaultTimeout = 10000; var notificationListener = new NotificationListener(); messageReceiver.AddListener(-1, notificationListener); //auth AuthorizeHciRequest request = new AuthorizeHciRequest(); request.ClientId = -1; request.Locale = "en-US"; var future = messageExecutor.Submit <AuthorizeHciResponse>(request); future.Wait(); AuthorizeHciResponse AuthorizeHciResponse = future.Value; int clientId = AuthorizeHciResponse.ClientId; System.Console.WriteLine("AuthorizeHciResponse precessed"); //login LoginRequest loginRequest = new LoginRequest(); loginRequest.UserLogin = "******"; loginRequest.UserPassword = "******"; loginRequest.ClientId = clientId; var loginResponcetask = messageExecutor.Submit <LoginResponse>(loginRequest); loginResponcetask.Wait(); //Lock vehicle example AcquireLockRequest lockRequest = new AcquireLockRequest { ClientId = clientId, ObjectType = "Vehicle", ObjectId = 2 }; var resultLock = messageExecutor.Submit <AcquireLockResponse>(lockRequest); resultLock.Wait(); // Click&Go example var sendCommandRequestGuided = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "guided", Subsystem = Subsystem.S_FLIGHT_CONTROLLER } }; sendCommandRequestGuided.Vehicles.Add(new Vehicle { Id = 2 }); var sendCommandResponseGuided = messageExecutor.Submit <SendCommandResponse>(sendCommandRequestGuided); sendCommandResponseGuided.Wait(); var sendCommandRequest = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "waypoint", Subsystem = Subsystem.S_FLIGHT_CONTROLLER } }; sendCommandRequest.Command.Arguments.AddRange(new CommandArgument[] { new CommandArgument { Code = "latitude", Value = new Value { DoubleValue = 0.994445232147517 } }, new CommandArgument { Code = "longitude", Value = new Value { DoubleValue = 0.4201742565140717 } }, new CommandArgument { Code = "altitude_agl", Value = new Value { DoubleValue = 5.0 } }, new CommandArgument { Code = "ground_speed", Value = new Value { DoubleValue = 5.0 } }, new CommandArgument { Code = "heading", Value = new Value { DoubleValue = 0.017453292519943295 } } }); sendCommandRequest.Vehicles.Add(new Vehicle { Id = 2 }); var sendCommandResponse = messageExecutor.Submit <SendCommandResponse>(sendCommandRequest); sendCommandResponse.Wait(); System.Console.WriteLine("Click&Go command sent"); //Import mission var byteArray = File.ReadAllBytes("Demo mission.xml"); ImportMissionFromXmlRequest importMissionRequest = new ImportMissionFromXmlRequest() { ClientId = clientId, MissionXml = byteArray }; var importMissionResponse = messageExecutor.Submit <ImportMissionFromXmlResponse>(importMissionRequest); importMissionResponse.Wait(); //mission contains imported mission from Demo mission.xml var mission = importMissionResponse.Value.Mission; System.Console.WriteLine("Demo mission.xml imported to UCS with name '{0}'", mission.Name); //Get all vehicles GetObjectListRequest getObjectListRequest = new GetObjectListRequest() { ClientId = clientId, ObjectType = "Vehicle", RefreshDependencies = true }; getObjectListRequest.RefreshExcludes.Add("PayloadProfile"); getObjectListRequest.RefreshExcludes.Add("Route"); var task = messageExecutor.Submit <GetObjectListResponse>(getObjectListRequest); task.Wait(); var list = task.Value; foreach (var v in list.Objects) { System.Console.WriteLine(string.Format("name: {0}; id: {1}; type: {2}", v.Vehicle.Name, v.Vehicle.Id, v.Vehicle.Type.ToString())); } Vehicle vehicle = task.Value.Objects.FirstOrDefault().Vehicle; //Get mission from server GetObjectRequest getMissionObjectRequest = new GetObjectRequest() { ClientId = clientId, ObjectType = "Mission", ObjectId = mission.Id, RefreshDependencies = true }; var getMissionObjectResponse = messageExecutor.Submit <GetObjectResponse>(getMissionObjectRequest); getMissionObjectResponse.Wait(); //missionFromUcs contains retrieved mission var missionFromUcs = getMissionObjectResponse.Value.Object.Mission; System.Console.WriteLine("mission id '{0}' retrieved from UCS with name '{1}'", mission.Id, missionFromUcs.Name); //vehicles in mission System.Console.WriteLine("Vehicles in mission:"); foreach (var vehicleMission in missionFromUcs.Vehicles) { System.Console.WriteLine(vehicleMission.Vehicle.Name); } missionFromUcs.Vehicles.Clear(); //Add vehicle to mission missionFromUcs.Vehicles.Add( new MissionVehicle { Vehicle = vehicle }); System.Console.WriteLine("Vehicles in mission after add vehicle:"); foreach (var vehicleMission in missionFromUcs.Vehicles) { System.Console.WriteLine(vehicleMission.Vehicle.Name); } //save mission CreateOrUpdateObjectRequest createOrUpdateObjectRequestForMission = new CreateOrUpdateObjectRequest() { ClientId = clientId, Object = new DomainObjectWrapper().Put(missionFromUcs, "Mission"), WithComposites = true, ObjectType = "Mission", AcquireLock = false }; var updateMissionTask = messageExecutor.Submit <CreateOrUpdateObjectResponse>(createOrUpdateObjectRequestForMission); updateMissionTask.Wait(); //Import route var byteArrayRoute = File.ReadAllBytes("Demo route for Copter.xml"); ImportRouteRequest importRouteRequest = new ImportRouteRequest() { ClientId = clientId, RouteData = byteArrayRoute, Filename = "Demo route for Copter.xml" }; var importRouteResponse = messageExecutor.Submit <ImportRouteResponse>(importRouteRequest); importRouteResponse.Wait(); //importedRoute contains imported route from Demo route for Copter.xml var importedRoute = importRouteResponse.Value.Route; System.Console.WriteLine("Demo route for Copter.xml imported to UCS with name '{0}'", importedRoute.Name); //Add vehicle profile to route GetObjectRequest requestVehicle = new GetObjectRequest() { ClientId = clientId, ObjectType = "Vehicle", ObjectId = 1, //EMU-COPTER-17 RefreshDependencies = true }; var responseVehicle = messageExecutor.Submit <GetObjectResponse>(requestVehicle); responseVehicle.Wait(); importedRoute.VehicleProfile = responseVehicle.Value.Object.Vehicle.Profile; //Add route to mission importedRoute.Mission = missionFromUcs; //Save route on server CreateOrUpdateObjectRequest routeSaveRequest = new CreateOrUpdateObjectRequest() { ClientId = clientId, Object = new DomainObjectWrapper().Put(importedRoute, "Route"), WithComposites = true, ObjectType = "Route", AcquireLock = false }; var updateRouteTask = messageExecutor.Submit <CreateOrUpdateObjectResponse>(routeSaveRequest); updateRouteTask.Wait(); System.Console.WriteLine("route '{0}' added to mission '{1}'", updateRouteTask.Value.Object.Route.Name, missionFromUcs.Name); //Get route from server GetObjectRequest getRouteObjectRequest = new GetObjectRequest() { ClientId = clientId, ObjectType = "Route", ObjectId = updateRouteTask.Value.Object.Route.Id, RefreshDependencies = true }; var geRouteObjectResponse = messageExecutor.Submit <GetObjectResponse>(getRouteObjectRequest); geRouteObjectResponse.Wait(); //routeFromUcs contains retrieved route var routeFromUcs = geRouteObjectResponse.Value.Object.Route; System.Console.WriteLine(string.Format("route id '{0}' retrieved from UCS with name '{1}'", updateRouteTask.Value.Object.Route.Id, routeFromUcs.Name)); //add action to route ActionDefinition actionDefenition = new ActionDefinition(); actionDefenition.HeadingDefinition = new HeadingDefinition(); actionDefenition.HeadingDefinition.Heading = 1.57079633; // 90 degrees actionDefenition.HeadingDefinition.RelativeToNorth = true; if (routeFromUcs.Segments.Count > 2) { routeFromUcs.Segments[1].ActionDefinitions.Add(actionDefenition); } System.Console.WriteLine(string.Format("action to route '{0}'", routeFromUcs.Name)); //save route CreateOrUpdateObjectRequest createOrUpdateRouteRequest = new CreateOrUpdateObjectRequest() { ClientId = clientId, Object = new DomainObjectWrapper().Put(routeFromUcs, "Route"), WithComposites = true, ObjectType = "Route", AcquireLock = false }; var createOrUpdateRouteResponseTask = messageExecutor.Submit <CreateOrUpdateObjectResponse>(createOrUpdateRouteRequest); createOrUpdateRouteResponseTask.Wait(); if (createOrUpdateRouteResponseTask.Value != null) { System.Console.WriteLine(string.Format("'{0}' route updated on UCS", routeFromUcs.Name)); } else { System.Console.WriteLine(string.Format("fail to update route '{0}' on UCS", routeFromUcs.Name)); } // Payload control SendCommandRequest requestPaload = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "direct_payload_control", Subsystem = Subsystem.S_GIMBAL, Silent = true, ResultIndifferent = true } }; requestPaload.Vehicles.Add(new Vehicle() { Id = vehicle.Id }); List <CommandArgument> listCommands = new List <CommandArgument>(); listCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 1 } }); listCommands.Add(new CommandArgument { Code = "pitch", Value = new Value() { DoubleValue = 0 } }); listCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); listCommands.Add(new CommandArgument { Code = "zoom", Value = new Value() { DoubleValue = 0 } }); requestPaload.Command.Arguments.AddRange(listCommands); var resultPayload = messageExecutor.Submit <SendCommandResponse>(requestPaload); resultPayload.Wait(); //update vehicle object CreateOrUpdateObjectRequest createOrUpdateObjectRequest = new CreateOrUpdateObjectRequest() { ClientId = clientId, Object = new DomainObjectWrapper().Put(vehicle, "Vehicle"), WithComposites = true, ObjectType = "Vehicle", AcquireLock = false }; var createOrUpdateObjectResponseTask = messageExecutor.Submit <CreateOrUpdateObjectResponse>(createOrUpdateObjectRequest); createOrUpdateObjectResponseTask.Wait(); //Vehicle notification subscription var eventSubscriptionWrapper = new EventSubscriptionWrapper(); eventSubscriptionWrapper.ObjectModificationSubscription = new ObjectModificationSubscription(); eventSubscriptionWrapper.ObjectModificationSubscription.ObjectId = vehicle.Id; eventSubscriptionWrapper.ObjectModificationSubscription.ObjectType = "Vehicle"; SubscribeEventRequest requestEvent = new SubscribeEventRequest(); requestEvent.ClientId = clientId; requestEvent.Subscription = eventSubscriptionWrapper; var responce = messageExecutor.Submit <SubscribeEventResponse>(requestEvent); responce.Wait(); var subscribeEventResponse = responce.Value; SubscriptionToken st = new SubscriptionToken(subscribeEventResponse.SubscriptionId, ( (notification) => { //Vehicle notification } ), eventSubscriptionWrapper); notificationListener.AddSubscription(st); // Get Telemetry for vehicle DateTime utcTime = DateTime.Now.ToUniversalTime(); DateTime posixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan span = utcTime - posixEpoch; var beginningMilliseconds = (long)span.TotalMilliseconds; GetTelemetryRequest telemetryRequest = new GetTelemetryRequest { ClientId = clientId, FromTime = beginningMilliseconds, Limit = 10, Vehicle = new Vehicle() { Id = 1 } }; var responseTelemetry = messageExecutor.Submit <GetTelemetryResponse>(telemetryRequest); responseTelemetry.Wait(); //Go to manual mode SendCommandRequest manualModeCommand = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "manual", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = false, ResultIndifferent = false } }; manualModeCommand.Vehicles.Add(new Vehicle() { Id = 2 }); var manualMode = messageExecutor.Submit <SendCommandResponse>(manualModeCommand); manualMode.Wait(); //Go to joystick mode SendCommandRequest joystickModeCommand = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "joystick", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = false, ResultIndifferent = false } }; joystickModeCommand.Vehicles.Add(new Vehicle() { Id = 2 }); var joystickMode = messageExecutor.Submit <SendCommandResponse>(joystickModeCommand); joystickMode.Wait(); // Vehicle control in joystick mode SendCommandRequest vehicleJoystickControl = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "direct_vehicle_control", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = true, ResultIndifferent = true } }; vehicleJoystickControl.Vehicles.Add(new Vehicle() { Id = 2 }); //List of current joystick values to send to vehicle. List <CommandArgument> listJoystickCommands = new List <CommandArgument>(); listJoystickCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "pitch", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "throttle", Value = new Value() { DoubleValue = 1 } }); vehicleJoystickControl.Command.Arguments.AddRange(listJoystickCommands); for (int i = 1; i < 11; i++) { var sendJoystickCommandResponse = messageExecutor.Submit <SendCommandResponse>(vehicleJoystickControl); resultPayload.Wait(); System.Console.WriteLine("Joystick command to go UP {0}", i); Thread.Sleep(1000); } //TelemetrySubscription var telemetrySubscriptionWrapper = new EventSubscriptionWrapper(); telemetrySubscriptionWrapper.TelemetrySubscription = new TelemetrySubscription(); SubscribeEventRequest requestTelemetryEvent = new SubscribeEventRequest(); requestTelemetryEvent.ClientId = clientId; requestTelemetryEvent.Subscription = telemetrySubscriptionWrapper; var responceTelemetry = messageExecutor.Submit <SubscribeEventResponse>(requestTelemetryEvent); responceTelemetry.Wait(); var subscribeEventResponseTelemetry = responceTelemetry.Value; SubscriptionToken stTelemetry = new SubscriptionToken(subscribeEventResponseTelemetry.SubscriptionId, ( (notification) => { foreach (Telemetry t in notification.Event.TelemetryEvent.Telemetry) { System.Console.WriteLine("Vehicle id: {0} Code: {1} Semantic {2} Subsystem {3} Value {4}", notification.Event.TelemetryEvent.Vehicle.Id, t.TelemetryField.Code, t.TelemetryField.Semantic, t.TelemetryField.Subsystem, getTelemetryValue(t.Value)); } } ), telemetrySubscriptionWrapper); notificationListener.AddSubscription(stTelemetry); //Log notification subscription var logSubscriptionWrapper = new EventSubscriptionWrapper(); logSubscriptionWrapper.ObjectModificationSubscription = new ObjectModificationSubscription(); logSubscriptionWrapper.ObjectModificationSubscription.ObjectType = "VehicleLogEntry"; SubscribeEventRequest requestLogEvent = new SubscribeEventRequest(); requestLogEvent.ClientId = clientId; requestLogEvent.Subscription = logSubscriptionWrapper; var responceLog = messageExecutor.Submit <SubscribeEventResponse>(requestLogEvent); var subscribeEventResponseLog = responceLog.Value; SubscriptionToken stLog = new SubscriptionToken(subscribeEventResponseLog.SubscriptionId, ( (notification) => { var eventType = notification.Event.ObjectModificationEvent.ModificationType; var eventLog = notification.Event.ObjectModificationEvent.Object.VehicleLogEntry; if (eventType == ModificationType.MT_CREATE) { DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime date = start.AddMilliseconds(eventLog.Time).ToLocalTime(); var command = eventLog.CommandArguments != null ? eventLog.CommandArguments.CommandCode : string.Empty; System.Console.WriteLine("LOG: {0} Vehicle id: {1} Command: {2} Message: {3}", date.ToString("HH:mm:ss"), eventLog.Vehicle.Id, command, eventLog.Message); } }), logSubscriptionWrapper); notificationListener.AddSubscription(stLog); //Object notification subscription, subscribe for mission changed var missionObjectSubscriptionWrapper = new EventSubscriptionWrapper(); missionObjectSubscriptionWrapper.ObjectModificationSubscription = new ObjectModificationSubscription(); missionObjectSubscriptionWrapper.ObjectModificationSubscription.ObjectType = "Mission"; SubscribeEventRequest requestMissionEvent = new SubscribeEventRequest(); requestMissionEvent.ClientId = clientId; requestMissionEvent.Subscription = missionObjectSubscriptionWrapper; var responceMission = messageExecutor.Submit <SubscribeEventResponse>(requestMissionEvent); var subscribeEventResponseMission = responceMission.Value; SubscriptionToken stMission = new SubscriptionToken(subscribeEventResponseMission.SubscriptionId, ( (notification) => { var eventType = notification.Event.ObjectModificationEvent.ModificationType; var missionObject = notification.Event.ObjectModificationEvent.Object.Mission; if (eventType == ModificationType.MT_UPDATE) { System.Console.WriteLine("Mission id: {0} updated", missionObject.Id); } }), missionObjectSubscriptionWrapper); notificationListener.AddSubscription(stMission); System.Console.ReadKey(); tcpClient.Close(); messageSender.Cancel(); messageReceiver.Cancel(); messageExecutor.Close(); notificationListener.Dispose(); }
static void Main(string[] args) { //Connect TcpClient tcpClient = new TcpClient(); tcpClient.Connect("localhost", 3334); MessageSender messageSender = new MessageSender(tcpClient.Session); MessageReceiver messageReceiver = new MessageReceiver(tcpClient.Session); MessageExecutor messageExecutor = new MessageExecutor(messageSender, messageReceiver, new InstantTaskScheduler()); messageExecutor.Configuration.DefaultTimeout = 10000; var notificationListener = new NotificationListener(); messageReceiver.AddListener(-1, notificationListener); //auth AuthorizeHciRequest request = new AuthorizeHciRequest(); request.ClientId = -1; request.Locale = "en-US"; var future = messageExecutor.Submit <AuthorizeHciResponse>(request); future.Wait(); AuthorizeHciResponse AuthorizeHciResponse = future.Value; int clientId = AuthorizeHciResponse.ClientId; System.Console.WriteLine("AuthorizeHciResponse precessed"); //login LoginRequest loginRequest = new LoginRequest(); loginRequest.UserLogin = "******"; loginRequest.UserPassword = "******"; loginRequest.ClientId = clientId; var loginResponcetask = messageExecutor.Submit <LoginResponse>(loginRequest); loginResponcetask.Wait(); // Id of the emu-copter is 2 var vehicleToControl = new Vehicle { Id = 3 }; TcpClientt.TcpListener server = new TcpClientt.TcpListener(IPAddress.Any, 8080); server.Start(); // run server byte[] ok = new byte[100]; ok = Encoding.Default.GetBytes("ok"); while (true) // бесконечный цикл обслуживания клиентов { TcpClientt.TcpClient client = server.AcceptTcpClient(); TcpClientt.NetworkStream ns = client.GetStream(); while (client.Connected) { byte[] msg = new byte[100]; int count = ns.Read(msg, 0, msg.Length); Console.Write(Encoding.Default.GetString(msg, 0, count)); string allMessage = Encoding.Default.GetString(msg); string result = allMessage.Substring(0, count - 1); var commandName = result.ToString().Split(":")[0]; switch (commandName) { case "takeoff_command": { Console.Write("got command: {0}", commandName); SendCommandRequest takeoff = new SendCommandRequest { ClientId = clientId, Command = new Command { Code = "takeoff_command", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = true, ResultIndifferent = true } }; takeoff.Vehicles.Add(vehicleToControl); var takeoffCmd = messageExecutor.Submit <SendCommandResponse>(takeoff); takeoffCmd.Wait(); Thread.Sleep(5000); ns.Write(ok, 0, ok.Length); break; } case "direct_vehicle_control": { Console.Write("got command: {0}", commandName); var commandArgs = result.Split(":")[1]; Console.Write("args of command: {0}", commandArgs); // Vehicle control in joystick mode SendCommandRequest vehicleJoystickControl = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "direct_vehicle_control", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = true, ResultIndifferent = true } }; vehicleJoystickControl.Vehicles.Add(vehicleToControl); List <CommandArgument> listJoystickCommands = new List <CommandArgument>(); var directionCommand = commandArgs.ToString().Split(",")[0]; string commandValueStr = commandArgs.ToString().Split(",")[1]; double commandValue = double.Parse(commandValueStr, System.Globalization.CultureInfo.InvariantCulture); switch (directionCommand) { case "roll": listJoystickCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = commandValue } }); listJoystickCommands.Add(new CommandArgument { Code = "pitch", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "throttle", Value = new Value() { DoubleValue = 0 } }); break; case "pitch": listJoystickCommands.Add(new CommandArgument { Code = "pitch", Value = new Value() { DoubleValue = commandValue } }); listJoystickCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "throttle", Value = new Value() { DoubleValue = 0 } }); break; case "throttle": listJoystickCommands.Add(new CommandArgument { Code = "throttle", Value = new Value() { DoubleValue = commandValue } }); listJoystickCommands.Add(new CommandArgument { Code = "pitch", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); break; case "yaw": listJoystickCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = commandValue } }); listJoystickCommands.Add(new CommandArgument { Code = "pitch", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 0 } }); listJoystickCommands.Add(new CommandArgument { Code = "throttle", Value = new Value() { DoubleValue = 0 } }); break; } vehicleJoystickControl.Command.Arguments.AddRange(listJoystickCommands); var sendJoystickCommandResponse = messageExecutor.Submit <SendCommandResponse>(vehicleJoystickControl); sendJoystickCommandResponse.Wait(); System.Console.WriteLine("Was sent {0}", commandValue); Thread.Sleep(2000); ns.Write(ok, 0, ok.Length); break; } case "set_relative_heading": { Console.Write("got command: {0}", commandName); var commandArgs = result.Split(":")[1]; Console.Write("args of command: {0}", commandArgs); // Vehicle control in joystick mode SendCommandRequest vehicleRelativeOffsetControl = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "set_relative_heading", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = false, ResultIndifferent = false } }; vehicleRelativeOffsetControl.Vehicles.Add(vehicleToControl); List <CommandArgument> listRelativeOffsetCommands = new List <CommandArgument>(); var directionCommand = commandArgs.ToString().Split(",")[0]; string commandValueStr = commandArgs.ToString().Split(",")[1]; double commandValue = double.Parse(commandValueStr, System.Globalization.CultureInfo.InvariantCulture); switch (directionCommand) { case "relative_heading": listRelativeOffsetCommands.Add(new CommandArgument { Code = "relative_heading", Value = new Value() { DoubleValue = commandValue } }); break; } vehicleRelativeOffsetControl.Command.Arguments.AddRange(listRelativeOffsetCommands); var sendRelativeOffsetCommandResponse = messageExecutor.Submit <SendCommandResponse>(vehicleRelativeOffsetControl); sendRelativeOffsetCommandResponse.Wait(); System.Console.WriteLine("Was sent {0}", commandValue); Thread.Sleep(2000); ns.Write(ok, 0, ok.Length); break; } case "set_position_offset": { Console.Write("got command: {0}", commandName); var commandArgs = result.Split(":")[1]; Console.Write("args of command: {0}", commandArgs); // Vehicle control in joystick mode SendCommandRequest vehicleJoystickOffset = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "set_position_offset", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = false, ResultIndifferent = false } }; vehicleJoystickOffset.Vehicles.Add(vehicleToControl); List <CommandArgument> listJoystickOffsetCommands = new List <CommandArgument>(); var directionCommand = commandArgs.ToString().Split(",")[0]; string commandValueStr = commandArgs.ToString().Split(",")[1]; double commandValue = double.Parse(commandValueStr, System.Globalization.CultureInfo.InvariantCulture); switch (directionCommand) { case "x": listJoystickOffsetCommands.Add(new CommandArgument { Code = "x", Value = new Value() { DoubleValue = commandValue } }); listJoystickOffsetCommands.Add(new CommandArgument { Code = "y", Value = new Value() { DoubleValue = 0 } }); listJoystickOffsetCommands.Add(new CommandArgument { Code = "z", Value = new Value() { DoubleValue = 0 } }); break; case "y": listJoystickOffsetCommands.Add(new CommandArgument { Code = "y", Value = new Value() { DoubleValue = commandValue } }); listJoystickOffsetCommands.Add(new CommandArgument { Code = "x", Value = new Value() { DoubleValue = 0 } }); listJoystickOffsetCommands.Add(new CommandArgument { Code = "z", Value = new Value() { DoubleValue = 0 } }); break; case "z": listJoystickOffsetCommands.Add(new CommandArgument { Code = "z", Value = new Value() { DoubleValue = commandValue } }); listJoystickOffsetCommands.Add(new CommandArgument { Code = "y", Value = new Value() { DoubleValue = 0 } }); listJoystickOffsetCommands.Add(new CommandArgument { Code = "x", Value = new Value() { DoubleValue = 0 } }); break; } vehicleJoystickOffset.Command.Arguments.AddRange(listJoystickOffsetCommands); var sendJoystickOffsetResponse = messageExecutor.Submit <SendCommandResponse>(vehicleJoystickOffset); sendJoystickOffsetResponse.Wait(); System.Console.WriteLine("Was sent {0}", commandValue); Thread.Sleep(2000); ns.Write(ok, 0, ok.Length); break; } case "payload_control": { Console.Write("got command: {0}", commandName); var commandArgs = result.ToString().Split(":")[1]; Console.Write("args of command: {0}", commandArgs); SendCommandRequest vehiclePayloadCommandRequest = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "payload_control", Subsystem = Subsystem.S_CAMERA, Silent = false, ResultIndifferent = false } }; vehiclePayloadCommandRequest.Vehicles.Add(vehicleToControl); List <CommandArgument> listPayloadCommands = new List <CommandArgument>(); var directionCommand = commandArgs.ToString().Split(",")[0]; string commandValueStr = commandArgs.ToString().Split(",")[1]; double commandValue = double.Parse(commandValueStr, System.Globalization.CultureInfo.InvariantCulture); switch (directionCommand) { case "tilt": listPayloadCommands.Add(new CommandArgument { Code = "tilt", Value = new Value() { DoubleValue = commandValue } }); listPayloadCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "zoom_level", Value = new Value() { DoubleValue = 0 } }); break; case "roll": listPayloadCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = commandValue } }); listPayloadCommands.Add(new CommandArgument { Code = "tilt", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "zoom_level", Value = new Value() { DoubleValue = 0 } }); break; case "zoom_level": listPayloadCommands.Add(new CommandArgument { Code = "zoom_level", Value = new Value() { DoubleValue = commandValue } }); listPayloadCommands.Add(new CommandArgument { Code = "tilt", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = 0 } }); break; case "yaw": listPayloadCommands.Add(new CommandArgument { Code = "yaw", Value = new Value() { DoubleValue = commandValue } }); listPayloadCommands.Add(new CommandArgument { Code = "tilt", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "roll", Value = new Value() { DoubleValue = 0 } }); listPayloadCommands.Add(new CommandArgument { Code = "zoom_level", Value = new Value() { DoubleValue = 0 } }); break; } vehiclePayloadCommandRequest.Command.Arguments.AddRange(listPayloadCommands); var sendPayloadCommandResponse = messageExecutor.Submit <SendCommandResponse>(vehiclePayloadCommandRequest); sendPayloadCommandResponse.Wait(); System.Console.WriteLine("Was sent {0}", commandValue); Thread.Sleep(2000); ns.Write(ok, 0, ok.Length); break; } case "land_command": { SendCommandRequest land = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "land_command", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = false, ResultIndifferent = false } }; land.Vehicles.Add(vehicleToControl); var landCmd = messageExecutor.Submit <SendCommandResponse>(land); landCmd.Wait(); Thread.Sleep(5000); ns.Write(ok, 0, ok.Length); break; } case "joystick": { SendCommandRequest joystickModeCommand = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "joystick", Subsystem = Subsystem.S_FLIGHT_CONTROLLER, Silent = false, ResultIndifferent = false } }; joystickModeCommand.Vehicles.Add(vehicleToControl); var joystickMode = messageExecutor.Submit <SendCommandResponse>(joystickModeCommand); joystickMode.Wait(); ns.Write(ok, 0, ok.Length); break; } case "manual": { break; } } } // System.Console.ReadKey(); // tcpClient.Close(); // messageSender.Cancel(); // messageReceiver.Cancel(); // messageExecutor.Close(); // notificationListener.Dispose(); } }
static void Main(string[] args) { //Connect TcpClient tcpClient = new TcpClient("localhost", 3334); MessageSender messageSender = new MessageSender(tcpClient.Session); MessageReceiver messageReceiver = new MessageReceiver(tcpClient.Session); MessageExecutor messageExecutor = new MessageExecutor(messageSender, messageReceiver, new InstantTaskScheduler()); messageExecutor.Configuration.DefaultTimeout = 10000; var notificationListener = new NotificationListener(); messageReceiver.AddListener(-1, notificationListener); //auth AuthorizeHciRequest request = new AuthorizeHciRequest(); request.ClientId = -1; request.Locale = "en-US"; var future = messageExecutor.Submit <AuthorizeHciResponse>(request); future.Wait(); AuthorizeHciResponse AuthorizeHciResponse = future.Value; int clientId = AuthorizeHciResponse.ClientId; System.Console.WriteLine("AuthorizeHciResponse precessed"); //login LoginRequest loginRequest = new LoginRequest(); loginRequest.UserLogin = "******"; loginRequest.UserPassword = "******"; loginRequest.ClientId = clientId; var loginResponcetask = messageExecutor.Submit <LoginResponse>(loginRequest); loginResponcetask.Wait(); // Click&Go example var sendCommandRequest = new SendCommandRequest { ClientId = clientId, Command = new UGCS.Sdk.Protocol.Encoding.Command { Code = "waypoint", Subsystem = Subsystem.S_FLIGHT_CONTROLLER } }; sendCommandRequest.Command.Arguments.AddRange(new CommandArgument[] { new CommandArgument { Code = "latitude", Value = new Value { DoubleValue = 0.994445232147517 } }, new CommandArgument { Code = "longitude", Value = new Value { DoubleValue = 0.4201742565140717 } }, new CommandArgument { Code = "altitude_agl", Value = new Value { DoubleValue = 5.0 } }, new CommandArgument { Code = "ground_speed", Value = new Value { DoubleValue = 5.0 } }, new CommandArgument { Code = "heading", Value = new Value { DoubleValue = 0.017453292519943295 } } }); sendCommandRequest.Vehicles.Add(new Vehicle { Id = 2 }); var sendCommandResponse = messageExecutor.Submit <SendCommandResponse>(sendCommandRequest); sendCommandResponse.Wait(); System.Console.WriteLine("Click&Go command sent"); //Import mission var byteArray = File.ReadAllBytes("Demo mission.xml"); ImportMissionFromXmlRequest importMissionRequest = new ImportMissionFromXmlRequest() { ClientId = clientId, MissionXml = byteArray }; var importMissionResponse = messageExecutor.Submit <ImportMissionFromXmlResponse>(importMissionRequest); importMissionResponse.Wait(); //mission contains imported mission from Demo mission.xml var mission = importMissionResponse.Value.Mission; System.Console.WriteLine("Demo mission.xml imported to UCS with name '{0}'", mission.Name); //Get mission from server GetObjectRequest getMissionObjectRequest = new GetObjectRequest() { ClientId = clientId, ObjectType = "Mission", ObjectId = mission.Id, RefreshDependencies = true }; var getMissionObjectResponse = messageExecutor.Submit <GetObjectResponse>(getMissionObjectRequest); getMissionObjectResponse.Wait(); //missionFromUcs contains retrieved mission var missionFromUcs = getMissionObjectResponse.Value.Object.Mission; System.Console.WriteLine("mission id '{0}' retrieved from UCS with name '{1}'", mission.Id, missionFromUcs.Name); //Import route var byteArrayRoute = File.ReadAllBytes("Demo route for Copter.xml"); ImportRouteRequest importRouteRequest = new ImportRouteRequest() { ClientId = clientId, RouteData = byteArrayRoute, Filename = "Demo route for Copter.xml" }; var importRouteResponse = messageExecutor.Submit <ImportRouteResponse>(importRouteRequest); importRouteResponse.Wait(); //importedRoute contains imported route from Demo route for Copter.xml var importedRoute = importRouteResponse.Value.Route; System.Console.WriteLine("Demo route for Copter.xml imported to UCS with name '{0}'", importedRoute.Name); //Add vehicle profile to route GetObjectRequest requestVehicle = new GetObjectRequest() { ClientId = clientId, ObjectType = "Vehicle", ObjectId = 1, //EMU-COPTER-17 RefreshDependencies = true }; var responseVehicle = messageExecutor.Submit <GetObjectResponse>(requestVehicle); responseVehicle.Wait(); importedRoute.VehicleProfile = responseVehicle.Value.Object.Vehicle.Profile; //Add route to mission importedRoute.Mission = missionFromUcs; //Save route on server CreateOrUpdateObjectRequest routeSaveRequest = new CreateOrUpdateObjectRequest() { ClientId = clientId, Object = new DomainObjectWrapper().Put(importedRoute, "Route"), WithComposites = true, ObjectType = "Route", AcquireLock = false }; var updateRouteTask = messageExecutor.Submit <CreateOrUpdateObjectResponse>(routeSaveRequest); updateRouteTask.Wait(); System.Console.WriteLine("route '{0}' added to mission '{1}'", updateRouteTask.Value.Object.Route.Name, missionFromUcs.Name); //Get route from server GetObjectRequest getRouteObjectRequest = new GetObjectRequest() { ClientId = clientId, ObjectType = "Route", ObjectId = updateRouteTask.Value.Object.Route.Id, RefreshDependencies = true }; var geRouteObjectResponse = messageExecutor.Submit <GetObjectResponse>(getRouteObjectRequest); geRouteObjectResponse.Wait(); //routeFromUcs contains retrieved route var routeFromUcs = geRouteObjectResponse.Value.Object.Route; System.Console.WriteLine(string.Format("route id '{0}' retrieved from UCS with name '{1}'", updateRouteTask.Value.Object.Route.Id, routeFromUcs.Name)); //Get all vehicles GetObjectListRequest getObjectListRequest = new GetObjectListRequest() { ClientId = clientId, ObjectType = "Vehicle", RefreshDependencies = true }; getObjectListRequest.RefreshExcludes.Add("Avatar"); getObjectListRequest.RefreshExcludes.Add("PayloadProfile"); getObjectListRequest.RefreshExcludes.Add("Route"); var task = messageExecutor.Submit <GetObjectListResponse>(getObjectListRequest); task.Wait(); var list = task.Value; foreach (var v in list.Objects) { System.Console.WriteLine(string.Format("name: {0}; id: {1}; type: {2}", v.Vehicle.Name, v.Vehicle.Id, v.Vehicle.Type.ToString())); } Vehicle vehicle = task.Value.Objects.FirstOrDefault().Vehicle; //update vehicle object CreateOrUpdateObjectRequest createOrUpdateObjectRequest = new CreateOrUpdateObjectRequest() { ClientId = clientId, Object = new DomainObjectWrapper().Put(vehicle, "Vehicle"), WithComposites = true, ObjectType = "Vehicle", AcquireLock = false }; var createOrUpdateObjectResponseTask = messageExecutor.Submit <CreateOrUpdateObjectResponse>(createOrUpdateObjectRequest); createOrUpdateObjectResponseTask.Wait(); //Vehicle notification subscription var eventSubscriptionWrapper = new EventSubscriptionWrapper(); eventSubscriptionWrapper.ObjectModificationSubscription = new ObjectModificationSubscription(); eventSubscriptionWrapper.ObjectModificationSubscription.ObjectId = vehicle.Id; eventSubscriptionWrapper.ObjectModificationSubscription.ObjectType = "Vehicle"; SubscribeEventRequest requestEvent = new SubscribeEventRequest(); requestEvent.ClientId = clientId; requestEvent.Subscription = eventSubscriptionWrapper; var responce = messageExecutor.Submit <SubscribeEventResponse>(requestEvent); responce.Wait(); var subscribeEventResponse = responce.Value; SubscriptionToken st = new SubscriptionToken(subscribeEventResponse.SubscriptionId, ( (notification) => { //Vehicle notification } ), eventSubscriptionWrapper); notificationListener.AddSubscription(st); // Get Telemetry for vehicle DateTime utcTime = DateTime.Now.ToUniversalTime(); DateTime posixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan span = utcTime - posixEpoch; var beginningMilliseconds = (long)span.TotalMilliseconds; GetTelemetryRequest telemetryRequest = new GetTelemetryRequest { ClientId = clientId, FromTime = beginningMilliseconds, Limit = 10, Vehicle = new Vehicle() { Id = 1 } }; var responseTelemetry = messageExecutor.Submit <GetTelemetryResponse>(telemetryRequest); responseTelemetry.Wait(); //TelemetrySubscription var telemetrySubscriptionWrapper = new EventSubscriptionWrapper(); telemetrySubscriptionWrapper.TelemetrySubscription = new TelemetrySubscription(); SubscribeEventRequest requestTelemetryEvent = new SubscribeEventRequest(); requestTelemetryEvent.ClientId = clientId; requestTelemetryEvent.Subscription = telemetrySubscriptionWrapper; var responceTelemetry = messageExecutor.Submit <SubscribeEventResponse>(requestTelemetryEvent); responceTelemetry.Wait(); var subscribeEventResponseTelemetry = responceTelemetry.Value; SubscriptionToken stTelemetry = new SubscriptionToken(subscribeEventResponseTelemetry.SubscriptionId, ( (notification) => { foreach (var t in notification.Event.TelemetryEvent.Telemetry) { System.Console.WriteLine("Vehicle id: {0} Type: {1} Value {2}", t.Vehicle.Id, t.Type.ToString(), t.Value); } } ), telemetrySubscriptionWrapper); notificationListener.AddSubscription(stTelemetry); System.Console.ReadKey(); tcpClient.Close(); messageSender.Cancel(); messageReceiver.Cancel(); messageExecutor.Close(); notificationListener.Dispose(); }
static void Main(string[] args) { //Connect TcpClient tcpClient = new TcpClient("localhost", 3334); MessageSender messageSender = new MessageSender(tcpClient.Session); MessageReceiver messageReceiver = new MessageReceiver(tcpClient.Session); MessageExecutor messageExecutor = new MessageExecutor(messageSender, messageReceiver, new InstantTaskScheduler()); messageExecutor.Configuration.DefaultTimeout = 10000; var notificationListener = new NotificationListener(); messageReceiver.AddListener(-1, notificationListener); //auth AuthorizeHciRequest request = new AuthorizeHciRequest(); request.ClientId = -1; request.Locale = "en-US"; var future = messageExecutor.Submit <AuthorizeHciResponse>(request); future.Wait(); AuthorizeHciResponse AuthorizeHciResponse = future.Value; int clientId = AuthorizeHciResponse.ClientId; //login LoginRequest loginRequest = new LoginRequest(); loginRequest.UserLogin = "******"; loginRequest.UserPassword = "******"; loginRequest.ClientId = clientId; var loginResponcetask = messageExecutor.Submit <LoginResponse>(loginRequest); loginResponcetask.Wait(); //Get all vehicles GetObjectListRequest getObjectListRequest = new GetObjectListRequest() { ClientId = clientId, ObjectType = "Vehicle", RefreshDependencies = true }; getObjectListRequest.RefreshExcludes.Add("Avatar"); getObjectListRequest.RefreshExcludes.Add("PayloadProfile"); getObjectListRequest.RefreshExcludes.Add("Route"); var task = messageExecutor.Submit <GetObjectListResponse>(getObjectListRequest); task.Wait(); var list = task.Value; foreach (var v in list.Objects) { System.Console.WriteLine(string.Format("name: {0}; id: {1}; type: {2}", v.Vehicle.Name, v.Vehicle.Id, v.Vehicle.Type.ToString())); } Vehicle vehicle = task.Value.Objects.FirstOrDefault().Vehicle; //update vehicle object CreateOrUpdateObjectRequest createOrUpdateObjectRequest = new CreateOrUpdateObjectRequest() { ClientId = clientId, Object = new DomainObjectWrapper().Put(vehicle, "Vehicle"), WithComposites = true, ObjectType = "Vehicle", AcquireLock = false }; var createOrUpdateObjectResponseTask = messageExecutor.Submit <CreateOrUpdateObjectResponse>(createOrUpdateObjectRequest); createOrUpdateObjectResponseTask.Wait(); //Vehicle notification subscription var eventSubscriptionWrapper = new EventSubscriptionWrapper(); eventSubscriptionWrapper.ObjectModificationSubscription = new ObjectModificationSubscription(); eventSubscriptionWrapper.ObjectModificationSubscription.ObjectId = vehicle.Id; eventSubscriptionWrapper.ObjectModificationSubscription.ObjectType = "Vehicle"; SubscribeEventRequest requestEvent = new SubscribeEventRequest(); requestEvent.ClientId = clientId; requestEvent.Subscription = eventSubscriptionWrapper; var responce = messageExecutor.Submit <SubscribeEventResponse>(requestEvent); responce.Wait(); var subscribeEventResponse = responce.Value; SubscriptionToken st = new SubscriptionToken(subscribeEventResponse.SubscriptionId, ( (notification) => { //Vehicle notification } ), eventSubscriptionWrapper); notificationListener.AddSubscription(st); //TelemetrySubscription var telemetrySubscriptionWrapper = new EventSubscriptionWrapper(); telemetrySubscriptionWrapper.TelemetrySubscription = new TelemetrySubscription(); SubscribeEventRequest requestTelemetryEvent = new SubscribeEventRequest(); requestTelemetryEvent.ClientId = clientId; requestTelemetryEvent.Subscription = telemetrySubscriptionWrapper; var responceTelemetry = messageExecutor.Submit <SubscribeEventResponse>(requestTelemetryEvent); responceTelemetry.Wait(); var subscribeEventResponseTelemetry = responceTelemetry.Value; SubscriptionToken stTelemetry = new SubscriptionToken(subscribeEventResponseTelemetry.SubscriptionId, ( (notification) => { foreach (var t in notification.Event.TelemetryEvent.Telemetry) { System.Console.WriteLine("Vehicle id: {0} Type: {1} Value {2}", t.Vehicle.Id, t.Type.ToString(), t.Value); } } ), telemetrySubscriptionWrapper); notificationListener.AddSubscription(stTelemetry); System.Console.ReadKey(); Environment.Exit(1); }