Skip to content

Commit

Permalink
Add LoggedAdifMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
xylo04 committed Oct 30, 2020
1 parent ad74314 commit ffa7973
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
20 changes: 18 additions & 2 deletions wsjtx/wsjtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion wsjtx/wsjtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
<adif_ver:5>3.1.0
<programid:6>WSJT-X
<EOH>
<call:4>T3ST <gridsquare:4>JK73 <mode:3>FT8 <rst_sent:2>-8 <rst_rcvd:2>-9 <qso_date:8>20201030 <time_on:6>120816 <qso_date_off:8>20201030 <time_off:6>120916 <band:3>40m <freq:8>7.075950 <station_callsign:5>K0SWE <my_gridsquare:6>DM79LV <tx_pwr:1>5 <comment:7>Comment <name:4>Jess <operator:5>T3STR <EOR>`,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit ffa7973

Please sign in to comment.