コード例 #1
0
ファイル: WifiDevices.cs プロジェクト: heppyn/Bachelor-Thesis
        /// <summary>
        /// Sends schedule to all heaters on list.
        /// Starts in new thread.
        /// </summary>
        /// <param name="heaters">heaters to change</param>
        public void SendAlternativeSchedules(List <Heater> heaters, List <Schedule> schedules)
        {
            Thread t = new Thread(delegate()
            {
                bool found;
                foreach (Heater h in heaters)
                {
                    found = false;
                    lock (m_heaters)
                    {
                        foreach (KeyValuePair <IPAddress, String> elem in m_heaters)
                        {
                            if (elem.Value.Equals(h.Id))
                            {
                                WiFiClient wc = new WiFiClient(elem.Key.ToString());
                                foreach (Schedule s in schedules)
                                {
                                    if (s.GetName().Equals(h.Name))
                                    {
                                        wc.SendAlternativeSchedule(s);
                                    }
                                }
                                found = true;
                                break;
                            }
                        }
                    }

                    if (found)
                    {
                        continue;
                    }

                    FindHeaters();

                    lock (m_heaters)
                    {
                        foreach (KeyValuePair <IPAddress, String> elem in m_heaters)
                        {
                            if (elem.Value.Equals(h.Id))
                            {
                                WiFiClient wc = new WiFiClient(elem.Key.ToString());
                                foreach (Schedule s in schedules)
                                {
                                    if (s.GetName().Equals(h.Name))
                                    {
                                        wc.SendAlternativeSchedule(s);
                                    }
                                }
                                found = true;
                                break;
                            }
                        }
                    }
                }
            });

            t.Start();
        }
コード例 #2
0
ファイル: WifiDevices.cs プロジェクト: heppyn/Bachelor-Thesis
        /// <summary>
        /// Sends return date and temperature to specified device.
        /// Creates new thread.
        /// </summary>
        /// <param name="date">Return date</param>
        /// <param name="temp">Desired temperature</param>
        /// <param name="address">IP address of device</param>
        private void SendReturnDateAndTemperatureToDevice(DateTime date, int temp, IPAddress address)
        {
            Thread t = new Thread(delegate()
            {
                WiFiClient wc = new WiFiClient(address.ToString());
                wc.SendReturnDateAndTemperature(date, temp);
            });

            t.Start();
        }
コード例 #3
0
ファイル: WifiDevices.cs プロジェクト: heppyn/Bachelor-Thesis
        /// <summary>
        /// Sends request to heater, to get temperature.
        /// Writes temperature to m_temperatures.
        /// </summary>
        /// <param name="address">IP address of heater</param>
        /// <param name="name">Name of heater</param>
        private void GetTemperatureFromDevice(IPAddress address, String name)
        {
            WiFiClient wc  = new WiFiClient(address.ToString());
            double     res = wc.GetTemperature();

            lock (m_temperatures)
            {
                if (m_temperatures.ContainsKey(name))
                {
                    m_temperatures.Remove(name);
                }
                m_temperatures.Add(name, res);
            }
        }
コード例 #4
0
ファイル: WifiDevices.cs プロジェクト: heppyn/Bachelor-Thesis
        /// <summary>
        /// Starts in new thread
        /// Adds address and id to m_heaters
        /// </summary>
        /// <param name="address">Adress to communicate with</param>
        private void AuthenticateDevice(IPAddress address)
        {
            Debug.WriteLine("Contacting: " + address.ToString());
            String id;

            try
            {
                WiFiClient wc = new WiFiClient(address.ToString());
                id = wc.IdentifyHeater();
            }
            catch
            {
                return;
            }
            lock (m_heaters)
            {
                if (!m_heaters.ContainsKey(address))
                {
                    m_heaters.Add(address, id);
                }
            }
            Debug.WriteLine("Found ID " + id + " that belongs to " + address.ToString());
        }
コード例 #5
0
ファイル: WifiDevices.cs プロジェクト: heppyn/Bachelor-Thesis
        /// <summary>
        /// Changes id of new heater to new id.
        /// Only one new heater must be connected.
        /// Starts in new thread.
        /// </summary>
        /// <param name="newId"></param>
        public void ChangeIdfromStartId(String newId)
        {
            Thread t = new Thread(delegate()
            {
                lock (m_heaters)
                {
                    foreach (KeyValuePair <IPAddress, String> elem in m_heaters)
                    {
                        if (elem.Value.Equals(newId))
                        {
                            WiFiClient wc = new WiFiClient(elem.Key.ToString());
                            wc.ChangeId(newId);
                            m_heaters.Remove(elem.Key);
                            return;
                        }
                    }
                }
                FindHeaters();

                lock (m_heaters)
                {
                    foreach (KeyValuePair <IPAddress, String> elem in m_heaters)
                    {
                        if (elem.Value.Equals(newId))
                        {
                            WiFiClient wc = new WiFiClient(elem.Key.ToString());
                            wc.ChangeId(newId);
                            m_heaters.Remove(elem.Key);
                            return;
                        }
                    }
                }
            });

            t.Start();
        }