From ffa797374cec96f6dec82cf14118210c5c9e6f41 Mon Sep 17 00:00:00 2001 From: Chris Keller Date: Fri, 30 Oct 2020 06:00:02 -0600 Subject: [PATCH] Add LoggedAdifMessage --- main.go | 2 ++ wsjtx/wsjtx.go | 20 ++++++++++++++++++-- wsjtx/wsjtx_test.go | 15 ++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 799a540..71d715a 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,8 @@ func main() { fmt.Println("QSO Logged:", message) case wsjtx.CloseMessage: fmt.Println("Close:", message) + case wsjtx.LoggedAdifMessage: + fmt.Println("Logged Adif:", message) default: fmt.Println("Other:", reflect.TypeOf(message), message) } diff --git a/wsjtx/wsjtx.go b/wsjtx/wsjtx.go index 58719c1..76700dd 100644 --- a/wsjtx/wsjtx.go +++ b/wsjtx/wsjtx.go @@ -82,8 +82,13 @@ type CloseMessage struct { Id string `json:"id"` } +type LoggedAdifMessage struct { + Id string `json:"id"` + Adif string `json:"adif"` +} + const Magic = 0xadbccbda -const BufLen = 256 +const BufLen = 1024 type parser struct { buffer []byte @@ -163,7 +168,9 @@ func ParseMessage(buffer []byte, length int) interface{} { case 10: log.Printf("WSJT-X WSPR Decode isn't implemented yet: %v\n", string(p.buffer[p.cursor:])) case 12: - log.Printf("WSJT-X LoggedAdif isn't implemented yet: %v\n", string(p.buffer[p.cursor:])) + loggedAdif := p.parseLoggedAdif() + p.checkParse(loggedAdif) + return loggedAdif } return nil } @@ -314,6 +321,15 @@ func (p *parser) parseClose() interface{} { } } +func (p *parser) parseLoggedAdif() interface{} { + id := p.parseUtf8() + adif := p.parseUtf8() + return LoggedAdifMessage{ + Id: id, + Adif: adif, + } +} + func (p *parser) parseUint8() uint8 { value := p.buffer[p.cursor] p.cursor += 1 diff --git a/wsjtx/wsjtx_test.go b/wsjtx/wsjtx_test.go index 38d038e..6ef2784 100644 --- a/wsjtx/wsjtx_test.go +++ b/wsjtx/wsjtx_test.go @@ -101,13 +101,26 @@ func TestParseMessage(t *testing.T) { ExchangeSent: "1B", ExchangeReceived: "1D", }, - }, { + }, + { name: "Parse Close", args: argsFrom(`adbccbda00000002000000060000000657534a542d58`), want: CloseMessage{ Id: "WSJT-X", }, }, + { + name: "Parse Logged Adif", + args: argsFrom(`adbccbda000000020000000c0000000657534a542d580000015c0a3c616469665f7665723a353e332e312e300a3c70726f6772616d69643a363e57534a542d580a3c454f483e0a3c63616c6c3a343e54335354203c677269647371756172653a343e4a4b3733203c6d6f64653a333e465438203c7273745f73656e743a323e2d38203c7273745f726376643a323e2d39203c71736f5f646174653a383e3230323031303330203c74696d655f6f6e3a363e313230383136203c71736f5f646174655f6f66663a383e3230323031303330203c74696d655f6f66663a363e313230393136203c62616e643a333e34306d203c667265713a383e372e303735393530203c73746174696f6e5f63616c6c7369676e3a353e4b30535745203c6d795f677269647371756172653a363e444d37394c56203c74785f7077723a313e35203c636f6d6d656e743a373e436f6d6d656e74203c6e616d653a343e4a657373203c6f70657261746f723a353e5433535452203c454f523e`), + want: LoggedAdifMessage{ + Id: "WSJT-X", + Adif: ` +3.1.0 +WSJT-X + +T3ST JK73 FT8 -8 -9 20201030 120816 20201030 120916 40m 7.075950 K0SWE DM79LV 5 Comment Jess T3STR `, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {