private void PopulateDictionaries() { foreach (TabPage page in this.mTabControl.TabPages) { String COMPort = page.Text; String MACAddr = null; String Label = null; foreach (Control c in page.Controls) { if (c.Name == "addrlabel") { MACAddr = (c as Label).Text; } if (c.Name == "newComboBox") { Label = ((c as ComboBox).SelectedItem) as String; if (Label == null) { Label = ((c as ComboBox).SelectedValue as String); } } } SensorIdentification tmpSensorID = new SensorIdentification(Label, MACAddr, COMPort); if (mNexus.mSensorIDDict.ContainsKey(Label) == false) { mNexus.mSensorIDDict.Add(Label, tmpSensorID); } if (mNexus.mSensorDict.ContainsKey(Label) == false) { mNexus.mSensorDict.Add(Label, new Sensor(tmpSensorID)); } } }
public Sensor(SensorIdentification config) { mID = config.Id; mMAC = config.Mac; mPortName = config.PortName; mData = new RingBuffer <SensorDataEntry>(HISTORY_BUFFER_SIZE); /** Add an empty entry in case getLastEntry is called before data comes in */ mData.Add(new SensorDataEntry()); mTimeoutWatch = new System.Diagnostics.Stopwatch(); }
public Sensor(SensorIdentification config) { mID = config.Id; mMAC = config.Mac; mPortName = config.PortName; mData = new RingBuffer<SensorDataEntry>(HISTORY_BUFFER_SIZE); /** Add an empty entry in case getLastEntry is called before data comes in */ mData.Add( new SensorDataEntry() ); mTimeoutWatch = new System.Diagnostics.Stopwatch(); }
/// <summary> /// Reads the config file at %APPDATA%/Sensor-Aware-PT/config.xml /// </summary> private bool ReadConfigFile() { bool retval = true; StreamReader fileStream = null; try { // Get an array of sensor IDs from the xml file fileStream = new StreamReader(ConfigFilePath); SensorIdentification[] tmpArray = new SensorIdentification[1] { null }; XmlSerializer serializer = new XmlSerializer(tmpArray.GetType()); // Take each array object and insert it into the id dictionary tmpArray = serializer.Deserialize(fileStream) as SensorIdentification[]; foreach (SensorIdentification id in tmpArray) { if (mNexus.mSensorIDDict.Keys.Contains(id.Id)) { throw new ArgumentOutOfRangeException(String.Format("There is already a sensor with ID \"{0}\"", id.Id)); } mNexus.mSensorIDDict[id.Id] = id; } } catch (System.InvalidOperationException e) { if (e.Message.StartsWith("There is an error in XML document")) { Logger.Warning(String.Format("{0}- {1}", e.GetType().ToString(), e.Message)); retval = false; } } catch (FileNotFoundException exc) { Logger.Warning("FileNotFoundException- {0}", exc.FileName); if (fileStream.BaseStream.CanRead) { fileStream.Close(); } return(false); } catch (Exception) { throw; } finally { fileStream.Close(); } return(retval); }
/// <summary> /// Reads the config file at %APPDATA%/Sensor-Aware-PT/config.xml /// </summary> private bool ReadConfigFile() { bool retval = true; StreamReader fileStream = null; try { // Get an array of sensor IDs from the xml file fileStream = new StreamReader(ConfigFilePath); SensorIdentification[] tmpArray = new SensorIdentification[1] { null }; XmlSerializer serializer = new XmlSerializer(tmpArray.GetType()); // Take each array object and insert it into the id dictionary tmpArray = serializer.Deserialize(fileStream) as SensorIdentification[]; foreach (SensorIdentification id in tmpArray) { if (mNexus.mSensorIDDict.Keys.Contains(id.Id)) { throw new ArgumentOutOfRangeException(String.Format("There is already a sensor with ID \"{0}\"", id.Id)); } mNexus.mSensorIDDict[id.Id] = id; } } catch (System.InvalidOperationException e) { if (e.Message.StartsWith("There is an error in XML document")) { Logger.Warning(String.Format("{0}- {1}", e.GetType().ToString(), e.Message)); retval = false; } } catch (FileNotFoundException exc) { Logger.Warning("FileNotFoundException- {0}", exc.FileName); if (fileStream.BaseStream.CanRead) { fileStream.Close(); } return false; } catch (Exception) { throw; } finally { fileStream.Close(); } return retval; }
private void PopulateDictionaries() { foreach (TabPage page in this.mTabControl.TabPages) { String COMPort = page.Text; String MACAddr = null; String Label = null; foreach (Control c in page.Controls) { if (c.Name == "addrlabel") { MACAddr = (c as Label).Text; } if (c.Name == "newComboBox") { Label = ((c as ComboBox).SelectedItem) as String; if (Label == null) { Label = ((c as ComboBox).SelectedValue as String); } } } SensorIdentification tmpSensorID = new SensorIdentification(Label, MACAddr, COMPort); if (mNexus.mSensorIDDict.ContainsKey(Label) == false) { mNexus.mSensorIDDict.Add(Label, tmpSensorID); } if (mNexus.mSensorDict.ContainsKey(Label) == false) { mNexus.mSensorDict.Add(Label, new Sensor(tmpSensorID)); } } }
/// <summary> /// Generates a tab for each sensor on the TabControl and every control in each tab /// </summary> /// <param name="MacAddress">Mac Address of the sensor</param> /// <param name="portName">The COM Port of th sensor</param> /// <param name="mPossibleIds">Possible Letters of the alphabet we can assign to this sensor</param> /// <param name="id">An optional SensorIdentification parameter that should not be passed in by the user. Use the overload instead.</param> private void GenerateControls(string MacAddress, string portName, List<char> mPossibleIds, SensorIdentification id = null) { TabPage newpage = new TabPage(portName); ComboBox newcombo = new ComboBox(); Label maclabel = new Label(); Label addrlabel = new Label(); maclabel.Name = "maclabel"; maclabel.Text = "MAC"; addrlabel.Name = "addrlabel"; addrlabel.Text = MacAddress; newcombo.Name = "newComboBox"; foreach (Char c in this.mPossibleIds) { newcombo.Items.Add(c.ToString()); }; newpage.Controls.Add(newcombo); newcombo.Dock = DockStyle.None; newcombo.Left = (mTabControl.Width / 2) - newcombo.Width; newcombo.Top = (mTabControl.Height / 2) - newcombo.Height; if (id == null) newcombo.SelectedIndex = 0; else newcombo.SelectedItem = id.Id; newpage.Controls.Add(maclabel); newpage.Dock = DockStyle.None; maclabel.Top = newcombo.Top - maclabel.Height; maclabel.Left = newcombo.Left; maclabel.AutoSize = true; newpage.Controls.Add(addrlabel); newpage.Dock = DockStyle.None; addrlabel.Top = maclabel.Top; addrlabel.Left = maclabel.Left + maclabel.Width; this.mTabControl.TabPages.Add(newpage); }
/// <summary> /// Calls the other overload of GenerateControls using the hidden id parameter. /// </summary> /// <param name="id">A SensorIdentification containing an already-detected sensor's info</param> /// <param name="mPossibleIds">A list of possible letters we can assign to that sensor.</param> private void GenerateControls(SensorIdentification id, List<Char> mPossibleIds) { GenerateControls(id.Mac, id.PortName, mPossibleIds, id); }
/// <summary> /// Generates a tab for each sensor on the TabControl and every control in each tab /// </summary> /// <param name="MacAddress">Mac Address of the sensor</param> /// <param name="portName">The COM Port of th sensor</param> /// <param name="mPossibleIds">Possible Letters of the alphabet we can assign to this sensor</param> /// <param name="id">An optional SensorIdentification parameter that should not be passed in by the user. Use the overload instead.</param> private void GenerateControls(string MacAddress, string portName, List <char> mPossibleIds, SensorIdentification id = null) { TabPage newpage = new TabPage(portName); ComboBox newcombo = new ComboBox(); Label maclabel = new Label(); Label addrlabel = new Label(); maclabel.Name = "maclabel"; maclabel.Text = "MAC"; addrlabel.Name = "addrlabel"; addrlabel.Text = MacAddress; newcombo.Name = "newComboBox"; foreach (Char c in this.mPossibleIds) { newcombo.Items.Add(c.ToString()); } ; newpage.Controls.Add(newcombo); newcombo.Dock = DockStyle.None; newcombo.Left = (mTabControl.Width / 2) - newcombo.Width; newcombo.Top = (mTabControl.Height / 2) - newcombo.Height; if (id == null) { newcombo.SelectedIndex = 0; } else { newcombo.SelectedItem = id.Id; } newpage.Controls.Add(maclabel); newpage.Dock = DockStyle.None; maclabel.Top = newcombo.Top - maclabel.Height; maclabel.Left = newcombo.Left; maclabel.AutoSize = true; newpage.Controls.Add(addrlabel); newpage.Dock = DockStyle.None; addrlabel.Top = maclabel.Top; addrlabel.Left = maclabel.Left + maclabel.Width; this.mTabControl.TabPages.Add(newpage); }
/// <summary> /// Calls the other overload of GenerateControls using the hidden id parameter. /// </summary> /// <param name="id">A SensorIdentification containing an already-detected sensor's info</param> /// <param name="mPossibleIds">A list of possible letters we can assign to that sensor.</param> private void GenerateControls(SensorIdentification id, List <Char> mPossibleIds) { GenerateControls(id.Mac, id.PortName, mPossibleIds, id); }