From 7cbe3204728685ef16b81be555cf5baa8004fc3e Mon Sep 17 00:00:00 2001 From: Nonoo Date: Wed, 4 Nov 2020 10:01:07 +0100 Subject: [PATCH] Add NR display/adjustment --- README.md | 7 ++++-- civcontrol.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++---- hotkeys.go | 22 ++++++++++++++++-- statuslog.go | 33 ++++++++++++++++++++++++++- 4 files changed, 115 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 16d3979..5a87bd8 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ is up) with the following info: overflow - `rfg`: RF gain in percent - `sql`: squelch level in percent + - `nr`: noise reduction level in percent - Second status bar line: - `state`: RX/TX/TUNE depending on the PTT status @@ -144,12 +145,14 @@ Some basic CAT control hotkeys are also supported: - `[`, `]`: decreases, increases frequency - `{`, `}`: decreases, increases tuning step - `;`, `'`: decreases, increases RF gain -- `,`, `.`: decreases, increases squelch level +- `:`, `"`: decreases, increases squelch level +- `,`, `.`: decreases, increases noise reduction level +- `/`: toggles noise reduction - `n`, `m`: cycles through operating modes - `d`, `f`: cycles through filters - `D`: toggles data mode - `v`, `b`: cycles through bands -- `p`: toggle preamp +- `p`: toggles preamp ## Icom IC-705 Wi-Fi notes diff --git a/civcontrol.go b/civcontrol.go index d0497ac..06a0c3c 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -75,6 +75,8 @@ type civControlStruct struct { pwrPercent int rfGainPercent int sqlPercent int + nrPercent int + nrEnabled bool operatingModeIdx int filterIdx int dataMode bool @@ -109,13 +111,13 @@ func (s *civControlStruct) decode(d []byte) { case 0x1a: s.decodeDataModeAndOVF(payload) case 0x14: - s.decodePowerRFGainSquelch(payload) + s.decodePowerRFGainSQLNR(payload) case 0x1c: s.decodeTransmitStatus(payload) case 0x15: s.decodeVdAndS(payload) case 0x16: - s.decodePreamp(payload) + s.decodePreampAndNR(payload) } } @@ -251,7 +253,7 @@ func (s *civControlStruct) decodeDataModeAndOVF(d []byte) { } } -func (s *civControlStruct) decodePowerRFGainSquelch(d []byte) { +func (s *civControlStruct) decodePowerRFGainSQLNR(d []byte) { if len(d) < 3 { return } @@ -265,6 +267,10 @@ func (s *civControlStruct) decodePowerRFGainSquelch(d []byte) { hex := uint16(d[1])<<8 | uint16(d[2]) s.state.sqlPercent = int(math.Round((float64(hex) / 0x0255) * 100)) statusLog.reportSQL(s.state.sqlPercent) + case 0x06: + hex := uint16(d[1])<<8 | uint16(d[2]) + s.state.nrPercent = int(math.Round((float64(hex) / 0x0255) * 100)) + statusLog.reportNR(s.state.nrPercent) case 0x0a: hex := uint16(d[1])<<8 | uint16(d[2]) s.state.pwrPercent = int(math.Round((float64(hex) / 0x0255) * 100)) @@ -348,7 +354,7 @@ func (s *civControlStruct) decodeVdAndS(d []byte) { } } -func (s *civControlStruct) decodePreamp(d []byte) { +func (s *civControlStruct) decodePreampAndNR(d []byte) { if len(d) < 2 { return } @@ -357,6 +363,13 @@ func (s *civControlStruct) decodePreamp(d []byte) { case 0x02: s.state.preamp = int(d[1]) statusLog.reportPreamp(s.state.preamp) + case 0x40: + if d[1] == 1 { + s.state.nrEnabled = true + } else { + s.state.nrEnabled = false + } + statusLog.reportNREnabled(s.state.nrEnabled) } } @@ -417,6 +430,25 @@ func (s *civControlStruct) decSQL() error { return nil } +func (s *civControlStruct) setNR(percent int) error { + v := uint16(0x0255 * (float64(percent) / 100)) + return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x06, byte(v >> 8), byte(v & 0xff), 253}) +} + +func (s *civControlStruct) incNR() error { + if s.state.nrPercent < 100 { + return s.setNR(s.state.nrPercent + 1) + } + return nil +} + +func (s *civControlStruct) decNR() error { + if s.state.nrPercent > 0 { + return s.setNR(s.state.nrPercent - 1) + } + return nil +} + func (s *civControlStruct) getDigit(v uint, n int) byte { f := float64(v) for n > 0 { @@ -570,6 +602,14 @@ func (s *civControlStruct) togglePreamp() error { return s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x02, b, 253}) } +func (s *civControlStruct) toggleNR() error { + var b byte + if !s.state.nrEnabled { + b = 1 + } + return s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x40, b, 253}) +} + func (s *civControlStruct) incTS() error { var b byte if s.state.tsValue == 13 { @@ -633,6 +673,14 @@ func (s *civControlStruct) getSQL() error { return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x03, 253}) } +func (s *civControlStruct) getNR() error { + return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x06, 253}) +} + +func (s *civControlStruct) getNREnabled() error { + return s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x40, 253}) +} + func (s *civControlStruct) loop() { for { select { @@ -688,6 +736,12 @@ func (s *civControlStruct) init(st *serialStream) error { if err := s.getSQL(); err != nil { return err } + if err := s.getNR(); err != nil { + return err + } + if err := s.getNREnabled(); err != nil { + return err + } s.deinitNeeded = make(chan bool) s.deinitFinished = make(chan bool) diff --git a/hotkeys.go b/hotkeys.go index dddeacb..3b2ba87 100644 --- a/hotkeys.go +++ b/hotkeys.go @@ -36,18 +36,36 @@ func handleHotkey(k byte) { log.Error("can't decrease rf gain: ", err) } } - case '.': + case '"': if civControl != nil { if err := civControl.incSQL(); err != nil { log.Error("can't increase sql: ", err) } } - case ',': + case ':': if civControl != nil { if err := civControl.decSQL(); err != nil { log.Error("can't decrease sql: ", err) } } + case '.': + if civControl != nil { + if err := civControl.incNR(); err != nil { + log.Error("can't increase nr: ", err) + } + } + case ',': + if civControl != nil { + if err := civControl.decNR(); err != nil { + log.Error("can't decrease nr: ", err) + } + } + case '/': + if civControl != nil { + if err := civControl.toggleNR(); err != nil { + log.Error("can't toggle nr: ", err) + } + } case ']': if civControl != nil { if err := civControl.incFreq(); err != nil { diff --git a/statuslog.go b/statuslog.go index a1db9bc..9e1ef61 100644 --- a/statuslog.go +++ b/statuslog.go @@ -25,6 +25,8 @@ type statusLogData struct { txPower string rfGain string sql string + nr string + nrEnabled bool s string ovf bool ts string @@ -153,6 +155,16 @@ func (s *statusLogStruct) reportPreamp(preamp int) { s.data.preamp = fmt.Sprint("PAMP", preamp) } +func (s *statusLogStruct) reportNREnabled(enabled bool) { + s.mutex.Lock() + defer s.mutex.Unlock() + + if s.data == nil { + return + } + s.data.nrEnabled = enabled +} + func (s *statusLogStruct) reportVd(voltage float64) { s.mutex.Lock() defer s.mutex.Unlock() @@ -250,6 +262,16 @@ func (s *statusLogStruct) reportSQL(percent int) { s.data.sql = fmt.Sprint(percent, "%") } +func (s *statusLogStruct) reportNR(percent int) { + s.mutex.Lock() + defer s.mutex.Unlock() + + if s.data == nil { + return + } + s.data.nr = fmt.Sprint(percent, "%") +} + func (s *statusLogStruct) clearInternal() { fmt.Printf("%c[2K", 27) } @@ -296,7 +318,16 @@ func (s *statusLogStruct) update() { if s.data.sql != "" { sqlStr = " sql " + s.data.sql } - s.data.line1 = fmt.Sprint(s.data.s, ovfStr, rfGainStr, sqlStr) + var nrStr string + if s.data.nr != "" { + nrStr = " nr " + if s.data.nrEnabled { + nrStr += s.data.nr + } else { + nrStr += "-" + } + } + s.data.line1 = fmt.Sprint(s.data.s, ovfStr, rfGainStr, sqlStr, nrStr) var tsStr string if s.data.ts != "" {