예제 #1
0
        public WriteReplyPacket(byte entryPort, byte exitPort, string dateString, List <byte> packetBytes, string endCode)
            : base(entryPort, exitPort, dateString, packetBytes, endCode)
        {
            int byteCount = m_remainingBytes.Count;
            int byteIndex = 0;

            if (byteIndex >= byteCount)
            {
                return;
            }

            // Packet type
            m_packetTypeByte = m_remainingBytes[byteIndex];

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Status
            m_status = m_remainingBytes[byteIndex];

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Destination logical address
            m_destinationLogicalAddress = m_remainingBytes[byteIndex];

            // Transaction identifier
            {
                if ((2 + byteIndex) >= byteCount)
                {
                    return;
                }

                m_transactionId = (ushort)(
                    m_remainingBytes[2 + byteIndex] +
                    (m_remainingBytes[1 + byteIndex] << 8)
                    );

                byteIndex += 2;
            }

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Reply RmapCRC
            m_replyCRC = m_remainingBytes[byteIndex];

            List <byte> headerBytes = new List <byte>(byteIndex + 3);

            headerBytes.Add(m_logicalAddress);
            headerBytes.Add((byte)m_protocolId);
            headerBytes.AddRange(m_remainingBytes.Take(byteIndex));

            if (!m_CRCError && !RmapCRC.validCRC(headerBytes.ToArray(), m_replyCRC))
            {
                m_CRCError = true;
            }

            m_remainingBytes = null;
        }
예제 #2
0
        public WriteCommandPacket(byte entryPort, byte exitPort, string dateString, List <byte> packetBytes, string endCode)
            : base(entryPort, exitPort, dateString, packetBytes, endCode)
        {
            m_sourcePathAddress = new byte[0];
            m_dataBytes         = new byte[0];

            int byteCount = m_remainingBytes.Count;
            int byteIndex = 0;

            if (byteIndex >= byteCount)
            {
                return;
            }

            // Packet type
            m_packetTypeByte = m_remainingBytes[byteIndex];

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Destination key
            m_destinationKey = m_remainingBytes[byteIndex];

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Source path address
            // Source logical address
            {
                List <byte> tmpBytes = new List <byte>();
                for (; byteIndex < byteCount; ++byteIndex)
                {
                    if (byteIndex >= byteCount)
                    {
                        return;
                    }
                    if (m_remainingBytes[byteIndex] >= 32)
                    {
                        m_sourceLogicalAddress = m_remainingBytes[byteIndex];
                        break;
                    }
                    tmpBytes.Add(m_remainingBytes[byteIndex]);
                }
                m_sourcePathAddress = tmpBytes.ToArray();
            }

            // Transaction identifier
            {
                if ((2 + byteIndex) >= byteCount)
                {
                    return;
                }

                m_transactionId = (ushort)(
                    m_remainingBytes[2 + byteIndex] +
                    (m_remainingBytes[1 + byteIndex] << 8)
                    );

                byteIndex += 2;
            }

            // Extended write address
            if (++byteIndex >= byteCount)
            {
                return;
            }
            m_extendedWriteAddress = m_remainingBytes[byteIndex];

            // Write address
            {
                if ((4 + byteIndex) >= byteCount)
                {
                    return;
                }

                m_writeAddress = (uint)(
                    m_remainingBytes[4 + byteIndex] +
                    (m_remainingBytes[3 + byteIndex] << 8) +
                    (m_remainingBytes[2 + byteIndex] << 16) +
                    (m_remainingBytes[1 + byteIndex] << 24)
                    );

                byteIndex += 4;
            }

            // Data length
            {
                if ((3 + byteIndex) >= byteCount)
                {
                    return;
                }

                m_dataLength = (uint)(
                    m_remainingBytes[3 + byteIndex] +
                    (m_remainingBytes[2 + byteIndex] << 8) +
                    (m_remainingBytes[1 + byteIndex] << 16)
                    );

                byteIndex += 3;
            }

            if ((++byteIndex) >= byteCount)
            {
                return;
            }

            // Header CRC
            m_headerCRC = m_remainingBytes[byteIndex];

            List <byte> headerBytes = new List <byte>(byteIndex + 3);

            headerBytes.Add(m_logicalAddress);
            headerBytes.Add((byte)m_protocolId);
            headerBytes.AddRange(m_remainingBytes.Take(byteIndex));

            if (!m_CRCError && !RmapCRC.validCRC(headerBytes.ToArray(), m_headerCRC))
            {
                m_CRCError = true;
            }

            if (byteIndex + 2 >= byteCount)
            {
                return;
            }

            // Data
            {
                List <byte> tmpBytes = new List <byte>();
                for (++byteIndex; byteIndex < (byteCount - 1); ++byteIndex)
                {
                    tmpBytes.Add(m_remainingBytes[byteIndex]);
                }
                m_dataBytes = tmpBytes.ToArray();
            }

            // Data RmapCRC
            m_dataCRC = m_remainingBytes[byteIndex];

            if (!m_CRCError && !RmapCRC.validCRC(DataBytes, m_dataCRC))
            {
                m_CRCError = true;
            }

            m_remainingBytes = null;
        }
