private void DeviceFounder(HeartbeatPacket packet)
        {
            MavlinkDevice newItem = null;

            _deviceListLock.EnterUpgradeableReadLock();
            var founded = _info.Find(_ => _.Packet.SystemId == packet.SystemId && _.Packet.ComponenId == packet.ComponenId);

            if (founded != null)
            {
                founded.Touch();
            }
            else
            {
                _deviceListLock.EnterWriteLock();
                newItem = new MavlinkDevice(packet);
                _info.Add(newItem);
                _deviceListLock.ExitWriteLock();
                Logger.Info($"Found new device {JsonConvert.SerializeObject(newItem.GetInfo())}");
            }
            _deviceListLock.ExitUpgradeableReadLock();

            if (newItem != null)
            {
                _foundDeviceSubject.OnNext(newItem.GetInfo());
            }
        }
Ejemplo n.º 2
0
        public void threadTick()
        {
            this.process();
            if (!this._client.Connected)
            {
                return;
            }

            int currentTime = (int)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            if ((currentTime - lastUpdate) >= 5000)
            {
                lastUpdate = currentTime;
                HeartbeatPacket packet = new HeartbeatPacket();
                packet.tps    = 20; //Calculation needed
                packet.load   = 20; //-||-
                packet.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - startTime;
                packet.encode();
                sendDataPacket(packet, packet.Id);
            }

            int finalTime = (int)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            if ((finalTime - currentTime) >= 30000)
            {
                reconnect();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends heartbeat packet to server.
        /// </summary>
        public bool SendHeartbeat()
        {
            try
            {
                //create packet
                HeartbeatPacket packet = new HeartbeatPacket(
                    gameTitle: _config.GameTitle,
                    gameVersion: _config.GameVersion,
                    sourceIP: _config.LocalIP,
                    destinationIP: _config.ServerIP,
                    playerName: _localPlayer.Name,
                    count: _heartbeatsSent + 1);

                //send packet
                _client.SendPacket(packet);
                _heartbeatsSent++;

                //success
                return(true);
            }
            catch (Exception ex)
            {
                _tcpErrors++;
                Log.Write("SendHeartbeat: Error sending data");
                ErrorHandler.LogError(ex);
                return(false);
            }
        }
Ejemplo n.º 4
0
        public void HeartbeatPacket_Initialization()
        {
            const IncomingGamePacketType ExpectedPacketType = IncomingGamePacketType.Heartbeat;

            IActionWithoutContentInfo actionWithoutContentInfo = new HeartbeatPacket();

            Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}.");
        }
Ejemplo n.º 5
0
        private void OnHeartBeat(HeartbeatPacket heartbeatPacket)
        {
            _lastHearteat = DateTime.Now;
            _link.Upgrade();
            _heartBeat.OnNext(heartbeatPacket.Payload);
            _armed.OnNext(heartbeatPacket.Payload.BaseMode.HasFlag(MavModeFlag.MavModeFlagSafetyArmed));

            _disposeCancel.Token.Register(() => _armed.Dispose());
            _disposeCancel.Token.Register(() => _heartBeat.Dispose());
        }
 public Task HeartbeatLoop()
 {
     return(Task.Run(async() =>
     {
         while (this != null)
         {
             Send(HeartbeatPacket.Request());
             await Task.Delay(30000); // every 30 seconds
         }
     }));
 }
Ejemplo n.º 7
0
 void HandleHeartbeat(Session session, HeartbeatPacket p)
 {
     session.RefreshHeartbeat();
     log.Info($"heartbeat: id={session.ID}");
 }
 public MavlinkDevice(HeartbeatPacket packet)
 {
     Packet = packet;
     Touch();
 }
 public MavlinkDeviceInfo(HeartbeatPacket packet)
 {
     _packet = packet;
 }