From 7167334c0e89dd84827d59e726123d14776e3a09 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 16 六月 2020 11:14:13 +0800
Subject: [PATCH] 2020-06-16-1

---
 HDL_ON/DriverLayer/Control_Bus.cs |  131 ++++++++++++++++++++++++++++++++-----------
 1 files changed, 98 insertions(+), 33 deletions(-)

diff --git a/HDL_ON/DriverLayer/Control_Bus.cs b/HDL_ON/DriverLayer/Control_Bus.cs
index 7ba3779..b5d7d40 100644
--- a/HDL_ON/DriverLayer/Control_Bus.cs
+++ b/HDL_ON/DriverLayer/Control_Bus.cs
@@ -3,6 +3,8 @@
 using HDL_ON.DAL;
 using HDL_ON.DAL.Net;
 using HDL_ON.Entity;
+using Shared;
+using Shared.Net;
 
 namespace HDL_ON
 {
@@ -14,25 +16,6 @@
         /// 鎵�鏈夊井淇″涓�绔彛鐨勬帶鍒堕兘浼氭斁鍒拌繖涓泦鍚堥噷
         /// </summary>
         private static List<Control> controlList = new List<Control>(50);
-
-        /// <summary>
-        /// 鍙戦�佹暟鎹紝绛夊緟鏈夊弽棣�
-        /// </summary>
-        /// <returns>The bytes send has return.</returns>
-        static byte[] ControlBytesSendHasReturn(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3)
-        {
-            Control control = new Control();
-            control.Send(new Target()
-            {
-                IPEndPoint = CommonPage.EndPoint,
-                Command = command,
-                SubnetID = subnetID,
-                DeviceID = deviceID,
-                AddData = gatewayBytes,
-            }, sendCount, true);
-
-            return control.UsefulBytes;
-        }
 
         /// <summary>
         /// 鍙戦�佹暟鎹紝涓嶉渶瑕佺瓑寰呭洖澶�
@@ -50,6 +33,72 @@
             }, sendCount, false);
             MainPage.Log(command.ToString() + "::" + CommonPage.EndPoint.ToString());
 
+        }
+        /// <summary>
+        /// 000E 鎼滅储鍥炲
+        /// </summary>
+        /// <param name="usefullBytes"></param>
+        static void ReceiveReadRemark(byte[] usefullBytes)
+        {
+            try
+            {
+                //璐﹀彿娌$櫥褰曚笉鍥炲
+                if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin)
+                {
+                    return;
+                }
+
+                //if (!isHttpListenerStart)
+                //{
+                //    //鏁版嵁鎺ユ敹绔彛娌℃墦寮�锛屼笉鍥炲
+                //    return;
+                //}
+
+                var sendStr = MainPage.LoginUser.accountString;
+
+
+                //濡傛灉IP鍦板潃鑾峰彇鎴愬姛 鏄剧ず鏈�鍚庝竴浣�
+                var mAddressBytes = new Shared.Net.NetWiFi().IpAddress.GetAddressBytes();
+                if (mAddressBytes != null && mAddressBytes.Length == 4)
+                {
+                    sendStr = (mAddressBytes[3] & 0xFF).ToString() + ":" + sendStr;
+                }
+
+                if (usefullBytes.Length <= 2)
+                {
+                    byte[] sendBytes = new byte[20];
+                    byte[] b1 = CommonPage.MyEncodingGB2312.GetBytes(sendStr);
+                    Array.Copy(b1, 0, sendBytes, 0, 20 < b1.Length ? 20 : b1.Length);
+                    Control.ControlBytesSend(Command.ReadRemarkACK, 0xFF, 0xFF, sendBytes, 1);
+
+                }
+                else
+                {
+
+                    for (int i = 2, len = usefullBytes.Length; i < len; i++)
+                    {
+                        if (i % 2 == 0)
+                        {
+                            if ((usefullBytes[i] & 0xFF) == 0xFC
+                                    && (usefullBytes[i + 1] & 0xFF) == 0xFC
+                            )
+                            {
+
+                                byte[] sendBytes = new byte[20];
+                                byte[] b1 = CommonPage.MyEncodingGB2312.GetBytes(sendStr);
+                                //Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1);
+                                Array.Copy(b1, 0, sendBytes, 0, 20 < b1.Length ? 20 : b1.Length);
+                                Control.ControlBytesSend(Command.ReadRemarkACK, 0xFF, 0xFF, sendBytes, 1);
+
+                                break;
+                            }
+                        }
+                    }
+
+                }
+
+            }
+            catch { }
         }
 
         /// <summary>
