Error checking - mostly to avoid crashes on short reads.

pull/35/head
Christopher Young 2015-09-05 13:02:06 -04:00
rodzic 5264985278
commit cb0140a946
1 zmienionych plików z 9 dodań i 3 usunięć

Wyświetl plik

@ -347,6 +347,11 @@ func parseInput(buf string) ([]byte, uint16) {
return nil, 0 return nil, 0
} }
msgtype := uint16(0) msgtype := uint16(0)
isUplink := false
if s[0] == '+' {
isUplink = true
}
if s[0] == '-' { if s[0] == '-' {
parseDownlinkReport(s) parseDownlinkReport(s)
@ -377,13 +382,14 @@ func parseInput(buf string) ([]byte, uint16) {
frame := make([]byte, UPLINK_FRAME_DATA_BYTES) frame := make([]byte, UPLINK_FRAME_DATA_BYTES)
hex.Decode(frame, []byte(s)) hex.Decode(frame, []byte(s))
pos := 10
var thisMsg msg var thisMsg msg
thisMsg.MessageClass = MSGCLASS_UAT thisMsg.MessageClass = MSGCLASS_UAT
thisMsg.TimeReceived = time.Now() thisMsg.TimeReceived = time.Now()
thisMsg.Data = frame thisMsg.Data = frame
thisMsg.Product = ((uint32(frame[pos]) & 0x1f) << 6) | (uint32(frame[pos+1]) >> 2) thisMsg.Product = 9999
if isUplink && msgtype == MSGTYPE_UPLINK && len(x) > 11 { //FIXME: Need to pull out FIS-B frames from within the uplink packet.
thisMsg.Product = ((uint32(frame[10]) & 0x1f) << 6) | (uint32(frame[11]) >> 2)
}
MsgLog = append(MsgLog, thisMsg) MsgLog = append(MsgLog, thisMsg)
return frame, msgtype return frame, msgtype