Add signal strength and timestamp parsing.

pull/750/head
cyoung 2018-05-01 13:41:31 -04:00
rodzic b9ac1a394a
commit d8a9d5c1a3
1 zmienionych plików z 16 dodań i 4 usunięć

Wyświetl plik

@ -66,7 +66,7 @@ func radioSerialPortReader() {
for i := 0; i < bufLen-6; i++ {
if (buf[i] == radioMagic[0]) && (buf[i+1] == radioMagic[1]) && (buf[i+2] == radioMagic[2]) && (buf[i+3] == radioMagic[3]) {
// Found the magic sequence. Get the length.
msgLen := int(uint16(buf[i+4]) + (uint16(buf[i+5]) << 8))
msgLen := int(uint16(buf[i+4])+(uint16(buf[i+5])<<8)) + 5 // 5 bytes for RSSI and TS.
// Check if we've read enough to finish this message.
if bufLen < i+6+msgLen {
break // Wait for more of the message to come in.
@ -91,13 +91,25 @@ func radioSerialPortReader() {
func processRadioMessage(msg []byte) {
log.Printf("processRadioMessage(): %d %s\n", len(msg), hex.EncodeToString(msg))
// RSSI and message timestamp are prepended to the actual packet.
// RSSI
rssiRaw := int8(msg[0])
rssiAdjusted := int16(rssiRaw) - 132 // -132 dBm, calculated minimum RSSI.
rssiDump978 := int16(1000 * (10 ^ (float64(rssiAdjusted) / 20)))
_ := uint32(msg[1]) + (uint32(msg[2]) << 8) + (uint32(msg[3]) << 16) + (uint32(msg[4]) << 24) // Timestamp. Currently unused.
msg = msg[5:]
var toRelay string
switch len(msg) {
case 552:
to := make([]byte, 552)
var rs_errors int
i := int(C.correct_uplink_frame((*C.uint8_t)(unsafe.Pointer(&msg[0])), (*C.uint8_t)(unsafe.Pointer(&to[0])), (*C.int)(unsafe.Pointer(&rs_errors))))
toRelay = "+" + hex.EncodeToString(to[:432]) + ";"
toRelay = fmt.Sprintf("+%s;ss=%d;", hex.EncodeToString(to[:432]), rssiDump978)
log.Printf("i=%d, rs_errors=%d, msg=%s\n", i, rs_errors, toRelay)
case 48:
to := make([]byte, 48)
@ -106,11 +118,11 @@ func processRadioMessage(msg []byte) {
i := int(C.correct_adsb_frame((*C.uint8_t)(unsafe.Pointer(&to[0])), (*C.int)(unsafe.Pointer(&rs_errors))))
if i == 1 {
// Short ADS-B frame.
toRelay = "-" + hex.EncodeToString(to[:18]) + ";"
toRelay = fmt.Sprintf("-%s;ss=%d;", hex.EncodeToString(to[:18]), rssiDump978)
log.Printf("i=%d, rs_errors=%d, msg=%s\n", i, rs_errors, toRelay)
} else if i == 2 {
// Long ADS-B frame.
toRelay = "-" + hex.EncodeToString(to[:34]) + ";"
toRelay = fmt.Sprintf("-%s;ss=%d;", hex.EncodeToString(to[:34]), rssiDump978)
log.Printf("i=%d, rs_errors=%d, msg=%s\n", i, rs_errors, toRelay)
} else {
log.Printf("i=%d, rs_errors=%d, msg=%s\n", i, rs_errors, hex.EncodeToString(to))