Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "rts" and "dtr" configuration parameters. #21

Merged
merged 8 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-go-dependencies-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Check Go Dependencies

env:
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
GO_VERSION: "1.17"
GO_VERSION: "1.18.5"

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Check Go

env:
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
GO_VERSION: "1.17"
GO_VERSION: "1.18.5"

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
Expand Down
2 changes: 1 addition & 1 deletion .licenses/serial-monitor/go/go.bug.st/serial.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: go.bug.st/serial
version: v1.3.5
version: v1.4.0
type: go
summary: Package serial is a cross-platform serial library for the go language.
homepage: https://pkg.go.dev/go.bug.st/serial
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
name: go.bug.st/serial/unixutils
version: v1.3.5
version: v1.4.0
type: go
summary:
homepage: https://pkg.go.dev/go.bug.st/serial/unixutils
license: bsd-3-clause
licenses:
- sources: serial@v1.3.5/LICENSE
- sources: serial@v1.4.0/LICENSE
text: |2+

Copyright (c) 2014-2021, Cristian Maglie.
Expand Down Expand Up @@ -41,7 +41,7 @@ licenses:
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

- sources: serial@v1.3.5/README.md
- sources: serial@v1.4.0/README.md
text: |-
The software is release under a [BSD 3-clause license]

Expand Down
63 changes: 63 additions & 0 deletions .licenses/serial-monitor/go/golang.org/x/exp/constraints.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: golang.org/x/exp/constraints
version: v0.0.0-20220722155223-a9213eeb770e
type: go
summary: Package constraints defines a set of useful constraints to be used with type
parameters.
homepage: https://pkg.go.dev/golang.org/x/exp/constraints
license: bsd-3-clause
licenses:
- sources: exp@v0.0.0-20220722155223-a9213eeb770e/LICENSE
text: |
Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- sources: exp@v0.0.0-20220722155223-a9213eeb770e/PATENTS
text: |
Additional IP Rights Grant (Patents)

"This implementation" means the copyrightable works distributed by
Google as part of the Go project.

Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.
notices: []
62 changes: 62 additions & 0 deletions .licenses/serial-monitor/go/golang.org/x/exp/slices.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
name: golang.org/x/exp/slices
version: v0.0.0-20220722155223-a9213eeb770e
type: go
summary: Package slices defines various functions useful with slices of any type.
homepage: https://pkg.go.dev/golang.org/x/exp/slices
license: bsd-3-clause
licenses:
- sources: exp@v0.0.0-20220722155223-a9213eeb770e/LICENSE
text: |
Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- sources: exp@v0.0.0-20220722155223-a9213eeb770e/PATENTS
text: |
Additional IP Rights Grant (Patents)

"This implementation" means the copyrightable works distributed by
Google as part of the Go project.

Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.
notices: []
2 changes: 1 addition & 1 deletion DistTasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version: "3"

vars:
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
GO_VERSION: "1.17.5"
GO_VERSION: "1.18.5"
CHECKSUM_FILE: "{{.VERSION}}-checksums.txt"

tasks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The `serial-monitor` tool is a command line program that interacts via stdio. It

## How to build

Install a recent go environment (>=13.0) and run `go build`. The executable `serial-monitor` will be produced in your working directory.
Install a recent go environment and run `go build`. The executable `serial-monitor` will be produced in your working directory.

## Usage

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/arduino/serial-monitor

go 1.17
go 1.18

require (
github.com/arduino/pluggable-monitor-protocol-handler v0.9.2
go.bug.st/serial v1.3.5
go.bug.st/serial v1.4.0
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
)

require (
Expand Down
13 changes: 4 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ github.com/arduino/pluggable-monitor-protocol-handler v0.9.2 h1:vb5AmE3bT9we5Ej4
github.com/arduino/pluggable-monitor-protocol-handler v0.9.2/go.mod h1:vMG8tgHyE+hli26oT0JB/M7NxUMzzWoU5wd6cgJQRK4=
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand All @@ -11,15 +10,11 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
go.bug.st/serial v1.3.5 h1:k50SqGZCnHZ2MiBQgzccXWG+kd/XpOs1jUljpDDKzaE=
go.bug.st/serial v1.3.5/go.mod h1:z8CesKorE90Qr/oRSJiEuvzYRKol9r/anJZEb5kt304=
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
go.bug.st/serial v1.4.0 h1:IXHzPVbUBbql66lQZ1iV9LWzGXT5lh6S9gZxHK/KyQE=
go.bug.st/serial v1.4.0/go.mod h1:z8CesKorE90Qr/oRSJiEuvzYRKol9r/anJZEb5kt304=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
74 changes: 56 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/serial-monitor/args"
"github.com/arduino/serial-monitor/version"
"go.bug.st/serial"
"golang.org/x/exp/slices"
)

