You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by pa...@apache.org on 2016/09/26 22:14:46 UTC
[1/6] incubator-mynewt-core git commit: finished serial server
example for ocf
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 8999db3dc -> b98fe7095
finished serial server example for ocf
To replicate, create two targets
targets/ocf_server_ser
app=@apache-mynewt-core/apps/ocf_sample
bsp=@apache-mynewt-core/hw/bsp/native
build_profile=debug
cflags=-DOC_SERVER -DOC_TRANSPORT_SERIAL
targets/ocf_client_ser
app=@apache-mynewt-core/apps/ocf_sample
bsp=@apache-mynewt-core/hw/bsp/native
build_profile=debug
cflags=-DOC_CLIENT -DOC_TRANSPORT_SERIAL
Run them (via the debugger) and use socat to connect their serial ports
socat -x /dev/ttys004,raw,echo=0 /dev/ttys006,raw,echo=0
You should see the client discover the server and then request obsevations on the client.
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/f5df33ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f5df33ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f5df33ce
Branch: refs/heads/develop
Commit: f5df33ce1bd069c72431342ed096a6415ad06f1a
Parents: 8999db3
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Wed Sep 21 16:56:45 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Mon Sep 26 10:40:17 2016 -0700
----------------------------------------------------------------------
apps/ocf_sample/src/main.c | 8 +++++++-
libs/console/full/include/console/prompt.h | 2 ++
libs/console/full/src/cons_tty.c | 1 +
libs/console/full/src/prompt.c | 10 +++++++++-
libs/iotivity/src/port/mynewt/serial_adaptor.c | 16 ++++++++++++----
5 files changed, 31 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index 78846d2..ebe9988 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -20,6 +20,7 @@
#include <os/os.h>
#include <bsp/bsp.h>
#include <console/console.h>
+#include <console/prompt.h>
#include <shell/shell.h>
#include <log/log.h>
@@ -29,7 +30,7 @@
/* Shell */
#define SHELL_TASK_PRIO (8)
-#define SHELL_MAX_INPUT_LEN (256)
+#define SHELL_MAX_INPUT_LEN (512)
#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
@@ -286,6 +287,11 @@ main(int argc, char **argv)
rc = os_msys_register(&default_mbuf_pool);
assert(rc == 0);
+#ifdef OC_TRANSPORT_SERIAL
+ console_echo(0);
+ console_no_prompt();
+#endif
+
/* Init tasks */
rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
SHELL_MAX_INPUT_LEN);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/console/full/include/console/prompt.h
----------------------------------------------------------------------
diff --git a/libs/console/full/include/console/prompt.h b/libs/console/full/include/console/prompt.h
index f930879..849ec7e 100644
--- a/libs/console/full/include/console/prompt.h
+++ b/libs/console/full/include/console/prompt.h
@@ -28,4 +28,6 @@ void console_print_prompt();
/* set the console prompt character */
void console_set_prompt(char);
+void console_no_prompt(void);
+
#endif /* __CONSOLE_PROMPT_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index db8c88e..412f93c 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -282,6 +282,7 @@ console_rx_char(void *arg, uint8_t data)
/* echo */
switch (data) {
case '\r':
+ break;
case '\n':
/*
* linefeed
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/console/full/src/prompt.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/prompt.c b/libs/console/full/src/prompt.c
index 5a811bf..3806310 100644
--- a/libs/console/full/src/prompt.c
+++ b/libs/console/full/src/prompt.c
@@ -23,18 +23,26 @@
/* console prompt, always followed by a space */
static char console_prompt[] = " > ";
+static char do_prompt = 1;
/* set the prompt character, leave the space */
void
console_set_prompt(char p)
{
+ do_prompt = 1;
console_prompt[1] = p;
}
+void console_no_prompt(void) {
+ do_prompt = 0;
+}
+
/* print the prompt to the console */
void
console_print_prompt(void)
{
- console_printf("%s", console_prompt);
+ if (do_prompt) {
+ console_printf("%s", console_prompt);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5df33ce/libs/iotivity/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/serial_adaptor.c b/libs/iotivity/src/port/mynewt/serial_adaptor.c
index ddca3bb..7fa94b3 100644
--- a/libs/iotivity/src/port/mynewt/serial_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/serial_adaptor.c
@@ -54,6 +54,7 @@ oc_connectivity_init_serial(void) {
}
/* override the eventq type */
oc_serial_mqueue.mq_ev.ev_type = OC_ADATOR_EVENT_SERIAL;
+ return 0;
err:
oc_connectivity_shutdown_serial();
@@ -68,25 +69,27 @@ void oc_send_buffer_serial(oc_message_t *message) {
/* get a packet header */
m = os_msys_get_pkthdr(0, 0);
if (m == NULL) {
+ ERROR("oc_transport_serial: No mbuf available\n");
goto err;
}
/* add this data to the mbuf */
rc = os_mbuf_append(m, message->data, message->length);
if (rc != 0) {
+ ERROR("oc_transport_serial: could not append data \n");
goto err;
}
/* send over the shell output */
rc = shell_nlip_output(m);
if (rc != 0) {
+ ERROR("oc_transport_serial: nlip output failed \n");
goto err;
}
- return;
+ LOG("oc_transport_serial: send buffer %lu\n", message->length);
- err:
- ERROR("Unable to send message via oc_serial %d\n", rc);
+err:
oc_message_unref(message);
return;
@@ -103,8 +106,13 @@ oc_attempt_rx_serial(void) {
/* get an mbuf from the queue */
m = os_mqueue_get(&oc_serial_mqueue);
+ if (NULL == m) {
+ ERROR("oc_transport_serial: Woke for for receive but found no mbufs\n");
+ goto rx_attempt_err;
+ }
if (!OS_MBUF_IS_PKTHDR(m)) {
+ ERROR("oc_transport_serial: received mbuf that wasn't a packet header\n");
goto rx_attempt_err;
}
@@ -150,4 +158,4 @@ rx_attempt_err:
return NULL;
}
-#endif
\ No newline at end of file
+#endif
[6/6] incubator-mynewt-core git commit: refactor iotivity to match
new sysconfig interfaces. retested serial, IP,
and gatt server. gat client is still not working
Posted by pa...@apache.org.
refactor iotivity to match new sysconfig interfaces.
retested serial, IP, and gatt server. gat client is still not working
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/b98fe709
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b98fe709
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b98fe709
Branch: refs/heads/develop
Commit: b98fe70953d6fc68d06da8c861d17d2ff720b578
Parents: 5b51d6b
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Mon Sep 26 15:13:47 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Mon Sep 26 15:13:47 2016 -0700
----------------------------------------------------------------------
apps/ocf_sample/pkg.yml | 23 +--
apps/ocf_sample/src/main.c | 163 ++++----------------
libs/console/full/pkg.yml | 8 +
libs/console/full/src/cons_tty.c | 2 +
libs/console/full/src/prompt.c | 3 +-
libs/iotivity/include/iotivity/oc_api.h | 1 +
libs/iotivity/include/iotivity/oc_gatt.h | 2 +-
libs/iotivity/pkg.yml | 40 ++++-
libs/iotivity/src/port/mynewt/adaptor.c | 39 ++---
libs/iotivity/src/port/mynewt/adaptor.h | 6 +-
libs/iotivity/src/port/mynewt/ble_adaptor.c | 38 ++---
libs/iotivity/src/port/mynewt/config.h | 18 ++-
libs/iotivity/src/port/mynewt/ip_adaptor.c | 14 +-
libs/iotivity/src/port/mynewt/serial_adaptor.c | 4 +-
14 files changed, 157 insertions(+), 204 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/apps/ocf_sample/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/pkg.yml b/apps/ocf_sample/pkg.yml
index bf9b362..3abca7e 100644
--- a/apps/ocf_sample/pkg.yml
+++ b/apps/ocf_sample/pkg.yml
@@ -25,23 +25,16 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.deps:
- - libs/console/full
- libs/os
- - libs/shell
- libs/util
- sys/log
- libs/iotivity
- - "@apache-mynewt-core/net/nimble/host"
- - "@apache-mynewt-core/net/nimble/controller"
- - "@apache-mynewt-core/net/nimble/transport/ram"
- - "@apache-mynewt-core/net/nimble/host/store/ram"
- - "@apache-mynewt-core/net/nimble/host/services/gap"
- - "@apache-mynewt-core/net/nimble/host/services/gatt"
-# this tells the library that you intend to suppor the server functionality
-pkg.cflags:
-#-DOC_SERVER -- build the server examples
-#-DOC_CLIENT -- build the client examples
-#-DOC_TRANSPORT_GATT -- to send COAP over GATT
-#-DOC_TRANSPORT_SERIAL -- to send COAP over serial
-#-DOC_TRANSPORT_IP -- to send COAP over IP ��
\ No newline at end of file
+pkg.deps.OC_TRANSPORT_SERIAL:
+ - libs/shell
+ - libs/console/full
+
+pkg.deps.OC_TRANSPORT_GATT:
+ - net/nimble/controller
+ - net/nimble/transport/ram
+ - net/nimble/host/store/ram
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index e767dce..948408b 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -19,82 +19,40 @@
#include <assert.h>
#include <os/os.h>
#include <bsp/bsp.h>
-#include <console/console.h>
-#include <console/prompt.h>
-#include <shell/shell.h>
#include <log/log.h>
#include <hal/hal_cputime.h>
#include <iotivity/oc_api.h>
+
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+#include <console/console.h>
+#include <console/prompt.h>
+#include <shell/shell.h>
+#endif
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
#include "mn_socket/mn_socket.h"
#include "mn_socket/arch/sim/native_sock.h"
+#endif
-#ifdef OC_TRANSPORT_GATT
-
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
#include <iotivity/oc_gatt.h>
-
-/* BLE */
#include "nimble/ble.h"
#include "host/ble_hs.h"
-#include "host/ble_hs_adv.h"
-#include "host/ble_uuid.h"
-#include "host/ble_att.h"
-#include "host/ble_gap.h"
-#include "host/ble_gatt.h"
-#include "host/ble_l2cap.h"
-#include "host/ble_sm.h"
#include "controller/ble_ll.h"
-
-/* RAM HCI transport. */
-#include "transport/ram/ble_hci_ram.h"
-
-/* RAM persistence layer. */
-#include "store/ram/ble_store_ram.h"
-
-/* Mandatory services. */
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
-
-uint8_t g_random_addr[6] = {6,5,4,3,2,1};
-uint8_t g_dev_addr[6] = {1,2,3,4,5,6};
-
-/** Priority of the nimble host and controller tasks. */
-#define BLE_LL_TASK_PRI (OS_TASK_PRI_HIGHEST)
-
-#endif
-
-/* Shell */
-#ifdef OC_TRANSPORT_SERIAL
-#define SHELL_TASK_PRIO (8)
-#define SHELL_MAX_INPUT_LEN (512)
-#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
-static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
#endif
#define OCF_TASK_PRIO (8)
-#define OCF_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
+#define OCF_TASK_STACK_SIZE (OS_STACK_ALIGN(512))
static os_stack_t ocf_stack[OCF_TASK_STACK_SIZE];
struct os_task ocf_task;
-#ifdef OC_TRANSPORT_GATT
-#define MBUF_PAYLOAD_SIZE BLE_MBUF_PAYLOAD_SIZE
-#else
-#define MBUF_PAYLOAD_SIZE 128
-#endif
-
-#define DEFAULT_MBUF_MPOOL_BUF_LEN OS_ALIGN(MBUF_PAYLOAD_SIZE, 4)
-#define DEFAULT_MBUF_MPOOL_NBUFS (12)
-
-static uint8_t default_mbuf_mpool_data[DEFAULT_MBUF_MPOOL_BUF_LEN *
- DEFAULT_MBUF_MPOOL_NBUFS];
-
-static struct os_mbuf_pool default_mbuf_pool;
-static struct os_mempool default_mbuf_mpool;
-
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
static void issue_requests(void);
#endif
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
static bool light_state = false;
static void
@@ -156,7 +114,7 @@ register_resources(void)
}
#endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
#define MAX_URI_LENGTH (30)
static char light_1[MAX_URI_LENGTH];
static oc_server_handle_t light_server;
@@ -245,29 +203,27 @@ issue_requests(void)
{
oc_do_ip_discovery("oic.r.light", &discovery);
}
-
#endif
static void
app_init(void)
{
oc_init_platform("Mynewt", NULL, NULL);
-#ifdef OC_CLIENT
- oc_add_device("/oic/d", "oic.d.phone", "MynewtClient", "1.0", "1.0",
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+ oc_add_device("/oic/d", "oic.d.light", "MynewtClient", "1.0", "1.0",
set_device_custom_property, NULL);
#endif
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
oc_add_device("/oic/d", "oic.d.light", "MynewtServer", "1.0", "1.0", NULL, NULL);
#endif
}
-
oc_handler_t ocf_handler = {.init = app_init,
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
.register_resources = register_resources,
#endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
.requests_entry = issue_requests,
#endif
};
@@ -309,14 +265,14 @@ ocf_task_init(void) {
oc_main_init(&ocf_handler);
}
+static const uint8_t addr[6] = {1,2,3,4,5,6};
+
int
main(int argc, char **argv)
{
int rc;
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
struct os_eventq *ev;
- struct ble_hci_ram_cfg hci_cfg;
- struct ble_hs_cfg cfg;
#endif
/* Initialize OS */
os_init();
@@ -325,86 +281,27 @@ main(int argc, char **argv)
rc = cputime_init(1000000);
assert(rc == 0);
-
- rc = os_mempool_init(&default_mbuf_mpool, DEFAULT_MBUF_MPOOL_NBUFS,
- DEFAULT_MBUF_MPOOL_BUF_LEN, default_mbuf_mpool_data,
- "default_mbuf_data");
- assert(rc == 0);
-
- rc = os_mbuf_pool_init(&default_mbuf_pool, &default_mbuf_mpool,
- DEFAULT_MBUF_MPOOL_BUF_LEN, DEFAULT_MBUF_MPOOL_NBUFS);
- assert(rc == 0);
-
- rc = os_msys_register(&default_mbuf_pool);
- assert(rc == 0);
-
-#ifdef OC_TRANSPORT_SERIAL
- console_echo(0);
- console_no_prompt();
-
- /* Init tasks */
- rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
- SHELL_MAX_INPUT_LEN);
- assert(rc == 0);
-#else
- console_init(NULL);
-#endif
-
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
rc = native_sock_init();
assert(rc == 0);
#endif
-#ifdef OC_TRANSPORT_GATT
- /* Initialize the BLE LL */
- rc = ble_ll_init(BLE_LL_TASK_PRI, DEFAULT_MBUF_MPOOL_NBUFS,
- DEFAULT_MBUF_MPOOL_BUF_LEN - BLE_HCI_DATA_HDR_SZ);
- assert(rc == 0);
-
- /* Initialize the RAM HCI transport. */
- hci_cfg = ble_hci_ram_cfg_dflt;
- rc = ble_hci_ram_init(&hci_cfg);
- assert(rc == 0);
-
- /* Initialize the BLE host. */
- cfg = ble_hs_cfg_dflt;
- cfg.max_hci_bufs = hci_cfg.num_evt_hi_bufs + hci_cfg.num_evt_lo_bufs;
- cfg.max_connections = 1;
- cfg.max_gattc_procs = 2;
- cfg.max_l2cap_chans = 3;
- cfg.max_l2cap_sig_procs = 1;
- cfg.sm_bonding = 1;
- cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
- cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
- cfg.sync_cb = NULL; /* TODO */
- cfg.store_read_cb = ble_store_ram_read;
- cfg.store_write_cb = ble_store_ram_write;
-
- /* Populate config with the required GATT server settings. */
- cfg.max_attrs = 0;
- cfg.max_services = 0;
- cfg.max_client_configs = 0;
-
- rc = ble_svc_gap_init(&cfg);
- assert(rc == 0);
-
- rc = ble_svc_gatt_init(&cfg);
- assert(rc == 0);
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
+ memcpy(g_dev_addr, addr, sizeof(g_dev_addr));
/* COAP Gatt server initialization */
- rc = ble_coap_gatt_srv_init(&cfg, &ev);
+ rc = ble_coap_gatt_srv_init(&ev);
assert(rc == 0);
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
/* TODO INIT CLIENT */
#endif
-
- rc = ble_hs_init(ev, &cfg);
- assert(rc == 0);
-
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("Mynewt_OCF");
assert(rc == 0);
+
+ /* Initialize the BLE host. */
+ ble_hs_cfg.parent_evq = ev;
#endif
ocf_task_init();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/console/full/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/console/full/pkg.yml b/libs/console/full/pkg.yml
index cf0e2d2..f7b895f 100644
--- a/libs/console/full/pkg.yml
+++ b/libs/console/full/pkg.yml
@@ -31,3 +31,11 @@ pkg.apis: console
pkg.init_function: console_pkg_init
pkg.init_stage: 0
+
+pkg.syscfg_defs:
+ CONSOLE_PROMPT:
+ description: 'Default console prompt '
+ value: '0'
+ CONSOLE_ECHO:
+ description: 'Default console echo '
+ value: '0'
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index f420c2a..0b4fab4 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -19,6 +19,7 @@
#include <inttypes.h>
#include <assert.h>
+#include "syscfg/syscfg.h"
#include "sysinit/sysinit.h"
#include "os/os.h"
#include "uart/uart.h"
@@ -404,6 +405,7 @@ console_init(console_rx_cb rx_cb)
if (!ct->ct_dev) {
return -1;
}
+ ct->ct_echo_off = ! MYNEWT_VAL(CONSOLE_ECHO);
}
console_print_prompt();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/console/full/src/prompt.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/prompt.c b/libs/console/full/src/prompt.c
index 3806310..33e37c0 100644
--- a/libs/console/full/src/prompt.c
+++ b/libs/console/full/src/prompt.c
@@ -20,10 +20,11 @@
#include "console/console.h"
#include "console/prompt.h"
+#include <syscfg/syscfg.h>
/* console prompt, always followed by a space */
static char console_prompt[] = " > ";
-static char do_prompt = 1;
+static char do_prompt = MYNEWT_VAL(CONSOLE_PROMPT);
/* set the prompt character, leave the space */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/include/iotivity/oc_api.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_api.h b/libs/iotivity/include/iotivity/oc_api.h
index ce83b64..31eb3c2 100644
--- a/libs/iotivity/include/iotivity/oc_api.h
+++ b/libs/iotivity/include/iotivity/oc_api.h
@@ -17,6 +17,7 @@
#ifndef OC_API_H
#define OC_API_H
+#include "../src/port/mynewt/config.h"
#include "../src/messaging/coap/oc_coap.h"
#include "oc_ri.h"
#include "../src/port/oc_signal_main_loop.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/include/iotivity/oc_gatt.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_gatt.h b/libs/iotivity/include/iotivity/oc_gatt.h
index 0cb48a8..ae6c59c 100644
--- a/libs/iotivity/include/iotivity/oc_gatt.h
+++ b/libs/iotivity/include/iotivity/oc_gatt.h
@@ -28,7 +28,7 @@ struct ble_hs_cfg;
/* returns the event q for bluetooth to use */
int
-ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out);
+ble_coap_gatt_srv_init(struct os_eventq **out);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/iotivity/pkg.yml b/libs/iotivity/pkg.yml
index abecc02..6c2480e 100644
--- a/libs/iotivity/pkg.yml
+++ b/libs/iotivity/pkg.yml
@@ -26,19 +26,51 @@ pkg.keywords:
pkg.deps:
- "@apache-mynewt-core/libs/tinycbor"
- "@apache-mynewt-core/libs/os"
- - "@apache-mynewt-core/sys/mn_socket"
- "@apache-mynewt-core/sys/log"
+
+pkg.deps.OC_TRANSPORT_GATT:
- "@apache-mynewt-core/net/nimble/host"
- - "@apache-mynewt-core/net/nimble/transport/ram"
- "@apache-mynewt-core/net/nimble/host/services/gap"
- "@apache-mynewt-core/net/nimble/host/services/gatt"
+
+pkg.deps.OC_TRANSPORT_IP:
+ - "@apache-mynewt-core/sys/mn_socket"
+
+pkg.deps.OC_TRANSPORT_SERIAL:
+ - "@apache-mynewt-core/libs/shell"
+
# remove debug option to save logging
pkg.cflags: -std=c99
- -DDEBUG=1
-DSECURE=0
-I./port/mynewt
-I../port/mynewt
-I../../port/mynewt
-I../include/iotivity
-I../../include/iotivity
- -I../../../include/iotivity
\ No newline at end of file
+ -I../../../include/iotivity
+
+pkg.syscfg_defs:
+ OC_TRANSPORT_SERIAL:
+ description: 'Enables OIC transport over nlip serial'
+ value: '0'
+ OC_TRANSPORT_GATT:
+ description: 'Enables OIC transport over BLE GATT'
+ value: '0'
+ OC_TRANSPORT_IP:
+ description: 'Enables OIC transport over IP UDP'
+ value: '0'
+ OC_CLIENT:
+ description: 'Enables OIC client support'
+ value: '0'
+ OC_SERVER:
+ description: 'Enables OIC server support'
+ value: '0'
+ OC_DEBUG:
+ description: 'Enables OIC debug logs'
+ value: '0'
+ OC_TASK_PRIORITY:
+ description: 'The task priority for an internal tasks that runs the OCF stack'
+ value: '4'
+ OC_TASK_STACK_SIZE:
+ description: 'The stack size of the OC task in words'
+ value: '300'
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/adaptor.c b/libs/iotivity/src/port/mynewt/adaptor.c
index 144ef9b..0367c67 100644
--- a/libs/iotivity/src/port/mynewt/adaptor.c
+++ b/libs/iotivity/src/port/mynewt/adaptor.c
@@ -17,6 +17,7 @@
* under the License.
*/
#include <assert.h>
+#include <syscfg/syscfg.h>
#include <os/os.h>
#include <os/endian.h>
#include <string.h>
@@ -54,8 +55,8 @@ oc_network_event_handler_mutex_unlock(void)
}
/* need a task to process OCF messages */
-#define OC_NET_TASK_STACK_SIZE OS_STACK_ALIGN(300)
-#define OC_NET_TASK_PRIORITY (4)
+#define OC_NET_TASK_STACK_SIZE MYNEWT_VAL(OC_TASK_STACK_SIZE)
+#define OC_NET_TASK_PRIORITY MYNEWT_VAL(OC_TASK_PRIORITY)
struct os_task oc_task;
os_stack_t *oc_stack;
@@ -64,17 +65,17 @@ oc_send_buffer(oc_message_t *message) {
switch (message->endpoint.flags)
{
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
case IP:
oc_send_buffer_ip(message);
break;
#endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
case GATT:
oc_send_buffer_gatt(message);
break;
#endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
case SERIAL:
oc_send_buffer_serial(message);
break;
@@ -91,17 +92,17 @@ void oc_send_multicast_message(oc_message_t *message)
/* send on all the transports. Don't forget to reference the message
* so it doesn't get deleted */
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
oc_send_buffer_ip_mcast(message);
#endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
/* no multicast for GATT, just send unicast */
oc_message_add_ref(message);
oc_send_buffer_gatt(message);
#endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
/* no multi-cast for serial. just send unicast */
oc_message_add_ref(message);
oc_send_buffer_serial(message);
@@ -112,7 +113,7 @@ void oc_send_multicast_message(oc_message_t *message)
void
oc_task_handler(void *arg) {
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
oc_connectivity_start_gatt();
#endif
@@ -123,21 +124,21 @@ oc_task_handler(void *arg) {
struct os_event *evt = os_eventq_get(&oc_event_q);
switch(evt->ev_type) {
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
case OC_ADATOR_EVENT_IP:
while ((pmsg = oc_attempt_rx_ip()) != NULL) {
oc_network_event(pmsg);
}
break;
#endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
case OC_ADATOR_EVENT_SERIAL:
while ((pmsg = oc_attempt_rx_serial()) != NULL) {
oc_network_event(pmsg);
}
break;
#endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
case OC_ADATOR_EVENT_GATT:
while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
oc_network_event(pmsg);
@@ -182,13 +183,13 @@ oc_init_task(void) {
void
oc_connectivity_shutdown(void)
{
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
oc_connectivity_shutdown_ip();
#endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
oc_connectivity_shutdown_serial();
#endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
oc_connectivity_shutdown_gatt();
#endif
}
@@ -198,25 +199,25 @@ oc_connectivity_init(void)
{
int rc;
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
rc = oc_connectivity_init_ip();
if (rc != 0) {
goto oc_connectivity_init_err;
}
#endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+
rc = oc_connectivity_init_serial();
if (rc != 0) {
goto oc_connectivity_init_err;
}
#endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
rc = oc_connectivity_init_gatt();
if (rc != 0) {
goto oc_connectivity_init_err;
}
#endif
-
rc = oc_init_task();
if (rc != 0) {
goto oc_connectivity_init_err;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/adaptor.h b/libs/iotivity/src/port/mynewt/adaptor.h
index ea9034e..89c2599 100644
--- a/libs/iotivity/src/port/mynewt/adaptor.h
+++ b/libs/iotivity/src/port/mynewt/adaptor.h
@@ -31,7 +31,7 @@ extern "C" {
extern struct os_eventq oc_event_q;
-#ifdef OC_TRANSPORT_IP
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
int oc_connectivity_init_ip(void);
void oc_connectivity_shutdown_ip(void);
void oc_send_buffer_ip(oc_message_t *message);
@@ -39,7 +39,7 @@ void oc_send_buffer_ip_mcast(oc_message_t *message);
oc_message_t *oc_attempt_rx_ip(void);
#endif
-#ifdef OC_TRANSPORT_GATT
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
int oc_connectivity_init_gatt(void);
void oc_connectivity_start_gatt(void);
void oc_connectivity_shutdown_gatt(void);
@@ -49,7 +49,7 @@ oc_message_t *oc_attempt_rx_gatt(void);
#endif
-#ifdef OC_TRANSPORT_SERIAL
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
int oc_connectivity_init_serial(void);
void oc_connectivity_shutdown_serial(void);
void oc_send_buffer_serial(oc_message_t *message);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/ble_adaptor.c b/libs/iotivity/src/port/mynewt/ble_adaptor.c
index f6a2925..1ae2f8e 100644
--- a/libs/iotivity/src/port/mynewt/ble_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ble_adaptor.c
@@ -16,6 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include <syscfg/syscfg.h>
+#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
#include <assert.h>
#include <os/os.h>
#include <string.h>
@@ -26,7 +29,6 @@
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
-#ifdef OC_TRANSPORT_GATT
/* a custom service for COAP over GATT */
/* {e3f9f9c4-8a83-4055-b647-728b769745d6} */
@@ -47,7 +49,7 @@ struct os_mqueue ble_coap_mq;
static int
blecoap_gap_event(struct ble_gap_event *event, void *arg);
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
/* ble nmgr attr handle */
uint16_t g_ble_coap_attr_handle;
@@ -167,7 +169,7 @@ oc_gatt_advertise(void)
}
#endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
static char *
addr_str(const void *addr)
{
@@ -358,7 +360,7 @@ static int
blecoap_gap_event(struct ble_gap_event *event, void *arg)
{
switch (event->type) {
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
case BLE_GAP_EVENT_DISC:
/* Try to connect to the advertiser if it looks interesting. */
oc_gatt_connect_if_interesting(&event->disc);
@@ -373,11 +375,11 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
/* nothing to do here on the client */
}
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
/* keep advertising for multiple connections */
oc_gatt_advertise();
#endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
/* keep scanning for new connections */
oc_gatt_scan();
#endif
@@ -385,16 +387,16 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
case BLE_GAP_EVENT_DISCONNECT:
/* Connection terminated; resume advertising. */
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
/* keep scanning for new connections */
oc_gatt_scan();
#endif
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
/* resume advertising */
oc_gatt_advertise();
#endif
return 0;
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
case BLE_GAP_EVENT_NOTIFY_RX:
/* TODO queue the packet */
return 0;
@@ -404,11 +406,11 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
}
int
-ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out)
+ble_coap_gatt_srv_init(struct os_eventq **out)
{
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
int rc;
- rc = ble_gatts_count_cfg(gatt_svr_svcs, cfg);
+ rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
return rc;
}
@@ -435,13 +437,13 @@ void oc_connectivity_start_gatt(void) {
if (rc != 0) {
goto err;
}
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
rc = oc_gatt_advertise();
if (rc != 0) {
goto err;
}
#endif
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
rc = oc_gatt_scan();
if (rc != 0) {
goto err;
@@ -475,11 +477,11 @@ void oc_send_buffer_gatt(oc_message_t *message)
goto err;
}
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
ERROR("send not supported on client");
#endif
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
g_ble_coap_attr_handle, m);
m = NULL;
@@ -496,9 +498,9 @@ err:
void
oc_send_buffer_gatt_mcast(oc_message_t *message)
{
-#ifdef OC_CLIENT
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
ERROR("send not supported on client");
-#elif defined(OC_SERVER)
+#elif (MYNEWT_VAL(OC_SERVER) == 1)
oc_message_unref(message);
ERROR("oc_transport_gatt: no multicast support for server only system \n");
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/config.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/config.h b/libs/iotivity/src/port/mynewt/config.h
index 83e19de..5f8ba53 100644
--- a/libs/iotivity/src/port/mynewt/config.h
+++ b/libs/iotivity/src/port/mynewt/config.h
@@ -6,6 +6,22 @@
#include <stdint.h>
#include <os/os.h>
#include <log/log.h>
+#include <syscfg/syscfg.h>
+
+/* rather than change all their source files, just translate the mynewt
+ * package defines into their defines here */
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+#define OC_SERVER
+#endif
+
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+#define OC_CLIENT
+#endif
+
+#if (MYNEWT_VAL(OC_DEBUG) == 1)
+#define DEBUG 1
+#endif
+
extern struct log oc_log;
typedef os_time_t oc_clock_time_t;
@@ -54,6 +70,4 @@ typedef os_time_t oc_clock_time_t;
/* Max inactivity timeout before tearing down DTLS connection */
//#define DTLS_INACTIVITY_TIMEOUT (10)
-#define MYNEWT_OCF_SERIAL_PORT (1)
-
#endif /* CONFIG_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/ip_adaptor.c b/libs/iotivity/src/port/mynewt/ip_adaptor.c
index 8ae67e4..1bdf621 100644
--- a/libs/iotivity/src/port/mynewt/ip_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ip_adaptor.c
@@ -17,6 +17,8 @@
* under the License.
*/
+#include <syscfg/syscfg.h>
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
#include <assert.h>
#include <os/os.h>
#include <os/endian.h>
@@ -29,8 +31,6 @@
#include "../oc_log.h"
#include "adaptor.h"
-#ifdef OC_TRANSPORT_IP
-
struct os_event oc_sock_read_event = {
.ev_type = OC_ADATOR_EVENT_IP,
};
@@ -51,7 +51,7 @@ const struct mn_in6_addr coap_all_nodes_v6 = {
/* sockets to use for coap unicast and multicast */
struct mn_socket *ucast;
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
struct mn_socket *mcast;
#endif
@@ -188,7 +188,7 @@ oc_message_t *
oc_attempt_rx_ip(void) {
oc_message_t *pmsg;
pmsg = oc_attempt_rx_ip_sock(ucast);
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
if (pmsg == NULL ) {
pmsg = oc_attempt_rx_ip_sock(mcast);
}
@@ -218,7 +218,7 @@ oc_connectivity_shutdown_ip(void)
mn_close(ucast);
}
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
if (mcast) {
mn_close(mcast);
}
@@ -248,7 +248,7 @@ oc_connectivity_init_ip(void)
}
mn_socket_set_cbs(ucast, ucast, &oc_sock_cbs);
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
rc = mn_socket(&mcast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
if ( rc != 0 || !mcast ) {
mn_close(ucast);
@@ -270,7 +270,7 @@ oc_connectivity_init_ip(void)
goto oc_connectivity_init_err;
}
-#ifdef OC_SERVER
+#if (MYNEWT_VAL(OC_SERVER) == 1)
/* Set socket option to join multicast group on all valid interfaces */
while (1) {
struct mn_mreq join;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b98fe709/libs/iotivity/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/serial_adaptor.c b/libs/iotivity/src/port/mynewt/serial_adaptor.c
index 0c27b92..892db2b 100644
--- a/libs/iotivity/src/port/mynewt/serial_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/serial_adaptor.c
@@ -17,6 +17,9 @@
* under the License.
*/
+#include <syscfg/syscfg.h>
+#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
+
#include <assert.h>
#include <os/os.h>
#include <shell/shell.h>
@@ -24,7 +27,6 @@
#include "../oc_log.h"
#include "adaptor.h"
-#ifdef OC_TRANSPORT_SERIAL
struct os_mqueue oc_serial_mqueue;
[3/6] incubator-mynewt-core git commit: working BLE COAP GATT server
side.
Posted by pa...@apache.org.
working BLE COAP GATT server side.
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/afeca1aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/afeca1aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/afeca1aa
Branch: refs/heads/develop
Commit: afeca1aaecab156dc69fc96782cef9ff5dea0d18
Parents: 7c30b04
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Mon Sep 26 10:03:34 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Mon Sep 26 10:41:37 2016 -0700
----------------------------------------------------------------------
apps/ocf_sample/src/main.c | 11 +++++++++--
libs/iotivity/src/port/mynewt/adaptor.c | 2 +-
libs/iotivity/src/port/mynewt/ble_adaptor.c | 14 +++++++++++---
3 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/afeca1aa/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index 17d0f6a..9c5ccb2 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -23,6 +23,7 @@
#include <console/prompt.h>
#include <shell/shell.h>
#include <log/log.h>
+#include <hal/hal_cputime.h>
#include <iotivity/oc_api.h>
#include "mn_socket/mn_socket.h"
#include "mn_socket/arch/sim/native_sock.h"
@@ -74,7 +75,13 @@ static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
static os_stack_t ocf_stack[OCF_TASK_STACK_SIZE];
struct os_task ocf_task;
-#define DEFAULT_MBUF_MPOOL_BUF_LEN OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
+#ifdef OC_TRANSPORT_GATT
+#define MBUF_PAYLOAD_SIZE BLE_MBUF_PAYLOAD_SIZE
+#else
+#define MBUF_PAYLOAD_SIZE 128
+#endif
+
+#define DEFAULT_MBUF_MPOOL_BUF_LEN OS_ALIGN(MBUF_PAYLOAD_SIZE, 4)
#define DEFAULT_MBUF_MPOOL_NBUFS (12)
static uint8_t default_mbuf_mpool_data[DEFAULT_MBUF_MPOOL_BUF_LEN *
@@ -306,8 +313,8 @@ int
main(int argc, char **argv)
{
int rc;
- struct os_eventq *ev;
#ifdef OC_TRANSPORT_GATT
+ struct os_eventq *ev;
struct ble_hci_ram_cfg hci_cfg;
struct ble_hs_cfg cfg;
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/afeca1aa/libs/iotivity/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/adaptor.c b/libs/iotivity/src/port/mynewt/adaptor.c
index 7c2925b..144ef9b 100644
--- a/libs/iotivity/src/port/mynewt/adaptor.c
+++ b/libs/iotivity/src/port/mynewt/adaptor.c
@@ -143,12 +143,12 @@ oc_task_handler(void *arg) {
oc_network_event(pmsg);
}
break;
+#endif
case OS_EVENT_T_TIMER:
cf = (struct os_callout_func *)evt;
assert(cf->cf_func);
cf->cf_func(CF_ARG(cf));
break;
-#endif
default:
ERROR("oc_task_handler: Unidentified event %d\n", evt->ev_type);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/afeca1aa/libs/iotivity/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/ble_adaptor.c b/libs/iotivity/src/port/mynewt/ble_adaptor.c
index edca8a0..0328940 100644
--- a/libs/iotivity/src/port/mynewt/ble_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ble_adaptor.c
@@ -26,6 +26,8 @@
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
+#ifdef OC_TRANSPORT_GATT
+
/* a custom service for COAP over GATT */
/* {e3f9f9c4-8a83-4055-b647-728b769745d6} */
const uint8_t gatt_svr_svc_coap[16] = {
@@ -62,7 +64,7 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
/* Characteristic: Write No Rsp */
.uuid128 = (void *)gatt_svr_chr_coap,
.access_cb = gatt_svr_chr_access_coap,
- .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
+ .flags = BLE_GATT_CHR_F_WRITE_NO_RSP | BLE_GATT_CHR_F_NOTIFY,
.val_handle = &g_ble_coap_attr_handle,
}, {
0, /* No more characteristics in this service */
@@ -459,13 +461,17 @@ void oc_send_buffer_gatt(oc_message_t *message)
ERROR("oc_transport_gatt: could not append data \n");
goto err;
}
+
#ifdef OC_CLIENT
- /* TODO */
+ ERROR("send not supported on client");
#endif
+
#ifdef OC_SERVER
ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
g_ble_coap_attr_handle, m);
+ m = NULL;
#endif
+
err:
if (m) {
os_mbuf_free_chain(m);
@@ -478,9 +484,11 @@ void
oc_send_buffer_gatt_mcast(oc_message_t *message)
{
#ifdef OC_CLIENT
- /* TODO */
+ ERROR("send not supported on client");
#elif defined(OC_SERVER)
oc_message_unref(message);
ERROR("oc_transport_gatt: no multicast support for server only system \n");
#endif
}
+
+#endif
\ No newline at end of file
[5/6] incubator-mynewt-core git commit: partially working gatt coap
service
Posted by pa...@apache.org.
partially working gatt coap service
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/7c30b040
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7c30b040
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7c30b040
Branch: refs/heads/develop
Commit: 7c30b040bc6a3de9a7a97ab1557f3e366a69f8b0
Parents: 6aea712
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Fri Sep 23 16:08:44 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Mon Sep 26 10:41:37 2016 -0700
----------------------------------------------------------------------
apps/ocf_sample/pkg.yml | 9 +-
apps/ocf_sample/src/main.c | 109 ++++-
libs/console/full/src/cons_tty.c | 2 +-
libs/iotivity/include/iotivity/oc_gatt.h | 38 ++
libs/iotivity/pkg.yml | 5 +-
libs/iotivity/src/port/mynewt/adaptor.c | 15 +-
libs/iotivity/src/port/mynewt/adaptor.h | 3 +
libs/iotivity/src/port/mynewt/ble_adaptor.c | 468 +++++++++++++++++++
libs/iotivity/src/port/mynewt/serial_adaptor.c | 1 +
libs/iotivity/src/port/oc_connectivity.h | 1 +
.../transport/ble/include/nmgrble/newtmgr_ble.h | 1 +
11 files changed, 636 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/apps/ocf_sample/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/pkg.yml b/apps/ocf_sample/pkg.yml
index 52858b5..bf9b362 100644
--- a/apps/ocf_sample/pkg.yml
+++ b/apps/ocf_sample/pkg.yml
@@ -31,11 +31,16 @@ pkg.deps:
- libs/util
- sys/log
- libs/iotivity
-
+ - "@apache-mynewt-core/net/nimble/host"
+ - "@apache-mynewt-core/net/nimble/controller"
+ - "@apache-mynewt-core/net/nimble/transport/ram"
+ - "@apache-mynewt-core/net/nimble/host/store/ram"
+ - "@apache-mynewt-core/net/nimble/host/services/gap"
+ - "@apache-mynewt-core/net/nimble/host/services/gatt"
# this tells the library that you intend to suppor the server functionality
pkg.cflags:
-#-DOC_SERVER -- build the server examples
+#-DOC_SERVER -- build the server examples
#-DOC_CLIENT -- build the client examples
#-DOC_TRANSPORT_GATT -- to send COAP over GATT
#-DOC_TRANSPORT_SERIAL -- to send COAP over serial
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index ebe9988..17d0f6a 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -23,24 +23,59 @@
#include <console/prompt.h>
#include <shell/shell.h>
#include <log/log.h>
-
#include <iotivity/oc_api.h>
#include "mn_socket/mn_socket.h"
#include "mn_socket/arch/sim/native_sock.h"
+#ifdef OC_TRANSPORT_GATT
+
+#include <iotivity/oc_gatt.h>
+
+/* BLE */
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "host/ble_hs_adv.h"
+#include "host/ble_uuid.h"
+#include "host/ble_att.h"
+#include "host/ble_gap.h"
+#include "host/ble_gatt.h"
+#include "host/ble_l2cap.h"
+#include "host/ble_sm.h"
+#include "controller/ble_ll.h"
+
+/* RAM HCI transport. */
+#include "transport/ram/ble_hci_ram.h"
+
+/* RAM persistence layer. */
+#include "store/ram/ble_store_ram.h"
+
+/* Mandatory services. */
+#include "services/gap/ble_svc_gap.h"
+#include "services/gatt/ble_svc_gatt.h"
+
+uint8_t g_random_addr[6] = {6,5,4,3,2,1};
+uint8_t g_dev_addr[6] = {1,2,3,4,5,6};
+
+/** Priority of the nimble host and controller tasks. */
+#define BLE_LL_TASK_PRI (OS_TASK_PRI_HIGHEST)
+
+#endif
+
/* Shell */
+#ifdef OC_TRANSPORT_SERIAL
#define SHELL_TASK_PRIO (8)
#define SHELL_MAX_INPUT_LEN (512)
#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
+#endif
#define OCF_TASK_PRIO (8)
#define OCF_TASK_STACK_SIZE (OS_STACK_ALIGN(2048))
static os_stack_t ocf_stack[OCF_TASK_STACK_SIZE];
struct os_task ocf_task;
-#define DEFAULT_MBUF_MPOOL_BUF_LEN (256)
-#define DEFAULT_MBUF_MPOOL_NBUFS (10)
+#define DEFAULT_MBUF_MPOOL_BUF_LEN OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
+#define DEFAULT_MBUF_MPOOL_NBUFS (12)
static uint8_t default_mbuf_mpool_data[DEFAULT_MBUF_MPOOL_BUF_LEN *
DEFAULT_MBUF_MPOOL_NBUFS];
@@ -238,8 +273,6 @@ oc_signal_main_loop(void) {
}
void ocf_task_handler(void *arg) {
- /* TODO */
- oc_main_init(&ocf_handler);
os_sem_init(&ocf_main_loop_sem, 1);
@@ -265,16 +298,27 @@ ocf_task_init(void) {
rc = os_task_init(&ocf_task, "ocf", ocf_task_handler, NULL,
OCF_TASK_PRIO, OS_WAIT_FOREVER, ocf_stack, OCF_TASK_STACK_SIZE);
assert(rc == 0);
+
+ oc_main_init(&ocf_handler);
}
int
main(int argc, char **argv)
{
int rc;
-
+ struct os_eventq *ev;
+#ifdef OC_TRANSPORT_GATT
+ struct ble_hci_ram_cfg hci_cfg;
+ struct ble_hs_cfg cfg;
+#endif
/* Initialize OS */
os_init();
+ /* Set cputime to count at 1 usec increments */
+ rc = cputime_init(1000000);
+ assert(rc == 0);
+
+
rc = os_mempool_init(&default_mbuf_mpool, DEFAULT_MBUF_MPOOL_NBUFS,
DEFAULT_MBUF_MPOOL_BUF_LEN, default_mbuf_mpool_data,
"default_mbuf_data");
@@ -290,18 +334,68 @@ main(int argc, char **argv)
#ifdef OC_TRANSPORT_SERIAL
console_echo(0);
console_no_prompt();
-#endif
/* Init tasks */
rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
SHELL_MAX_INPUT_LEN);
assert(rc == 0);
+#else
+ console_init(NULL);
+#endif
#ifdef OC_TRANSPORT_IP
rc = native_sock_init();
assert(rc == 0);
#endif
+#ifdef OC_TRANSPORT_GATT
+ /* Initialize the BLE LL */
+ rc = ble_ll_init(BLE_LL_TASK_PRI, DEFAULT_MBUF_MPOOL_NBUFS,
+ DEFAULT_MBUF_MPOOL_BUF_LEN - BLE_HCI_DATA_HDR_SZ);
+ assert(rc == 0);
+
+ /* Initialize the RAM HCI transport. */
+ hci_cfg = ble_hci_ram_cfg_dflt;
+ rc = ble_hci_ram_init(&hci_cfg);
+ assert(rc == 0);
+
+ /* Initialize the BLE host. */
+ cfg = ble_hs_cfg_dflt;
+ cfg.max_hci_bufs = hci_cfg.num_evt_hi_bufs + hci_cfg.num_evt_lo_bufs;
+ cfg.max_connections = 1;
+ cfg.max_gattc_procs = 2;
+ cfg.max_l2cap_chans = 3;
+ cfg.max_l2cap_sig_procs = 1;
+ cfg.sm_bonding = 1;
+ cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
+ cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
+ cfg.sync_cb = NULL; /* TODO */
+ cfg.store_read_cb = ble_store_ram_read;
+ cfg.store_write_cb = ble_store_ram_write;
+
+ /* Populate config with the required GATT server settings. */
+ cfg.max_attrs = 0;
+ cfg.max_services = 0;
+ cfg.max_client_configs = 0;
+
+ rc = ble_svc_gap_init(&cfg);
+ assert(rc == 0);
+
+ rc = ble_svc_gatt_init(&cfg);
+ assert(rc == 0);
+
+ /* COAP Gatt server initialization */
+ rc = ble_coap_gatt_srv_init(&cfg, &ev);
+ assert(rc == 0);
+
+ rc = ble_hs_init(ev, &cfg);
+ assert(rc == 0);
+
+ /* Set the default device name. */
+ rc = ble_svc_gap_device_name_set("Mynewt_OCF");
+ assert(rc == 0);
+#endif
+
ocf_task_init();
/* Start the OS */
@@ -309,5 +403,4 @@ main(int argc, char **argv)
/* os start should never return. If it does, this should be an error */
assert(0);
-
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index 412f93c..f420c2a 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -265,7 +265,7 @@ console_rx_char(void *arg, uint8_t data)
struct console_tty *ct = (struct console_tty *)arg;
struct console_ring *tx = &ct->ct_tx;
struct console_ring *rx = &ct->ct_rx;
- int tx_space;
+ int tx_space = 0;
int i;
int tx_buf[3];
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/iotivity/include/iotivity/oc_gatt.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/include/iotivity/oc_gatt.h b/libs/iotivity/include/iotivity/oc_gatt.h
new file mode 100644
index 0000000..0cb48a8
--- /dev/null
+++ b/libs/iotivity/include/iotivity/oc_gatt.h
@@ -0,0 +1,38 @@
+/**
+ * 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 OC_GATT_H
+#define OC_GATT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ble_hs_cfg;
+
+/* returns the event q for bluetooth to use */
+int
+ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OC_GATT_H */
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/iotivity/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/iotivity/pkg.yml b/libs/iotivity/pkg.yml
index f837bf4..abecc02 100644
--- a/libs/iotivity/pkg.yml
+++ b/libs/iotivity/pkg.yml
@@ -28,7 +28,10 @@ pkg.deps:
- "@apache-mynewt-core/libs/os"
- "@apache-mynewt-core/sys/mn_socket"
- "@apache-mynewt-core/sys/log"
-
+ - "@apache-mynewt-core/net/nimble/host"
+ - "@apache-mynewt-core/net/nimble/transport/ram"
+ - "@apache-mynewt-core/net/nimble/host/services/gap"
+ - "@apache-mynewt-core/net/nimble/host/services/gatt"
# remove debug option to save logging
pkg.cflags: -std=c99
-DDEBUG=1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/iotivity/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/adaptor.c b/libs/iotivity/src/port/mynewt/adaptor.c
index 2a80f4c..7c2925b 100644
--- a/libs/iotivity/src/port/mynewt/adaptor.c
+++ b/libs/iotivity/src/port/mynewt/adaptor.c
@@ -111,13 +111,18 @@ void oc_send_multicast_message(oc_message_t *message)
/* send all the entries to the OCF stack through the same task */
void
oc_task_handler(void *arg) {
+
+#ifdef OC_TRANSPORT_GATT
+ oc_connectivity_start_gatt();
+#endif
+
while (1) {
+ struct os_callout_func *cf;
oc_message_t *pmsg;
(void) pmsg; /* to avoid unused */
struct os_event *evt = os_eventq_get(&oc_event_q);
switch(evt->ev_type) {
-
#ifdef OC_TRANSPORT_IP
case OC_ADATOR_EVENT_IP:
while ((pmsg = oc_attempt_rx_ip()) != NULL) {
@@ -125,7 +130,6 @@ oc_task_handler(void *arg) {
}
break;
#endif
-
#ifdef OC_TRANSPORT_SERIAL
case OC_ADATOR_EVENT_SERIAL:
while ((pmsg = oc_attempt_rx_serial()) != NULL) {
@@ -133,17 +137,20 @@ oc_task_handler(void *arg) {
}
break;
#endif
-
#ifdef OC_TRANSPORT_GATT
case OC_ADATOR_EVENT_GATT:
while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
oc_network_event(pmsg);
}
break;
+ case OS_EVENT_T_TIMER:
+ cf = (struct os_callout_func *)evt;
+ assert(cf->cf_func);
+ cf->cf_func(CF_ARG(cf));
+ break;
#endif
default:
ERROR("oc_task_handler: Unidentified event %d\n", evt->ev_type);
-
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/iotivity/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/adaptor.h b/libs/iotivity/src/port/mynewt/adaptor.h
index 431c7e9..ea9034e 100644
--- a/libs/iotivity/src/port/mynewt/adaptor.h
+++ b/libs/iotivity/src/port/mynewt/adaptor.h
@@ -41,9 +41,12 @@ oc_message_t *oc_attempt_rx_ip(void);
#ifdef OC_TRANSPORT_GATT
int oc_connectivity_init_gatt(void);
+void oc_connectivity_start_gatt(void);
void oc_connectivity_shutdown_gatt(void);
void oc_send_buffer_gatt(oc_message_t *message);
+void oc_send_buffer_gatt_mcast(oc_message_t *message);
oc_message_t *oc_attempt_rx_gatt(void);
+
#endif
#ifdef OC_TRANSPORT_SERIAL
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/iotivity/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/ble_adaptor.c b/libs/iotivity/src/port/mynewt/ble_adaptor.c
index f736fe1..edca8a0 100644
--- a/libs/iotivity/src/port/mynewt/ble_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ble_adaptor.c
@@ -16,3 +16,471 @@
* specific language governing permissions and limitations
* under the License.
*/
+#include <assert.h>
+#include <os/os.h>
+#include <string.h>
+#include "oc_buffer.h"
+#include "../oc_log.h"
+#include "adaptor.h"
+#include "host/ble_hs.h"
+#include "services/gap/ble_svc_gap.h"
+#include "services/gatt/ble_svc_gatt.h"
+
+/* a custom service for COAP over GATT */
+/* {e3f9f9c4-8a83-4055-b647-728b769745d6} */
+const uint8_t gatt_svr_svc_coap[16] = {
+ 0xd6, 0x45, 0x97, 0x76, 0x8b, 0x72, 0x47, 0xb6,
+ 0x55, 0x40, 0x83, 0x8a, 0xc4, 0xf9, 0xf9, 0xe3,
+};
+
+/* {e467fee6-d6bb-4956-94df-0090350631f5} */
+const uint8_t gatt_svr_chr_coap[16] = {
+ 0xf5, 0x31, 0x06, 0x35, 0x90, 0x00, 0xdf, 0x94,
+ 0x56, 0x49, 0xbb, 0xd6, 0xe6, 0xfe, 0x67, 0xe4,
+};
+
+/* queue to hold mbufs until we get called from oic */
+struct os_mqueue ble_coap_mq;
+
+static int
+blecoap_gap_event(struct ble_gap_event *event, void *arg);
+
+#ifdef OC_SERVER
+/* ble nmgr attr handle */
+uint16_t g_ble_coap_attr_handle;
+
+static int
+gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
+ {
+ /* Service: newtmgr */
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid128 = (void *)gatt_svr_svc_coap,
+ .characteristics = (struct ble_gatt_chr_def[]) { {
+ /* Characteristic: Write No Rsp */
+ .uuid128 = (void *)gatt_svr_chr_coap,
+ .access_cb = gatt_svr_chr_access_coap,
+ .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
+ .val_handle = &g_ble_coap_attr_handle,
+ }, {
+ 0, /* No more characteristics in this service */
+ } },
+ },
+ {
+ 0, /* No more services */
+ },
+};
+
+static int
+gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+ struct os_mbuf *m;
+ int rc;
+ (void) attr_handle; /* no need to use this since we have onyl one attr
+ * tied to this callback */
+
+ switch (ctxt->op) {
+ case BLE_GATT_ACCESS_OP_WRITE_CHR:
+ m = ctxt->om;
+ /* stick the conn handle at the end of the frame -- we will
+ * pull it out later */
+ rc = os_mbuf_append(m, &conn_handle, sizeof(conn_handle));
+ if (rc) {
+ return BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
+ rc = os_mqueue_put(&ble_coap_mq, &oc_event_q, m);
+ if (rc) {
+ return BLE_ATT_ERR_PREPARE_QUEUE_FULL;
+ }
+
+ /* tell nimble we are keeping the mbuf */
+ ctxt->om = NULL;
+
+ break;
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
+ }
+ return 0;
+}
+
+static int
+oc_gatt_advertise(void)
+{
+ struct ble_gap_adv_params adv_params;
+ struct ble_hs_adv_fields fields;
+ int rc;
+
+ /*
+ * Set the advertisement data included in our advertisements:
+ * o Flags (indicates advertisement type and other general info).
+ * o Advertising tx power.
+ * o 128 bit UUID
+ */
+
+ memset(&fields, 0, sizeof fields);
+
+ /* Indicate that the flags field should be included; specify a value of 0
+ * to instruct the stack to fill the value in for us.
+ */
+ fields.flags_is_present = 1;
+ fields.flags = 0;
+
+ /* Indicate that the TX power level field should be included; have the
+ * stack fill this one automatically as well. This is done by assigning
+ * the special value BLE_HS_ADV_TX_PWR_LVL_AUTO.
+ */
+ fields.tx_pwr_lvl_is_present = 1;
+ fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
+
+ fields.uuids128 = (void *)gatt_svr_svc_coap;
+ fields.num_uuids128 = 1;
+ fields.uuids128_is_complete = 1;
+
+ rc = ble_gap_adv_set_fields(&fields);
+ if (rc != 0) {
+ return rc;
+ }
+
+ memset(&fields, 0, sizeof fields);
+ fields.name = (uint8_t *)ble_svc_gap_device_name();
+ fields.name_len = strlen((char *)fields.name);
+ fields.name_is_complete = 1;
+
+ rc = ble_gap_adv_rsp_set_fields(&fields);
+ if (rc != 0) {
+ return rc;
+ }
+
+ /* Begin advertising. */
+ memset(&adv_params, 0, sizeof adv_params);
+ adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
+ adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
+ rc = ble_gap_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, BLE_HS_FOREVER,
+ &adv_params, blecoap_gap_event, NULL);
+ return rc;
+}
+#endif
+
+#ifdef OC_CLIENT
+/**
+ * Indicates whether we should tre to connect to the sender of the specified
+ * advertisement. The function returns a positive result if the device
+ * advertises connectability and support for the Alert Notification service.
+ */
+static int
+oc_gatt_should_connect(const struct ble_gap_disc_desc *disc)
+{
+ int i;
+
+ /* The device has to be advertising connectability. */
+ if (disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
+ disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
+
+ return 0;
+ }
+
+ /* The device has to advertise support for the COAP service
+ */
+ for
+ for (i = 0; i < disc->fields->num_uuids128; i++) {
+ if (disc->fields->uuids128[i] == gatt_svr_svc_coap) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * Connects to the sender of the specified advertisement of it looks
+ * interesting. A device is "interesting" if it advertises connectability and
+ * support for the Alert Notification service.
+ */
+static void
+oc_gatt_connect_if_interesting(const struct ble_gap_disc_desc *disc)
+{
+ int rc;
+
+ /* Don't do anything if we don't care about this advertiser. */
+ if (!oc_gatt_should_connect(disc)) {
+ return;
+ }
+
+ /* Scanning must be stopped before a connection can be initiated. */
+ rc = ble_gap_disc_cancel();
+ if (rc != 0) {
+ ERROR("Failed to cancel scan; rc=%d\n", rc);
+ return;
+ }
+
+ /* Try to connect the the advertiser. Allow 30 seconds (30000 ms) for
+ * timeout.
+ */
+ rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, disc->addr_type, disc->addr,
+ 30000, NULL, blecoap_gap_event, NULL);
+ if (rc != 0) {
+ ERROR("Error: Failed to connect to device; addr_type=%d "
+ "addr=%s\n", disc->addr_type, addr_str(disc->addr));
+ return;
+ }
+}
+
+
+/**
+ * Initiates the GAP general discovery procedure.
+ */
+static int
+oc_gatt_scan(void)
+{
+ struct ble_gap_disc_params disc_params;
+ int rc;
+
+ /* Tell the controller to filter duplicates; we don't want to process
+ * repeated advertisements from the same device.
+ */
+ disc_params.filter_duplicates = 1;
+
+ /**
+ * Perform a passive scan. I.e., don't send follow-up scan requests to
+ * each advertiser.
+ */
+ disc_params.passive = 1;
+
+ /* Use defaults for the rest of the parameters. */
+ disc_params.itvl = 0;
+ disc_params.window = 0;
+ disc_params.filter_policy = 0;
+ disc_params.limited = 0;
+
+ rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
+ blecent_gap_event, NULL);
+ if (rc != 0) {
+ ERROR("Error initiating GAP discovery procedure; rc=%d\n",
+ rc);
+ }
+ return rc;
+}
+
+#endif
+
+oc_message_t *
+oc_attempt_rx_gatt(void) {
+ int rc;
+ struct os_mbuf *m = NULL;
+ struct os_mbuf_pkthdr *pkt;
+ uint16_t conn_handle;
+ oc_message_t *message = NULL;
+
+ LOG("oc_transport_gatt attempt rx\n");
+
+ /* get an mbuf from the queue */
+ m = os_mqueue_get(&ble_coap_mq);
+ if (NULL == m) {
+ ERROR("oc_transport_gatt: Woke for for receive but found no mbufs\n");
+ goto rx_attempt_err;
+ }
+
+ if (!OS_MBUF_IS_PKTHDR(m)) {
+ ERROR("oc_transport_gatt: received mbuf that wasn't a packet header\n");
+ goto rx_attempt_err;
+ }
+
+ pkt = OS_MBUF_PKTHDR(m);
+
+ LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
+ /* get the conn handle from the end of the message */
+ rc = os_mbuf_copydata(m, pkt->omp_len - sizeof(conn_handle),
+ sizeof(conn_handle), &conn_handle);
+ if (rc != 0) {
+ ERROR("Failed to retrieve conn_handle from mbuf \n");
+ goto rx_attempt_err;
+ }
+
+ /* trim conn_handle from the end */
+ os_mbuf_adj(m, - sizeof(conn_handle));
+
+ message = oc_allocate_message();
+ if (NULL == message) {
+ ERROR("Could not allocate OC message buffer\n");
+ goto rx_attempt_err;
+ }
+
+ if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
+ ERROR("Message to large for OC message buffer\n");
+ goto rx_attempt_err;
+ }
+ /* copy to message from mbuf chain */
+ rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
+ if (rc != 0) {
+ ERROR("Failed to copy message from mbuf to OC message buffer \n");
+ goto rx_attempt_err;
+ }
+
+ os_mbuf_free_chain(m);
+ message->endpoint.flags = GATT;
+ message->endpoint.bt_addr.conn_handle = conn_handle;
+ message->length = pkt->omp_len;
+ LOG("Successfully rx length %lu\n", message->length);
+ return message;
+
+ /* add the addr info to the message */
+rx_attempt_err:
+ if (m) {
+ os_mbuf_free_chain(m);
+ }
+ if (message) {
+ oc_message_unref(message);
+ }
+ return NULL;
+}
+
+static int
+blecoap_gap_event(struct ble_gap_event *event, void *arg)
+{
+ switch (event->type) {
+#ifdef OC_CLIENT
+ case BLE_GAP_EVENT_DISC:
+ /* Try to connect to the advertiser if it looks interesting. */
+ blecent_connect_if_interesting(&event->disc);
+ return 0;
+#endif
+ case BLE_GAP_EVENT_CONNECT:
+ /* A new connection was established or a connection attempt failed. */
+ if (event->connect.status == 0) {
+ /* nothing to do here on the server */
+ }
+ if (event->connect.status != 0) {
+ /* nothing to do here on the client */
+ }
+
+#ifdef OC_SERVER
+ /* keep advertising for multiple connections */
+ oc_gatt_advertise();
+#endif
+#ifdef OC_CLIENT
+ /* keep scanning for new connections */
+ oc_gatt_scan();
+#endif
+ return 0;
+
+ case BLE_GAP_EVENT_DISCONNECT:
+ /* Connection terminated; resume advertising. */
+#ifdef OC_CLIENT
+ /* keep scanning for new connections */
+ oc_gatt_scan();
+#endif
+#ifdef OC_SERVER
+ /* resume advertising */
+ oc_gatt_advertise();
+#endif
+ return 0;
+#ifdef OC_CLIENT
+ case BLE_GAP_EVENT_NOTIFY_RX:
+ /* TODO queue the packet */
+ return 0;
+#endif
+ }
+ return 0;
+}
+
+#ifdef OC_SERVER
+int
+ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out)
+{
+ int rc;
+
+ *out = &oc_event_q;
+
+ rc = ble_gatts_count_cfg(gatt_svr_svcs, cfg);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_gatts_add_svcs(gatt_svr_svcs);
+ if (rc != 0) {
+ return rc;
+ }
+ return 0;
+}
+#endif
+
+int oc_connectivity_init_gatt(void) {
+ os_mqueue_init(&ble_coap_mq, NULL);
+ ble_coap_mq.mq_ev.ev_type = OC_ADATOR_EVENT_GATT;
+ return 0;
+}
+
+void oc_connectivity_start_gatt(void) {
+ int rc;
+ rc = ble_hs_start();
+ if (rc != 0) {
+ goto err;
+ }
+#ifdef OC_SERVER
+ rc = oc_gatt_advertise();
+ if (rc != 0) {
+ goto err;
+ }
+#endif
+#ifdef OC_CLIENT
+ rc = oc_gatt_scan();
+ if (rc != 0) {
+ goto err;
+ }
+#endif
+err:
+ ERROR("error enabling advertisement; rc=%d\n", rc);
+}
+
+void oc_connectivity_shutdown_gatt(void)
+{
+ /* there is not unregister for BLE */
+}
+
+void oc_send_buffer_gatt(oc_message_t *message)
+{
+ struct os_mbuf *m = NULL;
+ int rc;
+
+ /* get a packet header */
+ m = os_msys_get_pkthdr(0, 0);
+ if (m == NULL) {
+ ERROR("oc_transport_gatt: No mbuf available\n");
+ goto err;
+ }
+
+ /* add this data to the mbuf */
+ rc = os_mbuf_append(m, message->data, message->length);
+ if (rc != 0) {
+ ERROR("oc_transport_gatt: could not append data \n");
+ goto err;
+ }
+#ifdef OC_CLIENT
+ /* TODO */
+#endif
+#ifdef OC_SERVER
+ ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
+ g_ble_coap_attr_handle, m);
+#endif
+err:
+ if (m) {
+ os_mbuf_free_chain(m);
+ }
+ oc_message_unref(message);
+ return;
+}
+
+void
+oc_send_buffer_gatt_mcast(oc_message_t *message)
+{
+#ifdef OC_CLIENT
+ /* TODO */
+#elif defined(OC_SERVER)
+ oc_message_unref(message);
+ ERROR("oc_transport_gatt: no multicast support for server only system \n");
+#endif
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/iotivity/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/serial_adaptor.c b/libs/iotivity/src/port/mynewt/serial_adaptor.c
index 7fa94b3..0c27b92 100644
--- a/libs/iotivity/src/port/mynewt/serial_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/serial_adaptor.c
@@ -76,6 +76,7 @@ void oc_send_buffer_serial(oc_message_t *message) {
/* add this data to the mbuf */
rc = os_mbuf_append(m, message->data, message->length);
if (rc != 0) {
+
ERROR("oc_transport_serial: could not append data \n");
goto err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/iotivity/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/oc_connectivity.h b/libs/iotivity/src/port/oc_connectivity.h
index 4e4cdec..9b3b185 100644
--- a/libs/iotivity/src/port/oc_connectivity.h
+++ b/libs/iotivity/src/port/oc_connectivity.h
@@ -34,6 +34,7 @@ typedef struct
{
uint8_t type;
uint8_t address[6];
+ uint16_t conn_handle;
} oc_le_addr_t;
typedef struct
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c30b040/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
----------------------------------------------------------------------
diff --git a/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h b/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
index 315a6e8..b0d2e51 100644
--- a/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
+++ b/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
@@ -22,6 +22,7 @@
int
nmgr_ble_proc_mq_evt(struct os_event *ev);
+
int
nmgr_ble_gatt_svr_init(void);
[4/6] incubator-mynewt-core git commit: this file needs to be
consistent with the one in full. They had different names
Posted by pa...@apache.org.
this file needs to be consistent with the one in full. They had different names
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/6aea7128
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6aea7128
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6aea7128
Branch: refs/heads/develop
Commit: 6aea7128449ec463ee80d0740a9a572bc8439c4a
Parents: f5df33c
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Wed Sep 21 17:07:41 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Mon Sep 26 10:41:37 2016 -0700
----------------------------------------------------------------------
libs/console/stub/include/console/prompt.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6aea7128/libs/console/stub/include/console/prompt.h
----------------------------------------------------------------------
diff --git a/libs/console/stub/include/console/prompt.h b/libs/console/stub/include/console/prompt.h
index 9d7f622..a1d72c9 100644
--- a/libs/console/stub/include/console/prompt.h
+++ b/libs/console/stub/include/console/prompt.h
@@ -17,8 +17,9 @@
* under the License.
*/
-#ifndef H_CONSOLE_PROMPT_
-#define H_CONSOLE_PROMPT_
+#ifndef __CONSOLE_PROMPT_H__
+#define __CONSOLE_PROMPT_H__
+nclude/console/prompt.h
#include <stdarg.h>
@@ -31,4 +32,4 @@ void console_set_prompt(char);
extern char console_prompt[2];
-#endif /* __CONSOLE_H__ */
+#endif /* __CONSOLE_PROMPT_H__ */
[2/6] incubator-mynewt-core git commit: get the client gatt to
compile (not tested yet)
Posted by pa...@apache.org.
get the client gatt to compile (not tested yet)
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/5b51d6b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5b51d6b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5b51d6b1
Branch: refs/heads/develop
Commit: 5b51d6b1c31dc1e36ffd0fe2b4d535a2282ad8dc
Parents: afeca1a
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Mon Sep 26 10:39:06 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Mon Sep 26 10:41:37 2016 -0700
----------------------------------------------------------------------
apps/ocf_sample/src/main.c | 4 +++
libs/iotivity/src/port/mynewt/ble_adaptor.c | 31 +++++++++++++++++-------
2 files changed, 26 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b51d6b1/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index 9c5ccb2..e767dce 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -395,6 +395,10 @@ main(int argc, char **argv)
rc = ble_coap_gatt_srv_init(&cfg, &ev);
assert(rc == 0);
+#ifdef OC_CLIENT
+ /* TODO INIT CLIENT */
+#endif
+
rc = ble_hs_init(ev, &cfg);
assert(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b51d6b1/libs/iotivity/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/libs/iotivity/src/port/mynewt/ble_adaptor.c b/libs/iotivity/src/port/mynewt/ble_adaptor.c
index 0328940..f6a2925 100644
--- a/libs/iotivity/src/port/mynewt/ble_adaptor.c
+++ b/libs/iotivity/src/port/mynewt/ble_adaptor.c
@@ -168,6 +168,20 @@ oc_gatt_advertise(void)
#endif
#ifdef OC_CLIENT
+static char *
+addr_str(const void *addr)
+{
+ static char buf[6 * 2 + 5 + 1];
+ const uint8_t *u8p;
+
+ u8p = addr;
+ sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
+ u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
+
+ return buf;
+}
+
+
/**
* Indicates whether we should tre to connect to the sender of the specified
* advertisement. The function returns a positive result if the device
@@ -187,9 +201,9 @@ oc_gatt_should_connect(const struct ble_gap_disc_desc *disc)
/* The device has to advertise support for the COAP service
*/
- for
for (i = 0; i < disc->fields->num_uuids128; i++) {
- if (disc->fields->uuids128[i] == gatt_svr_svc_coap) {
+ char *ptr = ((char*) disc->fields->uuids128) + 16 * i;
+ if (memcmp(ptr, gatt_svr_svc_coap, sizeof(gatt_svr_svc_coap)) == 0) {
return 1;
}
}
@@ -259,7 +273,7 @@ oc_gatt_scan(void)
disc_params.limited = 0;
rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
- blecent_gap_event, NULL);
+ blecoap_gap_event, NULL);
if (rc != 0) {
ERROR("Error initiating GAP discovery procedure; rc=%d\n",
rc);
@@ -347,7 +361,7 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
#ifdef OC_CLIENT
case BLE_GAP_EVENT_DISC:
/* Try to connect to the advertiser if it looks interesting. */
- blecent_connect_if_interesting(&event->disc);
+ oc_gatt_connect_if_interesting(&event->disc);
return 0;
#endif
case BLE_GAP_EVENT_CONNECT:
@@ -389,14 +403,11 @@ blecoap_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
-#ifdef OC_SERVER
int
ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out)
{
+#ifdef OC_SERVER
int rc;
-
- *out = &oc_event_q;
-
rc = ble_gatts_count_cfg(gatt_svr_svcs, cfg);
if (rc != 0) {
return rc;
@@ -406,9 +417,11 @@ ble_coap_gatt_srv_init(struct ble_hs_cfg *cfg, struct os_eventq **out)
if (rc != 0) {
return rc;
}
+#endif
+
+ *out = &oc_event_q;
return 0;
}
-#endif
int oc_connectivity_init_gatt(void) {
os_mqueue_init(&ble_coap_mq, NULL);