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/20 01:04:27 UTC
[4/6] incubator-mynewt-newt git commit: image;
decode return code coming from target. Report errors for non-zero
codes.
image; decode return code coming from target. Report errors for
non-zero codes.
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/49439638
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/49439638
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/49439638
Branch: refs/heads/develop
Commit: 4943963844acb341e725f50bba5e2adf05e7a2c7
Parents: f2682e0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 29 17:50:58 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 18:00:15 2016 -0700
----------------------------------------------------------------------
newtmgr/protocol/imageboot.go | 5 +++++
newtmgr/protocol/imageboot2.go | 5 +++++
newtmgr/protocol/imagefiledownload.go | 11 ++++++++---
newtmgr/protocol/imagefileupload.go | 13 +++++++++----
newtmgr/protocol/imageupload.go | 11 ++++++++---
5 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/49439638/newtmgr/protocol/imageboot.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageboot.go b/newtmgr/protocol/imageboot.go
index 54fa619..b949928 100644
--- a/newtmgr/protocol/imageboot.go
+++ b/newtmgr/protocol/imageboot.go
@@ -31,6 +31,7 @@ type ImageBoot struct {
Test string
Main string
Active string
+ ReturnCode int `json:"rc"`
}
func NewImageBoot() (*ImageBoot, error) {
@@ -81,5 +82,9 @@ func DecodeImageBootResponse(data []byte) (*ImageBoot, error) {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
err.Error()))
}
+ if i.ReturnCode != 0 {
+ return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
+ i.ReturnCode))
+ }
return i, nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/49439638/newtmgr/protocol/imageboot2.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageboot2.go b/newtmgr/protocol/imageboot2.go
index c8d4cf8..47f63e7 100644
--- a/newtmgr/protocol/imageboot2.go
+++ b/newtmgr/protocol/imageboot2.go
@@ -31,6 +31,7 @@ type ImageBoot2 struct {
Test string
Main string
Active string
+ ReturnCode int `json:"rc"`
}
func NewImageBoot2() (*ImageBoot2, error) {
@@ -85,6 +86,10 @@ func DecodeImageBoot2Response(data []byte) (*ImageBoot2, error) {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
err.Error()))
}
+ if i.ReturnCode != 0 {
+ return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
+ i.ReturnCode))
+ }
if i.Test != "" {
i.Test, err = HashDecode(i.Test)
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/49439638/newtmgr/protocol/imagefiledownload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagefiledownload.go b/newtmgr/protocol/imagefiledownload.go
index 00e6798..ae4038e 100644
--- a/newtmgr/protocol/imagefiledownload.go
+++ b/newtmgr/protocol/imagefiledownload.go
@@ -70,9 +70,10 @@ func (f *FileDownload) EncodeWriteRequest() (*NmgrReq, error) {
func DecodeFileDownloadResponse(data []byte) (*FileDownload, error) {
type DownloadResp struct {
- Off uint32 `json:"off"`
- Size uint32 `json:"len"`
- Data string `json:"data"`
+ Off uint32 `json:"off"`
+ Size uint32 `json:"len"`
+ Data string `json:"data"`
+ ReturnCode int `json:"rc"`
}
resp := &DownloadResp{}
@@ -81,6 +82,10 @@ func DecodeFileDownloadResponse(data []byte) (*FileDownload, error) {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
err.Error()))
}
+ if resp.ReturnCode != 0 {
+ return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
+ resp.ReturnCode))
+ }
decodedData, err := base64.StdEncoding.DecodeString(resp.Data)
if err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/49439638/newtmgr/protocol/imagefileupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagefileupload.go b/newtmgr/protocol/imagefileupload.go
index 6749911..390e9c7 100644
--- a/newtmgr/protocol/imagefileupload.go
+++ b/newtmgr/protocol/imagefileupload.go
@@ -27,10 +27,11 @@ import (
)
type FileUpload struct {
- Offset uint32 `json:"off"`
- Name string
- Size uint32
- Data []byte
+ Offset uint32 `json:"off"`
+ Name string
+ Size uint32
+ Data []byte
+ ReturnCode int `json:"rc"`
}
func NewFileUpload() (*FileUpload, error) {
@@ -92,5 +93,9 @@ func DecodeFileUploadResponse(data []byte) (*FileUpload, error) {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
err.Error()))
}
+ if f.ReturnCode != 0 {
+ return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
+ f.ReturnCode))
+ }
return f, nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/49439638/newtmgr/protocol/imageupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageupload.go b/newtmgr/protocol/imageupload.go
index f1c8de5..9f52074 100644
--- a/newtmgr/protocol/imageupload.go
+++ b/newtmgr/protocol/imageupload.go
@@ -27,9 +27,10 @@ import (
)
type ImageUpload struct {
- Offset uint32 `json:"off"`
- Size uint32
- Data []byte
+ Offset uint32 `json:"off"`
+ Size uint32
+ Data []byte
+ ReturnCode int `json:"rc"`
}
func NewImageUpload() (*ImageUpload, error) {
@@ -89,5 +90,9 @@ func DecodeImageUploadResponse(data []byte) (*ImageUpload, error) {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
err.Error()))
}
+ if i.ReturnCode != 0 {
+ return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
+ i.ReturnCode))
+ }
return i, nil
}