func main() {
Expand Down Expand Up @@ -66,8 +67,8 @@ func NewSerialMonitor() *SerialMonitor {
"parity": {
Label: "Parity",
Type: "enum",
Values: []string{"None", "Even", "Odd", "Mark", "Space"},
Selected: "None",
Values: []string{"none", "even", "odd", "mark", "space"},
Selected: "none",
},
"bits": {
Label: "Data bits",
Expand All @@ -81,6 +82,18 @@ func NewSerialMonitor() *SerialMonitor {
Values: []string{"1", "1.5", "2"},
Selected: "1",
},
"rts": {
Label: "RTS",
Type: "enum",
Values: []string{"on", "off"},
Selected: "on",
},
"dtr": {
Label: "DTR",
Type: "enum",
Values: []string{"on", "off"},
Selected: "on",
},
},
},
openedPort: false,
Expand All @@ -99,25 +112,39 @@ func (d *SerialMonitor) Describe() (*monitor.PortDescriptor, error) {

// Configure is the handler for the pluggable-monitor CONFIGURE command
func (d *SerialMonitor) Configure(parameterName string, value string) error {
if d.serialSettings.ConfigurationParameter[parameterName] == nil {
parameter, ok := d.serialSettings.ConfigurationParameter[parameterName]
if !ok {
return fmt.Errorf("could not find parameter named %s", parameterName)
}
values := d.serialSettings.ConfigurationParameter[parameterName].Values
for _, i := range values {
if i == value {
oldValue := d.serialSettings.ConfigurationParameter[parameterName].Selected
d.serialSettings.ConfigurationParameter[parameterName].Selected = value
if d.openedPort {
err := d.serialPort.SetMode(d.getMode())
if err != nil {
d.serialSettings.ConfigurationParameter[parameterName].Selected = oldValue
return errors.New(err.Error())
}
}
return nil
if !slices.Contains(parameter.Values, value) {
return fmt.Errorf("invalid value for parameter %s: %s", parameterName, value)
}
// Set configuration
oldValue := parameter.Selected
parameter.Selected = value

// Apply configuration to port
var configErr error
if d.openedPort {
switch parameterName {
case "baudrate", "parity", "bits", "stop_bits":
configErr = d.serialPort.SetMode(d.getMode())
case "dtr":
configErr = d.serialPort.SetDTR(d.getDTR())
case "rts":
configErr = d.serialPort.SetRTS(d.getRTS())
default:
// Should never happen
panic("Invalid parameter: " + parameterName)
}
}
return fmt.Errorf("invalid value for parameter %s: %s", parameterName, value)

// If configuration failed, rollback settings
if configErr != nil {
parameter.Selected = oldValue
return configErr
}
return nil
}

// Open is the handler for the pluggable-monitor OPEN command
Expand All @@ -128,7 +155,6 @@ func (d *SerialMonitor) Open(boardPort string) (io.ReadWriter, error) {
serialPort, err := serial.Open(boardPort, d.getMode())
if err != nil {
return nil, err

}
d.openedPort = true
d.serialPort = serialPort
Expand Down Expand Up @@ -179,6 +205,18 @@ func (d *SerialMonitor) getMode() *serial.Mode {
Parity: parity,
DataBits: dataBits,
StopBits: stopBits,
InitialStatusBits: &serial.ModemOutputBits{
DTR: d.getDTR(),
RTS: d.getRTS(),
},
}
return mode
}

func (d *SerialMonitor) getDTR() bool {
return d.serialSettings.ConfigurationParameter["dtr"].Selected == "on"
}

func (d *SerialMonitor) getRTS() bool {
return d.serialSettings.ConfigurationParameter["rts"].Selected == "on"
}