| | |
| | | /// <summary> |
| | | /// 本地udp |
| | | /// </summary> |
| | | public Control_Udp myUdp = null; |
| | | public Control_Udp myUdp1 = null; |
| | | |
| | | /// <summary> |
| | | /// 通讯方式 |
| | |
| | | /// </summary> |
| | | public void OpenUdp(int port) |
| | | { |
| | | if (myUdp == null) |
| | | { |
| | | myUdp = new Control_Udp(); |
| | | } |
| | | |
| | | UdpSocket._BusSocket.Start(port); |
| | | } |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public void CloseUdp() |
| | | { |
| | | if (myUdp != null) |
| | | { |
| | | myUdp = null; |
| | | } |
| | | UdpSocket._BusSocket.Stop(); |
| | | } |
| | | |
| | |
| | | break; |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | { |
| | | myUdp.ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); |
| | | new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); |
| | | } |
| | | else if (DB_ResidenceData.Instance.GatewayType == 1) |
| | | { |
| | | myUdp.SearchLocalGateway(); |
| | | new Control_Udp().SearchLocalGateway(); |
| | | } |
| | | System.Threading.Thread.Sleep(500); |
| | | } |
| | |
| | | { |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | { |
| | | myUdp.ControlBusScenes(scene); |
| | | new Control_Udp().ControlBusScenes(scene); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | if (myUdp != null) |
| | | { |
| | | myUdp.WriteBusData(function, commandDictionary); |
| | | } |
| | | new Control_Udp().WriteBusData(function, commandDictionary); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | //ALink控制 |
| | | else |
| | | { |
| | | if (myUdp != null) |
| | | { |
| | | var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary); |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); |
| | | Ins.myUdp.SendLocalHdlLinkData(sendBytes); |
| | | } |
| | | var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary); |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | Ins.myUdp.ReadBusData(function); |
| | | new Control_Udp().ReadBusData(function); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | }; |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson); |
| | | Ins.myUdp.SendLocalHdlLinkData(sendBytes); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes,readDataObj.id); |
| | | } |
| | | } |
| | | } |
| | |
| | | }; |
| | | var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson); |
| | | Ins.myUdp.SendLocalHdlLinkData(sendBytes); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes,aLinkData.id); |
| | | } |
| | | } |
| | | /// <summary> |
| | |
| | | else if(receiveObj.Topic == CommunicationTopic.ct.ReadStatus+"_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus) |
| | | { |
| | | UpdataFunctionStatus(receiveObj.BodyDataString); |
| | | //TODO 暂时不传正确的数据上去,如果后面要优化前面这些代码 |
| | | UpdataFunctionStatus(receiveObj.BodyDataString,null); |
| | | } |
| | | } |
| | | return receiveObj; |
| | |
| | | /// A协议数据 |
| | | /// </summary> |
| | | /// <param name="updateBytes"></param> |
| | | public void UpdataFunctionStatus(string revString) |
| | | public void UpdataFunctionStatus(string revString,byte []usefulBytes) |
| | | { |
| | | MainPage.Log($"A协议更新状态:{revString}"); |
| | | if(Control.Ins.myUdp!= null) |
| | |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString); |
| | | if (temp != null) |
| | | { |
| | | Control_Udp.ReceiveRepeatManager(temp.id,usefulBytes); |
| | | var allLocalFuntion = FunctionList.List.GetDeviceFunctionList(); |
| | | foreach (var updateTemp in temp.objects) |
| | | { |