Beispiel #1
0
        public static bool GetBool(SignalItem signal, byte[] data)
        {
            ulong v64  = BitConverter.ToUInt64(data, 0);
            ulong mask = (ulong)1 << signal.StartBit;

            return((v64 & mask) == mask);
        }
Beispiel #2
0
 public static ulong GetUInt64(SignalItem signal, byte[] data)
 {
     return(BitConverter.ToUInt64(data, 0));
 }
Beispiel #3
0
        public static uint GetUInt32(SignalItem signal, byte[] data)
        {
            ulong v64 = BitConverter.ToUInt64(data, 0);

            return((uint)(v64 >> signal.StartBit));
        }
Beispiel #4
0
 public static float GetSingle(SignalItem signal, byte[] data)
 {
     return(BitConverter.ToSingle(data, signal.StartBit / 8));
 }
Beispiel #5
0
        /// <summary>
        /// Egy signal küldése
        /// </summary>
        public static CanMsg MakeMessage(byte nodeTypeId, byte nodeAddress, bool broadcast, SignalItem signal, string value)
        {
            uint arbId = (uint)(nodeTypeId << 24 | nodeAddress << 16 | signal.Message.Id << 8);

            if (broadcast)
            {
                arbId |= 0x1;
            }

            ulong mask = 0;

            for (int i = 0; i < signal.Bits; i++)
            {
                mask |= (ulong)1 << i;
            }
            mask <<= signal.StartBit;
            signal.Message.Value &= ~mask;

            switch (signal.Type.ToUpper().Trim())
            {
            case "UNSIGNED":
            {
                ulong val = ulong.Parse(value);
                signal.Message.Value |= val <<= signal.StartBit;
                break;
            }

            case "FLOAT":
            {
                float val   = float.Parse(value);
                var   bytes = BitConverter.GetBytes(val);
                ulong val64 = BitConverter.ToUInt32(bytes, 0);
                signal.Message.Value |= val64 <<= signal.StartBit;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException("signal.Type");
            }
            }
            return(new CanMsg(arbId, BitConverter.GetBytes(signal.Message.Value)));
        }