@@ -67,7 +67,7 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab
67
67
}
68
68
defer release ()
69
69
70
- m , err := findMonitorForProtocolAndBoard (pme , req .GetPort ().GetProtocol (), req .GetFqbn ())
70
+ m , boardSettings , err := findMonitorAndSettingsForProtocolAndBoard (pme , req .GetPort ().GetProtocol (), req .GetFqbn ())
71
71
if err != nil {
72
72
return nil , nil , err
73
73
}
@@ -82,18 +82,25 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab
82
82
return nil , nil , & arduino.FailedMonitorError {Cause : err }
83
83
}
84
84
85
- monIO , err := m .Open (req .GetPort ().GetAddress (), req .GetPort ().GetProtocol ())
86
- if err != nil {
87
- m .Quit ()
88
- return nil , nil , & arduino.FailedMonitorError {Cause : err }
89
- }
85
+ // Apply user-requested settings
90
86
if portConfig := req .GetPortConfiguration (); portConfig != nil {
91
87
for _ , setting := range portConfig .Settings {
88
+ boardSettings .Remove (setting .SettingId ) // Remove board settings overridden by the user
92
89
if err := m .Configure (setting .SettingId , setting .Value ); err != nil {
93
90
logrus .Errorf ("Could not set configuration %s=%s: %s" , setting .SettingId , setting .Value , err )
94
91
}
95
92
}
96
93
}
94
+ // Apply specific board settings
95
+ for setting , value := range boardSettings .AsMap () {
96
+ m .Configure (setting , value )
97
+ }
98
+
99
+ monIO , err := m .Open (req .GetPort ().GetAddress (), req .GetPort ().GetProtocol ())
100
+ if err != nil {
101
+ m .Quit ()
102
+ return nil , nil , & arduino.FailedMonitorError {Cause : err }
103
+ }
97
104
98
105
logrus .Infof ("Port %s successfully opened" , req .GetPort ().GetAddress ())
99
106
return & PortProxy {
@@ -106,36 +113,39 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab
106
113
}, descriptor , nil
107
114
}
108
115
109
- func findMonitorForProtocolAndBoard (pme * packagemanager.Explorer , protocol , fqbn string ) (* pluggableMonitor.PluggableMonitor , error ) {
116
+ func findMonitorAndSettingsForProtocolAndBoard (pme * packagemanager.Explorer , protocol , fqbn string ) (* pluggableMonitor.PluggableMonitor , * properties. Map , error ) {
110
117
if protocol == "" {
111
- return nil , & arduino.MissingPortProtocolError {}
118
+ return nil , nil , & arduino.MissingPortProtocolError {}
112
119
}
113
120
114
121
var monitorDepOrRecipe * cores.MonitorDependency
122
+ boardSettings := properties .NewMap ()
115
123
116
124
// If a board is specified search the monitor in the board package first
117
125
if fqbn != "" {
118
126
fqbn , err := cores .ParseFQBN (fqbn )
119
127
if err != nil {
120
- return nil , & arduino.InvalidFQBNError {Cause : err }
128
+ return nil , nil , & arduino.InvalidFQBNError {Cause : err }
121
129
}
122
130
123
- _ , boardPlatform , _ , boardProperties , _ , err := pme .ResolveFQBN (fqbn )
131
+ _ , boardPlatform , board , boardProperties , _ , err := pme .ResolveFQBN (fqbn )
124
132
if err != nil {
125
- return nil , & arduino.UnknownFQBNError {Cause : err }
133
+ return nil , nil , & arduino.UnknownFQBNError {Cause : err }
126
134
}
127
135
136
+ boardSettings = board .GetMonitorSettings (protocol )
137
+
128
138
if mon , ok := boardPlatform .Monitors [protocol ]; ok {
129
139
monitorDepOrRecipe = mon
130
140
} else if recipe , ok := boardPlatform .MonitorsDevRecipes [protocol ]; ok {
131
141
// If we have a recipe we must resolve it
132
142
cmdLine := boardProperties .ExpandPropsInString (recipe )
133
143
cmdArgs , err := properties .SplitQuotedString (cmdLine , `"'` , false )
134
144
if err != nil {
135
- return nil , & arduino.InvalidArgumentError {Message : tr ("Invalid recipe in platform.txt" ), Cause : err }
145
+ return nil , nil , & arduino.InvalidArgumentError {Message : tr ("Invalid recipe in platform.txt" ), Cause : err }
136
146
}
137
147
id := fmt .Sprintf ("%s-%s" , boardPlatform , protocol )
138
- return pluggableMonitor .New (id , cmdArgs ... ), nil
148
+ return pluggableMonitor .New (id , cmdArgs ... ), boardSettings , nil
139
149
}
140
150
}
141
151
@@ -150,17 +160,17 @@ func findMonitorForProtocolAndBoard(pme *packagemanager.Explorer, protocol, fqbn
150
160
}
151
161
152
162
if monitorDepOrRecipe == nil {
153
- return nil , & arduino.NoMonitorAvailableForProtocolError {Protocol : protocol }
163
+ return nil , nil , & arduino.NoMonitorAvailableForProtocolError {Protocol : protocol }
154
164
}
155
165
156
166
// If it is a monitor dependency, resolve tool and create a monitor client
157
167
tool := pme .FindMonitorDependency (monitorDepOrRecipe )
158
168
if tool == nil {
159
- return nil , & arduino.MonitorNotFoundError {Monitor : monitorDepOrRecipe .String ()}
169
+ return nil , nil , & arduino.MonitorNotFoundError {Monitor : monitorDepOrRecipe .String ()}
160
170
}
161
171
162
172
return pluggableMonitor .New (
163
173
monitorDepOrRecipe .Name ,
164
174
tool .InstallDir .Join (monitorDepOrRecipe .Name ).String (),
165
- ), nil
175
+ ), boardSettings , nil
166
176
}
0 commit comments