From afe56656e9d6fc603afefd14c73715f135ba3d40 Mon Sep 17 00:00:00 2001 From: Nonoo Date: Thu, 5 Nov 2020 08:19:16 +0100 Subject: [PATCH] Add AGC display/toggle --- README.md | 1 + civcontrol.go | 40 ++++++++++++++++++++++++++++++++++++++-- hotkeys.go | 6 ++++++ statuslog.go | 17 ++++++++++++++++- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1623e0b..2a818fc 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ Some basic CAT control hotkeys are also supported: - `D`: toggles data mode - `v`, `b`: cycles through bands - `p`: toggles preamp +- `a`: toggles AGC ## Icom IC-705 Wi-Fi notes diff --git a/civcontrol.go b/civcontrol.go index 7a4a6d3..1684a70 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -9,6 +9,8 @@ import ( const civAddress = 0xa4 const sReadInterval = time.Second +// Commands reference: https://www.icomeurope.com/wp-content/uploads/2020/08/IC-705_ENG_CI-V_1_20200721.pdf + type civOperatingMode struct { name string code byte @@ -88,6 +90,7 @@ type civControlStruct struct { setTuneSent bool setDataModeSent bool setPreampSent bool + setAGCSent bool setNREnabledSent bool setTSSent bool @@ -105,6 +108,7 @@ type civControlStruct struct { bandIdx int bandChanging bool preamp int + agc int tsValue byte ts uint } @@ -144,7 +148,7 @@ func (s *civControlStruct) decode(d []byte) bool { case 0x15: return s.decodeVdSWRS(payload) case 0x16: - return s.decodePreampAndNR(payload) + return s.decodePreampAGCNR(payload) } return true } @@ -480,7 +484,7 @@ func (s *civControlStruct) decodeVdSWRS(d []byte) bool { return true } -func (s *civControlStruct) decodePreampAndNR(d []byte) bool { +func (s *civControlStruct) decodePreampAGCNR(d []byte) bool { switch d[0] { case 0x02: if len(d) < 2 { @@ -492,6 +496,25 @@ func (s *civControlStruct) decodePreampAndNR(d []byte) bool { s.state.setPreampSent = false return false } + case 0x12: + if len(d) < 2 { + return !s.state.setAGCSent + } + s.state.agc = int(d[1]) + var agc string + switch s.state.agc { + case 1: + agc = "F" + case 2: + agc = "M" + case 3: + agc = "S" + } + statusLog.reportAGC(agc) + if s.state.setAGCSent { + s.state.setAGCSent = false + return false + } case 0x40: if len(d) < 2 { return !s.state.setNREnabledSent @@ -745,6 +768,15 @@ func (s *civControlStruct) togglePreamp() error { return s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x02, b, 253}) } +func (s *civControlStruct) toggleAGC() error { + s.state.setAGCSent = true + b := byte(s.state.agc + 1) + if b > 3 { + b = 1 + } + return s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x12, b, 253}) +} + func (s *civControlStruct) toggleNR() error { s.state.setNRSent = true var b byte @@ -877,6 +909,10 @@ func (s *civControlStruct) init(st *serialStream) error { if err := s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x02, 253}); err != nil { return err } + // Querying AGC. + if err := s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x12, 253}); err != nil { + return err + } if err := s.getVd(); err != nil { return err } diff --git a/hotkeys.go b/hotkeys.go index 3dbd2d7..e5506a6 100644 --- a/hotkeys.go +++ b/hotkeys.go @@ -204,6 +204,12 @@ func handleHotkey(k byte) { log.Error("can't change preamp: ", err) } } + case 'a': + if civControl != nil { + if err := civControl.toggleAGC(); err != nil { + log.Error("can't change agc: ", err) + } + } case 'q': quitChan <- true } diff --git a/statuslog.go b/statuslog.go index ba3104d..e500d61 100644 --- a/statuslog.go +++ b/statuslog.go @@ -21,6 +21,7 @@ type statusLogData struct { dataMode string filter string preamp string + agc string vd string txPower string rfGain string @@ -156,6 +157,16 @@ func (s *statusLogStruct) reportPreamp(preamp int) { s.data.preamp = fmt.Sprint("PAMP", preamp) } +func (s *statusLogStruct) reportAGC(agc string) { + s.mutex.Lock() + defer s.mutex.Unlock() + + if s.data == nil { + return + } + s.data.agc = "AGC" + agc +} + func (s *statusLogStruct) reportNREnabled(enabled bool) { s.mutex.Lock() defer s.mutex.Unlock() @@ -368,6 +379,10 @@ func (s *statusLogStruct) update() { if s.data.preamp != "" { preampStr = " " + s.data.preamp } + var agcStr string + if s.data.agc != "" { + agcStr = " " + s.data.agc + } var vdStr string if s.data.vd != "" { vdStr = " " + s.data.vd @@ -381,7 +396,7 @@ func (s *statusLogStruct) update() { swrStr = " swr " + s.data.swr } s.data.line2 = fmt.Sprint(s.data.stateStr, " ", fmt.Sprintf("%.6f", float64(s.data.frequency)/1000000), - tsStr, modeStr, filterStr, preampStr, vdStr, txPowerStr, swrStr) + tsStr, modeStr, filterStr, preampStr, agcStr, vdStr, txPowerStr, swrStr) up, down, lost, retransmits := netstat.get() lostStr := "0"