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/10/26 22:58:53 UTC

incubator-mynewt-newt git commit: newtmgr oic; decode to even more generic entity. Return error if COAP response code says so.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop ef941d4e8 -> 2ac611b62


newtmgr oic; decode to even more generic entity. Return error if
COAP response code says so.


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

Branch: refs/heads/develop
Commit: 2ac611b6209c1f7111b2f4089f7e216c7fc0d502
Parents: ef941d4
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Oct 26 15:57:06 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Oct 26 15:57:06 2016 -0700

----------------------------------------------------------------------
 newtmgr/protocol/omgr.go | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/2ac611b6/newtmgr/protocol/omgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/omgr.go b/newtmgr/protocol/omgr.go
index a0ab05f..29bff4c 100644
--- a/newtmgr/protocol/omgr.go
+++ b/newtmgr/protocol/omgr.go
@@ -30,8 +30,8 @@ import (
 )
 
 type OicRsp struct {
-	Read  map[string]interface{} `codec:"r"`
-	Write map[string]interface{} `codec:"w"`
+	Read  interface{} `codec:"r"`
+	Write interface{} `codec:"w"`
 }
 
 /*
@@ -46,7 +46,12 @@ func DeserializeOmgrReq(data []byte) (*NmgrReq, error) {
 		return nil, util.NewNewtError(fmt.Sprintf(
 			"Oicmgr request invalid %s", err.Error()))
 	}
-	log.Debugf("Deserialized COAP %+v", req)
+	if req.Code != coap.Created && req.Code != coap.Deleted &&
+		req.Code != coap.Valid && req.Code != coap.Changed &&
+		req.Code != coap.Content {
+		return nil, util.NewNewtError(fmt.Sprintf(
+			"OIC error rsp: %s", req.Code.String()))
+	}
 
 	var rsp OicRsp
 	err = codec.NewDecoderBytes(req.Payload, new(codec.CborHandle)).Decode(&rsp)
@@ -54,17 +59,19 @@ func DeserializeOmgrReq(data []byte) (*NmgrReq, error) {
 		return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming cbor: %s",
 			err.Error()))
 	}
+	log.Debugf("Deserialized response %+v", rsp)
 
 	nmr := &NmgrReq{}
 
 	var ndata []byte = make([]byte, 0)
-	if len(rsp.Read) != 0 {
+
+	if rsp.Read != nil {
 		err = codec.NewEncoderBytes(&ndata,
 			new(codec.CborHandle)).Encode(rsp.Read)
 		nmr.Op = NMGR_OP_READ_RSP
 	} else {
 		err = codec.NewEncoderBytes(&ndata,
-			new(codec.CborHandle)).Encode(rsp.Read)
+			new(codec.CborHandle)).Encode(rsp.Write)
 		nmr.Op = NMGR_OP_WRITE_RSP
 	}
 	if err != nil {