Esempio n. 1
0
        private uint GetValue(List <byte> data, VdfByteOrder byteOrder, int startBit, int bitLen)
        {
            switch (byteOrder)
            {
            default:
            case VdfByteOrder.Intel:
                return(ValueUtils.GetValueIntel(data, startBit, bitLen));

            case VdfByteOrder.Motorola:
                return(ValueUtils.GetValueMotorola(data, startBit, bitLen));
            }
        }
Esempio n. 2
0
        private static void decodeByValue(List <byte> data, VdfSignal signal, string value)
        {
            // 按照值的方式
            uint decodeValue = signal.VdfValueDesc.Decode(value);

            switch (signal.ByteOrder)
            {
            case VdfByteOrder.Intel:
                ValueUtils.SetValueIntel(data, signal.StartBit, signal.BitLen, decodeValue);
                break;

            case VdfByteOrder.Motorola:
                ValueUtils.SetValueMotorola(data, signal.StartBit, signal.BitLen, decodeValue);
                break;

            default:
                throw new VdfException("Invalid Byte Order: " + signal.ByteOrder.ToString());
            }
        }
Esempio n. 3
0
        public static void ForEachByte(List <byte> data, VdfSignal signal,
                                       Action <int, int, byte> action)
        {
            switch (signal.ByteOrder)
            {
            case VdfByteOrder.Intel:
                ValueUtils.ForEachByteIntel(data, signal.StartBit, signal.BitLen,
                                            action);
                break;

            case VdfByteOrder.Motorola:
                ValueUtils.ForEachByteMotorola(data, signal.StartBit, signal.BitLen,
                                               action);
                break;

            default:
                throw new ArgumentException("VdfEncoder.ForEachByte: " +
                                            "Invalid Signal ByteOrder");
            }
        }
Esempio n. 4
0
        // 对信号的值进行编码
        // 信号值从data中获取
        public static string Encode(List <byte> data, VdfSignal signal, bool withUnit = false)
        {
            if (signal.VdfValueDesc == null)
            {
                throw new VdfException("Signal Value Desc cannot be null");
            }

            string ret;

            // 使用两个编码接口,
            // 因为BCD编码使用传整形值是不能满足需求的,必须传递字节数组,并且需要直到,字节序
            try
            {
                uint value = 0;
                switch (signal.ByteOrder)
                {
                case VdfByteOrder.Intel:
                    value = ValueUtils.GetValueIntel(data, signal.StartBit, signal.BitLen);
                    break;

                case VdfByteOrder.Motorola:
                    value = ValueUtils.GetValueMotorola(data, signal.StartBit, signal.BitLen);
                    break;

                default:
                    throw new VdfException("Invalid Byte Order: " + signal.ByteOrder.ToString());
                }
                ret = signal.VdfValueDesc.Encode(value, withUnit);
            }
            catch (NotImplementedException)
            {
                ret = signal.VdfValueDesc.Encode(data, signal, withUnit);
            }

            return(ret);
        }