From d7c4481baa9d8e69cff268b1ff48f9d8528378ee Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 4 Jun 2013 17:26:31 +0200 Subject: [PATCH] Using additional info in avahi payload to print discovered board type --- app/src/processing/app/Base.java | 6 +++++- app/src/processing/app/Editor.java | 7 ++++--- app/src/processing/app/Platform.java | 13 +++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 1a103562f..c7f0a57b4 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -421,8 +421,12 @@ public class Base { @Override public void boardOnline(ServiceEvent serviceEvent) { Map board = new HashMap(); + board.put("hostname", serviceEvent.getName()); board.put("addresses", serviceEvent.getInfo().getInet4Addresses()); - board.put("type", serviceEvent.getType()); + if (serviceEvent.getInfo().hasData()) { + board.put("id", serviceEvent.getInfo().getPropertyString("board")); + board.put("distro_version", serviceEvent.getInfo().getPropertyString("distro_version")); + } Base.this.boardsViaNetwork.put(serviceEvent.getName(), board); } }); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 84ed3afd7..7a500b568 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1008,9 +1008,10 @@ public class Editor extends JFrame implements RunnerListener { exception.printStackTrace(); } - for (Map.Entry> entry : base.getBoardsViaNetwork().entrySet()) { - Inet4Address[] addresses = (Inet4Address[]) entry.getValue().get("addresses"); - String label = addresses[0].getHostAddress() + " (" + entry.getKey() + ")"; + for (Map board : base.getBoardsViaNetwork().values()) { + String boardName = Base.getPlatform().resolveDeviceByBoardID(Base.packages, (String) board.get("id")); + Inet4Address[] addresses = (Inet4Address[]) board.get("addresses"); + String label = board.get("hostname") + "@" + addresses[0].getHostAddress() + " (" + boardName + ")"; JCheckBoxMenuItem rbMenuItem = new JCheckBoxMenuItem(label, label.equals(Preferences.get("serial.port"))); rbMenuItem.addActionListener(new SerialMenuListener(label)); serialMenu.add(rbMenuItem); diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 149b74437..db29cb295 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -165,6 +165,19 @@ public class Platform { return null; } + public String resolveDeviceByBoardID(Map packages, String boardId) { + for (TargetPackage targetPackage : packages.values()) { + for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) { + for (TargetBoard board : targetPlatform.getBoards().values()) { + if (boardId.equals(board.getId())) { + return board.getName(); + } + } + } + } + return null; + } + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .