mirror of
https://github.com/nonoo/kappanhang.git
synced 2025-12-06 08:02:00 +01:00
Add RF gain display/adjustment
This commit is contained in:
parent
ab19ba4211
commit
3075cf3896
|
|
@ -87,6 +87,7 @@ is up) with the following info:
|
||||||
- First status bar line:
|
- First status bar line:
|
||||||
- `S meter`: periodically refreshed S meter value, OVF is displayed on
|
- `S meter`: periodically refreshed S meter value, OVF is displayed on
|
||||||
overflow
|
overflow
|
||||||
|
- `rfg`: RF gain in percent
|
||||||
|
|
||||||
- Second status bar line:
|
- Second status bar line:
|
||||||
- `state`: RX/TX/TUNE depending on the PTT status
|
- `state`: RX/TX/TUNE depending on the PTT status
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ type civControlStruct struct {
|
||||||
ptt bool
|
ptt bool
|
||||||
tune bool
|
tune bool
|
||||||
pwrPercent int
|
pwrPercent int
|
||||||
|
rfGainPercent int
|
||||||
operatingModeIdx int
|
operatingModeIdx int
|
||||||
filterIdx int
|
filterIdx int
|
||||||
dataMode bool
|
dataMode bool
|
||||||
|
|
@ -107,7 +108,7 @@ func (s *civControlStruct) decode(d []byte) {
|
||||||
case 0x1a:
|
case 0x1a:
|
||||||
s.decodeDataModeAndOVF(payload)
|
s.decodeDataModeAndOVF(payload)
|
||||||
case 0x14:
|
case 0x14:
|
||||||
s.decodePower(payload)
|
s.decodePowerAndRFGain(payload)
|
||||||
case 0x1c:
|
case 0x1c:
|
||||||
s.decodeTransmitStatus(payload)
|
s.decodeTransmitStatus(payload)
|
||||||
case 0x15:
|
case 0x15:
|
||||||
|
|
@ -249,15 +250,21 @@ func (s *civControlStruct) decodeDataModeAndOVF(d []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *civControlStruct) decodePower(d []byte) {
|
func (s *civControlStruct) decodePowerAndRFGain(d []byte) {
|
||||||
if len(d) < 3 || d[0] != 0x0a {
|
if len(d) < 3 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hex := uint16(d[1])<<8 | uint16(d[2])
|
switch d[0] {
|
||||||
s.state.pwrPercent = int(math.Round((float64(hex) / 0x0255) * 100))
|
case 0x02:
|
||||||
|
hex := uint16(d[1])<<8 | uint16(d[2])
|
||||||
statusLog.reportTxPower(s.state.pwrPercent)
|
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) {
|
func (s *civControlStruct) decodeTransmitStatus(d []byte) {
|
||||||
|
|
@ -367,6 +374,25 @@ func (s *civControlStruct) decPwr() error {
|
||||||
return nil
|
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 {
|
func (s *civControlStruct) getDigit(v uint, n int) byte {
|
||||||
f := float64(v)
|
f := float64(v)
|
||||||
for n > 0 {
|
for n > 0 {
|
||||||
|
|
@ -575,6 +601,10 @@ func (s *civControlStruct) getTS() error {
|
||||||
return s.st.send([]byte{254, 254, civAddress, 224, 0x10, 253})
|
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() {
|
func (s *civControlStruct) loop() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
@ -624,6 +654,9 @@ func (s *civControlStruct) init(st *serialStream) error {
|
||||||
if err := s.getTS(); err != nil {
|
if err := s.getTS(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := s.getRFGain(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
s.deinitNeeded = make(chan bool)
|
s.deinitNeeded = make(chan bool)
|
||||||
s.deinitFinished = make(chan bool)
|
s.deinitFinished = make(chan bool)
|
||||||
|
|
|
||||||
12
hotkeys.go
12
hotkeys.go
|
|
@ -24,6 +24,18 @@ func handleHotkey(k byte) {
|
||||||
log.Error("can't decrease power: ", err)
|
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 ']':
|
case ']':
|
||||||
if civControl != nil {
|
if civControl != nil {
|
||||||
if err := civControl.incFreq(); err != nil {
|
if err := civControl.incFreq(); err != nil {
|
||||||
|
|
|
||||||
17
statuslog.go
17
statuslog.go
|
|
@ -23,6 +23,7 @@ type statusLogData struct {
|
||||||
preamp string
|
preamp string
|
||||||
vd string
|
vd string
|
||||||
txPower string
|
txPower string
|
||||||
|
rfGain string
|
||||||
s string
|
s string
|
||||||
ovf bool
|
ovf bool
|
||||||
ts string
|
ts string
|
||||||
|
|
@ -228,6 +229,16 @@ func (s *statusLogStruct) reportTxPower(percent int) {
|
||||||
s.data.txPower = fmt.Sprint(percent, "%")
|
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() {
|
func (s *statusLogStruct) clearInternal() {
|
||||||
fmt.Printf("%c[2K", 27)
|
fmt.Printf("%c[2K", 27)
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +277,11 @@ func (s *statusLogStruct) update() {
|
||||||
if s.data.ovf {
|
if s.data.ovf {
|
||||||
ovfStr = " " + s.preGenerated.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
|
var tsStr string
|
||||||
if s.data.ts != "" {
|
if s.data.ts != "" {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue