rom_config = romconfig;
}
- public AltosRomconfig target_romconfig() throws InterruptedException {
+ public AltosRomconfig target_romconfig(AltosUsbId usb_id, String usb_product) throws InterruptedException {
if (!check_rom_config())
return null;
+ if (rom_config.usb_id == null)
+ rom_config.usb_id = usb_id;
+ if (rom_config.usb_product == null)
+ rom_config.usb_product = usb_product;
return rom_config;
}
final static long invalid_addr = 0xffffffff;
+ public String toString() {
+ return String.format("%s:0x%x", name, address);
+ }
+
public AltosHexsym(String name, long address) {
this.name = name;
this.address = address;
}
-}
\ No newline at end of file
+}
abstract public void abort();
- abstract public AltosRomconfig target_romconfig() throws InterruptedException;
+ abstract public AltosRomconfig target_romconfig(AltosUsbId usb_id, String usb_product) throws InterruptedException;
abstract public AltosRomconfig image_romconfig();
throw new IOException("writing new rom config failed\n");
}
+ public String toString() {
+ return String.format("valid %b version %d serial %d radio %d usb %04x:%04x %s",
+ valid, version, serial_number, radio_calibration,
+ usb_id == null ? 0 : usb_id.vid,
+ usb_id == null ? 0 : usb_id.pid,
+ usb_product == null ? "unknown" : usb_product);
+ }
+
public AltosRomconfig(int in_serial_number, int in_radio_calibration) {
valid = true;
version = 1;
}
public boolean valid() {
- return valid && serial_number != 0;
+ return valid;
}
public AltosRomconfig() {
rom_config = romconfig;
}
- public AltosRomconfig target_romconfig() throws InterruptedException {
+ public AltosRomconfig target_romconfig(AltosUsbId usb_id, String usb_product) throws InterruptedException {
if (!check_rom_config())
return null;
+ if (rom_config.usb_id == null)
+ rom_config.usb_id = usb_id;
+ if (rom_config.usb_product == null)
+ rom_config.usb_product = usb_product;
return rom_config;
}
public class AltosDeviceUIDialog extends AltosDeviceDialog {
+ boolean include_bluetooth;
+
public AltosDevice[] devices() {
java.util.List<AltosDevice> usb_devices = AltosUSBDevice.list(product);
int num_devices = usb_devices.size();
- java.util.List<AltosDevice> bt_devices = AltosBTKnown.bt_known().list(product);
- num_devices += bt_devices.size();
+
+ java.util.List<AltosDevice> bt_devices = null;
+
+ if (include_bluetooth) {
+ bt_devices = AltosBTKnown.bt_known().list(product);
+ num_devices += bt_devices.size();
+ }
+
AltosDevice[] devices = new AltosDevice[num_devices];
for (int i = 0; i < usb_devices.size(); i++)
devices[i] = usb_devices.get(i);
- int off = usb_devices.size();
- for (int j = 0; j < bt_devices.size(); j++)
- devices[off + j] = bt_devices.get(j);
+ if (include_bluetooth) {
+ int off = usb_devices.size();
+ for (int j = 0; j < bt_devices.size(); j++)
+ devices[off + j] = bt_devices.get(j);
+ }
return devices;
}
public void add_bluetooth() {
- JButton manage_bluetooth_button = new JButton("Manage Bluetooth");
- manage_bluetooth_button.setActionCommand("manage");
- manage_bluetooth_button.addActionListener(this);
- buttonPane.add(manage_bluetooth_button);
- buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+ if (include_bluetooth) {
+ JButton manage_bluetooth_button = new JButton("Manage Bluetooth");
+ manage_bluetooth_button.setActionCommand("manage");
+ manage_bluetooth_button.addActionListener(this);
+ buttonPane.add(manage_bluetooth_button);
+ buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+ }
}
public void actionPerformed(ActionEvent e) {
}
}
- public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) {
+ public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product, boolean include_bluetooth) {
super(in_frame, location, in_product);
+ this.include_bluetooth = include_bluetooth;
}
- public static AltosDevice show (Component frameComp, int product) {
+ public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) {
+ this(in_frame, location, in_product, true);
+ }
+
+ public static AltosDevice show (Component frameComp, int product, boolean include_bluetooth) {
Frame frame = JOptionPane.getFrameForComponent(frameComp);
AltosDeviceUIDialog dialog;
- dialog = new AltosDeviceUIDialog(frame, frameComp, product);
+ dialog = new AltosDeviceUIDialog(frame, frameComp, product, include_bluetooth);
dialog.setVisible(true);
return dialog.getValue();
}
+
+ public static AltosDevice show (Component frameComp, int product) {
+ return show(frameComp, product, true);
+ }
+
+ public static AltosUSBDevice show_usb (Component frameComp, int product) {
+ return (AltosUSBDevice) show(frameComp, product, false);
+ }
}
File file;
// Debug connection
- AltosDevice device;
+ AltosUSBDevice device;
AltosLink link;
}
static class AltosHexfileFilter extends javax.swing.filechooser.FileFilter {
- int product;
String head;
String description;
- public AltosHexfileFilter(int product, String head, String description) {
- this.product = product;
- this.head = head;
- this.description = description;
+ public AltosHexfileFilter(String usb_product) {
+ int l;
+
+ /* Trim off any trailing variants (1.0a vs 1.0) */
+ for (l = usb_product.length(); l > 0; l--) {
+ char c = usb_product.charAt(l-1);
+ if (c < 'a' || 'z' < c)
+ break;
+ }
+ head = usb_product.substring(0, l).toLowerCase();
+ description = String.format("%s Image File", usb_product);
}
public boolean accept(File file) {
}
}
- static AltosHexfileFilter[] filters = {
- new AltosHexfileFilter(AltosLib.product_telemetrum, "telemetrum", "TeleMetrum Image"),
- new AltosHexfileFilter(AltosLib.product_teledongle, "teledongle", "TeleDongle Image"),
- new AltosHexfileFilter(AltosLib.product_telemega, "telemega", "TeleMega Image"),
- new AltosHexfileFilter(AltosLib.product_easymini, "easymini", "EasyMini Image"),
- new AltosHexfileFilter(AltosLib.product_easymega, "easymega", "EasyMega Image"),
- };
-
boolean select_source_file() {
JFileChooser hexfile_chooser = new JFileChooser();
hexfile_chooser.setDialogTitle("Select Flash Image");
- for (int i = 0; i < filters.length; i++) {
- hexfile_chooser.addChoosableFileFilter(filters[i]);
- }
javax.swing.filechooser.FileFilter ihx_filter = new FileNameExtensionFilter("Flash Image", "ihx");
hexfile_chooser.addChoosableFileFilter(ihx_filter);
hexfile_chooser.setFileFilter(ihx_filter);
if (!is_pair_programmed() && !device.matchProduct(AltosLib.product_altusmetrum)) {
- for (int i = 0; i < filters.length; i++) {
- if (device != null && device.matchProduct(filters[i].product))
- hexfile_chooser.setFileFilter(filters[i]);
- }
+ AltosHexfileFilter filter = new AltosHexfileFilter(device.usb_product());
+ hexfile_chooser.addChoosableFileFilter(filter);
+ hexfile_chooser.setFileFilter(filter);
}
int returnVal = hexfile_chooser.showOpenDialog(frame);
boolean select_device() {
int product = AltosLib.product_any;
- device = AltosDeviceUIDialog.show(frame, AltosLib.product_any);
+ device = AltosDeviceUIDialog.show_usb(frame, AltosLib.product_any);
if (device == null)
return false;
else
programmer = new AltosSelfFlash(ui.file, link, this);
- final AltosRomconfig current_config = programmer.target_romconfig();
+ final AltosRomconfig current_config = programmer.target_romconfig(device.usb_id(), device.usb_product());
final AltosRomconfig image_config = programmer.image_romconfig();
+ System.out.printf("product %s current %s image %s\n", device.usb_product(), current_config, image_config);
+
final Semaphore await_rom_config = new Semaphore(0);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
}
if (!matched) {
System.out.printf("Identified new device %s\n", d.toShortString());
- device = d;
+ device = (AltosUSBDevice) d;
break;
}
}
import java.util.*;
import libaltosJNI.*;
+import org.altusmetrum.altoslib_13.*;
public class AltosUSBDevice extends altos_device implements AltosDevice {
return getVendor() ^ getProduct() ^ getSerial() ^ getPath().hashCode();
}
+ public AltosUsbId usb_id() {
+ return new AltosUsbId(getVendor(), getProduct());
+ }
+
+ public String usb_product() {
+ return getName();
+ }
+
public boolean equals(Object o) {
if (o == null)
return false;