wxr
2022-12-14 a61775710f8c4466db5bfce58af58f886d58edf3
SmartHome/UI/SimpleControl/CommonPage.cs
@@ -13,7 +13,7 @@
        //public static AirQuality AirQuality;
        //public static Action RefreshAir;           
        public static bool IsRemote = false;
        public static bool FindGateway = false;
        //public static bool FindGateway = false;
        public static bool FindGatewayChilren = false;
        public static string FindGatewayChilrenIPAddress = new Net.NetWiFi ().BroadcastIpAddress.ToString ();
        public static bool LocalPhoneFindDevice = false;
@@ -32,17 +32,18 @@
                        }
                        return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (ip), 9999);
                    } else {
                        if (FindGateway) {
                            return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 6000);
                        } else if (FindGatewayChilren) {
                            try {
                                return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (FindGatewayChilrenIPAddress), 6000);
                            } catch {
                                return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 6000);
                            }
                        } else {
                        //if (FindGateway) {
                        //    return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 6000);
                        //} else if (FindGatewayChilren) {
                        //    try {
                        //        return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (FindGatewayChilrenIPAddress), 6000);
                        //    } catch {
                        //        return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 6000);
                        //    }
                        //} else {
                        //    return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new Net.NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
                        //}
                            return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new Net.NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
                        }
                    }
                } catch {
                    //防止异常导致程序退出
@@ -73,11 +74,40 @@
        static object lockobj = new object ();
        static List<int> supportList = new List<int> () {
            228, 229,230,4618, 231, 232, 233, 234, 235, 236, 237, 238
            ,740,741,742,743,744,745,746,750,752,754, 755,756,757,761,758,759,760,762,894,
            4602,4604 ,4613, 4622,4605,4606,4607,4609, 4611,4620,4621,4615,4617,4619,4612,
            36865,9600,19600,
            1099,1163,3501,3502,3503,3504,3505,3506,
            3508,3509,3516,3517,3521,3527,3528,3530,3532,3533,3534,3536,3538,
            3539,3541,3543,3550,3559,3600,3601,3605,4599,4601,4602,
            30001,63479,65282,65532,65534,
        };
        static void Packet_ReceiveEvent (byte subnetID, byte deviceID, Command command, byte [] usefullBytes,int deviceTypeNumber)
        {
            try {
                List<byte> ButtonBkeyModelList = new List<byte> ();
                switch (command) {
                case Command.ReadRemarkACK:
                    if(supportList.Contains(deviceTypeNumber)) {
                        lock (GateWayList) {
                            if (GateWayList.Find ((l) => { return l.SubnetID == subnetID && l.DeviceID == deviceID; }) != null) {
                                return;
                            }
                            DeviceType deviceType = (DeviceType)(usefullBytes [2] * 256 + usefullBytes [3]);
                            GatewayBase gatewayBase = new GatewayBase ();
                            gatewayBase.DeviceTypeNumber = deviceTypeNumber;
                            gatewayBase.SubnetID = subnetID;
                            gatewayBase.DeviceID = deviceID;
                            gatewayBase.Type = deviceType;
                            gatewayBase.Name = MyEncodingGB2312.GetString (usefullBytes, 0, 20).Trim ('\0');//=============
                            GateWayList.Add (gatewayBase);
                        }
                    }
                    break;
                //读取网关设备回复
                case Command.ReadGatewayACK:
                    if (usefullBytes [0] != RandomHigh | usefullBytes [1] != RandomLow) {