Example #1
0
        public void DD_WriteRegister(byte[] addr, byte num, byte[] data)
        {
            byte[] poBuf = new byte[addr.Length + data.Length + 1 + 3 + 2];
            poBuf[0] = m_bSourceAddress;
            poBuf[1] = 0x03;
            poBuf[2] = 0x10;
            int offset = 3;

            Buffer.BlockCopy(addr, 0, poBuf, offset, addr.Length);
            offset       += addr.Length;
            poBuf[offset] = num;
            offset       += 1;
            Buffer.BlockCopy(data, 0, poBuf, offset, data.Length);
            offset       += data.Length;
            poBuf[offset] = 0x00;
            offset       += 1;
            poBuf[offset] = 0x00;
            offset       += 1;

            byte[] crc16 = CRC_Check.CRC16(poBuf, 0, poBuf.Length - 2);

            poBuf[poBuf.Length - 2] = crc16[1];
            poBuf[poBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[poBuf.Length - 2];
            Buffer.BlockCopy(poBuf, 2, cmdBuf, 0, poBuf.Length - 2);

            SendMultiFrame(cmdBuf, cmdBuf.Length);
        }
Example #2
0
        public void EraseDidiRecord()
        {
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0xDD, 0xBD, 0x00, 0x06, 0x00, 0x00 };
            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[6];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #3
0
        public void ReadDidiCurrentRecordData()
        {
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0xCC, 0xA4, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00 };
            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[8];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #4
0
        public void DD_ReleyEvent()
        {
            byte[] Buf = new byte[] { m_bSourceAddress, 0x03, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00 };

            byte[] crc16 = CRC_Check.CRC16(Buf, 0, Buf.Length - 2);

            Buf[Buf.Length - 2] = crc16[1];
            Buf[Buf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[6];
            Buffer.BlockCopy(Buf, 2, cmdBuf, 0, 6);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #5
0
        public void DD_SettingBrakeStatus(byte status)
        {
            byte[] Buf = new byte[] { m_bSourceAddress, 0x03, 0x10, 0xA2, 0x68, 0x01, status, 0x00, 0x00, 0x00 };

            byte[] crc16 = CRC_Check.CRC16(Buf, 0, Buf.Length - 2);

            Buf[Buf.Length - 2] = crc16[1];
            Buf[Buf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[8];
            Buffer.BlockCopy(Buf, 2, cmdBuf, 0, 8);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #6
0
        public void DD_ReadFeedbackInfo()
        {
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0xA2, 0xA0, 0x03, 0x00, 0x00 };

            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[6];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #7
0
        public void DD_PowerOff()
        {
            byte[] poBuf = new byte[] { m_bSourceAddress, 0x03, 0x10, 0xA2, 0x00, 0x01, 0x00, 0x00, 0x5A, 0xE9 };

            byte[] crc16 = CRC_Check.CRC16(poBuf, 0, poBuf.Length - 2);

            poBuf[poBuf.Length - 2] = crc16[1];
            poBuf[poBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[8];
            Buffer.BlockCopy(poBuf, 2, cmdBuf, 0, 8);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #8
0
        private void CheckConnectReadSOH()
        {
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0xA2, 0x00, 0x01, 0x00, 0x00 };

            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[6];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, 6);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #9
0
        public void SendMultiFrame(byte[] dataBuf, int len, byte nCmd)
        {
            byte[] cmdBuf = new byte[len + 8];
            cmdBuf[0] = m_bSourceAddress;
            cmdBuf[1] = 0x03;
            cmdBuf[2] = 0xDD;
            cmdBuf[3] = nCmd;
            byte[] lenBuf = BitConverter.GetBytes((short)cmdBuf.Length - 2);
            cmdBuf[4] = lenBuf[1];
            cmdBuf[5] = lenBuf[0];
            Buffer.BlockCopy(dataBuf, 0, cmdBuf, 6, len);

            byte[] crc16 = CRC_Check.CRC16(cmdBuf, 0, cmdBuf.Length - 2);

            cmdBuf[cmdBuf.Length - 2] = crc16[1];
            cmdBuf[cmdBuf.Length - 1] = crc16[0];

            int nFrameLen = 0;

            if ((cmdBuf.Length - 2) % 8 == 0)
            {
                nFrameLen = (cmdBuf.Length - 2) / 8;
            }
            else
            {
                nFrameLen = (cmdBuf.Length - 2) / 8 + 1;
            }
            m_bIsSendMultiFrame = true;
            int nSendIndex = 2;

            for (int n = nFrameLen; n > 0; n--)
            {
                byte[] byteCmdBuf = new byte[8];
                if (nSendIndex + 8 > cmdBuf.Length)
                {
                    Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, (cmdBuf.Length - nSendIndex));
                }
                else
                {
                    Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, 8);
                }

                uint BqProtID = (uint)(BqProtocolID | (n - 1));
                DataLinkLayer.SendCanFrame(BqProtID, byteCmdBuf);

                nSendIndex += 8;
                Thread.Sleep(5);
            }
            m_bIsSendMultiFrame = false;
        }
Example #10
0
        private void SendSingleFrameData(byte[] rdBuf)
        {
            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[rdBuf.Length - 2];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            DataLinkLayer.SendCanFrame(BqProtocolID, cmdBuf);

            bReadBqBmsResp = false;
        }
Example #11
0
        public void DD_ReadRegister(byte[] addr, byte num)
        {
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 };
            Buffer.BlockCopy(addr, 0, rdBuf, 3, addr.Length);
            rdBuf[addr.Length + 3] = num;
            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[6];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #12
0
        public void Didi_ReadRTC()
        {
            if (m_bIsStopCommunication)
            {
                return;
            }
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0xA2, 0x48, 0x02, 0x00, 0x00 };
            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];

            byte[] cmdBuf = new byte[6];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf);
        }
Example #13
0
        public void AdjustDidiRTC(uint dt)
        {
            byte[] data  = BitConverter.GetBytes(dt);
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x10, 0xA2, 0x48, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            rdBuf[rdBuf.Length - 3] = data[0];
            rdBuf[rdBuf.Length - 4] = data[1];
            rdBuf[rdBuf.Length - 5] = data[2];
            rdBuf[rdBuf.Length - 6] = data[3];
            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];


            byte[] cmdBuf = new byte[10];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            SendMultiFrame(cmdBuf, cmdBuf.Length);
        }
