diff --git a/civdecoder.go b/civdecoder.go index f3e7726..2c14651 100644 --- a/civdecoder.go +++ b/civdecoder.go @@ -23,6 +23,8 @@ func (s *civDecoderStruct) decode(d []byte) { s.decodeFreq(payload) case 0x04: s.decodeMode(payload) + case 0x14: + s.decodePower(payload) case 0x1c: s.decodePTT(payload) } @@ -85,6 +87,17 @@ func (s *civDecoderStruct) decodeMode(d []byte) { statusLog.reportMode(mode, filter) } +func (s *civDecoderStruct) decodePower(d []byte) { + if len(d) < 3 || d[0] != 0x0a { + return + } + + hex := uint16(d[1])<<8 | uint16(d[2]) + percent := int(math.Round((float64(hex) / 0x0255) * 100)) + + statusLog.reportTxPower(percent) +} + func (s *civDecoderStruct) decodePTT(d []byte) { if len(d) < 2 { return @@ -114,6 +127,10 @@ func (s *civDecoderStruct) query(st *serialStream) error { if err := st.send([]byte{254, 254, civAddress, 224, 4, 253}); err != nil { return err } + // Querying power. + if err := st.send([]byte{254, 254, civAddress, 224, 0x14, 0x0a, 253}); err != nil { + return err + } // Querying PTT. if err := st.send([]byte{254, 254, civAddress, 224, 0x1c, 0, 253}); err != nil { return err diff --git a/statuslog.go b/statuslog.go index 3055910..9e51a45 100644 --- a/statuslog.go +++ b/statuslog.go @@ -14,10 +14,11 @@ type statusLogData struct { line1 string line2 string - stateStr string - frequency float64 - mode string - filter string + stateStr string + frequency float64 + mode string + filter string + txPowerStr string startTime time.Time rttStr string @@ -93,6 +94,16 @@ func (s *statusLogStruct) reportPTT(ptt, tune bool) { } } +func (s *statusLogStruct) reportTxPower(percent int) { + s.mutex.Lock() + defer s.mutex.Unlock() + + if s.data == nil { + return + } + s.data.txPowerStr = fmt.Sprint(percent, "%") +} + func (s *statusLogStruct) clearInternal() { fmt.Printf("%c[2K", 27) } @@ -133,8 +144,12 @@ func (s *statusLogStruct) update() { if s.data.filter != "" { filterStr = " " + s.data.filter } + var txPowerStr string + if s.data.txPowerStr != "" { + txPowerStr = " txpwr " + s.data.txPowerStr + } s.data.line1 = fmt.Sprint("state ", s.data.stateStr, " freq: ", fmt.Sprintf("%f", s.data.frequency/1000000), - modeStr, filterStr) + modeStr, filterStr, txPowerStr) up, down, lost, retransmits := netstat.get() lostStr := "0"