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/12/13 18:15:43 UTC

[1/4] incubator-mynewt-core git commit: ocf_sample; use cbor_read_flat_attrs() to read in payload from put light request.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 6cf018b5c -> 1a85f14f9


ocf_sample; use cbor_read_flat_attrs() to read in payload from
put light request.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/96953c4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/96953c4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/96953c4d

Branch: refs/heads/develop
Commit: 96953c4dbd1e4501a97a6a756cfc025b4b482c46
Parents: 1361306
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 10:08:45 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 10:15:21 2016 -0800

----------------------------------------------------------------------
 apps/ocf_sample/pkg.yml    |  1 +
 apps/ocf_sample/src/main.c | 54 +++++++++++++++++++++++------------------
 2 files changed, 31 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/96953c4d/apps/ocf_sample/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/pkg.yml b/apps/ocf_sample/pkg.yml
index c18f2eb..7cf3510 100644
--- a/apps/ocf_sample/pkg.yml
+++ b/apps/ocf_sample/pkg.yml
@@ -28,6 +28,7 @@ pkg.deps:
     - kernel/os
     - sys/log
     - net/oic
+    - encoding/cborattr
     - sys/console/full
 
 pkg.deps.OC_TRANSPORT_SERIAL:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/96953c4d/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index bd6d7e1..a68c5ff 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -23,6 +23,7 @@
 #include <bsp/bsp.h>
 #include <log/log.h>
 #include <oic/oc_api.h>
+#include <cborattr/cborattr.h>
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 #include <console/console.h>
 #include <console/prompt.h>
@@ -54,13 +55,13 @@ get_light(oc_request_t *request, oc_interface_mask_t interface)
     printf("GET_light:\n");
     oc_rep_start_root_object();
     switch (interface) {
-        case OC_IF_BASELINE:
-            oc_process_baseline_interface(request->resource);
-        case OC_IF_RW:
-            oc_rep_set_boolean(root, state, light_state);
-            break;
-        default:
-            break;
+    case OC_IF_BASELINE:
+        oc_process_baseline_interface(request->resource);
+    case OC_IF_RW:
+        oc_rep_set_boolean(root, state, light_state);
+        break;
+    default:
+        break;
     }
     oc_rep_end_root_object();
     oc_send_response(request, OC_STATUS_OK);
