@@ -67,7 +67,7 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab
6767 }
6868 defer release ()
6969
70- m , err := findMonitorForProtocolAndBoard (pme , req .GetPort ().GetProtocol (), req .GetFqbn ())
70+ m , boardSettings , err := findMonitorAndSettingsForProtocolAndBoard (pme , req .GetPort ().GetProtocol (), req .GetFqbn ())
7171 if err != nil {
7272 return nil , nil , err
7373 }
@@ -82,18 +82,25 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab
8282 return nil , nil , & arduino.FailedMonitorError {Cause : err }
8383 }
8484
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
9086 if portConfig := req .GetPortConfiguration (); portConfig != nil {
9187 for _ , setting := range portConfig .Settings {
88+ boardSettings .Remove (setting .SettingId ) // Remove board settings overridden by the user
9289 if err := m .Configure (setting .SettingId , setting .Value ); err != nil {
9390 logrus .Errorf ("Could not set configuration %s=%s: %s" , setting .SettingId , setting .Value , err )
9491 }
9592 }
9693 }
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+ }
97104
98105 logrus .Infof ("Port %s successfully opened" , req .GetPort ().GetAddress ())
99106 return & PortProxy {
@@ -106,36 +113,39 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab
106113 }, descriptor , nil
107114}
108115
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 ) {
110117 if protocol == "" {
111- return nil , & arduino.MissingPortProtocolError {}
118+ return nil , nil , & arduino.MissingPortProtocolError {}
112119 }
113120
114121 var monitorDepOrRecipe * cores.MonitorDependency
122+ boardSettings := properties .NewMap ()
115123
116124 // If a board is specified search the monitor in the board package first
117125 if fqbn != "" {
118126 fqbn , err := cores .ParseFQBN (fqbn )
119127 if err != nil {
120- return nil , & arduino.InvalidFQBNError {Cause : err }
128+ return nil , nil , & arduino.InvalidFQBNError {Cause : err }
121129 }
122130
123131 _ , boardPlatform , _ , boardProperties , _ , err := pme .ResolveFQBN (fqbn )
124132 if err != nil {
125- return nil , & arduino.UnknownFQBNError {Cause : err }
133+ return nil , nil , & arduino.UnknownFQBNError {Cause : err }
126134 }
127135
136+ boardSettings = cores .GetMonitorSettings (protocol , boardProperties )
137+
128138 if mon , ok := boardPlatform .Monitors [protocol ]; ok {
129139 monitorDepOrRecipe = mon
130140 } else if recipe , ok := boardPlatform .MonitorsDevRecipes [protocol ]; ok {
131141 // If we have a recipe we must resolve it
132142 cmdLine := boardProperties .ExpandPropsInString (recipe )
133143 cmdArgs , err := properties .SplitQuotedString (cmdLine , `"'` , false )
134144 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 }
136146 }
137147 id := fmt .Sprintf ("%s-%s" , boardPlatform , protocol )
138- return pluggableMonitor .New (id , cmdArgs ... ), nil
148+ return pluggableMonitor .New (id , cmdArgs ... ), boardSettings , nil
139149 }
140150 }
141151
@@ -150,17 +160,17 @@ func findMonitorForProtocolAndBoard(pme *packagemanager.Explorer, protocol, fqbn
150160 }
151161
152162 if monitorDepOrRecipe == nil {
153- return nil , & arduino.NoMonitorAvailableForProtocolError {Protocol : protocol }
163+ return nil , nil , & arduino.NoMonitorAvailableForProtocolError {Protocol : protocol }
154164 }
155165
156166 // If it is a monitor dependency, resolve tool and create a monitor client
157167 tool := pme .FindMonitorDependency (monitorDepOrRecipe )
158168 if tool == nil {
159- return nil , & arduino.MonitorNotFoundError {Monitor : monitorDepOrRecipe .String ()}
169+ return nil , nil , & arduino.MonitorNotFoundError {Monitor : monitorDepOrRecipe .String ()}
160170 }
161171
162172 return pluggableMonitor .New (
163173 monitorDepOrRecipe .Name ,
164174 tool .InstallDir .Join (monitorDepOrRecipe .Name ).String (),
165- ), nil
175+ ), boardSettings , nil
166176}
0 commit comments