Skip to content

Commit

Permalink
Add sending "Switch Configuration"
Browse files Browse the repository at this point in the history
Resolves #10
  • Loading branch information
xylo04 committed Nov 4, 2020
1 parent a2d89fe commit df10179
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ func encodeLocation(msg LocationMessage) ([]byte, error) {
return e.finish()
}

func encodeSwitchConfiguration(msg SwitchConfigurationMessage) ([]byte, error) {
e := newEncoder()
e.encodeUint32(switchConfigurationNum)
e.encodeUtf8(msg.Id)
e.encodeUtf8(msg.ConfigurationName)
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 @@ -275,3 +275,35 @@ func Test_encodeLocation(t *testing.T) {
})
}
}

func Test_encodeSwitchConfiguration(t *testing.T) {
type args struct {
msg SwitchConfigurationMessage
}
wantBin, _ := hex.DecodeString("adbccbda000000020000000e0000000657534a542d58000000184d79416c7465726e617465436f6e66696775726174696f6e")
tests := []struct {
name string
args args
want []byte
wantErr bool
}{
{
name: "encodeSwitchConfiguration",
args: args{msg: SwitchConfigurationMessage{"WSJT-X", "MyAlternateConfiguration"}},
want: wantBin,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := encodeSwitchConfiguration(tt.args.msg)
if (err != nil) != tt.wantErr {
t.Errorf("encodeSwitchConfiguration() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("encodeSwitchConfiguration() got = %v, want %v", got, tt.want)
}
})
}
}
16 changes: 16 additions & 0 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,19 @@ type LoggedAdifMessage struct {
}

const loggedAdifNum = 12

/*
The server may send this message at any time. The message
specifies the name of the configuration to switch to. The new
configuration must exist.
In only.
https://sourceforge.net/p/wsjt/wsjtx/ci/8f99fcce/tree/Network/NetworkMessage.hpp#l468
*/
type SwitchConfigurationMessage struct {
Id string `json:"id"`
ConfigurationName string `json:"configurationName"`
}

const switchConfigurationNum = 14
7 changes: 7 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func (s *Server) Location(msg LocationMessage) error {
return err
}

// Send a message to WSJT-X to switch to a different pre-defined configuration.
func (s *Server) SwitchConfiguration(msg SwitchConfigurationMessage) error {
msgBytes, _ := encodeSwitchConfiguration(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 df10179

Please sign in to comment.