diff --git a/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/core/IDFMonitor.java b/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/core/IDFMonitor.java index ce8f17126..0e0c31c5b 100644 --- a/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/core/IDFMonitor.java +++ b/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/core/IDFMonitor.java @@ -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; } @@ -71,6 +74,10 @@ private List 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()); diff --git a/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/handlers/SerialMonitorHandler.java b/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/handlers/SerialMonitorHandler.java index f2fdf797e..dd4c2375f 100644 --- a/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/handlers/SerialMonitorHandler.java +++ b/bundles/com.espressif.idf.serial.monitor/src/com/espressif/idf/serial/monitor/handlers/SerialMonitorHandler.java @@ -17,13 +17,16 @@ 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() @@ -31,7 +34,8 @@ 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(); diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialConnector.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialConnector.java index 07691b62f..afa0ce315 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialConnector.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialConnector.java @@ -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 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; @@ -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.getEncryptionOption(); serialPort = new SerialPortHandler(portName, this, project); serialPort.open(); @@ -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); } } diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialPortHandler.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialPortHandler.java index 17d7875fb..3fda8468b 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialPortHandler.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialPortHandler.java @@ -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>> openPorts = new HashMap<>(); private Process process; @@ -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; } /** @@ -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); } @@ -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() diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialSettings.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialSettings.java index 3ab791dc4..444571157 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialSettings.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/connector/SerialSettings.java @@ -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.encryption"; //$NON-NLS-1$ private String portName; private String filterText; private String selectedProject; + private boolean encryptionOption; /** * 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$ + encryptionOption = 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(encryptionOption)); } - 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 getEncryptionOption() + { + return encryptionOption; + } + + 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 setEncryptionOption(boolean encryptionOption) + { + this.encryptionOption = encryptionOption; + } + } diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialConfigPanel.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialConfigPanel.java index 1d3858486..6fd72517a 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialConfigPanel.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialConfigPanel.java @@ -26,17 +26,20 @@ import com.espressif.idf.terminal.connector.serial.connector.SerialConnector; import com.espressif.idf.terminal.connector.serial.connector.SerialSettings; -public class SerialConfigPanel extends AbstractExtendedConfigurationPanel { +public class SerialConfigPanel extends AbstractExtendedConfigurationPanel +{ private SerialSettings settings; private SerialSettingsPage page; - public SerialConfigPanel(IConfigurationPanelContainer container) { + public SerialConfigPanel(IConfigurationPanelContainer container) + { super(container); } @Override - public void setupPanel(Composite parent) { + public void setupPanel(Composite parent) + { Composite panel = new Composite(parent, SWT.NONE); panel.setLayout(new GridLayout()); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); @@ -53,8 +56,10 @@ public void setupPanel(Composite parent) { } @Override - public void extractData(Map data) { - if (data == null) { + public void extractData(Map data) + { + if (data == null) + { return; } @@ -62,38 +67,48 @@ public void extractData(Map data) { data.put(SerialSettings.PORT_NAME_ATTR, settings.getPortName()); data.put(SerialSettings.MONITOR_FILTER, settings.getFilterText()); data.put(SerialSettings.SELECTED_PROJECT_ATTR, settings.getProjectName()); + data.put(SerialSettings.ENCRYPTION_ATTR, settings.getEncryptionOption()); - if (getEncoding() != null) { + if (getEncoding() != null) + { data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding()); } } @Override - public void setupData(Map data) { - if (data == null) { + public void setupData(Map data) + { + if (data == null) + { return; } settings.setPortName((String) data.get(SerialSettings.PORT_NAME_ATTR)); settings.setFilterText((String) data.get(SerialSettings.MONITOR_FILTER)); - + Boolean encryptionValue = (Boolean) data.get(SerialSettings.ENCRYPTION_ATTR); + settings.setEncryptionOption(encryptionValue != null && encryptionValue); String encoding = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING); - if (encoding != null) { + if (encoding != null) + { setEncoding(encoding); } } @Override - protected void saveSettingsForHost(boolean add) { + protected void saveSettingsForHost(boolean add) + { } @Override - protected void fillSettingsForHost(String host) { + protected void fillSettingsForHost(String host) + { } @Override - protected String getHostFromSettings() { - if (page != null) { + protected String getHostFromSettings() + { + if (page != null) + { page.saveSettings(); return settings.getPortName(); } diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java index 78628829b..1917980dd 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java @@ -28,6 +28,7 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -60,6 +61,8 @@ public class SerialSettingsPage extends AbstractSettingsPage private String lastUsedSerialPort; private Text filterText; private String filterConfig; + private Button encryptionCheckbox; + private boolean encryptionOption; public SerialSettingsPage(SerialSettings settings, IConfigurationPanel panel) { @@ -71,6 +74,7 @@ public SerialSettingsPage(SerialSettings settings, IConfigurationPanel panel) this.getClass().getSimpleName()); dialogSettings.get(SerialSettings.PORT_NAME_ATTR); filterConfig = dialogSettings.get(SerialSettings.MONITOR_FILTER); + encryptionOption = Boolean.parseBoolean(dialogSettings.get(SerialSettings.ENCRYPTION_ATTR)); lastUsedSerialPort = getLastUsedSerialPort(); @@ -152,6 +156,12 @@ public void widgetSelected(SelectionEvent e) filterText = new Text(comp, SWT.SINGLE | SWT.BORDER); filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + encryptionCheckbox = new Button(comp, SWT.CHECK); + encryptionCheckbox.setText(Messages.SerialSettingsPage_EncryptionOption); + encryptionCheckbox.setToolTipText(Messages.SerialSettingsPage_EncryptionOptionTooltip1 + System.lineSeparator() + + Messages.SerialSettingsPage_EncryptionOptionTooltip2); + encryptionCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + loadSettings(); } @@ -192,6 +202,8 @@ else if (portCombo.getItemCount() > 0) { this.filterText.setText(filterConfig); } + + this.encryptionCheckbox.setSelection(encryptionOption); } @Override @@ -200,10 +212,12 @@ public void saveSettings() settings.setPortName(portCombo.getText()); settings.setFilterText(filterText.getText().trim()); settings.setProject(projectCombo.getText()); + settings.setEncryptionOption(encryptionCheckbox.getSelection()); dialogSettings.put(SerialSettings.SELECTED_PROJECT_ATTR, projectCombo.getText()); dialogSettings.put(SerialSettings.PORT_NAME_ATTR, portCombo.getText()); dialogSettings.put(SerialSettings.MONITOR_FILTER, filterText.getText().trim()); + dialogSettings.put(SerialSettings.ENCRYPTION_ATTR, encryptionCheckbox.getSelection()); } @Override diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/launcher/SerialLauncherDelegate.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/launcher/SerialLauncherDelegate.java index fdb5e48af..28e3277eb 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/launcher/SerialLauncherDelegate.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/launcher/SerialLauncherDelegate.java @@ -30,25 +30,30 @@ import com.espressif.idf.terminal.connector.serial.connector.SerialSettings; import com.espressif.idf.terminal.connector.serial.controls.SerialConfigPanel; -public class SerialLauncherDelegate extends AbstractLauncherDelegate { +public class SerialLauncherDelegate extends AbstractLauncherDelegate +{ @Override - public boolean needsUserConfiguration() { + public boolean needsUserConfiguration() + { return true; } @Override - public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { + public IConfigurationPanel getPanel(IConfigurationPanelContainer container) + { return new SerialConfigPanel(container); } @Override - public ITerminalConnector createTerminalConnector(Map properties) { + public ITerminalConnector createTerminalConnector(Map properties) + { Assert.isNotNull(properties); // Check for the terminal connector id String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); - if (connectorId == null) { + if (connectorId == null) + { connectorId = "com.espressif.idf.terminal.connector.serial.SerialConnector"; //$NON-NLS-1$ } @@ -57,13 +62,16 @@ public ITerminalConnector createTerminalConnector(Map properties settings.setPortName((String) properties.get(SerialSettings.PORT_NAME_ATTR)); settings.setFilterText((String) properties.get(SerialSettings.MONITOR_FILTER)); settings.setProject((String) properties.get(SerialSettings.SELECTED_PROJECT_ATTR)); + Boolean encryptionOption = (Boolean) properties.get(SerialSettings.ENCRYPTION_ATTR); + settings.setEncryptionOption(encryptionOption != null && encryptionOption); // Construct the terminal settings store ISettingsStore store = new SettingsStore(); settings.save(store); // Construct the terminal connector instance ITerminalConnector connector = TerminalConnectorExtension.makeTerminalConnector(connectorId); - if (connector != null) { + if (connector != null) + { // Apply default settings connector.setDefaultSettings(); // And load the real settings @@ -74,7 +82,8 @@ public ITerminalConnector createTerminalConnector(Map properties } @Override - public void execute(Map properties, Done done) { + public void execute(Map properties, Done done) + { Assert.isNotNull(properties); // Set the terminal tab title @@ -83,14 +92,16 @@ public void execute(Map properties, Done done) { // Force a new terminal tab each time it is launched, if not set otherwise from outside // TODO need a command shell service routing to get this - if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) { + if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) + { properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE); } // Get the terminal service ITerminalService terminal = TerminalServiceFactory.getService(); // If not available, we cannot fulfill this request - if (terminal != null) { + if (terminal != null) + { terminal.openConsole(properties, done); } } diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.java index f8d6b9ef0..6fe96948b 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.java @@ -34,6 +34,9 @@ public class Messages extends NLS // **** Declare externalized string id's down here ***** + public static String SerialSettingsPage_EncryptionOption; + public static String SerialSettingsPage_EncryptionOptionTooltip1; + public static String SerialSettingsPage_EncryptionOptionTooltip2; public static String SerialSettingsPage_FilterOptions; public static String SerialSettingsPage_ProjectName; public static String SerialTerminalSettingsPage_SerialPort; diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.properties b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.properties index f04f18d51..27162ce11 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.properties +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/nls/Messages.properties @@ -11,6 +11,9 @@ # QNX Software Systems - Initial API and implementation ############################################################################### +SerialSettingsPage_EncryptionOption=Enable Flash Encryption +SerialSettingsPage_EncryptionOptionTooltip1=Enable Flash Encryption. Ctrl+F and Ctrl+A will trigger the encrypted-flash and encrypted-app-flash commands. +SerialSettingsPage_EncryptionOptionTooltip2=To use encrypted flash, make sure flash encryption is enabled in sdkconfig. SerialSettingsPage_FilterOptions=Filter Options: SerialSettingsPage_ProjectName=Project name: SerialTerminalSettingsPage_SerialPort=Serial port: