Exemple #1
0
        /// <summary>
        /// Encode DM1 fault code object
        /// </summary>
        /// <param name="DM1FaultCode"></param>
        /// <returns></returns>
        public static ulong EncodeDM1(DM1Value DM1FaultCode)
        {
            uint b5 = DM1FaultCode.SPN >> 16;

            b5 = (b5 << 5) | DM1FaultCode.FMI;
            return((DM1FaultCode.SPN & 0xffff) | (b5 << 16));
        }
Exemple #2
0
        public object DecodeCANMessage(ulong signalValue)
        {
            switch (sType)
            {
            //连续值解析
            case SignalType.Continuous:
                double value = signalValue;
                value *= cRatio;
                value += cOffset;
                return(value);

            //离散值解析
            case SignalType.Discrete:
                return(DiscreteDecodeTable.ContainsKey(signalValue) ? DiscreteDecodeTable[signalValue] : string.Format("Undef:{0}", signalValue));

            //开关量解析
            case SignalType.Switch:
                return(SwitchMap[signalValue]);

            //DM1故障码
            case SignalType.DM1FaultCode:
                DM1Value dm1Obj = new DM1Value()
                {
                    FMI = (uint)(signalValue >> 16 & 0x1F),
                    SPN = (uint)(signalValue >> 21 & 7 << 16 | (signalValue & 0xFFFF))
                };
                return(dm1Obj);

            case SignalType.UserDefined:
                //用匿名函数的形式描述解析器(少用)
                //JS: function(var_ulong_value){...}
                return(JavaScriptEngine.runCmd(string.Format("{0}({1})", UDFName, signalValue)));

            default:
                throw new Exception("Undefined signal type, please check your code:" + sType.ToString());
            }
        }