diff --git a/README.md b/README.md index 80de8af..b164053 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ 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, - preamp (PAMP0 means the preamp is off) + preamp (PAMP0 means the preamp is off), Vd voltage - `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) diff --git a/civcontrol.go b/civcontrol.go index b9bfe0a..4850bd9 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -6,6 +6,7 @@ import ( ) const civAddress = 0xa4 +const vdReadInterval = time.Minute type civOperatingMode struct { name string @@ -61,7 +62,8 @@ var civBands = []civBand{ } type civControlStruct struct { - st *serialStream + st *serialStream + vdReadTimer *time.Timer state struct { freq uint @@ -101,6 +103,8 @@ func (s *civControlStruct) decode(d []byte) { s.decodePower(payload) case 0x1c: s.decodeTransmitStatus(payload) + case 0x15: + s.decodeVd(payload) case 0x16: s.decodePreamp(payload) } @@ -224,6 +228,23 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) { 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) { if len(d) < 2 { return @@ -427,6 +448,10 @@ func (s *civControlStruct) getTransmitStatus() error { 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 { 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 { return err } + if err := s.getVd(); err != nil { + return err + } return nil } + +func (s *civControlStruct) deinit(st *serialStream) { + if s.vdReadTimer != nil { + s.vdReadTimer.Stop() + s.vdReadTimer = nil + } +} diff --git a/serialstream.go b/serialstream.go index 5ce4806..2a0a7dc 100644 --- a/serialstream.go +++ b/serialstream.go @@ -270,6 +270,9 @@ func (s *serialStream) deinit() { s.deinitNeededChan <- true <-s.deinitFinishedChan } + if civControl != nil { + civControl.deinit() + } civControl = nil s.common.deinit() s.rxSeqBuf.deinit() diff --git a/statuslog.go b/statuslog.go index 6143154..4ff52ce 100644 --- a/statuslog.go +++ b/statuslog.go @@ -20,6 +20,7 @@ type statusLogData struct { dataMode string filter string preamp string + vd string txPowerStr string startTime time.Time @@ -144,6 +145,16 @@ func (s *statusLogStruct) reportPreamp(preamp int) { 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) { s.mutex.Lock() defer s.mutex.Unlock() @@ -214,12 +225,16 @@ func (s *statusLogStruct) update() { if s.data.preamp != "" { preampStr = " " + s.data.preamp } + var vdStr string + if s.data.vd != "" { + vdStr = " " + s.data.vd + } 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, preampStr, txPowerStr, " audio ", s.data.audioStateStr) + modeStr, filterStr, preampStr, vdStr, txPowerStr, " audio ", s.data.audioStateStr) up, down, lost, retransmits := netstat.get() lostStr := "0"