wxr
2023-08-04 20f70e3446df19bf5d0faaae9f7bd58fd0fc4bcc
Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs
@@ -98,7 +98,25 @@
            try {
                List<byte> ButtonBkeyModelList = new List<byte> ();
                switch (command) {
                case Command.readGatewayVision:
                case Command.InitializationGatewayACK:
                    if (usefullBytes.Length == 4) {
                        if (usefullBytes [0] == 0xF8 && usefullBytes [3] == 0) {
                            MainPage.GatewayStatus = "Initialization_complete";//初始化完成
                        }
                    }
                    break;
                case Command.enjoyUpgrade2ACK:
                    if (usefullBytes.Length > 1) {
                        if(usefullBytes [0] == 0xF8 && usefullBytes [1] == 0xF8) {
                            MainPage.GatewayStatus = "upgrade_100_success";//升级成功
                        }
                        else {
                            MainPage.GatewayStatus = "upgrading_" + (usefullBytes [0] * 256 + usefullBytes [1])+"_"+subnetID+"_"+deviceID;//升级中
                            Console.WriteLine (MainPage.GatewayStatus);
                        }
                    }
                    break;
                case Command.readGatewayVisionACK:
                    var visionString = MyEncodingGB2312.GetString (usefullBytes);
                    Console.WriteLine ($"当前网关版本信息:{visionString}");
                    break;
@@ -937,8 +955,8 @@
                        Array.Copy (ddd, 0, newddd, 0, 20 < ddd.Length ? 20 : ddd.Length);
                        Array.Copy (newddd, 0, usefullBytes, 13, 20 < newddd.Length ? 20 : newddd.Length);
                    }
                    switch (deviceType) {
                    case DeviceType.SuperWireless:
                    if (usefullBytes [2] == 254 && usefullBytes [3] > 4) {
                        #region
                        SuperWireless superWireless = new SuperWireless ();
                        string superWirelessPath = "Equipment_" + typeof (OnePortWirelessFR).Name + "_" + subnetID + "_" + deviceID;
@@ -965,172 +983,208 @@
                            superWireless.WirelessPassword = MyEncodingGB2312.GetString (usefullBytes, 64, 16).Trim ('\0');
                        }
                        GateWayList.Add (superWireless);
                        //IO.FileUtils.SaveEquipmentMessage (superWireless);
                        //System.Threading.Tasks.Task.Run (() => {
                        //    if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
                        //        var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, superWireless.SubnetID, superWireless.DeviceID, new byte [] { });
                        //        if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
                        //            UserConfig.Current.RemoteModeFile = "Equipment_" + superWireless.Type.ToString () + "_" + superWireless.SubnetID.ToString () + "_" + superWireless.DeviceID.ToString ();
                        //            UserConfig.Current.SaveUserConfig ();
                        //        }
                        //    }
                        //});
                        #endregion
                        break;
                    case DeviceType.OnePortWirelessFR:
                        #region
                        OnePortWirelessFR onePortWirelessFR = new OnePortWirelessFR ();
                        string wirelessPath = "Equipment_" + typeof (OnePortWirelessFR).Name + "_" + subnetID + "_" + deviceID;
                        var bytes = IO.FileUtils.ReadFile (wirelessPath);
                        if (bytes.Length > 1) {
                            onePortWirelessFR = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortWirelessFR> (MyEncodingUTF8.GetString (bytes));
                        }
                        onePortWirelessFR.SubnetID = subnetID;
                        onePortWirelessFR.DeviceID = deviceID;
                        onePortWirelessFR.ChNumberCount = usefullBytes [4];
                        onePortWirelessFR.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                        onePortWirelessFR.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                        onePortWirelessFR.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                        onePortWirelessFR.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                        onePortWirelessFR.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                        onePortWirelessFR.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                        onePortWirelessFR.DHCP = usefullBytes [51] == 0 ? false : true;
                        if (usefullBytes.Length == 80) {
                            onePortWirelessFR.EncryptionFlag = usefullBytes [53];
                            onePortWirelessFR.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
                            onePortWirelessFR.WirelessBand = usefullBytes [62];
                            onePortWirelessFR.WirelessChannel = usefullBytes [63];
                            onePortWirelessFR.WirelessPassword = MyEncodingGB2312.GetString (usefullBytes, 64, 16).Trim ('\0');
                        }
                        GateWayList.Add (onePortWirelessFR);
                        if (onePortWirelessFR.Name == "") {
                            onePortWirelessFR.Name = onePortWirelessFR.CommonLoopID.ToString ();
                        }
                        Application.RunOnMainThread (() => {
                            GuideAddGateway.InitGatewayRowView (onePortWirelessFR);
                            GuideAddGateway.InitGatewayRowView (superWireless);
                        });
                        //IO.FileUtils.SaveEquipmentMessage (onePortWirelessFR);
                        //System.Threading.Tasks.Task.Run (() => {
                        //    if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
                        //        var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, onePortWirelessFR.SubnetID, onePortWirelessFR.DeviceID, new byte [] { });
                        //        if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
                        //            UserConfig.Current.RemoteModeFile = "Equipment_" + onePortWirelessFR.Type.ToString () + "_" + onePortWirelessFR.SubnetID.ToString () + "_" + onePortWirelessFR.DeviceID.ToString ();
                        //            UserConfig.Current.SaveUserConfig ();
                        //        }
                        //    }
                        //});
                        #endregion
                        break;
                    case DeviceType.OnePortBus:
                        #region
                        OnePortBus onePortBus = new OnePortBus ();
                        string onePath = "Equipment_" + typeof (OnePortBus).Name + "_" + subnetID + "_" + deviceID;
                        var bytesOne = IO.FileUtils.ReadFile (onePath);
                        if (bytesOne.Length > 1) {
                            onePortBus = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortBus> (MyEncodingUTF8.GetString (bytesOne));
                        }
                        onePortBus.SubnetID = subnetID;
                        onePortBus.DeviceID = deviceID;
                        onePortBus.ChNumberCount = usefullBytes [4];
                        onePortBus.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                        onePortBus.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0'); ;
                        onePortBus.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                        onePortBus.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                        onePortBus.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                        onePortBus.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                        onePortBus.DHCP = usefullBytes [51] == 0 ? false : true;
                        //onePortBus.SubnetID = usefullBytes [52];
                        if (usefullBytes.Length == 53 + 1 + 8) {
                            onePortBus.EncryptionFlag = usefullBytes [53];
                            onePortBus.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
                        }
                        GateWayList.Add (onePortBus);
                        if (onePortBus.Name == "") {
                            onePortBus.Name = onePortBus.CommonLoopID.ToString ();
                        }
                        Application.RunOnMainThread (() => {
                            GuideAddGateway.InitGatewayRowView (onePortBus);
                        });
                        //IO.FileUtils.SaveEquipmentMessage (onePortBus);
                        //System.Threading.Tasks.Task.Run (() => {
                        //    if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
                        //        var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, onePortBus.SubnetID, onePortBus.DeviceID, new byte [] { });
                        //        if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
                        //            UserConfig.Current.RemoteModeFile = "Equipment_" + onePortBus.Type.ToString () + "_" + onePortBus.SubnetID.ToString () + "_" + onePortBus.DeviceID.ToString ();
                        //            UserConfig.Current.SaveUserConfig ();
                        //        }
                        //    }
                        //});
                        #endregion
                        break;
                    case DeviceType.RCU:
                        RCU RCU_Device = new RCU ();
                        string RCU_DevicePath = "Equipment_" + typeof (RCU).Name + "_" + subnetID + "_" + deviceID;
                        var RCU_DeviceBytes = IO.FileUtils.ReadFile (RCU_DevicePath);
                        if (RCU_DeviceBytes.Length > 1) {
                            RCU_Device = Newtonsoft.Json.JsonConvert.DeserializeObject<RCU> (MyEncodingUTF8.GetString (RCU_DeviceBytes));
                        }
                        RCU_Device.SubnetID = subnetID;
                        RCU_Device.DeviceID = deviceID;
                        RCU_Device.LoopID = usefullBytes [4];
                        RCU_Device.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                        RCU_Device.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                        RCU_Device.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                        RCU_Device.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                        RCU_Device.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                        RCU_Device.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                        RCU_Device.DHCP = usefullBytes [51] == 0 ? false : true;
                        RCU_Device.LinkNetworkLine = true;
                        GateWayList.Add (RCU_Device);
                        if (RCU_Device.Name == "") {
                            RCU_Device.Name = RCU_Device.CommonLoopID.ToString ();
                        }
                        //IO.FileUtils.SaveEquipmentMessage (RCU_Device);
                        break;
                    case DeviceType.MusicModel:
                        MusicModel mm = new MusicModel ();
                        GateWayList.Add (mm);
                        mm.SubnetID = subnetID;
                        mm.DeviceID = deviceID;
                        mm.ChNumberCount = usefullBytes [4];
                        mm.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                        mm.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                        mm.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                        mm.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                        mm.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                        mm.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                        mm.DHCP = 0;
                        if (mm.Name == "") {
                            mm.Name = mm.CommonLoopID.ToString ();
                        }
                        IO.FileUtils.SaveEquipmentMessage (mm);
                        IO.FileUtils.SaveEquipmentMessage (mm, "1");
                        break;
                    case DeviceType.MusicA31:
                        MusicA31 mm31 = new MusicA31 ();
                        GateWayList.Add (mm31);
                        mm31.SubnetID = subnetID;
                        mm31.DeviceID = deviceID;
                        mm31.ChNumberCount = usefullBytes [4];
                        mm31.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                        mm31.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                        mm31.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                        mm31.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                        mm31.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                        mm31.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                        mm31.DHCP = usefullBytes [51];
                        if (mm31.Name == "") {
                            mm31.Name = mm31.CommonLoopID.ToString ();
                        }
                        //mm31.SubnetID
                        IO.FileUtils.SaveEquipmentMessage (mm31);
                        IO.FileUtils.SaveEquipmentMessage (mm31, "1");
                        break;
                    default:
                    } else {
                        switch (deviceType) {
                        case DeviceType.SuperWireless:
                            #region
                            SuperWireless superWireless = new SuperWireless ();
                            string superWirelessPath = "Equipment_" + typeof (OnePortWirelessFR).Name + "_" + subnetID + "_" + deviceID;
                            var superWirelessbytes = IO.FileUtils.ReadFile (superWirelessPath);
                            if (superWirelessbytes.Length > 1) {
                                superWireless = Newtonsoft.Json.JsonConvert.DeserializeObject<SuperWireless> (MyEncodingUTF8.GetString (superWirelessbytes));
                            }
                            superWireless.SubnetID = subnetID;
                            superWireless.DeviceID = deviceID;
                            superWireless.ChNumberCount = usefullBytes [4];
                            superWireless.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                        break;
                            superWireless.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                            superWireless.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                            superWireless.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                            superWireless.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                            superWireless.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                            superWireless.DHCP = usefullBytes [51] == 0 ? false : true;
                            if (usefullBytes.Length == 80) {
                                superWireless.EncryptionFlag = usefullBytes [53];
                                superWireless.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
                                superWireless.WirelessBand = usefullBytes [62];
                                superWireless.WirelessChannel = usefullBytes [63];
                                superWireless.WirelessPassword = MyEncodingGB2312.GetString (usefullBytes, 64, 16).Trim ('\0');
                            }
                            GateWayList.Add (superWireless);
                            Application.RunOnMainThread (() => {
                                GuideAddGateway.InitGatewayRowView (superWireless);
                            });
                            //IO.FileUtils.SaveEquipmentMessage (superWireless);
                            //System.Threading.Tasks.Task.Run (() => {
                            //    if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
                            //        var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, superWireless.SubnetID, superWireless.DeviceID, new byte [] { });
                            //        if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
                            //            UserConfig.Current.RemoteModeFile = "Equipment_" + superWireless.Type.ToString () + "_" + superWireless.SubnetID.ToString () + "_" + superWireless.DeviceID.ToString ();
                            //            UserConfig.Current.SaveUserConfig ();
                            //        }
                            //    }
                            //});
                            #endregion
                            break;
                        case DeviceType.OnePortWirelessFR:
                            #region
                            OnePortWirelessFR onePortWirelessFR = new OnePortWirelessFR ();
                            string wirelessPath = "Equipment_" + typeof (OnePortWirelessFR).Name + "_" + subnetID + "_" + deviceID;
                            var bytes = IO.FileUtils.ReadFile (wirelessPath);
                            if (bytes.Length > 1) {
                                onePortWirelessFR = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortWirelessFR> (MyEncodingUTF8.GetString (bytes));
                            }
                            onePortWirelessFR.SubnetID = subnetID;
                            onePortWirelessFR.DeviceID = deviceID;
                            onePortWirelessFR.ChNumberCount = usefullBytes [4];
                            onePortWirelessFR.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                            onePortWirelessFR.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                            onePortWirelessFR.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                            onePortWirelessFR.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                            onePortWirelessFR.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                            onePortWirelessFR.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                            onePortWirelessFR.DHCP = usefullBytes [51] == 0 ? false : true;
                            if (usefullBytes.Length == 80) {
                                onePortWirelessFR.EncryptionFlag = usefullBytes [53];
                                onePortWirelessFR.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
                                onePortWirelessFR.WirelessBand = usefullBytes [62];
                                onePortWirelessFR.WirelessChannel = usefullBytes [63];
                                onePortWirelessFR.WirelessPassword = MyEncodingGB2312.GetString (usefullBytes, 64, 16).Trim ('\0');
                            }
                            GateWayList.Add (onePortWirelessFR);
                            if (onePortWirelessFR.Name == "") {
                                onePortWirelessFR.Name = onePortWirelessFR.CommonLoopID.ToString ();
                            }
                            Application.RunOnMainThread (() => {
                                GuideAddGateway.InitGatewayRowView (onePortWirelessFR);
                            });
                            //IO.FileUtils.SaveEquipmentMessage (onePortWirelessFR);
                            //System.Threading.Tasks.Task.Run (() => {
                            //    if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
                            //        var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, onePortWirelessFR.SubnetID, onePortWirelessFR.DeviceID, new byte [] { });
                            //        if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
                            //            UserConfig.Current.RemoteModeFile = "Equipment_" + onePortWirelessFR.Type.ToString () + "_" + onePortWirelessFR.SubnetID.ToString () + "_" + onePortWirelessFR.DeviceID.ToString ();
                            //            UserConfig.Current.SaveUserConfig ();
                            //        }
                            //    }
                            //});
                            #endregion
                            break;
                        case DeviceType.OnePortBus:
                            #region
                            OnePortBus onePortBus = new OnePortBus ();
                            string onePath = "Equipment_" + typeof (OnePortBus).Name + "_" + subnetID + "_" + deviceID;
                            var bytesOne = IO.FileUtils.ReadFile (onePath);
                            if (bytesOne.Length > 1) {
                                onePortBus = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortBus> (MyEncodingUTF8.GetString (bytesOne));
                            }
                            onePortBus.SubnetID = subnetID;
                            onePortBus.DeviceID = deviceID;
                            onePortBus.ChNumberCount = usefullBytes [4];
                            onePortBus.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                            onePortBus.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0'); ;
                            onePortBus.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                            onePortBus.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                            onePortBus.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                            onePortBus.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                            onePortBus.DHCP = usefullBytes [51] == 0 ? false : true;
                            //onePortBus.SubnetID = usefullBytes [52];
                            if (usefullBytes.Length == 53 + 1 + 8) {
                                onePortBus.EncryptionFlag = usefullBytes [53];
                                onePortBus.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
                            }
                            GateWayList.Add (onePortBus);
                            if (onePortBus.Name == "") {
                                onePortBus.Name = onePortBus.CommonLoopID.ToString ();
                            }
                            Application.RunOnMainThread (() => {
                                GuideAddGateway.InitGatewayRowView (onePortBus);
                            });
                            //IO.FileUtils.SaveEquipmentMessage (onePortBus);
                            //System.Threading.Tasks.Task.Run (() => {
                            //    if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
                            //        var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, onePortBus.SubnetID, onePortBus.DeviceID, new byte [] { });
                            //        if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
                            //            UserConfig.Current.RemoteModeFile = "Equipment_" + onePortBus.Type.ToString () + "_" + onePortBus.SubnetID.ToString () + "_" + onePortBus.DeviceID.ToString ();
                            //            UserConfig.Current.SaveUserConfig ();
                            //        }
                            //    }
                            //});
                            #endregion
                            break;
                        case DeviceType.RCU:
                            RCU RCU_Device = new RCU ();
                            string RCU_DevicePath = "Equipment_" + typeof (RCU).Name + "_" + subnetID + "_" + deviceID;
                            var RCU_DeviceBytes = IO.FileUtils.ReadFile (RCU_DevicePath);
                            if (RCU_DeviceBytes.Length > 1) {
                                RCU_Device = Newtonsoft.Json.JsonConvert.DeserializeObject<RCU> (MyEncodingUTF8.GetString (RCU_DeviceBytes));
                            }
                            RCU_Device.SubnetID = subnetID;
                            RCU_Device.DeviceID = deviceID;
                            RCU_Device.LoopID = usefullBytes [4];
                            RCU_Device.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                            RCU_Device.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                            RCU_Device.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                            RCU_Device.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                            RCU_Device.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                            RCU_Device.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                            RCU_Device.DHCP = usefullBytes [51] == 0 ? false : true;
                            RCU_Device.LinkNetworkLine = true;
                            GateWayList.Add (RCU_Device);
                            if (RCU_Device.Name == "") {
                                RCU_Device.Name = RCU_Device.CommonLoopID.ToString ();
                            }
                            //IO.FileUtils.SaveEquipmentMessage (RCU_Device);
                            break;
                        case DeviceType.MusicModel:
                            MusicModel mm = new MusicModel ();
                            GateWayList.Add (mm);
                            mm.SubnetID = subnetID;
                            mm.DeviceID = deviceID;
                            mm.ChNumberCount = usefullBytes [4];
                            mm.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                            mm.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                            mm.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                            mm.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                            mm.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                            mm.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                            mm.DHCP = 0;
                            if (mm.Name == "") {
                                mm.Name = mm.CommonLoopID.ToString ();
                            }
                            IO.FileUtils.SaveEquipmentMessage (mm);
                            IO.FileUtils.SaveEquipmentMessage (mm, "1");
                            break;
                        case DeviceType.MusicA31:
                            MusicA31 mm31 = new MusicA31 ();
                            GateWayList.Add (mm31);
                            mm31.SubnetID = subnetID;
                            mm31.DeviceID = deviceID;
                            mm31.ChNumberCount = usefullBytes [4];
                            mm31.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
                            mm31.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
                            mm31.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
                            mm31.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
                            mm31.IPMAC = usefullBytes [41] + "." + usefullBytes [42] + "." + usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
                            mm31.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
                            mm31.DHCP = usefullBytes [51];
                            if (mm31.Name == "") {
                                mm31.Name = mm31.CommonLoopID.ToString ();
                            }
                            //mm31.SubnetID
                            IO.FileUtils.SaveEquipmentMessage (mm31);
                            IO.FileUtils.SaveEquipmentMessage (mm31, "1");
                            break;
                        default:
                            break;
                        }
                    }
                    //GuideAddGateway.InitGatewayRowView (new Common () {
                    //    SubnetID = subnetID, DeviceID = deviceID, Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0')
                    //});