Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop e1aa9abfe -> 6b9622e98


MYNEWT-569 Move file cmds from imgr to new grp: fs


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

Branch: refs/heads/develop
Commit: 6b9622e987a6c05fee1363862f0a13f578059c4a
Parents: e1aa9ab
Author: Christopher Collins <[email protected]>
Authored: Thu Jan 26 19:04:14 2017 -0800
Committer: Christopher Collins <[email protected]>
Committed: Thu Jan 26 19:04:14 2017 -0800

----------------------------------------------------------------------
 newtmgr/cli/commands.go               |  13 +-
 newtmgr/cli/fs.go                     | 216 +++++++++++++++++++++++++++++
 newtmgr/cli/image.go                  | 174 -----------------------
 newtmgr/protocol/coreerase.go         |   2 +-
 newtmgr/protocol/corelist.go          |   2 +-
 newtmgr/protocol/coreload.go          |   2 +-
 newtmgr/protocol/defs.go              |   1 +
 newtmgr/protocol/fsdefs.go            |  24 ++++
 newtmgr/protocol/fsdownload.go        | 102 ++++++++++++++
 newtmgr/protocol/fsupload.go          | 104 ++++++++++++++
 newtmgr/protocol/imagedefs.go         |   9 +-
 newtmgr/protocol/imagefiledownload.go | 102 --------------
 newtmgr/protocol/imagefileupload.go   | 104 --------------
 newtmgr/protocol/imagestate.go        |   4 +-
 newtmgr/protocol/imageupload.go       |   2 +-
 15 files changed, 464 insertions(+), 397 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/cli/commands.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/commands.go b/newtmgr/cli/commands.go
