using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using Telerik.WinControls.UI; using System.Collections; using Nini.Config; using Telerik.WinControls; using SafeMobileLib; using MotoTRBO_XNL_Cmd; using System.Threading; using System.Diagnostics; namespace MotoTrbo_GW { public partial class radioForm : ShapeNew { private bool radioON=false; System.Threading.Timer _gatewayStatusTimer = null; private bool onOFFpreStatus = false; private int radioID; private int radioIMEI; private int radioNetworkID; private IConfigSource source = null; public string DBServer, DBSchema, DBUser, DBPass, DBPort; DBgatewaysManager db4gateway; List zonesList; List channelList; private Boolean Collapse = false; ArrayList radioIPlist; //voice device private int selectedOUTDevice; private string selectedOUTDeviceName; private int selectedINDevice; private string selectedINDeviceName; public ArrayList soundOUTDevices; public ArrayList soundINDevices; //IP's private string radioIP; private string messageBusIP; private int messageBusPort = 17233; public RadioComHandler rcHandler =null; private PingThread ping; RadioConnection radioC; private object _locker = new object(); #region LINX /// /// Returns the Radio gateway ID /// public int RadioID { get { return radioID; } } /// /// Returns the Radio gateway IP /// public string RadioIP { get { return radioIP; } } #endregion #region constructor public radioForm(int RadioID, string radioIP, int radioImei) { selectedZoneNr = 0; selectedChannelNr = 0; radioID = RadioID; this.radioIP = radioIP; this.radioIMEI = radioImei; //constructor stuff constructorHelper(); //load config LoadConfig(); //DB manager for zones and channels db4gateway = new DBgatewaysManager(DBServer, DBSchema, DBUser, DBPass, DBPort); //add zones LoadZones(); //add channels LoadChannels(); iniVoiceComponents(); SafeMobileLib.Utils.WriteLine("Constructor done for radio with ID:" + radioID); // add default to texboxes string voiceMulticastIP = "224.10." + Main.GWID.ToString() + "." + radioID.ToString(); tbVoiceIP.Text = voiceMulticastIP; tbVoicePort.Text = "17234"; tbRadioIMEI.Text = radioIMEI.ToString(); tbMulticastIp.Text = Main.messageBusIP; tbMulticastPort.Text = Main.messageBusPort; _gatewayStatusTimer = new System.Threading.Timer(_gatewayStatusTimer_Elapsed, null, 3000, 10000); Thread PingThreadObj = new Thread(new ThreadStart(watchForPing)); PingThreadObj.IsBackground = true; PingThreadObj.Start(); } void _gatewayStatusTimer_Elapsed(object obj) { if (radioON) { //send Gateway On command to MSG bus string test = "#500#" + Main.GWID + "#" + radioID + "#ON#"; MessageBusHandler.SendOnMsgBuss("0.0", test); } } #region ping events private bool Connect_in_progress = false; void watchForPing() { bool status = false; while (true) { if(Main.RadioComArr.ContainsKey(radioIP)) status = true; else status =false; if (!status) { if (radioON) { SafeMobileLib.Utils.WriteLine("Ping failed and gw still ON -> shuting GW down to sync"); onOFFpreStatus = true; PingCallbackTurnOff d = new PingCallbackTurnOff(PingFallowUPTurnOff); this.Invoke(d, new object[] { }); } else { //SafeMobileLib.Utils.WriteLine("Ping failed and gw OFF -> already sync"); } } else { if (!radioON) { if (onOFFpreStatus) { if (!Connect_in_progress) { PingCallback d = new PingCallback(PingFallowUP); this.Invoke(d, new object[] { }); } } } else { //SafeMobileLib.Utils.WriteLine("Ping success and gw ON -> already sync"); } } Thread.Sleep(5000); } } void ping_OnNewPingComplete(bool status, string interfaceIP) { if (!status) { if (radioON) { SafeMobileLib.Utils.WriteLine("Ping failed and gw still ON -> shuting GW down to sync"); onOFFpreStatus = true; PingCallbackTurnOff d = new PingCallbackTurnOff(PingFallowUPTurnOff); this.Invoke(d, new object[] { }); } else { //SafeMobileLib.Utils.WriteLine("Ping failed and gw OFF -> already sync"); } } else { if (!radioON) { if (onOFFpreStatus) { if (!Connect_in_progress) { PingCallback d = new PingCallback(PingFallowUP); this.Invoke(d, new object[] { }); } } } else { //SafeMobileLib.Utils.WriteLine("Ping success and gw ON -> already sync"); } } } delegate void PingCallback(); public void PingFallowUP() { System.Threading.Thread.Sleep(500); btONOFF.PerformClick(); } delegate void PingCallbackTurnOff(); public void PingFallowUPTurnOff() { TurnOff(true); } #endregion private void constructorHelper() { soundOUTDevices = new ArrayList(); soundINDevices = new ArrayList(); // load default configuration selectedOUTDevice = 0; selectedOUTDeviceName = ""; selectedINDevice = 0; selectedINDeviceName = ""; InitializeComponent(); ((Telerik.WinControls.Primitives.BorderPrimitive)(this.btCollapse.GetChildAt(2))).ForeColor = System.Drawing.Color.Transparent; ((Telerik.WinControls.Primitives.BorderPrimitive)(this.ImgRad.GetChildAt(2))).ForeColor = System.Drawing.Color.Transparent; ((Telerik.WinControls.Primitives.BorderPrimitive)(this.ImgStat.GetChildAt(2))).ForeColor = System.Drawing.Color.Transparent; btONOFF.Text = "ON"; cbChan.Enabled = false; cbZone.Enabled = false; //this before loadSetup radioIPlist = new ArrayList(); radioIPlist.Add(this.radioIP); //radioIPlist = RadioStuff.getAllRadiosIPs(); cbRadioIP.DataSource = radioIPlist; lbStatusScreen.Text = ""; } #endregion private void EnableAudioSettingsPanels(bool value) { listPlayBDevices.Enabled = value; listRecBDevices.Enabled = value; btnSaveRadioSettings.Enabled = value; } #region events public void AuthDone() { btONOFF.Text = "OFF"; ImgRad.Image = global::MotoTrbo_GW.Properties.Resources.radioGREEN; ImgStat.Image = global::MotoTrbo_GW.Properties.Resources.green_status; EnableAudioSettingsPanels(false); cbChan.Enabled = true; cbZone.Enabled = true; radioON = true; btONOFF.Enabled = true; rcHandler.SendZoneChannelChange(0,0); Connect_in_progress = false; //send on message to MSG bus string test = "#100#" + Main.GWID + "." + radioID + "#1#"; MessageBusHandler.SendOnMsgBuss("0.0", test); try { SafeMobileLib.Utils.WriteEventLog("Safemobile", "Station with IP:" + radioIP + " is ON", EventLogEntryType.Information, 31021); } catch (Exception ex) { SafeMobileLib.Utils.WriteLine("Unable to write log Event ex:" + ex.ToString()); } } delegate void ChannelEventCallback(int zoneNr, int channelNr); void rcHandler_OnChannelEvent(int zoneNr,int channelNr) { ChannelEventCallback d = new ChannelEventCallback(ChannelEvent); this.Invoke(d, new object[] {zoneNr, channelNr }); } public void ChannelEvent(int zoneNr, int channelNr) { try { selectedChannelNr = channelNr; selectedZoneNr = zoneNr; int cnt = -1; SafeMobileLib.Utils.WriteLine("GW== received zone nr " + zoneNr); SafeMobileLib.Utils.WriteLine("GW== received channel nr " + channelNr); // zone stuff if (cbZone.Items.Count > 0 && cbZone.Items.Count >=zoneNr) { cbZone.Text = cbZone.Items[zoneNr - 1].Text; lbZone.Text = cbZone.Items[zoneNr - 1].Text; cnt = -1; foreach (RadMenuItem obj in cbZone.Items) { cnt++; if (obj.Name == cbZone.Items[zoneNr - 1].Name) { obj.IsChecked = true; } else obj.IsChecked = false; } } //channel stuff LoadChannels(); if (cbChan.Items.Count > 0 && cbChan.Items.Count >= channelNr) { cbChan.Text = cbChan.Items[channelNr - 1].Text; lbChannel.Text = cbChan.Items[channelNr - 1].Text; cnt = -1; foreach (RadMenuItem obj in cbChan.Items) { cnt++; if (obj.Name == cbChan.Items[channelNr - 1].Name) { obj.IsChecked = true; } else obj.IsChecked = false; } } } catch (Exception ex) { SafeMobileLib.Utils.WriteLine(ex.ToString()); RadMessageBox.Show("Invalid channel....switching to channel 1 zone 1"); rcHandler.SendZoneChannelChange(1, 1); } } delegate void PropertyChangedCallback(RADIO_STATUS rStatus); void rcHandler_PropertyChanged(object sender, PropertyChangedEventArgs e) { SafeMobileLib.Utils.WriteLine("New value for radio status:" + ((RadioComHandler)sender).RadioStatusProp); PropertyChangedCallback d = new PropertyChangedCallback(RadioStatusChanged); this.Invoke(d, new object[] { ((RadioComHandler)sender).RadioStatusProp }); } private void RadioStatusChanged(RADIO_STATUS rStatus) { lbRadio_Status.Text = rStatus.ToString(); } #endregion #region configs private void LoadConfig() { try { source = new IniConfigSource(Main.CFG_FILE); DBServer = Main.DBServer;//source.Configs["Database"].Get("IP"); DBSchema = Main.DBSchema;//source.Configs["Database"].Get("Schema"); DBUser = Main.DBUser;//source.Configs["Database"].Get("User"); DBPort = Main.DBPort;//source.Configs["Database"].Get("Port"); DBPass = Main.DBPass;//source.Configs["Database"].Get("Passwd"); //messageBusIP = source.Configs["MessageBus"].Get("ip"); //messageBusPort = Convert.ToInt32(source.Configs["MessageBus"].Get("port")); //tbMulticastIp.Text = messageBusIP; if (source.Configs["Voice"].Contains("SelectedOutDevice" + radioID.ToString())) { selectedOUTDeviceName = source.Configs["Voice"].Get("SelectedOutDevice" + radioID.ToString()); selectedINDeviceName = source.Configs["Voice"].Get("SelectedInDevice" + radioID.ToString()); onOFFpreStatus = Convert.ToBoolean(source.Configs["Voice"].Get("onOFF" + radioID.ToString())); SafeMobileLib.Utils.WriteLine("settings loaded for radio :" + radioID); } else { SafeMobileLib.Utils.WriteLine("No settings found for radio :" + radioID); } } catch (Exception e) { SafeMobileLib.Utils.WriteLine(e.Message + " " + e.StackTrace + " " + e.Source); } } public void SaveConfig() { //SafeMobileLib.Utils.WriteLine("saving settings for " + radioIMEI.ToString() + " IP:" + cbRadioIP.SelectedValue); source = new IniConfigSource(Main.CFG_FILE); if (source.Configs["Voice"].Contains("SelectedOutDevice" + radioID.ToString())) { SafeMobileLib.Utils.WriteLine("Saving settings for radio ID:" + radioID); source.Configs["Voice"].Set("SelectedOutDevice" + radioID.ToString(), selectedOUTDeviceName); source.Configs["Voice"].Set("SelectedInDevice" + radioID.ToString(), selectedINDeviceName); source.Configs["Voice"].Set("RadioIP" + radioID.ToString(), cbRadioIP.SelectedValue); source.Configs["Voice"].Set("onOFF" + radioID.ToString(), radioON); } else { SafeMobileLib.Utils.WriteLine("Adding new entry in config file for radio ID:" + radioIMEI); source.Configs["Voice"].Set("SelectedOutDevice" + radioID.ToString(), selectedOUTDeviceName); source.Configs["Voice"].Set("SelectedInDevice" + radioID.ToString(), selectedINDeviceName); source.Configs["Voice"].Set("RadioIP" + radioID.ToString(), cbRadioIP.SelectedValue); source.Configs["Voice"].Set("onOFF" + radioID.ToString(), radioON); } source.Save(); } public void DeleteConfig() { source = new IniConfigSource(Main.CFG_FILE); if (source.Configs["Voice"].Contains("SelectedOutDevice" + radioID.ToString())) { source.Configs["Voice"].Remove("SelectedOutDevice" + radioID.ToString()); source.Configs["Voice"].Remove("SelectedInDevice" + radioID.ToString()); source.Configs["Voice"].Remove("RadioIP" + radioID.ToString()); source.Configs["Voice"].Remove("MulticastIP" + radioID.ToString()); } source.Save(); } #endregion #region bigu private void btCollapse_Click(object sender, EventArgs e) { ChangeState(); } public Boolean ChangeState() { if (Collapse) { this.Size = new Size(this.Size.Width, 230); btCollapse.Image = global::MotoTrbo_GW.Properties.Resources.minus; } else { this.Size = new Size(this.Size.Width, 27); btCollapse.Image = global::MotoTrbo_GW.Properties.Resources.plus; } Collapse = !Collapse; return Collapse; } private void btONOFF_Click(object sender, EventArgs e) { SafeMobileLib.Utils.WriteLine("******************************\n" + radioIP + "\n***** CALL to btONOFF_Click(start) ******\n******************************"); if (!radioON) { Connect_in_progress = true; btONOFF.Enabled = false; //start if (soundOUTDevices.Count > 0 && soundINDevices.Count > 0) { int rNetworkID = -1; // Lock here because the hash is populated on another thread and the containsKey method can return false info lock (_locker) { if (RouteManager.NetworkIDs_Hash.ContainsKey(radioIP)) rNetworkID = (int)RouteManager.NetworkIDs_Hash[radioIP]; } if (rNetworkID == -1) { SafeMobileLib.Utils.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); SafeMobileLib.Utils.WriteLine($"Network ID missing for {radioIP} Gateway radio could not Start!!!" ); SafeMobileLib.Utils.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); RadMessageBox.Show("Gateway radio not found!!" + radioIP, "MotoTRBO gateway", MessageBoxButtons.OK, RadMessageIcon.Exclamation); btONOFF.Enabled = true; Connect_in_progress = false; } else { try { SafeMobileLib.Utils.WriteLine($"******************************\n {radioIP} \n***** CALL to btONOFF_Click (network ID found)******\n******************************"); if (Main.RadioComArr.ContainsKey(radioIP)) { SafeMobileLib.Utils.WriteLine($"******************************\n {radioIP} \n***** CALL to btONOFF_Click (connection found)******\n******************************"); radioC = Main.RadioComArr[radioIP]; SafeMobileLib.Utils.WriteLine("(((((((((((( devIN:" + selectedINDevice + " devOUT:" + selectedOUTDevice + ")))))))"); rcHandler = new RadioComHandler(radioC, radioID, radioIP, rNetworkID, radioIMEI, selectedINDevice, selectedOUTDevice); rcHandler.OnChannelEvent += new RadioComHandler.ChannelEvent(rcHandler_OnChannelEvent); rcHandler.PropertyChanged += new PropertyChangedEventHandler(rcHandler_PropertyChanged); // Fire event for LINX StartedRadioComHandler?.Invoke(this, rcHandler); while (!radioC.AuthDone) { SafeMobileLib.Utils.WriteLine("VOice thread Spleeping.. AUTH not completed"); SafeMobileLib.Utils.WriteLine($"******************************\n {radioIP} \n***** CALL to btONOFF_Click (Connection not complited)******\n******************************"); System.Threading.Thread.Sleep(500); } if (rcHandler.Start() == false) { SafeMobileLib.Utils.WriteLine($"******************************\n {radioIP} \n***** CALL to btONOFF_Click 3******\n******************************"); RadMessageBox.Show("Gateway radio not found!!" + radioIP, "MotoTRBO gateway", MessageBoxButtons.OK, RadMessageIcon.Exclamation); btONOFF.Enabled = true; Connect_in_progress = false; } else { SafeMobileLib.Utils.WriteLine($"******************************\n {radioIP} \n***** CALL to btONOFF_Click (END)******\n******************************"); AuthDone(); } } else { SafeMobileLib.Utils.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); SafeMobileLib.Utils.WriteLine($"Main.RadioComArr ip {radioIP} missing Gateway radio could not Start!! Waiting for antother ping" ); SafeMobileLib.Utils.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); //RadMessageBox.Show("Gateway radio not found!!" + radioIP, "MotoTRBO gateway", MessageBoxButtons.OK, RadMessageIcon.Exclamation); btONOFF.Enabled = true; Connect_in_progress = false; } } catch (Exception ex) { SafeMobileLib.Utils.WriteLine("Error on ON/OFF button click:"+ex.ToString()); } } } else { RadMessageBox.Show("No sound device found!!!"); TurnOff(false); btONOFF.Enabled = true; Connect_in_progress = false; } } else { TurnOff(false); } } #endregion #region zones and channels //channels private List ChanelList = null; private int selectedChannelNr = 0; private void LoadChannels() { if (selectedZoneNr > 0) { cbChan.Items.Clear(); channelList = db4gateway.gelAllradioChannels(zonesList[selectedZoneNr - 1].Id); ChanelList = new List(); foreach (RadioChannels rc in channelList) ChanelList.Add(rc.Name); int cnt = -1; foreach (String obj in ChanelList) { cnt++; RadMenuItem tmp = new RadMenuItem(obj); tmp.Name = "chmenu" + cnt.ToString(); cbChan.Items.Add(tmp); tmp.Click += new System.EventHandler(ChannelChangeEvent); } if (cbChan.Items.Count > 0) { ((RadMenuItem)cbChan.Items[0]).IsChecked = true; cbChan.Text = ((RadMenuItem)cbChan.Items[0]).Text; } } } private void ChannelChangeEvent(object sender, EventArgs e) { selectedChannelNr = 0; foreach (RadMenuItem obj in cbChan.Items) { selectedChannelNr++; if (obj.Name == ((RadMenuItem)sender).Name) { break; } } SafeMobileLib.Utils.WriteLine("Sending channel change nr=" + selectedChannelNr); rcHandler.SendZoneChannelChange(selectedZoneNr, selectedChannelNr); } //zones private List ZoneList = null; private int selectedZoneNr = 0; private void LoadZones() { zonesList = db4gateway.gelAllradioZones(radioID); ZoneList = new List(); foreach (RadioZones rz in zonesList) ZoneList.Add("zone "+rz.Nr); int cnt = -1; foreach (String obj in ZoneList) { cnt++; RadMenuItem tmp = new RadMenuItem(obj); tmp.Name = "chmenu" + cnt.ToString(); cbZone.Items.Add(tmp); tmp.Click += new System.EventHandler(ZoneChangeEvent); } if (cbZone.Items.Count > 0) { selectedZoneNr = 1; ((RadMenuItem)cbZone.Items[0]).IsChecked = true; cbZone.Text = ((RadMenuItem)cbZone.Items[0]).Text; } } private void ZoneChangeEvent(object sender, EventArgs e) { selectedZoneNr = 0; foreach (RadMenuItem obj in cbZone.Items) { selectedZoneNr++; if (obj.Name == ((RadMenuItem)sender).Name) { break; } } SafeMobileLib.Utils.WriteLine("Sending zone change nr=" + selectedZoneNr); rcHandler.SendZoneChannelChange(selectedZoneNr, selectedChannelNr); } #endregion #region VOICE Components private void iniVoiceComponents() { // load default configuration selectedOUTDevice = -1; selectedINDevice = -1; for (int i = 0; i < cbRadioIP.Items.Count; i++) { if (cbRadioIP.Items[i].Text == radioIP) { cbRadioIP.SelectedIndex = i; break; } } try { sDevice soundDevice; List listOfInputDevices, listOfOutputDevices; if (Main.AudioDriver == AudioDriverType.Asio) { listOfInputDevices = Main.GetAsioInputDevices(); listOfOutputDevices = Main.GetAsioOutputDevices(); } else { listOfInputDevices = AudioManager.GetWaveInputDevices(); listOfOutputDevices = AudioManager.GetWaveOutputDevices(); } int nrOfInDevices = listOfInputDevices.Count; for (int i = 0; i < nrOfInDevices; i++) { soundDevice = listOfInputDevices[i]; soundINDevices.Add(soundDevice); RadListDataItem ci = new RadListDataItem(soundDevice.name); listRecBDevices.Items.Add(ci); } int nrOfOUTDevices = listOfOutputDevices.Count; for (int i = 0; i < nrOfOUTDevices; i++) { soundDevice = listOfOutputDevices[i]; soundOUTDevices.Add(soundDevice); RadListDataItem ci = new RadListDataItem(soundDevice.name); listPlayBDevices.Items.Add(ci); } if (listPlayBDevices.Items.Count > 0) { if (selectedOUTDevice < listPlayBDevices.Items.Count) { bool found = false; foreach (sDevice dev in soundOUTDevices) { if (dev.name.Equals(selectedOUTDeviceName)) { found = true; SafeMobileLib.Utils.WriteLine("Sound Device OUT found on config file dev name: " + dev.name + " with index: " + dev.index); listPlayBDevices.SelectedIndex = dev.index; selectedOUTDevice = dev.index; break; } } if (!found) { listPlayBDevices.SelectedIndex = 0; selectedOUTDevice = 0; } } else { listPlayBDevices.SelectedIndex = 0; selectedOUTDevice = 0; } } if (listRecBDevices.Items.Count > 0) { if (selectedINDevice < listRecBDevices.Items.Count) { bool found = false; foreach (sDevice dev in soundINDevices) { if (dev.name == selectedINDeviceName) { found = true; SafeMobileLib.Utils.WriteLine("Sound Device IN found on config file dev name: " + dev.name + " with index: " + dev.index); listRecBDevices.SelectedIndex = dev.index; selectedINDevice = dev.index; break; } } if (!found) { listRecBDevices.SelectedIndex = 0; selectedINDevice = 0; } } else { listRecBDevices.SelectedIndex = 0; selectedINDevice = 0; } } } catch (Exception ex) { SafeMobileLib.Utils.WriteLine("ERROR in voice ini : " + ex.ToString()); } } private void Filler(IntPtr data, int size) { //this is dummy function } private void Voice_Out(IntPtr data, int size) { //this is dummy function } public struct sDevice { public int index; public string name; } #endregion private void btnSaveRadioSettings_Click(object sender, EventArgs e) { SaveConfig(); RestarRadio(); } private void radioForm_FormClosing(object sender, FormClosingEventArgs e) { //send off to SD string test = "#100#" + Main.GWID + "." + radioID + "#0#"; MessageBusHandler.SendOnMsgBuss("0.0", test); SaveConfig(); } public void SendClose() { if (radioON) { //send off to SD string test = "#100#" + Main.GWID + "." + radioID + "#0#"; MessageBusHandler.SendOnMsgBuss("0.0", test); } } private void RestarRadio() { SafeMobileLib.Utils.WriteLine("Resarting radio " + radioIP.ToString()); if (radioON) { btONOFF.Text = "ON"; ImgRad.Image = global::MotoTrbo_GW.Properties.Resources.radioblack1; ImgStat.Image = global::MotoTrbo_GW.Properties.Resources.red_status; EnableAudioSettingsPanels(true); cbChan.Enabled = false; cbZone.Enabled = false; radioON = false; //stop // Fire Event for LINX StoppingRadioComHandler?.Invoke(this, rcHandler); rcHandler.Stop(); Connect_in_progress = true; SafeMobileLib.Utils.WriteLine("Restarting rcHandler for" + radioIP.ToString()); if (Main.RadioComArr.ContainsKey(radioIP)) { RadioConnection radioC = Main.RadioComArr[radioIP]; rcHandler = new RadioComHandler(radioC, radioID, radioIP, radioNetworkID, radioIMEI, selectedINDevice, selectedOUTDevice); //rcHandler.OnAuthDone += new RadioComHandler.AuthDoneDEl(rcHandler_OnAuthDone); rcHandler.OnChannelEvent += new RadioComHandler.ChannelEvent(rcHandler_OnChannelEvent); rcHandler.PropertyChanged += new PropertyChangedEventHandler(rcHandler_PropertyChanged); // Fire Event for LINX StartedRadioComHandler?.Invoke(this, rcHandler); btONOFF.Enabled = false; //start while (!radioC.AuthDone) { SafeMobileLib.Utils.WriteLine("VOice thread Spleeping.. AUTH not completed"); System.Threading.Thread.Sleep(500); } if (rcHandler.Start() == false) { RadMessageBox.Show("Gateway radio not found!!" + radioIP, "MotoTRBO gateway", MessageBoxButtons.OK, RadMessageIcon.Exclamation); btONOFF.Enabled = true; } else { AuthDone(); } } else { RadMessageBox.Show("Gateway radio not found!!" + radioIP, "MotoTRBO gateway", MessageBoxButtons.OK, RadMessageIcon.Exclamation); btONOFF.Enabled = true; } } } private void TurnOff(bool restartWhenPowerOn) { btONOFF.Text = "ON"; ImgRad.Image = global::MotoTrbo_GW.Properties.Resources.radioblack1; ImgStat.Image = global::MotoTrbo_GW.Properties.Resources.red_status; EnableAudioSettingsPanels(true); cbChan.Enabled = false; cbZone.Enabled = false; radioON = false; onOFFpreStatus = restartWhenPowerOn; //stop // Fire event for LINX StoppingRadioComHandler?.Invoke(this, rcHandler); try { if (rcHandler != null) rcHandler.Stop(); } catch (Exception ex) { SafeMobileLib.Utils.WriteLine(ex.ToString()); } rcHandler = null; lbRadio_Status.Text = "Off"; try { SafeMobileLib.Utils.WriteEventLog("Safemobile", "Station with IP:"+radioIP+" is OFF", EventLogEntryType.Information, 31020); } catch (Exception ex) { SafeMobileLib.Utils.WriteLine("Unable to write log Event ex:" + ex.ToString()); } } private void listPlayBDevices_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e) { try { foreach (sDevice dev in soundOUTDevices) { if (dev.name == ((RadListDataItem)listPlayBDevices.SelectedItem).Text) { selectedOUTDevice = dev.index; selectedOUTDeviceName = dev.name; break; } } } catch (Exception ex) { SafeMobileLib.Utils.WriteLine("Error in selecting device"); SafeMobileLib.Utils.WriteLine(ex.ToString()); } } private void listPlayBDevices_EnabledChanged(object sender, EventArgs e) { foreach(RadListDataItem item in ((RadListControl)sender).Items) { if (item == null || item.VisualItem == null) continue; if(((RadListControl)sender).Enabled) { item.VisualItem.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local); item.VisualItem.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local); item.VisualItem.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local); item.VisualItem.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local); item.VisualItem.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local); } else { item.VisualItem.NumberOfColors = 1; item.VisualItem.BackColor = item.Selected ? Color.Wheat : Color.Transparent; } } } bool firstTime = true; private void radTabStrip1_SelectedPageChanged(object sender, EventArgs e) { if(radTabStrip1.SelectedPage == radPageViewPage2 && firstTime) { listPlayBDevices_EnabledChanged(listPlayBDevices, null); listPlayBDevices_EnabledChanged(listRecBDevices, null); firstTime = false; } } private void listRecBDevices_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e) { try { foreach (sDevice dev in soundINDevices) { if (dev.name == ((RadListDataItem)listRecBDevices.SelectedItem).Text) { selectedINDevice = dev.index; selectedINDeviceName = dev.name; break; } } } catch (Exception ex) { SafeMobileLib.Utils.WriteLine("Error in selecting device"); SafeMobileLib.Utils.WriteLine(ex.ToString()); } } public delegate void RadioComHandlerDelegate(object sender, RadioComHandler rcHandler); public event RadioComHandlerDelegate StartedRadioComHandler; public event RadioComHandlerDelegate StoppingRadioComHandler; } }