You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/08/18 02:02:05 UTC

[mynewt-newtmgr] branch master updated (b4c69b4 -> badfa44)

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git.


    from b4c69b4  newtmgr - revendor
     new 8ad49ef  nmxact - Fix incorrect error about unsupported chr
     new 73025e8  nmxact - Fix duplicate notification listener bug.
     new 1af0b3e  newtmgr - Support for CoAP POST and DELETE
     new badfa44  newtmgr - revendor

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 newtmgr/Godeps/Godeps.json                         |  72 +++----
 newtmgr/cli/res.go                                 | 206 +++++++++++++++++----
 .../newtmgr/nmxact/bledefs/bledefs.go              |  10 +
 .../newtmgr/nmxact/nmble/ble_sesn.go               |  55 +++---
 .../mynewt.apache.org/newtmgr/nmxact/nmble/conn.go |  40 ++--
 .../newtmgr/nmxact/nmble/profile.go                |   4 +
 .../newtmgr/nmxact/sesn/sesn_util.go               |   2 +-
 .../mynewt.apache.org/newtmgr/nmxact/xact/res.go   | 101 +++++++++-
 nmxact/bledefs/bledefs.go                          |  10 +
 nmxact/nmble/ble_sesn.go                           |  55 +++---
 nmxact/nmble/conn.go                               |  40 ++--
 nmxact/nmble/profile.go                            |   4 +
 nmxact/sesn/sesn_util.go                           |   2 +-
 nmxact/xact/res.go                                 | 101 +++++++++-
 14 files changed, 528 insertions(+), 174 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@mynewt.apache.org" <co...@mynewt.apache.org>'].

[mynewt-newtmgr] 01/04: nmxact - Fix incorrect error about unsupported chr

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git

commit 8ad49ef51a2862dc35a41fb33970bce5b77df67c
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Aug 17 17:26:00 2017 -0700

    nmxact - Fix incorrect error about unsupported chr
---
 nmxact/nmble/ble_sesn.go | 46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/nmxact/nmble/ble_sesn.go b/nmxact/nmble/ble_sesn.go
index 31a8173..3719750 100644
--- a/nmxact/nmble/ble_sesn.go
+++ b/nmxact/nmble/ble_sesn.go
@@ -110,6 +110,13 @@ func (s *BleSesn) disconnectListen() {
 	}()
 }
 
