/// <summary> /// Publishes a new time-bound observation value of type 'Position' to the server. /// </summary> /// <param name="observationId">Observation identifier.</param> /// <param name="timestamp">Date and time in UTC.</param> /// <param name="value">Position coordinates according with reference to WGS84.</param> /// <returns>True if successful, False otherwise.</returns> public bool PublishObservation(int observationId, DateTime timestamp, Position value) { PositionObservation o = new PositionObservation() { Timestamp = timestamp, Value = value }; string json = JsonConvert.SerializeObject(o); return(PublishObservationMessage(observationId, Encoding.UTF8.GetBytes(json))); }
public void PositionObservation_Insert_Read() { using (var repo = CreateRepository()) { Assert.IsTrue(repo.CreateCatalog <Session>()); Assert.IsTrue(repo.CreateCatalog <ObservationGroup>()); Assert.IsTrue(repo.CreateCatalog <PositionObservation>()); var start = DateTime.UtcNow; var session = repo.NewEntity <Session>(start, TimeSpan.FromSeconds(1)); Assert.IsNotNull(session); Assert.AreEqual(1, session.Id); Assert.AreEqual(start, session.StartTime); Assert.AreEqual(1000, session.Duration.TotalMilliseconds); var group = repo.NewEntity <ObservationGroup>(session, start); Assert.IsNotNull(group); Assert.AreEqual(1, group.Id); Assert.AreEqual(start, group.Timestamp); group = repo.Read <ObservationGroup>(1); Assert.IsNotNull(group); Assert.AreEqual(1, group.Id); Assert.AreEqual(start, group.Timestamp); var stateString = "mid:-1;x:0;y:0;z:0;mpry:0,0,0;pitch:1;roll:2;yaw:3;vgx:4;vgy:5;vgz:6;templ:7;temph:8;tof:9;h:10;bat:11;baro:12.13;time:14;agx:15.16;agy:17.18;agz:19.20;"; var state = new TelloState(stateString); var observation = new PositionObservation(group, state); Assert.AreEqual(1, repo.Insert(observation)); observation = repo.Read <PositionObservation>(1); Assert.IsNotNull(observation); Assert.AreEqual(1, observation.Id); Assert.AreEqual(state.Timestamp, observation.Timestamp); Assert.AreEqual(1, observation.GroupId); Assert.AreEqual(10, observation.AltitudeAGLInCm); Assert.AreEqual(12.13, observation.BarometricPressueInCm); Assert.AreEqual(0, observation.Heading); Assert.AreEqual(0, observation.X); Assert.AreEqual(0, observation.Y); } }
private ObservationPackage GetBufferedObservations(out int maxId) { maxId = -1; ObservationPackageBuilder builder = new ObservationPackageBuilder(); using (LiteDatabase db = new LiteDatabase(_liteDBPathName)) { var col = db.GetCollection <BufferedObservation>(_OBSBUF_NAME); var records = col.Find(c => c.Uploaded == false).OrderBy(c => c.Id); IEnumerable <BufferedObservation> observations = null; if (UploadRowLimit > 0) { observations = records.Take(UploadRowLimit); } else { observations = records; } foreach (BufferedObservation bo in observations) { maxId = bo.Id; if (bo.Value != null) { Observation observation = null; switch ((DataType)(bo.DataType)) { case DataType.Boolean: observation = new BooleanObservation() { Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseBooleanValue(bo.Value) }; break; case DataType.Double: observation = new DoubleObservation() { Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseDoubleValue(bo.Value) }; break; case DataType.Integer: observation = new IntegerObservation() { Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseIntegerValue(bo.Value) }; break; case DataType.Position: observation = new PositionObservation() { Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParsePositionValue(bo.Value) }; break; case DataType.String: observation = new StringObservation() { Timestamp = bo.Timestamp, Value = bo.Value }; break; case DataType.Statistics: observation = new StatisticsObservation() { Timestamp = bo.Timestamp, Value = DataTypeStringConverter.ParseStatisticsValue(bo.Value) }; break; default: throw new NotSupportedException("Unknown data type: " + bo.DataType.ToString()); } IdentifiedObservation io = new IdentifiedObservation() { ObservationId = bo.ObservationId, Observation = observation }; builder.Append(io); } } } return(builder.GetAsObservationPackage()); }