예제 #1
0
        public MainPage()
        {
            if (UdpServer.IsRunning == false)
            {
                ThemeManager.Init();
                StartServer();
                RoomCreater.LoadListFromFile();

                DataSample newel = new DataSample
                {
                    SenderId    = "21000000",
                    Temperature = 35,
                    Humidity    = 20,
                    Movement    = 1,
                    CoLevel     = 12,
                    LpgLevel    = 0,
                    SmokeLevel  = 0
                };



                Unit newUnit = new Unit
                {
                    Id   = "21000000",
                    Type = "Switcer",
                    Auto = true
                };
                Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Collections.AddToActualDatas(newel);
                    Collections.UnitsToLocalize.Add(newel.SenderId);
                    Collections.AddToNodeList(newUnit);
                });
            }
            this.InitializeComponent();
            DataContext = this;
            InitClock();


            RefreshAvgTemp("init");
            Collections.ResreshSenderDataEvent += RefreshAvgTemp;
        }
예제 #2
0
        public static void AutoLightControl(DataSample newdata)
        {
            var unit = Collections.CurrentNodes.Where(u => u.Id == newdata.SenderId).FirstOrDefault();

            if (unit != null && unit.Type == "PIR")
            {
                Room room = Collections.Rooms.Where(r => r.Name == unit.Location).FirstOrDefault();
                if (room.Auto)
                {
                    if (newdata.Movement == 1)
                    {
                        room.TurnLightOn(true);
                    }
                    else
                    {
                        room.TurnLightOff(true);
                    }
                }
            }
        }
예제 #3
0
 public static void RefreshActualDatas(DataSample newSender)
 {
     ActualDatas[newSender.SenderId] = newSender;
 }
예제 #4
0
        //Bejövő adatok szortírozása, a Process hívja meg
        private async static Task <string> SortString(string[] data)
        {
            string cmd = data[0];

            if (cmd == "SND")
            {
                DataSample newel = new DataSample
                {
                    SenderId    = data[1],
                    Temperature = double.Parse(data[6]),
                    Humidity    = double.Parse(data[5]),
                    Movement    = int.Parse(data[7]),
                    CoLevel     = double.Parse(data[3]),
                    LpgLevel    = double.Parse(data[2]),
                    SmokeLevel  = double.Parse(data[4])
                };
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    AutoLightControl(newel);
                    Collections.AddToActualDatas(newel);
                });

                DBInstance.SaveData(newel);
            }
            if (cmd == "JND")
            {
                Unit newUnit = new Unit
                {
                    Id   = data[1],
                    Type = data[2]
                };
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Collections.AddToNodeList(newUnit);
                });
            }

            if (cmd == "REQIP")
            {
                Unit newUnit = new Unit
                {
                    Type = data[1]
                };
                newUnit.Id = GivenId.ToString();
                GivenId   += 10000000;
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Collections.AddToNodeList(newUnit);
                });
            }

            if (cmd == "SEL")
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (!Collections.UnitsToLocalize.Contains(data[1]))
                    {
                        Collections.UnitsToLocalize.Add(data[1]);
                    }
                });
            }
            return(cmd);
        }