diff --git a/README.adoc b/README.adoc index 83ad1d9d..4945de77 100644 --- a/README.adoc +++ b/README.adoc @@ -48,9 +48,11 @@ The full list of command line options can be obtained with the `-h` option: `./u == How to build the tools from source file == - go get github.com/arduino/FirmwareUpdater/cli +From the sources root directory run: -This will create a bin folder with `cli` executable in it. + go build -o updater + +This will create the `updater` executable. == License == diff --git a/distrib.sh b/distrib.sh index 5700c2bd..d3eda586 100755 --- a/distrib.sh +++ b/distrib.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/bin/bash -ex -VERSION=`cd src/github.com/arduino/FirmwareUpdater/cli && git describe --tags` +VERSION=`git describe --tags` FILENAME="FirmwareUpdater" rm -rf distrib @@ -13,22 +13,22 @@ mkdir -p distrib/windows export CGO_ENABLED=0 -GOOS=linux GOARCH=amd64 go build -o distrib/linux64/updater github.com/arduino/FirmwareUpdater/cli -GOOS=linux GOARCH=386 GO386=387 go build -o distrib/linux32/updater github.com/arduino/FirmwareUpdater/cli -GOOS=linux GOARCH=arm go build -o distrib/linuxarm/updater github.com/arduino/FirmwareUpdater/cli -GOOS=linux GOARCH=arm64 go build -o distrib/linuxarm64/updater github.com/arduino/FirmwareUpdater/cli -GOOS=windows GOARCH=386 GO386=387 go build -o distrib/windows/updater.exe github.com/arduino/FirmwareUpdater/cli +GOOS=linux GOARCH=amd64 go build -o distrib/linux64/updater +GOOS=linux GOARCH=386 GO386=387 go build -o distrib/linux32/updater +GOOS=linux GOARCH=arm go build -o distrib/linuxarm/updater +GOOS=linux GOARCH=arm64 go build -o distrib/linuxarm64/updater +GOOS=windows GOARCH=386 GO386=387 go build -o distrib/windows/updater.exe #export CGO_ENABLED=1 # need osxcross in path -GOOS=darwin GOARCH=amd64 go build -o distrib/osx/updater github.com/arduino/FirmwareUpdater/cli +GOOS=darwin GOARCH=amd64 go build -o distrib/osx/updater -cp -r $GOPATH/src/github.com/arduino/FirmwareUpdater/firmwares distrib/linux64 -cp -r $GOPATH/src/github.com/arduino/FirmwareUpdater/firmwares distrib/linux32 -cp -r $GOPATH/src/github.com/arduino/FirmwareUpdater/firmwares distrib/linuxarm -cp -r $GOPATH/src/github.com/arduino/FirmwareUpdater/firmwares distrib/linuxarm64 -cp -r $GOPATH/src/github.com/arduino/FirmwareUpdater/firmwares distrib/windows -cp -r $GOPATH/src/github.com/arduino/FirmwareUpdater/firmwares distrib/osx +cp -r firmwares distrib/linux64 +cp -r firmwares distrib/linux32 +cp -r firmwares distrib/linuxarm +cp -r firmwares distrib/linuxarm64 +cp -r firmwares distrib/windows +cp -r firmwares distrib/osx cd distrib/linux64 && tar cjf ../${FILENAME}-${VERSION}-linux64.tar.bz2 * && cd - LINUX64_SHA=`sha256sum distrib/${FILENAME}-${VERSION}-linux64.tar.bz2 | cut -f1 -d " "` @@ -59,7 +59,7 @@ echo "==============================" echo "BOARD MANAGER SNIPPET" echo "==============================" -cat $GOPATH/src/github.com/arduino/FirmwareUpdater/extras/package_index.json.template | +cat extras/package_index.json.template | sed "s/%%VERSION%%/${VERSION}/" | sed "s/%%FILENAME%%/${FILENAME}/" | sed "s/%%LINUX64_SHA%%/${LINUX64_SHA}/" | @@ -76,4 +76,4 @@ sed "s/%%WINDOWS_SHA%%/${WINDOWS_SHA}/" | sed "s/%%WINDOWS_SIZE%%/${WINDOWS_SIZE}/" # call the tool with something like -# ./linux64/updater -flasher firmwares/NINA/FirmwareUpdater.mkrwifi1010.ino.bin -firmware firmwares/NINA/1.2.1/NINA_W102.bin -port /dev/ttyACM0 -address arduino.cc:443 -restore_binary /tmp/arduino_build_619137/WiFiSSLClient.ino.bin -programmer {runtime.tools.bossac}/bossac \ No newline at end of file +# ./linux64/updater -flasher firmwares/NINA/FirmwareUpdater.mkrwifi1010.ino.bin -firmware firmwares/NINA/1.2.1/NINA_W102.bin -port /dev/ttyACM0 -address arduino.cc:443 -restore_binary /tmp/arduino_build_619137/WiFiSSLClient.ino.bin -programmer {runtime.tools.bossac}/bossac diff --git a/go.mod b/go.mod index 4dd3de24..5a1bc6ab 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,11 @@ module github.com/arduino/FirmwareUpdater go 1.14 +// branch with support for serial timeouts +replace go.bug.st/serial => github.com/cmaglie/go-serial v0.0.0-20200923162623-b214c147e37e + require ( - github.com/creack/goselect v0.0.0-20180501195510-58854f77ee8d // indirect - github.com/facchinm/go-serial v0.0.0-20190206110233-459a153afba0 - go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 - golang.org/x/sys v0.0.0-20190411185658-b44545bcd369 // indirect + github.com/arduino/arduino-cli v0.0.0-20200924151007-69ac12c98b2b + github.com/pkg/errors v0.9.1 + go.bug.st/serial v1.1.1 ) diff --git a/go.sum b/go.sum index 00a06017..78f25a4f 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,333 @@ -github.com/creack/goselect v0.0.0-20180501195510-58854f77ee8d h1:6o8WW5zZ+Ny9sbk69epnAPmBzrBaRnvci+l4+pqleeY= -github.com/creack/goselect v0.0.0-20180501195510-58854f77ee8d/go.mod h1:gHrIcH/9UZDn2qgeTUeW5K9eZsVYCH6/60J/FHysWyE= -github.com/facchinm/go-serial v0.0.0-20190206110233-459a153afba0 h1:TmQMjEpI656fxIDUgWVNnAvFJ6eaHx2uCVOlrX07+Yc= -github.com/facchinm/go-serial v0.0.0-20190206110233-459a153afba0/go.mod h1:082o96cvX/yKg1NvcnyT1HriTGUI5jLbCbtAVqbsTyw= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/arduino/arduino-cli v0.0.0-20200924151007-69ac12c98b2b h1:CfjoOrbIDUGET/k7D3+/gQuuw2SIrdHMBcgQ7on0aE4= +github.com/arduino/arduino-cli v0.0.0-20200924151007-69ac12c98b2b/go.mod h1:FoP2RfB4sX+XvDiLKysORud9lv8HtgYq14sNawOnx7o= +github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT96G8egU7FEb13L4dq3fnCN7lxXhJ86t69+W7s= +github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8= +github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= +github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= +github.com/arduino/go-paths-helper v1.3.2 h1:5U9TSKQODiwSVgTxskC0PNl0l0Vf40GUlp99Zy2SK8w= +github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= +github.com/arduino/go-properties-orderedmap v1.1.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= +github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o= +github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= +github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4= +github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ= +github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20= +github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cmaglie/go-serial v0.0.0-20200923162623-b214c147e37e h1:XETkjcWmNrh5M9hIpkgI0uANZsdD8zg2wjDzspe3bRw= +github.com/cmaglie/go-serial v0.0.0-20200923162623-b214c147e37e/go.mod h1:k7j3AWnS4CLHK94Z32+qkukjlSyASt1YYrbWcnr9r4E= +github.com/cmaglie/go.rice v1.0.3 h1:ZBLmBdQp6ejc+n8eMNH0uuRSKkg6kKe6ORjXKnyHBYw= +github.com/cmaglie/go.rice v1.0.3/go.mod h1:AF3bOWkvdOpp8/S3UL8qbQ4N7DiISIbJtj54GWFPAsc= +github.com/cmaglie/pb v1.0.27 h1:ynGj8vBXR+dtj4B7Q/W/qGt31771Ux5iFfRQBnwdQiA= +github.com/cmaglie/pb v1.0.27/go.mod h1:GilkKZMXYjBA4NxItWFfO+lwkp59PLHQ+IOW/b/kmZI= +github.com/codeclysm/cc v1.2.2 h1:1ChS4EvWTjw6bH2sd6QiMcmih0itVVrWdh9MmOliX/I= +github.com/codeclysm/cc v1.2.2/go.mod h1:XtW4ArCNgQwFphcRGG9+sPX5WM1J6/u0gMy5ZdV3obA= +github.com/codeclysm/extract/v3 v3.0.1 h1:uVutzakOCBzoguzMNs41FPLR7+x/2sIoiRA6hLbaLqA= +github.com/codeclysm/extract/v3 v3.0.1/go.mod h1:NKsw+hqua9H+Rlwy/w/3Qgt9jDonYEgB6wJu+25eOKw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/goselect v0.1.1 h1:tiSSgKE1eJtxs1h/VgGQWuXUP0YS4CDIFMp6vaI1ls0= +github.com/creack/goselect v0.1.1/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= +github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY= +github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +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/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fluxio/iohelpers v0.0.0-20160419043813-3a4dd67a94d2 h1:C6sOwknxwWfLBEQ91zhmptlfxf7pVEs5s6wOnDxNpS4= +github.com/fluxio/iohelpers v0.0.0-20160419043813-3a4dd67a94d2/go.mod h1:c7sGIpDbBo0JZZ1tKyC1p5smWf8QcUjK4bFtZjHAecg= +github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5 h1:R8jFW6G/bjoXjWPFrEfw9G5YQDlYhwV4AC+Eonu6wmk= +github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5/go.mod h1:BEUDl7FG1cc76sM0J0x8dqr6RhiL4uqvk6oFkwuNyuM= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/h2non/filetype v1.0.6/go.mod h1:isekKqOuhMj+s/7r3rIeTErIRy4Rub5uBWHfvMusLMU= +github.com/h2non/filetype v1.0.8 h1:le8gpf+FQA0/DlDABbtisA1KiTS0Xi+YSC/E8yY3Y14= +github.com/h2non/filetype v1.0.8/go.mod h1:isekKqOuhMj+s/7r3rIeTErIRy4Rub5uBWHfvMusLMU= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/imjasonmiller/godice v0.1.2 h1:T1/sW/HoDzFeuwzOOuQjmeMELz9CzZ53I2CnD+08zD4= +github.com/imjasonmiller/godice v0.1.2/go.mod h1:8cTkdnVI+NglU2d6sv+ilYcNaJ5VSTBwvMbFULJd/QQ= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/juju/clock v0.0.0-20180524022203-d293bb356ca4/go.mod h1:nD0vlnrUjcjJhqN5WuCWZyzfd5AHZAC9/ajvbSx69xA= +github.com/juju/errors v0.0.0-20150916125642-1b5e39b83d18/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= +github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 h1:rhqTjzJlm7EbkELJDKMTU7udov+Se0xZkWmugr6zGok= +github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= +github.com/juju/loggo v0.0.0-20170605014607-8232ab8918d9/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= +github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= +github.com/juju/retry v0.0.0-20160928201858-1998d01ba1c3/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= +github.com/juju/testing v0.0.0-20200510222523-6c8c298c77a0/go.mod h1:hpGvhGHPVbNBraRLZEhoQwFLMrjK8PSlO4D3nDjKYXo= +github.com/juju/utils v0.0.0-20180808125547-9dfc6dbfb02b/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= +github.com/juju/version v0.0.0-20161031051906-1f41e27e54f2/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +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/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/marcinbor85/gohex v0.0.0-20200531163658-baab2527a9a2 h1:n7R8fUwWZUB2XtyzBNsYNNm9/XgOBj6pvLi7GLMCHtM= +github.com/marcinbor85/gohex v0.0.0-20200531163658-baab2527a9a2/go.mod h1:Pb6XcsXyropB9LNHhnqaknG/vEwYztLkQzVCHv8sQ3M= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4= +github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA= +github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072/go.mod h1:sGdS7A6CAETR53zkdjGkgoFlh1vSm7MtX+i8XfEsTMA= +github.com/miekg/dns v1.0.5 h1:MQBGf2JEJDu0rg9WOpQZzeO+zW8UKwgkvP3R1dUU1Yw= +github.com/miekg/dns v1.0.5/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 h1:Cvfd2dOlXIPTeEkOT/h8PyK4phBngOM4at9/jlgy7d4= +github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228/go.mod h1:MGuVJ1+5TX1SCoO2Sx0eAnjpdRytYla2uC1YIZfkC9c= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +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/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583 h1:ogHi8YLNeIxABOaH6UgtbwkODheuAK+ErP8gWXYQVj0= +github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583/go.mod h1:sFPiU/UgDcsQVu3vkqpZLCXWFwUoQRpHGu9ATihPAl0= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= +github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/schollz/closestmatch v2.1.0+incompatible h1:Uel2GXEpJqOWBrlyI+oY9LTiyyjYS17cCYRqP13/SHk= +github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g= +github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e h1:uO75wNGioszjmIzcY/tvdDYKRLVvzggtAmmJkn9j4GQ= +github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e/go.mod h1:tm/wZFQ8e24NYaBGIlnO2WGCAi67re4HHuOm0sftE/M= +github.com/segmentio/objconv v1.0.1/go.mod h1:auayaH5k3137Cl4SoXTgrzQcuQDmvuVtZgS0fb1Ahys= +github.com/segmentio/stats/v4 v4.5.3 h1:Y/DSUWZ4c8ICgqJ9rQohzKvGqGWbLPWad5zmxVoKN+Y= +github.com/segmentio/stats/v4 v4.5.3/go.mod h1:LsaahUJR7iiSs8mnkvQvdQ/RLHAS5adGLxuntg0ydGo= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.0.1-0.20200710201246-675ae5f5a98c h1:/dP/1GnfVIlWnB0YDImenSmneUCw3wjyq2RMgAG1e2o= +github.com/spf13/cobra v1.0.1-0.20200710201246-675ae5f5a98c/go.mod h1:aeNIJzz/GSSVlS+gpCpQWZ83BKbsoW57mr90+YthtkQ= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E= +github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.bug.st/cleanup v1.0.0 h1:XVj1HZxkBXeq3gMT7ijWUpHyIC1j8XAoNSyQ06CskgA= +go.bug.st/cleanup v1.0.0/go.mod h1:EqVmTg2IBk4znLbPD28xne3abjsJftMdqqJEjhn70bk= +go.bug.st/downloader/v2 v2.0.1 h1:F/ZgVDrUHo2tHIeOVbcl4rgGaMmQgAEjn5c8yi5t+Iw= +go.bug.st/downloader/v2 v2.0.1/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13RzVII= +go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 h1:F1qxtaFuewctYc/SsHRn+Q7Dtwi+yJGPgVq8YLtQz98= +go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 h1:mACY1anK6HNCZtm/DK2Rf2ZPHggVqeB0+7rY9Gl6wyI= go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkXgJMDOdSwNfo2g1orOGE/gBGdvjZw= -golang.org/x/sys v0.0.0-20190411185658-b44545bcd369 h1:aBlRBZoCuZNRDClvfkDoklQqdLzBaA3uViASg2z2p24= -golang.org/x/sys v0.0.0-20190411185658-b44545bcd369/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180214000028-650f4a345ab4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170712054546-1be3d31502d6/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +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= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/cli/main.go b/main.go similarity index 100% rename from cli/main.go rename to main.go diff --git a/modules/nina/flasher.go b/modules/nina/flasher.go index 3c23b9bc..c1c4a904 100644 --- a/modules/nina/flasher.go +++ b/modules/nina/flasher.go @@ -20,13 +20,14 @@ package nina import ( + "bytes" "crypto/md5" "encoding/binary" - "github.com/arduino/FirmwareUpdater/utils" "log" "time" - serial "github.com/facchinm/go-serial" + "github.com/arduino/FirmwareUpdater/utils" + "go.bug.st/serial" ) type FlasherError struct { @@ -169,13 +170,14 @@ func (flasher *Flasher) serialFillBuffer(buffer []byte) error { } func (flasher *Flasher) sendCommand(command byte, address uint32, val uint32, payload []byte) error { - if err := binary.Write(flasher.port, binary.BigEndian, command); err != nil { + buff := new(bytes.Buffer) + if err := binary.Write(buff, binary.BigEndian, command); err != nil { return err } - if err := binary.Write(flasher.port, binary.BigEndian, address); err != nil { + if err := binary.Write(buff, binary.BigEndian, address); err != nil { return err } - if err := binary.Write(flasher.port, binary.BigEndian, val); err != nil { + if err := binary.Write(buff, binary.BigEndian, val); err != nil { return err } var length uint16 @@ -184,13 +186,23 @@ func (flasher *Flasher) sendCommand(command byte, address uint32, val uint32, pa } else { length = uint16(len(payload)) } - if err := binary.Write(flasher.port, binary.BigEndian, length); err != nil { + if err := binary.Write(buff, binary.BigEndian, length); err != nil { return err } if payload != nil { - if _, err := flasher.port.Write(payload); err != nil { + buff.Write(payload) + } + data := buff.Bytes() + for { + sent, err := flasher.port.Write(data) + if err != nil { return err } + if sent == len(data) { + break + } + // fmt.Println("HEY! sent", sent, "out of", len(data)) + data = data[sent:] } return nil } diff --git a/modules/sara/flasher.go b/modules/sara/flasher.go index ff79e283..79fb0081 100644 --- a/modules/sara/flasher.go +++ b/modules/sara/flasher.go @@ -20,12 +20,12 @@ package sara import ( - "github.com/arduino/FirmwareUpdater/utils" - serial "github.com/facchinm/go-serial" "log" "strings" "time" - //"strconv" + + "github.com/arduino/FirmwareUpdater/utils" + "go.bug.st/serial" ) type FlasherError struct { @@ -124,8 +124,14 @@ func (flasher *Flasher) serialFillBuffer(buffer []byte) error { func (flasher *Flasher) sendCommand(payload []byte) error { if payload != nil { - if _, err := flasher.port.Write(payload); err != nil { - return err + for { + if sent, err := flasher.port.Write(payload); err != nil { + return err + } else if sent < len(payload) { + payload = payload[sent:] + } else { + break + } } } return nil diff --git a/modules/winc/flasher.go b/modules/winc/flasher.go index f29664ee..14bc47d7 100644 --- a/modules/winc/flasher.go +++ b/modules/winc/flasher.go @@ -20,11 +20,13 @@ package winc import ( + "bytes" "encoding/binary" - "github.com/arduino/FirmwareUpdater/utils" - serial "github.com/facchinm/go-serial" "log" "time" + + "github.com/arduino/FirmwareUpdater/utils" + "go.bug.st/serial" ) type FlasherError struct { @@ -167,13 +169,14 @@ func (flasher *Flasher) serialFillBuffer(buffer []byte) error { } func (flasher *Flasher) sendCommand(command byte, address uint32, val uint32, payload []byte) error { - if err := binary.Write(flasher.port, binary.BigEndian, command); err != nil { + buff := new(bytes.Buffer) + if err := binary.Write(buff, binary.BigEndian, command); err != nil { return err } - if err := binary.Write(flasher.port, binary.BigEndian, address); err != nil { + if err := binary.Write(buff, binary.BigEndian, address); err != nil { return err } - if err := binary.Write(flasher.port, binary.BigEndian, val); err != nil { + if err := binary.Write(buff, binary.BigEndian, val); err != nil { return err } var length uint16 @@ -182,13 +185,24 @@ func (flasher *Flasher) sendCommand(command byte, address uint32, val uint32, pa } else { length = uint16(len(payload)) } - if err := binary.Write(flasher.port, binary.BigEndian, length); err != nil { + if err := binary.Write(buff, binary.BigEndian, length); err != nil { return err } if payload != nil { - if _, err := flasher.port.Write(payload); err != nil { + buff.Write(payload) + } + + data := buff.Bytes() + for { + sent, err := flasher.port.Write(data) + if err != nil { return err } + if sent == len(data) { + break + } + // fmt.Println("HEY! sent", sent, "out of", len(data)) + data = data[sent:] } return nil } diff --git a/modules/winc/main.go b/modules/winc/main.go index a09b28e3..dff2490f 100644 --- a/modules/winc/main.go +++ b/modules/winc/main.go @@ -23,22 +23,22 @@ import ( "bytes" "errors" "fmt" - "github.com/arduino/FirmwareUpdater/programmers/bossac" - "github.com/arduino/FirmwareUpdater/utils/context" "io/ioutil" "log" "os" "strconv" + + "github.com/arduino/FirmwareUpdater/programmers/bossac" + "github.com/arduino/FirmwareUpdater/utils/context" ) var f *Flasher var payloadSize uint16 -var programmer context.Programmer func Run(ctx context.Context) { var err error - programmer = &bossac.Bossac{} + programmer := &bossac.Bossac{} if ctx.FWUploaderBinary != "" { log.Println("Flashing firmware uploader winc") diff --git a/programmers/avrdude/avrdude.go b/programmers/avrdude/avrdude.go index 806bba4c..53cb33ff 100644 --- a/programmers/avrdude/avrdude.go +++ b/programmers/avrdude/avrdude.go @@ -1,17 +1,15 @@ package avrdude import ( - "bytes" - "errors" "io/ioutil" "log" - "os/exec" + "os" "path/filepath" + "time" "github.com/arduino/FirmwareUpdater/utils/context" - serial "go.bug.st/serial.v1" - //"go.bug.st/serial.v1/enumerator" - "time" + "github.com/arduino/arduino-cli/executils" + "github.com/pkg/errors" ) type Avrdude struct { @@ -19,183 +17,40 @@ type Avrdude struct { func (b *Avrdude) Flash(ctx *context.Context, filename string) error { log.Println("Flashing " + filename) - err := invokeAvrdude([]string{ctx.ProgrammerPath, "-C" + filepath.Join(filepath.Dir(ctx.ProgrammerPath), "..", "etc/avrdude.conf"), "-v", "-patmega4809", "-cxplainedmini_updi", "-Pusb", "-b115200", "-e", "-D", "-Uflash:w:" + filename + ":i", "-Ufuse8:w:0x00:m"}) time.Sleep(3 * time.Second) + return err } func (b *Avrdude) DumpAndFlash(ctx *context.Context, filename string) (string, error) { - log.Println("Flashing " + filename) dir, err := ioutil.TempDir("", "wifiFlasher_dump") + if err != nil { + return "", errors.WithMessage(err, "creating temp dir to store current sketch") + } + + log.Println("Reading existing sketch from the baord, to restore it later") err = invokeAvrdude([]string{ctx.ProgrammerPath, "-C" + filepath.Join(filepath.Dir(ctx.ProgrammerPath), "..", "etc/avrdude.conf"), "-v", "-patmega4809", "-cxplainedmini_updi", "-Pusb", "-b115200", "-D", "-Uflash:r:" + filepath.Join(dir, "dump.bin") + ":i"}) - log.Println("Original sketch saved at " + filepath.Join(dir, "dump.bin")) if err != nil { return "", err } + log.Println("Original sketch saved at " + filepath.Join(dir, "dump.bin")) + + log.Println("Flashing " + filename) err = invokeAvrdude([]string{ctx.ProgrammerPath, "-C" + filepath.Join(filepath.Dir(ctx.ProgrammerPath), "..", "etc/avrdude.conf"), "-v", "-patmega4809", "-cxplainedmini_updi", "-Pusb", "-b115200", "-e", "-D", "-Uflash:w:" + filename + ":i", "-Ufuse8:w:0x00:m"}) + time.Sleep(3 * time.Second) return filepath.Join(dir, "dump.bin"), err } func invokeAvrdude(args []string) error { - cmd := exec.Command(args[0], args[1:]...) - var out bytes.Buffer - var stderr bytes.Buffer - cmd.Stdout = &out - cmd.Stderr = &stderr - err := cmd.Run() - log.Println(out.String()) - log.Println(stderr.String()) - return err -} - -func touchSerialPortAt1200bps(port string) error { - log.Println("Touching port " + port + " at 1200bps") - - // Open port - p, err := serial.Open(port, &serial.Mode{BaudRate: 1200}) - if err != nil { - return errors.New("Open port " + port) - } - defer p.Close() - - // Set DTR - err = p.SetDTR(false) - log.Println("Set DTR off") + cmd, err := executils.NewProcess(args...) if err != nil { - return errors.New("Can't set DTR") + return err } - - // Wait a bit to allow restart of the board - time.Sleep(200 * time.Millisecond) - - return nil -} - -// reset opens the port at 1200bps. It returns the new port name (which could change -// sometimes) and an error (usually because the port listing failed) -func reset(port string, wait bool) (string, error) { - log.Println("Restarting in bootloader mode") - - // Get port list before reset - ports, err := serial.GetPortsList() - log.Println("Get port list before reset") - if err != nil { - return "", errors.New("Get port list before reset") - } - - // Touch port at 1200bps - err = touchSerialPortAt1200bps(port) - if err != nil { - return "", errors.New("1200bps Touch") - } - - // Wait for port to disappear and reappear - if wait { - port = waitReset(ports, port) - } - - return port, nil -} - -// waitReset is meant to be called just after a reset. It watches the ports connected -// to the machine until a port disappears and reappears. The port name could be different -// so it returns the name of the new port. -func waitReset(beforeReset []string, originalPort string) string { - var port string - timeout := false - - go func() { - time.Sleep(10 * time.Second) - timeout = true - }() - - for { - ports, _ := serial.GetPortsList() - port = differ(ports, beforeReset) - - if port != "" { - break - } - if timeout { - break - } - time.Sleep(time.Millisecond * 100) - } - - // Wait for the port to reappear - log.Println("Wait for the port to reappear") - afterReset, _ := serial.GetPortsList() - for { - ports, _ := serial.GetPortsList() - port = differ(ports, afterReset) - if port != "" { - time.Sleep(time.Millisecond * 500) - break - } - if timeout { - break - } - time.Sleep(time.Millisecond * 100) - } - - // try to upload on the existing port if the touch was ineffective - if port == "" { - port = originalPort - } - - return port -} - -func waitPort(beforeReset []string, originalPort string) string { - var port string - timeout := false - - go func() { - time.Sleep(10 * time.Second) - timeout = true - }() - - for { - ports, _ := serial.GetPortsList() - port = differ(ports, beforeReset) - - if port != "" { - break - } - if timeout { - break - } - time.Sleep(time.Millisecond * 100) - } - - // try to upload on the existing port if the touch was ineffective - if port == "" { - port = originalPort - } - - return port -} - -// differ returns the first item that differ between the two input slices -func differ(slice1 []string, slice2 []string) string { - m := map[string]int{} - - for _, s1Val := range slice1 { - m[s1Val] = 1 - } - for _, s2Val := range slice2 { - m[s2Val] = m[s2Val] + 1 - } - - for mKey, mVal := range m { - if mVal == 1 { - return mKey - } - } - - return "" + cmd.RedirectStdoutTo(os.Stdout) + cmd.RedirectStderrTo(os.Stderr) + return cmd.Run() } diff --git a/programmers/bossac/bossac.go b/programmers/bossac/bossac.go index 7ef78396..86851b65 100644 --- a/programmers/bossac/bossac.go +++ b/programmers/bossac/bossac.go @@ -1,212 +1,74 @@ package bossac import ( - "bytes" - "errors" - "github.com/arduino/FirmwareUpdater/utils/context" - serial "go.bug.st/serial.v1" "io/ioutil" "log" - "os/exec" + "os" "path/filepath" - //"go.bug.st/serial.v1/enumerator" "time" + + "github.com/arduino/FirmwareUpdater/utils/context" + "github.com/arduino/arduino-cli/arduino/serialutils" + "github.com/arduino/arduino-cli/executils" + "github.com/pkg/errors" ) type Bossac struct { } func (b *Bossac) Flash(ctx *context.Context, filename string) error { - log.Println("Flashing " + filename) - - port, err := reset(ctx.PortName, true) + log.Println("Entering board into bootloader mode") + port, err := serialutils.Reset(ctx.PortName, true) if err != nil { return err } - err = invokeBossac([]string{ctx.ProgrammerPath, "-e", "-R", "-p", port, "-w", filename}) - ports, err := serial.GetPortsList() - ctx.PortName = waitPort(ports, port) + log.Println("Flashing " + filename) + err = invokeBossac([]string{ctx.ProgrammerPath, "-e", "-R", "-p", port, "-w", filename}) - log.Println("Port is online " + ctx.PortName) + ctx.PortName, err = serialutils.WaitForNewSerialPortOrDefaultTo(port) + log.Println("Board is back online " + ctx.PortName) time.Sleep(1 * time.Second) return err } func (b *Bossac) DumpAndFlash(ctx *context.Context, filename string) (string, error) { - log.Println("Flashing " + filename) dir, err := ioutil.TempDir("", "wifiFlasher_dump") - port, err := reset(ctx.PortName, true) + if err != nil { + return "", errors.WithMessage(err, "creating temp dir to store current sketch") + } + + log.Println("Entering board into bootloader mode") + port, err := serialutils.Reset(ctx.PortName, true) if err != nil { return "", err } + + log.Println("Reading existing sketch from the baord, to restore it later") err = invokeBossac([]string{ctx.ProgrammerPath, "-u", "-r", "-p", port, filepath.Join(dir, "dump.bin")}) + log.Println("Original sketch saved at " + filepath.Join(dir, "dump.bin")) if err != nil { return "", err } + + log.Println("Flashing " + filename) err = invokeBossac([]string{ctx.ProgrammerPath, "-e", "-R", "-p", port, "-w", filename}) - ports, err := serial.GetPortsList() - ctx.PortName = waitPort(ports, port) + ctx.PortName, err = serialutils.WaitForNewSerialPortOrDefaultTo(port) + log.Println("Board is back online " + ctx.PortName) + time.Sleep(1 * time.Second) return filepath.Join(dir, "dump.bin"), err } func invokeBossac(args []string) error { - cmd := exec.Command(args[0], args[1:]...) - var out bytes.Buffer - cmd.Stdout = &out - err := cmd.Run() - log.Println(out.String()) - return err -} - -func touchSerialPortAt1200bps(port string) error { - log.Println("Touching port " + port + " at 1200bps") - - // Open port - p, err := serial.Open(port, &serial.Mode{BaudRate: 1200}) - if err != nil { - return errors.New("Open port " + port) - } - defer p.Close() - - // Set DTR - err = p.SetDTR(false) - log.Println("Set DTR off") - if err != nil { - return errors.New("Can't set DTR") - } - - // Wait a bit to allow restart of the board - time.Sleep(200 * time.Millisecond) - - return nil -} - -// reset opens the port at 1200bps. It returns the new port name (which could change -// sometimes) and an error (usually because the port listing failed) -func reset(port string, wait bool) (string, error) { - log.Println("Restarting in bootloader mode") - - // Get port list before reset - ports, err := serial.GetPortsList() - log.Println("Get port list before reset") - if err != nil { - return "", errors.New("Get port list before reset") - } - - // Touch port at 1200bps - err = touchSerialPortAt1200bps(port) + cmd, err := executils.NewProcess(args...) if err != nil { - return "", errors.New("1200bps Touch") - } - - // Wait for port to disappear and reappear - if wait { - port = waitReset(ports, port) - } - - return port, nil -} - -// waitReset is meant to be called just after a reset. It watches the ports connected -// to the machine until a port disappears and reappears. The port name could be different -// so it returns the name of the new port. -func waitReset(beforeReset []string, originalPort string) string { - var port string - timeout := false - - go func() { - time.Sleep(10 * time.Second) - timeout = true - }() - - for { - ports, _ := serial.GetPortsList() - port = differ(ports, beforeReset) - - if port != "" { - break - } - if timeout { - break - } - time.Sleep(time.Millisecond * 100) - } - - // Wait for the port to reappear - log.Println("Wait for the port to reappear") - afterReset, _ := serial.GetPortsList() - for { - ports, _ := serial.GetPortsList() - port = differ(ports, afterReset) - if port != "" { - time.Sleep(time.Millisecond * 500) - break - } - if timeout { - break - } - time.Sleep(time.Millisecond * 100) - } - - // try to upload on the existing port if the touch was ineffective - if port == "" { - port = originalPort - } - - return port -} - -func waitPort(beforeReset []string, originalPort string) string { - var port string - timeout := false - - go func() { - time.Sleep(10 * time.Second) - timeout = true - }() - - for { - ports, _ := serial.GetPortsList() - port = differ(ports, beforeReset) - - if port != "" { - break - } - if timeout { - break - } - time.Sleep(time.Millisecond * 100) - } - - // try to upload on the existing port if the touch was ineffective - if port == "" { - port = originalPort - } - - return port -} - -// differ returns the first item that differ between the two input slices -func differ(slice1 []string, slice2 []string) string { - m := map[string]int{} - - for _, s1Val := range slice1 { - m[s1Val] = 1 - } - for _, s2Val := range slice2 { - m[s2Val] = m[s2Val] + 1 - } - - for mKey, mVal := range m { - if mVal == 1 { - return mKey - } + return err } - - return "" + cmd.RedirectStdoutTo(os.Stdout) + cmd.RedirectStderrTo(os.Stderr) + return cmd.Run() } diff --git a/utils/flasher.go b/utils/flasher.go index b88938c4..b02e34f8 100644 --- a/utils/flasher.go +++ b/utils/flasher.go @@ -1,8 +1,10 @@ package utils import ( - "github.com/facchinm/go-serial" "log" + "time" + + "go.bug.st/serial" ) // http://www.ni.com/product-documentation/54548/en/ @@ -15,20 +17,24 @@ var baudRates = []int{ } func OpenSerial(portName string) (serial.Port, error) { - var port serial.Port var err error for _, baudRate := range baudRates { mode := &serial.Mode{ BaudRate: baudRate, - Vtimeout: 255, - Vmin: 0, } port, err := serial.Open(portName, mode) - if err == nil { - log.Printf("Open the serial port with baud rate %d", baudRate) - return port, nil + if err != nil { + // try another baudrate + continue + } + log.Printf("Opened the serial port with baud rate %d", baudRate) + + if err := port.SetReadTimeout(30 * time.Second); err != nil { + log.Fatalf("Could not set timeout on serial port: %s", err) + return nil, err } + return port, nil } - return port, err + return nil, err } diff --git a/vendor/github.com/facchinm/go-serial/.travis.yml b/vendor/github.com/facchinm/go-serial/.travis.yml deleted file mode 100644 index 6cbc8139..00000000 --- a/vendor/github.com/facchinm/go-serial/.travis.yml +++ /dev/null @@ -1,70 +0,0 @@ -language: go - -os: - - linux - - osx - -go: - - 1.7.x - - 1.8.x - - 1.9.x - - 1.10.x - - 1.11.x - -go_import_path: go.bug.st/serial.v1 - -env: - - TEST_OS=linux TEST_ARCH=386 - - TEST_OS=linux TEST_ARCH=amd64 - - TEST_OS=linux TEST_ARCH=arm - - TEST_OS=windows TEST_ARCH=386 - - TEST_OS=windows TEST_ARCH=amd64 - - TEST_OS=darwin TEST_ARCH=386 - - TEST_OS=darwin TEST_ARCH=amd64 - - TEST_OS=freebsd TEST_ARCH=amd64 - - TEST_OS=openbsd TEST_ARCH=amd64 - - TEST_OS=openbsd TEST_ARCH=386 - - TEST_OS=openbsd TEST_ARCH=arm - -matrix: - exclude: - - os: linux - env: TEST_OS=darwin TEST_ARCH=386 - - os: linux - env: TEST_OS=darwin TEST_ARCH=amd64 - - os: osx - env: TEST_OS=linux TEST_ARCH=386 - - os: osx - env: TEST_OS=linux TEST_ARCH=amd64 - - os: osx - env: TEST_OS=linux TEST_ARCH=arm - - os: osx - env: TEST_OS=windows TEST_ARCH=386 - - os: osx - env: TEST_OS=windows TEST_ARCH=amd64 - - os: osx - env: TEST_OS=freebsd TEST_ARCH=amd64 - - os: osx - env: TEST_OS=openbsd TEST_ARCH=amd64 - - os: osx - env: TEST_OS=openbsd TEST_ARCH=386 - - os: osx - env: TEST_OS=openbsd TEST_ARCH=arm - allow_failures: - - env: TEST_OS=openbsd TEST_ARCH=arm - -before_install: - -script: - - GOARM=5 GO386=387 GOOS=$TEST_OS GOARCH=$TEST_ARCH go get github.com/stretchr/testify/require - - GOARM=5 GO386=387 GOOS=$TEST_OS GOARCH=$TEST_ARCH go get golang.org/x/sys/windows - - GOARM=5 GO386=387 GOOS=$TEST_OS GOARCH=$TEST_ARCH go build -v go.bug.st/serial.v1 - - GOARM=5 GO386=387 GOOS=$TEST_OS GOARCH=$TEST_ARCH go test -c -v go.bug.st/serial.v1 - -notifications: - email: - recipients: - - c.maglie@bug.st - on_success: change - on_failure: always - diff --git a/vendor/github.com/facchinm/go-serial/LICENSE b/vendor/github.com/facchinm/go-serial/LICENSE deleted file mode 100644 index 8596faba..00000000 --- a/vendor/github.com/facchinm/go-serial/LICENSE +++ /dev/null @@ -1,33 +0,0 @@ - -Copyright (c) 2014-2016, Cristian Maglie. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the copyright holder 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 HOLDER 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. - diff --git a/vendor/github.com/facchinm/go-serial/README.md b/vendor/github.com/facchinm/go-serial/README.md deleted file mode 100644 index 4ff3ccb4..00000000 --- a/vendor/github.com/facchinm/go-serial/README.md +++ /dev/null @@ -1,35 +0,0 @@ -[![Build Status](https://travis-ci.org/bugst/go-serial.svg?branch=v1)](https://travis-ci.org/bugst/go-serial) - -# go.bug.st/serial.v1 - -A cross-platform serial library for go-lang. - -## Documentation and examples - -See the godoc here: https://godoc.org/go.bug.st/serial.v1 - -## Development - -If you want to contribute to the development of this library, you must clone this git repository directly into your `src` folder under `src/go.bug.st/serial.v1` and checkout the branch `v1`. - -``` -cd $GOPATH -mkdir -p src/go.bug.st/ -git clone https://github.com/bugst/go-serial.git -b v1 src/go.bug.st/serial.v1 -go test go.bug.st/serial.v1 -``` - -## What's new in v1 - -There are some API improvements, in particular object naming is now more idiomatic, class names are less redundant (for example `serial.SerialPort` is now called `serial.Port`), some internal class fields, constants or enumerations are now private and some methods have been moved into the proper interface. - -If you come from the version v0 and want to see the full list of API changes, please check this pull request: - -https://github.com/bugst/go-serial/pull/5/files - -## License - -The software is release under a BSD 3-clause license - -https://github.com/bugst/go-serial/blob/v1/LICENSE - diff --git a/vendor/github.com/facchinm/go-serial/doc.go b/vendor/github.com/facchinm/go-serial/doc.go deleted file mode 100644 index d84c21f2..00000000 --- a/vendor/github.com/facchinm/go-serial/doc.go +++ /dev/null @@ -1,113 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -/* -Package serial is a cross-platform serial library for the go language. - -The canonical import for this library is go.bug.st/serial.v1 so the import line -is the following: - - import "go.bug.st/serial.v1" - -It is possible to get the list of available serial ports with the -GetPortsList function: - - ports, err := serial.GetPortsList() - if err != nil { - log.Fatal(err) - } - if len(ports) == 0 { - log.Fatal("No serial ports found!") - } - for _, port := range ports { - fmt.Printf("Found port: %v\n", port) - } - -The serial port can be opened with the Open function: - - mode := &serial.Mode{ - BaudRate: 115200, - } - port, err := serial.Open("/dev/ttyUSB0", mode) - if err != nil { - log.Fatal(err) - } - -The Open function needs a "mode" parameter that specifies the configuration -options for the serial port. If not specified the default options are 9600_N81, -in the example above only the speed is changed so the port is opened using 115200_N81. -The following snippets shows how to declare a configuration for 57600_E71: - - mode := &serial.Mode{ - BaudRate: 57600, - Parity: serial.EvenParity, - DataBits: 7, - StopBits: serial.OneStopBit, - } - -The configuration can be changed at any time with the SetMode function: - - err := port.SetMode(mode) - if err != nil { - log.Fatal(err) - } - -The port object implements the io.ReadWriteCloser interface, so we can use -the usual Read, Write and Close functions to send and receive data from the -serial port: - - n, err := port.Write([]byte("10,20,30\n\r")) - if err != nil { - log.Fatal(err) - } - fmt.Printf("Sent %v bytes\n", n) - - buff := make([]byte, 100) - for { - n, err := port.Read(buff) - if err != nil { - log.Fatal(err) - break - } - if n == 0 { - fmt.Println("\nEOF") - break - } - fmt.Printf("%v", string(buff[:n])) - } - -If a port is a virtual USB-CDC serial port (for example an USB-to-RS232 -cable or a microcontroller development board) is possible to retrieve -the USB metadata, like VID/PID or USB Serial Number, with the -GetDetailedPortsList function in the enumerator package: - - import "go.bug.st/serial.v1/enumerator" - - ports, err := enumerator.GetDetailedPortsList() - if err != nil { - log.Fatal(err) - } - if len(ports) == 0 { - fmt.Println("No serial ports found!") - return - } - for _, port := range ports { - fmt.Printf("Found port: %s\n", port.Name) - if port.IsUSB { - fmt.Printf(" USB ID %s:%s\n", port.VID, port.PID) - fmt.Printf(" USB serial %s\n", port.SerialNumber) - } - } - -for details on USB port enumeration see the documentation of the specific package. - -This library tries to avoid the use of the "C" package (and consequently the need -of cgo) to simplify cross compiling. -Unfortunately the USB enumeration package for darwin (MacOSX) requires cgo -to access the IOKit framework. This means that if you need USB enumeration -on darwin you're forced to use cgo. -*/ -package serial diff --git a/vendor/github.com/facchinm/go-serial/enumerator/doc.go b/vendor/github.com/facchinm/go-serial/enumerator/doc.go deleted file mode 100644 index d214715a..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/doc.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -/* -Package enumerator is a golang cross-platform library for USB serial port discovery. - -WARNING: this library is still beta-testing code! please consider the library -and the API as *unstable*. Beware that, even if at this point it's unlike to -happen, the API may be subject to change until this notice is removed from -the documentation. - -This library has been tested on Linux, Windows and Mac and uses specific OS -services to enumerate USB PID/VID, in particular on MacOSX the use of cgo is -required in order to access the IOKit Framework. This means that the library -cannot be easily cross compiled for GOOS=darwing targets. - -*/ -package enumerator // import "go.bug.st/serial.v1/enumerator" diff --git a/vendor/github.com/facchinm/go-serial/enumerator/enumerator.go b/vendor/github.com/facchinm/go-serial/enumerator/enumerator.go deleted file mode 100644 index 3dbc1979..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/enumerator.go +++ /dev/null @@ -1,43 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package enumerator // import "go.bug.st/serial.v1/enumerator" - -//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output syscall_windows.go usb_windows.go - -// PortDetails contains detailed information about USB serial port. -// Use GetDetailedPortsList function to retrieve it. -type PortDetails struct { - Name string - IsUSB bool - VID string - PID string - SerialNumber string - - // Manufacturer string - // Product string -} - -// GetDetailedPortsList retrieve ports details like USB VID/PID. -// Please note that this function may not be available on all OS: -// in that case a FunctionNotImplemented error is returned. -func GetDetailedPortsList() ([]*PortDetails, error) { - return nativeGetDetailedPortsList() -} - -// PortEnumerationError is the error type for serial ports enumeration -type PortEnumerationError struct { - causedBy error -} - -// Error returns the complete error code with details on the cause of the error -func (e PortEnumerationError) Error() string { - reason := "Error while enumerating serial ports" - if e.causedBy != nil { - reason += ": " + e.causedBy.Error() - } - return reason -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/example_getdetailedportlist_test.go b/vendor/github.com/facchinm/go-serial/enumerator/example_getdetailedportlist_test.go deleted file mode 100644 index 18c7738b..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/example_getdetailedportlist_test.go +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package enumerator_test - -import "fmt" -import "log" -import "go.bug.st/serial.v1/enumerator" - -func ExampleGetDetailedPortsList() { - ports, err := enumerator.GetDetailedPortsList() - if err != nil { - log.Fatal(err) - } - if len(ports) == 0 { - fmt.Println("No serial ports found!") - return - } - for _, port := range ports { - fmt.Printf("Found port: %s\n", port.Name) - if port.IsUSB { - fmt.Printf(" USB ID %s:%s\n", port.VID, port.PID) - fmt.Printf(" USB serial %s\n", port.SerialNumber) - } - } -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/syscall_windows.go b/vendor/github.com/facchinm/go-serial/enumerator/syscall_windows.go deleted file mode 100644 index cd598c75..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/syscall_windows.go +++ /dev/null @@ -1,113 +0,0 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT - -package enumerator - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -var _ unsafe.Pointer - -var ( - modsetupapi = windows.NewLazySystemDLL("setupapi.dll") - - procSetupDiClassGuidsFromNameW = modsetupapi.NewProc("SetupDiClassGuidsFromNameW") - procSetupDiGetClassDevsW = modsetupapi.NewProc("SetupDiGetClassDevsW") - procSetupDiDestroyDeviceInfoList = modsetupapi.NewProc("SetupDiDestroyDeviceInfoList") - procSetupDiEnumDeviceInfo = modsetupapi.NewProc("SetupDiEnumDeviceInfo") - procSetupDiGetDeviceInstanceIdW = modsetupapi.NewProc("SetupDiGetDeviceInstanceIdW") - procSetupDiOpenDevRegKey = modsetupapi.NewProc("SetupDiOpenDevRegKey") - procSetupDiGetDeviceRegistryPropertyW = modsetupapi.NewProc("SetupDiGetDeviceRegistryPropertyW") -) - -func setupDiClassGuidsFromNameInternal(class string, guid *guid, guidSize uint32, requiredSize *uint32) (err error) { - var _p0 *uint16 - _p0, err = syscall.UTF16PtrFromString(class) - if err != nil { - return - } - return _setupDiClassGuidsFromNameInternal(_p0, guid, guidSize, requiredSize) -} - -func _setupDiClassGuidsFromNameInternal(class *uint16, guid *guid, guidSize uint32, requiredSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiClassGuidsFromNameW.Addr(), 4, uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(guid)), uintptr(guidSize), uintptr(unsafe.Pointer(requiredSize)), 0, 0) - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setupDiGetClassDevs(guid *guid, enumerator *string, hwndParent uintptr, flags uint32) (set devicesSet, err error) { - r0, _, e1 := syscall.Syscall6(procSetupDiGetClassDevsW.Addr(), 4, uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(enumerator)), uintptr(hwndParent), uintptr(flags), 0, 0) - set = devicesSet(r0) - if set == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setupDiDestroyDeviceInfoList(set devicesSet) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiDestroyDeviceInfoList.Addr(), 1, uintptr(set), 0, 0) - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setupDiEnumDeviceInfo(set devicesSet, index uint32, info *devInfoData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiEnumDeviceInfo.Addr(), 3, uintptr(set), uintptr(index), uintptr(unsafe.Pointer(info))) - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setupDiGetDeviceInstanceId(set devicesSet, devInfo *devInfoData, devInstanceId unsafe.Pointer, devInstanceIdSize uint32, requiredSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiGetDeviceInstanceIdW.Addr(), 5, uintptr(set), uintptr(unsafe.Pointer(devInfo)), uintptr(devInstanceId), uintptr(devInstanceIdSize), uintptr(unsafe.Pointer(requiredSize)), 0) - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setupDiOpenDevRegKey(set devicesSet, devInfo *devInfoData, scope dicsScope, hwProfile uint32, keyType uint32, samDesired regsam) (hkey syscall.Handle, err error) { - r0, _, e1 := syscall.Syscall6(procSetupDiOpenDevRegKey.Addr(), 6, uintptr(set), uintptr(unsafe.Pointer(devInfo)), uintptr(scope), uintptr(hwProfile), uintptr(keyType), uintptr(samDesired)) - hkey = syscall.Handle(r0) - if hkey == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setupDiGetDeviceRegistryProperty(set devicesSet, devInfo *devInfoData, property deviceProperty, propertyType *uint32, outValue *byte, outSize *uint32, reqSize *uint32) (res bool) { - r0, _, _ := syscall.Syscall9(procSetupDiGetDeviceRegistryPropertyW.Addr(), 7, uintptr(set), uintptr(unsafe.Pointer(devInfo)), uintptr(property), uintptr(unsafe.Pointer(propertyType)), uintptr(unsafe.Pointer(outValue)), uintptr(unsafe.Pointer(outSize)), uintptr(unsafe.Pointer(reqSize)), 0, 0) - res = r0 != 0 - return -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/usb_darwin.go b/vendor/github.com/facchinm/go-serial/enumerator/usb_darwin.go deleted file mode 100644 index 4fcd4dc6..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/usb_darwin.go +++ /dev/null @@ -1,226 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// +build go1.10,darwin - -package enumerator // import "go.bug.st/serial.v1/enumerator" - -// #cgo LDFLAGS: -framework CoreFoundation -framework IOKit -// #include -// #include -// #include -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -func nativeGetDetailedPortsList() ([]*PortDetails, error) { - var ports []*PortDetails - - services, err := getAllServices("IOSerialBSDClient") - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - for _, service := range services { - defer service.Release() - - port, err := extractPortInfo(C.io_registry_entry_t(service)) - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - ports = append(ports, port) - } - return ports, nil -} - -func extractPortInfo(service C.io_registry_entry_t) (*PortDetails, error) { - name, err := service.GetStringProperty("IOCalloutDevice") - if err != nil { - return nil, fmt.Errorf("Error extracting port info from device: %s", err.Error()) - } - port := &PortDetails{} - port.Name = name - port.IsUSB = false - - usbDevice := service - var searchErr error - for usbDevice.GetClass() != "IOUSBDevice" { - if usbDevice, searchErr = usbDevice.GetParent("IOService"); searchErr != nil { - break - } - } - if searchErr == nil { - // It's an IOUSBDevice - vid, _ := usbDevice.GetIntProperty("idVendor", C.kCFNumberSInt16Type) - pid, _ := usbDevice.GetIntProperty("idProduct", C.kCFNumberSInt16Type) - serialNumber, _ := usbDevice.GetStringProperty("USB Serial Number") - //product, _ := usbDevice.GetStringProperty("USB Product Name") - //manufacturer, _ := usbDevice.GetStringProperty("USB Vendor Name") - //fmt.Println(product + " - " + manufacturer) - - port.IsUSB = true - port.VID = fmt.Sprintf("%04X", vid) - port.PID = fmt.Sprintf("%04X", pid) - port.SerialNumber = serialNumber - } - return port, nil -} - -func getAllServices(serviceType string) ([]C.io_object_t, error) { - i, err := getMatchingServices(serviceMatching(serviceType)) - if err != nil { - return nil, err - } - defer i.Release() - - var services []C.io_object_t - tries := 0 - for tries < 5 { - // Extract all elements from iterator - if service, ok := i.Next(); ok { - services = append(services, service) - continue - } - // If iterator is still valid return the result - if i.IsValid() { - return services, nil - } - // Otherwise empty the result and retry - for _, s := range services { - s.Release() - } - services = []C.io_object_t{} - i.Reset() - tries++ - } - // Give up if the iteration continues to fail... - return nil, fmt.Errorf("IOServiceGetMatchingServices failed, data changed while iterating") -} - -// serviceMatching create a matching dictionary that specifies an IOService class match. -func serviceMatching(serviceType string) C.CFMutableDictionaryRef { - t := C.CString(serviceType) - defer C.free(unsafe.Pointer(t)) - return C.IOServiceMatching(t) -} - -// getMatchingServices look up registered IOService objects that match a matching dictionary. -func getMatchingServices(matcher C.CFMutableDictionaryRef) (C.io_iterator_t, error) { - var i C.io_iterator_t - err := C.IOServiceGetMatchingServices(C.kIOMasterPortDefault, C.CFDictionaryRef(matcher), &i) - if err != C.KERN_SUCCESS { - return 0, fmt.Errorf("IOServiceGetMatchingServices failed (code %d)", err) - } - return i, nil -} - -// CFStringRef - -func cfStringCreateWithString(s string) C.CFStringRef { - c := C.CString(s) - defer C.free(unsafe.Pointer(c)) - return C.CFStringCreateWithCString( - C.kCFAllocatorDefault, c, C.kCFStringEncodingMacRoman) -} - -func (ref C.CFStringRef) Release() { - C.CFRelease(C.CFTypeRef(ref)) -} - -// CFTypeRef - -func (ref C.CFTypeRef) Release() { - C.CFRelease(ref) -} - -// io_registry_entry_t - -func (me *C.io_registry_entry_t) GetParent(plane string) (C.io_registry_entry_t, error) { - cPlane := C.CString(plane) - defer C.free(unsafe.Pointer(cPlane)) - var parent C.io_registry_entry_t - err := C.IORegistryEntryGetParentEntry(*me, cPlane, &parent) - if err != 0 { - return 0, errors.New("No parent device available") - } - return parent, nil -} - -func (me *C.io_registry_entry_t) CreateCFProperty(key string) (C.CFTypeRef, error) { - k := cfStringCreateWithString(key) - defer k.Release() - property := C.IORegistryEntryCreateCFProperty(*me, k, C.kCFAllocatorDefault, 0) - if property == 0 { - return 0, errors.New("Property not found: " + key) - } - return property, nil -} - -func (me *C.io_registry_entry_t) GetStringProperty(key string) (string, error) { - property, err := me.CreateCFProperty(key) - if err != nil { - return "", err - } - defer property.Release() - - if ptr := C.CFStringGetCStringPtr(C.CFStringRef(property), 0); ptr != nil { - return C.GoString(ptr), nil - } - // in certain circumstances CFStringGetCStringPtr may return NULL - // and we must retrieve the string by copy - buff := make([]C.char, 1024) - if C.CFStringGetCString(C.CFStringRef(property), &buff[0], 1024, 0) != C.true { - return "", fmt.Errorf("Property '%s' can't be converted", key) - } - return C.GoString(&buff[0]), nil -} - -func (me *C.io_registry_entry_t) GetIntProperty(key string, intType C.CFNumberType) (int, error) { - property, err := me.CreateCFProperty(key) - if err != nil { - return 0, err - } - defer property.Release() - var res int - if C.CFNumberGetValue((C.CFNumberRef)(property), intType, unsafe.Pointer(&res)) != C.true { - return res, fmt.Errorf("Property '%s' can't be converted or has been truncated", key) - } - return res, nil -} - -// io_iterator_t - -// IsValid checks if an iterator is still valid. -// Some iterators will be made invalid if changes are made to the -// structure they are iterating over. This function checks the iterator -// is still valid and should be called when Next returns zero. -// An invalid iterator can be Reset and the iteration restarted. -func (me *C.io_iterator_t) IsValid() bool { - return C.IOIteratorIsValid(*me) == C.true -} - -func (me *C.io_iterator_t) Reset() { - C.IOIteratorReset(*me) -} - -func (me *C.io_iterator_t) Next() (C.io_object_t, bool) { - res := C.IOIteratorNext(*me) - return res, res != 0 -} - -// io_object_t - -func (me *C.io_object_t) Release() { - C.IOObjectRelease(*me) -} - -func (me *C.io_object_t) GetClass() string { - class := make([]C.char, 1024) - C.IOObjectGetClass(*me, &class[0]) - return C.GoString(&class[0]) -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/usb_darwin_go1.9.go b/vendor/github.com/facchinm/go-serial/enumerator/usb_darwin_go1.9.go deleted file mode 100644 index 442278d2..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/usb_darwin_go1.9.go +++ /dev/null @@ -1,222 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// +build !go1.10,darwin - -// This file is here to keep compatibility with the older versions of go -// and is no more maintained or bugfixed, please update your go version -// to at least 1.10 to get the latest updates. - -package enumerator // import "go.bug.st/serial.v1/enumerator" - -// #cgo LDFLAGS: -framework CoreFoundation -framework IOKit -// #include -// #include -// #include -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -func nativeGetDetailedPortsList() ([]*PortDetails, error) { - var ports []*PortDetails - - services, err := getAllServices("IOSerialBSDClient") - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - for _, service := range services { - defer service.Release() - - port, err := extractPortInfo(C.io_registry_entry_t(service)) - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - ports = append(ports, port) - } - return ports, nil -} - -func extractPortInfo(service C.io_registry_entry_t) (*PortDetails, error) { - name, err := service.GetStringProperty("IOCalloutDevice") - if err != nil { - return nil, fmt.Errorf("Error extracting port info from device: %s", err.Error()) - } - port := &PortDetails{} - port.Name = name - port.IsUSB = false - - usbDevice := service - for usbDevice.GetClass() != "IOUSBDevice" { - if usbDevice, err = usbDevice.GetParent("IOService"); err != nil { - break - } - } - if err == nil { - // It's an IOUSBDevice - vid, _ := usbDevice.GetIntProperty("idVendor", C.kCFNumberSInt16Type) - pid, _ := usbDevice.GetIntProperty("idProduct", C.kCFNumberSInt16Type) - serialNumber, _ := usbDevice.GetStringProperty("USB Serial Number") - //product, _ := usbDevice.GetStringProperty("USB Product Name") - //manufacturer, _ := usbDevice.GetStringProperty("USB Vendor Name") - //fmt.Println(product + " - " + manufacturer) - - port.IsUSB = true - port.VID = fmt.Sprintf("%04X", vid) - port.PID = fmt.Sprintf("%04X", pid) - port.SerialNumber = serialNumber - } - return port, nil -} - -func getAllServices(serviceType string) ([]C.io_object_t, error) { - i, err := getMatchingServices(serviceMatching(serviceType)) - if err != nil { - return nil, err - } - defer i.Release() - - var services []C.io_object_t - tries := 0 - for tries < 5 { - // Extract all elements from iterator - if service, ok := i.Next(); ok { - services = append(services, service) - continue - } - // If iterator is still valid return the result - if i.IsValid() { - return services, nil - } - // Otherwise empty the result and retry - for _, s := range services { - s.Release() - } - services = []C.io_object_t{} - i.Reset() - tries++ - } - // Give up if the iteration continues to fail... - return nil, fmt.Errorf("IOServiceGetMatchingServices failed, data changed while iterating") -} - -// serviceMatching create a matching dictionary that specifies an IOService class match. -func serviceMatching(serviceType string) C.CFMutableDictionaryRef { - t := C.CString(serviceType) - defer C.free(unsafe.Pointer(t)) - return C.IOServiceMatching(t) -} - -// getMatchingServices look up registered IOService objects that match a matching dictionary. -func getMatchingServices(matcher C.CFMutableDictionaryRef) (C.io_iterator_t, error) { - var i C.io_iterator_t - err := C.IOServiceGetMatchingServices(C.kIOMasterPortDefault, matcher, &i) - if err != C.KERN_SUCCESS { - return 0, fmt.Errorf("IOServiceGetMatchingServices failed (code %d)", err) - } - return i, nil -} - -// CFStringRef - -func cfStringCreateWithString(s string) C.CFStringRef { - c := C.CString(s) - defer C.free(unsafe.Pointer(c)) - return C.CFStringCreateWithCString( - C.kCFAllocatorDefault, c, C.kCFStringEncodingMacRoman) -} - -// io_registry_entry_t - -func (me *C.io_registry_entry_t) GetParent(plane string) (C.io_registry_entry_t, error) { - cPlane := C.CString(plane) - defer C.free(unsafe.Pointer(cPlane)) - var parent C.io_registry_entry_t - err := C.IORegistryEntryGetParentEntry(*me, cPlane, &parent) - if err != 0 { - return 0, errors.New("No parent device available") - } - return parent, nil -} - -func (me *C.io_registry_entry_t) GetClass() string { - obj := (*C.io_object_t)(me) - return obj.GetClass() -} - -func (me *C.io_registry_entry_t) GetStringProperty(key string) (string, error) { - k := cfStringCreateWithString(key) - defer C.CFRelease(C.CFTypeRef(k)) - property := C.IORegistryEntryCreateCFProperty(*me, k, C.kCFAllocatorDefault, 0) - if property == nil { - return "", errors.New("Property not found: " + key) - } - defer C.CFRelease(property) - - if ptr := C.CFStringGetCStringPtr((C.CFStringRef)(unsafe.Pointer(property)), 0); ptr != nil { - return C.GoString(ptr), nil - } - // in certain circumstances CFStringGetCStringPtr may return NULL - // and we must retrieve the string by copy - buff := make([]C.char, 1024) - if C.CFStringGetCString((C.CFStringRef)(property), &buff[0], 1024, 0) != C.true { - return "", fmt.Errorf("Property '%s' can't be converted", key) - } - return C.GoString(&buff[0]), nil -} - -func (me *C.io_registry_entry_t) GetIntProperty(key string, intType C.CFNumberType) (int, error) { - k := cfStringCreateWithString(key) - defer C.CFRelease(C.CFTypeRef(k)) - property := C.IORegistryEntryCreateCFProperty(*me, k, C.kCFAllocatorDefault, 0) - if property == nil { - return 0, errors.New("Property not found: " + key) - } - defer C.CFRelease(property) - var res int - if C.CFNumberGetValue((C.CFNumberRef)(property), intType, unsafe.Pointer(&res)) != C.true { - return res, fmt.Errorf("Property '%s' can't be converted or has been truncated", key) - } - return res, nil -} - -// io_iterator_t - -// IsValid checks if an iterator is still valid. -// Some iterators will be made invalid if changes are made to the -// structure they are iterating over. This function checks the iterator -// is still valid and should be called when Next returns zero. -// An invalid iterator can be Reset and the iteration restarted. -func (me *C.io_iterator_t) IsValid() bool { - return C.IOIteratorIsValid(*me) == C.true -} - -func (me *C.io_iterator_t) Reset() { - C.IOIteratorReset(*me) -} - -func (me *C.io_iterator_t) Next() (C.io_object_t, bool) { - res := C.IOIteratorNext(*me) - return res, res != 0 -} - -func (me *C.io_iterator_t) Release() { - C.IOObjectRelease(C.io_object_t(*me)) -} - -// io_object_t - -func (me *C.io_object_t) Release() { - C.IOObjectRelease(*me) -} - -func (me *C.io_object_t) GetClass() string { - class := make([]C.char, 1024) - C.IOObjectGetClass(*me, &class[0]) - return C.GoString(&class[0]) -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/usb_freebsd.go b/vendor/github.com/facchinm/go-serial/enumerator/usb_freebsd.go deleted file mode 100644 index d60d13ff..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/usb_freebsd.go +++ /dev/null @@ -1,12 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package enumerator // import "go.bug.st/serial.v1/enumerator" - -func nativeGetDetailedPortsList() ([]*PortDetails, error) { - // TODO - return nil, &PortEnumerationError{} -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/usb_linux.go b/vendor/github.com/facchinm/go-serial/enumerator/usb_linux.go deleted file mode 100644 index d2aca906..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/usb_linux.go +++ /dev/null @@ -1,109 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package enumerator // import "go.bug.st/serial.v1/enumerator" - -import ( - "bufio" - "fmt" - "os" - "path/filepath" - - "go.bug.st/serial.v1" -) - -func nativeGetDetailedPortsList() ([]*PortDetails, error) { - // Retrieve the port list - ports, err := serial.GetPortsList() - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - - var res []*PortDetails - for _, port := range ports { - details, err := nativeGetPortDetails(port) - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - res = append(res, details) - } - return res, nil -} - -func nativeGetPortDetails(portPath string) (*PortDetails, error) { - portName := filepath.Base(portPath) - devicePath := fmt.Sprintf("/sys/class/tty/%s/device", portName) - if _, err := os.Stat(devicePath); err != nil { - return &PortDetails{}, nil - } - realDevicePath, err := filepath.EvalSymlinks(devicePath) - if err != nil { - return nil, fmt.Errorf("Can't determine real path of %s: %s", devicePath, err.Error()) - } - subSystemPath, err := filepath.EvalSymlinks(filepath.Join(realDevicePath, "subsystem")) - if err != nil { - return nil, fmt.Errorf("Can't determine real path of %s: %s", filepath.Join(realDevicePath, "subsystem"), err.Error()) - } - subSystem := filepath.Base(subSystemPath) - - result := &PortDetails{Name: portPath} - switch subSystem { - case "usb-serial": - err := parseUSBSysFS(filepath.Dir(filepath.Dir(realDevicePath)), result) - return result, err - case "usb": - err := parseUSBSysFS(filepath.Dir(realDevicePath), result) - return result, err - // TODO: other cases? - default: - return result, nil - } -} - -func parseUSBSysFS(usbDevicePath string, details *PortDetails) error { - vid, err := readLine(filepath.Join(usbDevicePath, "idVendor")) - if err != nil { - return err - } - pid, err := readLine(filepath.Join(usbDevicePath, "idProduct")) - if err != nil { - return err - } - serial, err := readLine(filepath.Join(usbDevicePath, "serial")) - if err != nil { - return err - } - //manufacturer, err := readLine(filepath.Join(usbDevicePath, "manufacturer")) - //if err != nil { - // return err - //} - //product, err := readLine(filepath.Join(usbDevicePath, "product")) - //if err != nil { - // return err - //} - - details.IsUSB = true - details.VID = vid - details.PID = pid - details.SerialNumber = serial - //details.Manufacturer = manufacturer - //details.Product = product - return nil -} - -func readLine(filename string) (string, error) { - file, err := os.Open(filename) - if os.IsNotExist(err) { - return "", nil - } - if err != nil { - return "", err - } - defer file.Close() - reader := bufio.NewReader(file) - line, _, err := reader.ReadLine() - return string(line), err -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/usb_ole_windows.go b/vendor/github.com/facchinm/go-serial/enumerator/usb_ole_windows.go deleted file mode 100644 index bbc04355..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/usb_ole_windows.go +++ /dev/null @@ -1,113 +0,0 @@ -// -// Copyright 2014-2017 Lars Knudsen, Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// +build ignore - -package enumerator - -import ( - "log" - "regexp" - - ole "github.com/go-ole/go-ole" - "github.com/go-ole/go-ole/oleutil" -) - -func init() { - err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED) - if err != nil { - log.Fatal("Init error: ", err) - } -} - -func nativeGetDetailedPortsList() ([]*PortDetails, error) { - unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator") - if err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err} - } - defer unknown.Release() - - wmi, err := unknown.QueryInterface(ole.IID_IDispatch) - if err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err} - } - defer wmi.Release() - - serviceRaw, err := wmi.CallMethod("ConnectServer") - if err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err} - } - service := serviceRaw.ToIDispatch() - defer service.Release() - - query := "SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0 and Name like '%(COM%'" - queryResult, err := oleutil.CallMethod(service, "ExecQuery", query) - if err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err} - } - result := queryResult.ToIDispatch() - defer result.Release() - - countVar, err := result.GetProperty("Count") - if err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err} - } - count := int(countVar.Val) - - res := []*PortDetails{} - - // Retrieve all items - for i := 0; i < count; i++ { - itemRaw, err := result.CallMethod("ItemIndex", i) - if err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err} - } - item := itemRaw.ToIDispatch() - defer item.Release() - - detail := &PortDetails{} - if err := getPortDetails(item, detail); err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err} - } - // SerialPort{Path: path, VendorId: VID, ProductId: PID, DisplayName: displayName.ToString()} - res = append(res, detail) - } - - return res, nil -} - -func getPortDetails(item *ole.IDispatch, res *PortDetails) error { - // Find port name - itemName, err := item.GetProperty("Name") - if err != nil { - return err - } - re := regexp.MustCompile("\\((COM[0-9]+)\\)").FindAllStringSubmatch(itemName.ToString(), 1) - if re == nil || len(re[0]) < 2 { - // Discard items that are not serial ports - return nil - } - res.Name = re[0][1] - - //itemPnPDeviceID, err := item.GetProperty("PnPDeviceID") - //if err != nil { - // return err - //} - //PnPDeviceID := itemPnPDeviceID.ToString() - - itemDeviceID, err := item.GetProperty("DeviceID") - if err != nil { - return err - } - parseDeviceID(itemDeviceID.ToString(), res) - - itemManufacturer, err := item.GetProperty("Product") - if err != nil { - return err - } - res.Manufacturer = itemManufacturer.ToString() - return nil -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/usb_windows.go b/vendor/github.com/facchinm/go-serial/enumerator/usb_windows.go deleted file mode 100644 index 12ded68e..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/usb_windows.go +++ /dev/null @@ -1,302 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package enumerator // import "go.bug.st/serial.v1/enumerator" - -import ( - "fmt" - "regexp" - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -func parseDeviceID(deviceID string, details *PortDetails) { - // Windows stock USB-CDC driver - if len(deviceID) >= 3 && deviceID[:3] == "USB" { - re := regexp.MustCompile("VID_(....)&PID_(....)(\\\\(\\w+)$)?").FindAllStringSubmatch(deviceID, -1) - if re == nil || len(re[0]) < 2 { - // Silently ignore unparsable strings - return - } - details.IsUSB = true - details.VID = re[0][1] - details.PID = re[0][2] - if len(re[0]) >= 4 { - details.SerialNumber = re[0][4] - } - return - } - - // FTDI driver - if len(deviceID) >= 7 && deviceID[:7] == "FTDIBUS" { - re := regexp.MustCompile("VID_(....)\\+PID_(....)(\\+(\\w+))?").FindAllStringSubmatch(deviceID, -1) - if re == nil || len(re[0]) < 2 { - // Silently ignore unparsable strings - return - } - details.IsUSB = true - details.VID = re[0][1] - details.PID = re[0][2] - if len(re[0]) >= 4 { - details.SerialNumber = re[0][4] - } - return - } - - // Other unidentified device type -} - -// setupapi based -// -------------- - -//sys setupDiClassGuidsFromNameInternal(class string, guid *guid, guidSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiClassGuidsFromNameW -//sys setupDiGetClassDevs(guid *guid, enumerator *string, hwndParent uintptr, flags uint32) (set devicesSet, err error) = setupapi.SetupDiGetClassDevsW -//sys setupDiDestroyDeviceInfoList(set devicesSet) (err error) = setupapi.SetupDiDestroyDeviceInfoList -//sys setupDiEnumDeviceInfo(set devicesSet, index uint32, info *devInfoData) (err error) = setupapi.SetupDiEnumDeviceInfo -//sys setupDiGetDeviceInstanceId(set devicesSet, devInfo *devInfoData, devInstanceId unsafe.Pointer, devInstanceIdSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetDeviceInstanceIdW -//sys setupDiOpenDevRegKey(set devicesSet, devInfo *devInfoData, scope dicsScope, hwProfile uint32, keyType uint32, samDesired regsam) (hkey syscall.Handle, err error) = setupapi.SetupDiOpenDevRegKey -//sys setupDiGetDeviceRegistryProperty(set devicesSet, devInfo *devInfoData, property deviceProperty, propertyType *uint32, outValue *byte, outSize *uint32, reqSize *uint32) (res bool) = setupapi.SetupDiGetDeviceRegistryPropertyW - -// Device registry property codes -// (Codes marked as read-only (R) may only be used for -// SetupDiGetDeviceRegistryProperty) -// -// These values should cover the same set of registry properties -// as defined by the CM_DRP codes in cfgmgr32.h. -// -// Note that SPDRP codes are zero based while CM_DRP codes are one based! -type deviceProperty uint32 - -const ( - spdrpDeviceDesc deviceProperty = 0x00000000 // DeviceDesc = R/W - spdrpHardwareID = 0x00000001 // HardwareID = R/W - spdrpCompatibleIDS = 0x00000002 // CompatibleIDs = R/W - spdrpUnused0 = 0x00000003 // Unused - spdrpService = 0x00000004 // Service = R/W - spdrpUnused1 = 0x00000005 // Unused - spdrpUnused2 = 0x00000006 // Unused - spdrpClass = 0x00000007 // Class = R--tied to ClassGUID - spdrpClassGUID = 0x00000008 // ClassGUID = R/W - spdrpDriver = 0x00000009 // Driver = R/W - spdrpConfigFlags = 0x0000000A // ConfigFlags = R/W - spdrpMFG = 0x0000000B // Mfg = R/W - spdrpFriendlyName = 0x0000000C // FriendlyName = R/W - spdrpLocationIinformation = 0x0000000D // LocationInformation = R/W - spdrpPhysicalDeviceObjectName = 0x0000000E // PhysicalDeviceObjectName = R - spdrpCapabilities = 0x0000000F // Capabilities = R - spdrpUINumber = 0x00000010 // UiNumber = R - spdrpUpperFilters = 0x00000011 // UpperFilters = R/W - spdrpLowerFilters = 0x00000012 // LowerFilters = R/W - spdrpBusTypeGUID = 0x00000013 // BusTypeGUID = R - spdrpLegactBusType = 0x00000014 // LegacyBusType = R - spdrpBusNumber = 0x00000015 // BusNumber = R - spdrpEnumeratorName = 0x00000016 // Enumerator Name = R - spdrpSecurity = 0x00000017 // Security = R/W, binary form - spdrpSecuritySDS = 0x00000018 // Security = W, SDS form - spdrpDevType = 0x00000019 // Device Type = R/W - spdrpExclusive = 0x0000001A // Device is exclusive-access = R/W - spdrpCharacteristics = 0x0000001B // Device Characteristics = R/W - spdrpAddress = 0x0000001C // Device Address = R - spdrpUINumberDescFormat = 0X0000001D // UiNumberDescFormat = R/W - spdrpDevicePowerData = 0x0000001E // Device Power Data = R - spdrpRemovalPolicy = 0x0000001F // Removal Policy = R - spdrpRemovalPolicyHWDefault = 0x00000020 // Hardware Removal Policy = R - spdrpRemovalPolicyOverride = 0x00000021 // Removal Policy Override = RW - spdrpInstallState = 0x00000022 // Device Install State = R - spdrpLocationPaths = 0x00000023 // Device Location Paths = R - spdrpBaseContainerID = 0x00000024 // Base ContainerID = R - - spdrpMaximumProperty = 0x00000025 // Upper bound on ordinals -) - -// Values specifying the scope of a device property change -type dicsScope uint32 - -const ( - dicsFlagGlobal dicsScope = 0x00000001 // make change in all hardware profiles - dicsFlagConfigSspecific = 0x00000002 // make change in specified profile only - dicsFlagConfigGeneral = 0x00000004 // 1 or more hardware profile-specific -) - -// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724878(v=vs.85).aspx -type regsam uint32 - -const ( - keyAllAccess regsam = 0xF003F - keyCreateLink = 0x00020 - keyCreateSubKey = 0x00004 - keyEnumerateSubKeys = 0x00008 - keyExecute = 0x20019 - keyNotify = 0x00010 - keyQueryValue = 0x00001 - keyRead = 0x20019 - keySetValue = 0x00002 - keyWOW64_32key = 0x00200 - keyWOW64_64key = 0x00100 - keyWrite = 0x20006 -) - -// KeyType values for SetupDiCreateDevRegKey, SetupDiOpenDevRegKey, and -// SetupDiDeleteDevRegKey. -const ( - diregDev = 0x00000001 // Open/Create/Delete device key - diregDrv = 0x00000002 // Open/Create/Delete driver key - diregBoth = 0x00000004 // Delete both driver and Device key -) - -// https://msdn.microsoft.com/it-it/library/windows/desktop/aa373931(v=vs.85).aspx -type guid struct { - data1 uint32 - data2 uint16 - data3 uint16 - data4 [8]byte -} - -func (g guid) String() string { - return fmt.Sprintf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - g.data1, g.data2, g.data3, - g.data4[0], g.data4[1], g.data4[2], g.data4[3], - g.data4[4], g.data4[5], g.data4[6], g.data4[7]) -} - -func classGuidsFromName(className string) ([]guid, error) { - // Determine the number of GUIDs for className - n := uint32(0) - if err := setupDiClassGuidsFromNameInternal(className, nil, 0, &n); err != nil { - // ignore error: UIDs array size too small - } - - res := make([]guid, n) - err := setupDiClassGuidsFromNameInternal(className, &res[0], n, &n) - return res, err -} - -const ( - digcfDefault = 0x00000001 // only valid with digcfDeviceInterface - digcfPresent = 0x00000002 - digcfAllClasses = 0x00000004 - digcfProfile = 0x00000008 - digcfDeviceInterface = 0x00000010 -) - -type devicesSet syscall.Handle - -func (g *guid) getDevicesSet() (devicesSet, error) { - return setupDiGetClassDevs(g, nil, 0, digcfPresent) -} - -func (set devicesSet) destroy() { - setupDiDestroyDeviceInfoList(set) -} - -// https://msdn.microsoft.com/en-us/library/windows/hardware/ff552344(v=vs.85).aspx -type devInfoData struct { - size uint32 - guid guid - devInst uint32 - reserved uintptr -} - -type deviceInfo struct { - set devicesSet - data devInfoData -} - -func (set devicesSet) getDeviceInfo(index int) (*deviceInfo, error) { - result := &deviceInfo{set: set} - - result.data.size = uint32(unsafe.Sizeof(result.data)) - err := setupDiEnumDeviceInfo(set, uint32(index), &result.data) - return result, err -} - -func (dev *deviceInfo) getInstanceID() (string, error) { - n := uint32(0) - setupDiGetDeviceInstanceId(dev.set, &dev.data, nil, 0, &n) - buff := make([]uint16, n) - if err := setupDiGetDeviceInstanceId(dev.set, &dev.data, unsafe.Pointer(&buff[0]), uint32(len(buff)), &n); err != nil { - return "", err - } - return windows.UTF16ToString(buff[:]), nil -} - -func (dev *deviceInfo) openDevRegKey(scope dicsScope, hwProfile uint32, keyType uint32, samDesired regsam) (syscall.Handle, error) { - return setupDiOpenDevRegKey(dev.set, &dev.data, scope, hwProfile, keyType, samDesired) -} - -func nativeGetDetailedPortsList() ([]*PortDetails, error) { - guids, err := classGuidsFromName("Ports") - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - - var res []*PortDetails - for _, g := range guids { - devsSet, err := g.getDevicesSet() - if err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - defer devsSet.destroy() - - for i := 0; ; i++ { - device, err := devsSet.getDeviceInfo(i) - if err != nil { - break - } - details := &PortDetails{} - portName, err := retrievePortNameFromDevInfo(device) - if err != nil { - continue - } - if len(portName) < 3 || portName[0:3] != "COM" { - // Accept only COM ports - continue - } - details.Name = portName - - if err := retrievePortDetailsFromDevInfo(device, details); err != nil { - return nil, &PortEnumerationError{causedBy: err} - } - res = append(res, details) - } - } - return res, nil -} - -func retrievePortNameFromDevInfo(device *deviceInfo) (string, error) { - h, err := device.openDevRegKey(dicsFlagGlobal, 0, diregDev, keyRead) - if err != nil { - return "", err - } - defer syscall.RegCloseKey(h) - - var name [1024]uint16 - nameP := (*byte)(unsafe.Pointer(&name[0])) - nameSize := uint32(len(name) * 2) - if err := syscall.RegQueryValueEx(h, syscall.StringToUTF16Ptr("PortName"), nil, nil, nameP, &nameSize); err != nil { - return "", err - } - return syscall.UTF16ToString(name[:]), nil -} - -func retrievePortDetailsFromDevInfo(device *deviceInfo, details *PortDetails) error { - deviceID, err := device.getInstanceID() - if err != nil { - return err - } - parseDeviceID(deviceID, details) - - var friendlyName [1024]uint16 - friendlyNameP := (*byte)(unsafe.Pointer(&friendlyName[0])) - friendlyNameSize := uint32(len(friendlyName) * 2) - if setupDiGetDeviceRegistryProperty(device.set, &device.data, spdrpDeviceDesc /* spdrpFriendlyName */, nil, friendlyNameP, &friendlyNameSize, nil) { - //details.Product = syscall.UTF16ToString(friendlyName[:]) - } - - return nil -} diff --git a/vendor/github.com/facchinm/go-serial/enumerator/usb_windows_test.go b/vendor/github.com/facchinm/go-serial/enumerator/usb_windows_test.go deleted file mode 100644 index 853c1a24..00000000 --- a/vendor/github.com/facchinm/go-serial/enumerator/usb_windows_test.go +++ /dev/null @@ -1,49 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package enumerator // import "go.bug.st/serial.v1/enumerator" - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func parseAndReturnDeviceID(deviceID string) *PortDetails { - res := &PortDetails{} - parseDeviceID(deviceID, res) - return res -} - -func TestParseDeviceID(t *testing.T) { - r := require.New(t) - test := func(deviceId, vid, pid, serialNo string) { - res := parseAndReturnDeviceID(deviceId) - r.True(res.IsUSB) - r.Equal(vid, res.VID) - r.Equal(pid, res.PID) - r.Equal(serialNo, res.SerialNumber) - } - - test("FTDIBUS\\VID_0403+PID_6001+A6004CCFA\\0000", "0403", "6001", "A6004CCFA") - test("USB\\VID_16C0&PID_0483\\12345", "16C0", "0483", "12345") - test("USB\\VID_2341&PID_0000\\64936333936351400000", "2341", "0000", "64936333936351400000") - test("USB\\VID_2341&PID_0000\\6493234373835191F1F1", "2341", "0000", "6493234373835191F1F1") - test("USB\\VID_2341&PID_804E&MI_00\\6&279A3900&0&0000", "2341", "804E", "") - test("USB\\VID_2341&PID_004E\\5&C3DC240&0&1", "2341", "004E", "") - test("USB\\VID_03EB&PID_2111&MI_01\\6&21F3553F&0&0001", "03EB", "2111", "") // Atmel EDBG - test("USB\\VID_2341&PID_804D&MI_00\\6&1026E213&0&0000", "2341", "804D", "") - test("USB\\VID_2341&PID_004D\\5&C3DC240&0&1", "2341", "004D", "") - test("USB\\VID_067B&PID_2303\\6&2C4CB384&0&3", "067B", "2303", "") // PL2303 -} - -func TestParseDeviceIDWithInvalidStrings(t *testing.T) { - r := require.New(t) - res := parseAndReturnDeviceID("ABC") - r.False(res.IsUSB) - res2 := parseAndReturnDeviceID("USB") - r.False(res2.IsUSB) -} diff --git a/vendor/github.com/facchinm/go-serial/example_getportlist_test.go b/vendor/github.com/facchinm/go-serial/example_getportlist_test.go deleted file mode 100644 index c8cb35b5..00000000 --- a/vendor/github.com/facchinm/go-serial/example_getportlist_test.go +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial_test - -import "fmt" -import "log" -import "go.bug.st/serial.v1" - -func ExampleGetPortsList() { - ports, err := serial.GetPortsList() - if err != nil { - log.Fatal(err) - } - if len(ports) == 0 { - fmt.Println("No serial ports found!") - } else { - for _, port := range ports { - fmt.Printf("Found port: %v\n", port) - } - } -} diff --git a/vendor/github.com/facchinm/go-serial/example_modem_bits_test.go b/vendor/github.com/facchinm/go-serial/example_modem_bits_test.go deleted file mode 100644 index 9ae3389b..00000000 --- a/vendor/github.com/facchinm/go-serial/example_modem_bits_test.go +++ /dev/null @@ -1,67 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial_test - -import "log" -import "go.bug.st/serial.v1" -import "fmt" -import "time" - -func ExampleGetSetModemBits() { - // Open the first serial port detected at 9600bps N81 - mode := &serial.Mode{ - BaudRate: 9600, - Parity: serial.NoParity, - DataBits: 8, - StopBits: serial.OneStopBit, - } - port, err := serial.Open("/dev/ttyACM1", mode) - if err != nil { - log.Fatal(err) - } - defer port.Close() - - count := 0 - for count < 25 { - status, err := port.GetModemStatusBits() - if err != nil { - log.Fatal(err) - } - fmt.Printf("Status: %+v\n", status) - - time.Sleep(time.Second) - count++ - if count == 5 { - err := port.SetDTR(false) - if err != nil { - log.Fatal(err) - } - fmt.Println("Set DTR OFF") - } - if count == 10 { - err := port.SetDTR(true) - if err != nil { - log.Fatal(err) - } - fmt.Println("Set DTR ON") - } - if count == 15 { - err := port.SetRTS(false) - if err != nil { - log.Fatal(err) - } - fmt.Println("Set RTS OFF") - } - if count == 20 { - err := port.SetRTS(true) - if err != nil { - log.Fatal(err) - } - fmt.Println("Set RTS ON") - } - } -} diff --git a/vendor/github.com/facchinm/go-serial/example_serialport_test.go b/vendor/github.com/facchinm/go-serial/example_serialport_test.go deleted file mode 100644 index 6f096590..00000000 --- a/vendor/github.com/facchinm/go-serial/example_serialport_test.go +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial_test - -import "fmt" -import "log" -import "go.bug.st/serial.v1" - -func ExampleSerialPort_SetMode() { - port, err := serial.Open("/dev/ttyACM0", &serial.Mode{}) - if err != nil { - log.Fatal(err) - } - mode := &serial.Mode{ - BaudRate: 9600, - Parity: serial.NoParity, - DataBits: 8, - StopBits: serial.OneStopBit, - } - if err := port.SetMode(mode); err != nil { - log.Fatal(err) - } - fmt.Println("Port set to 9600 N81") -} diff --git a/vendor/github.com/facchinm/go-serial/example_test.go b/vendor/github.com/facchinm/go-serial/example_test.go deleted file mode 100644 index 4f569789..00000000 --- a/vendor/github.com/facchinm/go-serial/example_test.go +++ /dev/null @@ -1,65 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial_test - -import "fmt" -import "log" -import "go.bug.st/serial.v1" - -// This example prints the list of serial ports and use the first one -// to send a string "10,20,30" and prints the response on the screen. -func Example_sendAndReceive() { - - // Retrieve the port list - ports, err := serial.GetPortsList() - if err != nil { - log.Fatal(err) - } - if len(ports) == 0 { - log.Fatal("No serial ports found!") - } - - // Print the list of detected ports - for _, port := range ports { - fmt.Printf("Found port: %v\n", port) - } - - // Open the first serial port detected at 9600bps N81 - mode := &serial.Mode{ - BaudRate: 9600, - Parity: serial.NoParity, - DataBits: 8, - StopBits: serial.OneStopBit, - } - port, err := serial.Open(ports[0], mode) - if err != nil { - log.Fatal(err) - } - - // Send the string "10,20,30\n\r" to the serial port - n, err := port.Write([]byte("10,20,30\n\r")) - if err != nil { - log.Fatal(err) - } - fmt.Printf("Sent %v bytes\n", n) - - // Read and print the response - buff := make([]byte, 100) - for { - // Reads up to 100 bytes - n, err := port.Read(buff) - if err != nil { - log.Fatal(err) - break - } - if n == 0 { - fmt.Println("\nEOF") - break - } - fmt.Printf("%v", string(buff[:n])) - } -} diff --git a/vendor/github.com/facchinm/go-serial/portlist/portlist.go b/vendor/github.com/facchinm/go-serial/portlist/portlist.go deleted file mode 100644 index 5d4d1272..00000000 --- a/vendor/github.com/facchinm/go-serial/portlist/portlist.go +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright 2014-2018 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// portlist is a tool to list all the available serial ports. -// Just run it and it will produce an output like: -// -// $ go run portlist.go -// Port: /dev/cu.Bluetooth-Incoming-Port -// Port: /dev/cu.usbmodemFD121 -// USB ID 2341:8053 -// USB serial FB7B6060504B5952302E314AFF08191A -// -package main - -import "fmt" -import "log" -import "go.bug.st/serial.v1/enumerator" - -func main() { - ports, err := enumerator.GetDetailedPortsList() - if err != nil { - log.Fatal(err) - } - if len(ports) == 0 { - return - } - for _, port := range ports { - fmt.Printf("Port: %s\n", port.Name) - if port.IsUSB { - fmt.Printf(" USB ID %s:%s\n", port.VID, port.PID) - fmt.Printf(" USB serial %s\n", port.SerialNumber) - } - } -} diff --git a/vendor/github.com/facchinm/go-serial/serial.go b/vendor/github.com/facchinm/go-serial/serial.go deleted file mode 100644 index 743151d4..00000000 --- a/vendor/github.com/facchinm/go-serial/serial.go +++ /dev/null @@ -1,179 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go - -// Port is the interface for a serial Port -type Port interface { - // SetMode sets all parameters of the serial port - SetMode(mode *Mode) error - - // Stores data received from the serial port into the provided byte array - // buffer. The function returns the number of bytes read. - // - // The Read function blocks until (at least) one byte is received from - // the serial port or an error occurs. - Read(p []byte) (n int, err error) - - // Send the content of the data byte array to the serial port. - // Returns the number of bytes written. - Write(p []byte) (n int, err error) - - // ResetInputBuffer Purges port read buffer - ResetInputBuffer() error - - // ResetOutputBuffer Purges port write buffer - ResetOutputBuffer() error - - // SetDTR sets the modem status bit DataTerminalReady - SetDTR(dtr bool) error - - // SetRTS sets the modem status bit RequestToSend - SetRTS(rts bool) error - - // GetModemStatusBits returns a ModemStatusBits structure containing the - // modem status bits for the serial port (CTS, DSR, etc...) - GetModemStatusBits() (*ModemStatusBits, error) - - // Close the serial port - Close() error -} - -// ModemStatusBits contains all the modem status bits for a serial port (CTS, DSR, etc...). -// It can be retrieved with the Port.GetModemStatusBits() method. -type ModemStatusBits struct { - CTS bool // ClearToSend status - DSR bool // DataSetReady status - RI bool // RingIndicator status - DCD bool // DataCarrierDetect status -} - -// Open opens the serial port using the specified modes -func Open(portName string, mode *Mode) (Port, error) { - return nativeOpen(portName, mode) -} - -// GetPortsList retrieve the list of available serial ports -func GetPortsList() ([]string, error) { - return nativeGetPortsList() -} - -// Mode describes a serial port configuration. -type Mode struct { - BaudRate int // The serial port bitrate (aka Baudrate) - DataBits int // Size of the character (must be 5, 6, 7 or 8) - Parity Parity // Parity (see Parity type for more info) - StopBits StopBits // Stop bits (see StopBits type for more info) - Vmin uint8 // Vmin (minimum characters to receive before returning) - Vtimeout uint8 // VTimeout (minimum time to wait before returning) -} - -// Parity describes a serial port parity setting -type Parity int - -const ( - // NoParity disable parity control (default) - NoParity Parity = iota - // OddParity enable odd-parity check - OddParity - // EvenParity enable even-parity check - EvenParity - // MarkParity enable mark-parity (always 1) check - MarkParity - // SpaceParity enable space-parity (always 0) check - SpaceParity -) - -// StopBits describe a serial port stop bits setting -type StopBits int - -const ( - // OneStopBit sets 1 stop bit (default) - OneStopBit StopBits = iota - // OnePointFiveStopBits sets 1.5 stop bits - OnePointFiveStopBits - // TwoStopBits sets 2 stop bits - TwoStopBits -) - -// PortError is a platform independent error type for serial ports -type PortError struct { - code PortErrorCode - causedBy error -} - -// PortErrorCode is a code to easily identify the type of error -type PortErrorCode int - -const ( - // PortBusy the serial port is already in used by another process - PortBusy PortErrorCode = iota - // PortNotFound the requested port doesn't exist - PortNotFound - // InvalidSerialPort the requested port is not a serial port - InvalidSerialPort - // PermissionDenied the user doesn't have enough priviledges - PermissionDenied - // InvalidSpeed the requested speed is not valid or not supported - InvalidSpeed - // InvalidDataBits the number of data bits is not valid or not supported - InvalidDataBits - // InvalidParity the selected parity is not valid or not supported - InvalidParity - // InvalidStopBits the selected number of stop bits is not valid or not supported - InvalidStopBits - // ErrorEnumeratingPorts an error occurred while listing serial port - ErrorEnumeratingPorts - // PortClosed the port has been closed while the operation is in progress - PortClosed - // FunctionNotImplemented the requested function is not implemented - FunctionNotImplemented -) - -// EncodedErrorString returns a string explaining the error code -func (e PortError) EncodedErrorString() string { - switch e.code { - case PortBusy: - return "Serial port busy" - case PortNotFound: - return "Serial port not found" - case InvalidSerialPort: - return "Invalid serial port" - case PermissionDenied: - return "Permission denied" - case InvalidSpeed: - return "Port speed invalid or not supported" - case InvalidDataBits: - return "Port data bits invalid or not supported" - case InvalidParity: - return "Port parity invalid or not supported" - case InvalidStopBits: - return "Port stop bits invalid or not supported" - case ErrorEnumeratingPorts: - return "Could not enumerate serial ports" - case PortClosed: - return "Port has been closed" - case FunctionNotImplemented: - return "Function not implemented" - default: - return "Other error" - } -} - -// Error returns the complete error code with details on the cause of the error -func (e PortError) Error() string { - if e.causedBy != nil { - return e.EncodedErrorString() + ": " + e.causedBy.Error() - } - return e.EncodedErrorString() -} - -// Code returns an identifier for the kind of error occurred -func (e PortError) Code() PortErrorCode { - return e.code -} diff --git a/vendor/github.com/facchinm/go-serial/serial_darwin.go b/vendor/github.com/facchinm/go-serial/serial_darwin.go deleted file mode 100644 index c2bd52bd..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_darwin.go +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -import "golang.org/x/sys/unix" - -const devFolder = "/dev" -const regexFilter = "^(cu|tty)\\..*" - -const ioctlTcgetattr = unix.TIOCGETA -const ioctlTcsetattr = unix.TIOCSETA -const ioctlTcflsh = unix.TIOCFLUSH diff --git a/vendor/github.com/facchinm/go-serial/serial_darwin_386.go b/vendor/github.com/facchinm/go-serial/serial_darwin_386.go deleted file mode 100644 index 1fde01c3..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_darwin_386.go +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -import "golang.org/x/sys/unix" - -// termios manipulation functions - -var baudrateMap = map[int]uint32{ - 0: unix.B9600, // Default to 9600 - 50: unix.B50, - 75: unix.B75, - 110: unix.B110, - 134: unix.B134, - 150: unix.B150, - 200: unix.B200, - 300: unix.B300, - 600: unix.B600, - 1200: unix.B1200, - 1800: unix.B1800, - 2400: unix.B2400, - 4800: unix.B4800, - 9600: unix.B9600, - 19200: unix.B19200, - 38400: unix.B38400, - 57600: unix.B57600, - 115200: unix.B115200, - 230400: unix.B230400, -} - -var databitsMap = map[int]uint32{ - 0: unix.CS8, // Default to 8 bits - 5: unix.CS5, - 6: unix.CS6, - 7: unix.CS7, - 8: unix.CS8, -} - -const tcCMSPAR uint32 = 0 // may be CMSPAR or PAREXT -const tcIUCLC uint32 = 0 - -const tcCCTS_OFLOW uint32 = 0x00010000 -const tcCRTS_IFLOW uint32 = 0x00020000 - -const tcCRTSCTS uint32 = (tcCCTS_OFLOW | tcCRTS_IFLOW) - -func toTermiosSpeedType(speed uint32) uint32 { - return speed -} diff --git a/vendor/github.com/facchinm/go-serial/serial_darwin_amd64.go b/vendor/github.com/facchinm/go-serial/serial_darwin_amd64.go deleted file mode 100644 index c0aa4761..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_darwin_amd64.go +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -import "golang.org/x/sys/unix" - -// termios manipulation functions - -var baudrateMap = map[int]uint64{ - 0: unix.B9600, // Default to 9600 - 50: unix.B50, - 75: unix.B75, - 110: unix.B110, - 134: unix.B134, - 150: unix.B150, - 200: unix.B200, - 300: unix.B300, - 600: unix.B600, - 1200: unix.B1200, - 1800: unix.B1800, - 2400: unix.B2400, - 4800: unix.B4800, - 9600: unix.B9600, - 19200: unix.B19200, - 38400: unix.B38400, - 57600: unix.B57600, - 115200: unix.B115200, - 230400: unix.B230400, -} - -var databitsMap = map[int]uint64{ - 0: unix.CS8, // Default to 8 bits - 5: unix.CS5, - 6: unix.CS6, - 7: unix.CS7, - 8: unix.CS8, -} - -const tcCMSPAR uint64 = 0 // may be CMSPAR or PAREXT -const tcIUCLC uint64 = 0 - -const tcCCTS_OFLOW uint64 = 0x00010000 -const tcCRTS_IFLOW uint64 = 0x00020000 - -const tcCRTSCTS uint64 = (tcCCTS_OFLOW | tcCRTS_IFLOW) - -func toTermiosSpeedType(speed uint64) uint64 { - return speed -} diff --git a/vendor/github.com/facchinm/go-serial/serial_freebsd.go b/vendor/github.com/facchinm/go-serial/serial_freebsd.go deleted file mode 100644 index d1e46e0a..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_freebsd.go +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -import "golang.org/x/sys/unix" - -const devFolder = "/dev" -const regexFilter = "^(cu|tty)\\..*" - -// termios manipulation functions - -var baudrateMap = map[int]uint32{ - 0: unix.B9600, // Default to 9600 - 50: unix.B50, - 75: unix.B75, - 110: unix.B110, - 134: unix.B134, - 150: unix.B150, - 200: unix.B200, - 300: unix.B300, - 600: unix.B600, - 1200: unix.B1200, - 1800: unix.B1800, - 2400: unix.B2400, - 4800: unix.B4800, - 9600: unix.B9600, - 19200: unix.B19200, - 38400: unix.B38400, - 57600: unix.B57600, - 115200: unix.B115200, - 230400: unix.B230400, - 460800: unix.B460800, - 921600: unix.B921600, -} - -var databitsMap = map[int]uint32{ - 0: unix.CS8, // Default to 8 bits - 5: unix.CS5, - 6: unix.CS6, - 7: unix.CS7, - 8: unix.CS8, -} - -const tcCMSPAR uint32 = 0 // may be CMSPAR or PAREXT -const tcIUCLC uint32 = 0 - -const tcCCTS_OFLOW uint32 = 0x00010000 -const tcCRTS_IFLOW uint32 = 0x00020000 - -const tcCRTSCTS uint32 = tcCCTS_OFLOW - -const ioctlTcgetattr = unix.TIOCGETA -const ioctlTcsetattr = unix.TIOCSETA -const ioctlTcflsh = unix.TIOCFLUSH - -func toTermiosSpeedType(speed uint32) uint32 { - return speed -} diff --git a/vendor/github.com/facchinm/go-serial/serial_linux.go b/vendor/github.com/facchinm/go-serial/serial_linux.go deleted file mode 100644 index 973970d2..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_linux.go +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -import "golang.org/x/sys/unix" - -const devFolder = "/dev" -const regexFilter = "(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO)[0-9]{1,3}" - -// termios manipulation functions - -var baudrateMap = map[int]uint32{ - 0: unix.B9600, // Default to 9600 - 50: unix.B50, - 75: unix.B75, - 110: unix.B110, - 134: unix.B134, - 150: unix.B150, - 200: unix.B200, - 300: unix.B300, - 600: unix.B600, - 1200: unix.B1200, - 1800: unix.B1800, - 2400: unix.B2400, - 4800: unix.B4800, - 9600: unix.B9600, - 19200: unix.B19200, - 38400: unix.B38400, - 57600: unix.B57600, - 115200: unix.B115200, - 230400: unix.B230400, - 460800: unix.B460800, - 500000: unix.B500000, - 576000: unix.B576000, - 921600: unix.B921600, - 1000000: unix.B1000000, - 1152000: unix.B1152000, - 1500000: unix.B1500000, - 2000000: unix.B2000000, - 2500000: unix.B2500000, - 3000000: unix.B3000000, - 3500000: unix.B3500000, - 4000000: unix.B4000000, -} - -var databitsMap = map[int]uint32{ - 0: unix.CS8, // Default to 8 bits - 5: unix.CS5, - 6: unix.CS6, - 7: unix.CS7, - 8: unix.CS8, -} - -const tcCMSPAR = unix.CMSPAR -const tcIUCLC = unix.IUCLC - -const tcCRTSCTS uint32 = unix.CRTSCTS - -const ioctlTcgetattr = unix.TCGETS -const ioctlTcsetattr = unix.TCSETS -const ioctlTcflsh = unix.TCFLSH - -func toTermiosSpeedType(speed uint32) uint32 { - return speed -} diff --git a/vendor/github.com/facchinm/go-serial/serial_openbsd.go b/vendor/github.com/facchinm/go-serial/serial_openbsd.go deleted file mode 100644 index 5fe2bb8a..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_openbsd.go +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -import "golang.org/x/sys/unix" - -const devFolder = "/dev" -const regexFilter = "^(cu|tty)\\..*" - -// termios manipulation functions - -var baudrateMap = map[int]uint32{ - 0: unix.B9600, // Default to 9600 - 50: unix.B50, - 75: unix.B75, - 110: unix.B110, - 134: unix.B134, - 150: unix.B150, - 200: unix.B200, - 300: unix.B300, - 600: unix.B600, - 1200: unix.B1200, - 1800: unix.B1800, - 2400: unix.B2400, - 4800: unix.B4800, - 9600: unix.B9600, - 19200: unix.B19200, - 38400: unix.B38400, - 57600: unix.B57600, - 115200: unix.B115200, - 230400: unix.B230400, - //460800: unix.B460800, - //921600: unix.B921600, -} - -var databitsMap = map[int]uint32{ - 0: unix.CS8, // Default to 8 bits - 5: unix.CS5, - 6: unix.CS6, - 7: unix.CS7, - 8: unix.CS8, -} - -const tcCMSPAR uint32 = 0 // may be CMSPAR or PAREXT -const tcIUCLC uint32 = 0 - -const tcCCTS_OFLOW uint32 = 0x00010000 -const tcCRTS_IFLOW uint32 = 0x00020000 - -const tcCRTSCTS uint32 = tcCCTS_OFLOW - -const ioctlTcgetattr = unix.TIOCGETA -const ioctlTcsetattr = unix.TIOCSETA -const ioctlTcflsh = unix.TIOCFLUSH - -func toTermiosSpeedType(speed uint32) int32 { - return int32(speed) -} diff --git a/vendor/github.com/facchinm/go-serial/serial_unix.go b/vendor/github.com/facchinm/go-serial/serial_unix.go deleted file mode 100644 index 61624e39..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_unix.go +++ /dev/null @@ -1,405 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// +build linux darwin freebsd openbsd - -package serial - -import ( - "io/ioutil" - "regexp" - "strings" - "sync" - "time" - "unsafe" - - "golang.org/x/sys/unix" - - "go.bug.st/serial.v1/unixutils" -) - -type unixPort struct { - handle int - - closeLock sync.RWMutex - closeSignal *unixutils.Pipe - opened bool -} - -func (port *unixPort) Close() error { - // Close port - port.releaseExclusiveAccess() - if err := unix.Close(port.handle); err != nil { - return err - } - port.opened = false - - if port.closeSignal != nil { - // Send close signal to all pending reads (if any) - port.closeSignal.Write([]byte{0}) - - // Wait for all readers to complete - port.closeLock.Lock() - defer port.closeLock.Unlock() - - // Close signaling pipe - if err := port.closeSignal.Close(); err != nil { - return err - } - } - return nil -} - -func (port *unixPort) Read(p []byte) (n int, err error) { - port.closeLock.RLock() - defer port.closeLock.RUnlock() - if !port.opened { - return 0, &PortError{code: PortClosed} - } - - fds := unixutils.NewFDSet(port.handle, port.closeSignal.ReadFD()) - res, err := unixutils.Select(fds, nil, fds, 1000 * time.Millisecond) - if err != nil { - return 0, err - } - if res.IsReadable(port.closeSignal.ReadFD()) { - return 0, &PortError{code: PortClosed} - } - return unix.Read(port.handle, p) -} - -func (port *unixPort) Write(p []byte) (n int, err error) { - return unix.Write(port.handle, p) -} - -func (port *unixPort) ResetInputBuffer() error { - return ioctl(port.handle, ioctlTcflsh, unix.TCIFLUSH) -} - -func (port *unixPort) ResetOutputBuffer() error { - return ioctl(port.handle, ioctlTcflsh, unix.TCOFLUSH) -} - -func (port *unixPort) SetMode(mode *Mode) error { - settings, err := port.getTermSettings() - if err != nil { - return err - } - if err := setTermSettingsBaudrate(mode.BaudRate, settings); err != nil { - return err - } - if err := setTermSettingsParity(mode.Parity, settings); err != nil { - return err - } - if err := setTermSettingsDataBits(mode.DataBits, settings); err != nil { - return err - } - if err := setTermSettingsStopBits(mode.StopBits, settings); err != nil { - return err - } - return port.setTermSettings(settings) -} - -func (port *unixPort) SetDTR(dtr bool) error { - status, err := port.getModemBitsStatus() - if err != nil { - return err - } - if dtr { - status |= unix.TIOCM_DTR - } else { - status &^= unix.TIOCM_DTR - } - return port.setModemBitsStatus(status) -} - -func (port *unixPort) SetRTS(rts bool) error { - status, err := port.getModemBitsStatus() - if err != nil { - return err - } - if rts { - status |= unix.TIOCM_RTS - } else { - status &^= unix.TIOCM_RTS - } - return port.setModemBitsStatus(status) -} - -func (port *unixPort) GetModemStatusBits() (*ModemStatusBits, error) { - status, err := port.getModemBitsStatus() - if err != nil { - return nil, err - } - return &ModemStatusBits{ - CTS: (status & unix.TIOCM_CTS) != 0, - DCD: (status & unix.TIOCM_CD) != 0, - DSR: (status & unix.TIOCM_DSR) != 0, - RI: (status & unix.TIOCM_RI) != 0, - }, nil -} - -func nativeOpen(portName string, mode *Mode) (*unixPort, error) { - h, err := unix.Open(portName, unix.O_RDWR|unix.O_NOCTTY|unix.O_NDELAY, 0) - if err != nil { - switch err { - case unix.EBUSY: - return nil, &PortError{code: PortBusy} - case unix.EACCES: - return nil, &PortError{code: PermissionDenied} - } - return nil, err - } - port := &unixPort{ - handle: h, - opened: true, - } - - // Setup serial port - if port.SetMode(mode) != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort} - } - - settings, err := port.getTermSettings() - if err != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort} - } - - // Set raw mode - setRawMode(settings, mode) - - // Explicitly disable RTS/CTS flow control - setTermSettingsCtsRts(false, settings) - - if port.setTermSettings(settings) != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort} - } - - unix.SetNonblock(h, false) - - port.acquireExclusiveAccess() - - // This pipe is used as a signal to cancel blocking Read - pipe := &unixutils.Pipe{} - if err := pipe.Open(); err != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort, causedBy: err} - } - port.closeSignal = pipe - - return port, nil -} - -func nativeGetPortsList() ([]string, error) { - files, err := ioutil.ReadDir(devFolder) - if err != nil { - return nil, err - } - - ports := make([]string, 0, len(files)) - for _, f := range files { - // Skip folders - if f.IsDir() { - continue - } - - // Keep only devices with the correct name - match, err := regexp.MatchString(regexFilter, f.Name()) - if err != nil { - return nil, err - } - if !match { - continue - } - - portName := devFolder + "/" + f.Name() - - // Check if serial port is real or is a placeholder serial port "ttySxx" - if strings.HasPrefix(f.Name(), "ttyS") { - port, err := nativeOpen(portName, &Mode{}) - if err != nil { - serr, ok := err.(*PortError) - if ok && serr.Code() == InvalidSerialPort { - continue - } - } else { - port.Close() - } - } - - // Save serial port in the resulting list - ports = append(ports, portName) - } - - return ports, nil -} - -// termios manipulation functions - -func setTermSettingsBaudrate(speed int, settings *unix.Termios) error { - baudrate, ok := baudrateMap[speed] - if !ok { - return &PortError{code: InvalidSpeed} - } - // revert old baudrate - for _, rate := range baudrateMap { - settings.Cflag &^= rate - } - // set new baudrate - settings.Cflag |= baudrate - settings.Ispeed = toTermiosSpeedType(baudrate) - settings.Ospeed = toTermiosSpeedType(baudrate) - return nil -} - -func setTermSettingsParity(parity Parity, settings *unix.Termios) error { - switch parity { - case NoParity: - settings.Cflag &^= unix.PARENB - settings.Cflag &^= unix.PARODD - settings.Cflag &^= tcCMSPAR - settings.Iflag &^= unix.INPCK - case OddParity: - settings.Cflag |= unix.PARENB - settings.Cflag |= unix.PARODD - settings.Cflag &^= tcCMSPAR - settings.Iflag |= unix.INPCK - case EvenParity: - settings.Cflag |= unix.PARENB - settings.Cflag &^= unix.PARODD - settings.Cflag &^= tcCMSPAR - settings.Iflag |= unix.INPCK - case MarkParity: - if tcCMSPAR == 0 { - return &PortError{code: InvalidParity} - } - settings.Cflag |= unix.PARENB - settings.Cflag |= unix.PARODD - settings.Cflag |= tcCMSPAR - settings.Iflag |= unix.INPCK - case SpaceParity: - if tcCMSPAR == 0 { - return &PortError{code: InvalidParity} - } - settings.Cflag |= unix.PARENB - settings.Cflag &^= unix.PARODD - settings.Cflag |= tcCMSPAR - settings.Iflag |= unix.INPCK - default: - return &PortError{code: InvalidParity} - } - return nil -} - -func setTermSettingsDataBits(bits int, settings *unix.Termios) error { - databits, ok := databitsMap[bits] - if !ok { - return &PortError{code: InvalidDataBits} - } - // Remove previous databits setting - settings.Cflag &^= unix.CSIZE - // Set requested databits - settings.Cflag |= databits - return nil -} - -func setTermSettingsStopBits(bits StopBits, settings *unix.Termios) error { - switch bits { - case OneStopBit: - settings.Cflag &^= unix.CSTOPB - case OnePointFiveStopBits: - return &PortError{code: InvalidStopBits} - case TwoStopBits: - settings.Cflag |= unix.CSTOPB - default: - return &PortError{code: InvalidStopBits} - } - return nil -} - -func setTermSettingsCtsRts(enable bool, settings *unix.Termios) { - if enable { - settings.Cflag |= tcCRTSCTS - } else { - settings.Cflag &^= tcCRTSCTS - } -} - -func setRawMode(settings *unix.Termios, mode *Mode) { - // Set local mode - settings.Cflag |= unix.CREAD - settings.Cflag |= unix.CLOCAL - - // Set raw mode - settings.Lflag &^= unix.ICANON - settings.Lflag &^= unix.ECHO - settings.Lflag &^= unix.ECHOE - settings.Lflag &^= unix.ECHOK - settings.Lflag &^= unix.ECHONL - settings.Lflag &^= unix.ECHOCTL - settings.Lflag &^= unix.ECHOPRT - settings.Lflag &^= unix.ECHOKE - settings.Lflag &^= unix.ISIG - settings.Lflag &^= unix.IEXTEN - - settings.Iflag &^= unix.IXON - settings.Iflag &^= unix.IXOFF - settings.Iflag &^= unix.IXANY - settings.Iflag &^= unix.INPCK - settings.Iflag &^= unix.IGNPAR - settings.Iflag &^= unix.PARMRK - settings.Iflag &^= unix.ISTRIP - settings.Iflag &^= unix.IGNBRK - settings.Iflag &^= unix.BRKINT - settings.Iflag &^= unix.INLCR - settings.Iflag &^= unix.IGNCR - settings.Iflag &^= unix.ICRNL - settings.Iflag &^= tcIUCLC - - settings.Oflag &^= unix.OPOST - - if mode.Vmin == 0 && mode.Vtimeout == 0 { - // Switch to default mode - // Block reads until at least one char is available (no timeout) - mode.Vmin = 1 - } - - settings.Cc[unix.VMIN] = mode.Vmin - settings.Cc[unix.VTIME] = mode.Vtimeout -} - -// native syscall wrapper functions - -func (port *unixPort) getTermSettings() (*unix.Termios, error) { - settings := &unix.Termios{} - err := ioctl(port.handle, ioctlTcgetattr, uintptr(unsafe.Pointer(settings))) - return settings, err -} - -func (port *unixPort) setTermSettings(settings *unix.Termios) error { - return ioctl(port.handle, ioctlTcsetattr, uintptr(unsafe.Pointer(settings))) -} - -func (port *unixPort) getModemBitsStatus() (int, error) { - var status int - err := ioctl(port.handle, unix.TIOCMGET, uintptr(unsafe.Pointer(&status))) - return status, err -} - -func (port *unixPort) setModemBitsStatus(status int) error { - return ioctl(port.handle, unix.TIOCMSET, uintptr(unsafe.Pointer(&status))) -} - -func (port *unixPort) acquireExclusiveAccess() error { - return ioctl(port.handle, unix.TIOCEXCL, 0) -} - -func (port *unixPort) releaseExclusiveAccess() error { - return ioctl(port.handle, unix.TIOCNXCL, 0) -} diff --git a/vendor/github.com/facchinm/go-serial/serial_windows.go b/vendor/github.com/facchinm/go-serial/serial_windows.go deleted file mode 100644 index 10b9f8f0..00000000 --- a/vendor/github.com/facchinm/go-serial/serial_windows.go +++ /dev/null @@ -1,444 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -/* - -// MSDN article on Serial Communications: -// http://msdn.microsoft.com/en-us/library/ff802693.aspx -// (alternative link) https://msdn.microsoft.com/en-us/library/ms810467.aspx - -// Arduino Playground article on serial communication with Windows API: -// http://playground.arduino.cc/Interfacing/CPPWindows - -*/ - -import "syscall" - -type windowsPort struct { - handle syscall.Handle -} - -func nativeGetPortsList() ([]string, error) { - subKey, err := syscall.UTF16PtrFromString("HARDWARE\\DEVICEMAP\\SERIALCOMM\\") - if err != nil { - return nil, &PortError{code: ErrorEnumeratingPorts} - } - - var h syscall.Handle - if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, subKey, 0, syscall.KEY_READ, &h) != nil { - return nil, &PortError{code: ErrorEnumeratingPorts} - } - defer syscall.RegCloseKey(h) - - var valuesCount uint32 - if syscall.RegQueryInfoKey(h, nil, nil, nil, nil, nil, nil, &valuesCount, nil, nil, nil, nil) != nil { - return nil, &PortError{code: ErrorEnumeratingPorts} - } - - list := make([]string, valuesCount) - for i := range list { - var data [1024]uint16 - dataSize := uint32(len(data)) - var name [1024]uint16 - nameSize := uint32(len(name)) - if regEnumValue(h, uint32(i), &name[0], &nameSize, nil, nil, &data[0], &dataSize) != nil { - return nil, &PortError{code: ErrorEnumeratingPorts} - } - list[i] = syscall.UTF16ToString(data[:]) - } - return list, nil -} - -func (port *windowsPort) Close() error { - return syscall.CloseHandle(port.handle) -} - -func (port *windowsPort) Read(p []byte) (int, error) { - var readed uint32 - params := &dcb{} - ev, err := createOverlappedEvent() - if err != nil { - return 0, err - } - defer syscall.CloseHandle(ev.HEvent) - for { - err := syscall.ReadFile(port.handle, p, &readed, ev) - switch err { - case nil: - // operation completed successfully - case syscall.ERROR_IO_PENDING: - // wait for overlapped I/O to complete - if err := getOverlappedResult(port.handle, ev, &readed, true); err != nil { - return int(readed), err - } - default: - // error happened - return int(readed), err - } - - if readed > 0 { - return int(readed), nil - } - if err := resetEvent(ev.HEvent); err != nil { - return 0, err - } - - // At the moment it seems that the only reliable way to check if - // a serial port is alive in Windows is to check if the SetCommState - // function fails. - - getCommState(port.handle, params) - if err := setCommState(port.handle, params); err != nil { - port.Close() - return 0, err - } - } -} - -func (port *windowsPort) Write(p []byte) (int, error) { - var writed uint32 - ev, err := createOverlappedEvent() - if err != nil { - return 0, err - } - defer syscall.CloseHandle(ev.HEvent) - err = syscall.WriteFile(port.handle, p, &writed, ev) - if err == syscall.ERROR_IO_PENDING { - // wait for write to complete - err = getOverlappedResult(port.handle, ev, &writed, true) - } - return int(writed), err -} - -const ( - purgeRxAbort uint32 = 0x0002 - purgeRxClear = 0x0008 - purgeTxAbort = 0x0001 - purgeTxClear = 0x0004 -) - -func (port *windowsPort) ResetInputBuffer() error { - return purgeComm(port.handle, purgeRxClear|purgeRxAbort) -} - -func (port *windowsPort) ResetOutputBuffer() error { - return purgeComm(port.handle, purgeTxClear|purgeTxAbort) -} - -const ( - dcbBinary uint32 = 0x00000001 - dcbParity = 0x00000002 - dcbOutXCTSFlow = 0x00000004 - dcbOutXDSRFlow = 0x00000008 - dcbDTRControlDisableMask = ^uint32(0x00000030) - dcbDTRControlEnable = 0x00000010 - dcbDTRControlHandshake = 0x00000020 - dcbDSRSensitivity = 0x00000040 - dcbTXContinueOnXOFF = 0x00000080 - dcbOutX = 0x00000100 - dcbInX = 0x00000200 - dcbErrorChar = 0x00000400 - dcbNull = 0x00000800 - dcbRTSControlDisbaleMask = ^uint32(0x00003000) - dcbRTSControlEnable = 0x00001000 - dcbRTSControlHandshake = 0x00002000 - dcbRTSControlToggle = 0x00003000 - dcbAbortOnError = 0x00004000 -) - -type dcb struct { - DCBlength uint32 - BaudRate uint32 - - // Flags field is a bitfield - // fBinary :1 - // fParity :1 - // fOutxCtsFlow :1 - // fOutxDsrFlow :1 - // fDtrControl :2 - // fDsrSensitivity :1 - // fTXContinueOnXoff :1 - // fOutX :1 - // fInX :1 - // fErrorChar :1 - // fNull :1 - // fRtsControl :2 - // fAbortOnError :1 - // fDummy2 :17 - Flags uint32 - - wReserved uint16 - XonLim uint16 - XoffLim uint16 - ByteSize byte - Parity byte - StopBits byte - XonChar byte - XoffChar byte - ErrorChar byte - EOFChar byte - EvtChar byte - wReserved1 uint16 -} - -type commTimeouts struct { - ReadIntervalTimeout uint32 - ReadTotalTimeoutMultiplier uint32 - ReadTotalTimeoutConstant uint32 - WriteTotalTimeoutMultiplier uint32 - WriteTotalTimeoutConstant uint32 -} - -const ( - noParity = 0 - oddParity = 1 - evenParity = 2 - markParity = 3 - spaceParity = 4 -) - -var parityMap = map[Parity]byte{ - NoParity: noParity, - OddParity: oddParity, - EvenParity: evenParity, - MarkParity: markParity, - SpaceParity: spaceParity, -} - -const ( - oneStopBit = 0 - one5StopBits = 1 - twoStopBits = 2 -) - -var stopBitsMap = map[StopBits]byte{ - OneStopBit: oneStopBit, - OnePointFiveStopBits: one5StopBits, - TwoStopBits: twoStopBits, -} - -const ( - commFunctionSetXOFF = 1 - commFunctionSetXON = 2 - commFunctionSetRTS = 3 - commFunctionClrRTS = 4 - commFunctionSetDTR = 5 - commFunctionClrDTR = 6 - commFunctionSetBreak = 8 - commFunctionClrBreak = 9 -) - -const ( - msCTSOn = 0x0010 - msDSROn = 0x0020 - msRingOn = 0x0040 - msRLSDOn = 0x0080 -) - -func (port *windowsPort) SetMode(mode *Mode) error { - params := dcb{} - if getCommState(port.handle, ¶ms) != nil { - port.Close() - return &PortError{code: InvalidSerialPort} - } - if mode.BaudRate == 0 { - params.BaudRate = 9600 // Default to 9600 - } else { - params.BaudRate = uint32(mode.BaudRate) - } - if mode.DataBits == 0 { - params.ByteSize = 8 // Default to 8 bits - } else { - params.ByteSize = byte(mode.DataBits) - } - params.StopBits = stopBitsMap[mode.StopBits] - params.Parity = parityMap[mode.Parity] - if setCommState(port.handle, ¶ms) != nil { - port.Close() - return &PortError{code: InvalidSerialPort} - } - return nil -} - -func (port *windowsPort) SetDTR(dtr bool) error { - // Like for RTS there are problems with the escapeCommFunction - // observed behaviour was that DTR is set from false -> true - // when setting RTS from true -> false - // 1) Connect -> RTS = true (low) DTR = true (low) OKAY - // 2) SetDTR(false) -> RTS = true (low) DTR = false (heigh) OKAY - // 3) SetRTS(false) -> RTS = false (heigh) DTR = true (low) ERROR: DTR toggled - // - // In addition this way the CommState Flags are not updated - /* - var res bool - if dtr { - res = escapeCommFunction(port.handle, commFunctionSetDTR) - } else { - res = escapeCommFunction(port.handle, commFunctionClrDTR) - } - if !res { - return &PortError{} - } - return nil - */ - - // The following seems a more reliable way to do it - - params := &dcb{} - if err := getCommState(port.handle, params); err != nil { - return &PortError{causedBy: err} - } - params.Flags &= dcbDTRControlDisableMask - if dtr { - params.Flags |= dcbDTRControlEnable - } - if err := setCommState(port.handle, params); err != nil { - return &PortError{causedBy: err} - } - - return nil -} - -func (port *windowsPort) SetRTS(rts bool) error { - // It seems that there is a bug in the Windows VCP driver: - // it doesn't send USB control message when the RTS bit is - // changed, so the following code not always works with - // USB-to-serial adapters. - // - // In addition this way the CommState Flags are not updated - - /* - var res bool - if rts { - res = escapeCommFunction(port.handle, commFunctionSetRTS) - } else { - res = escapeCommFunction(port.handle, commFunctionClrRTS) - } - if !res { - return &PortError{} - } - return nil - */ - - // The following seems a more reliable way to do it - - params := &dcb{} - if err := getCommState(port.handle, params); err != nil { - return &PortError{causedBy: err} - } - params.Flags &= dcbRTSControlDisbaleMask - if rts { - params.Flags |= dcbRTSControlEnable - } - if err := setCommState(port.handle, params); err != nil { - return &PortError{causedBy: err} - } - return nil -} - -func (port *windowsPort) GetModemStatusBits() (*ModemStatusBits, error) { - var bits uint32 - if !getCommModemStatus(port.handle, &bits) { - return nil, &PortError{} - } - return &ModemStatusBits{ - CTS: (bits & msCTSOn) != 0, - DCD: (bits & msRLSDOn) != 0, - DSR: (bits & msDSROn) != 0, - RI: (bits & msRingOn) != 0, - }, nil -} - -func createOverlappedEvent() (*syscall.Overlapped, error) { - h, err := createEvent(nil, true, false, nil) - return &syscall.Overlapped{HEvent: h}, err -} - -func nativeOpen(portName string, mode *Mode) (*windowsPort, error) { - portName = "\\\\.\\" + portName - path, err := syscall.UTF16PtrFromString(portName) - if err != nil { - return nil, err - } - handle, err := syscall.CreateFile( - path, - syscall.GENERIC_READ|syscall.GENERIC_WRITE, - 0, nil, - syscall.OPEN_EXISTING, - syscall.FILE_FLAG_OVERLAPPED, - 0) - if err != nil { - switch err { - case syscall.ERROR_ACCESS_DENIED: - return nil, &PortError{code: PortBusy} - case syscall.ERROR_FILE_NOT_FOUND: - return nil, &PortError{code: PortNotFound} - } - return nil, err - } - // Create the serial port - port := &windowsPort{ - handle: handle, - } - - // Set port parameters - if port.SetMode(mode) != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort} - } - - params := &dcb{} - if getCommState(port.handle, params) != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort} - } - params.Flags &= dcbRTSControlDisbaleMask - params.Flags |= dcbRTSControlEnable - params.Flags &= dcbDTRControlDisableMask - params.Flags |= dcbDTRControlEnable - params.Flags &^= dcbOutXCTSFlow - params.Flags &^= dcbOutXDSRFlow - params.Flags &^= dcbDSRSensitivity - params.Flags |= dcbTXContinueOnXOFF - params.Flags &^= dcbInX - params.Flags &^= dcbOutX - params.Flags &^= dcbErrorChar - params.Flags &^= dcbNull - params.Flags &^= dcbAbortOnError - params.XonLim = 2048 - params.XoffLim = 512 - params.XonChar = 17 // DC1 - params.XoffChar = 19 // C3 - if setCommState(port.handle, params) != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort} - } - - // Set timeouts to 1 second - timeouts := &commTimeouts{ - ReadIntervalTimeout: 0xFFFFFFFF, - ReadTotalTimeoutMultiplier: 0xFFFFFFFF, - ReadTotalTimeoutConstant: 1000, // 1 sec - WriteTotalTimeoutConstant: 0, - WriteTotalTimeoutMultiplier: 0, - } - - if (mode.Vtimeout > 0) { - timeouts.ReadIntervalTimeout = 0 - timeouts.ReadTotalTimeoutMultiplier = 0 - // tenth of seconds to milliseconds - timeouts.ReadTotalTimeoutConstant = uint32(mode.Vtimeout * 100) - } - - if setCommTimeouts(port.handle, timeouts) != nil { - port.Close() - return nil, &PortError{code: InvalidSerialPort} - } - - return port, nil -} diff --git a/vendor/github.com/facchinm/go-serial/syscall_darwin.go b/vendor/github.com/facchinm/go-serial/syscall_darwin.go deleted file mode 100644 index 2e1250a7..00000000 --- a/vendor/github.com/facchinm/go-serial/syscall_darwin.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/vendor/github.com/facchinm/go-serial/syscall_freebsd.go b/vendor/github.com/facchinm/go-serial/syscall_freebsd.go deleted file mode 100644 index 2e1250a7..00000000 --- a/vendor/github.com/facchinm/go-serial/syscall_freebsd.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/vendor/github.com/facchinm/go-serial/syscall_linux.go b/vendor/github.com/facchinm/go-serial/syscall_linux.go deleted file mode 100644 index 2e1250a7..00000000 --- a/vendor/github.com/facchinm/go-serial/syscall_linux.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/vendor/github.com/facchinm/go-serial/syscall_openbsd.go b/vendor/github.com/facchinm/go-serial/syscall_openbsd.go deleted file mode 100644 index 2e1250a7..00000000 --- a/vendor/github.com/facchinm/go-serial/syscall_openbsd.go +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/vendor/github.com/facchinm/go-serial/syscall_windows.go b/vendor/github.com/facchinm/go-serial/syscall_windows.go deleted file mode 100644 index e7d69f0a..00000000 --- a/vendor/github.com/facchinm/go-serial/syscall_windows.go +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -package serial - -//sys regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, value *uint16, valueLen *uint32) (regerrno error) = advapi32.RegEnumValueW - -//sys getCommState(handle syscall.Handle, dcb *dcb) (err error) = GetCommState - -//sys setCommState(handle syscall.Handle, dcb *dcb) (err error) = SetCommState - -//sys setCommTimeouts(handle syscall.Handle, timeouts *commTimeouts) (err error) = SetCommTimeouts - -//sys escapeCommFunction(handle syscall.Handle, function uint32) (res bool) = EscapeCommFunction - -//sys getCommModemStatus(handle syscall.Handle, bits *uint32) (res bool) = GetCommModemStatus - -//sys createEvent(eventAttributes *uint32, manualReset bool, initialState bool, name *uint16) (handle syscall.Handle, err error) = CreateEventW - -//sys resetEvent(handle syscall.Handle) (err error) = ResetEvent - -//sys getOverlappedResult(handle syscall.Handle, overlapEvent *syscall.Overlapped, n *uint32, wait bool) (err error) = GetOverlappedResult - -//sys purgeComm(handle syscall.Handle, flags uint32) (err error) = PurgeComm - diff --git a/vendor/github.com/facchinm/go-serial/unixutils/pipe.go b/vendor/github.com/facchinm/go-serial/unixutils/pipe.go deleted file mode 100644 index 93f34864..00000000 --- a/vendor/github.com/facchinm/go-serial/unixutils/pipe.go +++ /dev/null @@ -1,80 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// +build linux darwin freebsd openbsd - -package unixutils // import "go.bug.st/serial.v1/unixutils" - -import "syscall" -import "fmt" - -// Pipe represents a unix-pipe -type Pipe struct { - opened bool - rd int - wr int -} - -// Open creates a new pipe -func (p *Pipe) Open() error { - fds := []int{0, 0} - if err := syscall.Pipe(fds); err != nil { - return err - } - p.rd = fds[0] - p.wr = fds[1] - p.opened = true - return nil -} - -// ReadFD returns the file handle for the read side of the pipe. -func (p *Pipe) ReadFD() int { - if !p.opened { - return -1 - } - return p.rd -} - -// WriteFD returns the flie handle for the write side of the pipe. -func (p *Pipe) WriteFD() int { - if !p.opened { - return -1 - } - return p.wr -} - -// Write to the pipe the content of data. Returns the numbre of bytes written. -func (p *Pipe) Write(data []byte) (int, error) { - if !p.opened { - return 0, fmt.Errorf("Pipe not opened") - } - return syscall.Write(p.wr, data) -} - -// Read from the pipe into the data array. Returns the number of bytes read. -func (p *Pipe) Read(data []byte) (int, error) { - if !p.opened { - return 0, fmt.Errorf("Pipe not opened") - } - return syscall.Read(p.rd, data) -} - -// Close the pipe -func (p *Pipe) Close() error { - if !p.opened { - return fmt.Errorf("Pipe not opened") - } - err1 := syscall.Close(p.rd) - err2 := syscall.Close(p.wr) - p.opened = false - if err1 != nil { - return err1 - } - if err2 != nil { - return err2 - } - return nil -} diff --git a/vendor/github.com/facchinm/go-serial/unixutils/select.go b/vendor/github.com/facchinm/go-serial/unixutils/select.go deleted file mode 100644 index 0bd1d9af..00000000 --- a/vendor/github.com/facchinm/go-serial/unixutils/select.go +++ /dev/null @@ -1,101 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// +build linux darwin freebsd openbsd - -package unixutils // "go.bug.st/serial.v1/unixutils" - -import ( - "time" - - "github.com/creack/goselect" -) - -// FDSet is a set of file descriptors suitable for a select call -type FDSet struct { - set goselect.FDSet - max uintptr -} - -// NewFDSet creates a set of file descriptors suitable for a Select call. -func NewFDSet(fds ...int) *FDSet { - s := &FDSet{} - s.Add(fds...) - return s -} - -// Add adds the file descriptors passed as parameter to the FDSet. -func (s *FDSet) Add(fds ...int) { - for _, fd := range fds { - f := uintptr(fd) - s.set.Set(f) - if f > s.max { - s.max = f - } - } -} - -// FDResultSets contains the result of a Select operation. -type FDResultSets struct { - readable *goselect.FDSet - writeable *goselect.FDSet - errors *goselect.FDSet -} - -// IsReadable test if a file descriptor is ready to be read. -func (r *FDResultSets) IsReadable(fd int) bool { - return r.readable.IsSet(uintptr(fd)) -} - -// IsWritable test if a file descriptor is ready to be written. -func (r *FDResultSets) IsWritable(fd int) bool { - return r.writeable.IsSet(uintptr(fd)) -} - -// IsError test if a file descriptor is in error state. -func (r *FDResultSets) IsError(fd int) bool { - return r.errors.IsSet(uintptr(fd)) -} - -// Select performs a select system call, -// file descriptors in the rd set are tested for read-events, -// file descriptors in the wd set are tested for write-events and -// file descriptors in the er set are tested for error-events. -// The function will block until an event happens or the timeout expires. -// The function return an FDResultSets that contains all the file descriptor -// that have a pending read/write/error event. -func Select(rd, wr, er *FDSet, timeout time.Duration) (*FDResultSets, error) { - max := uintptr(0) - res := &FDResultSets{} - if rd != nil { - // fdsets are copied so the parameters are left untouched - copyOfRd := rd.set - res.readable = ©OfRd - // Determine max fd. - max = rd.max - } - if wr != nil { - // fdsets are copied so the parameters are left untouched - copyOfWr := wr.set - res.writeable = ©OfWr - // Determine max fd. - if wr.max > max { - max = wr.max - } - } - if er != nil { - // fdsets are copied so the parameters are left untouched - copyOfEr := er.set - res.errors = ©OfEr - // Determine max fd. - if er.max > max { - max = er.max - } - } - - err := goselect.Select(int(max+1), res.readable, res.writeable, res.errors, timeout) - return res, err -} diff --git a/vendor/github.com/facchinm/go-serial/zsyscall_darwin.go b/vendor/github.com/facchinm/go-serial/zsyscall_darwin.go deleted file mode 100644 index 21bab269..00000000 --- a/vendor/github.com/facchinm/go-serial/zsyscall_darwin.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_darwin.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "golang.org/x/sys/unix" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/vendor/github.com/facchinm/go-serial/zsyscall_freebsd.go b/vendor/github.com/facchinm/go-serial/zsyscall_freebsd.go deleted file mode 100644 index 3255a7dd..00000000 --- a/vendor/github.com/facchinm/go-serial/zsyscall_freebsd.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_freebsd.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "golang.org/x/sys/unix" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/vendor/github.com/facchinm/go-serial/zsyscall_linux.go b/vendor/github.com/facchinm/go-serial/zsyscall_linux.go deleted file mode 100644 index b09cb66c..00000000 --- a/vendor/github.com/facchinm/go-serial/zsyscall_linux.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_linux.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "golang.org/x/sys/unix" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/vendor/github.com/facchinm/go-serial/zsyscall_openbsd.go b/vendor/github.com/facchinm/go-serial/zsyscall_openbsd.go deleted file mode 100644 index 3a21be6e..00000000 --- a/vendor/github.com/facchinm/go-serial/zsyscall_openbsd.go +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2014-2017 Cristian Maglie. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// - -// This file is machine generated by the command: -// mksyscall.pl serial_openbsd.go -// The generated stub is modified to make it compile under the "serial" package - -package serial - -import "syscall" - -func ioctl(fd int, req uint64, data uintptr) (err error) { - _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) - if e1 != 0 { - err = e1 - } - return -} diff --git a/vendor/github.com/facchinm/go-serial/zsyscall_windows.go b/vendor/github.com/facchinm/go-serial/zsyscall_windows.go deleted file mode 100644 index f6005ea2..00000000 --- a/vendor/github.com/facchinm/go-serial/zsyscall_windows.go +++ /dev/null @@ -1,176 +0,0 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT - -package serial - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -var _ unsafe.Pointer - -// Do the interface allocations only once for common -// Errno values. -const ( - errnoERROR_IO_PENDING = 997 -) - -var ( - errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) -) - -// errnoErr returns common boxed Errno values, to prevent -// allocations at runtime. -func errnoErr(e syscall.Errno) error { - switch e { - case 0: - return nil - case errnoERROR_IO_PENDING: - return errERROR_IO_PENDING - } - // TODO: add more here, after collecting data on the common - // error values see on Windows. (perhaps when running - // all.bat?) - return e -} - -var ( - modadvapi32 = windows.NewLazySystemDLL("advapi32.dll") - modkernel32 = windows.NewLazySystemDLL("kernel32.dll") - - procRegEnumValueW = modadvapi32.NewProc("RegEnumValueW") - procGetCommState = modkernel32.NewProc("GetCommState") - procSetCommState = modkernel32.NewProc("SetCommState") - procSetCommTimeouts = modkernel32.NewProc("SetCommTimeouts") - procEscapeCommFunction = modkernel32.NewProc("EscapeCommFunction") - procGetCommModemStatus = modkernel32.NewProc("GetCommModemStatus") - procCreateEventW = modkernel32.NewProc("CreateEventW") - procResetEvent = modkernel32.NewProc("ResetEvent") - procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult") - procPurgeComm = modkernel32.NewProc("PurgeComm") -) - -func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, value *uint16, valueLen *uint32) (regerrno error) { - r0, _, _ := syscall.Syscall9(procRegEnumValueW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(value)), uintptr(unsafe.Pointer(valueLen)), 0) - if r0 != 0 { - regerrno = syscall.Errno(r0) - } - return -} - -func getCommState(handle syscall.Handle, dcb *dcb) (err error) { - r1, _, e1 := syscall.Syscall(procGetCommState.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(dcb)), 0) - if r1 == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setCommState(handle syscall.Handle, dcb *dcb) (err error) { - r1, _, e1 := syscall.Syscall(procSetCommState.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(dcb)), 0) - if r1 == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func setCommTimeouts(handle syscall.Handle, timeouts *commTimeouts) (err error) { - r1, _, e1 := syscall.Syscall(procSetCommTimeouts.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(timeouts)), 0) - if r1 == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func escapeCommFunction(handle syscall.Handle, function uint32) (res bool) { - r0, _, _ := syscall.Syscall(procEscapeCommFunction.Addr(), 2, uintptr(handle), uintptr(function), 0) - res = r0 != 0 - return -} - -func getCommModemStatus(handle syscall.Handle, bits *uint32) (res bool) { - r0, _, _ := syscall.Syscall(procGetCommModemStatus.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(bits)), 0) - res = r0 != 0 - return -} - -func createEvent(eventAttributes *uint32, manualReset bool, initialState bool, name *uint16) (handle syscall.Handle, err error) { - var _p0 uint32 - if manualReset { - _p0 = 1 - } else { - _p0 = 0 - } - var _p1 uint32 - if initialState { - _p1 = 1 - } else { - _p1 = 0 - } - r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttributes)), uintptr(_p0), uintptr(_p1), uintptr(unsafe.Pointer(name)), 0, 0) - handle = syscall.Handle(r0) - if handle == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func resetEvent(handle syscall.Handle) (err error) { - r1, _, e1 := syscall.Syscall(procResetEvent.Addr(), 1, uintptr(handle), 0, 0) - if r1 == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func getOverlappedResult(handle syscall.Handle, overlapEvent *syscall.Overlapped, n *uint32, wait bool) (err error) { - var _p0 uint32 - if wait { - _p0 = 1 - } else { - _p0 = 0 - } - r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapEvent)), uintptr(unsafe.Pointer(n)), uintptr(_p0), 0, 0) - if r1 == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -} - -func purgeComm(handle syscall.Handle, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procPurgeComm.Addr(), 2, uintptr(handle), uintptr(flags), 0) - if r1 == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -}