internal void update(RadioUpdate lastUpdate, TimeSpan elapsedSpan) { this.lastUpdate = lastUpdate; if (elapsedSpan.TotalSeconds > 5) { radioActive.Fill = new SolidColorBrush(Colors.Red); radioLabel.Content = "No Radio"; radioFrequency.Text = "Unknown"; radioVolume.IsEnabled = false; up10.IsEnabled = false; up1.IsEnabled = false; up01.IsEnabled = false; down10.IsEnabled = false; down1.IsEnabled = false; down01.IsEnabled = false; //reset dragging just incase this.dragging = false; } else { if (this.radioId == lastUpdate.selected) { radioActive.Fill = new SolidColorBrush(Colors.Green); } else { radioActive.Fill = new SolidColorBrush(Colors.Orange); } RadioInformation currentRadio = lastUpdate.radios[this.radioId]; if (currentRadio.modulation == 2) //intercom { radioFrequency.Text = "INTERCOM"; } else { radioFrequency.Text = (currentRadio.frequency / MHz).ToString("0.000") + (currentRadio.modulation == 0 ? "AM" : "FM"); } radioLabel.Content = lastUpdate.radios[this.radioId].name; if (lastUpdate.hasRadio) { radioVolume.IsEnabled = false; up10.IsEnabled = false; up1.IsEnabled = false; up01.IsEnabled = false; down10.IsEnabled = false; down1.IsEnabled = false; down01.IsEnabled = false; //reset dragging just incase this.dragging = false; } else { radioVolume.IsEnabled = true; up10.IsEnabled = true; up1.IsEnabled = true; up01.IsEnabled = true; down10.IsEnabled = true; down1.IsEnabled = true; down01.IsEnabled = true; } if (this.dragging == false) { radioVolume.Value = (currentRadio.volume * 100.0); } } }
internal void update(RadioUpdate lastUpdate, TimeSpan elapsedSpan) { this.lastUpdate = lastUpdate; if (elapsedSpan.TotalSeconds > 5) { radioActive.Fill = new SolidColorBrush(Colors.Red); radioLabel.Content = "No Radio"; radioFrequency.Text = "Unknown"; radioVolume.IsEnabled = false; up10.IsEnabled = false; up1.IsEnabled = false; up01.IsEnabled = false; down10.IsEnabled = false; down1.IsEnabled = false; down01.IsEnabled = false; //reset dragging just incase this.dragging = false; } else { if (this.radioId == lastUpdate.selected) { radioActive.Fill = new SolidColorBrush(Colors.Green); } else { radioActive.Fill = new SolidColorBrush(Colors.Orange); } RadioInformation currentRadio = lastUpdate.radios[this.radioId]; if(currentRadio.modulation == 2) //intercom { radioFrequency.Text = "INTERCOM"; } else { radioFrequency.Text = (currentRadio.frequency / MHz).ToString("0.000") + (currentRadio.modulation == 0 ? "AM" : "FM"); } radioLabel.Content = lastUpdate.radios[this.radioId].name; if (lastUpdate.hasRadio) { radioVolume.IsEnabled = false; up10.IsEnabled = false; up1.IsEnabled = false; up01.IsEnabled = false; down10.IsEnabled = false; down1.IsEnabled = false; down01.IsEnabled = false; //reset dragging just incase this.dragging = false; } else { radioVolume.IsEnabled = true; up10.IsEnabled = true; up1.IsEnabled = true; up01.IsEnabled = true; down10.IsEnabled = true; down1.IsEnabled = true; down01.IsEnabled = true; } if (this.dragging == false) { radioVolume.Value = (currentRadio.volume * 100.0); } } }
private void SetupRadioStatus() { //setup UDP this.udpClient = new UdpClient(); this.udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); this.udpClient.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. IPAddress multicastaddress = IPAddress.Parse("239.255.50.10"); udpClient.JoinMulticastGroup(multicastaddress); IPEndPoint localEp = new IPEndPoint(IPAddress.Any, UdpClientBroadcastPort); this.udpClient.Client.Bind(localEp); Task.Run(() => { using (udpClient) { while (!end) { try { //IPEndPoint object will allow us to read datagrams sent from any source. var remoteEndPoint = new IPEndPoint(IPAddress.Any, UdpClientBroadcastPort); udpClient.Client.ReceiveTimeout = 10000; var receivedResults = udpClient.Receive(ref remoteEndPoint); lastUpdate = JsonConvert.DeserializeObject<RadioUpdate>(Encoding.UTF8.GetString(receivedResults)); lastUpdateTime = DateTime.Now; } catch (Exception e) { Console.Out.WriteLine(e.ToString()); } } this.udpClient.Close(); } }); Task.Run(() => { while (!end) { Thread.Sleep(100); //check if (lastUpdate != null && lastUpdate.name != null) { Application.Current.Dispatcher.Invoke(new Action(() => { //check if current long elapsedTicks = DateTime.Now.Ticks - lastUpdateTime.Ticks; TimeSpan elapsedSpan = new TimeSpan(elapsedTicks); if (lastUpdate.allowNonPlayers) { this.muteStatusNonUsers.Fill = new SolidColorBrush(Colors.Red); this.muteStatusNonUsers.ToolTip = "Mute Non Players OFF"; } else { this.muteStatusNonUsers.Fill = new SolidColorBrush(Colors.Green); this.muteStatusNonUsers.ToolTip = "Mute Non Players ON"; } if (lastUpdate.caMode) { this.caModeStatus.Fill = new SolidColorBrush(Colors.Green); this.caModeStatus.ToolTip = "Radio ON - CA / JTAC / Spectator Mode"; } else { this.caModeStatus.Fill = new SolidColorBrush(Colors.Red); this.caModeStatus.ToolTip = "Radio OFF - CA / JTAC / Spectator Mode"; } radio1.update(lastUpdate, elapsedSpan); radio2.update(lastUpdate, elapsedSpan); radio3.update(lastUpdate, elapsedSpan); })); } } }); }
private void SetupRadioStatus() { //setup UDP this.udpClient = new UdpClient(); this.udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); this.udpClient.ExclusiveAddressUse = false; // only if you want to send/receive on same machine. IPAddress multicastaddress = IPAddress.Parse("239.255.50.10"); udpClient.JoinMulticastGroup(multicastaddress); IPEndPoint localEp = new IPEndPoint(IPAddress.Any, UdpClientBroadcastPort); this.udpClient.Client.Bind(localEp); Task.Run(() => { using (udpClient) { while (!end) { try { //IPEndPoint object will allow us to read datagrams sent from any source. var remoteEndPoint = new IPEndPoint(IPAddress.Any, UdpClientBroadcastPort); udpClient.Client.ReceiveTimeout = 10000; var receivedResults = udpClient.Receive(ref remoteEndPoint); lastUpdate = JsonConvert.DeserializeObject <RadioUpdate>(Encoding.UTF8.GetString(receivedResults)); lastUpdateTime = DateTime.Now; } catch (Exception e) { Console.Out.WriteLine(e.ToString()); } } this.udpClient.Close(); } }); Task.Run(() => { while (!end) { Thread.Sleep(100); //check if (lastUpdate != null && lastUpdate.name != null) { Application.Current.Dispatcher.Invoke(new Action(() => { //check if current long elapsedTicks = DateTime.Now.Ticks - lastUpdateTime.Ticks; TimeSpan elapsedSpan = new TimeSpan(elapsedTicks); if (lastUpdate.allowNonPlayers) { this.muteStatusNonUsers.Fill = new SolidColorBrush(Colors.Red); this.muteStatusNonUsers.ToolTip = "Mute Non Players OFF"; } else { this.muteStatusNonUsers.Fill = new SolidColorBrush(Colors.Green); this.muteStatusNonUsers.ToolTip = "Mute Non Players ON"; } if (lastUpdate.caMode) { this.caModeStatus.Fill = new SolidColorBrush(Colors.Green); this.caModeStatus.ToolTip = "Radio ON - CA / JTAC / Spectator Mode"; } else { this.caModeStatus.Fill = new SolidColorBrush(Colors.Red); this.caModeStatus.ToolTip = "Radio OFF - CA / JTAC / Spectator Mode"; } radio1.update(lastUpdate, elapsedSpan); radio2.update(lastUpdate, elapsedSpan); radio3.update(lastUpdate, elapsedSpan); })); } } }); }