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 2017/08/11 18:08:45 UTC

[mynewt-newtmgr] branch master updated: udp_oic_sesn; add UdpOicSesn.PutResourceOnce()

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8803aa3  udp_oic_sesn; add UdpOicSesn.PutResourceOnce()
8803aa3 is described below

commit 8803aa3f8f651a1182aeac2ae40b6ab963832cc0
Author: Marko Kiiskila <ma...@runtime.io>
AuthorDate: Fri Aug 11 11:08:07 2017 -0700

    udp_oic_sesn; add UdpOicSesn.PutResourceOnce()
---
 nmxact/udp/udp_oic_sesn.go | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/nmxact/udp/udp_oic_sesn.go b/nmxact/udp/udp_oic_sesn.go
index 9244048..c6a5400 100644
--- a/nmxact/udp/udp_oic_sesn.go
+++ b/nmxact/udp/udp_oic_sesn.go
@@ -181,5 +181,31 @@ func (uos *UdpOicSesn) PutResourceOnce(resType sesn.ResourceType,
 	uri string, value []byte,
 	opt sesn.TxOptions) (coap.COAPCode, error) {
 
-	return 0, fmt.Errorf("UdpOicSesn.PutResourceOnce() unsupported")
+	token := nmxutil.NextToken()
+
+	ol, err := uos.d.AddOicListener(token)
+	if err != nil {
+		return 0, err
+	}
+	defer uos.d.RemoveOicListener(token)
+
+	req, err := oic.EncodePut(false, uri, token, value)
+	if err != nil {
+		return 0, err
+	}
+
+	if _, err := uos.conn.WriteToUDP(req, uos.addr); err != nil {
+		return 0, err
+	}
+
+	for {
+		select {
+		case err := <-ol.ErrChan:
+			return 0, err
+		case rsp := <-ol.RspChan:
+			return rsp.Code(), nil
+		case <-ol.AfterTimeout(opt.Timeout):
+			return 0, nmxutil.NewRspTimeoutError("OIC timeout")
+		}
+	}
 }

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