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. msg[1] = 0x01 // Alert status, address type.
code, _ := hex.DecodeString(globalSettings.OwnshipModeS) code, _ := hex.DecodeString(globalSettings.OwnshipModeS)
msg[2] = code[0] // Mode S address. if len(code) != 3 {
msg[3] = code[1] // Mode S address. // Reserved dummy code.
msg[4] = code[2] // Mode S address. 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) tmp := makeLatLng(mySituation.Lat)
msg[5] = tmp[0] // Latitude. 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. if len(val.(string)) > 6 { // Too long.
continue continue
} }
// Pad string, must be 6 characters long.
vals := strings.ToUpper(val.(string)) vals := strings.ToUpper(val.(string))
hexn, _ := hex.DecodeString(vals) for len(vals) < 6 {
hexs := strings.ToUpper(hex.EncodeToString(hexn)) vals = "0" + vals
if vals != hexs { // Number not valid. }
log.Printf("handleSettingsSetRequest:OwnshipModeS: %s != %s\n", vals, hexs) hexn, err := hex.DecodeString(vals)
if err != nil { // Number not valid.
log.Printf("handleSettingsSetRequest:OwnshipModeS: %s\n", err.Error())
continue continue
} }
globalSettings.OwnshipModeS = vals globalSettings.OwnshipModeS = fmt.Sprintf("%02X%02X%02X", hexn[0], hexn[1], hexn[2])
default: default:
log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key) log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key)
} }