From 4c993fcb71b92f8e9837ca8f50f3b5e8f9c59cfe Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期三, 20 一月 2021 19:47:04 +0800 Subject: [PATCH] 2021-01-20 1.更新。2.增加写域名配置操作。 --- Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs | 260 ++++++++++++++++++++++--- Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs | 269 +++++++++++++++----------- Crabtree/SmartHome/HDL/Operation/Control.cs | 2 Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs | 3 Crabtree/.vs/SmartHome/xs/UserPrefs.xml | 24 +- Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs | 3 Crabtree/SmartHome/HDL/Operation/MyEnum.cs | 8 7 files changed, 407 insertions(+), 162 deletions(-) diff --git a/Crabtree/.vs/SmartHome/xs/UserPrefs.xml b/Crabtree/.vs/SmartHome/xs/UserPrefs.xml index bd66048..49811cc 100644 --- a/Crabtree/.vs/SmartHome/xs/UserPrefs.xml +++ b/Crabtree/.vs/SmartHome/xs/UserPrefs.xml @@ -1,27 +1,23 @@ 锘�<Properties StartupConfiguration="{1D83BF28-BA88-4152-BA41-D7EFE90A5437}|Default"> <MonoDevelop.Ide.ItemProperties.ON.Droid PreferredExecutionTarget="Android.Android_Accelerated_Oreo" /> - <MonoDevelop.Ide.Workbench ActiveDocument="SmartHome/HDL/Common/HttpUtil/HttpUtil.cs"> - <Files> - <File FileName="SmartHome/HDL/Common/HDLLinkUtlis.cs" Line="56" Column="20" /> - <File FileName="SmartHome/HDL/Common/HttpUtil/HttpUtil.cs" Line="521" Column="46" /> - </Files> + <MonoDevelop.Ide.Workbench> <Pads> <Pad Id="ProjectPad"> <State name="__root__"> - <Node name="SmartHome" expanded="True"> + <Node name="SmartHome" expanded="True" selected="True"> <Node name="ON.Droid" expanded="True" /> - <Node name="ON.Ios" expanded="True" /> <Node name="Shared" expanded="True"> <Node name="HDL" expanded="True"> - <Node name="Common" expanded="True"> - <Node name="HttpUtil" expanded="True"> - <Node name="HttpUtil.cs" selected="True" /> - </Node> + <Node name="Common" expanded="True" /> + <Node name="Operation" expanded="True"> + <Node name="Device" expanded="True" /> </Node> </Node> <Node name="UI" expanded="True"> <Node name="SimpleControl" expanded="True"> - <Node name="Phone" expanded="True" /> + <Node name="Phone" expanded="True"> + <Node name="Guide" expanded="True" /> + </Node> </Node> </Node> </Node> @@ -38,8 +34,8 @@ <String>IosService/IosService.csproj</String> <String>DroidService/DroidService.csproj</String> </DisabledProjects> - <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|iPhone" /> - <MonoDevelop.Ide.ItemProperties.ON.Ios PreferredExecutionTarget="MonoDevelop.IPhone.IPhoneDeviceTarget.00008030-00014C392121802E" /> + <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|iPhoneSimulator" /> + <MonoDevelop.Ide.ItemProperties.ON.Ios PreferredExecutionTarget="MonoDevelop.IPhone.IPhoneSimulatorTarget.08FD445C-3EE8-4ED2-BF28-B42ADD0DA92C" /> <MonoDevelop.Ide.DebuggingService.Breakpoints> <BreakpointStore /> </MonoDevelop.Ide.DebuggingService.Breakpoints> diff --git a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs index fd49cfb..3671959 100644 --- a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs +++ b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs @@ -27,6 +27,9 @@ // } // #endregion + + + // /// <summary> // /// 灏嗗湪绾胯澶囪浆鎹㈡垚sid + 灞炴�у垪琛� // /// </summary> @@ -51,13 +54,13 @@ // } // if (onlineDevice.bytSimpleParam != null && onlineDevice.bytSimpleParam.Length > 0) { // for (int intI = 0; intI < onlineDevice.bytSimpleParam.Length / 3; intI++) { -// Byte BigType = onlineDevice.bytSimpleParam [0 + intI * 3]; -// Byte SmallType = onlineDevice.bytSimpleParam [1 + intI * 3]; +// byte BigType = onlineDevice.bytSimpleParam [0 + intI * 3]; +// byte SmallType = onlineDevice.bytSimpleParam [1 + intI * 3]; // int Count = onlineDevice.bytSimpleParam [2 + intI * 3]; // if (Count > 0) { // for (int j = 1; j <= Count; j++) { // Sid tmpSid = new Sid (); -// tmpSid.sid = HDLSysPF.FormingNewSid (onlineDevice.DeviceType, sOid, j, false, BigType, SmallType); +// tmpSid.sid = HDLSysPF.FormingNewSid (onlineDevice.Type, sOid, j, false, BigType, SmallType); // tmpSid.oid = sOid; // try { @@ -181,50 +184,116 @@ // /// </summary> // /// <param name="iDeviceType"></param> // /// <returns></returns> -// public string FormingNewOid (int iDeviceType) +// public string FormingNewOid (DeviceType deviceType) // { // string sOid = ""; // try { +// //1.鐢熸垚 鍘傚晢 + 閫氳鏂瑰紡 // string sOidBeginsWith = "000101";//鍘傚晢 + 閫氳鏂瑰紡 - -// long sTimeSp = HDLSysPF.ConvertDateTimeLong (); +// //2.鐢熸垚浜у搧鏃堕棿鎴� +// long sTimeSp = ConvertDateTimeLong (); //浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣� // string sTimeSpan = ""; -// GateWay.ConvertIntToByteArray (sTimeSp, ref sTimeSpan); - +// ConvertIntToByteArray (sTimeSp, ref sTimeSpan); // if (sTimeSpan.Length != 8) return sOid; -// HDLUDP.TimeBetwnNext (10); -// sOid = sOidBeginsWith + sTimeSpan; -// if (iDeviceType == 00 -// || DimmerDeviceTypeList.HDLDimmerDeviceTypeList.Contains (iDeviceType) -// || DMXDeviceTypeList.HDLDMXDeviceTypeList.Contains (iDeviceType))//璋冨厜鍣� 20200730绫� -// { -// sOid += "01"; -// } else if (RelayDeviceTypeList.HDLRelayDeviceTypeList.Contains (iDeviceType))//缁х數鍣ㄧ被 -// { -// sOid += "02"; -// } else if (CurtainDeviceType.HDLCurtainModuleDeviceType.Contains (iDeviceType))//閬槼绫伙紙绐楀笜锛� -// { -// sOid += "03"; -// } else if (HVACModuleDeviceTypeList.HDLHVACModuleDeviceTypeLists.Contains (iDeviceType) || FloorheatingDeviceTypeList.HDLFloorHeatingDeviceType.Contains (iDeviceType))//鎭掓俯鍣紙绌鸿皟锛� -// { -// sOid += "12"; -// } else if (AudioDeviceTypeList.AudioBoxDeviceTypeList.Contains (iDeviceType)) { -// sOid += "10"; -// } else if (Eightin1DeviceTypeList.HDL8in1DeviceType.Contains (iDeviceType) -// || Sevenin1DeviceTypeList.HDL7in1DeviceType.Contains (iDeviceType) -// || Twelvein1DeviceTypeList.HDL12in1DeviceType.Contains (iDeviceType))//浼犳劅鍣ㄧ被 -// { -// sOid += "04"; -// } else { -// sOid += "07"; //缃戝叧浜у搧 -// } +// //寤惰繜10ms +// //3.鐢熸垚浜у搧绫诲埆 +// var productType = GetProductType (deviceType); +// sOid = sOidBeginsWith + sTimeSpan + productType; // return sOid; // } catch { // return sOid; // } // } + +// /// <summary> +// /// 鑾峰彇浜у搧绫诲埆 +// //浜у搧绫诲埆 1byte +// //缂栧彿 鎻忚堪 +// //01 璋冨厜鍣� +// //02 缁х數鍣� +// //03 骞叉帴鐐规ā鍧� +// //04 浼犳劅鍣� +// //05 闈㈡澘 +// //06 RCU +// //07 缃戝叧 +// //08 绾㈠鍙戝皠 +// //09 Android灞� +// //10 鍦烘櫙 +// //11 闊充箰鎾斁鍣� +// //12 232/485杞崲鍣� +// //21 鑷姩鍖� +// //22 瀹夐槻闃插尯 +// //14 绐楀笜妯″潡 +// //15 HVAC +// //16 鍦扮儹妯″潡 +// /// </summary> +// /// <param name="deviceType"></param> +// /// <returns></returns> +// public string GetProductType (DeviceType deviceType) +// { +// string productType = ""; +// switch (deviceType) { +// case DeviceType.LightDimming: +// productType = "01";//01 璋冨厜鍣� +// break; +// case DeviceType.LightSwitch: +// productType = "02";//02 缁х數鍣ㄧ被 +// break; +// case DeviceType.CurtainModel: +// case DeviceType.CurtainRoller: +// case DeviceType.CurtainTrietex: +// productType = "03";//03 閬槼绫伙紙绐楀笜锛� +// break; +// case DeviceType.SensorWindSpeed: +// productType = "04";//04 浼犳劅鍣級 +// break; +// case DeviceType.OnePortWirelessFR: +// case DeviceType.OnePortBus: +// case DeviceType.RCU: +// case DeviceType.SuperWireless: +// case DeviceType.OnePortMqttFR: +// productType = "07";//07 缃戝叧绫� +// break; +// case DeviceType.ACPanel: +// case DeviceType.ACDevice: +// case DeviceType.ACInfrared: +// case DeviceType.ACCoolmaster: +// case DeviceType.CustomAC: +// case DeviceType.HVAC: +// case DeviceType.FoolHeat: +// case DeviceType.FoolHeatPanel: +// productType = "12";//12 鎭掓俯鍣紙绌鸿皟銆佸湴鐑級 +// break; + +// } + +// return productType; +// } + + + +// /// <summary> +// /// 鑾峰彇鐢熸垚鐗╃悊妯″瀷鍙傛暟 + +// /// </summary> +// /// <param name="deviceType"></param> +// /// <returns></returns> +// public string GetPhysicalModelType (DeviceType deviceType) +// { +// string productType = ""; +// switch (deviceType) { +// case DeviceType.LightDimming: +// productType = "0101"; +// break; +// } + +// return productType; +// } + + + // /// <summary> // /// 鐢熸垚鍔熻兘璁惧Sid @@ -300,6 +369,33 @@ // } // } +// private long LastTime = 0; +// /// <summary> +// /// DateTime鏃堕棿鏍煎紡杞崲涓�13浣嶅甫姣鐨刄nix鏃堕棿鎴� +// /// </summary> +// /// <param name="time"> DateTime鏃堕棿鏍煎紡</param> +// /// <returns>Unix鏃堕棿鎴虫牸寮�</returns> +// public long ConvertDateTimeLong () +// { +// System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (new System.DateTime (2020, 1, 1)); +// long l = (long)(Math.Round ((DateTime.Now - startTime).TotalSeconds, 1) * 10); +// if (l <= LastTime) l = LastTime + 1; +// LastTime = l; +// return l; +// } + +// public bool ConvertIntToByteArray (long m, ref string strTmp) +// { +// strTmp = "00000000"; +// byte [] arry = new byte [4]; +// arry [0] = (byte)(m & 0xFF); +// arry [1] = (byte)((m & 0xFF00) >> 8); +// arry [2] = (byte)((m & 0xFF0000) >> 16); +// arry [3] = (byte)((m & 0xFF000000) >> 24); +// strTmp = arry [0].ToString ("X2") + arry [1].ToString ("X2") + arry [2].ToString ("X2") + arry [3].ToString ("X2"); +// return true; +// } + // } @@ -349,7 +445,7 @@ // { // public string sid { get; set; } // public string name { get; set; } -// public string[] uids { get; set; } +// public string [] uids { get; set; } // public string spk { get; set; } // public string oid { get; set; } //璁惧妯″潡鍦板潃 @@ -370,3 +466,97 @@ // } //} + + +////sid缁勬垚閮ㄥ垎锛� +////sid +////鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆 +////1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte +////oid缁勬垚閮ㄥ垎锛� +////鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 +////1byte 1 byte 1 byte 4 byte 1byte +////鍏朵腑鍚勯儴鍒嗕唬鐮佸垪琛細 +////鏉ユ簮 1byte 缂栧彿 鎻忚堪 +//// 00 榛樿鍘熺敓鎬佺郴缁熸暟鎹� +//// 01 缃戝叧鎴栬�呭叾浠朅璁惧 +//// 02 璋冭瘯杞欢 +//// 03 APP搴旂敤绋嬪簭 +//// 04 绗笁鏂圭綉鍏虫垨鑰呭钩鍙� + +////鍘傚晢浠g爜 1byte 缂栧彿 鎻忚堪 +//// 01 HDL +//// 02 + +////閫氳鏂瑰紡 1byte 缂栧彿 鎻忚堪 +//// 01 HDL Bus +//// 02 Zigbee +//// 03 KNX +//// 04 Z-Wave + +////浜у搧鏃堕棿鎴� 4bytes 浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣� + +////浜у搧绫诲埆 1byte 缂栧彿 鎻忚堪 +//// 01 璋冨厜鍣� +//// 02 缁х數鍣� +//// 03 骞叉帴鐐规ā鍧� +//// 04 浼犳劅鍣� +//// 05 闈㈡澘 +//// 06 RCU +//// 07 缃戝叧 +//// 08 绾㈠鍙戝皠 +//// 09 Android灞� +//// 10 鍦烘櫙 +//// 11 闊充箰鎾斁鍣� +//// 12 232/485杞崲鍣� +//// 21 鑷姩鍖� +//// 22 瀹夐槻闃插尯 +//// 14 绐楀笜妯″潡 +//// 15 HVAC +//// 16 鍦扮儹妯″潡 + +////鐗╂ā鍨嬬被鍨� 2bytes 缂栧彿 鎻忚堪 +//// 01 寮�鍏崇被 01 寮�鍏� +//// 02 鎻掑骇 +//// 03 +//// 02 鐓ф槑 01 寮�鍏� +//// 02 璋冨厜 +//// 03 鑹叉俯(CCT) +//// 04 RGB +//// 03 閬槼 01 绐楀笜鎺у埗鍣� +//// 02 鐧惧彾绐� +//// 03 寮�鍚堝笜 +//// 04 鍗峰笜 +//// 05 聽鎺ㄧ獥鍣� +//// 06 聽鎶曞奖骞� +//// 04 闈㈡澘 01 鎸夐敭闈㈡澘 +//// 05 浼犳劅鍣� 01 绉诲姩鎺㈡祴 +//// 02 娓╁害浼犳劅鍣� +//// 03 婀垮害浼犳劅鍣� +//// 04 鐓у害浼犳劅鍣� +//// 05 TVOC +//// 06 PM2.5 +//// 07 CO2 +//// 08 姣背娉紶鎰熷櫒 +//// 09 +//// 10 +//// 11 鐑熼浘浼犳劅鍣� +//// 25 骞叉帴鐐� +//// 07 鎭掓俯鍣� 01 绌鸿皟 +//// 02 椋庢墖 +//// 03 姣涚粏绌鸿皟 +//// 08 鍦扮儹 01 鍦扮儹妯″潡 +//// 09 鑳屾櫙闊充箰 01 闊充箰鎾斁鍣� +//// 02 Sonos +//// 10 鍦烘櫙 01 鍦烘櫙 +//// 02 鐢靛奖鍦烘櫙 +//// 19 鏂伴 01 鏂伴 + +////13 鑳芥簮 01 鐢佃〃 +//// 02 姘磋〃 +//// 03 鐕冩皵 +//// 16 鐢靛櫒 01 椋庢墖 +//// 02 TV +//// 20 瀹夐槻 01 瀹夐槻 +//// 21 鑷姩鍖� 01 鑷姩鍖� +////澶х被鍒� 1bytes 锛堥鐣欙級 +////灏忕被鍒� 1byte 锛堥鐣欙級 \ No newline at end of file diff --git a/Crabtree/SmartHome/HDL/Operation/Control.cs b/Crabtree/SmartHome/HDL/Operation/Control.cs index 8bbe6cf..e56a814 100644 --- a/Crabtree/SmartHome/HDL/Operation/Control.cs +++ b/Crabtree/SmartHome/HDL/Operation/Control.cs @@ -167,6 +167,7 @@ case Command.SetGateWayAdminInfoACK: case Command.ReadGateWayLocalEncryptionACK: case Command.SetReadGateWayLocalEncryptionACK: + case Command.SetGateWayMqttURLAddressACK: //************************************ case Command.ReadGateWayModelInfoACK: case Command.ReadGatewayServerIPACK: @@ -523,6 +524,7 @@ case Command.SetGateWayAdminInfo: case Command.SetGateWayLocalEncryption: case Command.ReadGateWayLocalEncryption: + case Command.SetGateWayMqttURLAddress: //************************************ case Command.ReadGateWayModelInfo: case Command.ReadGatewayServerIP: diff --git a/Crabtree/SmartHome/HDL/Operation/MyEnum.cs b/Crabtree/SmartHome/HDL/Operation/MyEnum.cs index cdcfcab..d58bf05 100644 --- a/Crabtree/SmartHome/HDL/Operation/MyEnum.cs +++ b/Crabtree/SmartHome/HDL/Operation/MyEnum.cs @@ -1913,6 +1913,14 @@ SetGateWayLocalEncryption = 0x303E, SetReadGateWayLocalEncryptionACK = 0x303F, + /// <summary> + /// 淇敼缃戝叧杩滅▼杩炴帴鍩熷悕鍦板潃 + /// </summary> + SetGateWayMqttURLAddress = 0x3046, + SetGateWayMqttURLAddressACK = 0x3047, + + + /// <summary> /// 0xF003 diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs index 49afd5a..79a02cd 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddGateway.cs @@ -4,6 +4,9 @@ namespace Shared.SimpleControl.Phone { + /// <summary> + /// 鎼滅储鍜屽啓鍔犲瘑缃戝叧銆佺粦瀹氱綉鍏崇殑椤甸潰 + /// </summary> public class GuideAddGateway : FrameLayout { static GuideAddGateway inView; diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs index 9def5f4..4dafb7b 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideAddResidence.cs @@ -3,6 +3,9 @@ namespace Shared.SimpleControl.Phone { + /// <summary> + /// 浣忓畢鍒楄〃椤甸潰 + /// </summary> public class GuideAddResidence : FrameLayout { public bool IsHideBack = false; diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs index 2f278d8..156c47f 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs @@ -157,7 +157,7 @@ RemoteSettingWithHDLMQTT (); } else { Utlis.WriteLine ("Assign OnePortWirelessFR"); - RemoteSettingWithOldDevice (); + //RemoteSettingWithOldDevice (); //RemoteSettingWithMQTT (); } } @@ -602,134 +602,134 @@ - /// <summary> - /// 杩滅▼閰嶇疆 - /// </summary> - void RemoteSettingWithOldDevice () - { - byte [] gatewayBytes = null; - byte [] serverIPBytes = null; + ///// <summary> + ///// 杩滅▼閰嶇疆 + ///// </summary> + //void RemoteSettingWithOldDevice () + //{ + // byte [] gatewayBytes = null; + // byte [] serverIPBytes = null; - string [] strServerIP = (MainPage.SeviceIP).Split ('.'); - string [] strServerIP1 = (MainPage.SeviceIP).Split ('.'); - MainPage.Loading.Start ("Configuring device..."); - System.Threading.Tasks.Task.Run (() => { - try { + // string [] strServerIP = (MainPage.SeviceIP).Split ('.'); + // string [] strServerIP1 = (MainPage.SeviceIP).Split ('.'); + // MainPage.Loading.Start ("Configuring device..."); + // System.Threading.Tasks.Task.Run (() => { + // try { - //var currentRegionIdBytes = new byte [] { - // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256 / 256), - // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256), - // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256), - // (byte)(UserConfig.Instance.CurrentRegion.RegionID % 256), - //}; + // //var currentRegionIdBytes = new byte [] { + // // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256 / 256), + // // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256), + // // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256), + // // (byte)(UserConfig.Instance.CurrentRegion.RegionID % 256), + // //}; - //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); + // //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); - byte [] RegionIDBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.Id.ToString ()); - var currentRegionIdBytes = new byte [4]; - Array.Copy (RegionIDBytes, 0, currentRegionIdBytes, 0, 4 < RegionIDBytes.Length ? 4 : RegionIDBytes.Length); + // byte [] RegionIDBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.Id.ToString ()); + // var currentRegionIdBytes = new byte [4]; + // Array.Copy (RegionIDBytes, 0, currentRegionIdBytes, 0, 4 < RegionIDBytes.Length ? 4 : RegionIDBytes.Length); - gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); - serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); + // gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); + // serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); - gatewayDeicve.Remote_GroupName = MainPage.LoginUser.AccountString;//UserConfig.Instance.CurrentRegion.RegionName; - gatewayDeicve.Remote_ProjectName = gatewayDeicve.MAC.Replace (".", "");//UserConfig.Instance.CurrentRegion.RegionName; - gatewayDeicve.Remote_UserName = "Admin"; - gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.ID; - byte [] ggn = new byte [20]; - byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName); - gatewayDeicve.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1); - Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length); + // gatewayDeicve.Remote_GroupName = MainPage.LoginUser.AccountString;//UserConfig.Instance.CurrentRegion.RegionName; + // gatewayDeicve.Remote_ProjectName = gatewayDeicve.MAC.Replace (".", "");//UserConfig.Instance.CurrentRegion.RegionName; + // gatewayDeicve.Remote_UserName = "Admin"; + // gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.ID; + // byte [] ggn = new byte [20]; + // byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName); + // gatewayDeicve.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1); + // Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length); - byte [] gpn = new byte [20]; - byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_ProjectName); - Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length); + // byte [] gpn = new byte [20]; + // byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_ProjectName); + // Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length); - byte [] gun = new byte [8]; - byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_UserName); - Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length); + // byte [] gun = new byte [8]; + // byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_UserName); + // Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length); - byte [] gpw = new byte [8]; - byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_Password); - Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length); + // byte [] gpw = new byte [8]; + // byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_Password); + // Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length); - byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); + // byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { }); - gatewayBytes [0] = 2;//杩滅▼鏍囩ず - Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length); - Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length); - Array.Copy (gun, 0, gatewayBytes, 41, 8 < gun.Length ? 8 : gun.Length); - Array.Copy (gpw, 0, gatewayBytes, 49, 8 < gpw.Length ? 8 : gpw.Length); + // gatewayBytes [0] = 2;//杩滅▼鏍囩ず + // Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length); + // Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length); + // Array.Copy (gun, 0, gatewayBytes, 41, 8 < gun.Length ? 8 : gun.Length); + // Array.Copy (gpw, 0, gatewayBytes, 49, 8 < gpw.Length ? 8 : gpw.Length); - Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, gatewayBytes); + // Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, gatewayBytes); - serverIPBytes [0] = Convert.ToByte (strServerIP [0]); - serverIPBytes [1] = Convert.ToByte (strServerIP [1]); - serverIPBytes [2] = Convert.ToByte (strServerIP [2]); - serverIPBytes [3] = Convert.ToByte (strServerIP [3]); - int point1 = 9999; + // serverIPBytes [0] = Convert.ToByte (strServerIP [0]); + // serverIPBytes [1] = Convert.ToByte (strServerIP [1]); + // serverIPBytes [2] = Convert.ToByte (strServerIP [2]); + // serverIPBytes [3] = Convert.ToByte (strServerIP [3]); + // int point1 = 9999; - serverIPBytes [4] = Convert.ToByte (point1 / 256); - serverIPBytes [5] = Convert.ToByte (point1 % 256); + // serverIPBytes [4] = Convert.ToByte (point1 / 256); + // serverIPBytes [5] = Convert.ToByte (point1 % 256); - serverIPBytes [6] = Convert.ToByte (strServerIP1 [0]); - serverIPBytes [7] = Convert.ToByte (strServerIP1 [1]); - serverIPBytes [8] = Convert.ToByte (strServerIP1 [2]); - serverIPBytes [9] = Convert.ToByte (strServerIP1 [3]); - int point2 = 9999; + // serverIPBytes [6] = Convert.ToByte (strServerIP1 [0]); + // serverIPBytes [7] = Convert.ToByte (strServerIP1 [1]); + // serverIPBytes [8] = Convert.ToByte (strServerIP1 [2]); + // serverIPBytes [9] = Convert.ToByte (strServerIP1 [3]); + // int point2 = 9999; - serverIPBytes [10] = Convert.ToByte (point2 / 256); - serverIPBytes [11] = Convert.ToByte (point2 % 256); + // serverIPBytes [10] = Convert.ToByte (point2 / 256); + // serverIPBytes [11] = Convert.ToByte (point2 % 256); - //杩滅▼ip鍦板潃鐨勮缃� - var mobytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInternetInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, serverIPBytes); - if (mobytes == null) { - Application.RunOnMainThread (() => { - new Alert ("", ErrorCode.GatewayNoResponse, - Language.StringByID (R.MyInternationalizationString.Close)).Show (); - }); - } else if (mobytes [0] == 0xF5) { - Application.RunOnMainThread (() => { - new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), - Language.StringByID (R.MyInternationalizationString.Close)).Show (); - }); - } else { - if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR) { - var bindReginIdStatus = Control.ControlBytesSendHasReturn (Command.Write_APP_Data_STORE_1D5E_CMD, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, currentRegionIdBytes); - if (bindReginIdStatus == null) { - Application.RunOnMainThread (() => { - new Alert ("", ErrorCode.GatewayNoResponse, Language.StringByID (R.MyInternationalizationString.Close)).Show (); - }); - return; - } else if (bindReginIdStatus [0] != 0xF8) { - //new Alert ("", "缃戝叧缁戝畾浣忓畢澶辫触锛�", Language.StringByID (R.MyInternationalizationString.Close)).Show (); - Application.RunOnMainThread (() => { - new Alert ("", "Gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); - }); - return; - } - } - GotoHomePage (); - } - } catch (Exception ex) { - Utlis.WriteLine (ex.Message); - Application.RunOnMainThread (() => { - new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show (); - }); - bool canRemove = false; - } finally { - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - //this.RemoveAll (); - }); - } - }); - //Room.InitAllRoom (); - } + // //杩滅▼ip鍦板潃鐨勮缃� + // var mobytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInternetInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, serverIPBytes); + // if (mobytes == null) { + // Application.RunOnMainThread (() => { + // new Alert ("", ErrorCode.GatewayNoResponse, + // Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // }); + // } else if (mobytes [0] == 0xF5) { + // Application.RunOnMainThread (() => { + // new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), + // Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // }); + // } else { + // if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR) { + // var bindReginIdStatus = Control.ControlBytesSendHasReturn (Command.Write_APP_Data_STORE_1D5E_CMD, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, currentRegionIdBytes); + // if (bindReginIdStatus == null) { + // Application.RunOnMainThread (() => { + // new Alert ("", ErrorCode.GatewayNoResponse, Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // }); + // return; + // } else if (bindReginIdStatus [0] != 0xF8) { + // //new Alert ("", "缃戝叧缁戝畾浣忓畢澶辫触锛�", Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // Application.RunOnMainThread (() => { + // new Alert ("", "Gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // }); + // return; + // } + // } + // GotoHomePage (); + // } + // } catch (Exception ex) { + // Utlis.WriteLine (ex.Message); + // Application.RunOnMainThread (() => { + // new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show (); + // }); + // bool canRemove = false; + // } finally { + // Application.RunOnMainThread (() => { + // MainPage.Loading.Hide (); + // //this.RemoveAll (); + // }); + // } + // }); + // //Room.InitAllRoom (); + //} @@ -757,8 +757,11 @@ if (SetGateWayModelInfo()) { //2.淇敼绠$悊淇℃伅 if (SetGateWayAdminInfo ()) { - //3.鍐欓厤缃垚鍔熷悗涓嬩竴姝ユ搷浣� - GatewaySettingSucceeded (); + //3.鍐橫qtt杩滅▼鍩熷悕鍦板潃 + if (SetGateWayMqttUrlAddress ()) { + //4.鍐欓厤缃垚鍔熷悗涓嬩竴姝ユ搷浣� + GatewaySettingSucceeded (); + } } } @@ -846,10 +849,9 @@ /// <returns></returns> bool SetGateWayAdminInfo () { - byte [] name = CommonPage.MyEncodingGB2312.GetBytes (MainPage.LoginUser.AccountString); - //byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID); + //byte [] name = CommonPage.MyEncodingGB2312.GetBytes (MainPage.LoginUser.AccountString); + byte [] name = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.HomeGateway.gatewayId);//甯愬彿鍚嶆敼鎴恎atewayId byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.Id.ToString ()); - //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); byte [] adminBytes = new byte [73]; adminBytes [36] = 1;//浣忓畢鏍囧織浣� Array.Copy (name, 0, adminBytes, 0, 36 < name.Length ? 36 : name.Length); @@ -861,6 +863,47 @@ } /// <summary> + /// + /// </summary> + /// <param name="bytes"></param> + /// <returns></returns> + private byte GetCheckSum (byte [] bytes) + { + //byte checksum = 0x00; + //foreach (byte bt in bytes) { + // checksum ^= bt; + //} + + int iSum = 0; + for (int i = 0; i < bytes.Length; i++) { + iSum += bytes [i]; + } + return (byte)(0xff & (0x100 - iSum)); + } + + /// <summary> + /// 淇敼Mqtt鍩熷悕鍦板潃 + /// </summary> + /// <returns></returns> + bool SetGateWayMqttUrlAddress () + { + byte [] utlBytes = new byte [65]; + var url = new Uri (UserConfig.Instance.CurrentRegion.regionUrl); + var host = ""; + if (url != null) { + host = url.Host; + } + byte [] hostBytes = CommonPage.MyEncodingGB2312.GetBytes (host); + Array.Copy (hostBytes, 0, utlBytes, 0, 64 < hostBytes.Length ? 64 : hostBytes.Length); + var sum = GetCheckSum (hostBytes); + utlBytes [64] = sum;//鏍¢獙浣� + byte [] backBytes = Control.ControlBytesSendHasReturn (Command.SetGateWayMqttURLAddress, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, utlBytes); + + return CheckIsSuccessfulWithBytes (backBytes, "Failed to modify gateway remote address!"); + } + + + /// <summary> /// 鍒ゆ柇鏄惁淇鎴愬姛 F8 = 鎴愬姛锛� F5=澶辫触 /// </summary> /// <param name="backBytes"></param> -- Gitblit v1.8.0