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/01/20 02:00:19 UTC

incubator-mynewt-larva git commit: Convert console echo setting handler to use json.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master de1d73f80 -> 532b4f24c


Convert console echo setting handler to use json.


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

Branch: refs/heads/master
Commit: 532b4f24cb612a0c40818716dc4837d4b693b150
Parents: de1d73f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Jan 19 16:45:32 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Jan 19 16:46:51 2016 -0800

----------------------------------------------------------------------
 libs/newtmgr/src/newtmgr.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/532b4f24/libs/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/libs/newtmgr/src/newtmgr.c b/libs/newtmgr/src/newtmgr.c
index 8f54040..99ad044 100644
--- a/libs/newtmgr/src/newtmgr.c
+++ b/libs/newtmgr/src/newtmgr.c
@@ -96,24 +96,34 @@ static int
 nmgr_def_console_echo(struct nmgr_hdr *nmr, struct os_mbuf *req,
         uint16_t srcoff, struct nmgr_hdr *rsp_hdr, struct os_mbuf *rsp)
 {
-    uint8_t echo_on;
+    int echo_on = 1;
     int rc;
-
-    if (nmr->nh_len == sizeof(echo_on)) {
-        rc = os_mbuf_copydata(req, srcoff + sizeof(*nmr), sizeof(echo_on),
-          &echo_on);
-        if (rc != 0) {
-            goto err;
-        }
-        if (echo_on) {
-            console_echo(1);
-        } else {
-            console_echo(0);
+    struct json_attr_t attrs[3] = {
+        [0] = {
+            .attribute = "echo",
+            .type = t_integer,
+            .addr.integer = &echo_on,
+            .nodefault = 1
+        },
+        [1] = {
+            .attribute = NULL
         }
+    };
+
+    nmgr_jbuf_setibuf(&nmgr_task_jbuf, req, srcoff + sizeof(*nmr),
+      nmr->nh_len);
+
+    rc = json_read_object(&nmgr_task_jbuf.njb_buf, attrs);
+    if (rc) {
+        return OS_EINVAL;
+    }
+
+    if (echo_on) {
+        console_echo(1);
+    } else {
+        console_echo(0);
     }
     return (0);
-err:
-    return (rc);
 }
 
 int