Skip to content

Commit

Permalink
Add WSPRDecodeMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
xylo04 committed Oct 30, 2020
1 parent ffa7973 commit 098fca5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
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.WSPRDecodeMessage:
fmt.Println("WSPR Decode:", message)
case wsjtx.LoggedAdifMessage:
fmt.Println("Logged Adif:", message)
default:
Expand Down
45 changes: 44 additions & 1 deletion wsjtx/wsjtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ type CloseMessage struct {
Id string `json:"id"`
}

type WSPRDecodeMessage struct {
Id string `json:"id"`
New bool `json:"new"`
Time uint32 `json:"time"`
Snr int32 `json:"snr"`
DeltaTime float64 `json:"deltaTime"`
Frequency uint64 `json:"frequency"`
Drift int32 `json:"drift"`
Callsign string `json:"callsign"`
Grid string `json:"grid"`
Power int32 `json:"power"`
OffAir bool `json:"offAir"`
}

type LoggedAdifMessage struct {
Id string `json:"id"`
Adif string `json:"adif"`
Expand Down Expand Up @@ -166,7 +180,9 @@ func ParseMessage(buffer []byte, length int) interface{} {
p.checkParse(closeMsg)
return closeMsg
case 10:
log.Printf("WSJT-X WSPR Decode isn't implemented yet: %v\n", string(p.buffer[p.cursor:]))
wspr := p.parseWsprDecode()
p.checkParse(wspr)
return wspr
case 12:
loggedAdif := p.parseLoggedAdif()
p.checkParse(loggedAdif)
Expand Down Expand Up @@ -321,6 +337,33 @@ func (p *parser) parseClose() interface{} {
}
}

func (p *parser) parseWsprDecode() interface{} {
id := p.parseUtf8()
newDecode := p.parseBool()
decodeTime := p.parseUint32()
snr := p.parseInt32()
deltaTime := p.parseFloat64()
frequency := p.parseUint64()
drift := p.parseInt32()
callsign := p.parseUtf8()
grid := p.parseUtf8()
power := p.parseInt32()
offAir := p.parseBool()
return WSPRDecodeMessage{
Id: id,
New: newDecode,
Time: decodeTime,
Snr: snr,
DeltaTime: deltaTime,
Frequency: frequency,
Drift: drift,
Callsign: callsign,
Grid: grid,
Power: power,
OffAir: offAir,
}
}

func (p *parser) parseLoggedAdif() interface{} {
id := p.parseUtf8()
adif := p.parseUtf8()
Expand Down
17 changes: 17 additions & 0 deletions wsjtx/wsjtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ func TestParseMessage(t *testing.T) {
Id: "WSJT-X",
},
},
{
name: "Parse WSPR Decode",
args: argsFrom(`adbccbda000000020000000a0000000657534a542d580102b5f840ffffffeebfe000000000000000000000006b6c7300000000000000054b3654475700000004434d39350000001700`),
want: WSPRDecodeMessage{
Id: "WSJT-X",
New: true,
Time: 45480000,
Snr: -18,
DeltaTime: -0.5,
Frequency: 7040115,
Drift: 0,
Callsign: "K6TGW",
Grid: "CM95",
Power: 23,
OffAir: false,
},
},
{
name: "Parse Logged Adif",
args: argsFrom(`adbccbda000000020000000c0000000657534a542d580000015c0a3c616469665f7665723a353e332e312e300a3c70726f6772616d69643a363e57534a542d580a3c454f483e0a3c63616c6c3a343e54335354203c677269647371756172653a343e4a4b3733203c6d6f64653a333e465438203c7273745f73656e743a323e2d38203c7273745f726376643a323e2d39203c71736f5f646174653a383e3230323031303330203c74696d655f6f6e3a363e313230383136203c71736f5f646174655f6f66663a383e3230323031303330203c74696d655f6f66663a363e313230393136203c62616e643a333e34306d203c667265713a383e372e303735393530203c73746174696f6e5f63616c6c7369676e3a353e4b30535745203c6d795f677269647371756172653a363e444d37394c56203c74785f7077723a313e35203c636f6d6d656e743a373e436f6d6d656e74203c6e616d653a343e4a657373203c6f70657261746f723a353e5433535452203c454f523e`),
Expand Down

0 comments on commit 098fca5

Please sign in to comment.