예제 #3
0
        public ReadReplyPacket(byte entryPort, byte exitPort, string dateString, List <byte> packetBytes, string endCode)
            : base(entryPort, exitPort, dateString, packetBytes, endCode)
        {
            int byteCount = m_remainingBytes.Count;
            int byteIndex = 0;

            if (byteIndex >= byteCount)
            {
                return;
            }

            // Packet type
            m_packetTypeByte = m_remainingBytes[byteIndex];

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Status
            m_status = m_remainingBytes[byteIndex];

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Destination logical address
            m_destinationLogicalAddress = m_remainingBytes[byteIndex];

            // Transaction identifier
            {
                if ((2 + byteIndex) >= byteCount)
                {
                    return;
                }

                m_transactionId = (ushort)(
                    m_remainingBytes[2 + byteIndex] +
                    (m_remainingBytes[1 + byteIndex] << 8)
                    );

                byteIndex += 2;
            }

            // Next byte is reserved, skip it
            if (2 + byteIndex >= byteCount)
            {
                return;
            }
            byteIndex += 1;

            // Data length
            {
                if ((3 + byteIndex) >= byteCount)
                {
                    return;
                }

                m_dataLength = (uint)(
                    m_remainingBytes[3 + byteIndex] +
                    (m_remainingBytes[2 + byteIndex] << 8) +
                    (m_remainingBytes[1 + byteIndex] << 16)
                    );

                byteIndex += 3;
            }

            if (++byteIndex >= byteCount)
            {
                return;
            }

            // Header CRC
            m_headerCRC = m_remainingBytes[byteIndex];

            List <byte> headerBytes = new List <byte>(byteIndex + 3);

            headerBytes.Add(m_logicalAddress);
            headerBytes.Add((byte)m_protocolId);
            headerBytes.AddRange(m_remainingBytes.Take(byteIndex));

            if (!m_CRCError && !RmapCRC.validCRC(headerBytes.ToArray(), m_headerCRC))
            {
                m_CRCError = true;
            }

            if (byteIndex + 2 >= byteCount)
            {
                return;
            }

            // Data
            {
                List <byte> tmpBytes = new List <byte>();
                for (++byteIndex; byteIndex < (byteCount - 1); ++byteIndex)
                {
                    tmpBytes.Add(m_remainingBytes[byteIndex]);
                }
                m_dataBytes = tmpBytes.ToArray();
            }

            // Data RmapCRC
            m_dataCRC = m_remainingBytes[byteIndex];

            if (!m_CRCError && !RmapCRC.validCRC(DataBytes, m_dataCRC))
            {
                m_CRCError = true;
            }

            m_remainingBytes = null;
        }