Error checking on OwnshipModeS.

pull/81/head
Christopher Young 2015-10-10 16:02:09 -04:00
rodzic a6f302dc13
commit 8769ced73e
2 zmienionych plików z 18 dodań i 8 usunięć

Wyświetl plik

@ -178,9 +178,16 @@ func makeOwnshipReport() bool {
msg[1] = 0x01 // Alert status, address type.
code, _ := hex.DecodeString(globalSettings.OwnshipModeS)
msg[2] = code[0] // Mode S address.
msg[3] = code[1] // Mode S address.
msg[4] = code[2] // Mode S address.
if len(code) != 3 {
// Reserved dummy code.
msg[2] = 0xF0
msg[3] = 0x00
msg[4] = 0x00
} else {
msg[2] = code[0] // Mode S address.
msg[3] = code[1] // Mode S address.
msg[4] = code[2] // Mode S address.
}
tmp := makeLatLng(mySituation.Lat)
msg[5] = tmp[0] // Latitude.

Wyświetl plik

@ -177,14 +177,17 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
if len(val.(string)) > 6 { // Too long.
continue
}
// Pad string, must be 6 characters long.
vals := strings.ToUpper(val.(string))
hexn, _ := hex.DecodeString(vals)
hexs := strings.ToUpper(hex.EncodeToString(hexn))
if vals != hexs { // Number not valid.
log.Printf("handleSettingsSetRequest:OwnshipModeS: %s != %s\n", vals, hexs)
for len(vals) < 6 {
vals = "0" + vals
}
hexn, err := hex.DecodeString(vals)
if err != nil { // Number not valid.
log.Printf("handleSettingsSetRequest:OwnshipModeS: %s\n", err.Error())
continue
}
globalSettings.OwnshipModeS = vals
globalSettings.OwnshipModeS = fmt.Sprintf("%02X%02X%02X", hexn[0], hexn[1], hexn[2])
default:
log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key)
}