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:24 UTC
[1/6] incubator-mynewt-newt git commit: imgmgr;
add boot2/list2 commands which include image hash.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop ff51f0731 -> cab3a2d4a
imgmgr; add boot2/list2 commands which include image hash.
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/1aaf0b01
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/1aaf0b01
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/1aaf0b01
Branch: refs/heads/develop
Commit: 1aaf0b012089d1a232c9b77dd8253d470d8d1bef
Parents: ff51f07
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 11:01:02 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 17:56:21 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/image.go | 136 +++++++++++++++++++++++++++++++++---
newtmgr/protocol/imageboot2.go | 107 ++++++++++++++++++++++++++++
newtmgr/protocol/imagelist.go | 32 ++++++---
newtmgr/protocol/imagelist2.go | 80 +++++++++++++++++++++
4 files changed, 336 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1aaf0b01/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 393dd91..74a3764 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -47,7 +47,7 @@ func imageListCmd(cmd *cobra.Command, args []string) {
conn, err := transport.NewConn(profile)
if err != nil {
- nmUsage(cmd, err)
+ nmUsage(nil, err)
}
runner, err := protocol.NewCmdRunner(conn)
@@ -84,6 +84,56 @@ func imageListCmd(cmd *cobra.Command, args []string) {
}
}
+func imageListCmd2(cmd *cobra.Command, args []string) {
+ cpm, err := config.NewConnProfileMgr()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ nmUsage(nil, err)
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ imageList, err := protocol.NewImageList2()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := imageList.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)
+ }
+
+ iRsp, err := protocol.DecodeImageListResponse2(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ fmt.Println("Images:")
+ for hash, ver := range iRsp.Images {
+ fmt.Printf(" %8s %s\n", ver, hash)
+ }
+}
+
func imageUploadCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
nmUsage(cmd, util.NewNewtError("Need to specify image to upload"))
@@ -106,7 +156,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
conn, err := transport.NewConn(profile)
if err != nil {
- nmUsage(cmd, err)
+ nmUsage(nil, err)
}
runner, err := protocol.NewCmdRunner(conn)
@@ -176,7 +226,7 @@ func imageBootCmd(cmd *cobra.Command, args []string) {
conn, err := transport.NewConn(profile)
if err != nil {
- nmUsage(cmd, err)
+ nmUsage(nil, err)
}
runner, err := protocol.NewCmdRunner(conn)
@@ -211,9 +261,63 @@ func imageBootCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
if len(args) == 0 {
- fmt.Println(" Test image :", iRsp.Test)
- fmt.Println(" Main image :", iRsp.Main)
- fmt.Println(" Active img :", iRsp.Active)
+ fmt.Println(" Test image:", iRsp.Test)
+ fmt.Println(" Main image:", iRsp.Main)
+ fmt.Println(" Active img:", iRsp.Active)
+ }
+}
+
+func imageBoot2Cmd(cmd *cobra.Command, args []string) {
+ cpm, err := config.NewConnProfileMgr()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ nmUsage(nil, err)
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ imageBoot, err := protocol.NewImageBoot2()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if len(args) >= 1 {
+ imageBoot.BootTarget = args[0]
+ }
+ nmr, err := imageBoot.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)
+ }
+
+ iRsp, err := protocol.DecodeImageBoot2Response(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ if len(args) == 0 {
+ fmt.Println(" Test image:", iRsp.Test)
+ fmt.Println(" Main image:", iRsp.Main)
+ fmt.Println(" Active img:", iRsp.Active)
}
}
@@ -245,7 +349,7 @@ func fileUploadCmd(cmd *cobra.Command, args []string) {
conn, err := transport.NewConn(profile)
if err != nil {
- nmUsage(cmd, err)
+ nmUsage(nil, err)
}
runner, err := protocol.NewCmdRunner(conn)
@@ -333,7 +437,7 @@ func fileDownloadCmd(cmd *cobra.Command, args []string) {
conn, err := transport.NewConn(profile)
if err != nil {
- nmUsage(cmd, err)
+ nmUsage(nil, err)
}
runner, err := protocol.NewCmdRunner(conn)
@@ -594,11 +698,18 @@ func imageCmd() *cobra.Command {
}
listCmd := &cobra.Command{
+ Use: "list2",
+ Short: "Show target images",
+ Run: imageListCmd2,
+ }
+ imageCmd.AddCommand(listCmd)
+
+ listOldCmd := &cobra.Command{
Use: "list",
Short: "Show target images",
Run: imageListCmd,
}
- imageCmd.AddCommand(listCmd)
+ imageCmd.AddCommand(listOldCmd)
uploadEx := " newtmgr -c olimex image upload <image_file\n"
uploadEx += " newtmgr -c olimex image upload bin/slinky_zero/apps/slinky.img\n"
@@ -623,6 +734,13 @@ func imageCmd() *cobra.Command {
}
imageCmd.AddCommand(bootCmd)
+ boot2Cmd := &cobra.Command{
+ Use: "boot2",
+ Short: "Which image to boot",
+ Run: imageBoot2Cmd,
+ }
+ imageCmd.AddCommand(boot2Cmd)
+
fileUploadEx := " newtmgr -c olimex image fileupload <filename> <tgt_file>\n"
fileUploadEx += " newtmgr -c olimex image fileupload sample.lua /sample.lua\n"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1aaf0b01/newtmgr/protocol/imageboot2.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageboot2.go b/newtmgr/protocol/imageboot2.go
new file mode 100644
index 0000000..c8d4cf8
--- /dev/null
+++ b/newtmgr/protocol/imageboot2.go
@@ -0,0 +1,107 @@
+/**
+ * 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 (
+ "encoding/json"
+ "fmt"
+
+ "mynewt.apache.org/newt/util"
+)
+
+type ImageBoot2 struct {
+ BootTarget string
+ Test string
+ Main string
+ Active string
+}
+
+func NewImageBoot2() (*ImageBoot2, error) {
+ s := &ImageBoot2{}
+ s.BootTarget = ""
+ s.Test = ""
+ s.Main = ""
+ s.Active = ""
+ return s, nil
+}
+
+func (i *ImageBoot2) EncodeWriteRequest() (*NmgrReq, error) {
+ 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_BOOT2
+ nmr.Len = 0
+
+ if i.BootTarget != "" {
+ type BootReq struct {
+ Test string `json:"test"`
+ }
+
+ hash, err := HashEncode(i.BootTarget)
+ if err != nil {
+ return nil, err
+ }
+ bReq := &BootReq{
+ Test: hash,
+ }
+ data, _ := json.Marshal(bReq)
+ nmr.Data = data
+ nmr.Len = uint16(len(data))
+ nmr.Op = NMGR_OP_WRITE
+ }
+ return nmr, nil
+}
+
+func DecodeImageBoot2Response(data []byte) (*ImageBoot2, error) {
+ i := &ImageBoot2{}
+
+ if len(data) == 0 {
+ return i, nil
+ }
+ err := json.Unmarshal(data, &i)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+ if i.Test != "" {
+ i.Test, err = HashDecode(i.Test)
+ if err != nil {
+ return nil, err
+ }
+ }
+ if i.Main != "" {
+ i.Main, err = HashDecode(i.Main)
+ if err != nil {
+ return nil, err
+ }
+ }
+ if i.Active != "" {
+ i.Active, err = HashDecode(i.Active)
+ if err != nil {
+ return nil, err
+ }
+ }
+ return i, nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1aaf0b01/newtmgr/protocol/imagelist.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagelist.go b/newtmgr/protocol/imagelist.go
index ea516e3..8f4fe8b 100644
--- a/newtmgr/protocol/imagelist.go
+++ b/newtmgr/protocol/imagelist.go
@@ -20,6 +20,8 @@
package protocol
import (
+ "encoding/base64"
+ "encoding/hex"
"encoding/json"
"fmt"
@@ -35,26 +37,36 @@ const (
IMGMGR_NMGR_OP_UPLOAD = 1
IMGMGR_NMGR_OP_BOOT = 2
IMGMGR_NMGR_OP_FILE = 3
+ IMGMGR_NMGR_OP_LIST2 = 4
+ IMGMGR_NMGR_OP_BOOT2 = 5
IMGMGR_NMGR_OP_CORELIST = 6
IMGMGR_NMGR_OP_CORELOAD = 7
)
+func HashDecode(src string) (string, error) {
+ imgHex, err := base64.StdEncoding.DecodeString(src)
+ if err != nil {
+ return "", util.NewNewtError(fmt.Sprintf("Hash decode error: %s",
+ err.Error()))
+ }
+ return hex.EncodeToString(imgHex), nil
+}
+
+func HashEncode(src string) (string, error) {
+ imgHex, err := hex.DecodeString(src)
+ if err != nil {
+ return "", util.NewNewtError(fmt.Sprintf("Hash encode error: %s",
+ err.Error()))
+ }
+ return base64.StdEncoding.EncodeToString(imgHex), nil
+}
+
func NewImageList() (*ImageList, error) {
s := &ImageList{}
s.Images = []string{}
return s, nil
}
-func ImageVersStr(major uint8, minor uint8, revision uint16, buildNum uint32) string {
- if major == 0xff && minor == 0xff && revision == 0xffff &&
- buildNum == 0xffffffff {
- return "Not set"
- } else {
- versStr := fmt.Sprintf("%d.%d.%d.%d", major, minor, revision, buildNum)
- return versStr
- }
-}
-
func (i *ImageList) EncodeWriteRequest() (*NmgrReq, error) {
nmr, err := NewNmgrReq()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1aaf0b01/newtmgr/protocol/imagelist2.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagelist2.go b/newtmgr/protocol/imagelist2.go
new file mode 100644
index 0000000..173919d
--- /dev/null
+++ b/newtmgr/protocol/imagelist2.go
@@ -0,0 +1,80 @@
+/**
+ * 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 (
+ "encoding/json"
+ "fmt"
+
+ "mynewt.apache.org/newt/util"
+)
+
+type ImageList2 struct {
+ Images map[string]string
+}
+
+func NewImageList2() (*ImageList2, error) {
+ s := &ImageList2{}
+ s.Images = map[string]string{}
+ return s, nil
+}
+
+func (i *ImageList2) EncodeWriteRequest() (*NmgrReq, error) {
+ 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_LIST2
+ nmr.Len = 0
+
+ return nmr, nil
+}
+
+func DecodeImageListResponse2(data []byte) (*ImageList2, error) {
+ type ImageInfoJson map[string]string
+
+ type ImageListJson struct {
+ Images []ImageInfoJson
+ }
+
+ list := &ImageListJson{}
+
+ err := json.Unmarshal(data, &list)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+
+ list2, _ := NewImageList2()
+ for _, info := range list.Images {
+ for hash, ver := range info {
+ hash, err := HashDecode(hash)
+ if err != nil {
+ return nil, err
+ }
+ list2.Images[hash] = ver
+ }
+ }
+ return list2, nil
+}
[6/6] incubator-mynewt-newt git commit: newtmgr; go formatting
Posted by ma...@apache.org.
newtmgr; go formatting
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/cab3a2d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/cab3a2d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/cab3a2d4
Branch: refs/heads/develop
Commit: cab3a2d4a43bd616e944d9a927ea0e7b50af3060
Parents: dc7f93f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 18:03:35 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 18:03:35 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/echo.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cab3a2d4/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/echo.go b/newtmgr/cli/echo.go
index d1ad619..bdcafcc 100644
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@ -56,7 +56,7 @@ func echoRunCmd(cmd *cobra.Command, args []string) {
}
if len(args) != 1 {
- nmUsage(cmd, nil);
+ nmUsage(cmd, nil)
}
echo.Message = args[0]
[3/6] incubator-mynewt-newt git commit: newtmgr;
add command to reset the target.
Posted by ma...@apache.org.
newtmgr; add command to reset the target.
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/f2682e06
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f2682e06
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f2682e06
Branch: refs/heads/develop
Commit: f2682e06a27ee5c4f919d75b41e12abcbf3fc4d5
Parents: c77c2f0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 14:55:38 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 17:59:45 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/commands.go | 1 +
newtmgr/cli/reset.go | 82 ++++++++++++++++++++++++++++++++++++++++++
newtmgr/protocol/defs.go | 1 +
newtmgr/protocol/reset.go | 48 +++++++++++++++++++++++++
4 files changed, 132 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f2682e06/newtmgr/cli/commands.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/commands.go b/newtmgr/cli/commands.go
index 29d2d86..e3fded5 100644
--- a/newtmgr/cli/commands.go
+++ b/newtmgr/cli/commands.go
@@ -61,6 +61,7 @@ func Commands() *cobra.Command {
nmCmd.AddCommand(configCmd())
nmCmd.AddCommand(logsCmd())
nmCmd.AddCommand(dTimeCmd())
+ nmCmd.AddCommand(resetCmd())
return nmCmd
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f2682e06/newtmgr/cli/reset.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/reset.go b/newtmgr/cli/reset.go
new file mode 100644
index 0000000..e477b4a
--- /dev/null
+++ b/newtmgr/cli/reset.go
@@ -0,0 +1,82 @@
+/**
+ * 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"
+
+ "github.com/spf13/cobra"
+ "mynewt.apache.org/newt/newtmgr/config"
+ "mynewt.apache.org/newt/newtmgr/protocol"
+ "mynewt.apache.org/newt/newtmgr/transport"
+)
+
+func resetRunCmd(cmd *cobra.Command, args []string) {
+ cpm, err := config.NewConnProfileMgr()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ reset, err := protocol.NewReset()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := reset.EncodeWriteRequest()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if err := runner.WriteReq(nmr); err != nil {
+ nmUsage(cmd, err)
+ }
+
+ _, err = runner.ReadResp()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Println("Done")
+}
+
+func resetCmd() *cobra.Command {
+ resetCmd := &cobra.Command{
+ Use: "reset",
+ Short: "Send reset request to remote endpoint using newtmgr",
+ Run: resetRunCmd,
+ }
+
+ return resetCmd
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f2682e06/newtmgr/protocol/defs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/defs.go b/newtmgr/protocol/defs.go
index efb2a05..1ecb6be 100644
--- a/newtmgr/protocol/defs.go
+++ b/newtmgr/protocol/defs.go
@@ -35,4 +35,5 @@ const (
NMGR_ID_TASKSTATS = 2
NMGR_ID_MPSTATS = 3
NMGR_ID_DATETIME_STR = 4
+ NMGR_ID_RESET = 5
)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f2682e06/newtmgr/protocol/reset.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/reset.go b/newtmgr/protocol/reset.go
new file mode 100644
index 0000000..4676a09
--- /dev/null
+++ b/newtmgr/protocol/reset.go
@@ -0,0 +1,48 @@
+/**
+ * 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
+
+type Reset struct {
+}
+
+func NewReset() (*Reset, error) {
+ r := &Reset{}
+ return r, nil
+}
+
+func (r *Reset) EncodeWriteRequest() (*NmgrReq, error) {
+ msg := "{}"
+
+ data := []byte(msg)
+
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_WRITE
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_DEFAULT
+ nmr.Id = NMGR_ID_RESET
+ nmr.Len = uint16(len(data))
+ nmr.Data = data
+
+ return nmr, nil
+}
[4/6] incubator-mynewt-newt git commit: image;
decode return code coming from target. Report errors for non-zero
codes.
Posted by ma...@apache.org.
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
}
[2/6] incubator-mynewt-newt git commit: newtmgr echo;
print out usage help if user passes no arguments.
Posted by ma...@apache.org.
newtmgr echo; print out usage help if user passes no arguments.
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/c77c2f0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/c77c2f0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/c77c2f0c
Branch: refs/heads/develop
Commit: c77c2f0c20822c9727d0794bfaff53cbf9cda18c
Parents: 1aaf0b0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 14:54:14 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 17:58:40 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/echo.go | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/c77c2f0c/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/echo.go b/newtmgr/cli/echo.go
index 62b08bb..d1ad619 100644
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@ -55,6 +55,9 @@ func echoRunCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
+ if len(args) != 1 {
+ nmUsage(cmd, nil);
+ }
echo.Message = args[0]
nmr, err := echo.EncodeWriteRequest()
[5/6] incubator-mynewt-newt git commit: Support timeouts on newtmgr
connections
Posted by ma...@apache.org.
Support timeouts on newtmgr connections
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/dc7f93f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/dc7f93f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/dc7f93f6
Branch: refs/heads/develop
Commit: dc7f93f6c17bf61a23d37e6c4d16db8fac07e213
Parents: 4943963
Author: spoonofpower <sp...@gmail.com>
Authored: Fri Apr 29 19:00:26 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 18:00:32 2016 -0700
----------------------------------------------------------------------
newtmgr/transport/conn.go | 13 +++++++++++--
newtmgr/transport/connserial.go | 8 +++++---
2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dc7f93f6/newtmgr/transport/conn.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/conn.go b/newtmgr/transport/conn.go
index a774b38..42d22a4 100644
--- a/newtmgr/transport/conn.go
+++ b/newtmgr/transport/conn.go
@@ -21,13 +21,14 @@ package transport
import (
"bytes"
+ "time"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/util"
)
type Conn interface {
- Open(cp config.NewtmgrConnProfile) error
+ Open(cp config.NewtmgrConnProfile, timeout time.Duration) error
ReadPacket() (*Packet, error)
WritePacket(pkt *Packet) error
}
@@ -68,13 +69,21 @@ func (pkt *Packet) TrimEnd(count int) {
}
func NewConn(cp config.NewtmgrConnProfile) (Conn, error) {
+ return newConn(cp, 0)
+}
+
+func NewConnWithTimeout(cp config.NewtmgrConnProfile, readTimeout time.Duration) (Conn, error) {
+ return newConn(cp, readTimeout)
+}
+
+func newConn(cp config.NewtmgrConnProfile, readTimeout time.Duration) (Conn, error) {
// Based on ConnProfile, instantiate the right type of conn object, that
// implements the conn interface.
var c Conn
switch cp.Type() {
case "serial":
c = &ConnSerial{}
- if err := c.Open(cp); err != nil {
+ if err := c.Open(cp, readTimeout); err != nil {
return nil, err
}
default:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dc7f93f6/newtmgr/transport/connserial.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connserial.go b/newtmgr/transport/connserial.go
index b221e77..e9cb9f6 100644
--- a/newtmgr/transport/connserial.go
+++ b/newtmgr/transport/connserial.go
@@ -24,6 +24,7 @@ import (
"encoding/base64"
"encoding/binary"
"fmt"
+ "time"
log "github.com/Sirupsen/logrus"
"github.com/joaojeronimo/go-crc16"
@@ -41,12 +42,13 @@ type ConnSerial struct {
serialChannel *serial.Port
}
-func (cs *ConnSerial) Open(cp config.NewtmgrConnProfile) error {
+func (cs *ConnSerial) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
var err error
c := &serial.Config{
- Name: cp.ConnString(),
- Baud: 115200,
+ Name: cp.ConnString(),
+ Baud: 115200,
+ ReadTimeout: readTimeout,
}
cs.serialChannel, err = serial.OpenPort(c)