+func (s *BleSesn) errIfClosed() error {
+	if !s.IsOpen() {
+		return nmxutil.NewSesnClosedError("Attempt to use closed BLE session")
+	}
+	return nil
+}
+
 func (s *BleSesn) getChr(chrId *BleChrId) (*Characteristic, error) {
 	if chrId == nil {
 		return nil, fmt.Errorf("BLE session not configured with required " +
@@ -180,7 +187,7 @@ func (s *BleSesn) notifyListen() {
 func (s *BleSesn) openOnce() (bool, error) {
 	if s.IsOpen() {
 		return false, nmxutil.NewSesnAlreadyOpenError(
-			"Attempt to open an already-open bll session")
+			"Attempt to open an already-open BLE session")
 	}
 
 	if err := s.init(); err != nil {
@@ -290,10 +297,27 @@ func (s *BleSesn) EncodeNmpMsg(m *nmp.NmpMsg) ([]byte, error) {
 	return EncodeMgmtMsg(s.cfg.MgmtProto, m)
 }
 
-// Blocking.
+func (s *BleSesn) MtuIn() int {
+	mtu, _ := MtuIn(s.cfg.MgmtProto, s.conn.AttMtu())
+	return mtu
+}
+
+func (s *BleSesn) MtuOut() int {
+	mtu, _ := MtuOut(s.cfg.MgmtProto, s.conn.AttMtu())
+	return mtu
+}
+
+func (s *BleSesn) ConnInfo() (BleConnDesc, error) {
+	return s.conn.ConnInfo(), nil
+}
+
 func (s *BleSesn) TxNmpOnce(req *nmp.NmpMsg, opt sesn.TxOptions) (
 	nmp.NmpRsp, error) {
 
+	if err := s.errIfClosed(); err != nil {
+		return nil, err
+	}
+
 	chr, err := s.getChr(s.mgmtChrs.NmpReqChr)
 	if err != nil {
 		return nil, err
@@ -306,24 +330,14 @@ func (s *BleSesn) TxNmpOnce(req *nmp.NmpMsg, opt sesn.TxOptions) (
 	return s.txvr.TxNmp(txRaw, req, opt.Timeout)
 }
 
-func (s *BleSesn) MtuIn() int {
-	mtu, _ := MtuIn(s.cfg.MgmtProto, s.conn.AttMtu())
-	return mtu
-}
-
-func (s *BleSesn) MtuOut() int {
-	mtu, _ := MtuOut(s.cfg.MgmtProto, s.conn.AttMtu())
-	return mtu
-}
-
-func (s *BleSesn) ConnInfo() (BleConnDesc, error) {
-	return s.conn.ConnInfo(), nil
-}
-
 func (s *BleSesn) TxCoapOnce(m coap.Message,
 	resType sesn.ResourceType,
 	opt sesn.TxOptions) (coap.COAPCode, []byte, error) {
 
+	if err := s.errIfClosed(); err != nil {
+		return 0, nil, err
+	}
+
 	chrId := ResChrReqIdLookup(s.mgmtChrs, resType)
 	chr, err := s.getChr(chrId)
 	if err != nil {

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-newtmgr] 02/04: nmxact - Fix duplicate notification listener bug.

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git

commit 73025e88977ee642185dbb1cbea283a2af0db0f2
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Aug 17 17:50:05 2017 -0700

    nmxact - Fix duplicate notification listener bug.
---
 nmxact/bledefs/bledefs.go | 10 ++++++++++
 nmxact/nmble/ble_sesn.go  |  9 +++------
 nmxact/nmble/conn.go      | 40 ++++++++++++++++++++--------------------
 nmxact/nmble/profile.go   |  4 ++++
 4 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/nmxact/bledefs/bledefs.go b/nmxact/bledefs/bledefs.go
index e6bb5b9..5538681 100644
--- a/nmxact/bledefs/bledefs.go
+++ b/nmxact/bledefs/bledefs.go
@@ -824,6 +824,16 @@ func (b *BleChrId) String() string {
 	return fmt.Sprintf("s=%s c=%s", b.SvcUuid.String(), b.ChrUuid.String())
 }
 
+func CompareChrIds(a BleChrId, b BleChrId) int {
+	if rc := CompareUuids(a.SvcUuid, b.SvcUuid); rc != 0 {
+		return rc
+	}
+	if rc := CompareUuids(a.ChrUuid, b.ChrUuid); rc != 0 {
+		return rc
+	}
+	return 0
+}
+
 type BleMgmtChrs struct {
 	NmpReqChr       *BleChrId
 	NmpRspChr       *BleChrId
diff --git a/nmxact/nmble/ble_sesn.go b/nmxact/nmble/ble_sesn.go
index 3719750..2355c30 100644
--- a/nmxact/nmble/ble_sesn.go
+++ b/nmxact/nmble/ble_sesn.go
@@ -140,7 +140,7 @@ func (s *BleSesn) createNotifyListener(chrId *BleChrId) (
 		return nil, err
 	}
 
-	return s.conn.ListenForNotifications(chr), nil
+	return s.conn.ListenForNotifications(chr)
 }
 
 func (s *BleSesn) notifyListenOnce(chrId *BleChrId,
@@ -175,13 +175,10 @@ func (s *BleSesn) notifyListenOnce(chrId *BleChrId,
 }
 
 func (s *BleSesn) notifyListen() {
-	s.notifyListenOnce(s.mgmtChrs.NmpRspChr, s.txvr.DispatchNmpRsp)
 	s.notifyListenOnce(s.mgmtChrs.ResUnauthRspChr, s.txvr.DispatchCoap)
 	s.notifyListenOnce(s.mgmtChrs.ResSecureRspChr, s.txvr.DispatchCoap)
-
-	// XXX: Don't listen for public resource responses for now; characteristic
-	// may conflict with newtmgr.
-	//s.notifyListenOnce(s.mgmtChrs.ResPublicRspChr, s.txvr.DispatchCoap)
+	s.notifyListenOnce(s.mgmtChrs.ResPublicRspChr, s.txvr.DispatchCoap)
+	s.notifyListenOnce(s.mgmtChrs.NmpRspChr, s.txvr.DispatchNmpRsp)
 }
 
 func (s *BleSesn) openOnce() (bool, error) {
diff --git a/nmxact/nmble/conn.go b/nmxact/nmble/conn.go
index 5912d3d..40acaa0 100644
--- a/nmxact/nmble/conn.go
+++ b/nmxact/nmble/conn.go
@@ -46,7 +46,7 @@ type Conn struct {
 	// Terminates all go routines.  Gets set to null after disconnect.
 	stopChan chan struct{}
 
-	notifyMap map[*Characteristic][](*NotifyListener)
+	notifyMap map[*Characteristic]*NotifyListener
 
 	// Protects:
 	// * connHandle
@@ -64,7 +64,7 @@ func NewConn(bx *BleXport) *Conn {
 		attMtu:         BLE_ATT_MTU_DFLT,
 		disconnectChan: make(chan error, 1),
 		stopChan:       make(chan struct{}),
-		notifyMap:      map[*Characteristic][](*NotifyListener){},
+		notifyMap:      map[*Characteristic]*NotifyListener{},
 	}
 }
 
@@ -88,12 +88,10 @@ func (c *Conn) initiateShutdown() bool {
 func (c *Conn) abortNotifyListeners(err error) {
 	// No need to lock mutex; this should only be called after all go routines
 	// have terminated.
-	for _, nls := range c.notifyMap {
-		for _, nl := range nls {
-			nl.ErrChan <- err
-			close(nl.NotifyChan)
-			close(nl.ErrChan)
-		}
+	for _, nl := range c.notifyMap {
+		nl.ErrChan <- err
+		close(nl.NotifyChan)
+		close(nl.ErrChan)
 	}
 }
 
@@ -201,19 +199,16 @@ func (c *Conn) rxNotify(msg *BleNotifyRxEvt) {
 		return
 	}
 
-	nls := c.notifyMap[chr]
-	if nls == nil {
+	nl := c.notifyMap[chr]
+	if nl == nil {
 		return
 	}
 
-	n := Notification{
+	nl.NotifyChan <- Notification{
 		Chr:        chr,
 		Data:       msg.Data.Bytes,
 		Indication: msg.Indication,
 	}
-	for _, nl := range nls {
-		nl.NotifyChan <- n
-	}
 }
 
 // Listens for incoming notifications and indications.
@@ -662,17 +657,22 @@ func (c *Conn) Subscribe(chr *Characteristic) error {
 	return c.WriteHandle(dsc.Handle, payload, "subscribe")
 }
 
-func (c *Conn) ListenForNotifications(chr *Characteristic) *NotifyListener {
+func (c *Conn) ListenForNotifications(chr *Characteristic) (
+	*NotifyListener, error) {
+
 	c.mtx.Lock()
 	defer c.mtx.Unlock()
 
-	nl := NewNotifyListener()
-	slice := c.notifyMap[chr]
+	if _, ok := c.notifyMap[chr]; ok {
+		return nil, fmt.Errorf(
+			"Already listening for notifications on characteristic %s",
+			chr.String())
+	}
 
-	slice = append(slice, nl)
-	c.notifyMap[chr] = slice
+	nl := NewNotifyListener()
+	c.notifyMap[chr] = nl
 
-	return nl
+	return nl, nil
 }
 
 func (c *Conn) InitiateSecurity() error {
diff --git a/nmxact/nmble/profile.go b/nmxact/nmble/profile.go
index 0e98740..9db78e9 100644
--- a/nmxact/nmble/profile.go
+++ b/nmxact/nmble/profile.go
@@ -31,6 +31,10 @@ type Profile struct {
 	attrs map[uint16]*Characteristic
 }
 
+func (c *Characteristic) String() string {
+	return c.Uuid.String()
+}
+
 func (c *Characteristic) SubscribeType() BleChrFlags {
 	if c.Properties&BLE_GATT_F_NOTIFY != 0 {
 		return BLE_GATT_F_NOTIFY

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-newtmgr] 04/04: newtmgr - revendor

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git

commit badfa44761ef91da331ce91efe3525de9588edb4
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Aug 17 17:15:05 2017 -0700

    newtmgr - revendor
---
 newtmgr/Godeps/Godeps.json                         |  72 +++++++--------
 .../newtmgr/nmxact/bledefs/bledefs.go              |  10 ++
 .../newtmgr/nmxact/nmble/ble_sesn.go               |  55 ++++++-----
 .../mynewt.apache.org/newtmgr/nmxact/nmble/conn.go |  40 ++++----
 .../newtmgr/nmxact/nmble/profile.go                |   4 +
 .../newtmgr/nmxact/sesn/sesn_util.go               |   2 +-
 .../mynewt.apache.org/newtmgr/nmxact/xact/res.go   | 101 +++++++++++++++++++--
 7 files changed, 199 insertions(+), 85 deletions(-)

diff --git a/newtmgr/Godeps/Godeps.json b/newtmgr/Godeps/Godeps.json
index 9f98425..bb0fef8 100644
--- a/newtmgr/Godeps/Godeps.json
+++ b/newtmgr/Godeps/Godeps.json
@@ -107,93 +107,93 @@
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newt/util",
-			"Comment": "mynewt_1_0_1_tag-26-gd70e83c",
-			"Rev": "d70e83caba3debbd8eff933308d619fe67c51dce"
+			"Comment": "mynewt_1_0_1_tag-32-g84f53dd",
+			"Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newt/util/unixchild",
-			"Comment": "mynewt_1_0_1_tag-26-gd70e83c",
-			"Rev": "d70e83caba3debbd8eff933308d619fe67c51dce"
+			"Comment": "mynewt_1_0_1_tag-32-g84f53dd",
+			"Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newt/viper",
-			"Comment": "mynewt_1_0_1_tag-26-gd70e83c",
-			"Rev": "d70e83caba3debbd8eff933308d619fe67c51dce"
+			"Comment": "mynewt_1_0_1_tag-32-g84f53dd",
+			"Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newt/yaml",
-			"Comment": "mynewt_1_0_1_tag-26-gd70e83c",
-			"Rev": "d70e83caba3debbd8eff933308d619fe67c51dce"
+			"Comment": "mynewt_1_0_1_tag-32-g84f53dd",
+			"Rev": "84f53dd6fa887471393d955a5f179c89c57c95b3"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/adv",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/bledefs",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/mgmt",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmble",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmp",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmserial",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/nmxutil",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/oic",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/omp",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/scan",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/sesn",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/udp",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/xact",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		},
 		{
 			"ImportPath": "mynewt.apache.org/newtmgr/nmxact/xport",
-			"Comment": "mynewt_1_1_0_tag-50-g9bffc58",
-			"Rev": "9bffc58e20c9c5ca399d83899db51a8e7caffd29"
+			"Comment": "mynewt_1_1_0_tag-54-g96f7ef8",
+			"Rev": "96f7ef876d0f42b96f125884a69ad2b2e44c9462"
 		}
 	]
 }
diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go
index e6bb5b9..5538681 100644
--- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go
+++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/bledefs/bledefs.go
@@ -824,6 +824,16 @@ func (b *BleChrId) String() string {
 	return fmt.Sprintf("s=%s c=%s", b.SvcUuid.String(), b.ChrUuid.String())
 }
 
+func CompareChrIds(a BleChrId, b BleChrId) int {
+	if rc := CompareUuids(a.SvcUuid, b.SvcUuid); rc != 0 {
+		return rc
+	}
+	if rc := CompareUuids(a.ChrUuid, b.ChrUuid); rc != 0 {
+		return rc
+	}
+	return 0
+}
+
 type BleMgmtChrs struct {
 	NmpReqChr       *BleChrId
 	NmpRspChr       *BleChrId
diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go
index 31a8173..2355c30 100644
--- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go
+++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/ble_sesn.go
@@ -110,6 +110,13 @@ func (s *BleSesn) disconnectListen() {
 	}()
 }
 
+func (s *BleSesn) errIfClosed() error {
+	if !s.IsOpen() {
+		return nmxutil.NewSesnClosedError("Attempt to use closed BLE session")
+	}
+	return nil
+}
+
 func (s *BleSesn) getChr(chrId *BleChrId) (*Characteristic, error) {
 	if chrId == nil {
 		return nil, fmt.Errorf("BLE session not configured with required " +
@@ -133,7 +140,7 @@ func (s *BleSesn) createNotifyListener(chrId *BleChrId) (
 		return nil, err
 	}
 
-	return s.conn.ListenForNotifications(chr), nil
+	return s.conn.ListenForNotifications(chr)
 }
 
 func (s *BleSesn) notifyListenOnce(chrId *BleChrId,
@@ -168,19 +175,16 @@ func (s *BleSesn) notifyListenOnce(chrId *BleChrId,
 }
 
 func (s *BleSesn) notifyListen() {
-	s.notifyListenOnce(s.mgmtChrs.NmpRspChr, s.txvr.DispatchNmpRsp)
 	s.notifyListenOnce(s.mgmtChrs.ResUnauthRspChr, s.txvr.DispatchCoap)
 	s.notifyListenOnce(s.mgmtChrs.ResSecureRspChr, s.txvr.DispatchCoap)
-
-	// XXX: Don't listen for public resource responses for now; characteristic
-	// may conflict with newtmgr.
-	//s.notifyListenOnce(s.mgmtChrs.ResPublicRspChr, s.txvr.DispatchCoap)
+	s.notifyListenOnce(s.mgmtChrs.ResPublicRspChr, s.txvr.DispatchCoap)
+	s.notifyListenOnce(s.mgmtChrs.NmpRspChr, s.txvr.DispatchNmpRsp)
 }
 
 func (s *BleSesn) openOnce() (bool, error) {
 	if s.IsOpen() {
 		return false, nmxutil.NewSesnAlreadyOpenError(
-			"Attempt to open an already-open bll session")
+			"Attempt to open an already-open BLE session")
 	}
 
 	if err := s.init(); err != nil {
@@ -290,10 +294,27 @@ func (s *BleSesn) EncodeNmpMsg(m *nmp.NmpMsg) ([]byte, error) {
 	return EncodeMgmtMsg(s.cfg.MgmtProto, m)
 }
 
-// Blocking.
+func (s *BleSesn) MtuIn() int {
+	mtu, _ := MtuIn(s.cfg.MgmtProto, s.conn.AttMtu())
+	return mtu
+}
+
+func (s *BleSesn) MtuOut() int {
+	mtu, _ := MtuOut(s.cfg.MgmtProto, s.conn.AttMtu())
+	return mtu
+}
+
+func (s *BleSesn) ConnInfo() (BleConnDesc, error) {
+	return s.conn.ConnInfo(), nil
+}
+
 func (s *BleSesn) TxNmpOnce(req *nmp.NmpMsg, opt sesn.TxOptions) (
 	nmp.NmpRsp, error) {
 
+	if err := s.errIfClosed(); err != nil {
+		return nil, err
+	}
+
 	chr, err := s.getChr(s.mgmtChrs.NmpReqChr)
 	if err != nil {
 		return nil, err
@@ -306,24 +327,14 @@ func (s *BleSesn) TxNmpOnce(req *nmp.NmpMsg, opt sesn.TxOptions) (
 	return s.txvr.TxNmp(txRaw, req, opt.Timeout)
 }
 
-func (s *BleSesn) MtuIn() int {
-	mtu, _ := MtuIn(s.cfg.MgmtProto, s.conn.AttMtu())
-	return mtu
-}
-
-func (s *BleSesn) MtuOut() int {
-	mtu, _ := MtuOut(s.cfg.MgmtProto, s.conn.AttMtu())
-	return mtu
-}
-
-func (s *BleSesn) ConnInfo() (BleConnDesc, error) {
-	return s.conn.ConnInfo(), nil
-}
-
 func (s *BleSesn) TxCoapOnce(m coap.Message,
 	resType sesn.ResourceType,
 	opt sesn.TxOptions) (coap.COAPCode, []byte, error) {
 
+	if err := s.errIfClosed(); err != nil {
+		return 0, nil, err
+	}
+
 	chrId := ResChrReqIdLookup(s.mgmtChrs, resType)
 	chr, err := s.getChr(chrId)
 	if err != nil {
diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go
index 5912d3d..40acaa0 100644
--- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go
+++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/conn.go
@@ -46,7 +46,7 @@ type Conn struct {
 	// Terminates all go routines.  Gets set to null after disconnect.
 	stopChan chan struct{}
 
-	notifyMap map[*Characteristic][](*NotifyListener)
+	notifyMap map[*Characteristic]*NotifyListener
 
 	// Protects:
 	// * connHandle
@@ -64,7 +64,7 @@ func NewConn(bx *BleXport) *Conn {
 		attMtu:         BLE_ATT_MTU_DFLT,
 		disconnectChan: make(chan error, 1),
 		stopChan:       make(chan struct{}),
-		notifyMap:      map[*Characteristic][](*NotifyListener){},
+		notifyMap:      map[*Characteristic]*NotifyListener{},
 	}
 }
 
@@ -88,12 +88,10 @@ func (c *Conn) initiateShutdown() bool {
 func (c *Conn) abortNotifyListeners(err error) {
 	// No need to lock mutex; this should only be called after all go routines
 	// have terminated.
-	for _, nls := range c.notifyMap {
-		for _, nl := range nls {
-			nl.ErrChan <- err
-			close(nl.NotifyChan)
-			close(nl.ErrChan)
-		}
+	for _, nl := range c.notifyMap {
+		nl.ErrChan <- err
+		close(nl.NotifyChan)
+		close(nl.ErrChan)
 	}
 }
 
@@ -201,19 +199,16 @@ func (c *Conn) rxNotify(msg *BleNotifyRxEvt) {
 		return
 	}
 
-	nls := c.notifyMap[chr]
-	if nls == nil {
+	nl := c.notifyMap[chr]
+	if nl == nil {
 		return
 	}
 
-	n := Notification{
+	nl.NotifyChan <- Notification{
 		Chr:        chr,
 		Data:       msg.Data.Bytes,
 		Indication: msg.Indication,
 	}
-	for _, nl := range nls {
-		nl.NotifyChan <- n
-	}
 }
 
 // Listens for incoming notifications and indications.
@@ -662,17 +657,22 @@ func (c *Conn) Subscribe(chr *Characteristic) error {
 	return c.WriteHandle(dsc.Handle, payload, "subscribe")
 }
 
-func (c *Conn) ListenForNotifications(chr *Characteristic) *NotifyListener {
+func (c *Conn) ListenForNotifications(chr *Characteristic) (
+	*NotifyListener, error) {
+
 	c.mtx.Lock()
 	defer c.mtx.Unlock()
 
-	nl := NewNotifyListener()
-	slice := c.notifyMap[chr]
+	if _, ok := c.notifyMap[chr]; ok {
+		return nil, fmt.Errorf(
+			"Already listening for notifications on characteristic %s",
+			chr.String())
+	}
 
-	slice = append(slice, nl)
-	c.notifyMap[chr] = slice
+	nl := NewNotifyListener()
+	c.notifyMap[chr] = nl
 
-	return nl
+	return nl, nil
 }
 
 func (c *Conn) InitiateSecurity() error {
diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go
index 0e98740..9db78e9 100644
--- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go
+++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmble/profile.go
@@ -31,6 +31,10 @@ type Profile struct {
 	attrs map[uint16]*Characteristic
 }
 
+func (c *Characteristic) String() string {
+	return c.Uuid.String()
+}
+
 func (c *Characteristic) SubscribeType() BleChrFlags {
 	if c.Properties&BLE_GATT_F_NOTIFY != 0 {
 		return BLE_GATT_F_NOTIFY
diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go
index f7b38c2..26eec86 100644
--- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go
+++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_util.go
@@ -128,7 +128,7 @@ func PostResource(s Sesn, resType ResourceType, uri string,
 }
 
 func DeleteResource(s Sesn, resType ResourceType, uri string,
-	value []byte, o TxOptions) (coap.COAPCode, []byte, error) {
+	o TxOptions) (coap.COAPCode, []byte, error) {
 
 	return txCoap(func() (coap.COAPCode, []byte, error) {
 		return deleteResourceOnce(s, resType, uri, o)
diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go
index c9fec2f..f54614a 100644
--- a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go
+++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/res.go
@@ -27,8 +27,8 @@ import (
 
 type GetResCmd struct {
 	CmdBase
-	Uri string
-	Typ sesn.ResourceType
+	Path string
+	Typ  sesn.ResourceType
 }
 
 func NewGetResCmd() *GetResCmd {
@@ -55,7 +55,7 @@ func (r *GetResResult) Status() int {
 }
 
 func (c *GetResCmd) Run(s sesn.Sesn) (Result, error) {
-	status, val, err := sesn.GetResource(s, c.Typ, c.Uri, c.TxOptions())
+	status, val, err := sesn.GetResource(s, c.Typ, c.Path, c.TxOptions())
 	if err != nil {
 		return nil, err
 	}
@@ -68,7 +68,7 @@ func (c *GetResCmd) Run(s sesn.Sesn) (Result, error) {
 
 type PutResCmd struct {
 	CmdBase
-	Uri   string
+	Path  string
 	Typ   sesn.ResourceType
 	Value []byte
 }
@@ -89,7 +89,10 @@ func newPutResResult() *PutResResult {
 }
 
 func (r *PutResResult) Status() int {
-	if r.Code == coap.Created || r.Code == coap.Changed || r.Code == coap.Content {
+	if r.Code == coap.Created ||
+		r.Code == coap.Changed ||
+		r.Code == coap.Content {
+
 		return 0
 	} else {
 		return int(r.Code)
@@ -97,7 +100,7 @@ func (r *PutResResult) Status() int {
 }
 
 func (c *PutResCmd) Run(s sesn.Sesn) (Result, error) {
-	status, r, err := sesn.PutResource(s, c.Typ, c.Uri, c.Value, c.TxOptions())
+	status, r, err := sesn.PutResource(s, c.Typ, c.Path, c.Value, c.TxOptions())
 	if err != nil {
 		return nil, err
 	}
@@ -107,3 +110,89 @@ func (c *PutResCmd) Run(s sesn.Sesn) (Result, error) {
 	res.Value = r
 	return res, nil
 }
+
+type PostResCmd struct {
+	CmdBase
+	Path  string
+	Typ   sesn.ResourceType
+	Value []byte
+}
+
+func NewPostResCmd() *PostResCmd {
+	return &PostResCmd{
+		CmdBase: NewCmdBase(),
+	}
+}
+
+type PostResResult struct {
+	Code  coap.COAPCode
+	Value []byte
+}
+
+func newPostResResult() *PostResResult {
+	return &PostResResult{}
+}
+
+func (r *PostResResult) Status() int {
+	if r.Code == coap.Created ||
+		r.Code == coap.Changed ||
+		r.Code == coap.Content {
+
+		return 0
+	} else {
+		return int(r.Code)
+	}
+}
+
+func (c *PostResCmd) Run(s sesn.Sesn) (Result, error) {
+	status, r, err := sesn.PostResource(s, c.Typ, c.Path, c.Value, c.TxOptions())
+	if err != nil {
+		return nil, err
+	}
+
+	res := newPostResResult()
+	res.Code = status
+	res.Value = r
+	return res, nil
+}
+
+type DeleteResCmd struct {
+	CmdBase
+	Path string
+	Typ  sesn.ResourceType
+}
+
+func NewDeleteResCmd() *DeleteResCmd {
+	return &DeleteResCmd{
+		CmdBase: NewCmdBase(),
+	}
+}
+
+type DeleteResResult struct {
+	Code  coap.COAPCode
+	Value []byte
+}
+
+func newDeleteResResult() *DeleteResResult {
+	return &DeleteResResult{}
+}
+
+func (r *DeleteResResult) Status() int {
+	if r.Code == coap.Deleted {
+		return 0
+	} else {
+		return int(r.Code)
+	}
+}
+
+func (c *DeleteResCmd) Run(s sesn.Sesn) (Result, error) {
+	status, val, err := sesn.DeleteResource(s, c.Typ, c.Path, c.TxOptions())
+	if err != nil {
+		return nil, err
+	}
+
+	res := newDeleteResResult()
+	res.Code = status
+	res.Value = val
+	return res, nil
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-newtmgr] 03/04: newtmgr - Support for CoAP POST and DELETE

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git

commit 1af0b3ef25bc69726c0fa7c5309cf21b73f4a430
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Aug 17 18:38:42 2017 -0700

    newtmgr - Support for CoAP POST and DELETE
---
 newtmgr/cli/res.go       | 206 ++++++++++++++++++++++++++++++++++++++---------
 nmxact/sesn/sesn_util.go |   2 +-
 nmxact/xact/res.go       | 101 +++++++++++++++++++++--
 3 files changed, 262 insertions(+), 47 deletions(-)

diff --git a/newtmgr/cli/res.go b/newtmgr/cli/res.go
index 0e1c771..c1fd5a7 100644
--- a/newtmgr/cli/res.go
+++ b/newtmgr/cli/res.go
@@ -51,7 +51,7 @@ func cborValStr(itf interface{}) string {
 		return v
 
 	case []byte:
-		return hex.Dump(v)
+		return strings.TrimSuffix(hex.Dump(v), "\n")
 
 	default:
 		return fmt.Sprintf("%#v", v)
@@ -75,11 +75,44 @@ func extractResKv(params []string) (map[string]interface{}, error) {
 	return m, nil
 }
 
-func resGetRunCmd(s sesn.Sesn, resType sesn.ResourceType, uri string) {
+func resResponseStr(path string, cbor []byte) string {
+	s := path
+
+	m, err := nmxutil.DecodeCborMap(cbor)
+	if err != nil {
+		s += fmt.Sprintf("\n    invalid incoming cbor:\n%s", hex.Dump(cbor))
+	} else if len(m) == 0 {
+		s += "\n    <empty>"
+	} else {
+		for k, v := range m {
+			s += fmt.Sprintf("\n    %s\n%s", k, indent(cborValStr(v), 8))
+		}
+	}
+
+	return s
+}
+
+func resGetCmd(cmd *cobra.Command, args []string) {
+	if len(args) < 2 {
+		nmUsage(cmd, nil)
+	}
+
+	s, err := GetSesn()
+	if err != nil {
+		nmUsage(nil, err)
+	}
+
+	rt, err := sesn.ParseResType(args[0])
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	path := args[1]
+
 	c := xact.NewGetResCmd()
 	c.SetTxOptions(nmutil.TxOptions())
-	c.Uri = uri
-	c.Typ = resType
+	c.Path = path
+	c.Typ = rt
 
 	res, err := c.Run(s)
 	if err != nil {
@@ -93,34 +126,43 @@ func resGetRunCmd(s sesn.Sesn, resType sesn.ResourceType, uri string) {
 		return
 	}
 
-	var valstr string
+	if sres.Value != nil {
+		fmt.Printf("%s\n", resResponseStr(c.Path, sres.Value))
+	}
+}
 
-	m, err := nmxutil.DecodeCborMap(sres.Value)
+func resPutCmd(cmd *cobra.Command, args []string) {
+	if len(args) < 3 {
+		nmUsage(cmd, nil)
+	}
+
+	s, err := GetSesn()
 	if err != nil {
-		valstr = hex.Dump(sres.Value)
-	} else if len(m) == 0 {
-		valstr = "<empty>"
-	} else {
-		for k, v := range m {
-			valstr += fmt.Sprintf("\n    %s\n%s", k, indent(cborValStr(v), 8))
-		}
+		nmUsage(nil, err)
 	}
 
-	fmt.Printf("%s%s\n", uri, valstr)
-}
+	rt, err := sesn.ParseResType(args[0])
+	if err != nil {
+		nmUsage(cmd, err)
+	}
 
-func resPutRunCmd(s sesn.Sesn, resType sesn.ResourceType, uri string,
-	value map[string]interface{}) {
+	path := args[1]
 
-	b, err := nmxutil.EncodeCborMap(value)
+	var m map[string]interface{}
+	m, err = extractResKv(args[2:])
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	b, err := nmxutil.EncodeCborMap(m)
 	if err != nil {
 		nmUsage(nil, util.ChildNewtError(err))
 	}
 
 	c := xact.NewPutResCmd()
 	c.SetTxOptions(nmutil.TxOptions())
-	c.Uri = uri
-	c.Typ = resType
+	c.Path = path
+	c.Typ = rt
 	c.Value = b
 
 	res, err := c.Run(s)
@@ -132,29 +174,68 @@ func resPutRunCmd(s sesn.Sesn, resType sesn.ResourceType, uri string,
 	if sres.Status() != 0 {
 		fmt.Printf("Error: %s (%d)\n",
 			coap.COAPCode(sres.Status()), sres.Status())
-	} else {
-		fmt.Printf("Done\n")
+		return
+	}
+
+	if sres.Value != nil {
+		fmt.Printf("%s\n", resResponseStr(c.Path, sres.Value))
 	}
 }
 
-func resRunCmd(cmd *cobra.Command, args []string) {
-	if len(args) < 2 {
+func resPostCmd(cmd *cobra.Command, args []string) {
+	if len(args) < 3 {
 		nmUsage(cmd, nil)
 	}
 
+	s, err := GetSesn()
+	if err != nil {
+		nmUsage(nil, err)
+	}
+
 	rt, err := sesn.ParseResType(args[0])
 	if err != nil {
 		nmUsage(cmd, err)
 	}
 
-	uri := args[1]
+	path := args[1]
 
 	var m map[string]interface{}
-	if len(args) >= 3 {
-		m, err = extractResKv(args[2:])
-		if err != nil {
-			nmUsage(cmd, err)
-		}
+	m, err = extractResKv(args[2:])
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	b, err := nmxutil.EncodeCborMap(m)
+	if err != nil {
+		nmUsage(nil, util.ChildNewtError(err))
+	}
+
+	c := xact.NewPostResCmd()
+	c.SetTxOptions(nmutil.TxOptions())
+	c.Path = path
+	c.Typ = rt
+	c.Value = b
+
+	res, err := c.Run(s)
+	if err != nil {
+		nmUsage(nil, util.ChildNewtError(err))
+	}
+
+	sres := res.(*xact.PostResResult)
+	if sres.Status() != 0 {
+		fmt.Printf("Error: %s (%d)\n",
+			coap.COAPCode(sres.Status()), sres.Status())
+		return
+	}
+
+	if sres.Value != nil {
+		fmt.Printf("%s\n", resResponseStr(c.Path, sres.Value))
+	}
+}
+
+func resDeleteCmd(cmd *cobra.Command, args []string) {
+	if len(args) < 2 {
+		nmUsage(cmd, nil)
 	}
 
 	s, err := GetSesn()
@@ -162,22 +243,67 @@ func resRunCmd(cmd *cobra.Command, args []string) {
 		nmUsage(nil, err)
 	}
 
-	if m == nil {
-		resGetRunCmd(s, rt, uri)
-	} else {
-		resPutRunCmd(s, rt, uri, m)
+	rt, err := sesn.ParseResType(args[0])
+	if err != nil {
+		nmUsage(cmd, err)
+	}
+
+	path := args[1]
+
+	c := xact.NewDeleteResCmd()
+	c.SetTxOptions(nmutil.TxOptions())
+	c.Path = path
+	c.Typ = rt
+
+	res, err := c.Run(s)
+	if err != nil {
+		nmUsage(nil, util.ChildNewtError(err))
+	}
+
+	sres := res.(*xact.DeleteResResult)
+	if sres.Status() != 0 {
+		fmt.Printf("Error: %s (%d)\n",
+			coap.COAPCode(sres.Status()), sres.Status())
+		return
+	}
+
+	if sres.Value != nil {
+		fmt.Printf("%s\n", resResponseStr(c.Path, sres.Value))
 	}
 }
 
 func resCmd() *cobra.Command {
-	resEx := "   newtmgr -c olimex res public /dev\n"
-
 	resCmd := &cobra.Command{
-		Use:     "res <type> <uri> [k=v] [k=v] [...]",
-		Short:   "Read or write a CoAP resource on a device",
-		Example: resEx,
-		Run:     resRunCmd,
+		Use:   "res",
+		Short: "Access a CoAP resource on a device",
+		Run: func(cmd *cobra.Command, args []string) {
+			cmd.HelpFunc()(cmd, args)
+		},
 	}
 
+	resCmd.AddCommand(&cobra.Command{
+		Use:   "get <type> <path>",
+		Short: "Send a CoAP GET request",
+		Run:   resGetCmd,
+	})
+
+	resCmd.AddCommand(&cobra.Command{
+		Use:   "put <type> <path> <k=v> [k=v] [k=v]",
+		Short: "Send a CoAP PUT request",
+		Run:   resPutCmd,
+	})
+
+	resCmd.AddCommand(&cobra.Command{
+		Use:   "post <type> <path> <k=v> [k=v] [k=v]",
+		Short: "Send a CoAP POST request",
+		Run:   resPostCmd,
+	})
+
+	resCmd.AddCommand(&cobra.Command{
+		Use:   "delete <type> <path>",
+		Short: "Send a CoAP DELETE request",
+		Run:   resDeleteCmd,
+	})
+
 	return resCmd
 }
diff --git a/nmxact/sesn/sesn_util.go b/nmxact/sesn/sesn_util.go
index f7b38c2..26eec86 100644
--- a/nmxact/sesn/sesn_util.go
+++ b/nmxact/sesn/sesn_util.go
@@ -128,7 +128,7 @@ func PostResource(s Sesn, resType ResourceType, uri string,
 }
 
 func DeleteResource(s Sesn, resType ResourceType, uri string,
-	value []byte, o TxOptions) (coap.COAPCode, []byte, error) {
+	o TxOptions) (coap.COAPCode, []byte, error) {
 
 	return txCoap(func() (coap.COAPCode, []byte, error) {
 		return deleteResourceOnce(s, resType, uri, o)
diff --git a/nmxact/xact/res.go b/nmxact/xact/res.go
index c9fec2f..f54614a 100644
--- a/nmxact/xact/res.go
+++ b/nmxact/xact/res.go
@@ -27,8 +27,8 @@ import (
 
 type GetResCmd struct {
 	CmdBase
-	Uri string
-	Typ sesn.ResourceType
+	Path string
+	Typ  sesn.ResourceType
 }
 
 func NewGetResCmd() *GetResCmd {
@@ -55,7 +55,7 @@ func (r *GetResResult) Status() int {
 }
 
 func (c *GetResCmd) Run(s sesn.Sesn) (Result, error) {
-	status, val, err := sesn.GetResource(s, c.Typ, c.Uri, c.TxOptions())
+	status, val, err := sesn.GetResource(s, c.Typ, c.Path, c.TxOptions())
 	if err != nil {
 		return nil, err
 	}
@@ -68,7 +68,7 @@ func (c *GetResCmd) Run(s sesn.Sesn) (Result, error) {
 
 type PutResCmd struct {
 	CmdBase
-	Uri   string
+	Path  string
 	Typ   sesn.ResourceType
 	Value []byte
 }
@@ -89,7 +89,10 @@ func newPutResResult() *PutResResult {
 }
 
 func (r *PutResResult) Status() int {
-	if r.Code == coap.Created || r.Code == coap.Changed || r.Code == coap.Content {
+	if r.Code == coap.Created ||
+		r.Code == coap.Changed ||
+		r.Code == coap.Content {
+
 		return 0
 	} else {
 		return int(r.Code)
@@ -97,7 +100,7 @@ func (r *PutResResult) Status() int {
 }
 
 func (c *PutResCmd) Run(s sesn.Sesn) (Result, error) {
-	status, r, err := sesn.PutResource(s, c.Typ, c.Uri, c.Value, c.TxOptions())
+	status, r, err := sesn.PutResource(s, c.Typ, c.Path, c.Value, c.TxOptions())
 	if err != nil {
 		return nil, err
 	}
@@ -107,3 +110,89 @@ func (c *PutResCmd) Run(s sesn.Sesn) (Result, error) {
 	res.Value = r
 	return res, nil
 }
+
+type PostResCmd struct {
+	CmdBase
+	Path  string
+	Typ   sesn.ResourceType
+	Value []byte
+}
+
+func NewPostResCmd() *PostResCmd {
+	return &PostResCmd{
+		CmdBase: NewCmdBase(),
+	}
+}
+
+type PostResResult struct {
+	Code  coap.COAPCode
+	Value []byte
+}
+
+func newPostResResult() *PostResResult {
+	return &PostResResult{}
+}
+
+func (r *PostResResult) Status() int {
+	if r.Code == coap.Created ||
+		r.Code == coap.Changed ||
+		r.Code == coap.Content {
+
+		return 0
+	} else {
+		return int(r.Code)
+	}
+}
+
+func (c *PostResCmd) Run(s sesn.Sesn) (Result, error) {
+	status, r, err := sesn.PostResource(s, c.Typ, c.Path, c.Value, c.TxOptions())
+	if err != nil {
+		return nil, err
+	}
+
+	res := newPostResResult()
+	res.Code = status
+	res.Value = r
+	return res, nil
+}
+
+type DeleteResCmd struct {
+	CmdBase
+	Path string
+	Typ  sesn.ResourceType
+}
+
+func NewDeleteResCmd() *DeleteResCmd {
+	return &DeleteResCmd{
+		CmdBase: NewCmdBase(),
+	}
+}
+
+type DeleteResResult struct {
+	Code  coap.COAPCode
+	Value []byte
+}
+
+func newDeleteResResult() *DeleteResResult {
+	return &DeleteResResult{}
+}
+
+func (r *DeleteResResult) Status() int {
+	if r.Code == coap.Deleted {
+		return 0
+	} else {
+		return int(r.Code)
+	}
+}
+
+func (c *DeleteResCmd) Run(s sesn.Sesn) (Result, error) {
+	status, val, err := sesn.DeleteResource(s, c.Typ, c.Path, c.TxOptions())
+	if err != nil {
+		return nil, err
+	}
+
+	res := newDeleteResResult()
+	res.Code = status
+	res.Value = val
+	return res, nil
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.