From 8df24b0a3dfd5b6f39c5393ef24eab25b70ab858 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 11 九月 2020 13:18:33 +0800
Subject: [PATCH] 202009111

---
 HDL_ON/DriverLayer/Control_Bus.cs |  106 ++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 72 insertions(+), 34 deletions(-)

diff --git a/HDL_ON/DriverLayer/Control_Bus.cs b/HDL_ON/DriverLayer/Control_Bus.cs
index 472b644..b73abd8 100644
--- a/HDL_ON/DriverLayer/Control_Bus.cs
+++ b/HDL_ON/DriverLayer/Control_Bus.cs
@@ -1,20 +1,21 @@
 锘縰sing System;
 using System.Collections.Generic;
-using System.Net.Sockets;
 using System.Text;
 using HDL_ON.DAL;
 using HDL_ON.DAL.Net;
 using HDL_ON.Entity;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
-using Shared;
-using Shared.Net;
 
 namespace HDL_ON
 {
     public partial class Control
     {
         public DateTime LatestDateTime = DateTime.Now;
+        /// <summary>
+        /// 鎺у埗澶辫触娆℃暟
+        /// </summary>
+        public static int controlLostCount = 0;
 
         /// <summary>
         /// 鎵�鏈夊井淇″涓�绔彛鐨勬帶鍒堕兘浼氭斁鍒拌繖涓泦鍚堥噷
@@ -35,7 +36,6 @@
                 DeviceID = deviceID,
                 AddData = gatewayBytes,
             }, sendCount, false);
-            MainPage.Log(command.ToString() + "::" + CommonPage.EndPoint.ToString());
         }
 
         public static byte[] ReadGatewayIPAddress()
@@ -44,6 +44,8 @@
             control.ReadGatewayIP();
             return control.UsefulBytes;
         }
+
+        static DAL.Net.TcpListener tcpListener;
 
         /// <summary>
         /// 000E 鎼滅储鍥炲
@@ -59,12 +61,17 @@
                     return;
                 }
 
-
-                if (!CommonPage.isHttpListenerStart)
+                if (tcpListener == null)
                 {
-                    //鏁版嵁鎺ユ敹绔彛娌℃墦寮�锛屼笉鍥炲
-                    CommonPage.InitHttpListener();
+                    tcpListener = new DAL.Net.TcpListener();
+                    tcpListener.OpenServer(8586);
                 }
+
+                //if (!CommonPage.isHttpListenerStart)
+                //{
+                //    //鏁版嵁鎺ユ敹绔彛娌℃墦寮�锛屼笉鍥炲
+                //    CommonPage.InitHttpListener();
+                //}
                 var sendStr = MainPage.LoginUser.accountString;
                 if (usefullBytes.Length == 0)
                 {
@@ -73,7 +80,6 @@
                 else
                 {
                     bool isExit = false;
-
                     for (int i = 0, len = usefullBytes.Length; i < len; i++)
                     {
                         if (i % 2 == 0)
@@ -86,17 +92,16 @@
                             }
                         }
                     }
-
                     if (!isExit)
                     {
                         //涓嶅瓨鍦紝浠h〃娌℃敹鍒版湰鏈虹殑鍙戦�侊紝缁х画鍥炲
                         SenRemark(sendStr);
                     }
-
                 }
-
             }
-            catch { }
+            catch (Exception ex) {
+                Console.WriteLine($"鍥炲bus鎼滅储寮傚父 : {ex.Message}");
+            }
         }
 
         /// <summary>
@@ -173,6 +178,9 @@
                         Console.WriteLine("buspro 璇诲娉ㄥ洖澶�");
                         ReceiveReadRemark(usefulBytes);
                         break;
+                    case Command.ReadLightAllLoopBrightnessACK:
+                        receiveFlag += "";
+                        break;
                     //case Command.YIPanelDeviceInofACK:
                     //    for (int i = 0; i < 4; i++)
                     //    {
@@ -222,8 +230,6 @@
                     //case Command.SetSensorPushValuesACK:
                     //case Command.ReadSensorPushValuesACK:
                     //    receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
-                    //    break;
-                    //case Command.ReadLightEquipmentAllLoopBrightnessACK:
                     //    break;
                     //case Command.UpLoadInfraredACK:
                     //    receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
@@ -339,14 +345,14 @@
                     //case Command.ReadWirelessPanelButtonKeyACK:
                     //case Command.WriteWirelessPanelButtonKeyACK:
                     //case Command.ReadDryContactStatusACK:
