Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
14186ed4
Commit
14186ed4
authored
May 23, 2019
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reimplemented serial-discovery discovery
parent
65f1043b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
32 deletions
+43
-32
commands/board/list.go
commands/board/list.go
+0
-30
commands/bundled_tools_serial_discovery.go
commands/bundled_tools_serial_discovery.go
+15
-1
commands/instances.go
commands/instances.go
+28
-1
No files found.
commands/board/list.go
View file @
14186ed4
...
...
@@ -21,12 +21,8 @@ import (
"context"
"errors"
"fmt"
"os"
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/rpc"
)
...
...
@@ -36,32 +32,6 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp,
return
nil
,
errors
.
New
(
"invalid instance"
)
}
// Check for bultin serial-discovery tool
loadBuiltinSerialDiscoveryMetadata
(
pm
)
serialDiscoveryTool
,
_
:=
getBuiltinSerialDiscoveryTool
(
pm
)
if
!
serialDiscoveryTool
.
IsInstalled
()
{
formatter
.
Print
(
"Downloading and installing missing tool: "
+
serialDiscoveryTool
.
String
())
commands
.
DownloadToolRelease
(
pm
,
serialDiscoveryTool
,
cli
.
OutputProgressBar
())
commands
.
InstallToolRelease
(
pm
,
serialDiscoveryTool
,
cli
.
OutputTaskProgress
())
if
err
:=
pm
.
LoadHardware
(
cli
.
Config
);
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Could not load hardware packages."
)
os
.
Exit
(
cli
.
ErrCoreConfig
)
}
serialDiscoveryTool
,
_
=
getBuiltinSerialDiscoveryTool
(
pm
)
if
!
serialDiscoveryTool
.
IsInstalled
()
{
formatter
.
PrintErrorMessage
(
"Missing serial-discovery tool."
)
os
.
Exit
(
cli
.
ErrCoreConfig
)
}
}
// TODO: move to 'commands' modules
_
,
err
:=
discovery
.
NewFromCommandLine
(
serialDiscoveryTool
.
InstallDir
.
Join
(
"serial-discovery"
)
.
String
())
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Error setting up serial-discovery tool."
)
os
.
Exit
(
cli
.
ErrCoreConfig
)
}
resp
:=
&
rpc
.
BoardListResp
{
Ports
:
[]
*
rpc
.
DetectedPort
{}}
for
_
,
disc
:=
range
commands
.
GetDiscoveries
(
req
)
{
ports
,
err
:=
disc
.
List
()
...
...
commands/b
oard/serial-
discovery.go
→
commands/b
undled_tools_serial_
discovery.go
View file @
14186ed4
...
...
@@ -15,11 +15,14 @@
// a commercial license, send an email to license@arduino.cc.
//
package
board
package
commands
import
(
"fmt"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/arduino/resources"
semver
"go.bug.st/relaxed-semver"
)
...
...
@@ -87,3 +90,14 @@ func loadBuiltinSerialDiscoveryMetadata(pm *packagemanager.PackageManager) {
func
getBuiltinSerialDiscoveryTool
(
pm
*
packagemanager
.
PackageManager
)
(
*
cores
.
ToolRelease
,
error
)
{
return
pm
.
Package
(
"builtin"
)
.
Tool
(
"serial-discovery"
)
.
Release
(
serialDiscoveryVersion
)
.
Get
()
}
func
newBuiltinSerialDiscovery
(
pm
*
packagemanager
.
PackageManager
)
(
*
discovery
.
Discovery
,
error
)
{
t
,
err
:=
getBuiltinSerialDiscoveryTool
(
pm
)
if
err
!=
nil
{
return
nil
,
err
}
if
!
t
.
IsInstalled
()
{
return
nil
,
fmt
.
Errorf
(
"missing serial-discovery tool"
)
}
return
discovery
.
NewFromCommandLine
(
t
.
InstallDir
.
Join
(
"serial-discovery"
)
.
String
())
}
commands/instances.go
View file @
14186ed4
...
...
@@ -82,8 +82,35 @@ func GetDiscoveries(req InstanceContainer) []*discovery.Discovery {
}
func
(
instance
*
CoreInstance
)
startDiscoveries
(
downloadCB
DownloadProgressCB
,
taskCB
TaskProgressCB
)
error
{
// Check for bultin serial-discovery tool
loadBuiltinSerialDiscoveryMetadata
(
instance
.
pm
)
if
downloadCB
!=
nil
{
serialDiscoveryTool
,
_
:=
getBuiltinSerialDiscoveryTool
(
instance
.
pm
)
if
!
serialDiscoveryTool
.
IsInstalled
()
{
//formatter.Print("Downloading and installing missing tool: " + serialDiscoveryTool.String())
if
err
:=
DownloadToolRelease
(
instance
.
pm
,
serialDiscoveryTool
,
downloadCB
);
err
!=
nil
{
return
fmt
.
Errorf
((
"could not download serial-discovery tool"
))
}
if
err
:=
InstallToolRelease
(
instance
.
pm
,
serialDiscoveryTool
,
taskCB
);
err
!=
nil
{
return
fmt
.
Errorf
((
"could not install serial-discovery tool"
))
}
if
err
:=
instance
.
pm
.
LoadHardware
(
instance
.
config
);
err
!=
nil
{
return
fmt
.
Errorf
(
"could not load hardware packages: %s"
,
err
)
}
}
}
serialDiscovery
,
err
:=
newBuiltinSerialDiscovery
(
instance
.
pm
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"starting serial discovery: %s"
,
err
)
}
discoveriesToStop
:=
instance
.
discoveries
discoveriesToStart
:=
discovery
.
ExtractDiscoveriesFromPlatforms
(
instance
.
pm
)
discoveriesToStart
:=
append
(
discovery
.
ExtractDiscoveriesFromPlatforms
(
instance
.
pm
),
serialDiscovery
,
)
instance
.
discoveries
=
[]
*
discovery
.
Discovery
{}
for
_
,
disc
:=
range
discoveriesToStart
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment