public void SignalStrengthTest() { // arrange var balloonMessage = CreateBalloonMessage(); // act var compactMessageString = balloonMessage.ToCompactMessage(); compactMessageString += ":-97.1"; output.WriteLine("Compact: " + compactMessageString); var jsonMessage = JsonConvert.SerializeObject(balloonMessage); output.WriteLine(jsonMessage); var serializedBalloonMessage = BalloonMessage.FromCompactMessage(compactMessageString); var jsonResultMessage = JsonConvert.SerializeObject(serializedBalloonMessage); output.WriteLine(jsonResultMessage); // verify serializedBalloonMessage.SignalStrength.ShouldBe(-97.1); }
private void SerialDataReceived(object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string receivedData = sp.ReadLine(); Logger.LogInfo("SerialData : " + receivedData); if (receivedData.StartsWith('-')) { // ignore, serial debug messages. return; } if (!String.IsNullOrEmpty(receivedData)) { try { var balloonMessage = BalloonMessage.FromCompactMessage(receivedData); SendBalloonMessage(balloonMessage).Wait(); } catch (Exception ex) { Logger.LogInfo("Bad serial message: " + receivedData); Logger.LogException(ex); } } }
public void CompactSerializationTest() { // arrange var balloonMessage = CreateBalloonMessage(); // act var compactMessageString = balloonMessage.ToCompactMessage(); output.WriteLine("Compact: " + compactMessageString); var jsonMessage = JsonConvert.SerializeObject(balloonMessage); output.WriteLine(jsonMessage); var serializedBalloonMessage = BalloonMessage.FromCompactMessage(compactMessageString); var jsonResultMessage = JsonConvert.SerializeObject(serializedBalloonMessage); output.WriteLine(jsonResultMessage); // verify serializedBalloonMessage.State.ShouldBe(balloonMessage.State); serializedBalloonMessage.Timestamp.ShouldBe(balloonMessage.Timestamp.AddTicks(-(balloonMessage.Timestamp.Ticks % TimeSpan.TicksPerSecond))); serializedBalloonMessage.AveAscent.ShouldBe(balloonMessage.AveAscent); serializedBalloonMessage.AveDescent.ShouldBe(balloonMessage.AveDescent); serializedBalloonMessage.FlightId.ShouldBe(balloonMessage.FlightId); serializedBalloonMessage.BurstAltitude.ShouldBe(balloonMessage.BurstAltitude); var diffLat = Math.Abs(serializedBalloonMessage.Location.lat - Math.Round(balloonMessage.Location.lat, 5)); diffLat.ShouldBeLessThan(0.0001); var diffLong = Math.Abs(serializedBalloonMessage.Location.@long - Math.Round(balloonMessage.Location.@long, 5)); diffLong.ShouldBeLessThan(0.0001); serializedBalloonMessage.Location.alt.ShouldBe(Math.Round(balloonMessage.Location.alt, 2)); serializedBalloonMessage.Temperature.ShouldBe(balloonMessage.Temperature); serializedBalloonMessage.Pressure.ShouldBe(balloonMessage.Pressure); serializedBalloonMessage.Humidity.ShouldBe(balloonMessage.Humidity); serializedBalloonMessage.Location.climb.ShouldBe(Math.Round(balloonMessage.Location.climb, 2)); serializedBalloonMessage.Location.speed.ShouldBe(Math.Round(balloonMessage.Location.speed, 1)); }