- public AltosRomconfig(byte[] bytes, int offset) {
- version = get_int(bytes, offset + 0, 2);
- check = get_int(bytes, offset + 2, 2);
- if (check == (~version & 0xffff)) {
- switch (version) {
- case 2:
- case 1:
- serial_number = get_int(bytes, offset + 4, 2);
- radio_calibration = get_int(bytes, offset + 6, 4);
- valid = true;
- break;
+ final static String ao_romconfig_version = "ao_romconfig_version";
+ final static String ao_romconfig_check = "ao_romconfig_check";
+ final static String ao_serial_number = "ao_serial_number";
+ final static String ao_radio_cal = "ao_radio_cal";
+ final static String ao_usb_descriptors = "ao_usb_descriptors";
+
+ public AltosRomconfig(AltosHexfile hexfile) {
+ 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;
+ 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;
+ }
+
+ public static long fetch_base(AltosHexfile hexfile) throws AltosNoSymbol {
+ long base = 0xffffffffL;
+ for (String name : fetch_names) {
+ try {
+ int len = fetch_len(name);
+ long addr = find_address(hexfile, name, len);
+
+ if (addr < base)
+ base = addr;
+ } catch (AltosNoSymbol ns) {
+ if (name_required(name))
+ throw (ns);