@@ -74,7 +123,17 @@
                     case Command.SetLogicLoopColorACK:
                         receiveFlag += string.Format("{0},{1},{2}", usefulBytes[0], usefulBytes[1], usefulBytes[2]);
                         break;
-
+                    case Command.ReadLogicLoopColorACK:
+                    case Command.ReadACModeACK:
+                    case Command.SetACModeACK:
+                    case Command.ReadFloorHeatACK:
+                    case Command.SetFloorHeatACK:
+                        receiveFlag += string.Format("{0}", usefulBytes[0]);
+                        break;
+                    case Command.ReadRemark:
+                        //buspro 璇诲娉ㄥ洖澶�
+                        ReceiveReadRemark(usefulBytes);
+                        break;
                     //case Command.YIPanelDeviceInofACK:
                     //    for (int i = 0; i < 4; i++)
                     //    {
@@ -132,8 +191,6 @@
                     //    break;
                     //case Command.SetCommonACK:
                     //case Command.InfraredChannelControlACK:
-                    //case Command.ReadACModeACK:
-                    //case Command.SetACModeACK:
                     //case Command.Serverx_FH_CMD_ACK:
                     //case Command.ReadSensorHistoryACK:
                     //case Command.SetSensorAutomationTargetLevelEnableACK:
@@ -254,7 +311,6 @@
                     //case Command.AssignedAddressACK:
                     //case Command.UpdataCurtainModelRunTimeACK:
                     //case Command.ReadCurtainStutasACK:
-                    //case Command.ReadLogicLoopColorACK:
                     //case Command.ReadPanleTempACK:
                     //case Command.FreshAirReadACK:
                     //case Command.FreshAirControlACK:
@@ -460,6 +516,11 @@
             switch (target.Command)
             {
                 case Command.SetSingleLight:
+                case Command.ReadLogicLoopColor:
+                case Command.ReadACMode:
+                case Command.SetACMode:
+                case Command.ReadFloorHeat:
+                case Command.SetFloorHeat:
                     this.sendFlag += string.Format("{0}", target.AddData[0]);
                     break;
                 case Command.SetLogicLoopColor:
@@ -496,8 +557,6 @@
                 //    break;
                 //case Command.SetCommonSwitch:
                 //case Command.InfraredChannelControl:
-                //case Command.ReadACMode:
-                //case Command.SetACMode:
                 //case Command.ReadFoolHeat:
                 //case Command.SetFoolHeat:
                 //case Command.Serverx_FH_CMD:
@@ -620,7 +679,6 @@
                 //case Command.AssignedAddress:
                 //case Command.UpdataCurtainModelRunTime:
                 //case Command.ReadCurtainStatus:
-                //case Command.ReadLogicLoopColor:
                 //case Command.ReadPanleTemp:
                 //case Command.FreshAirRead:
                 //case Command.FreshAirControl:
@@ -665,14 +723,21 @@
         /// <param name="sendCount">閲嶅彂娆℃暟</param>
         public void Send(Target target, int sendCount, bool isWait)
         {
-            Packet = new Packet(target.SendBytes, target.IPEndPoint);
-            Packet.HaveSendCount = 3 - sendCount;
-
-            ini(target);
-
-            if (isWait)
+            try
             {
-                this.wait();
+                Packet = new Packet(target.SendBytes, target.IPEndPoint);
+                Packet.HaveSendCount = 3 - sendCount;
+
+                ini(target);
+
+                if (isWait)
+                {
+                    this.wait();
+                }
+            }
+            catch(Exception ex)
+            {
+                MainPage.Log($"Send bus data error {ex.Message}");
             }
         }
 

--
Gitblit v1.8.0