You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/06/05 05:46:50 UTC
incubator-mynewt-core git commit: Add tx command to bletiny
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 02ab1a63b -> 3ed632762
Add tx command to bletiny
This command will send N packets at rate R (in msecs) of a given length
to a specified handle. The format of the command is:
b tx h=<handle> r=<rate> n=<num> l=<len>
NOTE: length must be between 4 and 251, inclusive.
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/3ed63276
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3ed63276
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3ed63276
Branch: refs/heads/develop
Commit: 3ed6327623643b68cfb4763e5a76a7e2260bd6f0
Parents: 02ab1a6
Author: William San Filippo <wi...@runtime.io>
Authored: Sat Jun 4 22:45:14 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Sat Jun 4 22:46:42 2016 -0700
----------------------------------------------------------------------
apps/bletiny/src/bletiny.h | 5 +-
apps/bletiny/src/cmd.c | 46 ++++++++++++++++-
apps/bletiny/src/main.c | 109 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 158 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ed63276/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 0e3cae6..b6932e8 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -152,7 +152,7 @@ int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
void *value, uint16_t value_len);
int bletiny_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
int num_attrs);
-int bletiny_adv_start(int disc, int conn,
+int bletiny_adv_start(int disc, int conn,
uint8_t *peer_addr, uint8_t peer_addr_type,
struct ble_gap_adv_params *params);
int bletiny_adv_stop(void);
@@ -173,6 +173,9 @@ int bletiny_l2cap_update(uint16_t conn_handle,
int bletiny_sec_start(uint16_t conn_handle);
int bletiny_sec_restart(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
uint64_t rand_val, int auth);
+int bletiny_tx_start(uint16_t handle, uint16_t len, uint16_t rate,
+ uint16_t num);
+
#define BLETINY_LOG_MODULE (LOG_MODULE_PERUSER + 0)
#define BLETINY_LOG(lvl, ...) \
LOG_ ## lvl(&bletiny_log, BLETINY_LOG_MODULE, __VA_ARGS__)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ed63276/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index e0a361b..af343c5 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -868,7 +868,7 @@ cmd_scan(int argc, char **argv)
return EINVAL;
}
- addr_mode = parse_arg_kv_default("addr_mode",
+ addr_mode = parse_arg_kv_default("addr_mode",
cmd_scan_addr_types, BLE_ADDR_TYPE_PUBLIC);
if (addr_mode == -1) {
return EINVAL;
@@ -1970,6 +1970,49 @@ cmd_passkey(int argc, char **argv)
}
/*****************************************************************************
+ * $tx *
+ * *
+ * Command to transmit 'num' packets of size 'len' at rate 'r' to
+ * handle 'h' Note that length must be <= 251. The rate is in msecs.
+ *
+ *****************************************************************************/
+static int
+cmd_tx(int argc, char **argv)
+{
+ int rc;
+ uint16_t rate;
+ uint16_t len;
+ uint16_t handle;
+ uint16_t num;
+
+ rate = parse_arg_uint16("r", &rc);
+ if (rc != 0) {
+ return rc;
+ }
+
+ len = parse_arg_uint16("l", &rc);
+ if (rc != 0) {
+ return rc;
+ }
+ if ((len > 251) || (len < 4)) {
+ console_printf("error: len must be between 4 and 251, inclusive");
+ }
+
+ num = parse_arg_uint16("n", &rc);
+ if (rc != 0) {
+ return rc;
+ }
+
+ handle = parse_arg_uint16("h", &rc);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = bletiny_tx_start(handle, len, rate, num);
+ return rc;
+}
+
+/*****************************************************************************
* $init *
*****************************************************************************/
@@ -1990,6 +2033,7 @@ static struct cmd_entry cmd_b_entries[] = {
{ "store", cmd_keystore },
{ "term", cmd_term },
{ "update", cmd_update },
+ { "tx", cmd_tx },
{ "wl", cmd_wl },
{ "write", cmd_write },
{ NULL, NULL }
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ed63276/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 3657cc3..89288f2 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -34,6 +34,7 @@
/* BLE */
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
+#include "nimble/hci_transport.h"
#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "host/ble_hs_adv.h"
@@ -123,6 +124,16 @@ uint8_t bletiny_reconnect_addr[6];
uint8_t bletiny_pref_conn_params[8];
uint8_t bletiny_gatt_service_changed[4];
+static struct os_callout_func bletiny_tx_timer;
+struct bletiny_tx_data_s
+{
+ uint16_t tx_num;
+ uint16_t tx_rate;
+ uint16_t tx_handle;
+ uint16_t tx_len;
+};
+static struct bletiny_tx_data_s bletiny_tx_data;
+
#define XSTR(s) STR(s)
#define STR(s) #s
@@ -901,6 +912,62 @@ bletiny_on_scan(int event, int status, struct ble_gap_disc_desc *desc,
}
}
+static void
+bletiny_tx_timer_cb(void *arg)
+{
+ int i;
+ uint8_t len;
+ int32_t timeout;
+ uint8_t *dptr;
+ struct os_mbuf *om;
+
+ if ((bletiny_tx_data.tx_num == 0) || (bletiny_tx_data.tx_len == 0)) {
+ return;
+ }
+
+ len = bletiny_tx_data.tx_len;
+ om = NULL;
+ if (default_mbuf_mpool.mp_num_free >= 4) {
+ om = os_msys_get_pkthdr(len + 4, sizeof(struct ble_mbuf_hdr));
+ }
+
+ if (om) {
+ /* Put the HCI header in the mbuf */
+ om->om_len = len + 4;
+ htole16(om->om_data, bletiny_tx_data.tx_handle);
+ htole16(om->om_data + 2, len);
+ dptr = om->om_data + 4;
+
+ /*
+ * NOTE: first byte gets 0xff so not confused with l2cap channel.
+ * The rest of the data gets filled with incrementing pattern starting
+ * from 0.
+ */
+ htole16(dptr, len - 4);
+ dptr[2] = 0xff;
+ dptr[3] = 0xff;
+ dptr += 4;
+ len -= 4;
+
+ for (i = 0; i < len; ++i) {
+ *dptr = i;
+ ++dptr;
+ }
+
+ /* Set packet header length */
+ OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
+ ble_hci_transport_host_acl_data_send(om);
+
+ --bletiny_tx_data.tx_num;
+ }
+
+ if (bletiny_tx_data.tx_num) {
+ timeout = (int32_t)bletiny_tx_data.tx_rate;
+ timeout = (timeout * OS_TICKS_PER_SEC) / 1000;
+ os_callout_reset(&bletiny_tx_timer.cf_c, timeout);
+ }
+}
+
int
bletiny_exchange_mtu(uint16_t conn_handle)
{
@@ -1203,6 +1270,45 @@ bletiny_sec_restart(uint16_t conn_handle,
}
/**
+ * Called to start transmitting 'num' packets at rate 'rate' of size 'size'
+ * to connection handle 'handle'
+ *
+ * @param handle
+ * @param len
+ * @param rate
+ * @param num
+ *
+ * @return int
+ */
+int
+bletiny_tx_start(uint16_t handle, uint16_t len, uint16_t rate, uint16_t num)
+{
+ /* Cannot be currently in a session */
+ if (num == 0) {
+ return 0;
+ }
+
+ /* Do not allow start if already in progress */
+ if (bletiny_tx_data.tx_num != 0) {
+ return -1;
+ }
+
+ /* XXX: for now, must have contiguous mbuf space */
+ if ((len + 4) > MBUF_BUF_SIZE) {
+ return -2;
+ }
+
+ bletiny_tx_data.tx_num = num;
+ bletiny_tx_data.tx_rate = rate;
+ bletiny_tx_data.tx_len = len;
+ bletiny_tx_data.tx_handle = handle;
+
+ os_callout_reset(&bletiny_tx_timer.cf_c, 0);
+
+ return 0;
+}
+
+/**
* BLE test task
*
* @param arg
@@ -1359,6 +1465,9 @@ main(void)
gatt_svr_init();
+ os_callout_func_init(&bletiny_tx_timer, &bletiny_evq, bletiny_tx_timer_cb,
+ NULL);
+
/* Start the OS */
os_start();