Skip to content

Pluggable discovery: search in platform.txt (WIP) #8038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f81798b
Pluggable discovery: search in platform.txt (WIP)
cmaglie Sep 10, 2018
f5bf6e5
Add BoardPort copy constructor
PaulStoffregen Sep 29, 2018
5ba56ab
Initial PluggableDiscovery using BoardPort for JSON
PaulStoffregen Sep 29, 2018
b606657
PluggableDiscovery check for START_SYNC not supported
PaulStoffregen Sep 29, 2018
e029acc
Add PluggableDiscoveryMessage for BoardPort change metadata
PaulStoffregen Oct 1, 2018
05092bf
Move BoardPort fixed fields into prefs
PaulStoffregen Oct 1, 2018
d7143d6
Add BoardPort identificationPrefs and searchMatchingBoard
PaulStoffregen Oct 3, 2018
8d6fa72
Removing fixed fields in BoardPort
cmaglie Oct 4, 2018
3ccb2d9
Merged SerialDiscovery and SerialBoardLister
cmaglie Oct 4, 2018
80fb9a0
Optimized forceRefresh() method by removing redundant boolean paramater
cmaglie Oct 4, 2018
5bc9665
Slightly optimized method by removing redundant boolean flag
cmaglie Oct 4, 2018
ec4787a
Fixed board identification in BoardPort
cmaglie Oct 4, 2018
9ba172b
Show BoardName.boardName field in 'Ports' menu
cmaglie Nov 23, 2018
cfd3cf2
Use correctly the setBoardName() method in NetworkDiscovery
cmaglie Nov 23, 2018
c03a8bc
Minor fix in indentation and style
cmaglie Nov 23, 2018
349af4b
Added BoardPort.protocolLabel and simplified port menu rendering
cmaglie Nov 29, 2018
7186213
Slightly changed pluggable discovery json parsing
cmaglie Nov 30, 2018
8e9f0cf
PluggableDiscovery: added a 'port' field in json messages
cmaglie Nov 30, 2018
4c188c9
PluggableDiscovery: Factored out method to umarshal BoardPort from JSON
cmaglie Nov 30, 2018
4ae740a
PluggableDiscovery: BoardPort.label sanity check in the correct place
cmaglie Nov 30, 2018
7bc086a
PluggableDiscovery: correct synchronization on 'portList' access
cmaglie Nov 30, 2018
6c50007
Editor: renamed status bar field serialport -> port
cmaglie Dec 7, 2018
4fffcd6
Editor: use TargetBoard.getName() to get board name
cmaglie Dec 7, 2018
651dcd5
Removed unused field
cmaglie Dec 7, 2018
e1caaf1
Perform port selection after initializing packages
cmaglie Jan 23, 2019
feb863d
PluggableDiscovery: allow patterns to contain runtime variables
facchinm Dec 13, 2018
be1a840
Add TargetBoard.getFQBN helper
facchinm Mar 7, 2019
d4bbf71
Match wildcard property "." with board fqbn/name
facchinm Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Pluggable discovery: search in platform.txt (WIP)
  • Loading branch information
cmaglie committed Jan 23, 2019
commit f81798badfd31069566db5a4adb0c45a1327397f
46 changes: 41 additions & 5 deletions arduino-core/src/cc/arduino/packages/DiscoveryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,67 @@

package cc.arduino.packages;

import cc.arduino.packages.discoverers.NetworkDiscovery;
import cc.arduino.packages.discoverers.SerialDiscovery;
import static processing.app.I18n.format;
import static processing.app.I18n.tr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static processing.app.I18n.tr;
import cc.arduino.packages.discoverers.PluggableDiscovery;
import cc.arduino.packages.discoverers.NetworkDiscovery;
import cc.arduino.packages.discoverers.SerialDiscovery;
import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.StringReplacer;

public class DiscoveryManager {

private final List<Discovery> discoverers;
private final SerialDiscovery serialDiscoverer = new SerialDiscovery();
private final NetworkDiscovery networkDiscoverer = new NetworkDiscovery();

public DiscoveryManager() {
// private final Map<String, TargetPackage> packages;

public DiscoveryManager(Map<String, TargetPackage> packages) {
// this.packages = packages;

discoverers = new ArrayList<>();
discoverers.add(serialDiscoverer);
discoverers.add(networkDiscoverer);

// Search for discoveries in installed packages
for (TargetPackage targetPackage : packages.values()) {
for (TargetPlatform platform: targetPackage.getPlatforms().values()) {
//System.out.println("installed: "+platform);
PreferencesMap prefs = platform.getPreferences().subTree("discovery");
for (String discoveryName : prefs.firstLevelMap().keySet()) {
PreferencesMap discoveryPrefs = prefs.subTree(discoveryName);

String pattern = discoveryPrefs.get("pattern");
if (pattern == null) {
System.out.println(format(tr("No recipes defined for discovery '{0}'"),discoveryName));
continue;
}
try {
System.out.println("found discovery: " + discoveryName + " -> " + pattern);
System.out.println("with preferencess -> " + discoveryPrefs);
String[] cmd = StringReplacer.formatAndSplit(pattern, discoveryPrefs);
discoverers.add(new PluggableDiscovery(discoveryName, cmd));
} catch (Exception e) {
System.out.println(format(tr("Could not start discovery '{0}': {1}"), discoveryName, e.getMessage()));
}
}
}
}

// Start all discoverers
for (Discovery d : discoverers) {
try {
new Thread(d).start();
} catch (Exception e) {
System.err.println(tr("Error starting discovery method: ") + d.getClass());
System.err.println(tr("Error starting discovery method: ") + d.toString());
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2018 Arduino SA (http://www.arduino.cc/)
*/

package cc.arduino.packages.discoverers;

import java.util.ArrayList;
import java.util.List;

import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Discovery;
import processing.app.legacy.PApplet;

public class PluggableDiscovery implements Discovery {

private String discoveryName;

public PluggableDiscovery(String discoveryName, String[] cmd) {
this.discoveryName = discoveryName;
System.out.println("Starting: " + PApplet.join(cmd, " "));
}

@Override
public void run() {
// TODO this method is started as a new thread, it will constantly
// communicate with the discovery tool and keep track of the discovered
// port to be returned from listDiscoveredBoard()
try {
start();
while (true) { // TODO: Find a better way to terminate discovery
System.out.println(discoveryName + ": looping...");
Thread.sleep(500);
}
// stop();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void start() throws Exception {
// TODO send a START_SYNC command to the discovery tool
// or fallback to START if not available
}

@Override
public void stop() throws Exception {
// TODO send a STOP to the discovery
}

@Override
public List<BoardPort> listDiscoveredBoards() {
// TODO return the ports discovered so far
final List<BoardPort> empty = new ArrayList<>();
return empty;
}

@Override
public List<BoardPort> listDiscoveredBoards(boolean complete) {
// XXX: parameter "complete "is really needed?
// should be checked on all existing discoveries

// TODO
final List<BoardPort> empty = new ArrayList<>();
return empty;
}

@Override
public String toString() {
return discoveryName;
}
}
4 changes: 2 additions & 2 deletions arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static public File getDefaultSketchbookFolder() {

public static DiscoveryManager getDiscoveryManager() {
if (discoveryManager == null) {
discoveryManager = new DiscoveryManager();
discoveryManager = new DiscoveryManager(packages);
}
return discoveryManager;
}
Expand Down Expand Up @@ -506,7 +506,7 @@ static public void initPackages() throws Exception {
}

if (discoveryManager == null) {
discoveryManager = new DiscoveryManager();
discoveryManager = new DiscoveryManager(packages);
}
}

Expand Down