feat: auto guess port for monitoring
This commit is contained in:
@@ -360,12 +360,16 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = monitor.Monitor(monitor.MonitorConfig{
|
||||
monitorConfig := monitor.MonitorConfig{
|
||||
Port: ctx.buildConf.Port,
|
||||
Target: conf.Target,
|
||||
Executable: finalApp,
|
||||
BaudRate: conf.BaudRate,
|
||||
}, verbose)
|
||||
}
|
||||
if ctx.crossCompile.Flash.Method != "openocd" {
|
||||
monitorConfig.SerialPort = ctx.crossCompile.Flash.SerialPort
|
||||
}
|
||||
err = monitor.Monitor(monitorConfig, verbose)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -491,8 +491,8 @@ func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// useTarget loads configuration from a target name (e.g., "rp2040", "wasi")
|
||||
func useTarget(targetName string) (export Export, err error) {
|
||||
// UseTarget loads configuration from a target name (e.g., "rp2040", "wasi")
|
||||
func UseTarget(targetName string) (export Export, err error) {
|
||||
resolver := targets.NewDefaultResolver()
|
||||
|
||||
config, err := resolver.Resolve(targetName)
|
||||
@@ -716,7 +716,7 @@ func useTarget(targetName string) (export Export, err error) {
|
||||
// If targetName is provided, it takes precedence over goos/goarch
|
||||
func Use(goos, goarch string, wasiThreads bool, targetName string) (export Export, err error) {
|
||||
if targetName != "" && !strings.HasPrefix(targetName, "wasm") && !strings.HasPrefix(targetName, "wasi") {
|
||||
return useTarget(targetName)
|
||||
return UseTarget(targetName)
|
||||
}
|
||||
return use(goos, goarch, wasiThreads)
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ func TestUseTarget(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
export, err := useTarget(tc.targetName)
|
||||
export, err := UseTarget(tc.targetName)
|
||||
|
||||
if tc.expectError {
|
||||
if err == nil {
|
||||
|
||||
@@ -22,11 +22,12 @@ import (
|
||||
|
||||
// MonitorConfig contains configuration for the monitor
|
||||
type MonitorConfig struct {
|
||||
Port string // Serial port device
|
||||
Target string // Target name for crosscompile config
|
||||
BaudRate int // Baudrate of serial monitor
|
||||
Executable string // Optional path to executable for debug info
|
||||
WaitTime int // Wait time for port connection (ms)
|
||||
Port string // Serial port device
|
||||
Target string // Target name for crosscompile config
|
||||
BaudRate int // Baudrate of serial monitor
|
||||
Executable string // Optional path to executable for debug info
|
||||
WaitTime int // Wait time for port connection (ms)
|
||||
SerialPort []string // List of serial ports to use
|
||||
}
|
||||
|
||||
// Monitor starts serial monitoring with the given configuration
|
||||
@@ -40,7 +41,7 @@ func Monitor(config MonitorConfig, verbose bool) error {
|
||||
}
|
||||
|
||||
// Resolve port using flash.GetPort
|
||||
port, err := flash.GetPort(config.Port, nil)
|
||||
port, err := flash.GetPort(config.Port, config.SerialPort)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find port: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user