예제 #1
0
    bool ProcessData()
    {
        if (m_DataLen < PacketHeaderSize)
        {
            if (m_RecvLen <= 0)
            {
                return(false);
            }

            Array.Copy(m_RecvBuffer, 0, m_DataBuffer, m_DataLen, m_RecvLen);

            m_DataLen += m_RecvLen;

            m_RecvLen = 0;
        }

        if (m_DataLen < PacketHeaderSize)
        {
            return(false);
        }

        Byte CheckCode = m_DataBuffer[0];

        int nPacketSize = BitConverter.ToUInt16(m_DataBuffer, 1);

        if (nPacketSize <= m_DataLen)
        {
            //璇存槑涓€涓寘鐨勬暟鎹槸瓒冲?
            Array.Copy(m_DataBuffer, 0, m_ReadHelper.GetData(), 0, nPacketSize);

            Array.Copy(m_DataBuffer, nPacketSize, m_DataBuffer, 0, m_DataLen - nPacketSize);

            m_DataLen = m_DataLen - nPacketSize;
        }
        else
        {
            return(false);
        }

        if (!m_ReadHelper.BeginRead())
        {
            return(false);
        }

        OnCommandHandle((Command_ID)m_ReadHelper.m_CommandHeader.wCommandID, 0, m_ReadHelper);

        return(true);
    }