mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 09:15:38 +02:00
Hooked up Arduino launch to new build configs.
Wow, this is slick. Launch delegate gets upload command from build config. Change-Id: I779625407877610f1405a48eab851b25d886165f
This commit is contained in:
parent
f38efe2a91
commit
fb9547a46c
17 changed files with 296 additions and 161 deletions
|
@ -24,5 +24,6 @@ Bundle-ClassPath: libs/freemarker-2.3.22.jar,
|
|||
Export-Package: org.eclipse.cdt.arduino.core.internal;x-friends:="org.eclipse.cdt.arduino.ui",
|
||||
org.eclipse.cdt.arduino.core.internal.board;x-friends:="org.eclipse.cdt.arduino.ui",
|
||||
org.eclipse.cdt.arduino.core.internal.build;x-friends:="org.eclipse.cdt.arduino.ui",
|
||||
org.eclipse.cdt.arduino.core.internal.console;x-friends:="org.eclipse.cdt.arduino.ui"
|
||||
org.eclipse.cdt.arduino.core.internal.console;x-friends:="org.eclipse.cdt.arduino.ui",
|
||||
org.eclipse.cdt.arduino.core.internal.remote;x-friends:="org.eclipse.cdt.arduino.ui"
|
||||
Bundle-Localization: plugin
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<connectionService
|
||||
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
|
||||
factory="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection$Factory"
|
||||
service="org.eclipse.cdt.arduino.core.internal.IArduinoRemoteConnection">
|
||||
service="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection">
|
||||
</connectionService>
|
||||
<connectionService
|
||||
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
|
||||
|
|
|
@ -57,15 +57,13 @@ public class ArduinoProjectGenerator {
|
|||
command.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
|
||||
projDesc.setBuildSpec(new ICommand[] { command });
|
||||
|
||||
// Create the default config
|
||||
projDesc.setBuildConfigs(new String[] { "arduinoDefault" }); //$NON-NLS-1$
|
||||
// Create the default config - uno
|
||||
projDesc.setBuildConfigs(new String[] { "uno" }); //$NON-NLS-1$
|
||||
|
||||
project.setDescription(projDesc, monitor);
|
||||
|
||||
// Test config
|
||||
IBuildConfiguration config = project.getBuildConfig("arduinoDefault"); //$NON-NLS-1$
|
||||
IBuildConfiguration config = project.getBuildConfig("uno"); //$NON-NLS-1$
|
||||
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
|
||||
// TODO for now assume Uno
|
||||
ArduinoBoard board = ArduinoBoardManager.instance.getBoard("Arduino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
arduinoConfig.setBoard(board);
|
||||
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.arduino.core.internal;
|
||||
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
|
||||
/**
|
||||
* Arduino specific extensions to IRemoteConnection.
|
||||
*
|
||||
* @author dschaefer
|
||||
*
|
||||
*/
|
||||
public interface IArduinoRemoteConnection extends IRemoteConnection.Service {
|
||||
|
||||
final String TYPE_ID = "org.eclipse.cdt.arduino.core.connectionType"; //$NON-NLS-1$
|
||||
final String PORT_NAME = "ardiuno.portname"; //$NON-NLS-1$
|
||||
final String BOARD_ID = "arduino.board"; //$NON-NLS-1$
|
||||
final String PLATFORM_ID = "arduino.platform"; //$NON-NLS-1$
|
||||
final String PACKAGE_ID = "arduino.package"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Return the serial port name.
|
||||
*
|
||||
* @return serial port name
|
||||
*/
|
||||
String getPortName();
|
||||
|
||||
String getBoardName();
|
||||
|
||||
String getPlatformName();
|
||||
|
||||
String getPackageName();
|
||||
|
||||
void pause();
|
||||
|
||||
void resume();
|
||||
|
||||
}
|
|
@ -54,4 +54,35 @@ public class ArduinoBoard {
|
|||
return properties.flatten();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((platform == null) ? 0 : platform.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ArduinoBoard other = (ArduinoBoard) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (platform == null) {
|
||||
if (other.platform != null)
|
||||
return false;
|
||||
} else if (!platform.equals(other.platform))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
import com.google.gson.Gson;
|
||||
|
||||
// Closeable isn't API yet but it's recommended.
|
||||
@SuppressWarnings("restriction")
|
||||
public class ArduinoBoardManager {
|
||||
|
||||
public static final ArduinoBoardManager instance = new ArduinoBoardManager();
|
||||
|
@ -93,8 +92,18 @@ public class ArduinoBoardManager {
|
|||
|
||||
public List<ArduinoBoard> getBoards() throws CoreException {
|
||||
List<ArduinoBoard> boards = new ArrayList<>();
|
||||
for (ArduinoPackage pkg : packageIndex.getPackages()) {
|
||||
for (ArduinoPlatform platform : pkg.getPlatforms()) {
|
||||
for (ArduinoPackage pkg : getPackageIndex().getPackages()) {
|
||||
for (ArduinoPlatform platform : pkg.getLatestPlatforms()) {
|
||||
boards.addAll(platform.getBoards());
|
||||
}
|
||||
}
|
||||
return boards;
|
||||
}
|
||||
|
||||
public List<ArduinoBoard> getInstalledBoards() throws CoreException {
|
||||
List<ArduinoBoard> boards = new ArrayList<>();
|
||||
for (ArduinoPackage pkg : getPackageIndex().getPackages()) {
|
||||
for (ArduinoPlatform platform : pkg.getInstalledPlatforms()) {
|
||||
boards.addAll(platform.getBoards());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,19 @@ public class ArduinoPackage {
|
|||
platformMap.put(platform.getName(), platform);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableCollection(platformMap.values());
|
||||
}
|
||||
|
||||
public Collection<ArduinoPlatform> getInstalledPlatforms() {
|
||||
Map<String, ArduinoPlatform> platformMap = new HashMap<>();
|
||||
for (ArduinoPlatform platform : platforms) {
|
||||
if (platform.isInstalled()) {
|
||||
ArduinoPlatform p = platformMap.get(platform.getName());
|
||||
if (p == null || compareVersions(platform.getVersion(), p.getVersion()) > 0) {
|
||||
platformMap.put(platform.getName(), platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableCollection(platformMap.values());
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,9 @@ public class ArduinoPlatform {
|
|||
private List<ArduinoBoard> boards;
|
||||
private List<ToolDependency> toolsDependencies;
|
||||
|
||||
private transient ArduinoPackage pkg;
|
||||
private transient HierarchicalProperties boardsFile;
|
||||
private transient Properties platformProperties;
|
||||
private ArduinoPackage pkg;
|
||||
private HierarchicalProperties boardsFile;
|
||||
private Properties platformProperties;
|
||||
|
||||
void setOwner(ArduinoPackage pkg) {
|
||||
this.pkg = pkg;
|
||||
|
@ -127,6 +127,15 @@ public class ArduinoPlatform {
|
|||
return toolsDependencies;
|
||||
}
|
||||
|
||||
public ArduinoTool getTool(String name) throws CoreException {
|
||||
for (ToolDependency toolDep : toolsDependencies) {
|
||||
if (toolDep.getName().equals(name)) {
|
||||
return toolDep.getTool();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Properties getPlatformProperties() throws CoreException {
|
||||
if (platformProperties == null) {
|
||||
platformProperties = new Properties();
|
||||
|
@ -194,4 +203,41 @@ public class ArduinoPlatform {
|
|||
return mstatus != null ? mstatus : Status.OK_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((pkg == null) ? 0 : pkg.hashCode());
|
||||
result = prime * result + ((version == null) ? 0 : version.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ArduinoPlatform other = (ArduinoPlatform) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (pkg == null) {
|
||||
if (other.pkg != null)
|
||||
return false;
|
||||
} else if (!pkg.equals(other.pkg))
|
||||
return false;
|
||||
if (version == null) {
|
||||
if (other.version != null)
|
||||
return false;
|
||||
} else if (!version.equals(other.version))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,9 +9,11 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -36,6 +38,7 @@ import org.eclipse.core.resources.IBuildConfiguration;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceProxy;
|
||||
import org.eclipse.core.resources.IResourceProxyVisitor;
|
||||
|
@ -50,12 +53,13 @@ import org.osgi.service.prefs.BackingStoreException;
|
|||
|
||||
public class ArduinoBuildConfiguration {
|
||||
|
||||
private static final String PACKAGE_NAME = "packageId"; //$NON-NLS-1$
|
||||
private static final String PACKAGE_NAME = "packageName"; //$NON-NLS-1$
|
||||
private static final String PLATFORM_NAME = "platformName"; //$NON-NLS-1$
|
||||
private static final String BOARD_NAME = "boardName"; //$NON-NLS-1$
|
||||
|
||||
private final IBuildConfiguration config;
|
||||
|
||||
private ArduinoBoard board;
|
||||
private Properties properties;
|
||||
|
||||
// Cache for scanner info
|
||||
|
@ -90,12 +94,59 @@ public class ArduinoBuildConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
public static ArduinoBuildConfiguration getConfig(IProject project, ArduinoBoard board, IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
// return it if it exists already
|
||||
for (IBuildConfiguration config : project.getBuildConfigs()) {
|
||||
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
|
||||
if (board.equals(arduinoConfig.getBoard())) {
|
||||
return arduinoConfig;
|
||||
}
|
||||
}
|
||||
|
||||
// Not found, need to create one
|
||||
Set<String> configNames = new HashSet<>();
|
||||
for (IBuildConfiguration config : project.getBuildConfigs()) {
|
||||
configNames.add(config.getName());
|
||||
}
|
||||
String newName = board.getId();
|
||||
int n = 0;
|
||||
while (configNames.contains(newName)) {
|
||||
newName = board.getId() + (++n);
|
||||
}
|
||||
configNames.add(newName);
|
||||
IProjectDescription projectDesc = project.getDescription();
|
||||
projectDesc.setBuildConfigs(configNames.toArray(new String[configNames.size()]));
|
||||
project.setDescription(projectDesc, monitor);
|
||||
|
||||
// set it up for the board
|
||||
IBuildConfiguration config = project.getBuildConfig(newName);
|
||||
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
|
||||
arduinoConfig.setBoard(board);
|
||||
|
||||
return arduinoConfig;
|
||||
}
|
||||
|
||||
public void setActive(IProgressMonitor monitor) throws CoreException {
|
||||
IProject project = config.getProject();
|
||||
if (config.equals(project.getActiveBuildConfig())) {
|
||||
// already set
|
||||
return;
|
||||
}
|
||||
|
||||
IProjectDescription projectDesc = project.getDescription();
|
||||
projectDesc.setActiveBuildConfig(config.getName());
|
||||
project.setDescription(projectDesc, monitor);
|
||||
}
|
||||
|
||||
public IEclipsePreferences getSettings() {
|
||||
return (IEclipsePreferences) new ProjectScope(config.getProject()).getNode(Activator.getId()).node("config") //$NON-NLS-1$
|
||||
.node(config.getName());
|
||||
}
|
||||
|
||||
public void setBoard(ArduinoBoard board) throws CoreException {
|
||||
this.board = board;
|
||||
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
|
||||
|
@ -111,11 +162,14 @@ public class ArduinoBuildConfiguration {
|
|||
}
|
||||
|
||||
public ArduinoBoard getBoard() throws CoreException {
|
||||
IEclipsePreferences settings = getSettings();
|
||||
String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$
|
||||
String platformName = settings.get(PLATFORM_NAME, ""); //$NON-NLS-1$
|
||||
String boardName = settings.get(BOARD_NAME, ""); //$NON-NLS-1$
|
||||
return ArduinoBoardManager.instance.getBoard(boardName, platformName, packageName);
|
||||
if (board == null) {
|
||||
IEclipsePreferences settings = getSettings();
|
||||
String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$
|
||||
String platformName = settings.get(PLATFORM_NAME, ""); //$NON-NLS-1$
|
||||
String boardName = settings.get(BOARD_NAME, ""); //$NON-NLS-1$
|
||||
board = ArduinoBoardManager.instance.getBoard(boardName, platformName, packageName);
|
||||
}
|
||||
return board;
|
||||
}
|
||||
|
||||
private Properties getProperties() throws CoreException {
|
||||
|
@ -127,7 +181,12 @@ public class ArduinoBuildConfiguration {
|
|||
for (ToolDependency toolDep : platform.getToolsDependencies()) {
|
||||
properties.putAll(toolDep.getTool().getToolProperties());
|
||||
}
|
||||
properties.put("runtime.ide.version", "1.6.7"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$
|
||||
properties.put("build.path", config.getName()); //$NON-NLS-1$
|
||||
}
|
||||
// always do this in case the project changes names
|
||||
properties.put("build.project_name", config.getProject().getName()); //$NON-NLS-1$
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
@ -150,7 +209,6 @@ public class ArduinoBuildConfiguration {
|
|||
public IFile generateMakeFile(IProgressMonitor monitor) throws CoreException {
|
||||
final IProject project = config.getProject();
|
||||
|
||||
// Make sure build folder exists
|
||||
IFolder buildFolder = getBuildFolder();
|
||||
if (!buildFolder.exists()) {
|
||||
buildFolder.create(true, true, monitor);
|
||||
|
@ -194,10 +252,7 @@ public class ArduinoBuildConfiguration {
|
|||
// the recipes
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(getProperties());
|
||||
properties.put("runtime.ide.version", "1.6.7"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$
|
||||
properties.put("build.path", "$(OUTPUT_DIR)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("build.project_name", project.getName()); //$NON-NLS-1$
|
||||
buildModel.put("build_path", properties.get("build.path")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buildModel.put("project_name", project.getName()); //$NON-NLS-1$
|
||||
|
||||
String includes = null;
|
||||
|
@ -218,7 +273,7 @@ public class ArduinoBuildConfiguration {
|
|||
File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".cpp") || name.endsWith(".c");
|
||||
return name.endsWith(".cpp") || name.endsWith(".c"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -325,6 +380,8 @@ public class ArduinoBuildConfiguration {
|
|||
}
|
||||
|
||||
public String[] getSizeCommand() throws CoreException {
|
||||
// TODO this shouldn't be in the makefile
|
||||
// should be like the upload command
|
||||
return new String[] { "make", "-f", getMakeFile().getName(), "size" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
|
@ -346,6 +403,25 @@ public class ArduinoBuildConfiguration {
|
|||
return sizeStr != null ? Integer.parseInt(sizeStr) : -1;
|
||||
}
|
||||
|
||||
public String[] getUploadCommand(String serialPort) throws CoreException {
|
||||
String toolName = getProperties().getProperty("upload.tool"); //$NON-NLS-1$
|
||||
ArduinoTool tool = board.getPlatform().getTool(toolName);
|
||||
|
||||
Properties properties = getProperties();
|
||||
properties.put("runtime.tools." + toolName + ".path", tool.getInstallPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("serial.port", serialPort); //$NON-NLS-1$
|
||||
// to make up for some cheating in the platform.txt file
|
||||
properties.put("path", "{tools." + toolName + ".path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
properties.put("cmd.path", "{tools." + toolName + ".cmd.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
properties.put("config.path", "{tools." + toolName + ".config.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
properties.put("upload.verbose", "{tools." + toolName + ".upload.params.quiet}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
String command = resolveProperty("tools." + toolName + ".upload.pattern", properties); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// TODO Windows
|
||||
return new String[] { "sh", "-c", command }; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public IScannerInfo getScannerInfo(IResource resource) throws CoreException {
|
||||
// what language is this resource and pick the right path;
|
||||
switch (CCorePlugin.getContentType(resource.getProject(), resource.getName()).getId()) {
|
||||
|
@ -368,10 +444,8 @@ public class ArduinoBuildConfiguration {
|
|||
ArduinoPlatform platform = getBoard().getPlatform();
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(getProperties());
|
||||
properties.put("runtime.ide.version", "1.6.7"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$
|
||||
|
||||
Path tmpFile = Files.createTempFile("cdt", ".cpp");
|
||||
Path tmpFile = Files.createTempFile("cdt", ".cpp"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("source_file", tmpFile.toString()); //$NON-NLS-1$
|
||||
properties.put("object_file", "-"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
|
@ -383,7 +457,7 @@ public class ArduinoBuildConfiguration {
|
|||
|
||||
// TODO Windows
|
||||
String[] command = new String[] { "sh", "-c", resolveProperty(recipe, properties) }; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(getBuildDirectory())
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(tmpFile.getParent().toFile())
|
||||
.redirectErrorStream(true);
|
||||
setEnvironment(processBuilder.environment());
|
||||
Process process = processBuilder.start();
|
||||
|
|
|
@ -10,14 +10,12 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.arduino.core.internal.launch;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.core.internal.IArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.core.internal.Messages;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
|
||||
import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleService;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -50,10 +48,13 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
IRemoteConnection target = getTarget(configuration);
|
||||
ArduinoRemoteConnection arduinoTarget = target.getService(ArduinoRemoteConnection.class);
|
||||
ArduinoBoard targetBoard = arduinoTarget.getBoard();
|
||||
|
||||
// 1. make sure proper build config is set active
|
||||
IProject project = configuration.getMappedResources()[0].getProject();
|
||||
// TODO set active build config for the selected target
|
||||
ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project, targetBoard, monitor);
|
||||
arduinoConfig.setActive(monitor);
|
||||
|
||||
// 2. Run the build
|
||||
return super.buildForLaunch(configuration, mode, monitor);
|
||||
|
@ -78,42 +79,40 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
return new Status(IStatus.ERROR, Activator.getId(),
|
||||
Messages.ArduinoLaunchConfigurationDelegate_2);
|
||||
}
|
||||
ArduinoRemoteConnection arduinoTarget = target.getService(ArduinoRemoteConnection.class);
|
||||
|
||||
// The project
|
||||
IProject project = (IProject) configuration.getMappedResources()[0];
|
||||
|
||||
// The build environment
|
||||
List<String> envVarList = new ArrayList<>();
|
||||
|
||||
// Add in the serial port based on launch config
|
||||
IArduinoRemoteConnection arduinoRemote = target.getService(IArduinoRemoteConnection.class);
|
||||
envVarList.add("SERIAL_PORT=" + arduinoRemote.getPortName()); //$NON-NLS-1$
|
||||
String[] envp = envVarList.toArray(new String[envVarList.size()]);
|
||||
|
||||
// The project directory to launch from
|
||||
File projectDir = new File(project.getLocationURI());
|
||||
|
||||
// The build command
|
||||
String command = "make";
|
||||
// The build config
|
||||
ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project,
|
||||
arduinoTarget.getBoard(), monitor);
|
||||
String[] uploadCmd = arduinoConfig.getUploadCommand(arduinoTarget.getPortName());
|
||||
|
||||
// If opened, temporarily close the connection so we can use
|
||||
// it to download the firmware.
|
||||
boolean wasOpened = target.isOpen();
|
||||
if (wasOpened) {
|
||||
arduinoRemote.pause();
|
||||
arduinoTarget.pause();
|
||||
}
|
||||
|
||||
// Run the process and capture the results in the console
|
||||
Process process = Runtime.getRuntime().exec(command + " load", envp, projectDir); //$NON-NLS-1$
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(uploadCmd)
|
||||
.directory(arduinoConfig.getBuildDirectory());
|
||||
arduinoConfig.setEnvironment(processBuilder.environment());
|
||||
Process process = processBuilder.start();
|
||||
|
||||
consoleService.monitor(process, null);
|
||||
try {
|
||||
process.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
consoleService.writeOutput("Upload complete\n");
|
||||
|
||||
// Reopen the connection
|
||||
if (wasOpened) {
|
||||
arduinoRemote.resume();
|
||||
arduinoTarget.resume();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
|
|
|
@ -15,8 +15,10 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.core.internal.IArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoardManager;
|
||||
import org.eclipse.cdt.serial.SerialPort;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.remote.core.IRemoteCommandShellService;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||
|
@ -25,8 +27,14 @@ import org.eclipse.remote.core.IRemoteProcess;
|
|||
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||
import org.eclipse.remote.serial.core.SerialPortCommandShell;
|
||||
|
||||
public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService, IRemoteCommandShellService,
|
||||
IArduinoRemoteConnection, IRemoteConnectionChangeListener {
|
||||
public class ArduinoRemoteConnection
|
||||
implements IRemoteConnectionPropertyService, IRemoteCommandShellService, IRemoteConnectionChangeListener {
|
||||
|
||||
public static final String TYPE_ID = "org.eclipse.cdt.arduino.core.connectionType"; //$NON-NLS-1$
|
||||
public static final String PORT_NAME = "ardiuno.portname"; //$NON-NLS-1$
|
||||
public static final String PACKAGE_NAME = "packageName"; //$NON-NLS-1$
|
||||
public static final String PLATFORM_NAME = "platformName"; //$NON-NLS-1$
|
||||
public static final String BOARD_NAME = "boardName"; //$NON-NLS-1$
|
||||
|
||||
private final IRemoteConnection remoteConnection;
|
||||
private SerialPort serialPort;
|
||||
|
@ -53,7 +61,7 @@ public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService
|
|||
@Override
|
||||
public <T extends IRemoteConnection.Service> T getService(IRemoteConnection remoteConnection,
|
||||
Class<T> service) {
|
||||
if (IArduinoRemoteConnection.class.equals(service)) {
|
||||
if (ArduinoRemoteConnection.class.equals(service)) {
|
||||
synchronized (connectionMap) {
|
||||
ArduinoRemoteConnection connection = connectionMap.get(remoteConnection);
|
||||
if (connection == null) {
|
||||
|
@ -64,7 +72,7 @@ public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService
|
|||
}
|
||||
} else if (IRemoteConnectionPropertyService.class.equals(service)
|
||||
|| IRemoteCommandShellService.class.equals(service)) {
|
||||
return (T) remoteConnection.getService(IArduinoRemoteConnection.class);
|
||||
return (T) remoteConnection.getService(ArduinoRemoteConnection.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -86,27 +94,15 @@ public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBoardName() {
|
||||
return remoteConnection.getAttribute(BOARD_ID);
|
||||
public ArduinoBoard getBoard() throws CoreException {
|
||||
return ArduinoBoardManager.instance.getBoard(remoteConnection.getAttribute(BOARD_NAME),
|
||||
remoteConnection.getAttribute(PLATFORM_NAME), remoteConnection.getAttribute(PACKAGE_NAME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformName() {
|
||||
return remoteConnection.getAttribute(PLATFORM_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackageName() {
|
||||
return remoteConnection.getAttribute(PACKAGE_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPortName() {
|
||||
return remoteConnection.getAttribute(PORT_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRemoteProcess getCommandShell(int flags) throws IOException {
|
||||
if (serialPort != null && serialPort.isOpen()) {
|
||||
// can only have one open at a time
|
||||
|
@ -118,7 +114,6 @@ public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService
|
|||
return commandShell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
if (serialPort != null) {
|
||||
try {
|
||||
|
@ -130,7 +125,6 @@ public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
if (serialPort != null) {
|
||||
try {
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
EXE = ${projectName}
|
||||
LIBS =
|
||||
BOARD ?= uno
|
||||
OUTPUT_DIR ?= build/$(BOARD)
|
||||
|
||||
include arduino.mk
|
|
@ -1,5 +1,3 @@
|
|||
OUTPUT_DIR = ${boardId}
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
RMDIR = rmdir /s /q
|
||||
mymkdir = if not exist "$(call fixpath,$1)" mkdir $(call fixpath,$1)
|
||||
|
@ -12,7 +10,7 @@ PROJECT_OBJS = \
|
|||
<#list project_srcs as file>
|
||||
<#assign cpp = file?matches("(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
$(OUTPUT_DIR)/project/${cpp?groups[1]}.o \
|
||||
${build_path}/project/${cpp?groups[1]}.o \
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
|
@ -20,29 +18,29 @@ PLATFORM_OBJS = \
|
|||
<#list platform_srcs as file>
|
||||
<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
$(OUTPUT_DIR)/platform/${cpp?groups[1]}.o \
|
||||
${build_path}/platform/${cpp?groups[1]}.o \
|
||||
</#if>
|
||||
<#assign c = file?matches("${platform_path}/(.*)\\.c")>
|
||||
<#if c>
|
||||
$(OUTPUT_DIR)/platform/${c?groups[1]}.o \
|
||||
${build_path}/platform/${c?groups[1]}.o \
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
all: $(OUTPUT_DIR)/${project_name}.hex $(OUTPUT_DIR)/${project_name}.eep
|
||||
all: ${build_path}/${project_name}.hex ${build_path}/${project_name}.eep
|
||||
|
||||
$(OUTPUT_DIR)/${project_name}.hex: $(OUTPUT_DIR)/${project_name}.elf
|
||||
${build_path}/${project_name}.hex: ${build_path}/${project_name}.elf
|
||||
${recipe_objcopy_hex_pattern}
|
||||
|
||||
$(OUTPUT_DIR)/${project_name}.eep: $(OUTPUT_DIR)/${project_name}.elf
|
||||
${build_path}/${project_name}.eep: ${build_path}/${project_name}.elf
|
||||
${recipe_objcopy_eep_pattern}
|
||||
|
||||
$(OUTPUT_DIR)/${project_name}.elf: $(PROJECT_OBJS) $(OUTPUT_DIR)/libc.a
|
||||
${build_path}/${project_name}.elf: $(PROJECT_OBJS) ${build_path}/libc.a
|
||||
${recipe_c_combine_pattern}
|
||||
|
||||
$(OUTPUT_DIR)/libc.a: $(PLATFORM_OBJS)
|
||||
${build_path}/libc.a: $(PLATFORM_OBJS)
|
||||
|
||||
clean:
|
||||
$(RMDIR) $(OUTPUT_DIR)
|
||||
$(RMDIR) ${build_path}
|
||||
|
||||
size:
|
||||
${recipe_size_pattern}
|
||||
|
@ -50,7 +48,7 @@ size:
|
|||
<#list project_srcs as file>
|
||||
<#assign cpp = file?matches("(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
$(OUTPUT_DIR)/project/${cpp?groups[1]}.o: ../${file}
|
||||
${build_path}/project/${cpp?groups[1]}.o: ../${file}
|
||||
@$(call mymkdir,$(dir $@))
|
||||
${recipe_cpp_o_pattern}
|
||||
|
||||
|
@ -60,7 +58,7 @@ $(OUTPUT_DIR)/project/${cpp?groups[1]}.o: ../${file}
|
|||
<#list platform_srcs as file>
|
||||
<#assign cpp = file?matches("${platform_path}/(.*)\\.cpp")>
|
||||
<#if cpp>
|
||||
$(OUTPUT_DIR)/platform/${cpp?groups[1]}.o: ${file}
|
||||
${build_path}/platform/${cpp?groups[1]}.o: ${file}
|
||||
@$(call mymkdir,$(dir $@))
|
||||
${recipe_cpp_o_pattern}
|
||||
${recipe_ar_pattern}
|
||||
|
@ -68,7 +66,7 @@ $(OUTPUT_DIR)/platform/${cpp?groups[1]}.o: ${file}
|
|||
</#if>
|
||||
<#assign c = file?matches("${platform_path}/(.*)\\.c")>
|
||||
<#if c>
|
||||
$(OUTPUT_DIR)/platform/${c?groups[1]}.o: ${file}
|
||||
${build_path}/platform/${c?groups[1]}.o: ${file}
|
||||
@$(call mymkdir,$(dir $@))
|
||||
${recipe_c_o_pattern}
|
||||
${recipe_ar_pattern}
|
||||
|
|
|
@ -42,15 +42,6 @@ public class Activator extends AbstractUIPlugin {
|
|||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
|
||||
new UIJob("Arduino UI Startup") {
|
||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
ImageRegistry imageRegistry = getImageRegistry();
|
||||
imageRegistry.put(IMG_ARDUINO, imageDescriptorFromPlugin(PLUGIN_ID, "icons/cprojects.gif")); //$NON-NLS-1$
|
||||
imageRegistry.put(IMG_CONNECTION_TYPE, imageDescriptorFromPlugin(PLUGIN_ID, "icons/arduino.png")); //$NON-NLS-1$
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}.schedule();
|
||||
}
|
||||
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
|
@ -58,6 +49,14 @@ public class Activator extends AbstractUIPlugin {
|
|||
super.stop(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageRegistry createImageRegistry() {
|
||||
ImageRegistry registry = super.createImageRegistry();
|
||||
registry.put(IMG_ARDUINO, imageDescriptorFromPlugin(PLUGIN_ID, "icons/cprojects.gif")); //$NON-NLS-1$
|
||||
registry.put(IMG_CONNECTION_TYPE, imageDescriptorFromPlugin(PLUGIN_ID, "icons/arduino.png")); //$NON-NLS-1$
|
||||
return registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
|
|
|
@ -3,9 +3,11 @@ package org.eclipse.cdt.arduino.ui.internal.remote;
|
|||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.IArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoardManager;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoardManager;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPackage;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Messages;
|
||||
import org.eclipse.cdt.serial.SerialPort;
|
||||
|
@ -36,7 +38,7 @@ public class ArduinoTargetPropertyPage extends PropertyPage implements IWorkbenc
|
|||
comp.setLayout(new GridLayout(2, false));
|
||||
|
||||
IRemoteConnection remoteConnection = (IRemoteConnection) getElement().getAdapter(IRemoteConnection.class);
|
||||
IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class);
|
||||
ArduinoRemoteConnection arduinoRemote = remoteConnection.getService(ArduinoRemoteConnection.class);
|
||||
|
||||
Label portLabel = new Label(comp, SWT.NONE);
|
||||
portLabel.setText(Messages.ArduinoTargetPropertyPage_0);
|
||||
|
@ -73,8 +75,7 @@ public class ArduinoTargetPropertyPage extends PropertyPage implements IWorkbenc
|
|||
boardSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
try {
|
||||
ArduinoBoard currentBoard = ArduinoBoardManager.instance.getBoard(arduinoRemote.getBoardName(),
|
||||
arduinoRemote.getPlatformName(), arduinoRemote.getPackageName());
|
||||
ArduinoBoard currentBoard = arduinoRemote.getBoard();
|
||||
Collection<ArduinoBoard> boardList = ArduinoBoardManager.instance.getBoards();
|
||||
boards = new ArduinoBoard[boardList.size()];
|
||||
i = 0;
|
||||
|
@ -101,10 +102,14 @@ public class ArduinoTargetPropertyPage extends PropertyPage implements IWorkbenc
|
|||
IRemoteConnectionWorkingCopy workingCopy = remoteConnection.getWorkingCopy();
|
||||
|
||||
String portName = portSelector.getItem(portSelector.getSelectionIndex());
|
||||
workingCopy.setAttribute(IArduinoRemoteConnection.PORT_NAME, portName);
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PORT_NAME, portName);
|
||||
|
||||
ArduinoBoard board = boards[boardSelector.getSelectionIndex()];
|
||||
workingCopy.setAttribute(IArduinoRemoteConnection.BOARD_ID, board.getId());
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.BOARD_NAME, board.getName());
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PLATFORM_NAME, platform.getName());
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PACKAGE_NAME, pkg.getName());
|
||||
|
||||
try {
|
||||
workingCopy.save();
|
||||
|
|
|
@ -2,7 +2,10 @@ package org.eclipse.cdt.arduino.ui.internal.remote;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.IArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPackage;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
|
@ -27,9 +30,16 @@ public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectio
|
|||
if (getConnection() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
workingCopy.setAttribute(IArduinoRemoteConnection.PORT_NAME, page.portName);
|
||||
workingCopy.setAttribute(IArduinoRemoteConnection.BOARD_ID, page.board.getId());
|
||||
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PORT_NAME, page.portName);
|
||||
|
||||
ArduinoBoard board = page.board;
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.BOARD_NAME, board.getName());
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PLATFORM_NAME, platform.getName());
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PACKAGE_NAME, pkg.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,7 +52,7 @@ public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectio
|
|||
public IRemoteConnectionWorkingCopy getConnection() {
|
||||
if (workingCopy == null) {
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(IArduinoRemoteConnection.TYPE_ID);
|
||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
||||
try {
|
||||
workingCopy = connectionType.newConnection(page.name);
|
||||
} catch (RemoteConnectionException e) {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.eclipse.cdt.arduino.ui.internal.remote;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoardManager;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoardManager;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Messages;
|
||||
import org.eclipse.cdt.serial.SerialPort;
|
||||
|
@ -90,7 +93,15 @@ public class NewArduinoTargetWizardPage extends WizardPage {
|
|||
boardCombo = new Combo(comp, SWT.READ_ONLY);
|
||||
boardCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
try {
|
||||
boards = ArduinoBoardManager.instance.getBoards().toArray(new ArduinoBoard[0]);
|
||||
List<ArduinoBoard> boardList = ArduinoBoardManager.instance.getInstalledBoards();
|
||||
Collections.sort(boardList, new Comparator<ArduinoBoard>() {
|
||||
@Override
|
||||
public int compare(ArduinoBoard o1, ArduinoBoard o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
boards = boardList.toArray(new ArduinoBoard[0]);
|
||||
|
||||
for (ArduinoBoard board : boards) {
|
||||
boardCombo.add(board.getName());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue