Пример #1
0
        public static new WsjtxMessage Parse(byte[] message)
        {
            if (!CheckMagicNumber(message))
            {
                return(null);
            }

            var decodeMessage = new DecodeMessage();

            int cur = MAGIC_NUMBER_LENGTH;

            decodeMessage.SchemaVersion = DecodeQInt32(message, ref cur);

            var messageType = (MessageType)DecodeQInt32(message, ref cur);

            if (messageType != MessageType.DECODE_MESSAGE_TYPE)
            {
                return(null);
            }

            decodeMessage.Id             = DecodeString(message, ref cur);
            decodeMessage.New            = DecodeBool(message, ref cur);
            decodeMessage.SinceMidnight  = DecodeQTime(message, ref cur);
            decodeMessage.RxDate         = DateTime.UtcNow.Date;
            decodeMessage.Snr            = DecodeQInt32(message, ref cur);
            decodeMessage.DeltaTime      = DecodeDouble(message, ref cur);
            decodeMessage.DeltaFrequency = DecodeQInt32(message, ref cur);
            decodeMessage.Mode           = DecodeString(message, ref cur);
            decodeMessage.Message        = DecodeString(message, ref cur);

            //this actually happens, because of AP (a priori) set
            //'W1AW K1HZ FN42                      ? a2'
            //01234567890123456789012345678901234567890
            //          1         2         3         4
            int idx = decodeMessage.Message.IndexOf("   ");

            if (idx != -1)
            {
                decodeMessage.Message = decodeMessage.Message.Substring(0, idx);
            }

            //hashed message case, brackets and only two words:
            // <K1JT> KG6EMU/AG
            decodeMessage.Message = RemoveAngleBrackets(decodeMessage.Message);

            decodeMessage.UseStdReply = false; //used in ReplyToCq, was: DecodeBool(message, ref cur);
            decodeMessage.OffAir      = DecodeBool(message, ref cur);
            decodeMessage.Priority    = false;

            //decodeMessage.messageWords = decodeMessage.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            return(decodeMessage);
        }
Пример #2
0
        public static WsjtxMessage Parse(byte[] datagram)
        {
            if (!CheckMagicNumber(datagram))
            {
                return(null);
            }

            int cur = MAGIC_NUMBER_LENGTH;

            int schemaVersion = DecodeQInt32(datagram, ref cur);
            var messageType   = (MessageType)DecodeQInt32(datagram, ref cur);

            try
            {
                if (schemaVersion == 2 || schemaVersion == 3)
                {
                    WsjtxMessage result;

                    if (messageType == MessageType.HEARTBEAT_MESSAGE_TYPE)
                    {
                        result = HeartbeatMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.STATUS_MESSAGE_TYPE)
                    {
                        result = StatusMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.DECODE_MESSAGE_TYPE)
                    {
                        result = DecodeMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.ENQUEUE_DECODE_MESSAGE_TYPE)
                    {
                        result = EnqueueDecodeMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.CLEAR_MESSAGE_TYPE)
                    {
                        result = ClearMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.QSO_LOGGED_MESSAGE_TYPE)
                    {
                        result = QsoLoggedMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.CLOSE_MESSAGE_TYPE)
                    {
                        result = CloseMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.WSPR_DECODE_MESSAGE_TYPE)
                    {
                        result = WsprDecodeMessage.Parse(datagram);
                    }
                    else if (messageType == MessageType.LOGGED_ADIF_MESSAGE_TYPE)
                    {
                        result = LoggedAdifMessage.Parse(datagram);
                    }
                    else
                    {
                        result = new UnknownMessage();
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw new ParseFailureException(messageType, datagram, ex);
            }

            throw new NotImplementedException($"Schema version {schemaVersion}, message type {messageType}");
        }