Move S value calculation

This commit is contained in:
Nonoo 2020-11-03 22:06:51 +01:00
parent 9087140130
commit 3c331eac47
2 changed files with 18 additions and 16 deletions

View file

@ -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)
}

View file

@ -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) {