Skip to content

Implementation of port discovery through Pluggable discovery #900

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

Merged
merged 22 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ allowed:
# The following are based on: https://www.gnu.org/licenses/license-list.html#GPLCompatibleLicenses
- gpl-1.0-or-later
- gpl-1.0+ # Deprecated ID for `gpl-1.0-or-later`
- gpl-2.0
- gpl-2.0-or-later
- gpl-2.0+ # Deprecated ID for `gpl-2.0-or-later`
- gpl-3.0-only
Expand Down

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
---
name: github.com/arduino/arduino-cli/i18n
version: v0.35.0
name: github.com/arduino/pluggable-discovery-protocol-handler/v2
version: v2.2.0
type: go
summary:
homepage: https://pkg.go.dev/github.com/arduino/arduino-cli/i18n
license: gpl-3.0-only
summary: Package discovery is a library for handling the Arduino Pluggable-Discovery
protocol (https://github.com/arduino/tooling-rfcs/blob/main/RFCs/0002-pluggable-discovery.md#pluggable-discovery-api-via-stdinstdout)
homepage: https://pkg.go.dev/github.com/arduino/pluggable-discovery-protocol-handler/v2
license: other
licenses:
- sources: [email protected]/LICENSE.txt
text: |2
- sources: LICENSE.txt
text: |
This file includes licensing information for serial-discovery

Copyright (c) 2018 ARDUINO SA (www.arduino.cc)

The software is released under the GNU General Public License, which covers the main body
of the serial-discovery code. The terms of this license can be found at:
https://www.gnu.org/licenses/gpl-3.0.en.html

You can be released from the requirements of the above licenses by purchasing
a commercial license. Buying such a license is mandatory if you want to modify or
otherwise use the software for commercial activities involving the Arduino
software without disclosing the source code of your own applications. To purchase
a commercial license, send an email to [email protected]

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Expand Down Expand Up @@ -682,20 +697,13 @@ licenses:
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
- sources: [email protected]/license_header.tpl
text: |
This file is part of arduino-cli.
- sources: README.md
text: |-
Copyright (c) 2021 ARDUINO SA (www.arduino.cc)

Copyright{{ if .Year }} {{.Year}}{{ end }} {{.Holder}}

This software is released under the GNU General Public License version 3,
which covers the main part of arduino-cli.
The terms of this license can be found at:
The software is released under the GNU General Public License, which covers the main body
of the serial-discovery code. The terms of this license can be found at:
https://www.gnu.org/licenses/gpl-3.0.en.html

You can be released from the requirements of the above licenses by purchasing
a commercial license. Buying such a license is mandatory if you want to
modify or otherwise use the software for commercial activities involving the
Arduino software without disclosing the source code of your own applications.
To purchase a commercial license, send an email to [email protected].
See [LICENSE.txt](https://github.com/arduino/pluggable-discovery-protocol-handler/blob/master/LICENSE.txt) for details.
notices: []

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func uploadHandler(c *gin.Context) {

go func() {
// Resolve commandline
commandline, err := upload.PartiallyResolve(data.Board, filePath, tmpdir, data.Commandline, data.Extra, &Tools)
commandline, err := upload.PartiallyResolve(data.Board, filePath, tmpdir, data.Commandline, data.Extra, Tools)
if err != nil {
send(map[string]string{uploadStatusStr: "Error", "Msg": err.Error()})
return
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ go 1.21
require (
fyne.io/systray v1.10.0
github.com/ProtonMail/go-crypto v1.1.0-alpha.0
github.com/arduino/arduino-cli v0.35.0
github.com/arduino/go-paths-helper v1.12.0
github.com/arduino/go-serial-utils v0.1.2
github.com/arduino/pluggable-discovery-protocol-handler/v2 v2.2.0
github.com/blang/semver v3.5.1+incompatible
github.com/codeclysm/extract/v3 v3.1.1
github.com/gin-contrib/cors v1.5.0
Expand All @@ -28,6 +29,7 @@ require (

require (
github.com/AnatolyRugalev/goregen v0.1.0 // indirect
github.com/arduino/go-properties-orderedmap v1.8.0 // indirect
github.com/bytedance/sonic v1.10.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
Expand Down Expand Up @@ -56,13 +58,13 @@ require (
github.com/kr/binarydist v0.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/leonelquinteros/gotext v1.4.0 // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/tevino/abool v1.2.0 // indirect
Expand All @@ -76,5 +78,6 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 9 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ github.com/AnatolyRugalev/goregen v0.1.0 h1:xrdXkLaskMnbxW0x4FWNj2yoednv0X2bcTBW
github.com/AnatolyRugalev/goregen v0.1.0/go.mod h1:sVlY1tjcirqLBRZnCcIq1+7/Lwmqz5g7IK8AStjOVzI=
github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0=
github.com/ProtonMail/go-crypto v1.1.0-alpha.0/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/arduino/arduino-cli v0.35.0 h1:tkSpGun1hMgJPkvZJjofejWD+ivhCpvsl49H4n81iSc=
github.com/arduino/arduino-cli v0.35.0/go.mod h1:9aoXZdVGQ9uwf2M1nCSB+T051KbldslMFiJaHVycVsg=
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
github.com/arduino/go-paths-helper v1.12.0 h1:xizOQtI9iHdl19qXd1EmWg5i9W//2bOCOYwlNv8F61E=
github.com/arduino/go-paths-helper v1.12.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM=
github.com/arduino/go-properties-orderedmap v1.8.0 h1:wEfa6hHdpezrVOh787OmClsf/Kd8qB+zE3P2Xbrn0CQ=
github.com/arduino/go-properties-orderedmap v1.8.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-serial-utils v0.1.2 h1:MRFwME4w/uaVkJ1R+wzz4KSbI9cF9IDVrYorazvjpTk=
github.com/arduino/go-serial-utils v0.1.2/go.mod h1:kzIsNPgz8DFAd1sAFKve4ubxrdGcwQ4XzvRLlztsgnE=
github.com/arduino/pluggable-discovery-protocol-handler/v2 v2.2.0 h1:v7og6LpskewFabmaShKVzWXl5MXbmsxaRP3yo4dJta8=
github.com/arduino/pluggable-discovery-protocol-handler/v2 v2.2.0/go.mod h1:1dgblsmK2iBx3L5iNTyRIokeaxbTLUrYiUbHBK6yC3Y=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
Expand Down Expand Up @@ -97,8 +102,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/leonelquinteros/gotext v1.4.0 h1:2NHPCto5IoMXbrT0bldPrxj0qM5asOCwtb1aUQZ1tys=
github.com/leonelquinteros/gotext v1.4.0/go.mod h1:yZGXREmoGTtBvZHNcc+Yfug49G/2spuF/i/Qlsvz1Us=
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d h1:Zj+PHjnhRYWBK6RqCDBcAhLXoi3TzC27Zad/Vn+gnVQ=
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d/go.mod h1:WZy8Q5coAB1zhY9AOBJP0O6J4BuDfbupUDavKY+I3+s=
github.com/manveru/gobdd v0.0.0-20131210092515-f1a17fdd710b h1:3E44bLeN8uKYdfQqVQycPnaVviZdBLbizFhU49mtbe4=
Expand All @@ -123,8 +126,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down
2 changes: 1 addition & 1 deletion hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func checkCmd(m []byte) {
// will catch send and sendnobuf and sendraw
go spWrite(s)
} else if strings.HasPrefix(sl, "list") {
go spList()
go serialPorts.List()
} else if strings.HasPrefix(sl, "downloadtool") {
go func() {
args := strings.Split(s, " ")
Expand Down
64 changes: 31 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io"
"os"
"os/exec"
"regexp"
"runtime"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -69,24 +70,27 @@ var (

// iniflags
var (
address = iniConf.String("address", "127.0.0.1", "The address where to listen. Defaults to localhost")
appName = iniConf.String("appName", "", "")
gcType = iniConf.String("gc", "std", "Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)")
hostname = iniConf.String("hostname", "unknown-hostname", "Override the hostname we get from the OS")
httpProxy = iniConf.String("httpProxy", "", "Proxy server for HTTP requests")
httpsProxy = iniConf.String("httpsProxy", "", "Proxy server for HTTPS requests")
indexURL = iniConf.String("indexURL", "https://downloads.arduino.cc/packages/package_index.json", "The address from where to download the index json containing the location of upload tools")
iniConf = flag.NewFlagSet("ini", flag.ContinueOnError)
logDump = iniConf.String("log", "off", "off = (default)")
origins = iniConf.String("origins", "", "Allowed origin list for CORS")
regExpFilter = iniConf.String("regex", "usb|acm|com", "Regular expression to filter serial port list")
signatureKey = iniConf.String("signatureKey", globals.SignatureKey, "Pem-encoded public key to verify signed commandlines")
updateURL = iniConf.String("updateUrl", "", "")
verbose = iniConf.Bool("v", true, "show debug logging")
crashreport = iniConf.Bool("crashreport", false, "enable crashreport logging")
autostartMacOS = iniConf.Bool("autostartMacOS", true, "the Arduino Create Agent is able to start automatically after login on macOS (launchd agent)")
address = iniConf.String("address", "127.0.0.1", "The address where to listen. Defaults to localhost")
appName = iniConf.String("appName", "", "")
gcType = iniConf.String("gc", "std", "Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)")
hostname = iniConf.String("hostname", "unknown-hostname", "Override the hostname we get from the OS")
httpProxy = iniConf.String("httpProxy", "", "Proxy server for HTTP requests")
httpsProxy = iniConf.String("httpsProxy", "", "Proxy server for HTTPS requests")
indexURL = iniConf.String("indexURL", "https://downloads.arduino.cc/packages/package_index.json", "The address from where to download the index json containing the location of upload tools")
iniConf = flag.NewFlagSet("ini", flag.ContinueOnError)
logDump = iniConf.String("log", "off", "off = (default)")
origins = iniConf.String("origins", "", "Allowed origin list for CORS")
portsFilterRegexp = iniConf.String("regex", "usb|acm|com", "Regular expression to filter serial port list")
signatureKey = iniConf.String("signatureKey", globals.SignatureKey, "Pem-encoded public key to verify signed commandlines")
updateURL = iniConf.String("updateUrl", "", "")
verbose = iniConf.Bool("v", true, "show debug logging")
crashreport = iniConf.Bool("crashreport", false, "enable crashreport logging")
autostartMacOS = iniConf.Bool("autostartMacOS", true, "the Arduino Create Agent is able to start automatically after login on macOS (launchd agent)")
)

// the ports filter provided by the user via the -regex flag, if any
var portsFilter *regexp.Regexp

var homeTemplate = template.Must(template.New("home").Parse(homeTemplateHTML))

// If you navigate to this server's homepage, you'll get this HTML
Expand All @@ -97,7 +101,7 @@ var homeTemplateHTML string

// global clients
var (
Tools tools.Tools
Tools *tools.Tools
Systray systray.Systray
Index *index.Resource
)
Expand Down Expand Up @@ -247,7 +251,7 @@ func loop() {

// Instantiate Index and Tools
Index = index.Init(*indexURL, config.GetDataDir())
Tools = *tools.New(config.GetDataDir(), Index, logger)
Tools = tools.New(config.GetDataDir(), Index, logger)

// see if we are supposed to wait 5 seconds
if *isLaunchSelf {
Expand Down Expand Up @@ -302,19 +306,13 @@ func loop() {
}

// see if they provided a regex filter
if len(*regExpFilter) > 0 {
log.Printf("You specified a serial port regular expression filter: %v\n", *regExpFilter)
}

// list serial ports
portList, _ := enumerateSerialPorts()
log.Println("Your serial ports:")
if len(portList) == 0 {
log.Println("\tThere are no serial ports to list.")
}
for _, element := range portList {
log.Printf("\t%v\n", element)

if len(*portsFilterRegexp) > 0 {
log.Printf("You specified a serial port regular expression filter: %v\n", *portsFilterRegexp)
if filter, err := regexp.Compile("(?i)" + *portsFilterRegexp); err != nil {
log.Panicf("Error compiling the regex filter: %v\n", err)
} else {
portsFilter = filter
}
}

if !*verbose {
Expand Down Expand Up @@ -344,15 +342,15 @@ func loop() {
}
}

// launch the discoveries for the running system
go serialPorts.Run()
// launch the hub routine which is the singleton for the websocket server
go h.run()
// launch our serial port routine
go sh.run()
// launch our dummy data routine
//go d.run()

go discoverLoop()

r := gin.New()

socketHandler := wsHandler().ServeHTTP
Expand Down
Loading
Loading