@@ -70,25 +71,30 @@ get_light(oc_request_t *request, oc_interface_mask_t interface)
 static void
 put_light(oc_request_t *request, oc_interface_mask_t interface)
 {
-    printf("PUT_light:\n");
-    bool state = false;
-    oc_rep_t *rep = request->request_payload;
-    while (rep != NULL) {
-        printf("key: %s ", oc_string(rep->name));
-        switch (rep->type) {
-            case BOOL:
-                state = rep->value_boolean;
-                printf("value: %d\n", state);
-                break;
-            default:
-                oc_send_response(request, OC_STATUS_BAD_REQUEST);
-                return;
-                break;
+    bool state;
+    int len;
+    const uint8_t *data;
+    struct cbor_attr_t attrs[] = {
+        [0] = {
+            .attribute = "state",
+            .type = CborAttrBooleanType,
+            .addr.boolean = &state,
+            .dflt.boolean = false
+        },
+        [1] = {
         }
-        rep = rep->next;
+    };
+
+    printf("PUT_light:\n");
+
+    len = coap_get_payload(request->packet, &data);
+    if (cbor_read_flat_attrs(data, len, attrs)) {
+        oc_send_response(request, OC_STATUS_BAD_REQUEST);
+    } else {
+        printf("value: %d\n", state);
+        light_state = state;
+        oc_send_response(request, OC_STATUS_CHANGED);
     }
-    oc_send_response(request, OC_STATUS_CHANGED);
-    light_state = state;
 }
 
 static void


[2/4] incubator-mynewt-core git commit: cborattr; add helper routine cbor_read_flat_attrs(). This takes as argument pointer to beginning of cbor encoded data, and decodes it into an array of cbor_attr_t's.

Posted by ma...@apache.org.
cborattr; add helper routine cbor_read_flat_attrs().
This takes as argument pointer to beginning of cbor encoded data,
and decodes it into an array of cbor_attr_t's.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/13613065
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/13613065
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/13613065

Branch: refs/heads/develop
Commit: 13613065a2d8e4cbfb7074303a8001e6b6a04027
Parents: c78e39b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 10:07:02 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 10:15:21 2016 -0800

----------------------------------------------------------------------
 encoding/cborattr/include/cborattr/cborattr.h |  2 ++
 encoding/cborattr/src/cborattr.c              | 28 ++++++++++++++++++++++
 2 files changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/13613065/encoding/cborattr/include/cborattr/cborattr.h
----------------------------------------------------------------------
diff --git a/encoding/cborattr/include/cborattr/cborattr.h b/encoding/cborattr/include/cborattr/cborattr.h
index d3ca2fa..d7f0e03 100644
--- a/encoding/cborattr/include/cborattr/cborattr.h
+++ b/encoding/cborattr/include/cborattr/cborattr.h
@@ -121,6 +121,8 @@ struct cbor_attr_t {
 int cbor_read_object(struct CborValue *, const struct cbor_attr_t *);
 int cbor_read_array(struct CborParser *, const struct cbor_array_t *);
 
+int cbor_read_flat_attrs(const uint8_t *data, int len,
+                         const struct cbor_attr_t *attrs);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/13613065/encoding/cborattr/src/cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/src/cborattr.c b/encoding/cborattr/src/cborattr.c
index a7ca9c0..4101646 100644
--- a/encoding/cborattr/src/cborattr.c
+++ b/encoding/cborattr/src/cborattr.c
@@ -19,6 +19,7 @@
 
 #include <cborattr/cborattr.h>
 #include <tinycbor/cbor.h>
+#include <tinycbor/cbor_buf_reader.h>
 
 /* this maps a CborType to a matching CborAtter Type. The mapping is not
  * one-to-one because of signedness of integers
@@ -265,3 +266,30 @@ cbor_read_object(struct CborValue *value, const struct cbor_attr_t *attrs)
     st = cbor_internal_read_object(value, attrs, NULL, 0);
     return st;
 }
+
+/*
+ * Read in cbor key/values from flat buffer pointed by data, and fill them
+ * into attrs.
+ *
+ * @param data		Pointer to beginning of cbor encoded data
+ * @param len		Number of bytes in the buffer
+ * @param attrs		Array of cbor objects to look for.
+ *
+ * @return		0 on success; non-zero on failure.
+ */
+int
+cbor_read_flat_attrs(const uint8_t *data, int len,
+                     const struct cbor_attr_t *attrs)
+{
+    struct cbor_buf_reader reader;
+    struct CborParser parser;
+    struct CborValue value;
+    CborError err;
+
+    cbor_buf_reader_init(&reader, data, len);
+    err = cbor_parser_init(&reader.r, 0, &parser, &value);
+    if (err != CborNoError) {
+        return -1;
+    }
+    return cbor_read_object(&value, attrs);
+}


[4/4] incubator-mynewt-core git commit: oic; surround OIC client only function prototypes with an appropriate #ifdef.

Posted by ma...@apache.org.
oic; surround OIC client only function prototypes with an
appropriate #ifdef.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1a85f14f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1a85f14f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1a85f14f

Branch: refs/heads/develop
Commit: 1a85f14f9f7fad8a6f0b71693dea180a2f2c8129
Parents: 96953c4
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 10:14:09 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 10:15:22 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_api.h          | 2 ++
 net/oic/include/oic/oc_client_state.h | 2 ++
 2 files changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a85f14f/net/oic/include/oic/oc_api.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_api.h b/net/oic/include/oic/oc_api.h
index ca512e4..e7438e7 100644
--- a/net/oic/include/oic/oc_api.h
+++ b/net/oic/include/oic/oc_api.h
@@ -109,6 +109,7 @@ void oc_send_separate_response(oc_separate_response_t *handle,
 
 int oc_notify_observers(oc_resource_t *resource);
 
+#ifdef OC_CLIENT
 /** Client side */
 #include "oc_client_state.h"
 
@@ -136,6 +137,7 @@ bool oc_do_observe(const char *uri, oc_server_handle_t *server,
                    oc_qos_t qos);
 
 bool oc_stop_observe(const char *uri, oc_server_handle_t *server);
+#endif
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a85f14f/net/oic/include/oic/oc_client_state.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_client_state.h b/net/oic/include/oic/oc_client_state.h
index dd6308d..5897117 100644
--- a/net/oic/include/oic/oc_client_state.h
+++ b/net/oic/include/oic/oc_client_state.h
@@ -25,6 +25,7 @@
 extern "C" {
 #endif
 
+#ifdef OC_CLIENT
 typedef enum { HIGH_QOS = 0, LOW_QOS } oc_qos_t;
 
 typedef struct
@@ -88,6 +89,7 @@ oc_discovery_flags_t oc_ri_process_discovery_payload(uint8_t *payload, int len,
 
 bool oc_ri_send_rst(oc_endpoint_t *endpoint, uint8_t *token, uint8_t token_len,
                     uint16_t mid);
+#endif
 
 #ifdef __cplusplus
 }


[3/4] incubator-mynewt-core git commit: oic; remove oc_signal api.

Posted by ma...@apache.org.
oic; remove oc_signal api.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c78e39be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c78e39be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c78e39be

Branch: refs/heads/develop
Commit: c78e39bead61c5f783f38a42bc7a9432de529078
Parents: 6cf018b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Dec 12 14:18:02 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 10:15:21 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_api.h | 30 ++----------------------------
 1 file changed, 2 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c78e39be/net/oic/include/oic/oc_api.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_api.h b/net/oic/include/oic/oc_api.h
index f0c6346..ca512e4 100644
--- a/net/oic/include/oic/oc_api.h
+++ b/net/oic/include/oic/oc_api.h
@@ -19,7 +19,8 @@
 
 #include "../src/port/mynewt/config.h"
 #include "../src/messaging/coap/oc_coap.h"
-#include "oc_ri.h"
+#include "oic/oc_ri.h"
+#include "oic/oc_api.h"
 #include "../src/port/oc_signal_main_loop.h"
 #include "../src/port/oc_storage.h"
 
@@ -136,33 +137,6 @@ bool oc_do_observe(const char *uri, oc_server_handle_t *server,
 
 bool oc_stop_observe(const char *uri, oc_server_handle_t *server);
 
-/** Common operations */
-
-/** API for setting handlers for interrupts */
-
-#define oc_signal_interrupt_handler(name)                                      \
-  do {                                                                         \
-    oc_process_poll(&(name##_interrupt_x));                                    \
-    oc_signal_main_loop();                                                     \
-  } while (0)
-
-#define oc_activate_interrupt_handler(name)                                    \
-  (oc_process_start(&(name##_interrupt_x), 0))
-
-#define oc_define_interrupt_handler(name)                                      \
-  void name##_interrupt_x_handler(void);                                       \
-  OC_PROCESS(name##_interrupt_x, "");                                          \
-  OC_PROCESS_THREAD(name##_interrupt_x, ev, data)                              \
-  {                                                                            \
-    OC_PROCESS_POLLHANDLER(name##_interrupt_x_handler());                      \
-    OC_PROCESS_BEGIN();                                                        \
-    while (oc_process_is_running(&(name##_interrupt_x))) {                     \
-      OC_PROCESS_YIELD();                                                      \
-    }                                                                          \
-    OC_PROCESS_END();                                                          \
-  }                                                                            \
-  void name##_interrupt_x_handler(void)
-
 #ifdef __cplusplus
 }
 #endif