Example #1
0
            internal CanMessage UnpackCanMessage(BinaryReader br)
            {
                UInt32 cob = br.ReadUInt32();
                UInt16 tim = br.ReadUInt16();
                byte   src = br.ReadByte();
                byte   rs1 = br.ReadByte(); /* zero */

                byte[] d    = br.ReadBytes(8);
                byte   dlen = br.ReadByte();

                byte[] p = br.ReadBytes(7); /* PAD */
                UInt64 t = br.ReadUInt64();


                Array.Resize(ref d, dlen);

                return(new CanMessage(
                           CanSourceId.Source(_BoardID, (byte)((src & 7) - 1)),
                           CanMailboxId.Mailbox((src & 0x08) != 0, (byte)(src >> 4)),
                           cob, d)
                {
                    Time = tim,
                    Sec = (UInt32)(long)(t / (1000 * 1000)),
                    Usec = (UInt32)((long)(t % (1000 * 1000)))
                });
            }
Example #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            Random r = new Random();

            CanSharkCore.InputQueue.Enqueue(
                new CanMessage(
                    CanSourceId.Source(0, 0),
                    CanMailboxId.Mailbox(true, 0x00),
                    CanObjectId.Std(0x80))
            {
                Time = 0,
                Usec = 0
            });

            CanSharkCore.InputQueue.Enqueue(
                new CanMessage(
                    CanSourceId.Source(0, 1),
                    CanMailboxId.Mailbox(true, 0x00),
                    CanObjectId.Std(0x80))
            {
                Time = 0,
                Usec = 0
            });

            for (int i = 0; i < 10000; i++)
            {
                uint id = (uint)r.Next(0x800);
                while (id == 0x80)
                {
                    id = (uint)r.Next(0x800);
                }

                CanSharkCore.InputQueue.Enqueue(
                    new CanMessage(
                        CanSourceId.Source(0, (byte)(i % 2)),
                        CanMailboxId.Mailbox(false, 0x00),
                        CanObjectId.Std(id))
                {
                    Time = (ushort)(i * 44),
                    Usec = (ushort)((i * 44) % 1000000),
                    Sec  = (ushort)((i * 44) / 1000000)
                });
            }
        }