You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/11/14 16:39:07 UTC

[GitHub] rymanluk closed pull request #230: [porting][linux] Add support for BLE Mesh app on linux platform

rymanluk closed pull request #230: [porting][linux] Add support for BLE Mesh app on linux platform
URL: https://github.com/apache/mynewt-nimble/pull/230
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/mesh/src/adv.h b/nimble/host/mesh/src/adv.h
index d37e0d41..8e76e419 100644
--- a/nimble/host/mesh/src/adv.h
+++ b/nimble/host/mesh/src/adv.h
@@ -17,7 +17,7 @@
 #define BT_MESH_ADV_DATA_SIZE 31
 
 /* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
-#define BT_MESH_ADV_USER_DATA_SIZE 4
+#define BT_MESH_ADV_USER_DATA_SIZE (sizeof(struct bt_mesh_adv *))
 
 #define BT_MESH_MBUF_HEADER_SIZE (sizeof(struct os_mbuf_pkthdr) + \
                                     BT_MESH_ADV_USER_DATA_SIZE +\
diff --git a/nimble/host/mesh/src/testing.c b/nimble/host/mesh/src/testing.c
index 096cff63..4a0f1da2 100644
--- a/nimble/host/mesh/src/testing.c
+++ b/nimble/host/mesh/src/testing.c
@@ -97,7 +97,7 @@ void bt_test_print_credentials(void)
 	struct bt_mesh_subnet *sub;
 	struct bt_mesh_app_key *app_key;
 
-	console_printf("IV Index: %08lx\n", bt_mesh.iv_index);
+	console_printf("IV Index: %08lx\n", (long) bt_mesh.iv_index);
 	console_printf("Dev key: %s\n", bt_hex(bt_mesh.dev_key, 16));
 
 	for (i = 0; i < MYNEWT_VAL(BLE_MESH_SUBNET_COUNT); ++i)
@@ -157,7 +157,11 @@ void bt_test_print_credentials(void)
 
 int bt_test_shell_init(void)
 {
+#if MYNEWT_VAL(BLE_MESH_SHELL)
 	return cmd_mesh_init(0, NULL);
+#else
+	return -ENOTSUP;
+#endif
 }
 
 int bt_test_bind_app_key_to_model(struct bt_mesh_model *model, u16_t key_idx, u16_t id)
diff --git a/porting/npl/linux/include/console/console.h b/porting/npl/linux/include/console/console.h
new file mode 100644
index 00000000..ccbfc015
--- /dev/null
+++ b/porting/npl/linux/include/console/console.h
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __CONSOLE_H__
+#define __CONSOLE_H__
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define console_printf(_fmt, ...) printf(_fmt, ##__VA_ARGS__)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONSOLE_H__ */
diff --git a/porting/npl/linux/src/os_callout.c b/porting/npl/linux/src/os_callout.c
index ead7ff1d..2d77c9e1 100644
--- a/porting/npl/linux/src/os_callout.c
+++ b/porting/npl/linux/src/os_callout.c
@@ -130,3 +130,30 @@ ble_npl_callout_get_ticks(struct ble_npl_callout *co)
 {
     return co->c_ticks;
 }
+
+void
+ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
+{
+    co->c_ev.ev_arg = arg;
+}
+
+uint32_t
+ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
+                                ble_npl_time_t now)
+{
+    ble_npl_time_t rt;
+    uint32_t exp;
+
+    struct itimerspec its;
+    timer_gettime(co->c_timer, &its);
+
+    exp = its.it_value.tv_sec * 1000;
+
+    if (exp > now) {
+        rt = exp - now;
+    } else {
+        rt = 0;
+    }
+
+    return rt;
+}
diff --git a/porting/npl/linux/src/os_eventq.cc b/porting/npl/linux/src/os_eventq.cc
index a1459bdf..15ec4ef6 100644
--- a/porting/npl/linux/src/os_eventq.cc
+++ b/porting/npl/linux/src/os_eventq.cc
@@ -46,6 +46,18 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
     evq->q = new wqueue_t();
 }
 
+bool
+ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
+{
+    wqueue_t *q = static_cast<wqueue_t *>(evq->q);
+
+    if (q->size()) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
 int
 ble_npl_eventq_inited(const struct ble_npl_eventq *evq)
 {
@@ -71,8 +83,11 @@ struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq,
     struct ble_npl_event *ev;
     wqueue_t *q = static_cast<wqueue_t *>(evq->q);
 
-    ev = q->get();
-    ev->ev_queued = 0;
+    ev = q->get(tmo);
+
+    if (ev) {
+        ev->ev_queued = 0;
+    }
 
     return ev;
 }
diff --git a/porting/npl/linux/src/os_time.c b/porting/npl/linux/src/os_time.c
index 55cbb61a..3c2e4faa 100644
--- a/porting/npl/linux/src/os_time.c
+++ b/porting/npl/linux/src/os_time.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include "os/os.h"
 
+#include <unistd.h>
 #include <time.h>
 
 /**
@@ -62,3 +63,9 @@ uint32_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
 {
     return ticks;
 }
+
+void
+ble_npl_time_delay(ble_npl_time_t ticks)
+{
+    sleep(ble_npl_time_ticks_to_ms32(ticks)/1000);
+}
diff --git a/porting/npl/linux/src/wqueue.h b/porting/npl/linux/src/wqueue.h
index 8eb23b79..0a1e7cc2 100644
--- a/porting/npl/linux/src/wqueue.h
+++ b/porting/npl/linux/src/wqueue.h
@@ -54,13 +54,21 @@ template <typename T> class wqueue
         pthread_mutex_unlock(&m_mutex);
     }
 
-    T get() {
+    T get(uint32_t tmo) {
         pthread_mutex_lock(&m_mutex);
-        while (m_queue.size() == 0) {
-            pthread_cond_wait(&m_condv, &m_mutex);
+        if (tmo) {
+            while (m_queue.size() == 0) {
+                pthread_cond_wait(&m_condv, &m_mutex);
+            }
         }
-        T item = m_queue.front();
-        m_queue.pop_front();
+
+        T item = NULL;
+
+        if (m_queue.size() != 0) {
+            item = m_queue.front();
+            m_queue.pop_front();
+        }
+
         pthread_mutex_unlock(&m_mutex);
         return item;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services