Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/master 831c85757 -> 7f5231438


Add len field to first upload request.


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/7f523143
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/7f523143
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/7f523143

Branch: refs/heads/master
Commit: 7f5231438de6e79ea9c27b6cc445e34be84a3167
Parents: 831c857
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Jan 22 13:10:35 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Jan 22 13:10:35 2016 -0800

----------------------------------------------------------------------
 newtmgr/newtmgr.go              |  1 +
 newtmgr/protocol/imageupload.go | 25 +++++++++++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7f523143/newtmgr/newtmgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/newtmgr.go b/newtmgr/newtmgr.go
index 3899e1d..8d84e4c 100644
--- a/newtmgr/newtmgr.go
+++ b/newtmgr/newtmgr.go
@@ -426,6 +426,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
                }
 
                imageUpload.Offset = currOff
+               imageUpload.Size = imageSz
                imageUpload.Data = imageFile[currOff : currOff+blockSz]
 
                nmr, err := imageUpload.EncodeWriteRequest()

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7f523143/newtmgr/protocol/imageupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageupload.go b/newtmgr/protocol/imageupload.go
index a3f87f4..7f079b4 100644
--- a/newtmgr/protocol/imageupload.go
+++ b/newtmgr/protocol/imageupload.go
@@ -24,6 +24,7 @@ import (
 
 type ImageUpload struct {
        Offset uint32 `json:"off"`
+       Size   uint32
        Data   []byte
 }
 
@@ -39,6 +40,11 @@ func (i *ImageUpload) EncodeWriteRequest() (*NmgrReq, error) 
{
                Off  uint32 `json:"off"`
                Data string `json:"data"`
        }
+       type UploadFirstReq struct {
+               Off  uint32 `json:"off"`
+               Size uint32 `json:"len"`
+               Data string `json:"data"`
+       }
        nmr, err := NewNmgrReq()
        if err != nil {
                return nil, err
@@ -49,11 +55,22 @@ func (i *ImageUpload) EncodeWriteRequest() (*NmgrReq, 
error) {
        nmr.Group = NMGR_GROUP_ID_IMAGE
        nmr.Id = IMGMGR_NMGR_OP_UPLOAD
 
-       uploadReq := &UploadReq{
-               Off:  i.Offset,
-               Data: base64.StdEncoding.EncodeToString(i.Data),
+       data := []byte{}
+
+       if i.Offset == 0 {
+               uploadReq := &UploadFirstReq{
+                       Off:  i.Offset,
+                       Size: i.Size,
+                       Data: base64.StdEncoding.EncodeToString(i.Data),
+               }
+               data, _ = json.Marshal(uploadReq)
+       } else {
+               uploadReq := &UploadReq{
+                       Off:  i.Offset,
+                       Data: base64.StdEncoding.EncodeToString(i.Data),
+               }
+               data, _ = json.Marshal(uploadReq)
        }
-       data, _ := json.Marshal(uploadReq)
        nmr.Len = uint16(len(data))
        nmr.Data = data
 

Reply via email to