Ejemplo n.º 1
0
        public ReceiveBytesData(byte[] receivebyte)
        {
            Int32 minSizeReceiveData = sizePacket_CA + sizeHeader;

            if (receivebyte.Length >= minSizeReceiveData)
            {
                var segmentHeader = new ArraySegment <byte>(receivebyte, 0, sizeHeader);

                switch (GetTypeData(segmentHeader))
                {
                case 0xCA:
                    packet_CA = new Packet_CA();
                    var segmentCA = new ArraySegment <byte>(receivebyte, sizeHeader, sizePacket_CA);
                    GetPacket <Packet_CA>(segmentCA, ref packet_CA);
                    break;

                case 0xAB:
                    packet_AB = new Packet_AB();
                    var segmentAB = new ArraySegment <byte>(receivebyte, sizeHeader, sizePacket_AB);
                    GetPacket <Packet_AB>(segmentAB, ref packet_AB);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public byte[] getBytesToSendPacketCA(Packet_CA packet)
        {
            byte[] ret      = new byte[getLenToSendPacketCA()];
            byte[] byteCA   = StructToByteArray(packet);
            Header headerCA = new Header(0xCA, (byte)sizePacket_CA, this.calc_cs(byteCA, (byte)sizePacket_CA));

            byte[] byteHeader = StructToByteArray(headerCA);
            ret = byteHeader.Concat(byteCA).ToArray();

            return(ret);
        }