@@ -19,9 +19,9 @@ import (
19
19
"bytes"
20
20
"context"
21
21
"errors"
22
- "fmt"
23
22
"io"
24
23
"os"
24
+ "slices"
25
25
"sort"
26
26
"strings"
27
27
"time"
@@ -34,6 +34,7 @@ import (
34
34
"github.com/arduino/arduino-cli/internal/cli/instance"
35
35
"github.com/arduino/arduino-cli/internal/i18n"
36
36
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
37
+ "github.com/arduino/go-properties-orderedmap"
37
38
"github.com/fatih/color"
38
39
"github.com/sirupsen/logrus"
39
40
"github.com/spf13/cobra"
@@ -58,6 +59,8 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
58
59
Long : i18n .Tr ("Open a communication port with a board." ),
59
60
Example : "" +
60
61
" " + os .Args [0 ] + " monitor -p /dev/ttyACM0\n " +
62
+ " " + os .Args [0 ] + " monitor -p /dev/ttyACM0 -b arduino:avr:uno\n " +
63
+ " " + os .Args [0 ] + " monitor -p /dev/ttyACM0 --config 115200\n " +
61
64
" " + os .Args [0 ] + " monitor -p /dev/ttyACM0 --describe" ,
62
65
Run : func (cmd * cobra.Command , args []string ) {
63
66
sketchPath := ""
@@ -89,13 +92,6 @@ func runMonitorCmd(
89
92
quiet = true
90
93
}
91
94
92
- var (
93
- inst * rpc.Instance
94
- profile * rpc.SketchProfile
95
- fqbn string
96
- defaultPort , defaultProtocol string
97
- )
98
-
99
95
// Flags takes maximum precedence over sketch.yaml
100
96
// If {--port --fqbn --profile} are set we ignore the profile.
101
97
// If both {--port --profile} are set we read the fqbn in the following order: profile -> default_fqbn -> discovery
@@ -110,9 +106,9 @@ func runMonitorCmd(
110
106
)
111
107
}
112
108
sketch := resp .GetSketch ()
113
- if sketch != nil {
114
- defaultPort , defaultProtocol = sketch . GetDefaultPort (), sketch . GetDefaultProtocol ()
115
- }
109
+
110
+ var inst * rpc. Instance
111
+ var profile * rpc. SketchProfile
116
112
if fqbnArg .String () == "" {
117
113
if profileArg .Get () == "" {
118
114
inst , profile = instance .CreateAndInitWithProfile (ctx , srv , sketch .GetDefaultProfile ().GetName (), sketchPath )
@@ -123,11 +119,13 @@ func runMonitorCmd(
123
119
if inst == nil {
124
120
inst = instance .CreateAndInit (ctx , srv )
125
121
}
122
+
126
123
// Priority on how to retrieve the fqbn
127
124
// 1. from flag
128
125
// 2. from profile
129
126
// 3. from default_fqbn specified in the sketch.yaml
130
127
// 4. try to detect from the port
128
+ var fqbn string
131
129
switch {
132
130
case fqbnArg .String () != "" :
133
131
fqbn = fqbnArg .String ()
@@ -136,15 +134,19 @@ func runMonitorCmd(
136
134
case sketch .GetDefaultFqbn () != "" :
137
135
fqbn = sketch .GetDefaultFqbn ()
138
136
default :
139
- fqbn , _ = portArgs .DetectFQBN (ctx , inst , srv )
137
+ fqbn , _ , _ = portArgs .DetectFQBN (ctx , inst , srv )
140
138
}
141
139
140
+ var defaultPort , defaultProtocol string
141
+ if sketch != nil {
142
+ defaultPort , defaultProtocol = sketch .GetDefaultPort (), sketch .GetDefaultProtocol ()
143
+ }
142
144
portAddress , portProtocol , err := portArgs .GetPortAddressAndProtocol (ctx , inst , srv , defaultPort , defaultProtocol )
143
145
if err != nil {
144
146
feedback .FatalError (err , feedback .ErrGeneric )
145
147
}
146
148
147
- enumerateResp , err := srv .EnumerateMonitorPortSettings (ctx , & rpc.EnumerateMonitorPortSettingsRequest {
149
+ defaultSettings , err := srv .EnumerateMonitorPortSettings (ctx , & rpc.EnumerateMonitorPortSettingsRequest {
148
150
Instance : inst ,
149
151
PortProtocol : portProtocol ,
150
152
Fqbn : fqbn ,
@@ -153,14 +155,19 @@ func runMonitorCmd(
153
155
feedback .Fatal (i18n .Tr ("Error getting port settings details: %s" , err ), feedback .ErrGeneric )
154
156
}
155
157
if describe {
156
- settings := make ([]* result.MonitorPortSettingDescriptor , len (enumerateResp .GetSettings ()))
157
- for i , v := range enumerateResp .GetSettings () {
158
+ settings := make ([]* result.MonitorPortSettingDescriptor , len (defaultSettings .GetSettings ()))
159
+ for i , v := range defaultSettings .GetSettings () {
158
160
settings [i ] = result .NewMonitorPortSettingDescriptor (v )
159
161
}
160
162
feedback .PrintResult (& detailsResult {Settings : settings })
161
163
return
162
164
}
163
165
166
+ actualConfigurationLabels := properties .NewMap ()
167
+ for _ , setting := range defaultSettings .GetSettings () {
168
+ actualConfigurationLabels .Set (setting .GetSettingId (), setting .GetValue ())
169
+ }
170
+
164
171
configuration := & rpc.MonitorPortConfiguration {}
165
172
if len (configs ) > 0 {
166
173
for _ , config := range configs {
@@ -173,7 +180,7 @@ func runMonitorCmd(
173
180
}
174
181
175
182
var setting * rpc.MonitorPortSettingDescriptor
176
- for _ , s := range enumerateResp .GetSettings () {
183
+ for _ , s := range defaultSettings .GetSettings () {
177
184
if k == "" {
178
185
if contains (s .GetEnumValues (), v ) {
179
186
setting = s
@@ -196,10 +203,7 @@ func runMonitorCmd(
196
203
SettingId : setting .GetSettingId (),
197
204
Value : v ,
198
205
})
199
- if ! quiet {
200
- feedback .Print (i18n .Tr ("Monitor port settings:" ))
201
- feedback .Print (fmt .Sprintf ("%s=%s" , setting .GetSettingId (), v ))
202
- }
206
+ actualConfigurationLabels .Set (setting .GetSettingId (), v )
203
207
}
204
208
}
205
209
@@ -229,7 +233,6 @@ func runMonitorCmd(
229
233
}
230
234
ttyIn = io .TeeReader (ttyIn , ctrlCDetector )
231
235
}
232
-
233
236
monitorServer , portProxy := commands .MonitorServerToReadWriteCloser (ctx , & rpc.MonitorPortOpenRequest {
234
237
Instance : inst ,
235
238
Port : & rpc.Port {Address : portAddress , Protocol : portProtocol },
@@ -238,6 +241,21 @@ func runMonitorCmd(
238
241
})
239
242
go func () {
240
243
if ! quiet {
244
+ if len (configs ) == 0 {
245
+ if fqbn != "" {
246
+ feedback .Print (i18n .Tr ("Using default monitor configuration for board: %s" , fqbn ))
247
+ } else if portProtocol == "serial" {
248
+ feedback .Print (i18n .Tr ("Using generic monitor configuration.\n WARNING: Your board may require different settings to work!\n " ))
249
+ }
250
+ }
251
+ feedback .Print (i18n .Tr ("Monitor port settings:" ))
252
+ keys := actualConfigurationLabels .Keys ()
253
+ slices .Sort (keys )
254
+ for _ , k := range keys {
255
+ feedback .Printf (" %s=%s" , k , actualConfigurationLabels .Get (k ))
256
+ }
257
+ feedback .Print ("" )
258
+
241
259
feedback .Print (i18n .Tr ("Connecting to %s. Press CTRL-C to exit." , portAddress ))
242
260
}
243
261
if err := srv .Monitor (monitorServer ); err != nil {
0 commit comments