public static new WsjtxMessage Parse(byte[] message) { if (!CheckMagicNumber(message)) { return(null); } var statusMessage = new WsprDecodeMessage(); int cur = MAGIC_NUMBER_LENGTH; statusMessage.SchemaVersion = DecodeQInt32(message, ref cur); var messageType = (MessageType)DecodeQInt32(message, ref cur); if (messageType != MessageType.WSPR_DECODE_MESSAGE_TYPE) { return(null); } statusMessage.Id = DecodeString(message, ref cur); statusMessage.New = DecodeBool(message, ref cur); statusMessage.StartTime = DecodeQTime(message, ref cur); statusMessage.Snr = DecodeQInt32(message, ref cur); statusMessage.DeltaTime = DecodeDouble(message, ref cur); statusMessage.Frequency = DecodeQUInt64(message, ref cur); statusMessage.Drift = DecodeQInt32(message, ref cur); statusMessage.Callsign = DecodeString(message, ref cur); statusMessage.Grid = DecodeString(message, ref cur); statusMessage.PowerDbm = DecodeQInt32(message, ref cur); statusMessage.FromRecording = DecodeBool(message, ref cur); return(statusMessage); }
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}"); }