Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        public void Init(MssMsg mssMsg,
                         List <MssParamInfo> variableParamInfoList,
                         IMappingEntry mappingEntry)
        {
            IStaticMssMsgInfo inMsgInfo     = Factory_StaticMssMsgInfo.Create(mssMsg.Type);
            double            relativeData1 = (double)mssMsg.Data1 / (double)(inMsgInfo.MaxData1Value - inMsgInfo.MinData1Value);
            double            relativeData2 = (double)mssMsg.Data2 / (double)(inMsgInfo.MaxData2Value - inMsgInfo.MinData2Value);
            double            relativeData3 = (double)mssMsg.Data3 / (double)(inMsgInfo.MaxData3Value - inMsgInfo.MinData3Value);

            this.Init(relativeData1, relativeData2, relativeData3,
                      variableParamInfoList,
                      mappingEntry);
        }
        /// <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 ReturnStatus <XyPoint <double> > evaluateCurveAtXVal(double inputXVal, int curveIndex, IMappingEntry mappingEntry, List <MssParamInfo> variableParamInfoList, List <XyPoint <double> > controlPointList)
        {
            //For each sample point data1 data2 and data3 will be set to the X value of the
            //sample point.
            double relData1 = inputXVal;
            double relData2 = inputXVal;
            double relData3 = inputXVal;

            IStaticMssMsgInfo inMsgInfo =
                Factory_StaticMssMsgInfo.Create(mappingEntry.InMssMsgRange.MsgType);

            //If curXVal is outside of the relative input range for data 1 then set
            //relData1 to NaN
            double max    = (double)inMsgInfo.MaxData1Value;
            double min    = (double)inMsgInfo.MinData1Value;
            double bottom = (double)mappingEntry.InMssMsgRange.Data1RangeBottom;
            double top    = (double)mappingEntry.InMssMsgRange.Data1RangeTop;

            if (inputXVal < ((bottom - min) / (max - min + 1)) ||
                inputXVal > ((top - min) / (max - min + 1)))
            {
                relData1 = double.NaN;
            }

            //If curXVal is outside of the relative input range for data 2 then set relData2
            //to NaN
            max    = (double)inMsgInfo.MaxData2Value;
            min    = (double)inMsgInfo.MinData2Value;
            bottom = (double)mappingEntry.InMssMsgRange.Data2RangeBottom;
            top    = (double)mappingEntry.InMssMsgRange.Data2RangeTop;
            if (inputXVal < ((bottom - min) / (max - min + 1)) ||
                inputXVal > ((top - min) / (max - min + 1)))
            {
                relData2 = double.NaN;
            }

            var evalInput = new EvaluationCurveInput();

            evalInput.Init(
                relData1,
                relData2,
                relData3,
                variableParamInfoList,
                mappingEntry);

            var evalJob = new EvaluationCurveJob();

            var returnedExpression = CreateExpressionFromString(mappingEntry.CurveShapeInfo.CurveEquations[curveIndex], EvalType.Curve);

            if (returnedExpression.IsValid == false)
            {
                return(new ReturnStatus <XyPoint <double> >());
            }

            evalJob.Configure(evalInput, controlPointList, returnedExpression.Value);

            evalJob.Execute();

            if (evalJob.OutputIsValid)
            {
                var curPoint = new XyPoint <double>(inputXVal, evalJob.OutputVal);
                return(new ReturnStatus <XyPoint <double> >(curPoint));
            }
            else
            {
                return(new ReturnStatus <XyPoint <double> >());
            }
        }