Пример #1
0
 public static GPSLocation ToGpsLocation(GpsMeasurement gpsMeasurement)
 {
     return(new GPSLocation
     {
         deviceName = $"Radio {gpsMeasurement.RadioID}", // TODO, okay for ciabata?
         Latitude = gpsMeasurement.Latitude,
         Longitude = gpsMeasurement.Longitude,
         RadioID = gpsMeasurement.RadioID,
         Rssi = (float)(gpsMeasurement.Rssi ?? 0)
     });
 }
Пример #2
0
        private async Task PostGpsLocation(GpsMeasurement gpsMeasurement)
        {
            try
            {
                // Send to CiaBatac
                await ciaBataController.PostGpsLocation(CiaBataMapper.ToGpsLocation(gpsMeasurement));

                // Save to database
                await Repository.InsertOrUpdateAsync(DatabaseMapper.Map(gpsMeasurement));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error posting gps");
            }
        }
Пример #3
0
        private void DeviceLocationChanged(object sender, DeviceLocationChangedEventArgs e)
        {
            try
            {
                logger.Info("DeviceLocationChanged");

                foreach (var gpsInfo in e.GPSData)
                {
                    try
                    {
                        int deviceID = gpsInfo.DeviceID;

                        GpsMeasurement gpsMeasurement = new GpsMeasurement
                        {
                            Latitude  = gpsInfo.Latitude,
                            Longitude = gpsInfo.Longitude,
                            Timestamp = gpsInfo.InfoDate.ToString(), // right formatting?
                            Rssi      = gpsInfo.Rssi,
                            DeviceID  = deviceID,
                        };

                        DeviceInfo deviceInfo;
                        if (!GetDeviceInfoByDeviceID(deviceID, out deviceInfo))
                        {
                            logger.Warn($"Could not find deviceInfo to update GPSfor device with, created it for deviceID {deviceID} ");
                            devices.TryAdd(deviceID, new DeviceInfo(deviceID));
                        }

                        int radioID = deviceInfo.RadioID;
                        gpsMeasurement.RadioID = radioID;
                        deviceInfo.GpsLocations.Push(gpsMeasurement);

                        // Previous existing logging magic
                        StringBuilder build = new StringBuilder();
                        build.Append("DeviceLocationChanged");
                        build.Append("Altitude: " + gpsInfo.Altitude + " ");
                        build.Append("Description: " + gpsInfo.Description + " ");
                        build.Append("DeviceID: " + gpsInfo.DeviceID + " ");
                        build.Append("Direction: " + gpsInfo.Direction + " ");
                        build.Append("GpsSource: " + gpsInfo.GpsSource + " ");
                        build.Append("InfoDate: " + gpsInfo.InfoDate.ToString() + " ");
                        build.Append("InfoDateUtc: " + gpsInfo.InfoDateUtc.ToString() + " ");
                        build.Append("Latitude: " + gpsInfo.Latitude.ToString() + " ");
                        build.Append("Name: " + gpsInfo.Name + " ");
                        build.Append("Radius: " + gpsInfo.Radius.ToString() + " ");
                        build.Append("ReportId: " + gpsInfo.ReportId.ToString() + " ");
                        build.Append("Rssi: " + gpsInfo.Rssi.ToString() + " ");
                        build.Append("Speed: " + gpsInfo.Speed.ToString() + " ");
                        build.Append("StopTime: " + gpsInfo.StopTime.ToString() + " ");

                        logger.Info(build.ToString());

                        PostGpsLocation(gpsMeasurement);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, $"Adding location failed for deviceID {gpsInfo?.DeviceID}");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
        }