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:22:20 UTC

[11/13] incubator-mynewt-newt git commit: newtmgr; add command to reset the target.

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

Branch: refs/heads/develop
Commit: ee38234cfa556a0b6e3f720264a6a8dd42a03c93
Parents: a9bacbc
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 14:55:38 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 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/ee38234c/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/ee38234c/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/ee38234c/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/ee38234c/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
+}