index 021a9f0..e8f6c4e 100644
--- a/newtmgr/cli/commands.go
+++ b/newtmgr/cli/commands.go
@@ -56,18 +56,19 @@ func Commands() *cobra.Command {
        nmCmd.PersistentFlags().BoolVarP(&nmutil.TraceLogEnabled, "trace", "t",
                false, "print all bytes transmitted and received")
 
+       nmCmd.AddCommand(configCmd())
        nmCmd.AddCommand(connProfileCmd())
+       nmCmd.AddCommand(crashCmd())
+       nmCmd.AddCommand(dTimeCmd())
+       nmCmd.AddCommand(fsCmd())
        nmCmd.AddCommand(echoCmd())
        nmCmd.AddCommand(imageCmd())
-       nmCmd.AddCommand(statsCmd())
-       nmCmd.AddCommand(taskStatsCmd())
-       nmCmd.AddCommand(mempoolStatsCmd())
-       nmCmd.AddCommand(configCmd())
        nmCmd.AddCommand(logsCmd())
-       nmCmd.AddCommand(dTimeCmd())
+       nmCmd.AddCommand(mempoolStatsCmd())
        nmCmd.AddCommand(resetCmd())
-       nmCmd.AddCommand(crashCmd())
        nmCmd.AddCommand(runCmd())
+       nmCmd.AddCommand(statsCmd())
+       nmCmd.AddCommand(taskStatsCmd())
 
        return nmCmd
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/cli/fs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/fs.go b/newtmgr/cli/fs.go
new file mode 100644
index 0000000..bdcb062
--- /dev/null
+++ b/newtmgr/cli/fs.go
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package cli
+
+import (
+       "fmt"
+       "io"
+       "io/ioutil"
+       "os"
+
+       "mynewt.apache.org/newt/newtmgr/protocol"
+       "mynewt.apache.org/newt/util"
+
+       "github.com/spf13/cobra"
+)
+
+func fsUploadCmd(cmd *cobra.Command, args []string) {
+       if len(args) < 2 {
+               nmUsage(cmd, util.NewNewtError(
+                       "Need to specify source file and destination file to 
upload"))
+       }
+
+       file, err := ioutil.ReadFile(args[0])
+       if err != nil {
+               nmUsage(cmd, util.NewNewtError(err.Error()))
+       }
+
+       filename := args[1]
+       if len(filename) > 64 {
+               nmUsage(cmd, util.NewNewtError("Target filename too long"))
+       }
+
+       runner, err := getTargetCmdRunner()
+       if err != nil {
+               nmUsage(cmd, err)
+       }
+       defer runner.Conn.Close()
+
+       err = echoCtrl(runner, "0")
+       if err != nil {
+               nmUsage(cmd, err)
+       }
+       defer echoCtrl(runner, "1")
+       var currOff uint32 = 0
+       var cnt int = 0
+
+       fileSz := uint32(len(file))
+
+       for currOff < fileSz {
+               fsUpload, err := protocol.NewFileUpload()
+               if err != nil {
+                       echoOnNmUsage(runner, err, cmd)
+               }
+
+               blockSz := fileSz - currOff
+               if currOff == 0 {
+                       blockSz = 3
+               } else {
+                       if blockSz > 36 {
+                               blockSz = 36
+                       }
+               }
+
+               fsUpload.Offset = currOff
+               fsUpload.Size = fileSz
+               fsUpload.Name = filename
+               fsUpload.Data = file[currOff : currOff+blockSz]
+
+               nmr, err := fsUpload.EncodeWriteRequest()
+               if err != nil {
+                       echoOnNmUsage(runner, err, cmd)
+               }
+
+               if err := runner.WriteReq(nmr); err != nil {
+                       echoOnNmUsage(runner, err, cmd)
+               }
+
+               rsp, err := runner.ReadResp()
+               if err != nil {
+                       echoOnNmUsage(runner, err, cmd)
+               }
+
+               ersp, err := protocol.DecodeFileUploadResponse(rsp.Data)
+               if err != nil {
+                       echoOnNmUsage(runner, err, cmd)
+               }
+               currOff = ersp.Offset
+               cnt++
+               fmt.Println(cnt, currOff)
+       }
+       fmt.Println("Done")
+}
+
+func fsDownloadCmd(cmd *cobra.Command, args []string) {
+       if len(args) < 2 {
+               nmUsage(cmd, util.NewNewtError(
+                       "Need to specify source file and destination file to 
download"))
+       }
+
+       runner, err := getTargetCmdRunner()
+       if err != nil {
+               nmUsage(cmd, err)
+       }
+       defer runner.Conn.Close()
+
+       var currOff uint32 = 0
+       var cnt int = 0
+       var fileSz uint32 = 1
+
+       filename := args[0]
+       if len(filename) > 64 {
+               nmUsage(cmd, util.NewNewtError("Source filename too long"))
+       }
+
+       file, err := os.OpenFile(args[1], os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 
0660)
+       if err != nil {
+               nmUsage(cmd, util.NewNewtError(fmt.Sprintf(
+                       "Cannot open file %s - %s", args[1], err.Error())))
+       }
+
+       for currOff < fileSz {
+               fsDownload, err := protocol.NewFileDownload()
+               if err != nil {
+                       nmUsage(cmd, err)
+               }
+
+               fsDownload.Offset = currOff
+               fsDownload.Name = filename
+
+               nmr, err := fsDownload.EncodeWriteRequest()
+               if err != nil {
+                       nmUsage(cmd, err)
+               }
+
+               if err := runner.WriteReq(nmr); err != nil {
+                       nmUsage(cmd, err)
+               }
+
+               rsp, err := runner.ReadResp()
+               if err != nil {
+                       nmUsage(cmd, err)
+               }
+
+               ersp, err := protocol.DecodeFileDownloadResponse(rsp.Data)
+               if err != nil {
+                       nmUsage(cmd, err)
+               }
+               if currOff == ersp.Offset {
+                       n, err := file.Write(ersp.Data)
+                       if err == nil && n < len(ersp.Data) {
+                               err = io.ErrShortWrite
+                               nmUsage(cmd, util.NewNewtError(fmt.Sprintf(
+                                       "Cannot write file %s - %s", args[1],
+                                       err.Error())))
+                       }
+               }
+               if currOff == 0 {
+                       fileSz = ersp.Size
+               }
+               cnt++
+               currOff += uint32(len(ersp.Data))
+               fmt.Println(cnt, currOff)
+
+       }
+       file.Close()
+       fmt.Println("Done")
+}
+
+func fsCmd() *cobra.Command {
+       fsCmd := &cobra.Command{
+               Use:   "fs",
+               Short: "Access files on device",
+               Run: func(cmd *cobra.Command, args []string) {
+                       cmd.HelpFunc()(cmd, args)
+               },
+       }
+
+       uploadEx := "  newtmgr -c olimex fs upload sample.lua /sample.lua\n"
+
+       uploadCmd := &cobra.Command{
+               Use:     "upload <src-filename> <dst-filename>",
+               Short:   "Upload file to target",
+               Example: uploadEx,
+               Run:     fsUploadCmd,
+       }
+       fsCmd.AddCommand(uploadCmd)
+
+       downloadEx := "  newtmgr -c olimex image download /cfg/mfg mfg.txt\n"
+
+       downloadCmd := &cobra.Command{
+               Use:     "download <src-filename> <dst-filename>",
+               Short:   "Download file from target",
+               Example: downloadEx,
+               Run:     fsDownloadCmd,
+       }
+       fsCmd.AddCommand(downloadCmd)
+
+       return fsCmd
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index a70a68f..10ac1f0 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -23,7 +23,6 @@ import (
        "encoding/hex"
        "errors"
        "fmt"
-       "io"
        "io/ioutil"
        "os"
        "strings"
@@ -374,157 +373,6 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
        fmt.Println("Done")
 }
 
-func fileUploadCmd(cmd *cobra.Command, args []string) {
-       if len(args) < 2 {
-               nmUsage(cmd, util.NewNewtError(
-                       "Need to specify file and target filename to upload"))
-       }
-
-       file, err := ioutil.ReadFile(args[0])
-       if err != nil {
-               nmUsage(cmd, util.NewNewtError(err.Error()))
-       }
-
-       filename := args[1]
-       if len(filename) > 64 {
-               nmUsage(cmd, util.NewNewtError("Target filename too long"))
-       }
-
-       runner, err := getTargetCmdRunner()
-       if err != nil {
-               nmUsage(cmd, err)
-       }
-       defer runner.Conn.Close()
-
-       err = echoCtrl(runner, "0")
-       if err != nil {
-               nmUsage(cmd, err)
-       }
-       defer echoCtrl(runner, "1")
-       var currOff uint32 = 0
-       var cnt int = 0
-
-       fileSz := uint32(len(file))
-
-       for currOff < fileSz {
-               fileUpload, err := protocol.NewFileUpload()
-               if err != nil {
-                       echoOnNmUsage(runner, err, cmd)
-               }
-
-               blockSz := fileSz - currOff
-               if currOff == 0 {
-                       blockSz = 3
-               } else {
-                       if blockSz > 36 {
-                               blockSz = 36
-                       }
-               }
-
-               fileUpload.Offset = currOff
-               fileUpload.Size = fileSz
-               fileUpload.Name = filename
-               fileUpload.Data = file[currOff : currOff+blockSz]
-
-               nmr, err := fileUpload.EncodeWriteRequest()
-               if err != nil {
-                       echoOnNmUsage(runner, err, cmd)
-               }
-
-               if err := runner.WriteReq(nmr); err != nil {
-                       echoOnNmUsage(runner, err, cmd)
-               }
-
-               rsp, err := runner.ReadResp()
-               if err != nil {
-                       echoOnNmUsage(runner, err, cmd)
-               }
-
-               ersp, err := protocol.DecodeFileUploadResponse(rsp.Data)
-               if err != nil {
-                       echoOnNmUsage(runner, err, cmd)
-               }
-               currOff = ersp.Offset
-               cnt++
-               fmt.Println(cnt, currOff)
-       }
-       fmt.Println("Done")
-}
-
-func fileDownloadCmd(cmd *cobra.Command, args []string) {
-       if len(args) < 2 {
-               nmUsage(cmd, util.NewNewtError(
-                       "Need to specify file and target filename to download"))
-       }
-
-       filename := args[0]
-       if len(filename) > 64 {
-               nmUsage(cmd, util.NewNewtError("Target filename too long"))
-       }
-
-       runner, err := getTargetCmdRunner()
-       if err != nil {
-               nmUsage(cmd, err)
-       }
-       defer runner.Conn.Close()
-
-       var currOff uint32 = 0
-       var cnt int = 0
-       var fileSz uint32 = 1
-
-       file, err := os.OpenFile(args[1], os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 
0660)
-       if err != nil {
-               nmUsage(cmd, util.NewNewtError(fmt.Sprintf(
-                       "Cannot open file %s - %s", args[1], err.Error())))
-       }
-       for currOff < fileSz {
-               fileDownload, err := protocol.NewFileDownload()
-               if err != nil {
-                       nmUsage(cmd, err)
-               }
-
-               fileDownload.Offset = currOff
-               fileDownload.Name = filename
-
-               nmr, err := fileDownload.EncodeWriteRequest()
-               if err != nil {
-                       nmUsage(cmd, err)
-               }
-
-               if err := runner.WriteReq(nmr); err != nil {
-                       nmUsage(cmd, err)
-               }
-
-               rsp, err := runner.ReadResp()
-               if err != nil {
-                       nmUsage(cmd, err)
-               }
-
-               ersp, err := protocol.DecodeFileDownloadResponse(rsp.Data)
-               if err != nil {
-                       nmUsage(cmd, err)
-               }
-               if currOff == ersp.Offset {
-                       n, err := file.Write(ersp.Data)
-                       if err == nil && n < len(ersp.Data) {
-                               err = io.ErrShortWrite
-                               nmUsage(cmd, util.NewNewtError(fmt.Sprintf(
-                                       "Cannot write file %s - %s", args[1],
-                                       err.Error())))
-                       }
-               }
-               if currOff == 0 {
-                       fileSz = ersp.Size
-               }
-               cnt++
-               currOff += uint32(len(ersp.Data))
-               fmt.Println(cnt, currOff)
-
-       }
-       file.Close()
-       fmt.Println("Done")
-}
-
 func coreConvertCmd(cmd *cobra.Command, args []string) {
        if len(args) < 2 {
                nmUsage(cmd, nil)
@@ -718,28 +566,6 @@ func imageCmd() *cobra.Command {
        }
        imageCmd.AddCommand(uploadCmd)
 
-       fileUploadEx := "  newtmgr -c olimex image fileupload <filename> 
<tgt_file>\n"
-       fileUploadEx += "  newtmgr -c olimex image fileupload sample.lua 
/sample.lua\n"
-
-       fileUploadCmd := &cobra.Command{
-               Use:     "fileupload",
-               Short:   "Upload file to target",
-               Example: fileUploadEx,
-               Run:     fileUploadCmd,
-       }
-       imageCmd.AddCommand(fileUploadCmd)
-
-       fileDownloadEx := "  newtmgr -c olimex image filedownload <tgt_file> 
<filename>\n"
-       fileDownloadEx += "  newtmgr -c olimex image filedownload /cfg/mfg 
mfg.txt\n"
-
-       fileDownloadCmd := &cobra.Command{
-               Use:     "filedownload",
-               Short:   "Download file from target",
-               Example: fileDownloadEx,
-               Run:     fileDownloadCmd,
-       }
-       imageCmd.AddCommand(fileDownloadCmd)
-
        coreListEx := "  newtmgr -c olimex image corelist\n"
 
        coreListCmd := &cobra.Command{

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/coreerase.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/coreerase.go b/newtmgr/protocol/coreerase.go
index 51926fa..1dab8b0 100644
--- a/newtmgr/protocol/coreerase.go
+++ b/newtmgr/protocol/coreerase.go
@@ -45,7 +45,7 @@ func (ce *CoreErase) EncodeWriteRequest() (*NmgrReq, error) {
        nmr.Op = NMGR_OP_WRITE
        nmr.Flags = 0
        nmr.Group = NMGR_GROUP_ID_IMAGE
-       nmr.Id = IMGMGR_NMGR_OP_CORELOAD
+       nmr.Id = IMGMGR_NMGR_ID_CORELOAD
        nmr.Len = 0
 
        return nmr, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/corelist.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/corelist.go b/newtmgr/protocol/corelist.go
index e285955..9bd60f5 100644
--- a/newtmgr/protocol/corelist.go
+++ b/newtmgr/protocol/corelist.go
@@ -45,7 +45,7 @@ func (ce *CoreList) EncodeWriteRequest() (*NmgrReq, error) {
        nmr.Op = NMGR_OP_READ
        nmr.Flags = 0
        nmr.Group = NMGR_GROUP_ID_IMAGE
-       nmr.Id = IMGMGR_NMGR_OP_CORELIST
+       nmr.Id = IMGMGR_NMGR_ID_CORELIST
        nmr.Len = 0
 
        return nmr, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/coreload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/coreload.go b/newtmgr/protocol/coreload.go
index 55ca379..82f6d52 100644
--- a/newtmgr/protocol/coreload.go
+++ b/newtmgr/protocol/coreload.go
@@ -77,7 +77,7 @@ func (cl *CoreDownload) Download(off, size uint32) error {
                nmr.Op = NMGR_OP_READ
                nmr.Flags = 0
                nmr.Group = NMGR_GROUP_ID_IMAGE
-               nmr.Id = IMGMGR_NMGR_OP_CORELOAD
+               nmr.Id = IMGMGR_NMGR_ID_CORELOAD
                nmr.Len = uint16(len(data))
                nmr.Data = data
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/defs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/defs.go b/newtmgr/protocol/defs.go
index 7cdedd3..c2862fa 100644
--- a/newtmgr/protocol/defs.go
+++ b/newtmgr/protocol/defs.go
@@ -27,6 +27,7 @@ const (
        NMGR_GROUP_ID_CRASH   = 5
        NMGR_GROUP_ID_SPLIT   = 6
        NMGR_GROUP_ID_RUN     = 7
+       NMGR_GROUP_ID_FS      = 8
        NMGR_GROUP_ID_PERUSER = 64
 )
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/fsdefs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/fsdefs.go b/newtmgr/protocol/fsdefs.go
new file mode 100644
index 0000000..601b28e
--- /dev/null
+++ b/newtmgr/protocol/fsdefs.go
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package protocol
+
+const (
+       FS_NMGR_ID_FILE = 0
+)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/fsdownload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/fsdownload.go b/newtmgr/protocol/fsdownload.go
new file mode 100644
index 0000000..24c134d
--- /dev/null
+++ b/newtmgr/protocol/fsdownload.go
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package protocol
+
+import (
+       "fmt"
+
+       "github.com/ugorji/go/codec"
+       "mynewt.apache.org/newt/util"
+)
+
+type FileDownload struct {
+       Offset uint32
+       Size   uint32
+       Name   string
+       Data   []byte
+}
+
+func NewFileDownload() (*FileDownload, error) {
+       f := &FileDownload{}
+       f.Offset = 0
+       f.Data = make([]byte, 0)
+
+       return f, nil
+}
+
+func (f *FileDownload) EncodeWriteRequest() (*NmgrReq, error) {
+       type DownloadReq struct {
+               Off  uint32 `codec:"off"`
+               Name string `codec:"name"`
+       }
+       nmr, err := NewNmgrReq()
+       if err != nil {
+               return nil, err
+       }
+
+       nmr.Op = NMGR_OP_READ
+       nmr.Flags = 0
+       nmr.Group = NMGR_GROUP_ID_FS
+       nmr.Id = FS_NMGR_ID_FILE
+
+       downloadReq := &DownloadReq{
+               Off:  f.Offset,
+               Name: f.Name,
+       }
+
+       data := make([]byte, 0)
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
+       enc.Encode(downloadReq)
+       nmr.Len = uint16(len(data))
+       nmr.Data = data
+
+       return nmr, nil
+}
+
+func DecodeFileDownloadResponse(data []byte) (*FileDownload, error) {
+       type DownloadResp struct {
+               Off        uint32 `json:"off"`
+               Size       uint32 `json:"len"`
+               Data       []byte `json:"data"`
+               ReturnCode int    `json:"rc"`
+       }
+       resp := &DownloadResp{}
+
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
+       err := dec.Decode(&resp)
+       if err != nil {
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
+                       err.Error()))
+       }
+       if resp.ReturnCode != 0 {
+               return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
+                       resp.ReturnCode))
+       }
+       if err != nil {
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+                       err.Error()))
+       }
+       f := &FileDownload{
+               Offset: resp.Off,
+               Data:   resp.Data,
+               Size:   resp.Size,
+       }
+       return f, nil
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/fsupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/fsupload.go b/newtmgr/protocol/fsupload.go
new file mode 100644
index 0000000..9658952
--- /dev/null
+++ b/newtmgr/protocol/fsupload.go
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package protocol
+
+import (
+       "fmt"
+
+       "github.com/ugorji/go/codec"
+       "mynewt.apache.org/newt/util"
+)
+
+type FileUpload struct {
+       Offset     uint32 `codec:"off"`
+       Name       string
+       Size       uint32
+       Data       []byte
+       ReturnCode int `codec:"rc"`
+}
+
+func NewFileUpload() (*FileUpload, error) {
+       f := &FileUpload{}
+       f.Offset = 0
+
+       return f, nil
+}
+
+func (f *FileUpload) EncodeWriteRequest() (*NmgrReq, error) {
+       type UploadReq struct {
+               Off  uint32 `codec:"off"`
+               Data []byte `codec:"data"`
+       }
+       type UploadFirstReq struct {
+               Off  uint32 `codec:"off"`
+               Size uint32 `codec:"len"`
+               Name string `codec:"name"`
+               Data []byte `codec:"data"`
+       }
+       nmr, err := NewNmgrReq()
+       if err != nil {
+               return nil, err
+       }
+
+       nmr.Op = NMGR_OP_WRITE
+       nmr.Flags = 0
+       nmr.Group = NMGR_GROUP_ID_FS
+       nmr.Id = FS_NMGR_ID_FILE
+
+       data := []byte{}
+
+       if f.Offset == 0 {
+               uploadReq := &UploadFirstReq{
+                       Off:  f.Offset,
+                       Size: f.Size,
+                       Name: f.Name,
+                       Data: f.Data,
+               }
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
+               enc.Encode(uploadReq)
+       } else {
+               uploadReq := &UploadReq{
+                       Off:  f.Offset,
+                       Data: f.Data,
+               }
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
+               enc.Encode(uploadReq)
+       }
+       nmr.Len = uint16(len(data))
+       nmr.Data = data
+
+       return nmr, nil
+}
+
+func DecodeFileUploadResponse(data []byte) (*FileUpload, error) {
+       f := &FileUpload{}
+
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
+       err := dec.Decode(&f)
+       if err != nil {
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %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/6b9622e9/newtmgr/protocol/imagedefs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagedefs.go b/newtmgr/protocol/imagedefs.go
index 46f43c2..c01bb2a 100644
--- a/newtmgr/protocol/imagedefs.go
+++ b/newtmgr/protocol/imagedefs.go
@@ -28,11 +28,10 @@ import (
 )
 
 const (
-       IMGMGR_NMGR_OP_STATE    = 0
-       IMGMGR_NMGR_OP_UPLOAD   = 1
-       IMGMGR_NMGR_OP_FILE     = 2
-       IMGMGR_NMGR_OP_CORELIST = 3
-       IMGMGR_NMGR_OP_CORELOAD = 4
+       IMGMGR_NMGR_ID_STATE    = 0
+       IMGMGR_NMGR_ID_UPLOAD   = 1
+       IMGMGR_NMGR_ID_CORELIST = 3
+       IMGMGR_NMGR_ID_CORELOAD = 4
 )
 
 type SplitStatus int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/imagefiledownload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagefiledownload.go 
b/newtmgr/protocol/imagefiledownload.go
deleted file mode 100644
index 4acb83f..0000000
--- a/newtmgr/protocol/imagefiledownload.go
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
-       "fmt"
-
-       "github.com/ugorji/go/codec"
-       "mynewt.apache.org/newt/util"
-)
-
-type FileDownload struct {
-       Offset uint32
-       Size   uint32
-       Name   string
-       Data   []byte
-}
-
-func NewFileDownload() (*FileDownload, error) {
-       f := &FileDownload{}
-       f.Offset = 0
-       f.Data = make([]byte, 0)
-
-       return f, nil
-}
-
-func (f *FileDownload) EncodeWriteRequest() (*NmgrReq, error) {
-       type DownloadReq struct {
-               Off  uint32 `codec:"off"`
-               Name string `codec:"name"`
-       }
-       nmr, err := NewNmgrReq()
-       if err != nil {
-               return nil, err
-       }
-
-       nmr.Op = NMGR_OP_READ
-       nmr.Flags = 0
-       nmr.Group = NMGR_GROUP_ID_IMAGE
-       nmr.Id = IMGMGR_NMGR_OP_FILE
-
-       downloadReq := &DownloadReq{
-               Off:  f.Offset,
-               Name: f.Name,
-       }
-
-       data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
-       enc.Encode(downloadReq)
-       nmr.Len = uint16(len(data))
-       nmr.Data = data
-
-       return nmr, nil
-}
-
-func DecodeFileDownloadResponse(data []byte) (*FileDownload, error) {
-       type DownloadResp struct {
-               Off        uint32 `json:"off"`
-               Size       uint32 `json:"len"`
-               Data       []byte `json:"data"`
-               ReturnCode int    `json:"rc"`
-       }
-       resp := &DownloadResp{}
-
-       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
-       err := dec.Decode(&resp)
-       if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
-                       err.Error()))
-       }
-       if resp.ReturnCode != 0 {
-               return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
-                       resp.ReturnCode))
-       }
-       if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
-                       err.Error()))
-       }
-       f := &FileDownload{
-               Offset: resp.Off,
-               Data:   resp.Data,
-               Size:   resp.Size,
-       }
-       return f, nil
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/imagefileupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagefileupload.go 
b/newtmgr/protocol/imagefileupload.go
deleted file mode 100644
index 229f4f9..0000000
--- a/newtmgr/protocol/imagefileupload.go
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package protocol
-
-import (
-       "fmt"
-
-       "github.com/ugorji/go/codec"
-       "mynewt.apache.org/newt/util"
-)
-
-type FileUpload struct {
-       Offset     uint32 `codec:"off"`
-       Name       string
-       Size       uint32
-       Data       []byte
-       ReturnCode int `codec:"rc"`
-}
-
-func NewFileUpload() (*FileUpload, error) {
-       f := &FileUpload{}
-       f.Offset = 0
-
-       return f, nil
-}
-
-func (f *FileUpload) EncodeWriteRequest() (*NmgrReq, error) {
-       type UploadReq struct {
-               Off  uint32 `codec:"off"`
-               Data []byte `codec:"data"`
-       }
-       type UploadFirstReq struct {
-               Off  uint32 `codec:"off"`
-               Size uint32 `codec:"len"`
-               Name string `codec:"name"`
-               Data []byte `codec:"data"`
-       }
-       nmr, err := NewNmgrReq()
-       if err != nil {
-               return nil, err
-       }
-
-       nmr.Op = NMGR_OP_WRITE
-       nmr.Flags = 0
-       nmr.Group = NMGR_GROUP_ID_IMAGE
-       nmr.Id = IMGMGR_NMGR_OP_FILE
-
-       data := []byte{}
-
-       if f.Offset == 0 {
-               uploadReq := &UploadFirstReq{
-                       Off:  f.Offset,
-                       Size: f.Size,
-                       Name: f.Name,
-                       Data: f.Data,
-               }
-               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
-               enc.Encode(uploadReq)
-       } else {
-               uploadReq := &UploadReq{
-                       Off:  f.Offset,
-                       Data: f.Data,
-               }
-               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
-               enc.Encode(uploadReq)
-       }
-       nmr.Len = uint16(len(data))
-       nmr.Data = data
-
-       return nmr, nil
-}
-
-func DecodeFileUploadResponse(data []byte) (*FileUpload, error) {
-       f := &FileUpload{}
-
-       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
-       err := dec.Decode(&f)
-       if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %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/6b9622e9/newtmgr/protocol/imagestate.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagestate.go b/newtmgr/protocol/imagestate.go
index 44c6f59..d6482e5 100644
--- a/newtmgr/protocol/imagestate.go
+++ b/newtmgr/protocol/imagestate.go
@@ -75,7 +75,7 @@ func (i *ImageStateReadReq) Encode() (*NmgrReq, error) {
        nmr.Op = NMGR_OP_READ
        nmr.Flags = 0
        nmr.Group = NMGR_GROUP_ID_IMAGE
-       nmr.Id = IMGMGR_NMGR_OP_STATE
+       nmr.Id = IMGMGR_NMGR_ID_STATE
        nmr.Len = 0
 
        return nmr, nil
@@ -104,7 +104,7 @@ func (i *ImageStateWriteReq) Encode() (*NmgrReq, error) {
        nmr.Op = NMGR_OP_WRITE
        nmr.Flags = 0
        nmr.Group = NMGR_GROUP_ID_IMAGE
-       nmr.Id = IMGMGR_NMGR_OP_STATE
+       nmr.Id = IMGMGR_NMGR_ID_STATE
 
        data := make([]byte, 0)
        enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/6b9622e9/newtmgr/protocol/imageupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageupload.go b/newtmgr/protocol/imageupload.go
index 099352b..b974307 100644
--- a/newtmgr/protocol/imageupload.go
+++ b/newtmgr/protocol/imageupload.go
@@ -58,7 +58,7 @@ func (i *ImageUpload) EncodeWriteRequest() (*NmgrReq, error) {
        nmr.Op = NMGR_OP_WRITE
        nmr.Flags = 0
        nmr.Group = NMGR_GROUP_ID_IMAGE
-       nmr.Id = IMGMGR_NMGR_OP_UPLOAD
+       nmr.Id = IMGMGR_NMGR_ID_UPLOAD
 
        data := []byte{}
 

Reply via email to