Skip to content

Commit

Permalink
Add sending "Configure"
Browse files Browse the repository at this point in the history
Resolves #11
  • Loading branch information
xylo04 committed Nov 4, 2020
1 parent df10179 commit ea7b19e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
16 changes: 16 additions & 0 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ func encodeSwitchConfiguration(msg SwitchConfigurationMessage) ([]byte, error) {
return e.finish()
}

func encodeConfigure(msg ConfigureMessage) ([]byte, error) {
e := newEncoder()
e.encodeUint32(configureNum)
e.encodeUtf8(msg.Id)
e.encodeUtf8(msg.Mode)
e.encodeUint32(msg.FrequencyTolerance)
e.encodeUtf8(msg.Submode)
e.encodeBool(msg.FastMode)
e.encodeUint32(msg.TRPeriod)
e.encodeUint32(msg.RxDF)
e.encodeUtf8(msg.DXCall)
e.encodeUtf8(msg.DXGrid)
e.encodeBool(msg.GenerateMessages)
return e.finish()
}

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

func Test_encodeConfigure(t *testing.T) {
type args struct {
msg ConfigureMessage
}
wantBin, _ := hex.DecodeString("adbccbda000000020000000f0000000657534a542d580000000346543400000023ffffffff010000003c000003e80000000454335354000000044a4b373301")
tests := []struct {
name string
args args
want []byte
wantErr bool
}{
{
name: "encodeConfigure",
args: args{msg: ConfigureMessage{
Id: "WSJT-X",
Mode: "FT4",
FrequencyTolerance: 35,
Submode: "",
FastMode: true,
TRPeriod: 60,
RxDF: 1000,
DXCall: "T3ST",
DXGrid: "JK73",
GenerateMessages: true,
}},
want: wantBin,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := encodeConfigure(tt.args.msg)
if (err != nil) != tt.wantErr {
t.Errorf("encodeConfigure() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("encodeConfigure() got = %v, want %v", got, tt.want)
}
})
}
}
27 changes: 27 additions & 0 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,30 @@ type SwitchConfigurationMessage struct {
}

const switchConfigurationNum = 14

/*
The server may send this message at any time. The message
specifies various configuration options. For utf8 string
fields an empty value implies no change, for the quint32 Rx DF
and Frequency Tolerance fields the maximum quint32 value
implies no change. Invalid or unrecognized values will be
silently ignored.
In only.
https://sourceforge.net/p/wsjt/wsjtx/ci/8f99fcce/tree/Network/NetworkMessage.hpp#l477
*/
type ConfigureMessage struct {
Id string `json:"id"`
Mode string `json:"mode"`
FrequencyTolerance uint32 `json:"frequencyTolerance"`
Submode string `json:"submode"`
FastMode bool `json:"fastMode"`
TRPeriod uint32 `json:"trPeriod"`
RxDF uint32 `json:"rxDF"`
DXCall string `json:"dxCall"`
DXGrid string `json:"dxGrid"`
GenerateMessages bool `json:"generateMessages"`
}

const configureNum = 15
7 changes: 7 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ func (s *Server) SwitchConfiguration(msg SwitchConfigurationMessage) error {
return err
}

// Send a message to WSJT-X to change various configuration options.
func (s *Server) Configure(msg ConfigureMessage) error {
msgBytes, _ := encodeConfigure(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 ea7b19e

Please sign in to comment.