+ try {
+ version = get_int(hexfile, ao_romconfig_version, 2);
+ check = get_int(hexfile, ao_romconfig_check, 2);
+ if (check == (~version & 0xffff)) {
+ switch (version) {
+ case 2:
+ case 1:
+ serial_number = get_int(hexfile, ao_serial_number, 2);
+ try {
+ radio_calibration = get_int(hexfile, ao_radio_cal, 4);
+ } catch (AltosNoSymbol missing) {
+ radio_calibration = 0;
+ }
+
+ valid = true;
+
+ /* XXX TeleBT v4.0 units originally shipped without RF calibration programmed. Go fetch
+ * the correct value from the web site
+ */
+ if (serial_number == 2584 ||
+ (3686 <= serial_number && serial_number <= 3938 && radio_calibration == 5695485))
+ {
+ fetch_radio_cal();
+ }
+
+ break;
+ }
+ }
+ usb_id = hexfile.find_usb_id();
+ usb_product = hexfile.find_usb_product();
+
+ } catch (AltosNoSymbol missing) {
+ valid = false;
+ }
+ }
+
+ private final static String[] fetch_names = {
+ ao_romconfig_version,
+ ao_romconfig_check,
+ ao_serial_number,
+ ao_radio_cal,
+ ao_usb_descriptors,
+ };
+
+ private static int fetch_len(String name) {
+ if (name.equals(ao_usb_descriptors))
+ return 256;
+ return 2;
+ }
+
+ private final static String[] required_names = {
+ ao_romconfig_version,
+ ao_romconfig_check,
+ ao_serial_number
+ };
+
+ private static boolean name_required(String name) {
+ for (String required : required_names)
+ if (name.equals(required))
+ return true;
+ return false;