Filter S and OVF queries sent to the server from kappanhang

This commit is contained in:
Nonoo 2020-11-04 10:18:32 +01:00
parent 7cbe320472
commit ba29c38797
2 changed files with 40 additions and 12 deletions

View file

@ -69,6 +69,9 @@ type civControlStruct struct {
resetSReadTimer chan bool resetSReadTimer chan bool
state struct { state struct {
getSSent bool
getOVFSent bool
freq uint freq uint
ptt bool ptt bool
tune bool tune bool
@ -90,9 +93,10 @@ type civControlStruct struct {
var civControl *civControlStruct var civControl *civControlStruct
func (s *civControlStruct) decode(d []byte) { // Returns false if the message should not be forwarded to the serial port TCP server or the virtual serial port.
func (s *civControlStruct) decode(d []byte) bool {
if len(d) < 6 || d[0] != 0xfe || d[1] != 0xfe || d[len(d)-1] != 0xfd { if len(d) < 6 || d[0] != 0xfe || d[1] != 0xfe || d[len(d)-1] != 0xfd {
return return true
} }
payload := d[5 : len(d)-1] payload := d[5 : len(d)-1]
@ -109,16 +113,17 @@ func (s *civControlStruct) decode(d []byte) {
case 0x10: case 0x10:
s.decodeTS(payload) s.decodeTS(payload)
case 0x1a: case 0x1a:
s.decodeDataModeAndOVF(payload) return s.decodeDataModeAndOVF(payload)
case 0x14: case 0x14:
s.decodePowerRFGainSQLNR(payload) s.decodePowerRFGainSQLNR(payload)
case 0x1c: case 0x1c:
s.decodeTransmitStatus(payload) s.decodeTransmitStatus(payload)
case 0x15: case 0x15:
s.decodeVdAndS(payload) return s.decodeVdAndS(payload)
case 0x16: case 0x16:
s.decodePreampAndNR(payload) s.decodePreampAndNR(payload)
} }
return true
} }
func (s *civControlStruct) decodeFreq(d []byte) { func (s *civControlStruct) decodeFreq(d []byte) {
@ -222,15 +227,15 @@ func (s *civControlStruct) decodeTS(d []byte) {
statusLog.reportTS(s.state.ts) statusLog.reportTS(s.state.ts)
} }
func (s *civControlStruct) decodeDataModeAndOVF(d []byte) { func (s *civControlStruct) decodeDataModeAndOVF(d []byte) bool {
if len(d) < 2 { if len(d) < 1 {
return return true
} }
switch d[0] { switch d[0] {
case 0x06: case 0x06:
if len(d) < 3 { if len(d) < 3 {
return return true
} }
var dataMode string var dataMode string
var filter string var filter string
@ -245,12 +250,20 @@ func (s *civControlStruct) decodeDataModeAndOVF(d []byte) {
statusLog.reportDataMode(dataMode, filter) statusLog.reportDataMode(dataMode, filter)
case 0x09: case 0x09:
if len(d) < 2 {
return !s.state.getOVFSent
}
if d[1] != 0 { if d[1] != 0 {
statusLog.reportOVF(true) statusLog.reportOVF(true)
} else { } else {
statusLog.reportOVF(false) statusLog.reportOVF(false)
} }
if s.state.getOVFSent {
s.state.getOVFSent = false
return false
}
} }
return true
} }
func (s *civControlStruct) decodePowerRFGainSQLNR(d []byte) { func (s *civControlStruct) decodePowerRFGainSQLNR(d []byte) {
@ -311,13 +324,16 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) {
statusLog.reportPTT(s.state.ptt, s.state.tune) statusLog.reportPTT(s.state.ptt, s.state.tune)
} }
func (s *civControlStruct) decodeVdAndS(d []byte) { func (s *civControlStruct) decodeVdAndS(d []byte) bool {
if len(d) < 3 { if len(d) < 1 {
return return true
} }
switch d[0] { switch d[0] {
case 0x02: case 0x02:
if len(d) < 3 {
return !s.state.getSSent
}
sValue := (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" sStr := "S"
if sValue <= 9 { if sValue <= 9 {
@ -349,9 +365,17 @@ func (s *civControlStruct) decodeVdAndS(d []byte) {
} }
} }
statusLog.reportS(sStr) statusLog.reportS(sStr)
if s.state.getSSent {
s.state.getSSent = false
return false
}
case 0x15: case 0x15:
if len(d) < 3 {
return true
}
statusLog.reportVd(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 16) statusLog.reportVd(((float64(int(d[1])<<8) + float64(d[2])) / 0x0241) * 16)
} }
return true
} }
func (s *civControlStruct) decodePreampAndNR(d []byte) { func (s *civControlStruct) decodePreampAndNR(d []byte) {
@ -654,10 +678,12 @@ func (s *civControlStruct) getVd() error {
} }
func (s *civControlStruct) getS() error { func (s *civControlStruct) getS() error {
s.state.getSSent = true
return s.st.send([]byte{254, 254, civAddress, 224, 0x15, 0x02, 253}) return s.st.send([]byte{254, 254, civAddress, 224, 0x15, 0x02, 253})
} }
func (s *civControlStruct) getOVF() error { func (s *civControlStruct) getOVF() error {
s.state.getOVFSent = true
return s.st.send([]byte{254, 254, civAddress, 224, 0x1a, 0x09, 253}) return s.st.send([]byte{254, 254, civAddress, 224, 0x1a, 0x09, 253})
} }

View file

@ -92,7 +92,9 @@ func (s *serialStream) handleRxSeqBufEntry(e seqBufEntry) {
e.data = e.data[21:] e.data = e.data[21:]
civControl.decode(e.data) if !civControl.decode(e.data) {
return
}
if serialPort.write != nil { if serialPort.write != nil {
serialPort.write <- e.data serialPort.write <- e.data