Skip to content

Commit

Permalink
Add sending Replay
Browse files Browse the repository at this point in the history
Part of #2
  • Loading branch information
xylo04 committed Nov 1, 2020
1 parent 187b586 commit 61419c0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func handleCommand(command string, wsjtxServer wsjtx.Server) {
case "close":
fmt.Println("Sending Close")
err = wsjtxServer.Close(wsjtx.CloseMessage{Id: "WSJT-X"})

case "replay":
fmt.Println("Sending Replay")
err = wsjtxServer.Replay(wsjtx.ReplayMessage{Id: "WSJT-X"})

}
if err != nil {
fmt.Println(err)
Expand Down
7 changes: 7 additions & 0 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func encodeClose(msg CloseMessage) ([]byte, error) {
return e.finish()
}

func encodeReplay(msg ReplayMessage) ([]byte, error) {
e := newEncoder()
e.encodeUint32(replayNum)
e.encodeUtf8(msg.Id)
return e.finish()
}

type encoder struct {
buf *bytes.Buffer
}
Expand Down
32 changes: 32 additions & 0 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,35 @@ func Test_encodeClose(t *testing.T) {
})
}
}

func Test_encodeReplay(t *testing.T) {
type args struct {
msg ReplayMessage
}
wantBin, _ := hex.DecodeString("adbccbda00000002000000070000000657534a542d58")
tests := []struct {
name string
args args
want []byte
wantErr bool
}{
{
name: "encodeReplay",
args: args{msg: ReplayMessage{"WSJT-X"}},
want: wantBin,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := encodeReplay(tt.args.msg)
if (err != nil) != tt.wantErr {
t.Errorf("encodeReplay() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("encodeReplay() got = %v, want %v", got, tt.want)
}
})
}
}
17 changes: 17 additions & 0 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ type CloseMessage struct {

const closeNum = 6

/*
When a server starts it may be useful for it to determine the
state of preexisting clients. Sending this message to each
client as it is discovered will cause that client (WSJT-X) to
send a "Decode" message for each decode currently in its "Band
activity" window.
In only.
https://sourceforge.net/p/wsjt/wsjtx/ci/8f99fcce/tree/Network/NetworkMessage.hpp#l326
*/
type ReplayMessage struct {
Id string `json:"id"`
}

const replayNum = 7

/*
The decode message is sent when a new decode is completed, in
this case the 'New' field is true.
Expand Down
7 changes: 7 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func (s *Server) Close(msg CloseMessage) error {
return err
}

// Send a message to WSJT-X to replay QSOs in the Band Activity window.
func (s *Server) Replay(msg ReplayMessage) error {
msgBytes, _ := encodeReplay(msg)
_, err := s.conn.WriteTo(msgBytes, s.remoteAddr)
return err
}

func check(err error) {
if err != nil {
panic(err)
Expand Down

0 comments on commit 61419c0

Please sign in to comment.