/// <summary> /// Determines weather <paramref name="mssMsg"/> falls into this range. /// </summary> /// <returns>True if mssMsg is a member of this range. False otherwise.</returns> public bool MsgIsInRange(MssMsg mssMsg) { IStaticMssMsgInfo staticInfo = Factory_StaticMssMsgInfo.Create(this.MsgType); return(staticInfo.TypeIsInRange(mssMsg.Type) && mssMsg.Data1 >= this.Data1RangeBottom && mssMsg.Data1 <= this.Data1RangeTop && mssMsg.Data2 >= this.Data2RangeBottom && mssMsg.Data2 <= this.Data2RangeTop); }
public override bool Equals(object o) { MssMsg compareToMsg = (MssMsg)o; return(this.Type == compareToMsg.Type && this.Data1 == compareToMsg.Data1 && this.Data2 == compareToMsg.Data2 && this.Data3 == compareToMsg.Data3); }
protected void ParameterValueChanged(MssParameterID paramId, double newValue) { lock (MssComponentHub.criticalSectioinLock) { if (this.hostInfoOutput.SampleRateIsInitialized == false) { return; } long watchOffestAtParamChanged = this.stopwatch.Elapsed.Ticks; MssParamInfo paramInfo = this.mssParameters.GetParameterInfoCopy(paramId); double relValue = CustomMathUtils.AbsToRelVal(paramInfo.MinValue, paramInfo.MaxValue, newValue); MssMsg paramMsg = new MssMsg(MssMsgType.Parameter, (int)paramId, MssMsgUtil.UNUSED_MSS_MSG_DATA, relValue); MssEvent paramEvent = new MssEvent(); paramEvent.mssMsg = paramMsg; long ticksSinceCycleEnd = watchOffestAtParamChanged - this.watchOffestAtLastCycleEnd; double secondsSinceCycleEnd = ticksSinceCycleEnd / (double)TimeSpan.TicksPerSecond; long samplesSinceCycleEnd = (long)Math.Round(secondsSinceCycleEnd * this.hostInfoOutput.SampleRate); //Sometimes the stopwatch may not be accurate enough to notice the difference //between the end of the last cycle and now. Setting samplesSinceCycleEnd to //1 will cause this event to happen at the very start of this processing cycle. if (samplesSinceCycleEnd == 0) { samplesSinceCycleEnd = 1; } paramEvent.sampleTime = this.sampleTimeAtLastCycleEnd + samplesSinceCycleEnd; this.dryEventInput.ReceiveDryMssEvent(paramEvent); } }
/// <summary> /// Applies to <paramref name="mssMsg"/> any mappings in the MappingManager that are associated with it. /// </summary> /// <param name="mssMsg">A MSS message to process.</param> /// <returns> A list resulting messages.</returns> public IEnumerable<MssMsg> ProcessMssMsg(MssMsg mssMsg) { //Apply the pre mapping query processing. If this causes the msg type to change then //apply it again for the new type. MssMsgType curMsgType; do { curMsgType = mssMsg.Type; IStaticMssMsgInfo staticMsgInfo = Factory_StaticMssMsgInfo.Create(mssMsg.Type); staticMsgInfo.ApplyPreMappingQueryProcessing(mssMsg); } while(curMsgType != mssMsg.Type); //Retrieves mappings from the MappingManager that will affect mssMsg IEnumerable<IMappingEntry> mappingEntries = this.mappingMgr.GetCopiesOfMappingEntriesForMsg(mssMsg); List<MssMsg> outMessages = new List<MssMsg>(); if (mappingEntries.Any() == false) { outMessages.Add(mssMsg); } else { foreach (IMappingEntry entry in mappingEntries) { MssMsg inMsg = (MssMsg)mssMsg.Clone(); IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(entry.InMssMsgRange.MsgType); inMsgInfo.ApplyPreProcessing(inMsg); MssMsg preProcessedMsg = (MssMsg)inMsg.Clone(); EvaluationCurveInput evalInput = new EvaluationCurveInput(); evalInput.Init(inMsg, this.mssParameterViewer.GetVariableParamInfoList(), entry); ReturnStatus<double> evalReturnStatus = this.evaluator.Evaluate(evalInput); if (evalReturnStatus.IsValid == false) { continue; } double mappedRelativeData3 = evalReturnStatus.Value; IStaticMssMsgInfo outMsgInfo = Factory_StaticMssMsgInfo.Create(entry.OutMssMsgRange.MsgType); double data3RangeSize = outMsgInfo.MaxData3Value - outMsgInfo.MinData3Value; double mappedData3 = mappedRelativeData3 * data3RangeSize + outMsgInfo.MinData3Value; //If data3 has been mapped outside of the range of values for its message type then this //mapping will not output anything. if (mappedData3 >= outMsgInfo.MinData3Value && mappedData3 <= outMsgInfo.MaxData3Value) { //Calculate what mssMsg.Data1 will be mapped to. double mappedData1 = CalculateLinearMapping(entry.InMssMsgRange.Data1RangeBottom, entry.InMssMsgRange.Data1RangeTop, entry.OutMssMsgRange.Data1RangeBottom, entry.OutMssMsgRange.Data1RangeTop, mssMsg.Data1); //Calculate what mssMsg.Data2 will be mapped to. double mappedData2 = CalculateLinearMapping(entry.InMssMsgRange.Data2RangeBottom, entry.InMssMsgRange.Data2RangeTop, entry.OutMssMsgRange.Data2RangeBottom, entry.OutMssMsgRange.Data2RangeTop, mssMsg.Data2); MssMsg outMsg = new MssMsg(entry.OutMssMsgRange.MsgType, mappedData1, mappedData2, mappedData3); //Apply the post processing. If this causes the msg type to change then //apply it again for the new type. do { curMsgType = mssMsg.Type; IStaticMssMsgInfo staticMsgInfo = Factory_StaticMssMsgInfo.Create(outMsg.Type); staticMsgInfo.ApplyPostProcessing(preProcessedMsg, outMsg); } while (curMsgType != mssMsg.Type); yield return outMsg; } } } }
public MssEvent() { this.mssMsg = new MssMsg(); }
/// <summary> /// Determines weather <paramref name="mssMsg"/> falls into this range. /// </summary> /// <returns>True if mssMsg is a member of this range. False otherwise.</returns> public bool MsgIsInRange(MssMsg mssMsg) { IStaticMssMsgInfo staticInfo = Factory_StaticMssMsgInfo.Create(this.MsgType); return staticInfo.TypeIsInRange(mssMsg.Type) && mssMsg.Data1 >= this.Data1RangeBottom && mssMsg.Data1 <= this.Data1RangeTop && mssMsg.Data2 >= this.Data2RangeBottom && mssMsg.Data2 <= this.Data2RangeTop; }
/// <summary> /// Applies to <paramref name="mssMsg"/> any mappings in the MappingManager that are associated with it. /// </summary> /// <param name="mssMsg">A MSS message to process.</param> /// <returns> A list resulting messages.</returns> public IEnumerable <MssMsg> ProcessMssMsg(MssMsg mssMsg) { //Apply the pre mapping query processing. If this causes the msg type to change then //apply it again for the new type. MssMsgType curMsgType; do { curMsgType = mssMsg.Type; IStaticMssMsgInfo staticMsgInfo = Factory_StaticMssMsgInfo.Create(mssMsg.Type); staticMsgInfo.ApplyPreMappingQueryProcessing(mssMsg); } while(curMsgType != mssMsg.Type); //Retrieves mappings from the MappingManager that will affect mssMsg IEnumerable <IMappingEntry> mappingEntries = this.mappingMgr.GetCopiesOfMappingEntriesForMsg(mssMsg); List <MssMsg> outMessages = new List <MssMsg>(); if (mappingEntries.Any() == false) { outMessages.Add(mssMsg); } else { foreach (IMappingEntry entry in mappingEntries) { MssMsg inMsg = (MssMsg)mssMsg.Clone(); IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(entry.InMssMsgRange.MsgType); inMsgInfo.ApplyPreProcessing(inMsg); MssMsg preProcessedMsg = (MssMsg)inMsg.Clone(); EvaluationCurveInput evalInput = new EvaluationCurveInput(); evalInput.Init(inMsg, this.mssParameterViewer.GetVariableParamInfoList(), entry); ReturnStatus <double> evalReturnStatus = this.evaluator.Evaluate(evalInput); if (evalReturnStatus.IsValid == false) { continue; } double mappedRelativeData3 = evalReturnStatus.Value; IStaticMssMsgInfo outMsgInfo = Factory_StaticMssMsgInfo.Create(entry.OutMssMsgRange.MsgType); double data3RangeSize = outMsgInfo.MaxData3Value - outMsgInfo.MinData3Value; double mappedData3 = mappedRelativeData3 * data3RangeSize + outMsgInfo.MinData3Value; //If data3 has been mapped outside of the range of values for its message type then this //mapping will not output anything. if (mappedData3 >= outMsgInfo.MinData3Value && mappedData3 <= outMsgInfo.MaxData3Value) { //Calculate what mssMsg.Data1 will be mapped to. double mappedData1 = CalculateLinearMapping(entry.InMssMsgRange.Data1RangeBottom, entry.InMssMsgRange.Data1RangeTop, entry.OutMssMsgRange.Data1RangeBottom, entry.OutMssMsgRange.Data1RangeTop, mssMsg.Data1); //Calculate what mssMsg.Data2 will be mapped to. double mappedData2 = CalculateLinearMapping(entry.InMssMsgRange.Data2RangeBottom, entry.InMssMsgRange.Data2RangeTop, entry.OutMssMsgRange.Data2RangeBottom, entry.OutMssMsgRange.Data2RangeTop, mssMsg.Data2); MssMsg outMsg = new MssMsg(entry.OutMssMsgRange.MsgType, mappedData1, mappedData2, mappedData3); //Apply the post processing. If this causes the msg type to change then //apply it again for the new type. do { curMsgType = mssMsg.Type; IStaticMssMsgInfo staticMsgInfo = Factory_StaticMssMsgInfo.Create(outMsg.Type); staticMsgInfo.ApplyPostProcessing(preProcessedMsg, outMsg); } while (curMsgType != mssMsg.Type); yield return(outMsg); } } } }
protected List<MssMsg> ProcessMssMsg_CopyData3(MssMsg mssMsg) { MssMsg msg = new MssMsg(); msg.Type = MssMsgType.Generator; msg.Data1 = 0; msg.Data2 = MssMsgUtil.UNUSED_MSS_MSG_DATA; msg.Data3 = mssMsg.Data3; List<MssMsg> retList = new List<MssMsg>(); retList.Add(msg); return retList; }
/// <summary> /// Tests the ProcessMssMsg() method. /// </summary> /// <param name="inputMsg">The message to be precessed</param> /// <param name="matchingEntries"> /// Mapping entries where <paramref name="inputMsg"/> is in the input message range /// </param> /// <param name="desiredReturnedMsgList"> List of that should be returned by ProcessMssMsg() </param> /// <param name="doubleData3"> /// Simulates the equation "x*2" in each mapping if true. Simulates the equation "x" in each mapping if /// false. /// </param> protected void Test_ProcessMssMsg(MssMsg inputMsg, List<IMappingEntry> matchingEntries, List<MssMsg> desiredReturnedMsgList, bool doubleData3) { int inputMultiple; if (doubleData3 == true) { inputMultiple = 2; } else { inputMultiple = 1; } //Setup the MssEvaluator that msgProcessor will use so that it always just returns the input var mssEvanuatorMock = new Mock<IEvaluator>(); mssEvanuatorMock.Setup(evaluator => evaluator.Evaluate(It.IsAny<EvaluationCurveInput>())) .Returns((EvaluationCurveInput input) => new ReturnStatus<double>(input.RelData3 * inputMultiple, true)); IocMgr.Kernel.Rebind<IEvaluator>().ToConstant(mssEvanuatorMock.Object); MssMsgProcessor msgProcessor = new MssMsgProcessor(); var mapMgrMock = new Mock<IBaseGraphableMappingManager>(); mapMgrMock.Setup(mapMgr => mapMgr.GetCopiesOfMappingEntriesForMsg(inputMsg)).Returns(matchingEntries); var mssParameterViewerMock = new Mock<IMssParameterViewer>(); msgProcessor.Init(mapMgrMock.Object, mssParameterViewerMock.Object); //Ensure returnedMsgList and desiredReturnedMsgList contain the same elements. foreach (MssMsg returnedMsg in msgProcessor.ProcessMssMsg(inputMsg)) { int foundIndex = desiredReturnedMsgList.FindIndex( desiredReturnedMsg => desiredReturnedMsg.Equals(returnedMsg)); if (foundIndex == -1) { Assert.Fail("The desired MssMsgs were not returned."); return; } else { //Ensures that each message is desiredReturnedMsgs is only matched to a //message in returnedMsgs once. desiredReturnedMsgList.RemoveAt(foundIndex); } } Assert.IsTrue(desiredReturnedMsgList.Count == 0, "Some of the desired MssMSgs were not returned"); }