public DatagramType([NotNull] Type entryType) : base(entryType) { DatagramAttribute attribute = ( DatagramAttribute )entryType.GetCustomAttributes(typeof(DatagramAttribute), false). Single( ); XmlName = attribute.XmlName; BinaryType = attribute.BinaryType; }
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) { } }
public DatagramAttribute(string xmlName, BinaryDatagramType binaryType) { XmlName = xmlName; BinaryType = binaryType; }
public static Datagram Parse(BinaryDatagramType type, byte [] data) { return(Create(TypeList.Single(typ => typ.BinaryType == type), data)); }