Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f9a151f

Browse files
committedAug 30, 2022
Added methods to obtain specific monitor settings for a board
1 parent aa41d72 commit f9a151f

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed
 

‎arduino/cores/board.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,8 @@ func (b *Board) IsBoardMatchingIDProperties(query *properties.Map) bool {
173173
}
174174
return false
175175
}
176+
177+
// GetMonitorSettings returns the settings for the pluggable monitor of the given protocol
178+
func (b *Board) GetMonitorSettings(protocol string) *properties.Map {
179+
return b.Properties.SubTree("monitor_port." + protocol)
180+
}

‎arduino/cores/packagemanager/loader.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ func (pm *Builder) loadBoards(platform *cores.PlatformRelease) error {
504504
convertVidPidIdentificationPropertiesToPluggableDiscovery(boardProperties)
505505
convertUploadToolsToPluggableDiscovery(boardProperties)
506506
}
507+
convertLegacySerialPortRTSDTRSettingsToPluggableMonitor(boardProperties)
507508

508509
// The board's ID must be available in a board's properties since it can
509510
// be used in all configuration files for several reasons, like setting compilation
@@ -523,6 +524,24 @@ func (pm *Builder) loadBoards(platform *cores.PlatformRelease) error {
523524
return nil
524525
}
525526

527+
// Converts the old:
528+
//
529+
// - xxx.serial.disableRTS=true
530+
// - xxx.serial.disableDTR=true
531+
//
532+
// properties into pluggable monitor compatible:
533+
//
534+
// - xxx.monitor_port.serial.rts=off
535+
// - xxx.monitor_port.serial.dtr=off
536+
func convertLegacySerialPortRTSDTRSettingsToPluggableMonitor(boardProperties *properties.Map) {
537+
if boardProperties.GetBoolean("serial.disableDTR") {
538+
boardProperties.Set("monitor_port.serial.dtr", "off")
539+
}
540+
if boardProperties.GetBoolean("serial.disableRTS") {
541+
boardProperties.Set("monitor_port.serial.rts", "off")
542+
}
543+
}
544+
526545
// Converts the old:
527546
//
528547
// - xxx.vid.N
@@ -532,7 +551,6 @@ func (pm *Builder) loadBoards(platform *cores.PlatformRelease) error {
532551
//
533552
// - xxx.upload_port.N.vid
534553
// - xxx.upload_port.N.pid
535-
//
536554
func convertVidPidIdentificationPropertiesToPluggableDiscovery(boardProperties *properties.Map) {
537555
n := 0
538556
outputVidPid := func(vid, pid string) {

‎arduino/cores/packagemanager/loader_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ arduino_zero_native.pid.3=0x024d
106106
}`, zero4.Dump())
107107
}
108108

109+
func TestDisableDTRRTSConversionToPluggableMonitor(t *testing.T) {
110+
m, err := properties.LoadFromBytes([]byte(`
111+
arduino_zero.serial.disableDTR=true
112+
arduino_zero.serial.disableRTS=true
113+
arduino_zero_edbg.serial.disableDTR=false
114+
arduino_zero_edbg.serial.disableRTS=true
115+
`))
116+
require.NoError(t, err)
117+
118+
{
119+
zero := m.SubTree("arduino_zero")
120+
convertLegacySerialPortRTSDTRSettingsToPluggableMonitor(zero)
121+
require.Equal(t, `properties.Map{
122+
"serial.disableDTR": "true",
123+
"serial.disableRTS": "true",
124+
"monitor_port.serial.dtr": "off",
125+
"monitor_port.serial.rts": "off",
126+
}`, zero.Dump())
127+
}
128+
{
129+
zero_edbg := m.SubTree("arduino_zero_edbg")
130+
convertLegacySerialPortRTSDTRSettingsToPluggableMonitor(zero_edbg)
131+
require.Equal(t, `properties.Map{
132+
"serial.disableDTR": "false",
133+
"serial.disableRTS": "true",
134+
"monitor_port.serial.rts": "off",
135+
}`, zero_edbg.Dump())
136+
}
137+
}
138+
109139
func TestLoadDiscoveries(t *testing.T) {
110140
// Create all the necessary data to load discoveries
111141
fakePath := paths.New("fake-path")

0 commit comments

Comments
 (0)
Please sign in to comment.