Add AGC display/toggle

This commit is contained in:
Nonoo 2020-11-05 08:19:16 +01:00
parent adb9d682b4
commit afe56656e9
4 changed files with 61 additions and 3 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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"