mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [05/15] incubator-mynewt-newt git commit: MYNEWT-489 Changes to newtmgr fragmentation code
Date Wed, 23 Nov 2016 18:52:38 GMT
MYNEWT-489 Changes to newtmgr fragmentation code

- Removing RSP_COMPLETE flag


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

Branch: refs/heads/master
Commit: 3bd109255ee587b02466d5c36c67a5b2c182dce0
Parents: 496fc33
Author: Vipul Rahane <vipulrahane@apache.org>
Authored: Mon Nov 21 13:23:21 2016 -0800
Committer: Vipul Rahane <vipulrahane@apache.org>
Committed: Mon Nov 21 13:24:15 2016 -0800

----------------------------------------------------------------------
 newtmgr/protocol/cmdrunner.go | 41 +++++++++++++++++++++++++-------------
 newtmgr/protocol/nmgr.go      | 10 ----------
 newtmgr/protocol/omgr.go      |  2 +-
 3 files changed, 28 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/3bd10925/newtmgr/protocol/cmdrunner.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/cmdrunner.go b/newtmgr/protocol/cmdrunner.go
index 0c2a151..42d35eb 100644
--- a/newtmgr/protocol/cmdrunner.go
+++ b/newtmgr/protocol/cmdrunner.go
@@ -33,6 +33,11 @@ type CmdRunner struct {
 
 func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
 	var nmr NmgrReq
+	var nmrfrag *NmgrReq
+	var nonmgrhdr bool
+
+	nonmgrhdr = false
+
 	for {
 		pkt, err := cr.Conn.ReadPacket()
 		if err != nil {
@@ -42,23 +47,31 @@ func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
 		bytes := pkt.GetBytes()
 		log.Debugf("Rx packet dump:\n%s", hex.Dump(bytes))
 
-		var nmrfrag *NmgrReq
-		if cr.Conn.GetOICEncoded() == true {
-			nmrfrag, err = DeserializeOmgrReq(bytes)
-		} else {
-			nmrfrag, err = DeserializeNmgrReq(bytes)
-		}
-		if err != nil {
-			return nil, err
-		}
-		if nmrfrag == nil {
-			continue
+		if nonmgrhdr == false {
+			if cr.Conn.GetOICEncoded() == true {
+				nmrfrag, err = DeserializeOmgrReq(bytes)
+			} else {
+				nmrfrag, err = DeserializeNmgrReq(bytes)
+			}
+			if err != nil {
+				return nil, err
+			}
+			if nmrfrag == nil {
+				continue
+			}
 		}
 		if nmrfrag.Op == NMGR_OP_READ_RSP || nmrfrag.Op == NMGR_OP_WRITE_RSP {
-			nmr.Data = append(nmr.Data, nmrfrag.Data...)
-			nmr.Len += nmrfrag.Len
-			if nmrfrag.Flags&NMGR_F_JSON_RSP_COMPLETE == NMGR_F_JSON_RSP_COMPLETE {
+			if nonmgrhdr == false {
+				nmr.Data = append(nmr.Data, nmrfrag.Data...)
+				nmr.Len += uint16(len(nmrfrag.Data))
+			} else {
+				nmr.Data = append(nmr.Data, bytes...)
+				nmr.Len += uint16(len(bytes))
+			}
+			if nmr.Len >= nmrfrag.Len {
 				return &nmr, nil
+			} else {
+				nonmgrhdr = true
 			}
 		}
 	}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/3bd10925/newtmgr/protocol/nmgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/nmgr.go b/newtmgr/protocol/nmgr.go
index df2a3d0..44cfc0c 100644
--- a/newtmgr/protocol/nmgr.go
+++ b/newtmgr/protocol/nmgr.go
@@ -54,10 +54,6 @@ const (
 	NMGR_ERR_ENOENT   = 5
 )
 
-const (
-        NMGR_F_JSON_RSP_COMPLETE = 0x0001
-)
-
 func NewNmgrReq() (*NmgrReq, error) {
 	nmr := &NmgrReq{}
 	nmr.Data = []byte{}
@@ -81,12 +77,6 @@ func DeserializeNmgrReq(data []byte) (*NmgrReq, error) {
 	nmr.Id = uint8(data[7])
 
 	data = data[8:]
-	if int(nmr.Len) != len(data) {
-		return nil, util.NewNewtError(
-			fmt.Sprintf("Newtmgr request length doesn't match data length."+
-				"  Newtmgr length = %d, Data length = %d\n", nmr.Len,
-				len(data)))
-	}
 	nmr.Data = data
 
 	log.Debugf("Deserialized response %+v", nmr)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/3bd10925/newtmgr/protocol/omgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/omgr.go b/newtmgr/protocol/omgr.go
index b417546..8e9b5eb 100644
--- a/newtmgr/protocol/omgr.go
+++ b/newtmgr/protocol/omgr.go
@@ -83,7 +83,7 @@ func DeserializeOmgrReq(data []byte) (*NmgrReq, error) {
 	}
 
 	nmr.Len = uint16(len(ndata))
-	nmr.Flags = NMGR_F_JSON_RSP_COMPLETE
+	nmr.Flags = 0
 	nmr.Group = 0
 	nmr.Seq = 0
 	nmr.Id = 0


Mime
View raw message