mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-22 00:47:23 +00:00
directory re-org
X-Original-Commit: 6a7432f493900f8adad0fe9416b65d477fc5b316
This commit is contained in:
@@ -30,7 +30,7 @@ pkg.req_apis:
|
||||
- ble_transport
|
||||
|
||||
pkg.deps:
|
||||
- libs/os
|
||||
- kernel/os
|
||||
- sys/stats
|
||||
- net/nimble
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ pkg.keywords:
|
||||
pkg.deps:
|
||||
- sys/log
|
||||
- sys/stats
|
||||
- libs/os
|
||||
- kernel/os
|
||||
- libs/util
|
||||
- net/nimble
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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 _BLEUART_H_
|
||||
#define _BLEUART_H_
|
||||
|
||||
void
|
||||
bleuart_init(void);
|
||||
int
|
||||
bleuart_svc_register(void);
|
||||
int
|
||||
bleuart_gatt_svr_init(void);
|
||||
void
|
||||
bleuart_set_conn_handle(uint16_t conn_handle);
|
||||
|
||||
extern const uint8_t gatt_svr_svc_uart[16];
|
||||
|
||||
#endif /* _BLEUART_H */
|
||||
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
pkg.name: libs/bleuart
|
||||
pkg.description: BLE uart service.
|
||||
pkg.author: "Apache Mynewt <[email protected]>"
|
||||
pkg.homepage: "http://mynewt.apache.org/"
|
||||
pkg.keywords:
|
||||
- ble
|
||||
- bluetooth
|
||||
- uart
|
||||
|
||||
pkg.deps:
|
||||
- kernel/os
|
||||
- net/nimble/host
|
||||
|
||||
pkg.req_apis:
|
||||
- console
|
||||
|
||||
pkg.init_function: bleuart_init
|
||||
pkg.init_stage: 5
|
||||
|
||||
pkg.syscfg_defs:
|
||||
BLEUART_MAX_INPUT:
|
||||
description: 'TBD'
|
||||
value: 120
|
||||
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "bleuart/bleuart.h"
|
||||
#include "os/endian.h"
|
||||
#include "console/console.h"
|
||||
|
||||
/* ble uart attr read handle */
|
||||
uint16_t g_bleuart_attr_read_handle;
|
||||
|
||||
/* ble uart attr write handle */
|
||||
uint16_t g_bleuart_attr_write_handle;
|
||||
|
||||
/* Pointer to a console buffer */
|
||||
char *console_buf;
|
||||
|
||||
uint16_t g_console_conn_handle;
|
||||
/**
|
||||
* The vendor specific "bleuart" service consists of one write no-rsp characteristic
|
||||
* and one notification only read charateristic
|
||||
* o "write no-rsp": a single-byte characteristic that can be written only
|
||||
* over a non-encrypted connection
|
||||
* o "read": a single-byte characteristic that can always be read only via
|
||||
* notifications
|
||||
*/
|
||||
|
||||
/* {6E400001-B5A3-F393-E0A9-E50E24DCCA9E} */
|
||||
const uint8_t gatt_svr_svc_uart[16] = {
|
||||
0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
|
||||
0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e
|
||||
};
|
||||
|
||||
/* {6E400002-B5A3-F393-E0A9-E50E24DCCA9E} */
|
||||
const uint8_t gatt_svr_chr_uart_write[16] = {
|
||||
0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
|
||||
0x93, 0xf3, 0xa3, 0xb5, 0x02, 0x00, 0x40, 0x6e
|
||||
};
|
||||
|
||||
|
||||
/* {6E400003-B5A3-F393-E0A9-E50E24DCCA9E} */
|
||||
const uint8_t gatt_svr_chr_uart_read[16] = {
|
||||
0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
|
||||
0x93, 0xf3, 0xa3, 0xb5, 0x03, 0x00, 0x40, 0x6e
|
||||
};
|
||||
|
||||
static int
|
||||
gatt_svr_chr_access_uart_write(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: uart */
|
||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||
.uuid128 = (void *)gatt_svr_svc_uart,
|
||||
.characteristics = (struct ble_gatt_chr_def[]) { {
|
||||
.uuid128 = gatt_svr_chr_uart_read,
|
||||
.val_handle = &g_bleuart_attr_read_handle,
|
||||
.access_cb = gatt_svr_chr_access_uart_write,
|
||||
.flags = BLE_GATT_CHR_F_NOTIFY,
|
||||
}, {
|
||||
/* Characteristic: Write */
|
||||
.uuid128 = (void *)gatt_svr_chr_uart_write,
|
||||
.access_cb = gatt_svr_chr_access_uart_write,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_NO_RSP,
|
||||
.val_handle = &g_bleuart_attr_write_handle,
|
||||
}, {
|
||||
0, /* No more characteristics in this service */
|
||||
} },
|
||||
},
|
||||
|
||||
{
|
||||
0, /* No more services */
|
||||
},
|
||||
};
|
||||
|
||||
static int
|
||||
gatt_svr_chr_access_uart_write(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt, void *arg)
|
||||
{
|
||||
struct os_mbuf *om = ctxt->om;
|
||||
switch (ctxt->op) {
|
||||
case BLE_GATT_ACCESS_OP_WRITE_CHR:
|
||||
while(om) {
|
||||
console_write((char *)om->om_data, om->om_len);
|
||||
om = SLIST_NEXT(om, om_next);
|
||||
}
|
||||
console_write("\n", 1);
|
||||
return 0;
|
||||
default:
|
||||
assert(0);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* bleuart GATT server initialization
|
||||
*
|
||||
* @param eventq
|
||||
* @return 0 on success; non-zero on failure
|
||||
*/
|
||||
int
|
||||
bleuart_gatt_svr_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_gatts_count_cfg(gatt_svr_svcs);
|
||||
if (rc != 0) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
rc = ble_gatts_add_svcs(gatt_svr_svcs);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
err:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads console and sends data over BLE
|
||||
*/
|
||||
static void
|
||||
bleuart_uart_read(void)
|
||||
{
|
||||
int rc;
|
||||
int off;
|
||||
int full_line;
|
||||
struct os_mbuf *om;
|
||||
|
||||
off = 0;
|
||||
while (1) {
|
||||
rc = console_read(console_buf + off,
|
||||
MYNEWT_VAL(BLEUART_MAX_INPUT) - off, &full_line);
|
||||
if (rc <= 0 && !full_line) {
|
||||
continue;
|
||||
}
|
||||
off += rc;
|
||||
if (!full_line) {
|
||||
continue;
|
||||
}
|
||||
|
||||
om = ble_hs_mbuf_from_flat(console_buf, off);
|
||||
if (!om) {
|
||||
return;
|
||||
}
|
||||
ble_gattc_notify_custom(g_console_conn_handle,
|
||||
g_bleuart_attr_read_handle, om);
|
||||
off = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the global connection handle
|
||||
*
|
||||
* @param connection handle
|
||||
*/
|
||||
void
|
||||
bleuart_set_conn_handle(uint16_t conn_handle) {
|
||||
g_console_conn_handle = conn_handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* BLEuart console initialization
|
||||
*
|
||||
* @param Maximum input
|
||||
*/
|
||||
void
|
||||
bleuart_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = console_init(bleuart_uart_read);
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
|
||||
console_buf = malloc(MYNEWT_VAL(BLEUART_MAX_INPUT));
|
||||
SYSINIT_PANIC_ASSERT(console_buf != NULL);
|
||||
}
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "bsp/bsp.h"
|
||||
#include "stats/stats.h"
|
||||
#include "util/tpq.h"
|
||||
#include "os/os.h"
|
||||
#include "nimble/ble_hci_trans.h"
|
||||
#include "ble_hs_priv.h"
|
||||
@@ -61,11 +60,11 @@ static int ble_hs_reset_reason;
|
||||
#define BLE_HS_HEARTBEAT_OS_TICKS \
|
||||
(MYNEWT_VAL(BLE_HS_HEARTBEAT_FREQ) * OS_TICKS_PER_SEC / 1000)
|
||||
|
||||
#define BLE_HS_SYNC_RETRY_RATE (OS_TICKS_PER_SEC / 10)
|
||||
#define BLE_HS_SYNC_RETRY_RATE (OS_TICKS_PER_SEC / 10)
|
||||
|
||||
static struct os_task *ble_hs_parent_task;
|
||||
|
||||
#define BLE_HS_SYNC_RETRY_RATE (OS_TICKS_PER_SEC / 10)
|
||||
#define BLE_HS_SYNC_RETRY_RATE (OS_TICKS_PER_SEC / 10)
|
||||
|
||||
/**
|
||||
* Handles unresponsive timeouts and periodic retries in case of resource
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ pkg.keywords:
|
||||
- bluetooth
|
||||
|
||||
pkg.deps:
|
||||
- libs/os
|
||||
- kernel/os
|
||||
|
||||
pkg.syscfg_defs:
|
||||
# Supported GAP roles. By default, all four roles are enabled.
|
||||
|
||||
@@ -27,7 +27,7 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- net/nimble
|
||||
- libs/os
|
||||
- kernel/os
|
||||
|
||||
pkg.apis:
|
||||
- ble_transport
|
||||
|
||||
@@ -27,7 +27,7 @@ pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- hw/hal
|
||||
- libs/os
|
||||
- kernel/os
|
||||
- net/nimble
|
||||
|
||||
pkg.apis:
|
||||
|
||||
Reference in New Issue
Block a user