Skip to content

Commit 9cd0327

Browse files
committed
hamlib: use l RFPOWER command, discard bandwidth from mode report
Fixes #4
1 parent f3900df commit 9cd0327

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

waveloggoat.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,36 +222,37 @@ func (h *HamlibClient) GetData() (RigData, error) {
222222
if _, err := fmt.Fprintf(conn, "m\n"); err != nil {
223223
return RigData{}, fmt.Errorf("failed to send 'm' command to hamlib: %w", err)
224224
}
225-
modeResp, _, err := reader.ReadLine() // e.g., "USB 2400"
225+
modeResp, _, err := reader.ReadLine() // e.g., "USB"
226226
if err != nil {
227227
return RigData{}, fmt.Errorf("failed to read mode response from hamlib: %w", err)
228228
}
229-
modeParts := strings.Fields(string(modeResp))
230-
if len(modeParts) > 0 {
231-
data.Mode = modeParts[0]
232-
data.ModeB = modeParts[0] // Default modeB to Mode/RX for simplicity
233-
} else {
234-
return RigData{}, fmt.Errorf("invalid mode response format from hamlib: '%s'", modeResp)
235-
}
229+
data.Mode = modeResp
230+
data.ModeB = modeResp
231+
232+
// Discard next line (bandwidth) directly following mode
233+
if _, _, err := reader.ReadLine(); err != nil {
234+
log.Warnf("Failed to read mode bandwidth response from hamlib: %v.", err)
235+
}
236236

237237
// Query Power (P)
238-
if _, err := fmt.Fprintf(conn, "P\n"); err != nil {
239-
log.Warnf("Failed to send 'P' (power) command to hamlib: %v. Sending 0 W.", err)
238+
if _, err := fmt.Fprintf(conn, "l RFPOWER\n"); err != nil {
239+
log.Warnf("Failed to send 'l RFPOWER' (power) command to hamlib: %v. Sending 0 W.", err)
240240
data.Power = 0.0
241241
} else {
242242
powerStr, _, err := reader.ReadLine()
243243
if err != nil {
244244
log.Warnf("Failed to read power response from hamlib: %v. Sending 0 W.", err)
245245
data.Power = 0.0
246246
} else {
247-
// Hamlib returns 0-100 float percentage
247+
// Hamlib returns 0-1 float percentage
248+
log.Debugf("Power string from rig = %s", powerStr)
248249
powerPercent, err := strconv.ParseFloat(string(powerStr), 64)
249250
if err != nil {
250251
log.Warnf("Failed to parse power '%s': %v. Sending 0 W.", powerStr, err)
251252
data.Power = 0.0
252253
} else {
253254
// Convert percentage to 100W max for simple display (Wavelog typically expects watts)
254-
data.Power = powerPercent
255+
data.Power = powerPercent * 100
255256
}
256257
}
257258
}

0 commit comments

Comments
 (0)