CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2023-01-06 c05a93ddb0714a310a31574aaf030e677d9a07b6
增加多网关绑定支持
5个文件已修改
106 ■■■■ 已修改文件
Crabtree/ON/Properties/AndroidManifest.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/HDL/Operation/Packet.cs 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/ON/Properties/AndroidManifest.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtreenew" android:versionName="2.712301" android:versionCode="202212301">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtreenew" android:versionName="2.801062" android:versionCode="202301062">
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="30" />
    <!-- 在安卓P版本之后,必须要授予FOREGROUND_SERVICE权限,才能够使用前台服务 -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Crabtree/SmartHome/HDL/Operation/Packet.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shared.SimpleControl;
namespace Shared
{
@@ -57,8 +58,10 @@
        /// </summary>
        public virtual void Manager ()
        {
            //加密检测
            EncryptionDetection ();
            if (CommonPage.needEncryptionDetection) {
                //加密检测
                EncryptionDetection ();
            }
            //var mes2 = System.Text.Encoding.ASCII.GetString (Bytes, 0, Bytes.Length);
            //Utlis.WriteLine ($"============>GetBytes :{mes2}");
Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs
@@ -28,6 +28,11 @@
        public static bool LocalPhoneFindDevice = false;
        public static int searchTotal = 0;
        private static string ip="0.0.0.0";
        /// <summary>
        /// 是否需要加密检测、、为了适配多网关,搜索添加网关的时候需要关掉加密检测,然后同时发送密文,明文搜索网关 2023-01-06 16:49:30
        /// </summary>
        public static bool needEncryptionDetection = true;
        public static System.Net.IPEndPoint EndPoint {
            get {
                try {
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs
@@ -17,6 +17,21 @@
        {
            BackgroundColor = SkinStyle.Current.MainColor;
            inThisView = true;
            //var secretKeyPack = HttpServerRequest.Current.ApplyDeviceSecret ("3782DACE9D900428");
            //if (secretKeyPack != null) {
            //    if (secretKeyPack.Code == StateCode.SUCCESS) {
            //        var pack = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceSecret> (secretKeyPack.Data.ToString ());
            //        if (pack != null) {
            //            byte [] usefullBytes = new byte [17];
            //            usefullBytes [0] = 1;
            //            byte [] ddd = System.Text.Encoding.ASCII.GetBytes (pack.deviceSecret);
            //            Array.Copy (ddd, 0, usefullBytes, 1, 16 < ddd.Length ? 16 : ddd.Length);
            //        }
            //    }
            //}
        }
        public override void RemoveFromParent ()
@@ -427,6 +442,8 @@
                        MainPage.Loading.Start ("Searching for gateway...");
                    });
                    #region 搜索设备
                    //是否需要加密检测、、为了适配多网关,搜索添加网关的时候需要关掉加密检测,然后同时发送密文,明文搜索网关 2023-01-06 16:49:30
                    CommonPage.needEncryptionDetection = false;
                    ////2020-01-14 默认明文开始搜索
                    UserConfig.Instance.IsLocalEncrypt = false;
                    UserConfig.Instance.EncryptedPasswordCorrect = true;
@@ -482,8 +499,57 @@
                            readCount = 3;
                        }
                    }
                    CommonPage.FindGateway = false;
                    //2023-01-06 16:33:09 增加同时发送密文搜索
                    CommonPage.needEncryptionDetection = true;
                    UserConfig.Instance.IsLocalEncrypt = true;
                    readCount = 3;
                    while (0 < readCount) {
                        readCount--;
                        System.IO.MemoryStream ms = new System.IO.MemoryStream ();
                        ms.WriteByte (CommonPage.RandomHigh);
                        ms.WriteByte (CommonPage.RandomLow);
                        List<Common> list = CommonPage.GateWayList;
                        int tempCount = list.Count;
                        string s = ";";
                        for (int i = 0; i < list.Count; i++) {
                            Common common = list [i];
                            if (s.Contains (";" + common.SubnetID.ToString () + ":" + common.DeviceID.ToString ()))
                                continue;
                            s += common.SubnetID.ToString () + ":" + common.DeviceID.ToString () + ";";
                            ms.WriteByte (common.SubnetID);
                            ms.WriteByte (common.DeviceID);
                        }
                        Control control = new Control ();
                        Utlis.WriteLine ("组播搜索网关,搜索地址是:" + CommonPage.EndPoint.ToString () + "    " + CommonPage.GateWayList.Count);
                        control.Send (new Target () {
                            IPEndPoint = CommonPage.EndPoint,
                            Command = Command.ReadGateway,
                            SubnetID = 0xFF,
                            DeviceID = 0xFF,
                            AddData = ms.ToArray ()
                        }, SendCount.Zero, false);
                        Utlis.WriteLine ("广播搜索网关,搜索地址是:" + new Net.NetWiFi ().BroadcastIpAddress.ToString () + "    " + CommonPage.GateWayList.Count);
                        control.Send (new Target () {
                            IPEndPoint = new System.Net.IPEndPoint (new Net.NetWiFi ().BroadcastIpAddress, 6000),
                            Command = Command.ReadGateway,
                            SubnetID = 0xFF,
                            DeviceID = 0xFF,
                            AddData = ms.ToArray ()
                        }, SendCount.Zero, false);
                        System.Threading.Thread.Sleep (800);
                        //如果数量不相等,就重置次数
                        if (tempCount != CommonPage.GateWayList.Count) {
                            readCount = 3;
                        }
                    }
                    CommonPage.FindGateway = false;
                    CommonPage.LocalPhoneFindDevice = false;
                    #endregion
                } catch (Exception ex) {
@@ -645,14 +711,14 @@
            //    //UserConfig.Instance.LocalEncryptKey = aseKeyStr;
            //    Utlis.WriteLine ($"============>LocalEncryptKey 加密成功Key为:{UserConfig.Instance.LocalEncryptKey}");
            //}
            UserConfig.Instance.IsLocalEncrypt = false;
            var backBytes = Control.ControlBytesSendHasReturn (Command.Read_APP_Data_STORE_1D5C_CMD, common.SubnetID, common.DeviceID, new byte [] { });
          
            if (backBytes == null) {
                Application.RunOnMainThread (() => {
                    new Alert ("", "No response from gateway. Please make sure the gateway is online and its firmware is up to date.", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                });
                return false;
            }
            if (backBytes.Length >= 37) {
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
@@ -980,20 +980,28 @@
                var result = Control.ControlBytesSendHasReturn (Command.ApplyServerKey, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { 0});
                if (result != null && result.Length > 1) {
                    if (result [1] == 0xF5) {
                        var secretKeyPack = HttpServerRequest.Current.ApplyDeviceSecret (gatewayDeicve.MAC);
                        var secretKeyPack = HttpServerRequest.Current.ApplyDeviceSecret (gatewayDeicve.MAC.Replace(".",""));
                        if (secretKeyPack != null) {
                            if (secretKeyPack.Code == StateCode.SUCCESS) {
                                var pack = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceSecret> (secretKeyPack.Data.ToString ());
                                if (pack != null) {
                                    byte [] usefullBytes = new byte [17];
                                    usefullBytes [0] = 1;
                                    byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (pack.deviceSecret);
                                    byte [] ddd = System.Text.Encoding.ASCII.GetBytes (pack.deviceSecret);
                                    Array.Copy (ddd, 0, usefullBytes, 1, 16 < ddd.Length ? 16 : ddd.Length);
                                    var result2 = Control.ControlBytesSendHasReturn (Command.ApplyServerKey, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, usefullBytes);
                                    var result3 = Control.ControlBytesSendHasReturn (Command.RestartTheGateway, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
                                    Application.RunOnMainThread (() => {
                                        new Alert ("", "The Internet access key was successfully written, and the gateway is being restarted!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                    });
                                    //byte [] restartArray = new byte [12];
                                    //string [] macArray = gatewayDeicve.MAC.Split (".");
                                    //for(int i = 0; i < macArray.Length; i++) {
                                    //    restartArray [i + 2] = Convert.ToByte (macArray [i], 16);
                                    //}
                                    //restartArray [10] = gatewayDeicve.SubnetID;
                                    //restartArray [11] = gatewayDeicve.DeviceID;
                                    //var result3 = Control.ControlBytesSendHasReturn (Command.RestartTheGateway, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, restartArray);
                                    //Application.RunOnMainThread (() => {
                                    //    new Alert ("", "The Internet access key was successfully written, and the gateway is being restarted!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                    //});
                                }
                            }
                        } else {