| | |
| | | public class Control |
| | | { |
| | | |
| | | |
| | | static Control _control; |
| | | public static Control Ins |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 安防控制 |
| | | /// </summary> |
| | | public void ControlArm() |
| | | { |
| | | DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest(); |
| | | //var pack = httpServer.GetSecurityAlarmLogList |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 发送命令 |
| | |
| | | //远程通讯 |
| | | else |
| | | { |
| | | //Bug修复:一端口远程控制调光设备的调光属性时,无法控制到0,反复横跳。 |
| | | //因为On + 远程控制发送给云端使用的是link协议数据,杨涛中转给高胜处理时候逻辑上有冲突,导致无法单独控制亮度值,需要同时发送开关值与亮度值。 |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | { |
| | | if (commandDictionary.Count == 1) |
| | | { |
| | | if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness)) |
| | | { |
| | | commandDictionary.Add(FunctionAttributeKey.OnOff, commandDictionary[FunctionAttributeKey.Brightness] == "0" ? "off" : "on"); |
| | | } |
| | | } |
| | | if(function.spk == SPK.LightCCT) |
| | | { |
| | | if (!commandDictionary.ContainsKey(FunctionAttributeKey.CCT)) |
| | | { |
| | | commandDictionary.Add(FunctionAttributeKey.CCT, function.GetAttrState(FunctionAttributeKey.CCT)); |
| | | } |
| | | } |
| | | } |
| | | DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest(); |
| | | //ALink控制、Bus控制使用同一个接口控制,由云端负责解析 |
| | | var apiControlData = function.GetApiControlData(commandDictionary); |
| | | var actionObjs = new List<ApiAlinkControlActionObj>(); |
| | | actionObjs.Add(apiControlData); |
| | | var pack = httpServer.ControlDevice(actionObjs); |
| | | MainPage.Log($"远程控制反馈:{pack.message}"); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | var count = 0; |
| | | var logString = open ? "打开\r\n" : "关闭\r\n"; |
| | | List<ApiAlinkControlActionObj> actionObjs = new List<ApiAlinkControlActionObj>(); |
| | | Dictionary<string, string> d = new Dictionary<string, string>(); |
| | | d.Add(FunctionAttributeKey.OnOff, open ? "on" : "off"); |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | foreach (var temp in functions) |
| | | //一端口全开全关需要延时发送 |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | { |
| | | logString += temp.spk + ":" + temp.sid + "\r\n"; |
| | | var apiControlData = temp.GetApiControlData(d); |
| | | actionObjs.Add(apiControlData); |
| | | count++; |
| | | if (count > 9) |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var result = pm.ControlDevice(actionObjs); |
| | | actionObjs = new List<ApiAlinkControlActionObj>(); |
| | | count = 0; |
| | | MainPage.Log(logString); |
| | | logString = ""; |
| | | } |
| | | foreach (var temp in functions) |
| | | { |
| | | var apiControlData = temp.GetApiControlData(d); |
| | | var result = pm.ControlDevice(new List<ApiAlinkControlActionObj>() { apiControlData }); |
| | | System.Threading.Thread.Sleep(100); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | var pack = pm.ControlDevice(actionObjs); |
| | | MainPage.Log(logString); |
| | | else |
| | | { |
| | | foreach (var temp in functions) |
| | | { |
| | | var apiControlData = temp.GetApiControlData(d); |
| | | actionObjs.Add(apiControlData); |
| | | count++; |
| | | if (count > 9) |
| | | { |
| | | var result = pm.ControlDevice(actionObjs); |
| | | actionObjs = new List<ApiAlinkControlActionObj>(); |
| | | count = 0; |
| | | System.Threading.Thread.Sleep(100); |
| | | } |
| | | } |
| | | var pack = pm.ControlDevice(actionObjs); |
| | | } |
| | | } |
| | | |
| | | public void SendApiReadCommand(List<string> functionIds) |
| | |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 安防控制 |
| | | /// </summary> |
| | | public void ControlSecurity(SecurityAlarm securityAlarm,string state) |
| | | { |
| | | if (!Ins.GatewayOnline_Local)//网关本地不在线 |
| | | { |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | var result = pm.SetSecurityStatus(new List<SecurityState>() { new SecurityState() { |
| | | gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId, |
| | | sid = securityAlarm.sid, status = state, userSecurityId = securityAlarm.userSecurityId |
| | | } }); |
| | | MainPage.Log($"安防控制结果:{result.Code}"); |
| | | } |
| | | else |
| | | { |
| | | Dictionary<string, string> keys = new Dictionary<string, string>(); |
| | | keys.Add("sid", securityAlarm.sid); |
| | | keys.Add("status", state); |
| | | keys.Add("alarm", securityAlarm.alarm.ToString()); |
| | | var aLinkData = new AlinkReadFunctionStatusObj() |
| | | { |
| | | id = Ins.msg_id.ToString(), |
| | | objects = new List<Dictionary<string, string>>() |
| | | { |
| | | keys |
| | | }, |
| | | time_stamp = Utlis.GetTimestamp() |
| | | }; |
| | | var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlSeurity, aLinkJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id); |
| | | } |
| | | } |
| | | |
| | |
| | | //} |
| | | receiveObj.BodyDataString = res[1]; |
| | | |
| | | if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply) |
| | | if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast) |
| | | { |
| | | |
| | | var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); |
| | | if (bodyJObj == null) |
| | | { |
| | |
| | | { |
| | | Ins.GatewayId = device.device_mac; |
| | | } |
| | | reportIp = "239.0.168.188";// device.ip_address;//主播地址也能控制设备 |
| | | reportIp = device.ip_address;//主播地址也能控制设备//"239.0.168.188";// |
| | | } |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" || |
| | |
| | | { |
| | | //TODO 暂时不传正确的数据上去,如果后面要优化前面这些代码 |
| | | UpdataFunctionStatus(receiveObj.BodyDataString, null); |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity +"_reply" |
| | | || receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply" |
| | | || receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp) |
| | | { |
| | | try |
| | | { |
| | | MainPage.Log($"局域网安防信息: {receiveObj.Topic} : 内容: {res[1]}"); |
| | | var tt = ""; |
| | | lock (tt) { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString); |
| | | if (temp != null) |
| | | { |
| | | Control_Udp.ReceiveRepeatManager(temp.id, null); |
| | | foreach (var updataSecurity in temp.objects) |
| | | { |
| | | var updataLocalSecurity = FunctionList.List.securities.Find((obj) => obj.sid == updataSecurity.sid); |
| | | if (updataLocalSecurity != null) |
| | | { |
| | | updataLocalSecurity.status = updataSecurity.status; |
| | | updataLocalSecurity.alarm = updataSecurity.alarm; |
| | | ArmCenterPage.LoadEvent_RefreshSecurityStatus(updataLocalSecurity); |
| | | } |
| | | } |
| | | HomePage.LoadEvent_RefreshSecurityStatus(); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex){ |
| | | MainPage.Log($"安防局域网异常:{ex.Message}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | return; |
| | | } |
| | | } |
| | | MainPage.Log($"A协议更新状态:{revString}"); |
| | | //MainPage.Log($"A协议更新状态:{revString}"); |
| | | foreach (var attr in updateTemp.status) |
| | | { |
| | | localFunction.time_stamp = temp.time_stamp; |
| | |
| | | } |
| | | |
| | | //更新界面状态 |
| | | Function localObj = null; |
| | | switch (localFunction.spk) |
| | | { |
| | | case SPK.AirSwitch: |
| | | AirSwitchPage.UpdataState(localFunction); |
| | | break; |
| | | case SPK.ElectricEnergy: |
| | | EnergyMainPage.UpdataStatus(localFunction); |
| | | break; |
| | |
| | | } |
| | | break; |
| | | case SPK.FloorHeatStandard: |
| | | localFunction.lastState = ""; |
| | | switch (localFunction.GetAttrState(FunctionAttributeKey.Mode)) |
| | | { |
| | | case "normal": |
| | |
| | | HomePage.LoadEvent_RefreshEnvirIndoorHumi(); |
| | | } |
| | | EnvironmentalPage.LoadEvent_UpdataStatus(localFunction); |
| | | //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(localFunction); |
| | | break; |
| | | case SPK.SensorEnvironment: |
| | | case SPK.SensorEnvironment2: |
| | | case SPK.SensorEnvironment3: |
| | | if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Temperature)) |
| | | { |
| | | HomePage.LoadEvent_RefreshEnvirIndoorTemp(); |
| | | } |
| | | if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Humidity)) |
| | | { |
| | | HomePage.LoadEvent_RefreshEnvirIndoorHumi(); |
| | | } |
| | | EnvironmentalPage.LoadEvent_UpdataStatus(localFunction); |
| | | //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(localFunction); |
| | | break; |
| | | case SPK.ElectricSocket: |
| | | SocketPage.UpdataState(localFunction); |
| | |
| | | case SPK.ClothesHanger: |
| | | case SPK.AcIr: |
| | | case SPK.SenesorMegahealth: |
| | | case SPK.AirFreshStandard: |
| | | //设备状态推送 |
| | | //状态更新 |
| | | Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status); |