Esempio n. 1
0
            public DatagramType([NotNull] Type entryType) : base(entryType)
            {
                DatagramAttribute attribute =
                    ( DatagramAttribute )entryType.GetCustomAttributes(typeof(DatagramAttribute), false).
                    Single( );

                XmlName    = attribute.XmlName;
                BinaryType = attribute.BinaryType;
            }
Esempio n. 2
0
        public void BinaryListenTask( )
        {
            try
            {
                byte currentSequence = 0;
                while (IsRunning)
                {
                    if (UnderlyingStream.ReadByte( ) == DatagramHeaderInt)
                    {
                        byte sequence = ( byte )UnderlyingStream.ReadByte( );

                        if (sequence == currentSequence)
                        {
                            currentSequence++;
                        }
                        else
                        {
                            //Todo:???
                        }

                        BinaryDatagramType type = ( BinaryDatagramType )( byte )UnderlyingStream.ReadByte( );                               //todo:if not throw

                        byte crc = ( byte )UnderlyingStream.ReadByte( );

                        byte length = ( byte )UnderlyingStream.ReadByte( );

                        byte [] data = new byte[length];

                        UnderlyingStream.Read(data, 0, length);

                        if (data.CaluCrc8( ) == crc)
                        {
                            if (Datagram.Parse(type, data) is ReceiveDatagram datagram)
                            {
                                ReceiveQueue.Enqueue(datagram);
                            }
                        }
                        else
                        {
                            //todo:Warning?
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
        }
Esempio n. 3
0
 public DatagramAttribute(string xmlName, BinaryDatagramType binaryType)
 {
     XmlName    = xmlName;
     BinaryType = binaryType;
 }
Esempio n. 4
0
 public static Datagram Parse(BinaryDatagramType type, byte [] data)
 {
     return(Create(TypeList.Single(typ => typ.BinaryType == type), data));
 }