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/01/20 02:01:06 UTC

incubator-mynewt-newt git commit: Convert console echo setting handler to use json.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/master 837a3d00b -> 5c2d7525a


Convert console echo setting handler to use json.


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

Branch: refs/heads/master
Commit: 5c2d7525a659a705ebf336fb0fee711a2be9fb4e
Parents: 837a3d0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Jan 19 17:00:38 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Jan 19 17:00:38 2016 -0800

----------------------------------------------------------------------
 newtmgr/newtmgr.go       | 11 ++++-------
 newtmgr/protocol/echo.go | 23 ++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c2d7525/newtmgr/newtmgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/newtmgr.go b/newtmgr/newtmgr.go
index 85bbe14..e5a34bb 100644
--- a/newtmgr/newtmgr.go
+++ b/newtmgr/newtmgr.go
@@ -289,13 +289,12 @@ func imageListCmd(cmd *cobra.Command, args []string) {
 	}
 }
 
-func echoCtrl(runner *protocol.CmdRunner, on int) error {
-	echo := string(on)
+func echoCtrl(runner *protocol.CmdRunner, echoOn string) error {
 	echoCtrl, err := protocol.NewEcho()
 	if err != nil {
 		return err
 	}
-	echoCtrl.Message = echo
+	echoCtrl.Message = echoOn
 
 	nmr, err := echoCtrl.EncodeEchoCtrl()
 	if err != nil {
@@ -342,12 +341,10 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
 	if err != nil {
 		nmUsage(cmd, err)
 	}
-
-	err = echoCtrl(runner, 0)
+	err = echoCtrl(runner, "0")
 	if err != nil {
 		nmUsage(cmd, err)
 	}
-
 	var currOff uint32 = 0
 	imageSz := uint32(len(imageFile))
 
@@ -386,7 +383,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
 		currOff = ersp.Offset
 		fmt.Println(currOff)
 	}
-	err = echoCtrl(runner, 1)
+	err = echoCtrl(runner, "1")
 	if err != nil {
 		nmUsage(cmd, err)
 	}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c2d7525/newtmgr/protocol/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/echo.go b/newtmgr/protocol/echo.go
index 43c2527..8e544d6 100644
--- a/newtmgr/protocol/echo.go
+++ b/newtmgr/protocol/echo.go
@@ -15,6 +15,14 @@
 
 package protocol
 
+import (
+	"encoding/json"
+	"fmt"
+	"strconv"
+
+	"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/util"
+)
+
 type Echo struct {
 	Message string
 }
@@ -52,7 +60,18 @@ func (e *Echo) EncodeWriteRequest() (*NmgrReq, error) {
 }
 
 func (e *Echo) EncodeEchoCtrl() (*NmgrReq, error) {
-	data := []byte(e.Message)
+	type SerialEchoCtl struct {
+		Echo int `json:"echo"`
+	}
+
+	integer, err := strconv.Atoi(e.Message)
+	if err != nil {
+		return nil, util.NewNewtError(fmt.Sprintf("Invalid echo ctrl setting %s",
+			err.Error()))
+	}
+	echoCtl := &SerialEchoCtl{
+		Echo: integer,
+	}
 
 	nmr, err := NewNmgrReq()
 	if err != nil {
@@ -63,6 +82,8 @@ func (e *Echo) EncodeEchoCtrl() (*NmgrReq, error) {
 	nmr.Flags = 0
 	nmr.Group = NMGR_GROUP_ID_DEFAULT
 	nmr.Id = NMGR_ID_CONS_ECHO_CTRL
+
+	data, _ := json.Marshal(echoCtl)
 	nmr.Len = uint16(len(data))
 	nmr.Data = data