Read and display Vd voltage

This commit is contained in:
Nonoo 2020-11-03 16:35:23 +01:00
parent 8422814eb0
commit 7ce8b9e347
4 changed files with 56 additions and 3 deletions

View file

@ -87,7 +87,7 @@ is up) with the following info:
- First status bar line: - First status bar line:
- `state`: RX/TX/TUNE depending on the PTT status - `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) preamp (PAMP0 means the preamp is off), Vd voltage
- `txpwr`: current transmit power setting in percent - `txpwr`: current transmit power setting in percent
- `audiomon`: current status of the audio monitor (see the *Hotkeys* section - `audiomon`: current status of the audio monitor (see the *Hotkeys* section
in this README for more information about this feature) in this README for more information about this feature)

View file

@ -6,6 +6,7 @@ import (
) )
const civAddress = 0xa4 const civAddress = 0xa4
const vdReadInterval = time.Minute
type civOperatingMode struct { type civOperatingMode struct {
name string name string
@ -61,7 +62,8 @@ var civBands = []civBand{
} }
type civControlStruct struct { type civControlStruct struct {
st *serialStream st *serialStream
vdReadTimer *time.Timer
state struct { state struct {
freq uint freq uint
@ -101,6 +103,8 @@ func (s *civControlStruct) decode(d []byte) {
s.decodePower(payload) s.decodePower(payload)
case 0x1c: case 0x1c:
s.decodeTransmitStatus(payload) s.decodeTransmitStatus(payload)
case 0x15:
s.decodeVd(payload)
case 0x16: case 0x16:
s.decodePreamp(payload) s.decodePreamp(payload)
} }
@ -224,6 +228,23 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) {
statusLog.reportPTT(s.state.ptt, s.state.tune) statusLog.reportPTT(s.state.ptt, s.state.tune)
} }
func (s *civControlStruct) decodeVd(d []byte) {
if len(d) < 2 {
return
}
switch d[0] {
case 0x15:
if len(d) < 3 {
return
}
statusLog.reportVd(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 16)
s.vdReadTimer = time.AfterFunc(vdReadInterval, func() {
_ = s.getVd()
})
}
}
func (s *civControlStruct) decodePreamp(d []byte) { func (s *civControlStruct) decodePreamp(d []byte) {
if len(d) < 2 { if len(d) < 2 {
return return
@ -427,6 +448,10 @@ func (s *civControlStruct) getTransmitStatus() error {
return s.st.send([]byte{254, 254, civAddress, 224, 0x1c, 1, 253}) return s.st.send([]byte{254, 254, civAddress, 224, 0x1c, 1, 253})
} }
func (s *civControlStruct) getVd() error {
return s.st.send([]byte{254, 254, civAddress, 224, 0x15, 0x15, 253})
}
func (s *civControlStruct) init(st *serialStream) error { func (s *civControlStruct) init(st *serialStream) error {
s.st = st s.st = st
@ -450,5 +475,15 @@ func (s *civControlStruct) init(st *serialStream) error {
if err := s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x02, 253}); err != nil { if err := s.st.send([]byte{254, 254, civAddress, 224, 0x16, 0x02, 253}); err != nil {
return err return err
} }
if err := s.getVd(); err != nil {
return err
}
return nil return nil
} }
func (s *civControlStruct) deinit(st *serialStream) {
if s.vdReadTimer != nil {
s.vdReadTimer.Stop()
s.vdReadTimer = nil
}
}

View file

@ -270,6 +270,9 @@ func (s *serialStream) deinit() {
s.deinitNeededChan <- true s.deinitNeededChan <- true
<-s.deinitFinishedChan <-s.deinitFinishedChan
} }
if civControl != nil {
civControl.deinit()
}
civControl = nil civControl = nil
s.common.deinit() s.common.deinit()
s.rxSeqBuf.deinit() s.rxSeqBuf.deinit()

View file

@ -20,6 +20,7 @@ type statusLogData struct {
dataMode string dataMode string
filter string filter string
preamp string preamp string
vd string
txPowerStr string txPowerStr string
startTime time.Time startTime time.Time
@ -144,6 +145,16 @@ func (s *statusLogStruct) reportPreamp(preamp int) {
s.data.preamp = fmt.Sprint("PAMP", preamp) s.data.preamp = fmt.Sprint("PAMP", preamp)
} }
func (s *statusLogStruct) reportVd(voltage float64) {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.data == nil {
return
}
s.data.vd = fmt.Sprintf("%.1fV", voltage)
}
func (s *statusLogStruct) reportPTT(ptt, tune bool) { func (s *statusLogStruct) reportPTT(ptt, tune bool) {
s.mutex.Lock() s.mutex.Lock()
defer s.mutex.Unlock() defer s.mutex.Unlock()
@ -214,12 +225,16 @@ func (s *statusLogStruct) update() {
if s.data.preamp != "" { if s.data.preamp != "" {
preampStr = " " + s.data.preamp preampStr = " " + s.data.preamp
} }
var vdStr string
if s.data.vd != "" {
vdStr = " " + s.data.vd
}
var txPowerStr string var txPowerStr string
if s.data.txPowerStr != "" { if s.data.txPowerStr != "" {
txPowerStr = " txpwr " + 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), s.data.line1 = fmt.Sprint("state ", s.data.stateStr, " freq: ", fmt.Sprintf("%.6f", float64(s.data.frequency)/1000000),
modeStr, filterStr, preampStr, txPowerStr, " audio ", s.data.audioStateStr) modeStr, filterStr, preampStr, vdStr, txPowerStr, " audio ", s.data.audioStateStr)
up, down, lost, retransmits := netstat.get() up, down, lost, retransmits := netstat.get()
lostStr := "0" lostStr := "0"