protected override VehicleMode Interpret(HeartbeatPayload heartbeat) { var customMode = (PlaneMode)(heartbeat.CustomMode); return(new VehicleMode { BaseMode = heartbeat.BaseMode, CustomMode = new VehicleCustomMode { Name = customMode.GetDisplayName(), Value = (uint)customMode } }); }
protected abstract VehicleClass InterpretVehicleClass(HeartbeatPayload heartbeatPacket);
protected abstract VehicleMode Interpret(HeartbeatPayload heartbeat);
public Px4VehicleMode(HeartbeatPayload payload) { CustomMainMode = (CustomMainMode)((payload.CustomMode & 0xFF0000) >> 16); CustomSubMode = (CustomSubMode)((payload.CustomMode & 0xFF000000) >> 24); ModeFlag = payload.BaseMode; }
//new Thread(async() // => await HeartbeatSerivce()).Start(); public async Task HeartbeatSerivce(int bufferSize = 1024, bool isDebugging = false) { ClientWebSocket ws = new ClientWebSocket(); CancellationToken ct = new CancellationToken(); ArraySegment <byte> receiveBuffer = new ArraySegment <byte>(new byte[bufferSize]); ArraySegment <byte> sendBuffer = new ArraySegment <byte>(new byte[bufferSize]); await ws.ConnectAsync(new Uri("wss://gateway.discord.gg/?encoding=json&v=6"), ct); while (ws.State == WebSocketState.Connecting) { Thread.Sleep(10); } bool hasHeartbeat = false; int heartbeatInterval = 0; long previousHeartbeat = DateTimeOffset.Now.ToUnixTimeMilliseconds(); GenericPayload lastPayload = new GenericPayload(); while (ws.State == WebSocketState.Open) { if (hasHeartbeat == false) { await ws.ReceiveAsync(receiveBuffer, ct); string jsonData = Encoding.ASCII.GetString(receiveBuffer.ToArray()).Replace(" ", ""); GatewayPayload gateway = JsonConvert.DeserializeObject <GatewayPayload>(jsonData, JsonSettings); HeartbeatPayload heartbeat = JsonConvert.DeserializeObject <HeartbeatPayload>(gateway.d.ToString(), JsonSettings); lastPayload = new GenericPayload() { op = gateway.op, d = gateway.s, }; heartbeatInterval = heartbeat.heartbeat_interval; hasHeartbeat = true; } else { if (previousHeartbeat + heartbeatInterval - 1500 <= DateTimeOffset.Now.ToUnixTimeMilliseconds()) { GenericPayload payload = new GenericPayload() { op = 1, d = lastPayload.d }; string jsonData = JsonConvert.SerializeObject(payload); byte[] data = Encoding.ASCII.GetBytes(jsonData); sendBuffer = new ArraySegment <byte>(data); await ws.SendAsync(sendBuffer, WebSocketMessageType.Text, true, ct); Console.WriteLine("HEARTBEAT"); await ws.ReceiveAsync(receiveBuffer, ct); data = receiveBuffer.ToArray(); int i = 0; for (i = data.Length - 1; data[i] == 0; i--) { ; } byte[] responseData = new byte[i]; Buffer.BlockCopy(data, 0, responseData, 0, responseData.Length); jsonData = Encoding.ASCII.GetString(responseData); Console.WriteLine(jsonData); previousHeartbeat = DateTimeOffset.Now.ToUnixTimeMilliseconds(); } } receiveBuffer = new ArraySegment <byte>(new byte[bufferSize]); Thread.Sleep(1); } }
/// <summary> /// Post to the server a collection of heartbeat messages generated by the /// Robots from a Machine /// </summary> /// <remarks> /// Every 30 seconds the UiPath service running on a Robot Machine posts a /// collection of heartbeat messages (one for each Robot hosted on the /// Machine). /// The response is a collection of commands specific to all the Robots defined /// on that Machine, including the ones that were added in the meanwhile. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='payload'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <HeartbeatResponse> HeartbeatAsync(this IRobotsService operations, HeartbeatPayload payload, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { using (var _result = await operations.HeartbeatWithHttpMessagesAsync(payload, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Called by RobotSvc to disconnect all Robots. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='payload'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task StopServiceAsync(this IRobotsService operations, HeartbeatPayload payload, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { (await operations.StopServiceWithHttpMessagesAsync(payload, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
protected override VehicleClass InterpretVehicleClass(HeartbeatPayload heartbeatPacket) { return(VehicleClass.Plane); }
/// <summary> /// Called by RobotSvc to disconnect all Robots. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task StopServiceAsync(this IRobotsService operations, HeartbeatPayload body = default(HeartbeatPayload), CancellationToken cancellationToken = default(CancellationToken)) { (await operations.StopServiceWithHttpMessagesAsync(body, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Called by RobotSvc to disconnect all Robots. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// </param> public static void StopService(this IRobotsService operations, HeartbeatPayload body = default(HeartbeatPayload)) { operations.StopServiceAsync(body).GetAwaiter().GetResult(); }
/// <summary> /// Acquires licensing runtimes, updates machine's session state and reporting /// time. /// </summary> /// <remarks> /// Every 30 seconds the UiPath service sends a heartbeat. /// The response is a collection of commands specific to that machine. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <HeartbeatResponse> HeartbeatV2Async(this IRobotsService operations, HeartbeatPayload body = default(HeartbeatPayload), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.HeartbeatV2WithHttpMessagesAsync(body, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Acquires licensing runtimes, updates machine's session state and reporting /// time. /// </summary> /// <remarks> /// Every 30 seconds the UiPath service sends a heartbeat. /// The response is a collection of commands specific to that machine. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// </param> public static HeartbeatResponse HeartbeatV2(this IRobotsService operations, HeartbeatPayload body = default(HeartbeatPayload)) { return(operations.HeartbeatV2Async(body).GetAwaiter().GetResult()); }
/// <summary> /// Post to the server a collection of heartbeat messages generated by the /// Robots from a Machine /// </summary> /// <remarks> /// Every 30 seconds the UiPath service running on a Robot Machine posts a /// collection of heartbeat messages (one for each Robot hosted on the /// Machine). /// The response is a collection of commands specific to all the Robots defined /// on that Machine, including the ones that were added in the meanwhile. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='payload'> /// </param> public static HeartbeatResponse Heartbeat(this IRobotsService operations, HeartbeatPayload payload) { return(operations.HeartbeatAsync(payload).GetAwaiter().GetResult()); }
/// <summary> /// Called by RobotSvc to disconnect all Robots. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='payload'> /// </param> public static void StopService(this IRobotsService operations, HeartbeatPayload payload) { operations.StopServiceAsync(payload).GetAwaiter().GetResult(); }