Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ public class IDFMonitor
private IProject project;
private String filterOptions;
private int serverPort;
private boolean encryptionOption;

public IDFMonitor(IProject project, String port, String filterOptions, String pythonBinPath, int serverPort)
public IDFMonitor(IProject project, String port, String filterOptions, boolean encryptionOption,
String pythonBinPath, int serverPort)
{
this.project = project;
this.port = port;
this.pythonBinPath = pythonBinPath;
this.filterOptions = filterOptions;
this.encryptionOption = encryptionOption;
this.serverPort = serverPort;
}

Expand All @@ -71,6 +74,10 @@ private List<String> commandArgsWithSocketServer()
args.add(port);
args.add("-b"); //$NON-NLS-1$
args.add(getMonitorBaudRate());
if (encryptionOption)
{
args.add("--encrypted"); //$NON-NLS-1$
}
args.add("--ws"); //$NON-NLS-1$
args.add("ws://localhost:".concat(String.valueOf(serverPort))); //$NON-NLS-1$
args.add(getElfFilePath(project).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ public class SerialMonitorHandler
private String serialPort;
private String filterOptions;
private int serverPort;
private boolean encryptionOption;

public SerialMonitorHandler(IProject project, String serialPort, String filterOptions, int serverPort)
public SerialMonitorHandler(IProject project, String serialPort, String filterOptions, boolean encryptionOption,
int serverPort)
{
this.project = project;
this.serialPort = serialPort;
this.filterOptions = filterOptions;
this.serverPort = serverPort;
this.encryptionOption = encryptionOption;
}

public Process invokeIDFMonitor()
{
// python path
String pythonPath = IDFUtil.getIDFPythonEnvPath();

IDFMonitor monitor = new IDFMonitor(project, serialPort, filterOptions, pythonPath, serverPort);
IDFMonitor monitor = new IDFMonitor(project, serialPort, filterOptions, encryptionOption, pythonPath,
serverPort);
try
{
return monitor.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,55 +28,65 @@
import com.espressif.idf.core.util.StringUtil;
import com.espressif.idf.terminal.connector.serial.activator.Activator;

public class SerialConnector extends TerminalConnectorImpl {
public class SerialConnector extends TerminalConnectorImpl
{

private SerialSettings settings = new SerialSettings();
protected Process process;
protected Thread thread;
protected IProject project;
protected String filterOptions;
protected boolean encryptionOption;
protected ITerminalControl control;
private SerialPortHandler serialPort;

private static Set<String> openPorts = new HashSet<>();

public static boolean isOpen(String portName) {
public static boolean isOpen(String portName)
{
return openPorts.contains(portName);
}

@Override
public OutputStream getTerminalToRemoteStream() {
public OutputStream getTerminalToRemoteStream()
{
return process.getOutputStream();
}

public SerialSettings getSettings() {
public SerialSettings getSettings()
{
return settings;
}

@Override
public String getSettingsSummary() {
public String getSettingsSummary()
{
return settings.getSummary();
}

@Override
public void load(ISettingsStore store) {
public void load(ISettingsStore store)
{
settings.load(store);
}

@Override
public void save(ISettingsStore store) {
public void save(ISettingsStore store)
{
settings.save(store);
}

@Override
public void connect(ITerminalControl control) {
public void connect(ITerminalControl control)
{
super.connect(control);
this.control = control;

//Get selected project - which is required for IDF Monitor
// Get selected project - which is required for IDF Monitor
project = settings.getProject();

if (project == null) {
if (project == null)
{
String message = "project can't be null. Make sure you select a project before launch a serial monitor"; //$NON-NLS-1$
Activator.log(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), message, null));
return;
Expand All @@ -85,7 +95,7 @@ public void connect(ITerminalControl control) {
String portName = settings.getPortName();
filterOptions = settings.getFilterText();
filterOptions = StringUtil.isEmpty(filterOptions) ? StringUtil.EMPTY : filterOptions;

encryptionOption = settings.getExtraMonitorOptions();
serialPort = new SerialPortHandler(portName, this, project);
serialPort.open();

Expand All @@ -94,13 +104,18 @@ public void connect(ITerminalControl control) {
}

@Override
protected void doDisconnect() {
protected void doDisconnect()
{

if (serialPort != null && serialPort.isOpen()) {
if (serialPort != null && serialPort.isOpen())
{
openPorts.remove(serialPort.getPortName());
try {
try
{
serialPort.close();
} catch (IOException e) {
}
catch (IOException e)
{
Activator.log(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class SerialPortHandler
private boolean isOpen;
private boolean isPaused;
private Object pauseMutex = new Object();
private IProject project;

private static final Map<String, LinkedList<WeakReference<SerialPortHandler>>> openPorts = new HashMap<>();

private Process process;
Expand All @@ -37,14 +35,7 @@ public class SerialPortHandler

private static String adjustPortName(String portName)
{
if (System.getProperty("os.name").startsWith("Windows") && !portName.startsWith("\\\\.\\")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
{
return portName; // $NON-NLS-1$
}
else
{
return portName;
}
return portName;
}

/**
Expand Down Expand Up @@ -88,7 +79,6 @@ public SerialPortHandler(String portName, SerialConnector serialConnector, IProj
{
this.portName = adjustPortName(portName);
this.serialConnector = serialConnector;
this.project = project;
this.serverMessageHandler = new SocketServerMessageHandler(serialConnector, project);
}

Expand Down Expand Up @@ -123,7 +113,7 @@ public synchronized void open()

// Hook IDF Monitor with the CDT serial monitor
SerialMonitorHandler serialMonitorHandler = new SerialMonitorHandler(serialConnector.project, portName,
serialConnector.filterOptions, serverPort);
serialConnector.filterOptions, serialConnector.encryptionOption, serverPort);
process = serialMonitorHandler.invokeIDFMonitor();
serialConnector.process = process;
thread = new Thread()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,92 @@

import com.espressif.idf.core.util.StringUtil;

public class SerialSettings {
public class SerialSettings
{

public static final String PORT_NAME_ATTR = "cdtserial.portName"; //$NON-NLS-1$
public static final String MONITOR_FILTER = "idf.monitor.filter"; //$NON-NLS-1$
public static final String SELECTED_PROJECT_ATTR = "idf.monitor.project"; //$NON-NLS-1$
public static final String ENCRYPTION_ATTR = "idf.monitor.extraOptions"; //$NON-NLS-1$

private String portName;
private String filterText;
private String selectedProject;
private boolean extraMonitorOpts;

/**
* Load information into the RemoteSettings object.
*/
public void load(ISettingsStore store) {
public void load(ISettingsStore store)
{
portName = store.get(PORT_NAME_ATTR, ""); //$NON-NLS-1$
filterText = store.get(MONITOR_FILTER, ""); //$NON-NLS-1$
selectedProject = store.get(SELECTED_PROJECT_ATTR, ""); //$NON-NLS-1$
extraMonitorOpts = Boolean.parseBoolean(store.get(ENCRYPTION_ATTR, "false")); //$NON-NLS-1$
}

/**
* Extract information from the RemoteSettings object.
*/
public void save(ISettingsStore store) {
public void save(ISettingsStore store)
{
store.put(PORT_NAME_ATTR, portName);
store.put(MONITOR_FILTER, filterText);
store.put(SELECTED_PROJECT_ATTR, selectedProject);
store.put(ENCRYPTION_ATTR, Boolean.toString(extraMonitorOpts));
}

public String getPortName() {
public String getPortName()
{
return portName;
}

public String getFilterText() {
public String getFilterText()
{
return filterText;
}

public String getProjectName() {
public String getProjectName()
{
return selectedProject;
}

public IProject getProject() {
public boolean getExtraMonitorOptions()
{
return extraMonitorOpts;
}

public IProject getProject()
{

return !StringUtil.isEmpty(selectedProject)
? ResourcesPlugin.getWorkspace().getRoot().getProject(selectedProject)
: null;
}

public void setPortName(String portName) {
public void setPortName(String portName)
{
this.portName = portName;
}

public void setFilterText(String filterText) {
public void setFilterText(String filterText)
{
this.filterText = filterText;
}

public String getSummary() {
public String getSummary()
{
return portName;
}

public void setProject(String projectName) {
public void setProject(String projectName)
{
this.selectedProject = projectName;
}

public void setExtraOptions(boolean extraOptions)
{
this.extraMonitorOpts = extraOptions;
}

}
Loading
Loading