Пример #1
0
        public LcdpPacket Deserialize(byte[] bytes)
        {
            LcdpPacket output = null;

            try
            {
                #region CMN, LMN, RMN1, RMN2

                byte CMN = bytes[0];
                byte LMN = bytes[1];
                byte RMN1 = bytes[2];
                byte RMN2 = bytes[3];

                #endregion

                #region MessageID

                string MessageID = Encoding.ASCII.GetString(bytes, 4, 16);

                #endregion

                #region TotalChunks, ChunkIndex

                int TotalChunks = BitConverter.ToInt32(bytes, 20);
                int ChunkIndex = BitConverter.ToInt32(bytes, 24);

                #endregion

                #region DataLength, Data

                int DataLength = BitConverter.ToInt32(bytes, 28);
                byte[] Data = new byte[DataLength];

                bytes.CopyTo(Data, 32);

                #endregion

                output = new LcdpPacket()
                {
                    CMN = CMN,
                    DMN = LMN,
                    RMN1 = RMN1,
                    RMN2 = RMN2,
                    MessageId = MessageID,
                    TotalChunks = TotalChunks,
                    ChunkIndex = ChunkIndex,
                    Data = Data
                };

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return output;
        }
Пример #2
0
        public LcdpPacket Deserialize(byte[] bytes)
        {
            LcdpPacket output = null;

            try
            {
                #region CMN, DMN, RMN1, RMN2

                byte CMN = bytes[0];
                byte DMN = bytes[1];
                byte RMN1 = bytes[2];
                byte RMN2 = bytes[3];

                #endregion

                #region MessageID

                string MessageID = Encoding.ASCII.GetString(bytes, 4, 16);

                #endregion

                #region TotalChunks, ChunkIndex

                int TotalChunks = BitConverter.ToInt32(bytes, 20);
                int ChunkIndex = BitConverter.ToInt32(bytes, 24);

                #endregion

                #region DataLength, Data

                int DataLength = BitConverter.ToInt32(bytes, 28);
                byte[] Data = new byte[DataLength];
                Array.Copy(bytes, 32, Data, 0, DataLength);

                #endregion

                output = new LcdpPacket()
                {
                    CMN = CMN,
                    DMN = DMN,
                    RMN1 = RMN1,
                    RMN2 = RMN2,
                    MessageId = MessageID,
                    TotalChunks = TotalChunks,
                    ChunkIndex = ChunkIndex,
                    Data = Data
                };

            }
            catch (Exception e)
            {
                throw new LcdpPacketSerializationException("Error during lcdp serialization", bytes, e);
            }

            return output;
        }
Пример #3
0
 public void AddChunk(LcdpPacket chunk)
 {
     chunks[chunk.ChunkIndex] = chunk;
     TimeStamp = DateTime.Now;
     ++chunkCounter;
 }
Пример #4
0
 public LcdpMessage(LcdpPacket chunk)
 {
     Id = chunk.MessageId;
     chunks = new LcdpPacket[chunk.TotalChunks];
     AddChunk(chunk);
 }