| | |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON.Entity; |
| | | using HDL_ON.UI; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.DriverLayer |
| | | { |
| | | /// <summary> |
| | | /// 通讯方式 |
| | | /// </summary> |
| | | public enum CommunicationMode |
| | | { |
| | | none, |
| | | /// <summary> |
| | | /// 本地udp |
| | | /// </summary> |
| | | local_BusUdp, |
| | | /// <summary> |
| | | /// 本地tcp客户端 |
| | | /// </summary> |
| | | tcp_local_client, |
| | | } |
| | | |
| | | public class Control |
| | | { |
| | | |
| | |
| | | /// 记录接收到的消息,方便zb的工程师调试他们的设备 |
| | | /// </summary> |
| | | public List<string> MsgInfoList = new List<string>(); |
| | | /// <summary> |
| | | /// 本地tcp客户端连接是否成功 |
| | | /// 是否登录网关成功 |
| | | /// </summary> |
| | | public bool LocalTcpClientLogin = false; |
| | | |
| | | int _msg_id = 1; |
| | | /// <summary> |
| | |
| | | public Control_Udp myUdp1 = null; |
| | | |
| | | /// <summary> |
| | | /// 通讯方式 |
| | | /// </summary> |
| | | public CommunicationMode communicationMode; |
| | | |
| | | /// <summary> |
| | | /// 打开tcp服务端 |
| | | /// </summary> |
| | | public void OpenTcpServer() |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private System.Threading.Thread loginGatewayThread; |
| | | |
| | | /// <summary> |
| | | /// 登录网关 |
| | | /// </summary> |
| | | public void LoginGateway() |
| | | { |
| | | if(loginGatewayThread== null) |
| | | { |
| | | loginGatewayThread = new System.Threading.Thread(() => { |
| | | while (true) |
| | | { |
| | | if (Ins.GatewayOnline_Local && myTcpClient.isConnected && LocalTcpClientLogin) |
| | | { |
| | | var sendData = new { clientType = "app", version = "1.0" }; |
| | | var sendJob = new { id = Control.Ins.msg_id.ToString(), time_stamp = Utlis.GetTimestamp(), objects = sendData }; |
| | | |
| | | var bodyString = JsonConvert.SerializeObject(sendJob); |
| | | |
| | | var sendBytes = ConvertSendBodyData($"/user/{GatewayId}/custom/gateway/login", bodyString); |
| | | |
| | | Ins.myTcpClient.SendMessage(sendBytes); |
| | | } |
| | | System.Threading.Thread.Sleep(2000); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 场景控制入口 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 安防控制 |
| | | /// </summary> |
| | | public void ControlArm() |
| | | { |
| | | DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest(); |
| | | //var pack = httpServer.GetSecurityAlarmLogList |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 发送命令 |
| | |
| | | //} |
| | | receiveObj.BodyDataString = res[1]; |
| | | |
| | | if(receiveObj.Topic == CommunicationTopic.ct.HeartBeat) |
| | | { |
| | | |
| | | return null; |
| | | } |
| | | |
| | | //2021-09-23 过滤不需要解密的主题 目前搜索网关主题不加密 |
| | | if (receiveObj.Topic != CommunicationTopic.SearchLoaclGatewayReply) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | try |
| | | { |
| | | var idMsg = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); |
| | | var hasProcess = hasItBeenProcessed(idMsg.id); |
| | | if (hasProcess) |
| | | { |
| | | return null; |
| | | } |
| | | MainPage.Log($"处理局域网数据id:{idMsg.id}"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"解析局域网数据异常{ex.Message}"); |
| | | } |
| | | |
| | | if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast) |
| | | { |
| | |
| | | //2021-09-23 新增获取当前网关是否本地加密 |
| | | Ins.IsLocalEncrypt = device.isLocalEncrypt; |
| | | //MainPage.Log("网关本地加密状态:" + device.local_encrypt.ToString()); |
| | | |
| | | OpenTcpClent(); |
| | | |
| | | LoginGateway(); |
| | | |
| | | } |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus || |
| | | receiveObj.Topic.Contains( CommunicationTopic.ct.GatewayUpSortTopic)) |
| | | receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic)) |
| | | { |
| | | //TODO 暂时不传正确的数据上去,如果后面要优化前面这些代码 |
| | | UpdataFunctionStatus(receiveObj.BodyDataString, null); |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity +"_reply" |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity + "_reply" |
| | | || receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply" |
| | | || receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp) |
| | | { |
| | |
| | | { |
| | | MainPage.Log($"局域网安防信息: {receiveObj.Topic} : 内容: {res[1]}"); |
| | | var tt = ""; |
| | | lock (tt) { |
| | | lock (tt) |
| | | { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString); |
| | | if (temp != null) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex){ |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"安防局域网异常:{ex.Message}"); |
| | | } |
| | | } |
| | | else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString); |
| | | if (temp.GetValue("objects").ToString().Contains("success")) |
| | | { |
| | | LocalTcpClientLogin = true; |
| | | } |
| | | } |
| | | else |
| | |
| | | return receiveObj; |
| | | } |
| | | |
| | | |
| | | private List<string> processedDataList = new List<string>(); |
| | | /// <summary> |
| | | /// 是否已经处理过数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private bool hasItBeenProcessed(string msgId) |
| | | { |
| | | if (processedDataList.Contains(msgId)) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | if(processedDataList.Count> 50) |
| | | { |
| | | processedDataList.RemoveAt(0); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新设备状态 |
| | | /// A协议数据 |