diff --git a/.github/workflows/check-go-dependencies-task.yml b/.github/workflows/check-go-dependencies-task.yml index 502bc41..592f0b0 100644 --- a/.github/workflows/check-go-dependencies-task.yml +++ b/.github/workflows/check-go-dependencies-task.yml @@ -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: diff --git a/.github/workflows/check-go-task.yml b/.github/workflows/check-go-task.yml index 9008eae..cd75a33 100644 --- a/.github/workflows/check-go-task.yml +++ b/.github/workflows/check-go-task.yml @@ -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: diff --git a/.licenses/serial-monitor/go/go.bug.st/serial.dep.yml b/.licenses/serial-monitor/go/go.bug.st/serial.dep.yml index 3d11c35..071365f 100644 --- a/.licenses/serial-monitor/go/go.bug.st/serial.dep.yml +++ b/.licenses/serial-monitor/go/go.bug.st/serial.dep.yml @@ -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 diff --git a/.licenses/serial-monitor/go/go.bug.st/serial/unixutils.dep.yml b/.licenses/serial-monitor/go/go.bug.st/serial/unixutils.dep.yml index ec4b51a..d3859ba 100644 --- a/.licenses/serial-monitor/go/go.bug.st/serial/unixutils.dep.yml +++ b/.licenses/serial-monitor/go/go.bug.st/serial/unixutils.dep.yml @@ -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. @@ -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] diff --git a/.licenses/serial-monitor/go/golang.org/x/exp/constraints.dep.yml b/.licenses/serial-monitor/go/golang.org/x/exp/constraints.dep.yml new file mode 100644 index 0000000..4d3211c --- /dev/null +++ b/.licenses/serial-monitor/go/golang.org/x/exp/constraints.dep.yml @@ -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: [] diff --git a/.licenses/serial-monitor/go/golang.org/x/exp/slices.dep.yml b/.licenses/serial-monitor/go/golang.org/x/exp/slices.dep.yml new file mode 100644 index 0000000..d064d8d --- /dev/null +++ b/.licenses/serial-monitor/go/golang.org/x/exp/slices.dep.yml @@ -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: [] diff --git a/DistTasks.yml b/DistTasks.yml index 3f326b3..f75d1d1 100644 --- a/DistTasks.yml +++ b/DistTasks.yml @@ -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: diff --git a/README.md b/README.md index f5e0be9..1d6d6b5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/go.mod b/go.mod index 1d111f8..586f5e6 100644 --- a/go.mod +++ b/go.mod @@ -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 ( diff --git a/go.sum b/go.sum index 630602b..f1806ec 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/main.go b/main.go index 8416e39..67a990c 100644 --- a/main.go +++ b/main.go @@ -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() { @@ -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", @@ -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, @@ -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 @@ -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 @@ -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" +}