feat: added RIT and XIT for Icom

This commit is contained in:
2026-07-05 13:21:11 +02:00
parent e112de5967
commit 8cf53a0aa2
10 changed files with 430 additions and 64 deletions
+37
View File
@@ -44,6 +44,11 @@ const (
CmdSwitch = 0x16 // on/off + multi-state DSP settings (sub + 1 byte)
CmdATU = 0x1C // sub 0x01 = antenna tuner (0x00 off, 0x01 through, 0x02 tune)
CmdScope = 0x27 // spectrum-scope waveform stream (sub 0x00 = data, 0x11 = on/off)
CmdRIT = 0x21 // RIT/ΔTX: sub 0x00 offset freq, 0x01 RIT on/off, 0x02 ΔTX(XIT) on/off
SubRITFreq = 0x00 // RIT/ΔTX offset: 2 BCD bytes (LE, 0-9999) + sign byte (00 +, 01 -)
SubRITOn = 0x01 // RIT on/off (00/01)
SubXITOn = 0x02 // ΔTX (XIT) on/off (00/01)
SubDataMode = 0x06
SubPTT = 0x00
@@ -154,6 +159,38 @@ func BCDToLevel(b []byte) int {
return int(b[0])*100 + int(b[1]>>4)*10 + int(b[1]&0x0F)
}
// RITToBCD encodes a RIT/ΔTX offset (Hz, 9999..9999) as the 3 bytes CI-V
// command 0x21 0x00 uses: 2 little-endian BCD bytes of the magnitude followed by
// a sign byte (0x00 positive, 0x01 negative).
func RITToBCD(hz int) []byte {
neg := hz < 0
if neg {
hz = -hz
}
if hz > 9999 {
hz = 9999
}
lo := byte(hz%10 | (hz/10%10)<<4)
hi := byte(hz/100%10 | (hz/1000%10)<<4)
sign := byte(0)
if neg {
sign = 1
}
return []byte{lo, hi, sign}
}
// BCDToRIT decodes the 3 offset bytes of a 0x21 0x00 response back to signed Hz.
func BCDToRIT(b []byte) int {
if len(b) < 3 {
return 0
}
v := int(b[0]&0x0F) + int(b[0]>>4)*10 + int(b[1]&0x0F)*100 + int(b[1]>>4)*1000
if b[2] != 0 {
return -v
}
return v
}
// ByteToBCD / BCDToByte handle a single packed-BCD byte (used by the
// attenuator, where the value is dB: 0x00, 0x06, 0x12, 0x18…).
func ByteToBCD(v int) byte {