Пример #1
0
 /// <summary>
 /// Create a new canPacket from a canBOOTPacket.
 /// </summary>
 /// <param name="boot">The canBOOTPacket to create from.</param>
 /// <param name="sid">The sender id.</param>
 /// <param name="length">Length of data.</param>
 /// <param name="data">Data.</param>
 public CanPacket(canBOOTPacket boot, byte sid, byte length, byte[] data)
 {
     this.type = td.PACKET_TYPE.ptBOOT;
     this.boot = boot;
     this.sid = sid;
     this.length = length;
     for (int i = 0; i < 8; i++) this.data[i] = data[i];
 }
Пример #2
0
        /// <summary>
        /// Creates a new CanPacket from a raw data starting at index startIndex.
        /// </summary>
        /// <param name="raw">Raw data formatted like: id[0] id[1] id[2] id[3] extended remote_request data_length d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7]</param>
        /// <param name="startIndex">The startIndex in the raw byte to parse from.</param>
        public CanPacket(byte[] raw,uint startIndex)
        {
            // 17 bytes, a packet.
            // id[0] id[1] id[2] id[3] extended remote_request data_length d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7]

            ulong addr = (((ulong)raw[startIndex + 3]) << 24) + (((ulong)raw[startIndex + 2]) << 16) + (((ulong)raw[startIndex + 1]) << 8) + (((ulong)raw[startIndex + 0]));

            /*
             x x x P P T T T  O O O O O O O O  R R R R R R R R  S S S S S S S S
             x x x P P C C C  C I I I I I I I  I I I I I I I I  S S S S S S S S
             */

            // addr[28..27] PMODE 0x18000000 >> 27
            //PMODE = BOOT
            /*
            [26..24] TYPE    0x07000000 >> 24
            [23..16] OFFSET  0x00FF0000 >> 16
            [15...8] RID     0x0000FF00 >>  8
            [7....0] SID     0x000000FF
            */

            //PMODE = PGM
            /*
            [26..23] CLASS   0x07800000 >> 23
            [22...8] ID      0x007FFF00 >>  8
            [7....0] SID     0x000000FF
            */

            this.type = (td.PACKET_TYPE)((addr & 0x18000000) >> 27);

            if (this.type == td.PACKET_TYPE.ptBOOT)
            {
                boot.type = (td.BOOT_TYPE)((addr & 0x07000000) >> 24);
                boot.offset = (byte)((addr & 0x00FF0000) >> 16);
                boot.rid = (byte)((addr & 0x0000FF00) >> 8);
            }
            else
            {
                pgm._class = (td.PGM_CLASS)((addr & 0x07800000) >> 23);
                pgm.id = (ushort)((addr & 0x007FFF00) >> 8);
            }
            this.sid = (byte)(addr & 0x000000FF);

            this.length = raw[startIndex + 6];
            for (int i = 0; i < 8; i++) this.data[i] = raw[startIndex + 7 + i];
        }
Пример #3
0
 /// <summary>
 /// Create a new canPacket from a canPGMPacket.
 /// </summary>
 /// <param name="pgm">The canPGMPacket to create from.</param>
 /// <param name="sid">The sender id.</param>
 /// <param name="length">Length of data.</param>
 /// <param name="data">Data.</param>
 public CanPacket(canPGMPacket pgm, byte sid, byte length, byte[] data)
 {
     this.type = td.PACKET_TYPE.ptPGM;
     this.pgm = pgm;
     this.sid = sid;
     this.length = length;
     for (int i = 0; i < 8; i++) this.data[i] = data[i];
 }