You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/05/24 21:46:14 UTC
[2/3] incubator-mynewt-newt git commit: MYNEWT-300 newtmgr cli - add
timeouts and retries to image upload messages.
MYNEWT-300 newtmgr cli - add timeouts and retries to image upload messages.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/264a3ddc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/264a3ddc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/264a3ddc
Branch: refs/heads/develop
Commit: 264a3ddc055a057391c435807c63b4a36172630f
Parents: 87076df
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 24 14:42:00 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue May 24 14:42:00 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/image.go | 42 +++++++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/264a3ddc/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 74a3764..c85ff4c 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -24,6 +24,7 @@ import (
"io"
"io/ioutil"
"os"
+ "time"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/core"
@@ -45,7 +46,7 @@ func imageListCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
- conn, err := transport.NewConn(profile)
+ conn, err := transport.NewConnWithTimeout(profile, time.Second * 3)
if err != nil {
nmUsage(nil, err)
}
@@ -154,7 +155,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
- conn, err := transport.NewConn(profile)
+ conn, err := transport.NewConnWithTimeout(profile, time.Second)
if err != nil {
nmUsage(nil, err)
}
@@ -169,6 +170,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
}
var currOff uint32 = 0
imageSz := uint32(len(imageFile))
+ rexmits := 0
for currOff < imageSz {
imageUpload, err := protocol.NewImageUpload()
@@ -180,7 +182,6 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
if blockSz > 36 {
blockSz = 36
}
-
imageUpload.Offset = currOff
imageUpload.Size = imageSz
imageUpload.Data = imageFile[currOff : currOff+blockSz]
@@ -190,11 +191,35 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
- if err := runner.WriteReq(nmr); err != nil {
- nmUsage(cmd, err)
- }
+ var rsp *protocol.NmgrReq
+ var i int
+ for i = 0; i < 5; i++ {
+ if err := runner.WriteReq(nmr); err != nil {
+ nmUsage(cmd, err)
+ }
- rsp, err := runner.ReadResp()
+ rsp, err = runner.ReadResp()
+ if err == nil {
+ break;
+ }
+
+ /*
+ * Failed. Reopening tty.
+ */
+ conn, err = transport.NewConnWithTimeout(profile, time.Second)
+ if err != nil {
+ nmUsage(nil, err)
+ }
+
+ runner, err = protocol.NewCmdRunner(conn)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ }
+ rexmits += i
+ if i == 5 {
+ err = util.NewNewtError("Maximum number of TX retries reached")
+ }
if err != nil {
nmUsage(cmd, err)
}
@@ -210,6 +235,9 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ if rexmits != 0 {
+ fmt.Printf(" %d retransmits\n", rexmits)
+ }
fmt.Println("Done")
}