diff --git a/civcontrol.go b/civcontrol.go index e727bff..8a45d73 100644 --- a/civcontrol.go +++ b/civcontrol.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "math" "time" ) @@ -243,7 +244,21 @@ func (s *civControlStruct) decodeVdAndS(d []byte) { switch d[0] { case 0x02: - statusLog.reportS(int(math.Round(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 18))) + sValue := (int(math.Round(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 18))) + sStr := "S" + if sValue <= 9 { + sStr += fmt.Sprint(sValue) + } else { + sStr += "9+" + + if sValue > 18 { + sStr += "60" + } else { + dB := (float64((sValue - 9)) / 9) * 60 + sStr += fmt.Sprint(int(math.Round(dB/10) * 10)) + } + } + statusLog.reportS(sStr) case 0x15: statusLog.reportVd(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 16) } diff --git a/statuslog.go b/statuslog.go index c624041..49251b8 100644 --- a/statuslog.go +++ b/statuslog.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "math" "os" "sync" "time" @@ -157,26 +156,14 @@ func (s *statusLogStruct) reportVd(voltage float64) { s.data.vd = fmt.Sprintf("%.1fV", voltage) } -func (s *statusLogStruct) reportS(sValue int) { +func (s *statusLogStruct) reportS(sValue string) { s.mutex.Lock() defer s.mutex.Unlock() if s.data == nil { return } - s.data.s = "S" - if sValue <= 9 { - s.data.s += fmt.Sprint(sValue) - } else { - s.data.s += "9+" - - if sValue > 18 { - s.data.s += "60" - } else { - dB := (float64((sValue - 9)) / 9) * 60 - s.data.s += fmt.Sprint(int(math.Round(dB/10) * 10)) - } - } + s.data.s = sValue } func (s *statusLogStruct) reportPTT(ptt, tune bool) {