Skip to content

Commit

Permalink
feat: introducing serial_port dynamic variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaaa committed Aug 30, 2024
1 parent dd0324a commit abc7243
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ openocd_exe = openocd executable file
openocd_scripts = OPENOCD_SCRIPTS represents the value specified in environment variables
jtag_flash_args = JTAG_FLASH_ARGS dynamically converts ${JTAG_FLASH_ARGS} into a command line with -c and -f options. These options are generated based on the current launch target, configuring settings like flash voltage and specifying configuration files for the JTAG interface and target device.
gdb_client_executable = GDB_CLIENT_EXECUTABLE is a dynamic variable that is replaced during the debug session with the appropriate toolchain path automatically based on the selected target.
serial_port = serial_port is a dynamic variable that is replaced by the serial port specified in the launch target
5 changes: 5 additions & 0 deletions bundles/com.espressif.idf.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,10 @@ config-only component and an interface library is created instead."
name="GDB_CLIENT_EXECUTABLE"
resolver="com.espressif.idf.core.variable.GdbClientVariableResolver">
</variable>
<variable
description="%serial_port"
name="serial_port"
resolver="com.espressif.idf.core.variable.UartVariableResolver">
</variable>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.espressif.idf.core.variable;

public enum UartDynamicVariable
{
SERIAL_PORT("serial_port"); //$NON-NLS-1$

private String value;

UartDynamicVariable(String value)
{
this.value = value;
}

public String getValue()
{
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.espressif.idf.core.variable;

import java.util.Arrays;
import java.util.Optional;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IDynamicVariable;
import org.eclipse.core.variables.IDynamicVariableResolver;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;

import com.espressif.idf.core.IDFCorePlugin;
import com.espressif.idf.core.LaunchBarTargetConstants;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.StringUtil;

public class UartVariableResolver implements IDynamicVariableResolver
{

public String resolveValue(IDynamicVariable variable, String argument)
{
return getAppropriateEnumVariable(variable).map(this::resolveForDynamicEnum).orElse(variable.getName());
}

private Optional<UartDynamicVariable> getAppropriateEnumVariable(IDynamicVariable variable)
{
return Arrays.stream(UartDynamicVariable.values()).filter(v -> v.getValue().equals(variable.getName()))
.findFirst();
}

private String resolveForDynamicEnum(UartDynamicVariable enumVariable)
{

return switch (enumVariable)
{
case SERIAL_PORT -> getSerialPort(); // $NON-NLS-1$
};
}

private String getSerialPort()
{
return getActiveLaunchTarget().orElseGet(() -> ILaunchTarget.NULL_TARGET)
.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY);
}

private Optional<ILaunchTarget> getActiveLaunchTarget()
{

try
{
return Optional.of(IDFCorePlugin.getService(ILaunchBarManager.class).getActiveLaunchTarget());
}
catch (CoreException e)
{
Logger.log(e);
}
return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ protected void launchInternal(ILaunchConfiguration configuration, String mode, I
return;
}
String arguments = configuration.getAttribute(IDFLaunchConstants.ATTR_SERIAL_FLASH_ARGUMENTS, espFlashCommand);
arguments = arguments.replace(ESPFlashUtil.SERIAL_PORT, serialPort);
arguments = varManager.performStringSubstitution(arguments);
if (!arguments.isEmpty())
{
Expand Down

0 comments on commit abc7243

Please sign in to comment.