-                    //case Command.InstructionPanelKeyACK:
-                    //case Command.ReadInstructionPanelKeyACK:
-                    //case Command.ReadAnalogValueACK:
-                    //case Command.ReadSensorTargetRemarkACK:
-                    //case Command.SetHornTargetStateACK:
-                    //case Command.ReadHornTargetStateACK:
-                    //    receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
-                    //    break;
+                    case Command.InstructionPanelKeyACK:
+                    case Command.ReadInstructionPanelKeyACK:
+                        //case Command.ReadAnalogValueACK:
+                        //case Command.ReadSensorTargetRemarkACK:
+                        //case Command.SetHornTargetStateACK:
+                        //case Command.ReadHornTargetStateACK:
+                        receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
+                        break;
                     //case Command.AssignedAddressACK:
                     //case Command.UpdataCurtainModelRunTimeACK:
                     //case Command.ReadCurtainStutasACK:
@@ -497,11 +503,39 @@
         void managerSendCount(object o)
         {
             add();
-            if (CommonPage.IsRemote)
+            if (MainPage.IsRemote)
             {
-             鈥�            }
+                System.Console.WriteLine("杩滅▼鍙戦�佹暟鎹�:" + SendFlag);
+                Mqtt_Cloud.MqttRemoteSend(Packet.Bytes);
+                Packet.FlagDateTime = DateTime.Now;
+                Packet.HaveSendCount--;
+                //杩欓噷鏄噸鍙戜袱娆�
+                while (Packet.HaveSendCount < 3)
+                {
+                    if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= System.DateTime.Now.Ticks)
+                    {
+                        Mqtt_Cloud.MqttRemoteSend(Packet.Bytes);
+                        System.Console.WriteLine("閲嶅彂杩滅▼鍙戦�佹暟鎹�:" + SendFlag);
+                        Packet.FlagDateTime = DateTime.Now;
+                        Packet.HaveSendCount++;
+                    }
+                    System.Threading.Thread.Sleep(100);
+                }鈥�                allDone.Set();鈥�            }
             else
             {
+                //Bus socket鏃犳硶鎺у埗锛岄噸鍚満鍒�
+                if (controlLostCount > 10)
+                {
+                    BusSocket.Stop();
+                    new System.Threading.Thread(() =>
+                    {
+                        System.Threading.Thread.Sleep(1000);
+                        BusSocket.Start(6000);
+                        controlLostCount = 0;
+                    })
+                    { IsBackground = true }.Start();
+                }
+
                 try
                 {
                     MainPage.Log("鍙戦�佹暟鎹�:" + SendFlag);
@@ -511,10 +545,11 @@
                     //杩欓噷鏄噸鍙戜袱娆�
                     while (Packet.HaveSendCount < 3)
                     {
-                        if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= System.DateTime.Now.Ticks)
+                        if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
                         {
                             MainPage.Log("閲嶅彂鏁版嵁:" + SendFlag);
                             BusSocket.AsyncBeginSend(Packet);
+                            controlLostCount++;
                         }
                         System.Threading.Thread.Sleep(100);
                     }
@@ -551,6 +586,9 @@
                     break;
                 case Command.SetLogicLoopColor:
                     this.sendFlag += string.Format("{0},{1},{2}", target.AddData[0], target.AddData[1], target.AddData[2]);
+                    break;
+                case Command.ReadLightAllLoopBrightness:
+                    this.SendFlag += "";
                     break;
                 //case Command.YIPanelDeviceInof:
                 //    for (int i = 0; i < 4; i++)
@@ -696,12 +734,12 @@
                 //case Command.SetCurtainModelStutas:
                 //case Command.DownloadInfrared:
                 //case Command.UpLoadInfrared:
-                //case Command.InstructionPanelKey:
-                //case Command.ReadInstructionPanelKey:
-                //case Command.ReadSensorTargetRemark:
-                //case Command.SetHornTargetState:
-                //    this.sendFlag += string.Format("{0},{1}", target.AddData[0], target.AddData[1]);
-                //    break;
+                case Command.InstructionPanelKey:
+                case Command.ReadInstructionPanelKey:
+                    //case Command.ReadSensorTargetRemark:
+                    //case Command.SetHornTargetState:
+                    this.sendFlag += string.Format("{0},{1}", target.AddData[0], target.AddData[1]);
+                    break;
                 //case Command.AssignedAddress:
                 //case Command.UpdataCurtainModelRunTime:
                 //case Command.ReadCurtainStatus:
@@ -772,10 +810,10 @@
         {
             try
             {
-                var sendJob = new JObject { { "vendor_code", "HDL" }, { "command", "search" } };
+                var sendJob = new JObject {{ "command", "search" } };
                 var SearchGateway = JsonConvert.SerializeObject(sendJob);
                 var SearchGatewayPayload = Encoding.ASCII.GetBytes(SearchGateway);
-                Packet = new Packet(SearchGatewayPayload, CommonPage.GetGatewayIP_EndPoint);
+                Packet = new Packet(SearchGatewayPayload, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("224.0.168.188"), 6688));
                 System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
                 thread.IsBackground = true;
                 thread.Start(Packet);

--
Gitblit v1.8.0