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 RegisterHotKey(int hotkey_id, HotKey hk) { if (WindowHandle != null && hk != null) { uint VK_KEY = Convert.ToUInt32(hk.vkKey); uint MOD_KEY = 0x4000; if (hk.alt) { MOD_KEY = 0x0001; } if (hk.ctrl) { MOD_KEY = MOD_KEY | 0x0002; } if (hk.shift) { MOD_KEY = MOD_KEY | 0x0004; } if (!NativeMethods.RegisterHotKey(WindowHandle, hotkey_id, MOD_KEY, VK_KEY)) { BalloonMessage.ShowMessage("Hotkey failed to register", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Warning); } } Console.WriteLine(@"Registered"); }
/// <summary> /// Receive a Balloon Message, need to transmit the data in a new TrackerMessage /// </summary> /// <param name="message"></param> /// <returns></returns> public async Task <bool> Receive(BalloonMessage balloonMessage, IModuleClient moduleClient) { Logger.LogInfo($"Received Balloon Message."); UpdatePacketReceiveHistory(true); packetReceiptTimer.Change(packetReceiptInterval, packetReceiptInterval); this.FlightId = balloonMessage.FlightId; var trackerMessage = new TrackerMessage() { Location = this.Location, DeviceName = this.DeviceName, FlightId = balloonMessage.FlightId, PacketReceivedPercentage = CalculatePacketReceivedPercentage() }; try { Message balloonMessageRaw = new Message(balloonMessage.ToRawBytes()); await moduleClient.SendEventAsync(TrackerOutputName, balloonMessageRaw); Message trackerMessageRaw = new Message(trackerMessage.ToRawBytes()); await moduleClient.SendEventAsync(TrackerOutputName, trackerMessageRaw); Logger.LogInfo($"transmitted message: {JsonConvert.SerializeObject(trackerMessage)}."); } catch (Exception ex) { // Todo - wire in with application insights Logger.LogWarning($"Error Transmitter tracker message: {ex.Message}"); return(false); } return(true); }
public void OnReceive(BalloonMessage message) { var compactMessage = message.ToCompactMessage(); if (compactMessage.Length > MaxMessageSize) { Logger.LogWarning($"Max message size exceeded. {compactMessage.Length} {compactMessage}"); } if (!serialPort.IsOpen) { // attempt to reopen the serial port if it has been closed. Initialize().Wait(); } if (serialPort.IsOpen) { lock (transmitLock) { serialPort.WriteLine(compactMessage); } } else { Logger.LogError("Serial port is closed and could not be reopened. Message not sent: " + compactMessage); } }
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 static BalloonDocument Create(BalloonMessage message) { return(new BalloonDocument() { AveAscent = message.AveAscent, AveDescent = message.AveDescent, BurstAltitude = message.BurstAltitude, State = message.State, Track = (message.Location != null) ? message.Location.track : 0, GpsMode = (message.Location != null) ? message.Location.mode : 0, GpsTime = (message.Location != null) ? message.Location.time : "unknown", Speed = (message.Location != null) ? message.Location.speed : 0, Climb = (message.Location != null) ? message.Location.climb : 0, FlightId = message.FlightId, TimestampUTC = message.Timestamp, partitionid = message.partitionid, Latitude = (message.Location != null) ? message.Location.lat : 0, Longitude = (message.Location != null) ? message.Location.@long : 0, Altitude = (message.Location != null) ? message.Location.alt : 0, Geopoint = (message.Location != null) ? new Point(message.Location.@long, message.Location.lat) : null, TrackerSource = message.DeviceName, Humidity = message.Humidity, Pressure = message.Pressure, Temperature = message.Temperature, SignalStrength = message.SignalStrength }); }
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)); }
private async Task <bool> SendBalloonMessage(BalloonMessage balloonMessage) { Message message = new Message(balloonMessage.ToRawBytes()); try { await moduleClient.SendEventAsync(SerialOutputName, message); Logger.LogInfo($"transmitted message: {JsonConvert.SerializeObject(balloonMessage)}."); } catch (Exception ex) { Logger.LogError($"Failed to transmit iot balloon message."); Logger.LogException(ex); return(false); } return(true); }
public void FlushDNSCache() { BalloonMessage.SimpleSideMessage("DNS Resolver Cleared", $"Status: {DnsFlushResolverCache()}"); }
private void getprivIP() { BalloonMessage.SimpleSideMessage("Local IP Address", GetIPAddresses.GetLocalAddress); }
private void getPubIP() { BalloonMessage.SimpleSideMessage("Public IP Address", GetIPAddresses.GetPublicAddress); }
/// <summary> /// Shows the balloon message. /// </summary> /// <param name="balloonMessage">The balloon message.</param> public void ShowBalloonMessage(BalloonMessage balloonMessage) { this.MainTrayIcon.ShowBalloonTip(balloonMessage.Title, balloonMessage.Message, balloonMessage.Icon); }
public void Say(BalloonMessage msg) { switch (msg) { case BalloonMessage.Fire: { var rnd = new Random (); if (rnd.Next (2) == 0) { Speak ("撃てーーー!", 500); } var clip = new SoundClip ("media/0001_さとうささら_撃てーーー.wav"); Sound.AddClip (clip, true); break; } case BalloonMessage.Destroy: { Speak ("一気撃破!!", 2000); var clip = new SoundClip ("media/0000_さとうささら_一機、撃破.wav"); Sound.AddClip (clip, true); break; } case BalloonMessage.Complete: { Speak ("敵殲滅を確認", 30000); var clip = new SoundClip ("media/0002_さとうささら_敵機殲滅を確認しました.wav"); Sound.AddClip (clip, true); break; } default: Speak ("default", 3000); break; ; } }