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:10 UTC
[01/13] incubator-mynewt-newt git commit: Changing logs display
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop cab3a2d4a -> 01f442104
Changing logs display
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/2bd923b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/2bd923b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/2bd923b7
Branch: refs/heads/develop
Commit: 2bd923b7f6fdfb050af4a8b56ddc40d1159effe1
Parents: afc6659
Author: Vipul Rahane <vi...@runtime.io>
Authored: Mon May 9 16:58:40 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/logs.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/2bd923b7/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index ed97060..2f567d8 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -175,9 +175,9 @@ func logsShowCmd(cmd *cobra.Command, args []string) {
fmt.Println("Type:", LogTypeToString(decodedResponse.Logs[j].Type))
for i := 0; i < len(decodedResponse.Logs[j].Entries); i++ {
- fmt.Println(fmt.Sprintf("%+v:> %+v usecs :%s:%s:%s",
- decodedResponse.Logs[j].Entries[i].Index,
+ fmt.Println(fmt.Sprintf("%+v usecs, %+v > %s: %s: %s",
decodedResponse.Logs[j].Entries[i].Timestamp,
+ decodedResponse.Logs[j].Entries[i].Index,
LogModuleToString(decodedResponse.Logs[j].Entries[i].Module),
LoglevelToString(decodedResponse.Logs[j].Entries[i].Level),
decodedResponse.Logs[j].Entries[i].Msg))
[11/13] 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/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
+}
[09/13] incubator-mynewt-newt git commit: Adding Stats List Command
Posted by ma...@apache.org.
Adding Stats List Command
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/4bd61be2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4bd61be2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4bd61be2
Branch: refs/heads/develop
Commit: 4bd61be2f5eee8dde9548f232e82833b7460d3ae
Parents: 4724388
Author: Vipul Rahane <vi...@runtime.io>
Authored: Wed Apr 27 18:38:26 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/stats.go | 57 ++++++++++++++++++++++++++++++++++++++++++
newtmgr/protocol/stats.go | 46 ++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4bd61be2/newtmgr/cli/stats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/stats.go b/newtmgr/cli/stats.go
index 89f1298..6174182 100644
--- a/newtmgr/cli/stats.go
+++ b/newtmgr/cli/stats.go
@@ -28,6 +28,55 @@ import (
"mynewt.apache.org/newt/newtmgr/transport"
)
+func statsListRunCmd(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)
+ }
+
+ slr, err := protocol.NewStatsListReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := slr.Encode()
+ 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)
+ }
+
+ slrsp, err := protocol.DecodeStatsListResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Println(slrsp.List)
+ fmt.Printf("Return Code = %d\n", slrsp.ReturnCode)
+}
+
func statsRunCmd(cmd *cobra.Command, args []string) {
cpm, err := config.NewConnProfileMgr()
if err != nil {
@@ -91,5 +140,13 @@ func statsCmd() *cobra.Command {
Run: statsRunCmd,
}
+ ListCmd := &cobra.Command{
+ Use: "list",
+ Short: "Read list of statistics from a remote endpoint",
+ Run: statsListRunCmd,
+ }
+
+ statsCmd.AddCommand(ListCmd)
+
return statsCmd
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4bd61be2/newtmgr/protocol/stats.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/stats.go b/newtmgr/protocol/stats.go
index b3c9aac..5a08bfc 100644
--- a/newtmgr/protocol/stats.go
+++ b/newtmgr/protocol/stats.go
@@ -28,12 +28,21 @@ import (
const (
STATS_NMGR_OP_READ = 0
+ STATS_NMGR_OP_LIST = 1
)
type StatsReadReq struct {
Name string `json:"name"`
}
+type StatsListReq struct {
+}
+
+type StatsListRsp struct {
+ ReturnCode int `json:"rc"`
+ List []string `json:"stat_list"`
+}
+
type StatsReadRsp struct {
ReturnCode int `json:"rc"`
Name string `json:"name"`
@@ -41,6 +50,12 @@ type StatsReadRsp struct {
Fields map[string]interface{} `json:"fields"`
}
+func NewStatsListReq() (*StatsListReq, error) {
+ s := &StatsListReq{}
+
+ return s, nil
+}
+
func NewStatsReadReq() (*StatsReadReq, error) {
s := &StatsReadReq{}
s.Name = ""
@@ -48,6 +63,37 @@ func NewStatsReadReq() (*StatsReadReq, error) {
return s, nil
}
+func DecodeStatsListResponse(data []byte) (*StatsListRsp, error) {
+ var resp StatsListRsp
+ err := json.Unmarshal(data, &resp)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+
+ return &resp, nil
+}
+
+func (sr *StatsListReq) Encode() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_READ
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_STATS
+ nmr.Id = STATS_NMGR_OP_LIST
+
+ req := &StatsListReq{}
+
+ data, _ := json.Marshal(req)
+ nmr.Data = data
+ nmr.Len = uint16(len(data))
+
+ return nmr, nil
+}
+
func (sr *StatsReadReq) Encode() (*NmgrReq, error) {
nmr, err := NewNmgrReq()
if err != nil {
[03/13] incubator-mynewt-newt git commit: Add logs list support
Posted by ma...@apache.org.
Add logs list support
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/4724388c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4724388c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4724388c
Branch: refs/heads/develop
Commit: 4724388c2420086f14c804daca5899ea50a0ee64
Parents: ee38234
Author: Vipul Rahane <vi...@runtime.io>
Authored: Tue Apr 26 12:23:23 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/logs.go | 57 +++++++++++++++++++++++++++++++++++++++++++
newtmgr/protocol/logs.go | 46 ++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4724388c/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index bd26724..ed97060 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -237,6 +237,55 @@ func logsModuleListCmd(cmd *cobra.Command, args []string) {
}
+func logsListCmd(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)
+ }
+
+ req, err := protocol.NewLogsListReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := req.Encode()
+ 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)
+ }
+
+ decodedResponse, err := protocol.DecodeLogsListResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Println(decodedResponse.List)
+ fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
+}
+
func logsLevelListCmd(cmd *cobra.Command, args []string) {
cpm, err := config.NewConnProfileMgr()
if err != nil {
@@ -371,5 +420,13 @@ func logsCmd() *cobra.Command {
}
logsCmd.AddCommand(levelListCmd)
+
+ ListCmd := &cobra.Command{
+ Use: "log_list",
+ Short: "Log List Command",
+ Run: logsListCmd,
+ }
+
+ logsCmd.AddCommand(ListCmd)
return logsCmd
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4724388c/newtmgr/protocol/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/logs.go b/newtmgr/protocol/logs.go
index 327e79f..c75bc56 100644
--- a/newtmgr/protocol/logs.go
+++ b/newtmgr/protocol/logs.go
@@ -28,6 +28,7 @@ const (
LOGS_NMGR_OP_APPEND = 2
LOGS_NMGR_OP_MODULE_LIST = 3
LOGS_NMGR_OP_LEVEL_LIST = 4
+ LOGS_NMGR_OP_LOGS_LIST = 5
)
type LogsShowReq struct {
@@ -42,6 +43,9 @@ type LogsModuleListReq struct {
type LogsLevelListReq struct {
}
+type LogsListReq struct {
+}
+
type LogEntry struct {
Timestamp int64 `json:"ts"`
Msg string `json:"msg"`
@@ -71,6 +75,11 @@ type LogsLevelListRsp struct {
Map map[string]int `json:"level_map"`
}
+type LogsListRsp struct {
+ ReturnCode int `json:"rc"`
+ List []string `json:"log_list"`
+}
+
func NewLogsShowReq() (*LogsShowReq, error) {
s := &LogsShowReq{}
@@ -89,6 +98,12 @@ func NewLogsLevelListReq() (*LogsLevelListReq, error) {
return s, nil
}
+func NewLogsListReq() (*LogsListReq, error) {
+ s := &LogsListReq{}
+
+ return s, nil
+}
+
func (sr *LogsModuleListReq) Encode() (*NmgrReq, error) {
nmr, err := NewNmgrReq()
if err != nil {
@@ -109,6 +124,37 @@ func (sr *LogsModuleListReq) Encode() (*NmgrReq, error) {
return nmr, nil
}
+func DecodeLogsListResponse(data []byte) (*LogsListRsp, error) {
+ var resp LogsListRsp
+ err := json.Unmarshal(data, &resp)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+
+ return &resp, nil
+}
+
+func (sr *LogsListReq) Encode() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_READ
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_LOGS
+ nmr.Id = LOGS_NMGR_OP_LOGS_LIST
+
+ req := &LogsListReq{}
+
+ data, _ := json.Marshal(req)
+ nmr.Data = data
+ nmr.Len = uint16(len(data))
+
+ return nmr, nil
+}
+
func DecodeLogsLevelListResponse(data []byte) (*LogsLevelListRsp, error) {
var resp LogsLevelListRsp
err := json.Unmarshal(data, &resp)
[04/13] incubator-mynewt-newt git commit: Making changes to Log
protocol handlers
Posted by ma...@apache.org.
Making changes to Log protocol handlers
Making changes to log protocol handlers to understand module_list,
level_list and conditional log responses
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/4e34c081
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4e34c081
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4e34c081
Branch: refs/heads/develop
Commit: 4e34c0817299eb8730e9806319975eef986d264f
Parents: 3960627
Author: Vipul Rahane <vi...@runtime.io>
Authored: Thu Apr 21 18:06:45 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/logs.go | 192 +++++++++++++++++++++++++++++++++++++++---
newtmgr/protocol/logs.go | 119 ++++++++++++++++++++++++--
2 files changed, 293 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4e34c081/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index 390aa28..7b16f62 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -21,6 +21,7 @@ package cli
import (
"fmt"
+ "strconv"
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newtmgr/config"
@@ -29,13 +30,14 @@ import (
)
const (
- DEBUG uint64 = 1
- INFO uint64 = 2
- WARN uint64 = 4
- ERROR uint64 = 8
- CRITICAL uint64 = 10
+ LEVEL_DEBUG uint64 = 0
+ LEVEL_INFO uint64 = 1
+ LEVEL_WARN uint64 = 2
+ LEVEL_ERROR uint64 = 3
+ LEVEL_CRITICAL uint64 = 4
/* Upto 7 custom loglevels */
- PERUSER uint64 = 12
+ LEVEL_PERUSER uint64 = 64
+ LEVEL_MAX uint64 = 255
)
const (
@@ -44,20 +46,54 @@ const (
STORAGE_LOG uint64 = 2
)
+const (
+ MODULE_DEFAULT uint64 = 0
+ MODULE_OS uint64 = 1
+ MODULE_NEWTMGR uint64 = 2
+ MODULE_NIMBLE_CTLR uint64 = 3
+ MODULE_NIMBLE_HOST uint64 = 4
+ MODULE_NFFS uint64 = 5
+ MODULE_PERUSER uint64 = 64
+ MODULE_MAX uint64 = 255
+)
+
+func LogModuleToString(lm uint64) string {
+ s := ""
+ switch lm {
+ case MODULE_DEFAULT:
+ s = "DEFAULT"
+ case MODULE_OS:
+ s = "OS"
+ case MODULE_NEWTMGR:
+ s = "NEWTMGR"
+ case MODULE_NIMBLE_CTLR:
+ s = "NIMBLE_CTLR"
+ case MODULE_NIMBLE_HOST:
+ s = "NIMBLE_HOST"
+ case MODULE_NFFS:
+ s = "NFFS"
+ case MODULE_PERUSER:
+ s = "PERUSER"
+ default:
+ s = "CUSTOM"
+ }
+ return s
+}
+
func LoglevelToString(ll uint64) string {
s := ""
switch ll {
- case DEBUG:
+ case LEVEL_DEBUG:
s = "DEBUG"
- case INFO:
+ case LEVEL_INFO:
s = "INFO"
- case WARN:
+ case LEVEL_WARN:
s = "WARN"
- case ERROR:
+ case LEVEL_ERROR:
s = "ERROR"
- case CRITICAL:
+ case LEVEL_CRITICAL:
s = "CRITICAL"
- case PERUSER:
+ case LEVEL_PERUSER:
s = "PERUSER"
default:
s = "CUSTOM"
@@ -106,6 +142,20 @@ func logsShowCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
+ if len(args) > 0 {
+ req.Name = args[0]
+ if len(args) > 1 {
+ req.Timestamp, err = strconv.ParseInt(args[1], 0, 64)
+ if len(args) > 2 {
+ req.Index, err = strconv.ParseUint(args[2], 0, 64)
+ }
+ }
+
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+ }
+
nmr, err := req.Encode()
if err != nil {
nmUsage(cmd, err)
@@ -131,13 +181,115 @@ func logsShowCmd(cmd *cobra.Command, args []string) {
fmt.Println("Type:", LogTypeToString(decodedResponse.Logs[j].Type))
for i := 0; i < len(decodedResponse.Logs[j].Entries); i++ {
- fmt.Println(fmt.Sprintf("%+v:> %+v usecs :%s: %s",
+ fmt.Println(fmt.Sprintf("%+v:> %+v usecs :%s:%s:%s",
decodedResponse.Logs[j].Entries[i].Index,
decodedResponse.Logs[j].Entries[i].Timestamp,
+ LogModuleToString(decodedResponse.Logs[j].Entries[i].Module),
LoglevelToString(decodedResponse.Logs[j].Entries[i].Level),
decodedResponse.Logs[j].Entries[i].Msg))
}
}
+
+ fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
+}
+
+func logsModuleListCmd(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)
+ }
+
+ req, err := protocol.NewLogsModuleListReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := req.Encode()
+ 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)
+ }
+
+ decodedResponse, err := protocol.DecodeLogsModuleListResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Println(decodedResponse.ModuleList)
+ fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
+
+}
+
+func logsLevelListCmd(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)
+ }
+
+ req, err := protocol.NewLogsLevelListReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := req.Encode()
+ 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)
+ }
+
+ decodedResponse, err := protocol.DecodeLogsLevelListResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Println(decodedResponse.LevelList)
+ fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
}
func logsClearCmd(cmd *cobra.Command, args []string) {
@@ -211,5 +363,19 @@ func logsCmd() *cobra.Command {
}
logsCmd.AddCommand(clearCmd)
+ moduleListCmd := &cobra.Command{
+ Use: "module_list",
+ Short: "Module List Command",
+ Run: logsModuleListCmd,
+ }
+ logsCmd.AddCommand(moduleListCmd)
+
+ levelListCmd := &cobra.Command{
+ Use: "level_list",
+ Short: "Level List Command",
+ Run: logsLevelListCmd,
+ }
+
+ logsCmd.AddCommand(levelListCmd)
return logsCmd
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4e34c081/newtmgr/protocol/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/logs.go b/newtmgr/protocol/logs.go
index 9231350..67f00cd 100644
--- a/newtmgr/protocol/logs.go
+++ b/newtmgr/protocol/logs.go
@@ -23,12 +23,23 @@ import (
)
const (
- LOGS_NMGR_OP_READ = 0
- LOGS_NMGR_OP_CLEAR = 1
- LOGS_NMGR_OP_APPEND = 2
+ LOGS_NMGR_OP_READ = 0
+ LOGS_NMGR_OP_CLEAR = 1
+ LOGS_NMGR_OP_APPEND = 2
+ LOGS_NMGR_OP_MODULE_LIST = 3
+ LOGS_NMGR_OP_LEVEL_LIST = 4
)
type LogsShowReq struct {
+ Name string `json:"log_name"`
+ Timestamp int64 `json:"ts"`
+ Index uint64 `json:"index"`
+}
+
+type LogsModuleListReq struct {
+}
+
+type LogsLevelListReq struct {
}
type LogEntry struct {
@@ -36,6 +47,7 @@ type LogEntry struct {
Msg string `json:"msg"`
Level uint64 `json:"level"`
Index uint64 `json:"index"`
+ Module uint64 `json:"module"`
}
type LogsShowLog struct {
@@ -44,17 +56,111 @@ type LogsShowLog struct {
Entries []LogEntry `json:"entries"`
}
+type LogsModuleList struct {
+ ModuleName string `json:"module_name"`
+ Module uint64 `json:"module"`
+}
+
+type LogsLevelList struct {
+ LevelName string `json:"level_name"`
+ Level uint64 `json:"level"`
+}
+
type LogsShowRsp struct {
ReturnCode int `json:"rc"`
Logs []LogsShowLog `json:"logs"`
}
+type LogsModuleListRsp struct {
+ ReturnCode int `json:"rc"`
+ ModuleList []LogsModuleList `json:"log_module_map"`
+}
+
+type LogsLevelListRsp struct {
+ ReturnCode int `json:"rc"`
+ LevelList []LogsLevelList `json:"log_level_map"`
+}
+
func NewLogsShowReq() (*LogsShowReq, error) {
s := &LogsShowReq{}
return s, nil
}
+func NewLogsModuleListReq() (*LogsModuleListReq, error) {
+ s := &LogsModuleListReq{}
+
+ return s, nil
+}
+
+func NewLogsLevelListReq() (*LogsLevelListReq, error) {
+ s := &LogsLevelListReq{}
+
+ return s, nil
+}
+
+func (sr *LogsModuleListReq) Encode() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_READ
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_LOGS
+ nmr.Id = LOGS_NMGR_OP_MODULE_LIST
+
+ req := &LogsModuleListReq{}
+
+ data, _ := json.Marshal(req)
+ nmr.Data = data
+ nmr.Len = uint16(len(data))
+
+ return nmr, nil
+}
+
+func DecodeLogsLevelListResponse(data []byte) (*LogsLevelListRsp, error) {
+ var resp LogsLevelListRsp
+ err := json.Unmarshal(data, &resp)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+
+ return &resp, nil
+}
+
+func (sr *LogsLevelListReq) Encode() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_READ
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_LOGS
+ nmr.Id = LOGS_NMGR_OP_LEVEL_LIST
+
+ req := &LogsLevelListReq{}
+
+ data, _ := json.Marshal(req)
+ nmr.Data = data
+ nmr.Len = uint16(len(data))
+
+ return nmr, nil
+}
+
+func DecodeLogsModuleListResponse(data []byte) (*LogsModuleListRsp, error) {
+ var resp LogsModuleListRsp
+ err := json.Unmarshal(data, &resp)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+
+ return &resp, nil
+}
+
func (sr *LogsShowReq) Encode() (*NmgrReq, error) {
nmr, err := NewNmgrReq()
if err != nil {
@@ -65,8 +171,11 @@ func (sr *LogsShowReq) Encode() (*NmgrReq, error) {
nmr.Flags = 0
nmr.Group = NMGR_GROUP_ID_LOGS
nmr.Id = LOGS_NMGR_OP_READ
-
- req := &LogsShowReq{}
+ req := &LogsShowReq{
+ Name: sr.Name,
+ Timestamp: sr.Timestamp,
+ Index: sr.Index,
+ }
data, _ := json.Marshal(req)
nmr.Data = data
[08/13] 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/a9bacbcd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a9bacbcd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a9bacbcd
Branch: refs/heads/develop
Commit: a9bacbcd1a9218288513811c3179bce77d75f79a
Parents: f30e50e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 14:54:14 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/echo.go | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a9bacbcd/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/echo.go b/newtmgr/cli/echo.go
index f440cae..d3addc3 100644
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@ -54,6 +54,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()
[06/13] incubator-mynewt-newt git commit: imgmgr;
add boot2/list2 commands which include image hash.
Posted by ma...@apache.org.
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/e5b61950
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/e5b61950
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/e5b61950
Branch: refs/heads/develop
Commit: e5b61950abaf8d6072b663ff9673e051f930cede
Parents: 5c938a5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 11:01:02 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/image.go | 138 +++++++++++++++++++++++++++++++++---
newtmgr/protocol/imageboot2.go | 107 ++++++++++++++++++++++++++++
newtmgr/protocol/imagelist.go | 32 ++++++---
newtmgr/protocol/imagelist2.go | 80 +++++++++++++++++++++
4 files changed, 337 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e5b61950/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 8f4f52b..138eed8 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -25,11 +25,11 @@ import (
"io/ioutil"
"os"
+ "github.com/spf13/cobra"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
"mynewt.apache.org/newt/newtmgr/transport"
"mynewt.apache.org/newt/util"
- "github.com/spf13/cobra"
)
func imageListCmd(cmd *cobra.Command, args []string) {
@@ -45,7 +45,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)
@@ -82,6 +82,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"))
@@ -104,7 +154,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)
@@ -174,7 +224,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)
@@ -209,9 +259,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)
}
}
@@ -243,7 +347,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)
@@ -331,7 +435,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)
@@ -406,11 +510,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)
uploadCmd := &cobra.Command{
Use: "upload",
@@ -426,6 +537,13 @@ func imageCmd() *cobra.Command {
}
imageCmd.AddCommand(bootCmd)
+ boot2Cmd := &cobra.Command{
+ Use: "boot2",
+ Short: "Which image to boot",
+ Run: imageBoot2Cmd,
+ }
+ imageCmd.AddCommand(boot2Cmd)
+
fileUploadCmd := &cobra.Command{
Use: "fileupload",
Short: "Upload file to target",
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e5b61950/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/e5b61950/newtmgr/protocol/imagelist.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagelist.go b/newtmgr/protocol/imagelist.go
index e6e8172..8f28045 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,24 +37,34 @@ 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
)
+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/e5b61950/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
+}
[13/13] incubator-mynewt-newt git commit: This closes #9. Merge
branch 'newtmgr-add' of https://github.com/vrahane/incubator-mynewt-newt into
develop
Posted by ma...@apache.org.
This closes #9.
Merge branch 'newtmgr-add' of https://github.com/vrahane/incubator-mynewt-newt into develop
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/01f44210
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/01f44210
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/01f44210
Branch: refs/heads/develop
Commit: 01f442104b9fb60134f068ec185a5cb3df6381cb
Parents: cab3a2d 2bd923b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 18:19:13 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 18:19:13 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/logs.go | 247 ++++++++++++++++++++++++++++++++++++++---
newtmgr/cli/stats.go | 57 ++++++++++
newtmgr/protocol/logs.go | 155 +++++++++++++++++++++++++-
newtmgr/protocol/stats.go | 46 ++++++++
4 files changed, 485 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/01f44210/newtmgr/cli/stats.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/stats.go
index d7d963b,6174182..714a0bb
--- a/newtmgr/cli/stats.go
+++ b/newtmgr/cli/stats.go
@@@ -25,10 -25,58 +25,59 @@@ import
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
"mynewt.apache.org/newt/newtmgr/transport"
+
+ "github.com/spf13/cobra"
)
+ func statsListRunCmd(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)
+ }
+
+ slr, err := protocol.NewStatsListReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := slr.Encode()
+ 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)
+ }
+
+ slrsp, err := protocol.DecodeStatsListResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Println(slrsp.List)
+ fmt.Printf("Return Code = %d\n", slrsp.ReturnCode)
+ }
+
func statsRunCmd(cmd *cobra.Command, args []string) {
cpm, err := config.NewConnProfileMgr()
if err != nil {
[07/13] incubator-mynewt-newt git commit: newtmgr cli; Go formatting
Posted by ma...@apache.org.
newtmgr cli; 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/f30e50e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f30e50e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f30e50e0
Branch: refs/heads/develop
Commit: f30e50e05e8cd41569c455ec68965cd818507cbe
Parents: e5b6195
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 11:02:11 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/config.go | 2 +-
newtmgr/cli/connprofile.go | 2 +-
newtmgr/cli/echo.go | 2 +-
newtmgr/cli/mpstats.go | 2 +-
newtmgr/cli/stats.go | 2 +-
newtmgr/cli/taskstats.go | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f30e50e0/newtmgr/cli/config.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/config.go b/newtmgr/cli/config.go
index 405eba2..fe9dc68 100644
--- a/newtmgr/cli/config.go
+++ b/newtmgr/cli/config.go
@@ -22,11 +22,11 @@ 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"
"mynewt.apache.org/newt/util"
- "github.com/spf13/cobra"
)
func configRunCmd(cmd *cobra.Command, args []string) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f30e50e0/newtmgr/cli/connprofile.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/connprofile.go b/newtmgr/cli/connprofile.go
index 5035dc1..35a4081 100644
--- a/newtmgr/cli/connprofile.go
+++ b/newtmgr/cli/connprofile.go
@@ -23,9 +23,9 @@ import (
"fmt"
"strings"
+ "github.com/spf13/cobra"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/util"
- "github.com/spf13/cobra"
)
func connProfileAddCmd(cmd *cobra.Command, args []string) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f30e50e0/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/echo.go b/newtmgr/cli/echo.go
index 3f0e104..f440cae 100644
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@ -22,10 +22,10 @@ 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"
- "github.com/spf13/cobra"
)
func echoRunCmd(cmd *cobra.Command, args []string) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f30e50e0/newtmgr/cli/mpstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/mpstats.go b/newtmgr/cli/mpstats.go
index 8a4844a..1109d7e 100644
--- a/newtmgr/cli/mpstats.go
+++ b/newtmgr/cli/mpstats.go
@@ -22,10 +22,10 @@ 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"
- "github.com/spf13/cobra"
)
func mempoolStatsRunCmd(cmd *cobra.Command, args []string) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f30e50e0/newtmgr/cli/stats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/stats.go b/newtmgr/cli/stats.go
index cbfcd5a..89f1298 100644
--- a/newtmgr/cli/stats.go
+++ b/newtmgr/cli/stats.go
@@ -22,10 +22,10 @@ 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"
- "github.com/spf13/cobra"
)
func statsRunCmd(cmd *cobra.Command, args []string) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f30e50e0/newtmgr/cli/taskstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/taskstats.go b/newtmgr/cli/taskstats.go
index c9ec687..06e7d24 100644
--- a/newtmgr/cli/taskstats.go
+++ b/newtmgr/cli/taskstats.go
@@ -22,10 +22,10 @@ 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"
- "github.com/spf13/cobra"
)
func taskStatsRunCmd(cmd *cobra.Command, args []string) {
[12/13] incubator-mynewt-newt git commit: go formatting.
Posted by ma...@apache.org.
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/fd38a988
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/fd38a988
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/fd38a988
Branch: refs/heads/develop
Commit: fd38a988075dc2f1fe4bbe75463f60d78e611fd2
Parents: 4bd61be
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 29 17:50:18 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/echo.go | 2 +-
newtmgr/cli/usage.go | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fd38a988/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/echo.go b/newtmgr/cli/echo.go
index d3addc3..c3512f9 100644
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@ -55,7 +55,7 @@ func echoRunCmd(cmd *cobra.Command, args []string) {
}
if len(args) != 1 {
- nmUsage(cmd, nil);
+ nmUsage(cmd, nil)
}
echo.Message = args[0]
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fd38a988/newtmgr/cli/usage.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/usage.go b/newtmgr/cli/usage.go
index 123b61f..a1d947d 100644
--- a/newtmgr/cli/usage.go
+++ b/newtmgr/cli/usage.go
@@ -23,8 +23,8 @@ import (
"fmt"
"os"
- "mynewt.apache.org/newt/util"
"github.com/spf13/cobra"
+ "mynewt.apache.org/newt/util"
)
func nmUsage(cmd *cobra.Command, err error) {
[10/13] 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/2e875f56
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/2e875f56
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/2e875f56
Branch: refs/heads/develop
Commit: 2e875f565060aa198031b81cc51aeecd4b3e4428
Parents: fd38a98
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 29 17:50:58 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 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/2e875f56/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/2e875f56/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/2e875f56/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/2e875f56/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/2e875f56/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
}
[02/13] 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/afc66594
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/afc66594
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/afc66594
Branch: refs/heads/develop
Commit: afc66594840f77fc8f78b63494ecbe3654cd4317
Parents: 2e875f5
Author: spoonofpower <sp...@gmail.com>
Authored: Fri Apr 29 19:00:26 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 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/afc66594/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/afc66594/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)
[05/13] incubator-mynewt-newt git commit: Changing structures and
removing PERUSER
Posted by ma...@apache.org.
Changing structures and removing PERUSER
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/5c938a59
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/5c938a59
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/5c938a59
Branch: refs/heads/develop
Commit: 5c938a59716978909aab566a27b9bee60df12434
Parents: 4e34c08
Author: Vipul Rahane <vi...@runtime.io>
Authored: Fri Apr 22 19:19:47 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:39:53 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/logs.go | 12 +++---------
newtmgr/protocol/logs.go | 18 ++++--------------
2 files changed, 7 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c938a59/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index 7b16f62..bd26724 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -36,8 +36,7 @@ const (
LEVEL_ERROR uint64 = 3
LEVEL_CRITICAL uint64 = 4
/* Upto 7 custom loglevels */
- LEVEL_PERUSER uint64 = 64
- LEVEL_MAX uint64 = 255
+ LEVEL_MAX uint64 = 255
)
const (
@@ -53,7 +52,6 @@ const (
MODULE_NIMBLE_CTLR uint64 = 3
MODULE_NIMBLE_HOST uint64 = 4
MODULE_NFFS uint64 = 5
- MODULE_PERUSER uint64 = 64
MODULE_MAX uint64 = 255
)
@@ -72,8 +70,6 @@ func LogModuleToString(lm uint64) string {
s = "NIMBLE_HOST"
case MODULE_NFFS:
s = "NFFS"
- case MODULE_PERUSER:
- s = "PERUSER"
default:
s = "CUSTOM"
}
@@ -93,8 +89,6 @@ func LoglevelToString(ll uint64) string {
s = "ERROR"
case LEVEL_CRITICAL:
s = "CRITICAL"
- case LEVEL_PERUSER:
- s = "PERUSER"
default:
s = "CUSTOM"
}
@@ -238,7 +232,7 @@ func logsModuleListCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
- fmt.Println(decodedResponse.ModuleList)
+ fmt.Println(decodedResponse.Map)
fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
}
@@ -288,7 +282,7 @@ func logsLevelListCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
- fmt.Println(decodedResponse.LevelList)
+ fmt.Println(decodedResponse.Map)
fmt.Printf("Return Code = %d\n", decodedResponse.ReturnCode)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c938a59/newtmgr/protocol/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/logs.go b/newtmgr/protocol/logs.go
index 67f00cd..327e79f 100644
--- a/newtmgr/protocol/logs.go
+++ b/newtmgr/protocol/logs.go
@@ -56,29 +56,19 @@ type LogsShowLog struct {
Entries []LogEntry `json:"entries"`
}
-type LogsModuleList struct {
- ModuleName string `json:"module_name"`
- Module uint64 `json:"module"`
-}
-
-type LogsLevelList struct {
- LevelName string `json:"level_name"`
- Level uint64 `json:"level"`
-}
-
type LogsShowRsp struct {
ReturnCode int `json:"rc"`
Logs []LogsShowLog `json:"logs"`
}
type LogsModuleListRsp struct {
- ReturnCode int `json:"rc"`
- ModuleList []LogsModuleList `json:"log_module_map"`
+ ReturnCode int `json:"rc"`
+ Map map[string]int `json:"module_map"`
}
type LogsLevelListRsp struct {
- ReturnCode int `json:"rc"`
- LevelList []LogsLevelList `json:"log_level_map"`
+ ReturnCode int `json:"rc"`
+ Map map[string]int `json:"level_map"`
}
func NewLogsShowReq() (*LogsShowReq, error) {