Пример #1
0
 public void add(devTable dev)
 {
     devCtrl ctrl = new devCtrl(dev);
     cvsPanel.Children.Add(ctrl);
     cvsPanel.Height = cvsPanel.Children.Count * 30;
     int count = cvsPanel.Children.Count - 1;
     Canvas.SetLeft(ctrl, 10.0);
     Canvas.SetTop(ctrl, count  * 30);
    // ctrl.setId(count + 1);
 }
Пример #2
0
        public void update(devTable dev)
        {
            switch (dev.netId >> 8)
            {
                case 0x01://"灯";
                    灯.updateValue(dev);
                    break;
                case 0x02://"插座";

                    break;
                case 0x03://"窗帘";
                    {
                        窗帘.updateValue(dev);
                    }
                    break;
                case 0x04://"门锁";
                    {
                        门锁.updateValue(dev);
                    }
                    break;
                case 0x05://"警报器";
                    {
                        警报器.updateValue(dev);
                    }
                    break;

                case 0x80://"开关";

                    break;
                case 0x81://"人体";
                    if(dev.netId == 0x8101)
                    {
                        客厅感应.updateValue(dev);
                    }
                    else
                    {
                        卧室感应.updateValue(dev);
                    }
                    break;
                case 0x82://"烟感";
                   烟感.updateValue(dev);
                    break;
                case 0x83://"燃气";
                   燃气.updateValue(dev);
                    break;
                default:

                    break;

            }
        }
Пример #3
0
 public void update(devTable dev)
 {
     bool getDev = false;
     foreach(devCtrl ctrl in cvsPanel.Children)
     {
         if(ctrl.devObj.mac == dev.mac)
         {
             ctrl.update(dev);
             getDev = true;
             break;
         }
     }
     if(!getDev)
     {
         add(dev);
     }
 }
Пример #4
0
 public static bool addDev(devTable dev)
 {
     if(devLst.ContainsKey(dev.mac))
     {
         return false;
     }
     else
     {
         devLst.Add(dev.mac, dev);
         Console.WriteLine("[addDev]" + dev.mac);
         return true;
     }
 }
Пример #5
0
        public void update(devTable dev)
        {
            if (dev != null)
                devObj = dev;
            else
                throw new Exception("设备对象为空");
            txtState.Text = dev.devstate.ToString("X2");
            txtProtocol.Text = dev.protocol.ToString("X2");
            txtNetId.Text = dev.netId.ToString("X4");
            txtMac.Text = dev.mac;
            txtIO.Text = dev.io.ToString("X2");
            txtIOMode.Text = dev.ioMode.ToString("X2");
            txtCurSt.Text = dev.curSt.ToString("X4");
            txtType.Text = dev.type.ToString("X2");
            txtName.Text = dev.name;
            if(dev.io == 0)
            {
                btnOn.Visibility = Visibility.Hidden;
                btnOff.Visibility = Visibility.Hidden;
            }
            else if((devObj.netId & 0x8000) > 0)
            {
                btnOn.Visibility = Visibility.Hidden;
                btnOff.Visibility = Visibility.Hidden;
            }

            if(dev.curSt == 0)
            {
                btnOff.IsEnabled = false;
                btnOn.IsEnabled = true;
            }
            else if(dev.curSt == 1)
            {
                btnOff.IsEnabled = true;
                btnOn.IsEnabled = false;
            }
            btnStop.Visibility = Visibility.Hidden;
            switch(dev.netId >> 8)
            {
                case 0x01:
                    lbDevName.Content = "灯";
                    break;
                case 0x02:
                    lbDevName.Content = "插座";
                    break;
                case 0x03:
                    {
                        lbDevName.Content = "窗帘";
                        btnOn.Content = "FWD";
                        btnOff.Content = "BWD";
                        btnStop.Visibility = Visibility.Visible;
                    }
                    break;
                case 0x04:
                    {
                        lbDevName.Content = "门锁";
                    }
                    break;
                case 0x05:
                    {
                        lbDevName.Content = "警报器";
                    }
                    break;

                case 0x80:
                    lbDevName.Content = "开关";
                    break;
                case 0x81:
                    lbDevName.Content = "人体";
                    break;
                case 0x82:
                    lbDevName.Content = "烟感";
                    break;
                case 0x83:
                    lbDevName.Content = "燃气";
                    break;
                default:

                    break;

            }

           // lbDevName.Content = dev.mac.ToString("X8");

        }
