diff --git a/README.md b/README.md index a745f64..166637c 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ is up) with the following info: - `rfg`: RF gain in percent - `sql`: squelch level in percent - `nr`: noise reduction level in percent + - `audio`: current status of the audio monitor (see the *Hotkeys* section + in this README for more information about this feature) - Second status bar line: - `state`: RX/TX/TUNE depending on the PTT status @@ -100,8 +102,7 @@ is up) with the following info: - `preamp`: PAMP0 means the preamp is off - `voltage`: Vd voltage, updated when a TX/TUNE is over - `txpwr`: current transmit power setting in percent - - `audio`: current status of the audio monitor (see the *Hotkeys* section - in this README for more information about this feature) + - `swr`: reported SWR, it seems that the Icom IC-705 always reports 0.0 - Third status bar line: - `up`: how long the audio/serial connection is active diff --git a/civcontrol.go b/civcontrol.go index f7f9e14..badd55c 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -71,6 +71,7 @@ type civControlStruct struct { state struct { getSSent bool getOVFSent bool + getSWRSent bool freq uint ptt bool @@ -119,7 +120,7 @@ func (s *civControlStruct) decode(d []byte) bool { case 0x1c: s.decodeTransmitStatus(payload) case 0x15: - return s.decodeVdAndS(payload) + return s.decodeVdSWRS(payload) case 0x16: s.decodePreampAndNR(payload) } @@ -324,7 +325,7 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) { statusLog.reportPTT(s.state.ptt, s.state.tune) } -func (s *civControlStruct) decodeVdAndS(d []byte) bool { +func (s *civControlStruct) decodeVdSWRS(d []byte) bool { if len(d) < 1 { return true } @@ -369,6 +370,15 @@ func (s *civControlStruct) decodeVdAndS(d []byte) bool { s.state.getSSent = false return false } + case 0x12: + if len(d) < 3 { + return !s.state.getSWRSent + } + statusLog.reportSWR(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 16) + if s.state.getSWRSent { + s.state.getSWRSent = false + return false + } case 0x15: if len(d) < 3 { return true @@ -687,6 +697,11 @@ func (s *civControlStruct) getOVF() error { return s.st.send([]byte{254, 254, civAddress, 224, 0x1a, 0x09, 253}) } +func (s *civControlStruct) getSWR() error { + s.state.getSWRSent = true + return s.st.send([]byte{254, 254, civAddress, 224, 0x15, 0x12, 253}) +} + func (s *civControlStruct) getTS() error { return s.st.send([]byte{254, 254, civAddress, 224, 0x10, 253}) } @@ -716,6 +731,7 @@ func (s *civControlStruct) loop() { case <-time.After(sReadInterval): _ = s.getS() _ = s.getOVF() + _ = s.getSWR() case <-s.resetSReadTimer: } } @@ -753,6 +769,9 @@ func (s *civControlStruct) init(st *serialStream) error { if err := s.getOVF(); err != nil { return err } + if err := s.getSWR(); err != nil { + return err + } if err := s.getTS(); err != nil { return err } diff --git a/statuslog.go b/statuslog.go index 9e1ef61..b2b3422 100644 --- a/statuslog.go +++ b/statuslog.go @@ -29,6 +29,7 @@ type statusLogData struct { nrEnabled bool s string ovf bool + swr string ts string startTime time.Time @@ -195,6 +196,16 @@ func (s *statusLogStruct) reportOVF(ovf bool) { s.data.ovf = ovf } +func (s *statusLogStruct) reportSWR(swr float64) { + s.mutex.Lock() + defer s.mutex.Unlock() + + if s.data == nil { + return + } + s.data.swr = fmt.Sprintf("%.1f", swr) +} + func (s *statusLogStruct) reportTS(ts uint) { s.mutex.Lock() defer s.mutex.Unlock() @@ -327,7 +338,7 @@ func (s *statusLogStruct) update() { nrStr += "-" } } - s.data.line1 = fmt.Sprint(s.data.s, ovfStr, rfGainStr, sqlStr, nrStr) + s.data.line1 = fmt.Sprint(s.data.s, ovfStr, rfGainStr, sqlStr, nrStr, " audio ", s.data.audioStateStr) var tsStr string if s.data.ts != "" { @@ -353,8 +364,12 @@ func (s *statusLogStruct) update() { if s.data.txPower != "" { txPowerStr = " txpwr " + s.data.txPower } + var swrStr string + if s.data.swr != "" { + 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, " audio ", s.data.audioStateStr) + tsStr, modeStr, filterStr, preampStr, vdStr, txPowerStr, swrStr) up, down, lost, retransmits := netstat.get() lostStr := "0"