Skip to content

Commit f57d4fe

Browse files
committed
implement XIT handling via hamlib
1 parent 249ad5c commit f57d4fe

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

core/entry/entry.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,6 @@ func (c *Controller) ContestChanged(contest core.Contest) {
897897
}
898898

899899
func (c *Controller) WorkmodeChanged(workmode core.Workmode) {
900-
log.Printf("ENTRY: workmode changed %d", workmode)
901900
c.workmode = workmode
902901
}
903902

core/hamlib/hamlib.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ func (c *Client) connect(whenClosed func()) error {
103103
c.conn.StartPolling(c.pollingInterval, c.pollingTimeout,
104104
client.PollCommand(client.OnFrequency(c.setIncomingFrequency)),
105105
client.PollCommand(client.OnModeAndPassband(c.setIncomingModeAndPassband)),
106-
client.PollCommand(c.onXIT()),
106+
client.PollCommand(c.onXITActive()),
107+
client.PollCommand(c.onXITOffset()),
107108
)
108109

109110
c.conn.WhenClosed(func() {
@@ -173,7 +174,26 @@ func (c *Client) setIncomingModeAndPassband(mode client.Mode, _ client.Frequency
173174
// log.Printf("incoming mode %v", incomingMode)
174175
}
175176

176-
func (c *Client) onXIT() (client.ResponseHandler, string) {
177+
func (c *Client) onXITActive() (client.ResponseHandler, string, string) {
178+
return client.ResponseHandlerFunc(func(r protocol.Response) {
179+
if len(r.Data) == 0 {
180+
return
181+
}
182+
active := (r.Data[0] == "1")
183+
c.setIncomingXITActive(active)
184+
}), "get_func", "XIT"
185+
}
186+
187+
func (c *Client) setIncomingXITActive(active bool) {
188+
if c.incoming.xitActive == active {
189+
return
190+
}
191+
c.incoming.xitActive = active
192+
c.emitXITChanged(c.incoming.xitActive, c.incoming.xitOffset)
193+
// log.Printf("incoming XIT active: %v %d", c.incoming.xitActive, c.incoming.xitOffset)
194+
}
195+
196+
func (c *Client) onXITOffset() (client.ResponseHandler, string) {
177197
return client.ResponseHandlerFunc(func(r protocol.Response) {
178198
if len(r.Data) == 0 {
179199
return
@@ -183,20 +203,18 @@ func (c *Client) onXIT() (client.ResponseHandler, string) {
183203
log.Printf("cannot parse XIT offset: %v", err)
184204
return
185205
}
186-
c.setIncomingXIT(offset)
206+
c.setIncomingXITOffset(offset)
187207
}), "get_xit"
188208
}
189209

190-
func (c *Client) setIncomingXIT(offset int) {
191-
incomingXITActive := offset != 0
210+
func (c *Client) setIncomingXITOffset(offset int) {
192211
incomingXITOffset := core.Frequency(offset)
193-
if c.incoming.xitActive == incomingXITActive && c.incoming.xitOffset == incomingXITOffset {
212+
if c.incoming.xitOffset == incomingXITOffset {
194213
return
195214
}
196-
c.incoming.xitActive = incomingXITActive
197215
c.incoming.xitOffset = incomingXITOffset
198216
c.emitXITChanged(c.incoming.xitActive, c.incoming.xitOffset)
199-
// log.Printf("incoming XIT: %v %d", c.incoming.xitActive, c.incoming.xitOffset)
217+
// log.Printf("incoming XIT offset: %v %d", c.incoming.xitActive, c.incoming.xitOffset)
200218
}
201219

202220
func (c *Client) SetFrequency(f core.Frequency) {
@@ -285,14 +303,21 @@ func (c *Client) SetXIT(active bool, offset core.Frequency) {
285303
ctx, cancel := c.withRequestTimeout()
286304
defer cancel()
287305

288-
var err error
306+
activeStr := "0"
307+
if active {
308+
activeStr = "1"
309+
}
310+
err := c.conn.Set(ctx, "set_func", "XIT", activeStr)
311+
if err != nil {
312+
log.Printf("setting XTI active failed: %v", err)
313+
return
314+
}
315+
289316
if active {
290317
err = c.conn.Set(ctx, "set_xit", strconv.Itoa(int(offset)))
291-
} else {
292-
err = c.conn.Set(ctx, "set_xit", "0")
293318
}
294319
if err != nil {
295-
log.Printf("setting the XIT failed: %v", err)
320+
log.Printf("setting the XIT offset failed: %v", err)
296321
}
297322
}
298323

0 commit comments

Comments
 (0)