diff --git a/encoder.go b/encoder.go index 3a06c64..c58ceb2 100644 --- a/encoder.go +++ b/encoder.go @@ -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 } diff --git a/encoder_test.go b/encoder_test.go index ef6550e..5f664cd 100644 --- a/encoder_test.go +++ b/encoder_test.go @@ -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) + } + }) + } +} diff --git a/messages.go b/messages.go index c34b306..5d33af6 100644 --- a/messages.go +++ b/messages.go @@ -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 diff --git a/server.go b/server.go index 6da4362..fb5f51d 100644 --- a/server.go +++ b/server.go @@ -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)