Ejemplo n.º 1
0
        public async Task<ActionResult> Post([FromBody] Rootobject rootobject)
        {
            var playload = Convert.FromBase64String(rootobject.PayloadRaw);

            var cow = await _context.Cows.FirstOrDefaultAsync(x => x.HardwareSerial == rootobject.HardwareSerial);
            if (cow == null)
            {
                cow = new Cow
                {
                    Name = "Marguerite",
                    HardwareSerial = rootobject.HardwareSerial
                };

                await _context.Cows.AddAsync(cow);
            }

            var dateTime = new DateTime(rootobject.Metadata.Time.Ticks, DateTimeKind.Utc);

            var gpsEntry = new GpsEntry
            {
                Cow = cow,
                DateTime = dateTime,
                LatitudeDeg = Convert.ToInt32(playload[0]),
                LatitudeMinutes = Convert.ToInt32(playload[1]),
                LatitudeMinutesDecimals = Convert.ToInt32($"{Convert.ToInt32(playload[2]):00}" + $"{Convert.ToInt32(playload[3]):00}"),
                LatitudeDirection = Convert.ToChar(playload[4]),
                LongitudeDeg = Convert.ToInt32(playload[5]),
                LongitudeMinutes = Convert.ToInt32(playload[6]),
                LongitudeMinutesDecimals = Convert.ToInt32($"{Convert.ToInt32(playload[7]):00}" + $"{Convert.ToInt32(playload[8]):00}"),
                LongitudeDirection = Convert.ToChar(playload[9])
            };

            cow.GpsEntries.Add(gpsEntry);

            var temperatureEntry = new TemperatureEntry
            {
                Cow = cow,
                DateTime = dateTime,
                Temperature = Convert.ToSingle(Convert.ToInt32(playload[10]) + "." + Convert.ToInt32(playload[11]))
            };

            cow.TemperatureEntries.Add(temperatureEntry);

            var positionEntry = new PositionEntry
            {
                Cow = cow,
                DateTime = dateTime,
                IsUp = Convert.ToBoolean(Convert.ToInt32(playload[12])),
                X = Convert.ToInt32(playload[13]),
                Y = Convert.ToInt32(playload[14]),
                Z = Convert.ToInt32(playload[15])
            };

            cow.PositionEntries.Add(positionEntry);

            await _context.SaveChangesAsync();

            return Ok();
        }
Ejemplo n.º 2
0
 public GpsMeasurement(GpsEntry g)
 {
     //TODO JV
     RadioID   = g.RadioId ?? 0;
     Timestamp = DateTimeMapper.ToString(g.Timestamp);
     Latitude  = g.Latitude;
     Longitude = g.Longitude;
     Rssi      = g.Rssi;
 }
Ejemplo n.º 3
0
        public static GpsEntry Map(GpsMeasurement gpsMeasurement)
        {
            GpsEntry entry = new GpsEntry
            {
                RadioId   = gpsMeasurement.RadioID,
                DeviceId  = gpsMeasurement.DeviceID,
                Latitude  = gpsMeasurement.Latitude,
                Longitude = gpsMeasurement.Longitude,
                Rssi      = gpsMeasurement.Rssi,
                Timestamp = DateTimeMapper.ToDateTime(gpsMeasurement.Timestamp) ?? DateTime.Now,
            };

            return(entry);
        }