diff --git a/README.md b/README.md index d5be9ec..80de8af 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,8 @@ is up) with the following info: - First status bar line: - `state`: RX/TX/TUNE depending on the PTT status - - `freq`: operating frequency in MHz, mode (LSB/USB/FM...), active filter + - `freq`: operating frequency in MHz, mode (LSB/USB/FM...), active filter, + preamp (PAMP0 means the preamp is off) - `txpwr`: current transmit power setting in percent - `audiomon`: current status of the audio monitor (see the *Hotkeys* section in this README for more information about this feature) @@ -140,6 +141,7 @@ Some basic CAT control hotkeys are also supported: - `d`, `f`: cycles through filters - `D`: toggles data mode - `v`, `b`: cycles through bands +- `p`: toggle preamp ## Icom IC-705 Wi-Fi notes diff --git a/civcontrol.go b/civcontrol.go index 513f37b..b9bfe0a 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -73,6 +73,7 @@ type civControlStruct struct { dataMode bool bandIdx int bandChanging bool + preamp int } } @@ -100,6 +101,8 @@ func (s *civControlStruct) decode(d []byte) { s.decodePower(payload) case 0x1c: s.decodeTransmitStatus(payload) + case 0x16: + s.decodePreamp(payload) } } @@ -221,6 +224,18 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) { statusLog.reportPTT(s.state.ptt, s.state.tune) } +func (s *civControlStruct) decodePreamp(d []byte) { + if len(d) < 2 { + return + } + + switch d[0] { + case 0x02: + s.state.preamp = int(d[1]) + statusLog.reportPreamp(s.state.preamp) + } +} + func (s *civControlStruct) setPwr(percent int) error { v := uint16(0x0255 * (float64(percent) / 100)) return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x0a, byte(v >> 8), byte(v & 0xff), 253}) @@ -385,6 +400,14 @@ func (s *civControlStruct) decBand() error { return s.setFreq(f) } +func (s *civControlStruct) togglePreamp() error { + b := byte(s.state.preamp + 1) + if b > 2 { + b = 0 + } + return s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x02, b, 253}) +} + func (s *civControlStruct) getFreq() error { return s.st.send([]byte{254, 254, civAddress, 224, 3, 253}) } @@ -423,5 +446,9 @@ func (s *civControlStruct) init(st *serialStream) error { if err := s.getTransmitStatus(); err != nil { return err } + // Querying preamp. + if err := s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x02, 253}); err != nil { + return err + } return nil } diff --git a/keyboard-linux.go b/keyboard-linux.go index d25a65d..d3335b2 100644 --- a/keyboard-linux.go +++ b/keyboard-linux.go @@ -150,6 +150,12 @@ func (s *keyboardStruct) handleKey(k byte) { log.Error("can't change band: ", err) } } + case 'p': + if civControl != nil { + if err := civControl.togglePreamp(); err != nil { + log.Error("can't change preamp: ", err) + } + } case 'q': quitChan <- true } diff --git a/statuslog.go b/statuslog.go index 83893d3..6143154 100644 --- a/statuslog.go +++ b/statuslog.go @@ -19,6 +19,7 @@ type statusLogData struct { mode string dataMode string filter string + preamp string txPowerStr string startTime time.Time @@ -133,6 +134,16 @@ func (s *statusLogStruct) reportDataMode(dataMode, filter string) { } } +func (s *statusLogStruct) reportPreamp(preamp int) { + s.mutex.Lock() + defer s.mutex.Unlock() + + if s.data == nil { + return + } + s.data.preamp = fmt.Sprint("PAMP", preamp) +} + func (s *statusLogStruct) reportPTT(ptt, tune bool) { s.mutex.Lock() defer s.mutex.Unlock() @@ -199,12 +210,16 @@ func (s *statusLogStruct) update() { if s.data.filter != "" { filterStr = " " + s.data.filter } + var preampStr string + if s.data.preamp != "" { + preampStr = " " + s.data.preamp + } var txPowerStr string if s.data.txPowerStr != "" { txPowerStr = " txpwr " + s.data.txPowerStr } s.data.line1 = fmt.Sprint("state ", s.data.stateStr, " freq: ", fmt.Sprintf("%.6f", float64(s.data.frequency)/1000000), - modeStr, filterStr, txPowerStr, " audio ", s.data.audioStateStr) + modeStr, filterStr, preampStr, txPowerStr, " audio ", s.data.audioStateStr) up, down, lost, retransmits := netstat.get() lostStr := "0"