Example #14
0
        public void AdjustDidiRTC(DateTime dt)
        {
            TimeSpan ts = dt - systemStartTime;

            byte[] data  = BitConverter.GetBytes(((uint)(ts.Ticks / Math.Pow(10, 7))));
            byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x10, 0xA2, 0x48, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            rdBuf[rdBuf.Length - 3] = data[0];
            rdBuf[rdBuf.Length - 4] = data[1];
            rdBuf[rdBuf.Length - 5] = data[2];
            rdBuf[rdBuf.Length - 6] = data[3];
            byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2);

            rdBuf[rdBuf.Length - 2] = crc16[1];
            rdBuf[rdBuf.Length - 1] = crc16[0];


            byte[] cmdBuf = new byte[10];
            Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2);

            SendMultiFrame(cmdBuf, cmdBuf.Length);
        }
Example #15
0
        public void SendUpdateAppMultiFrame(byte[] dataBuf, int len, byte nCmd, List <UpdateInformation> queue, bool isAddQueue, object lockobj)
        {
            byte[] cmdBuf = new byte[len + 8];
            cmdBuf[0] = m_bSourceAddress;
            cmdBuf[1] = 0x03;
            cmdBuf[2] = 0x45;
            cmdBuf[3] = nCmd;
            byte[] lenBuf = BitConverter.GetBytes((short)len);
            cmdBuf[4] = lenBuf[1];
            cmdBuf[5] = lenBuf[0];
            Buffer.BlockCopy(dataBuf, 0, cmdBuf, 6, len);

            byte[] crc16 = CRC_Check.CRC16(cmdBuf, 0, cmdBuf.Length - 2);

            cmdBuf[cmdBuf.Length - 2] = crc16[1];
            cmdBuf[cmdBuf.Length - 1] = crc16[0];

            int nFrameLen = 0;

            if ((cmdBuf.Length - 2) % 8 == 0)
            {
                nFrameLen = (cmdBuf.Length - 2) / 8;
            }
            else
            {
                nFrameLen = (cmdBuf.Length - 2) / 8 + 1;
            }
            m_bIsSendMultiFrame = true;
            int nSendIndex = 2;

            for (int n = nFrameLen; n > 0; n--)
            {
                byte[] byteCmdBuf = new byte[8];
                if (nSendIndex + 8 > cmdBuf.Length)
                {
                    Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, (cmdBuf.Length - nSendIndex));
                }
                else
                {
                    Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, 8);
                }

                uint BqProtID = (uint)(BqProtocolID | (n - 1));
                DataLinkLayer.SendCanFrame(BqProtID, byteCmdBuf);

                nSendIndex += 8;
                //Thread.Sleep(5);
                if (isAddQueue)
                {
                    UpdateInformation info = new UpdateInformation();
                    info.DirectionStr = "发送";
                    info.Length       = byteCmdBuf.Length.ToString();
                    info.TimeStr      = DateTime.Now.ToString("MM/dd HH:mm:ss") + string.Format(":{0}", DateTime.Now.Millisecond);
                    info.ID           = string.Format("0x{0}", BqProtID.ToString("X"));
                    info.Content      = BitConverter.ToString(byteCmdBuf);
                    if (n == nFrameLen)
                    {
                        if (nCmd == 0x13)
                        {
                            info.Comments = string.Format("根据最新固件信息获取固件状态—多帧第{0}帧,共{1}帧", nFrameLen - n + 1, nFrameLen);
                        }
                        else if (nCmd == 0x15)
                        {
                            uint index = (uint)(dataBuf[4] << 8 | dataBuf[5]);
                            info.Comments = string.Format("第{0}块从机升级包—多帧第{1}帧,共{2}帧", index, nFrameLen - n + 1, nFrameLen);
                        }
                    }
                    else
                    {
                        info.Comments = string.Format("第{0}帧,共{1}帧", nFrameLen - n + 1, nFrameLen);
                    }
                    //queue.Enqueue(info);
                    lock (lockobj)
                    {
                        queue.Add(info);
                    }
                }
            }
            m_bIsSendMultiFrame = false;
        }