Пример #6
0
 public devCtrl(devTable dev)
 {
     InitializeComponent();
     update(dev);
 }
Пример #7
0
        public void updateValue(devTable dev)
        {
            //0x200黄色 
            //0x300红色
            obj = dev;
            Usable = true;
            switch (dev.netId >> 8)
            {
                case 0x81://"人体";
                    {
                        if( dev.curSt < 0) 
                            cvsMain.Background = Brushes.Red;
                        else
                            cvsMain.Background = Brushes.Transparent;
                    }
                    break;
                case 0x82://"烟感";
                case 0x83://"燃气";
                    {
                        if(dev.curSt > 0x300)
                        {
                            cvsMain.Background = Brushes.Red;
                            double pos = 66.0 + (dev.curSt - 0x300) * 34.0 / 0x200 - 1.5;
                            if (pos > 97.5)
                                pos = 97.5;
                            Canvas.SetLeft(pgValue,pos);
                        }
                        else if(dev.curSt > 0x200)
                        {
                            cvsMain.Background = Brushes.Yellow;
                            double pos = 33.0 + (dev.curSt - 0x200) * 33.0 / 0x100 - 1.5;
                            Canvas.SetLeft(pgValue, pos);
                        }
                        else
                        {
                            cvsMain.Background = Brushes.Transparent;
                            double pos = dev.curSt * 33.0 / 0x200 - 1.5;
                            Canvas.SetLeft(pgValue, pos);
                        }
                        lbValue.Content = dev.curSt.ToString();
                    }
                    break;
                //case 0x83://"燃气";
                //    {

                //    }
                //    break;
                default:
                    break;

            }
        }
Пример #8
0
 void refreshDevCtrls(devTable dev)
 {
     devCtrls.update(dev);
     userWindow.update(dev);
 }
Пример #9
0
  void refreshCtr(devTable devObj)
 {
     this.Dispatcher.BeginInvoke(new devTableDg(refreshDevCtrls), devObj);
 }
Пример #10
0
        public void updateValue(devTable dev)
        {
            obj = dev;
            Usable = true;
            switch (dev.netId >> 8)
            {
                case 0x01://"灯"
                case 0x04://"门锁";
                case 0x05://"警报器";
                    {
                        if(dev.curSt > 0)
                        {
                            cvsMain.Background = Brushes.Red;
                            //btnBack.IsEnabled = false;
                            //btnFore.IsEnabled = true;
                        }
                        else
                        {
                            cvsMain.Background = Brushes.Transparent;
                            //btnBack.IsEnabled = true;
                            //btnFore.IsEnabled = false;
                        }
                    }
                    break;
                case 0x02://"插座";
                    {

                    }
                    break;
                case 0x03://"窗帘";
                    {

                    }
                    break;
                case 0x80://"开关";
                    {

                    }
                    break;
                default:
                    break;

            }
        }
Пример #11
0
        public static void parseMsg_Data(byte[] data)
        {
            switch (data[0])
            {
                case 0x01://设备更新
                    {
                        if (data[1] != 0)
                        {
                            devTable dev = null;
                            byte state = 0;
                            byte protocol = 0;
                            UInt16 netId = 0;



                            int index = 1;
                            
                            state = data[index];
                            index++;//state      byte[1]

                            protocol = data[index];
                            index++;//protocol   byte[1]

                            netId = (UInt16)((data[index] << 8) | data[index + 1]);
                            index += 2;//netId   byte[2]

                            //通过MAC获取设备
                            dev = devMgr.getDev(data, index);
                            if (dev != null)
                            {
                                    
                            }
                            else
                            {
                                dev = new devTable();
                                dev.mac = getMac(data, index);
                                devMgr.addDev(dev);
                            }
                            index += 8;   //mac   byte[8]

                            dev.devstate = state;
                            dev.protocol = protocol;
                            dev.netId = netId;


                            dev.io = data[index];
                            index++;      //IO    byte[1]

                            dev.ioMode = data[index];
                            index++;

                            dev.curSt = (UInt16)((data[index] << 8) | data[index + 1]);
                            index += 2;   //curSt byte[2]
                            

                            dev.name = "";
                            for (int i = 0; i < DEV_NAME_SIZE; i++)
                            {
                                dev.name += data[index + i].ToString("X2") + " ";
                            }
                            index += DEV_NAME_SIZE;  //
                            
                            if (updateDevsHandle != null)
                                updateDevsHandle(dev);
                            //dev.show();
                        }
                    }
                    break;
            }
        }