Example #1
0
        public void Load()
        {
            try
            {
                _infoService.Query();
                LogDevice();

                _logger.Debug("Sending telemetry");
                Task.WaitAll(
                    _telemetry.SendTelemetry(new UserEngagementModel
                {
                    DeviceId = _infoService.DeviceId,
                    AppName  = "kflearning",
                    Event    = "app_start"
                }),
                    _telemetry.SendIdentification(new DeviceIdentificationModel
                {
                    DeviceId     = _infoService.DeviceId,
                    CPU          = _infoService.CPU,
                    RAM          = _infoService.RAM,
                    OS           = _infoService.OS,
                    Architecture = _infoService.Architecture
                })
                    );
            }
            catch (Exception ex)
            {
                _logger.Error("Cannot post telemetry data", ex);
            }
        }
Example #2
0
 public void Load()
 {
     try
     {
         _infoService.Query();
         Task.WaitAll(
             _telemetry.SendTelemetry(new UserEngagementModel
         {
             DeviceId = _infoService.DeviceId,
             AppName  = "kfmaintenance",
             Event    = "app_start"
         }),
             _telemetry.SendIdentification(new DeviceIdentificationModel
         {
             DeviceId     = _infoService.DeviceId,
             CPU          = _infoService.CPU,
             RAM          = _infoService.RAM,
             OS           = _infoService.OS,
             Architecture = _infoService.Architecture
         })
             );
     }
     catch (Exception)
     {
         // ignore
     }
 }
        private async Task SendTelemetry(Models.FlightData flightData)
        {
            if (_settings.CurrentFlightId == null)
            {
                await _messagesService.AddMessageAsync(
                    new Message("Not sending telemetry as no current flight ID is set."));

                return;
            }
            try
            {
                var lat             = (float)flightData.CurrentPosition.Latitude;
                var lon             = (float)flightData.CurrentPosition.Longitude;
                var alt             = (ushort)flightData.CurrentPosition.Altitude;
                var courseInRadians = flightData.CurrentPosition.Course / 180 * Math.PI;
                var xVel            = (float)(Math.Sin(courseInRadians) * flightData.CurrentPosition.Speed);
                var yVel            = (float)(Math.Cos(courseInRadians) * flightData.CurrentPosition.Speed);
                var zVel            = flightData.CurrentPosition.VerticalSpeed;


                // Create dataStructure
                var udpMessage = new UavPositionReport
                {
                    GpsTimestamp      = DateTime.UtcNow,
                    Pos               = new Position(lat, lon, 0),
                    Alt               = new Altitude(alt, AltitudeDatum.Agl, 1),
                    Velocity          = new Velocity(xVel, yVel, zVel, 1),
                    IsAirborne        = AirborneStatus.Airborne,
                    SatellitesVisible = 3
                };

                var telemetryId = Guid.Parse(_settings.CurrentTelemetryId);
                var telemetry   = new TelemetryEvent <UavPositionReport>(telemetryId, udpMessage)
                {
                    SequenceNumber = _sequenceNumber
                };

                var message = string.Format($"Sending Telemetry {flightData.CurrentPosition.Latitude}, {flightData.CurrentPosition.Longitude}, {flightData.CurrentPosition.Altitude}");
                await _messagesService.AddMessageAsync(new Message(message));

                _client.SendTelemetry(telemetry, _settings.TelemetryHostName, _settings.TelemetryPortNumber, _settings.EncryptionKey);
                _sequenceNumber += 1;
            }
            catch (Exception)
            {
                await _messagesService.AddMessageAsync(new Message("ERROR: Sending telemetry failed."));
            }
        }