| | |
| | | return _msg_id++; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 获取13位时间戳 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public string Get_TimeStamp() |
| | | { |
| | | long t = DateTime.Now.Ticks / 10000; |
| | | return t.ToString(); |
| | | } |
| | | |
| | | bool _gatewayOnline = false; |
| | | /// <summary> |
| | |
| | | UI.HomePage.LoadEvent_CheckLinkStatus(); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 网关通讯ID |
| | | /// </summary> |
| | | public string GatewayId; |
| | | /// <summary> |
| | | /// 是否为远程连接 |
| | | /// </summary> |
| | |
| | | |
| | | UdpSocket._BusSocket.Start(port); |
| | | } |
| | | /// <summary> |
| | | /// 关闭udp |
| | | /// </summary> |
| | | public void CloseUdp() |
| | | { |
| | | if(myUdp!= null) |
| | | { |
| | | myUdp = null; |
| | | } |
| | | UdpSocket._BusSocket.Stop(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 打开tcp客服端 |
| | | /// </summary> |
| | |
| | | { |
| | | function.usageCount++; |
| | | function.refreshTime = DateTime.Now; |
| | | if (DB_ResidenceData.residenceData.GatewayType == 0) |
| | | //远程通讯 |
| | | if (Ins.IsRemote) |
| | | { |
| | | try |
| | | //ALink控制 |
| | | if (DB_ResidenceData.residenceData.GatewayType == 0) |
| | | { |
| | | if(myUdp != null) |
| | | { |
| | | myUdp.WriteBusData(function, commandDictionary); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | //Bus控制 |
| | | else |
| | | { |
| | | MainPage.Log($"发送数据异常: {ex.Message}"); |
| | | |
| | | } |
| | | } |
| | | //本地通讯 |
| | | else |
| | | { |
| | | if (myTcpClient != null) |
| | | //ALink控制 |
| | | if (DB_ResidenceData.residenceData.GatewayType == 0) |
| | | { |
| | | var sendDataObj = function.GetControlSendData(commandDictionary); |
| | | var sendJson = Newtonsoft.Json.JsonConvert.SerializeObject(sendDataObj); |
| | | var sendBytes = System.Text.Encoding.UTF8.GetBytes(sendJson); |
| | | myTcpClient.SendMessage(sendBytes); |
| | | try |
| | | { |
| | | if (myUdp != null) |
| | | { |
| | | myUdp.WriteBusData(function, commandDictionary); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"发送数据异常: {ex.Message}"); |
| | | } |
| | | } |
| | | //Bus控制 |
| | | else |
| | | { |
| | | if (myUdp != null) |
| | | { |
| | | var functionControlDataObj = function.GetControlSendData(commandDictionary); |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); |
| | | myUdp.SendLocalHdlLinkData(sendBytes); |
| | | //MainPage.Log($"发送本地HDL-Link数据{functionControlDataJson}\r\n"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | string sendDataString = topicString + lengthString + bodyDataString; |
| | | byte[] sendDataBytes = Encoding.ASCII.GetBytes(sendDataString); |
| | | MainPage.Log($"转换HDL-Link数据\r\n{sendDataString}\r\n"); |
| | | |
| | | return sendDataBytes; |
| | | } |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //验证有效数据长度 |
| | | if (res[1].Length != receiveObj.Length) |
| | | { |
| | | MainPage.Log($"收到数据包长度不够"); |
| | | return receiveObj; |
| | | } |
| | | //if (res[1].Length != receiveObj.Length) |
| | | //{ |
| | | // MainPage.Log($"收到数据包长度不够"); |
| | | // return receiveObj; |
| | | //} |
| | | receiveObj.BodyDataString = res[1]; |
| | | |
| | | var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); |
| | |
| | | } |
| | | switch (receiveObj.Topic) |
| | | { |
| | | case CommunicationTopic.SearchLoaclGateway: |
| | | case CommunicationTopic.SearchLoaclGatewayReply: |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); |
| | | #if DEBUG |
| | | if (UserInfo.Current.AccountString == "464027401@qq.com") |
| | | { |
| | | DB_ResidenceData.residenceData.residenceGatewayMAC = "0000000000000000"; |
| | | } |
| | | #endif |
| | | if (device.device_mac == DB_ResidenceData.residenceData.residenceGatewayMAC) |
| | | { |
| | | Control.Ins.GatewayOnline = true; |
| | | Ins.GatewayOnline = true; |
| | | Ins.GatewayId = device.gatewayId; |
| | | reportIp = "239.0.168.188";// device.ip_address; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | return receiveObj; |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |