Add RF gain display/adjustment

This commit is contained in:
Nonoo 2020-11-04 09:41:36 +01:00
parent ab19ba4211
commit 3075cf3896
4 changed files with 69 additions and 8 deletions

View file

@ -87,6 +87,7 @@ is up) with the following info:
- First status bar line:
- `S meter`: periodically refreshed S meter value, OVF is displayed on
overflow
- `rfg`: RF gain in percent
- Second status bar line:
- `state`: RX/TX/TUNE depending on the PTT status

View file

@ -73,6 +73,7 @@ type civControlStruct struct {
ptt bool
tune bool
pwrPercent int
rfGainPercent int
operatingModeIdx int
filterIdx int
dataMode bool
@ -107,7 +108,7 @@ func (s *civControlStruct) decode(d []byte) {
case 0x1a:
s.decodeDataModeAndOVF(payload)
case 0x14:
s.decodePower(payload)
s.decodePowerAndRFGain(payload)
case 0x1c:
s.decodeTransmitStatus(payload)
case 0x15:
@ -249,15 +250,21 @@ func (s *civControlStruct) decodeDataModeAndOVF(d []byte) {
}
}
func (s *civControlStruct) decodePower(d []byte) {
if len(d) < 3 || d[0] != 0x0a {
func (s *civControlStruct) decodePowerAndRFGain(d []byte) {
if len(d) < 3 {
return
}
hex := uint16(d[1])<<8 | uint16(d[2])
s.state.pwrPercent = int(math.Round((float64(hex) / 0x0255) * 100))
statusLog.reportTxPower(s.state.pwrPercent)
switch d[0] {
case 0x02:
hex := uint16(d[1])<<8 | uint16(d[2])
s.state.rfGainPercent = int(math.Round((float64(hex) / 0x0255) * 100))
statusLog.reportRFGain(s.state.rfGainPercent)
case 0x0a:
hex := uint16(d[1])<<8 | uint16(d[2])
s.state.pwrPercent = int(math.Round((float64(hex) / 0x0255) * 100))
statusLog.reportTxPower(s.state.pwrPercent)
}
}
func (s *civControlStruct) decodeTransmitStatus(d []byte) {
@ -367,6 +374,25 @@ func (s *civControlStruct) decPwr() error {
return nil
}
func (s *civControlStruct) setRFGain(percent int) error {
v := uint16(0x0255 * (float64(percent) / 100))
return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x02, byte(v >> 8), byte(v & 0xff), 253})
}
func (s *civControlStruct) incRFGain() error {
if s.state.rfGainPercent < 100 {
return s.setRFGain(s.state.rfGainPercent + 1)
}
return nil
}
func (s *civControlStruct) decRFGain() error {
if s.state.rfGainPercent > 0 {
return s.setRFGain(s.state.rfGainPercent - 1)
}
return nil
}
func (s *civControlStruct) getDigit(v uint, n int) byte {
f := float64(v)
for n > 0 {
@ -575,6 +601,10 @@ func (s *civControlStruct) getTS() error {
return s.st.send([]byte{254, 254, civAddress, 224, 0x10, 253})
}
func (s *civControlStruct) getRFGain() error {
return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x02, 253})
}
func (s *civControlStruct) loop() {
for {
select {
@ -624,6 +654,9 @@ func (s *civControlStruct) init(st *serialStream) error {
if err := s.getTS(); err != nil {
return err
}
if err := s.getRFGain(); err != nil {
return err
}
s.deinitNeeded = make(chan bool)
s.deinitFinished = make(chan bool)

View file

@ -24,6 +24,18 @@ func handleHotkey(k byte) {
log.Error("can't decrease power: ", err)
}
}
case '\'':
if civControl != nil {
if err := civControl.incRFGain(); err != nil {
log.Error("can't increase rf gain: ", err)
}
}
case ';':
if civControl != nil {
if err := civControl.decRFGain(); err != nil {
log.Error("can't decrease rf gain: ", err)
}
}
case ']':
if civControl != nil {
if err := civControl.incFreq(); err != nil {

View file

@ -23,6 +23,7 @@ type statusLogData struct {
preamp string
vd string
txPower string
rfGain string
s string
ovf bool
ts string
@ -228,6 +229,16 @@ func (s *statusLogStruct) reportTxPower(percent int) {
s.data.txPower = fmt.Sprint(percent, "%")
}
func (s *statusLogStruct) reportRFGain(percent int) {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.data == nil {
return
}
s.data.rfGain = fmt.Sprint(percent, "%")
}
func (s *statusLogStruct) clearInternal() {
fmt.Printf("%c[2K", 27)
}
@ -266,7 +277,11 @@ func (s *statusLogStruct) update() {
if s.data.ovf {
ovfStr = " " + s.preGenerated.ovf
}
s.data.line1 = fmt.Sprint(s.data.s, ovfStr)
var rfGainStr string
if s.data.rfGain != "" {
rfGainStr = " rfg " + s.data.rfGain
}
s.data.line1 = fmt.Sprint(s.data.s, ovfStr, rfGainStr)
var tsStr string
if s.data.ts != "" {