feat: Implemented UDP Outbound Adif message, freq to pstrotator

This commit is contained in:
2026-07-05 18:17:30 +02:00
parent a8b3269b1e
commit 4f32012930
16 changed files with 704 additions and 123 deletions
+7
View File
@@ -386,6 +386,9 @@ type IcomTXState struct {
RITHz int `json:"rit_hz"` // RIT/XIT offset, signed Hz
RITOn bool `json:"rit_on"`
XITOn bool `json:"xit_on"`
// CW keyer (send messages via the rig's internal keyer, CI-V 0x17).
KeySpeedWPM int `json:"key_speed_wpm"` // current KEY SPEED in WPM
BreakIn int `json:"break_in"` // CW break-in: 0=OFF, 1=SEMI, 2=FULL
// Set controls.
RFPower int `json:"rf_power"` // 0-100 (TX output)
MicGain int `json:"mic_gain"` // 0-100
@@ -429,6 +432,10 @@ type IcomController interface {
SetRIT(int) error // RIT/ΔTX offset in signed Hz
SetRITOn(bool) error // RIT on/off
SetXITOn(bool) error // ΔTX (XIT) on/off
SendCW(string) error // key a CW message via the rig's keyer (CI-V 0x17)
StopCW() error // abort the CW message being sent
SetKeySpeed(int) error // CW keyer speed in WPM
SetBreakIn(int) error // CW break-in: 0=OFF, 1=SEMI, 2=FULL
}
// ScopeSweep is one complete spectrum-scope sweep reassembled from the Icom's
+62
View File
@@ -45,6 +45,15 @@ const (
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
CmdSendCW = 0x17 // send a CW message (ASCII, ≤30 chars) via the rig's keyer; data 0xFF = stop
SubLevelKeySpeed = 0x0C // CmdLevel: CW keying speed (0-255 → KeyMinWPM..KeyMaxWPM)
// CW keyer speed range for the KEY SPEED level (IC-7610: 6-48 WPM).
KeyMinWPM = 6
KeyMaxWPM = 48
StopCWByte = 0xFF // 0x17 data byte that stops an in-progress CW message
SubRITFreq = 0x00 // RIT/ΔTX offset: 2 BCD bytes (LE, 0-9999) + sign byte (00 +, 01 -)
SubRITOn = 0x01 // RIT on/off (00/01)
@@ -85,6 +94,14 @@ const (
SubSwNB = 0x22 // noise blanker on/off
SubSwNR = 0x40 // noise reduction on/off
SubSwANF = 0x41 // auto-notch on/off
SubSwBreakIn = 0x47 // CW break-in: 0=OFF, 1=SEMI, 2=FULL (needed so 0x17 CW keys TX)
)
// CW break-in modes (CmdSwitch 0x47).
const (
BreakInOff = 0
BreakInSemi = 1
BreakInFull = 2
)
// Icom mode codes (used by CmdReadMode / CmdSetMode).
@@ -191,6 +208,51 @@ func BCDToRIT(b []byte) int {
return v
}
// WPMToKeyLevel maps a CW speed in words-per-minute to the 0-255 value the KEY
// SPEED level (CmdLevel 0x0C) expects, linear across KeyMinWPM..KeyMaxWPM.
func WPMToKeyLevel(wpm int) int {
if wpm < KeyMinWPM {
wpm = KeyMinWPM
}
if wpm > KeyMaxWPM {
wpm = KeyMaxWPM
}
return (wpm - KeyMinWPM) * 255 / (KeyMaxWPM - KeyMinWPM)
}
// KeyLevelToWPM is the inverse of WPMToKeyLevel (0-255 → WPM).
func KeyLevelToWPM(v int) int {
if v < 0 {
v = 0
}
if v > 255 {
v = 255
}
return KeyMinWPM + (v*(KeyMaxWPM-KeyMinWPM)+127)/255
}
// CWText is the set of characters the rig's keyer accepts (command 0x17).
// Everything else is dropped. Space keys a word gap.
const CWText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 /?.,-=+@:"
// FilterCW upper-cases text and keeps only keyer-legal characters.
func FilterCW(text string) string {
out := make([]byte, 0, len(text))
for i := 0; i < len(text); i++ {
c := text[i]
if c >= 'a' && c <= 'z' {
c -= 32
}
for j := 0; j < len(CWText); j++ {
if CWText[j] == c {
out = append(out, c)
break
}
}
}
return string(out)
}
// 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 {
+91
View File
@@ -551,6 +551,91 @@ func (b *IcomSerial) SetXITOn(on bool) error {
return nil
}
// SendCW keys a CW message through the rig's internal keyer (CI-V 0x17). The
// text is upper-cased and filtered to keyer-legal characters; the radio must be
// in CW mode. Messages longer than 30 characters are split across several 0x17
// commands (the rig queues them).
func (b *IcomSerial) SendCW(text string) error {
msg := civ.FilterCW(text)
if msg == "" {
applog.Printf("icom cw: nothing to send (filtered %q → empty)", text)
return nil
}
applog.Printf("icom cw: send %q (%d chars) to rig 0x%02X", msg, len(msg), b.rigAddr)
for len(msg) > 0 {
n := len(msg)
if n > 30 {
n = 30
}
chunk := msg[:n]
msg = msg[n:]
payload := append([]byte{civ.CmdSendCW}, []byte(chunk)...)
if err := b.write(payload...); err != nil {
applog.Printf("icom cw: write failed: %v", err)
return err
}
// A missing ack is NOT fatal: some firmwares don't acknowledge 0x17, and
// the message bytes were already written. Only an explicit NG (0xFA) means
// the rig refused it (typically: not in CW mode / break-in off).
f, err := b.recv(icomCmdTimeout, func(d civ.Decoded) bool { return d.Cmd == civ.OK || d.Cmd == civ.NG })
if err != nil {
applog.Printf("icom cw: chunk %q written, no ack (sent anyway): %v", chunk, err)
} else if f.Cmd == civ.NG {
applog.Printf("icom cw: rig REJECTED CW (0xFA) — put the rig in CW mode / enable break-in")
return fmt.Errorf("icom: rig rejected CW — check CW mode / break-in")
} else {
applog.Printf("icom cw: chunk %q acked OK", chunk)
}
}
return nil
}
// SetBreakIn sets CW break-in (0=OFF, 1=SEMI, 2=FULL). Break-in must be on for
// the 0x17 CW keyer to actually switch the rig to transmit.
func (b *IcomSerial) SetBreakIn(mode int) error {
if mode < 0 {
mode = 0
}
if mode > 2 {
mode = 2
}
applog.Printf("icom cw: set break-in %d", mode)
if err := b.exec(civ.CmdSwitch, civ.SubSwBreakIn, byte(mode)); err != nil {
applog.Printf("icom cw: set break-in failed: %v", err)
return err
}
b.setCache(func(s *IcomTXState) { s.BreakIn = mode })
return nil
}
// StopCW aborts a CW message currently being sent (0x17 with the 0xFF stop code).
func (b *IcomSerial) StopCW() error {
applog.Printf("icom cw: stop")
if err := b.write(civ.CmdSendCW, civ.StopCWByte); err != nil {
return err
}
_, _ = b.recv(icomCmdTimeout, func(d civ.Decoded) bool { return d.Cmd == civ.OK || d.Cmd == civ.NG })
return nil
}
// SetKeySpeed sets the CW keyer speed in WPM (CmdLevel 0x0C).
func (b *IcomSerial) SetKeySpeed(wpm int) error {
lvl := civ.WPMToKeyLevel(wpm)
applog.Printf("icom cw: set key speed %d WPM (level %d)", wpm, lvl)
if err := b.exec(append([]byte{civ.CmdLevel, civ.SubLevelKeySpeed}, civ.LevelToBCD(lvl)...)...); err != nil {
applog.Printf("icom cw: set key speed failed: %v", err)
return err
}
if wpm < civ.KeyMinWPM {
wpm = civ.KeyMinWPM
}
if wpm > civ.KeyMaxWPM {
wpm = civ.KeyMaxWPM
}
b.setCache(func(s *IcomTXState) { s.KeySpeedWPM = wpm })
return nil
}
// readRIT reads the offset + RIT/ΔTX on-off flags into st (best-effort).
func (b *IcomSerial) readRIT(st *IcomTXState) {
if err := b.write(civ.CmdRIT, civ.SubRITFreq); err == nil {
@@ -812,6 +897,12 @@ func (b *IcomSerial) readDSP() {
st.Filter = int(f)
}
b.readRIT(&st)
if v, ok := b.readLevel(civ.SubLevelKeySpeed); ok {
st.KeySpeedWPM = civ.KeyLevelToWPM(v)
}
if v, ok := b.readSwitch(civ.SubSwBreakIn); ok {
st.BreakIn = int(v)
}
b.dspMu.Lock()
b.dsp = st