/// <summary> /// 向Ap发送Main模块过来的消息 /// </summary> /// <param name="MainMsg"></param> private void Send2ap_RecvMainMsg(InterModuleMsgStruct MainMsg) { AsyncUserToken apToKen = MyDeviceList.FindByApInfo(MainMsg.ApInfo); if (apToKen == null) { OnOutputLog(LogInfoType.WARN, string.Format("在线AP列表中找不到Ap[{0}:{1}]设备({2})!", MainMsg.ApInfo.IP, MainMsg.ApInfo.Port.ToString(), MainMsg.ApInfo.Fullname)); return; } MsgId2App msgId2App = new MsgId2App(); msgId2App.id = ApMsgIdClass.addNormalMsgId(); msgId2App.AppInfo = MainMsg.AppInfo; if (!MyDeviceList.AddMsgId2App(apToKen, msgId2App)) { OnOutputLog(LogInfoType.EROR, string.Format("添加消息Id到设备列表出错!")); Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type, string.Format("添加消息Id到设备列表出错!")); return; } if (!SendMsg2Ap(apToKen, msgId2App.id, MainMsg.Body)) { Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type, string.Format("封装向AP发送的XML消息({0})出错!", MainMsg.Body.type)); } }
/// <summary> /// 透传MainController模块过来的消息给设备 /// </summary> /// <param name="MainMsg"></param> private void Send2ap_TransparentMsg(InterModuleMsgStruct MainMsg) { AsyncUserToken apToKen = MyDeviceList.FindByApInfo(MainMsg.ApInfo); if (apToKen == null) { OnOutputLog(LogInfoType.WARN, string.Format("在线AP列表中找不到Ap[{0}:{1}]设备({2})!", MainMsg.ApInfo.IP, MainMsg.ApInfo.Port.ToString(), MainMsg.ApInfo.Fullname)); return; } string sendMsg = GetMsgStringValueInList("transparent_msg", MainMsg.Body); if (string.IsNullOrEmpty(sendMsg)) { OnOutputLog(LogInfoType.EROR, string.Format("透传XML消息为空!")); Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type, string.Format("透传XML消息为空!")); return; } if (!Regex.IsMatch(sendMsg, "<\\s*id\\s*>.+<\\s*/\\s*id\\s*>")) { OnOutputLog(LogInfoType.EROR, string.Format("透传的XML消息中没有id项!")); Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type, string.Format("透传的XML消息中没有id项!")); return; } UInt16 id = ApMsgIdClass.addTransparentMsgId(); sendMsg = Regex.Replace(sendMsg, "<\\s*id\\s*>.+<\\s*/\\s*id\\s*>", string.Format("<id>{0}</id>", id)); MsgId2App msgId2App = new MsgId2App(); msgId2App.id = id; msgId2App.AppInfo = MainMsg.AppInfo; if (!MyDeviceList.AddMsgId2App(apToKen, msgId2App)) { OnOutputLog(LogInfoType.EROR, string.Format("添加消息Id到设备列表出错!")); Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type, string.Format("添加消息Id到设备列表出错!")); return; } SendMsg2Ap(apToKen, MainMsg.Body.type, sendMsg); }