mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 09:39:10 -04:00
feat(ble_mesh): Remove ble_mesh_console example
This commit is contained in:
parent
bf51fb965b
commit
0e63bfcddc
@ -128,8 +128,6 @@ Mesh Applications
|
||||
* :example_file:`Tutorial <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md>`
|
||||
* :example:`Example <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist>`
|
||||
* `Demo Video <https://dl.espressif.com/BLE/public/ESP_BLE_MESH_WIFI_Coexistence.mp4>`__
|
||||
* ESP-BLE-MESH Console Commands
|
||||
* :example:`Example <bluetooth/esp_ble_mesh/ble_mesh_console>`
|
||||
|
||||
|
||||
Future Release Features
|
||||
|
@ -223,8 +223,6 @@ ESP-BLE-MESH Examples
|
||||
|
||||
* :example_file:`ESP-BLE-MESH and Wi-Fi Coexistence <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md>` - an example that demonstrates the Wi-Fi and Bluetooth (BLE/BR/EDR) coexistence feature of {IDF_TARGET_NAME}. Simply put, users can use the Wi-Fi while operating Bluetooth, see :example:`example code <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist>`.
|
||||
|
||||
* ESP-BLE-MESH Console - an example that implements BLE Mesh basic features. Within this example a node can be scanned and provisioned by Provisioner and reply to get/set message from Provisioner, see :example:`example node code <bluetooth/esp_ble_mesh/ble_mesh_console>`.
|
||||
|
||||
|
||||
.. _esp-ble-mesh-demo-videos:
|
||||
|
||||
|
@ -223,8 +223,6 @@ ESP-BLE-MESH 示例
|
||||
|
||||
* :example_file:`Wi-Fi 和 ESP-BLE-MESH 共存 <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md>` - 该示例用于演示 Wi-Fi 和 ESP-BLE-MESH 共存的功能。简而言之,用户可在运行 ESP-BLE-MESH 时使用 Wi-Fi,示例请见 :example:`example code <bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist>`。
|
||||
|
||||
* ESP-BLE-MESH 节点控制台 - 该演示实现 ESP-BLE-MESH 节点的基本功能。在演示中,Provisioner and Node 可以扫描、验证节点,节点可以回复 Provisioner 的获取/设置消息,示例请见::example:`example code <bluetooth/esp_ble_mesh/ble_mesh_console>`。
|
||||
|
||||
|
||||
.. _esp-ble-mesh-demo-videos:
|
||||
|
||||
|
@ -10,10 +10,6 @@ Note: To use examples in this directory, you need to have Bluetooth enabled in c
|
||||
|
||||
This directory includes examples to demonstrate ESP-BLE-MESH functionality based on [Zephyr Bluetooth Mesh stack](https://github.com/zephyrproject-rtos/zephyr/tree/master/subsys/bluetooth/mesh).
|
||||
|
||||
## ble_mesh_console
|
||||
|
||||
This example demonstrates how ESP-BLE-MESH uses Console for message transmitting/receiving tests.
|
||||
|
||||
## ble_mesh_fast_provision
|
||||
|
||||
This example illustrates the solution of ESP-BLE-MESH Fast Provisioning.
|
||||
|
@ -1,8 +0,0 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/bluetooth/esp_ble_mesh/common_components/example_init)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(ble_mesh_console)
|
@ -1,12 +0,0 @@
|
||||
| Supported Targets | ESP32 | ESP32-C3 | ESP32-C6 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- |
|
||||
|
||||
# ble mesh node console demo
|
||||
## Introduction
|
||||
This demo implements ble mesh node basic features.Based on this demo, node can be scaned and proved by provisioner, reply get/set message to provisioner.
|
||||
|
||||
Demo steps:
|
||||
1. Build the ble mesh node console demo with sdkconfig.default
|
||||
2. register node and set oob info, load model to init ble mesh node
|
||||
3. enable bearer, so that it can be scaned and provisioned by provisioner
|
||||
|
@ -1,166 +0,0 @@
|
||||
# The Document of ESP32 BLE_MESH Commands
|
||||
|
||||
## Overall Command
|
||||
|
||||
|
||||
* `bmreg`: Provisioner/node register callback
|
||||
* Example: `bmreg`
|
||||
* Result: `Bm:Reg,OK`
|
||||
|
||||
* `bminit`: Provisioner/node initialize
|
||||
* `-m`: `mesh modle`
|
||||
* Example: `bminit -m 0x0001`
|
||||
* Result: `Bm:Init,OK`
|
||||
|
||||
* `bmpbind`: Provisioner binds Appkey with local model
|
||||
* `-a`: `<appkey index>:appkey index`
|
||||
* `-e`: `<element address>:element address`
|
||||
* `-n`: `<network index>:network index`
|
||||
* `-m`: `<model id>:model id`
|
||||
* `-c`: `<model id>:company id`
|
||||
* Example: `bmpbind -a 0 -e 0x01 -m 0x1001 -n 0x00`
|
||||
* Result: `provisioning:AppKeyBind,OK`
|
||||
|
||||
* `bmpdev`: Provisioner add/delete unprovisioned device
|
||||
* `-z`: `action type <add/delete>`
|
||||
* `-d`: `device address`
|
||||
* `-u`: `device uuid`
|
||||
* `-a`: `address type`
|
||||
* `-f`: `address flag`
|
||||
* `-b`: `used bearer`
|
||||
* `-o`: `oob information`
|
||||
* Example: `bmpdev -z add -d bt_mac -b -1 -a 0`
|
||||
* Result: `provisioner:DevAdd/Del,OK`
|
||||
|
||||
* `bmoob`: Provisioner/node config OOB parameters
|
||||
* `-s`: `Static OOB value`
|
||||
* `-l`: `Static OOB value length`
|
||||
* `-x`: `Maximum size of Output OOB`
|
||||
* `-o`: `Supported Output OOB Actions`
|
||||
* `-y`: `Maximum size of Input OOB`
|
||||
* `-i`: `Supported Input OOB Actions`
|
||||
* `-p`: `start address assigned by provisioner`
|
||||
* Example: `bmoob -o -0 -x 0`
|
||||
* Result: `OOB:Load,OK`
|
||||
|
||||
* `bmpbearer`: Enable/disable provisioner different bearer
|
||||
* `-b`: `bearer supported`
|
||||
* `-e`: `enable or disable bearer`
|
||||
* Example: `bmpbearer -b 1 -e 1`
|
||||
* Result: `provisioner:EnBearer,OK`
|
||||
|
||||
* `bmnbearer`: Enable/disable node different bearer
|
||||
* `-b`: `bearer supported`
|
||||
* `-e`: `enable or disable bearer`
|
||||
* Example: `bmnbearer -b 1 -e 1`
|
||||
* Result: `Node:EnBearer,OK`
|
||||
|
||||
* `bmpkey`: Add/Delete NetKey and AppKey of Provisioner
|
||||
* `-z`: `<action type>:add app key or network key`
|
||||
* `-n`: `<net key index>:network key index`
|
||||
* `-k`: `<key>:appkey or network`
|
||||
* `-a`: `<app key index>:appkey index`
|
||||
* Example: `bmpkey -z netkey -n 1 -k <network_key>`
|
||||
* Result: `provisioner:NetKeyAdd,OK`
|
||||
|
||||
* `bmccm`: BLE Mesh configuration client model operations
|
||||
* `-z`: `<action>:action type`:add or del client model
|
||||
* `-x`: `<state>:set state`
|
||||
* `-o`: `<opcode>:message opcode`
|
||||
* `-u`: `<address>:unicast address`
|
||||
* `-n`: `<network>:net work index`
|
||||
* `-i`: `<index>:appkey index`
|
||||
* `-r`: `<relay>:relay statue`
|
||||
* `-t`: `<transmit>:relay transmit`
|
||||
* `-c`: `<cid>:company id`
|
||||
* `-v`: `<value>:value`
|
||||
* `-a`: `<address>:address`
|
||||
* `-m`: `<mod id>:model id`
|
||||
* Example: `bmccm -z reg`
|
||||
* Result: `ConfigClient:OK`
|
||||
|
||||
* `bmgocm`: BLE Mesh onoff client model operations
|
||||
* `-z`: `<action>:action type`: on or off client model
|
||||
* `-o`: `<opcode>:message opcode`
|
||||
* `-u`: `<address>:unicast address`
|
||||
* `-n`: `<netkey index>:network key index`
|
||||
* `-a`: `<index>:appkey index`
|
||||
* `-r`: `<role>:role`
|
||||
* `-t`: `<time>:time to complete state transition`
|
||||
* `-e`: `<optional>:whether optional parameters included`
|
||||
* `-s` : `<state>:present onoff state`
|
||||
* `-a`: `<address>:address`
|
||||
* `-i`: `<identifier>:transaction identifier`
|
||||
* `-d`: `<delay>:indicate message execution delay`
|
||||
* Example: `bmgocm -z reg`
|
||||
* Result: `GenONOFFClient:Reg,OK`
|
||||
|
||||
* `bmnreset`: Reset node to become an unprovisioned device
|
||||
* Example: `bmnreset`
|
||||
* Result: `Node:Reset`
|
||||
|
||||
* `bmpublish`: BLE Mesh model publication
|
||||
* `-d`: `<data>:message data`
|
||||
* `-o`: `<opcode>:operation opcode`
|
||||
* `-m`: `<module>:module published to`
|
||||
* `-r`: `<role>:device role`
|
||||
* `-a`: `<address>:unicast address`
|
||||
* `-i`: `<app key>:app key index`
|
||||
* `-p`: `<period>:period`
|
||||
* Example: `bmpublish -d 1 -o 0x8204 -m 0x1000 -r 0 -a 1 -p 0 -i 0`
|
||||
* Result: `PublishSend,OK`
|
||||
|
||||
* `bmnnwk`: An unprovisioned device enters the mesh network and becomes a node without the provisioning procedure
|
||||
* `-k`: `<net key>:network key`
|
||||
* `-n`: `<net index>:network key index`
|
||||
* `-u`: `<unicast address>:unicast address`
|
||||
* `-d`: `<device key>:device key`
|
||||
* `-a`: `<appkey>:app key`
|
||||
* `-i`: `<app key>:app key index`
|
||||
* `-g`: `<group address>:group address`
|
||||
* Example: `bnnnwk -k 0x1000 -n 1 -u 0x0010 -a 0x%s -d0x%s -i 0 -g 0xC000`
|
||||
* Result: `Provisioning:Success,%d`
|
||||
|
||||
* `bmpaddn`: Provisioner add device's information into the mesh database while unprovisioned device enter mesh network automatically
|
||||
* `-o`: `<oob info>:oob information`
|
||||
* `-a`: `<unicast address>:unicast address`
|
||||
* `-e`: `<element num>:element num`
|
||||
* `-n`: `<net index>:net index`
|
||||
* `-d`: `<device key>:device key`
|
||||
* `-u`: `<device uuid>:device uuid`
|
||||
* Example: `bmpaddn -o -0x0 -a %s -e 1 -n 1 -d 0x%s -u 0x%s`
|
||||
* Result: `Provisioner:AddNodeInfo,OK`
|
||||
|
||||
* `bmcperf`: BLE Mesh client test performance
|
||||
* `-z`: `<action>:action type`:init/get/destroy/percent
|
||||
* `-s`: `<test size>:test size`
|
||||
* `-n`: `<node number>:node number`
|
||||
* `-l`: `<test number>:ttl`
|
||||
* Example: `bmcperf -z init -n 1 -s %d -l 7`
|
||||
* Result: `VendorPerfTest:InitStatistics,OK`
|
||||
|
||||
* `bmperf`: BLE Mesh vendor server model performance test
|
||||
* `-z`: `<action>:action type`:init/get/destroy/percent
|
||||
* `-p`: `<package>:package number`
|
||||
* Example: `bmsperf -z init -p %d`
|
||||
* Result: `Node:InitStatistics,OK`
|
||||
|
||||
* `bmtpcvm`: BLE Mesh vendor client model performance test
|
||||
* `-z`: `<action>:action type`:init or start
|
||||
* `-p`: `<byte>:playload byte`
|
||||
* `-n`: `<number>:test number`
|
||||
* `-o`: `<opcode>:opcode`
|
||||
* `-u`: `<address>:unicast address`
|
||||
* `-t`: `<ttl>:ttl`
|
||||
* `-a`: `<appkey>:appkey index`
|
||||
* `-i`: `<network key>:network key index`
|
||||
* `-d`: `<role>:device role`
|
||||
* Example: `bmtpcvm -z start -p %d -n %d -o 0xC302C4 -u %s -t 7 -a 0 -i 1 -d 1`
|
||||
* Result: `VendorModel:SendPackage,Finish`
|
||||
|
||||
* `bmtxpower`: Provisioner/node set tx power or rx sensitivity"
|
||||
* `-z`: `<action>:action type`:set tx power or rx sensitivity
|
||||
* `-t`: `<power>:tx power or sense`
|
||||
* Example: `bmtxpower -z tx -t %d`
|
||||
* Result: `Node:SetPower,OK`
|
||||
|
@ -1,15 +0,0 @@
|
||||
set(srcs "ble_mesh_adapter.c"
|
||||
"ble_mesh_model.c"
|
||||
"ble_mesh_console_lib.c"
|
||||
"ble_mesh_console_main.c"
|
||||
"ble_mesh_console_system.c"
|
||||
"ble_mesh_register_cmd.c"
|
||||
"ble_mesh_reg_cfg_client_cmd.c"
|
||||
"ble_mesh_register_server_cmd.c"
|
||||
"ble_mesh_reg_gen_onoff_client_cmd.c"
|
||||
"ble_mesh_reg_test_perf_client_cmd.c"
|
||||
"transaction.c"
|
||||
"register_bluetooth.c")
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS ".")
|
@ -1,366 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
#include "ble_mesh_adapter.h"
|
||||
|
||||
ble_mesh_performance_statistics_t test_perf_statistics;
|
||||
ble_mesh_node_statistics_t ble_mesh_node_statistics;
|
||||
|
||||
ESP_BLE_MESH_MODEL_PUB_DEFINE(onoff_pub_0, 2 + 3, ROLE_NODE);
|
||||
ESP_BLE_MESH_MODEL_PUB_DEFINE(model_pub_config, 2 + 1, ROLE_NODE);
|
||||
|
||||
static esp_ble_mesh_model_t srv_models[] = {
|
||||
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
|
||||
ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(&onoff_pub_0, &onoff_server),
|
||||
};
|
||||
|
||||
esp_ble_mesh_model_t vendor_srv_models[] = {
|
||||
ESP_BLE_MESH_VENDOR_MODEL(CID_ESP, ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV,
|
||||
test_perf_srv_op, NULL, NULL),
|
||||
};
|
||||
|
||||
static esp_ble_mesh_elem_t srv_elements[] = {
|
||||
ESP_BLE_MESH_ELEMENT(0, srv_models, vendor_srv_models),
|
||||
};
|
||||
|
||||
static esp_ble_mesh_comp_t srv_composition = {
|
||||
.cid = CID_ESP,
|
||||
.elements = srv_elements,
|
||||
.element_count = ARRAY_SIZE(srv_elements),
|
||||
};
|
||||
|
||||
//client models
|
||||
esp_ble_mesh_model_t cli_models[] = {
|
||||
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
|
||||
ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli),
|
||||
ESP_BLE_MESH_MODEL_GEN_ONOFF_CLI(&model_pub_config, &gen_onoff_cli),
|
||||
ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(&onoff_pub_0, &onoff_server),
|
||||
};
|
||||
|
||||
esp_ble_mesh_model_t vendor_cli_models[] = {
|
||||
ESP_BLE_MESH_VENDOR_MODEL(CID_ESP, ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI,
|
||||
test_perf_cli_op, &vendor_model_pub_config, &test_perf_cli),
|
||||
};
|
||||
|
||||
static esp_ble_mesh_elem_t cli_elements[] = {
|
||||
ESP_BLE_MESH_ELEMENT(0, cli_models, vendor_cli_models),
|
||||
};
|
||||
|
||||
static esp_ble_mesh_comp_t cli_composition = {
|
||||
.cid = CID_ESP,
|
||||
.elements = cli_elements,
|
||||
.element_count = ARRAY_SIZE(cli_elements),
|
||||
};
|
||||
|
||||
esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id)
|
||||
{
|
||||
esp_ble_mesh_comp_t *comp = NULL;
|
||||
switch (model_id) {
|
||||
case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV:
|
||||
case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV:
|
||||
case ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV:
|
||||
comp = &srv_composition;
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_ID_CONFIG_CLI:
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI:
|
||||
#endif
|
||||
case ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI:
|
||||
comp = &cli_composition;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
int ble_mesh_init_node_prestore_params(void)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
for (i = 0; i < NODE_MAX_GROUP_CONFIG; i++) {
|
||||
ble_mesh_node_prestore_params[i].net_idx = ESP_BLE_MESH_KEY_UNUSED;
|
||||
ble_mesh_node_prestore_params[i].unicast_addr = ESP_BLE_MESH_ADDR_UNASSIGNED;
|
||||
}
|
||||
if(ble_mesh_node_sema == NULL) {
|
||||
ble_mesh_node_sema = xSemaphoreCreateMutex();
|
||||
if (!ble_mesh_node_sema) {
|
||||
ESP_LOGE(TAG, "%s init fail, mesh node semaphore create fail", __func__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr)
|
||||
{
|
||||
uint16_t i;
|
||||
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
|
||||
for (i = 0; i < NODE_MAX_GROUP_CONFIG; i++) {
|
||||
if (ble_mesh_node_prestore_params[i].net_idx != ESP_BLE_MESH_KEY_UNUSED && ble_mesh_node_prestore_params[i].unicast_addr != ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
ble_mesh_node_prestore_params[i].net_idx = netkey_index;
|
||||
ble_mesh_node_prestore_params[i].unicast_addr = unicast_addr;
|
||||
}
|
||||
}
|
||||
xSemaphoreGive(ble_mesh_node_sema);
|
||||
}
|
||||
|
||||
void ble_mesh_deinit_node_prestore_params(void)
|
||||
{
|
||||
if (ble_mesh_node_sema != NULL) {
|
||||
vSemaphoreDelete(ble_mesh_node_sema);
|
||||
ble_mesh_node_sema = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ble_mesh_node_statistics_get(void)
|
||||
{
|
||||
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
|
||||
ESP_LOGI(TAG, "Statistics:%" PRIu32, ble_mesh_node_statistics.package_num);
|
||||
xSemaphoreGive(ble_mesh_node_sema);
|
||||
}
|
||||
|
||||
int ble_mesh_node_statistics_accumulate(uint8_t *data, uint32_t value, uint16_t type)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t sequence_num = (data[0] << 8) | data[1];
|
||||
|
||||
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY);
|
||||
|
||||
for (i = 0; i < ble_mesh_node_statistics.total_package_num; i++) {
|
||||
/* Filter out repeated packages during retransmission */
|
||||
if (ble_mesh_node_statistics.package_index[i] == sequence_num) {
|
||||
xSemaphoreGive(ble_mesh_node_sema);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// package type wrong
|
||||
if (data[2] != type) {
|
||||
xSemaphoreGive(ble_mesh_node_sema);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < ble_mesh_node_statistics.total_package_num; i++) {
|
||||
/* Judge whether the package is received for the first time */
|
||||
if (ble_mesh_node_statistics.package_index[i] == 0) {
|
||||
ble_mesh_node_statistics.package_index[i] = sequence_num;
|
||||
ble_mesh_node_statistics.package_num += 1;
|
||||
ble_mesh_node_statistics.statistics += value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
xSemaphoreGive(ble_mesh_node_sema);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ble_mesh_node_statistics_init(uint16_t package_num)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
ble_mesh_node_statistics.package_index = malloc(sizeof(uint16_t) * package_num);
|
||||
ble_mesh_node_statistics.total_package_num = package_num;
|
||||
if (ble_mesh_node_statistics.package_index == NULL) {
|
||||
ESP_LOGE(TAG, " %s, %d malloc fail", __func__, __LINE__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
ble_mesh_node_statistics.package_num = 0;
|
||||
for (i = 0; i < package_num; i++) {
|
||||
ble_mesh_node_statistics.package_index[i] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ble_mesh_node_statistics_destroy(void)
|
||||
{
|
||||
if (ble_mesh_node_statistics.package_index != NULL) {
|
||||
free(ble_mesh_node_statistics.package_index);
|
||||
}
|
||||
}
|
||||
|
||||
void ble_mesh_create_send_data(char *data, uint16_t byte_num, uint16_t sequence_num, uint32_t opcode)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
// first two bytes are sequence num, third is type
|
||||
data[0] = sequence_num >> 8;
|
||||
data[1] = sequence_num & 0xFF;
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET:
|
||||
data[2] = VENDOR_MODEL_PERF_OPERATION_TYPE_GET;
|
||||
break;
|
||||
case ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET:
|
||||
data[2] = VENDOR_MODEL_PERF_OPERATION_TYPE_SET;
|
||||
break;
|
||||
case ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK:
|
||||
data[2] = VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 3; i < byte_num; i++) {
|
||||
data[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
void ble_mesh_test_performance_client_model_get(void)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t succeed_packet_count;
|
||||
uint32_t sum_time = 0;
|
||||
uint32_t failed_packet_num = 0;
|
||||
uint32_t rtt = 0;
|
||||
|
||||
for (i = 0, succeed_packet_count = 0; i < test_perf_statistics.test_num; i++) {
|
||||
if (test_perf_statistics.time[i] != 0) {
|
||||
sum_time += test_perf_statistics.time[i];
|
||||
succeed_packet_count += 1;
|
||||
} else {
|
||||
failed_packet_num += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(succeed_packet_count != 0){
|
||||
rtt = (int)(sum_time / succeed_packet_count);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "VendorModel:Statistics,%" PRIu32 ",%" PRIu32, failed_packet_num, rtt);
|
||||
}
|
||||
|
||||
void ble_mesh_test_performance_client_model_get_received_percent(void)
|
||||
{
|
||||
uint32_t i, j;
|
||||
uint32_t max_time = 1400;
|
||||
uint32_t min_time = 0;
|
||||
uint32_t time_level_num = 0;
|
||||
typedef struct {
|
||||
uint16_t time_level;
|
||||
uint16_t time_num;
|
||||
} statistics_time_performance;
|
||||
statistics_time_performance *statistics_time_percent;
|
||||
|
||||
time_level_num = ((max_time - min_time) / 50 + 1);
|
||||
statistics_time_percent = malloc(sizeof(statistics_time_performance) * time_level_num);
|
||||
if (statistics_time_percent == NULL) {
|
||||
ESP_LOGI(TAG, "malloc error");
|
||||
return;
|
||||
}
|
||||
|
||||
for (j = 0; j < time_level_num; j++) {
|
||||
statistics_time_percent[j].time_level = min_time + 50 * j;
|
||||
statistics_time_percent[j].time_num = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < test_perf_statistics.test_num; i++) {
|
||||
for (j = 0; j < time_level_num; j++) {
|
||||
if (test_perf_statistics.time[i] > max_time) {
|
||||
j -= 1;
|
||||
break;
|
||||
}
|
||||
if (test_perf_statistics.time[i] >= min_time + 50 * j
|
||||
&& test_perf_statistics.time[i] < min_time + 50 * (j + 1)) {
|
||||
statistics_time_percent[j].time_num += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for script match
|
||||
ESP_LOGI(TAG, "VendorModel:Statistics");
|
||||
for (j = 0; j < time_level_num; j++) {
|
||||
ESP_LOGI("", "%d:%d", statistics_time_percent[j].time_level, statistics_time_percent[j].time_num);
|
||||
}
|
||||
free(statistics_time_percent);
|
||||
}
|
||||
|
||||
void ble_mesh_test_performance_client_model_accumulate_statistics(uint32_t value)
|
||||
{
|
||||
test_perf_statistics.statistics += value;
|
||||
}
|
||||
|
||||
int ble_mesh_test_performance_client_model_accumulate_time(uint16_t time, uint8_t *data, uint8_t ack_ttl, uint16_t length)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t sequence_num = 0;
|
||||
uint16_t node_received_ttl = 0;
|
||||
|
||||
if (data != NULL) {
|
||||
sequence_num = (data[0] << 8) | data[1];
|
||||
if (data[2] == VENDOR_MODEL_PERF_OPERATION_TYPE_SET) {
|
||||
node_received_ttl = data[3];
|
||||
}
|
||||
}
|
||||
for (i = 0; i < test_perf_statistics.test_num; i++) {
|
||||
if (test_perf_statistics.package_index[i] == sequence_num) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < test_perf_statistics.test_num; i++) {
|
||||
if (test_perf_statistics.package_index[i] == 0) {
|
||||
test_perf_statistics.package_index[i] = sequence_num;
|
||||
if (data[2] == VENDOR_MODEL_PERF_OPERATION_TYPE_SET) {
|
||||
if (node_received_ttl == test_perf_statistics.ttl) {
|
||||
test_perf_statistics.time[i] = time;
|
||||
} else {
|
||||
test_perf_statistics.time[i] = 0;
|
||||
}
|
||||
} else if (data[2] == VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK) {
|
||||
test_perf_statistics.time[i] = time;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ble_mesh_test_performance_client_model_init(uint16_t node_num, uint32_t test_num, uint8_t ttl)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
test_perf_statistics.time = malloc(test_num * sizeof(uint16_t));
|
||||
if (test_perf_statistics.time == NULL) {
|
||||
ESP_LOGE(TAG, " %s %d, malloc fail", __func__, __LINE__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
test_perf_statistics.package_index = malloc(test_num * sizeof(uint16_t));
|
||||
if (test_perf_statistics.package_index == NULL) {
|
||||
ESP_LOGE(TAG, " %s %d, malloc fail", __func__, __LINE__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
for (i = 0; i < test_num; i++) {
|
||||
test_perf_statistics.time[i] = 0;
|
||||
test_perf_statistics.package_index[i] = 0;
|
||||
}
|
||||
|
||||
test_perf_statistics.test_num = test_num;
|
||||
test_perf_statistics.node_num = node_num;
|
||||
test_perf_statistics.ttl = ttl;
|
||||
test_perf_statistics.statistics = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ble_mesh_test_performance_client_model_destroy(void)
|
||||
{
|
||||
if (test_perf_statistics.time != NULL) {
|
||||
free(test_perf_statistics.time);
|
||||
}
|
||||
|
||||
if (test_perf_statistics.package_index != NULL) {
|
||||
free(test_perf_statistics.package_index);
|
||||
}
|
||||
|
||||
test_perf_statistics.test_num = 0;
|
||||
test_perf_statistics.ttl = 0;
|
||||
test_perf_statistics.node_num = 0;
|
||||
test_perf_statistics.statistics = 0;
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_ADAPTER_H_
|
||||
#define _BLE_MESH_ADAPTER_H_
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "ble_mesh_console_lib.h"
|
||||
#include "ble_mesh_model.h"
|
||||
#include "esp_ble_mesh_local_data_operation_api.h"
|
||||
|
||||
#define TAG "ble_mesh_console"
|
||||
|
||||
#define TRANS_TYPE_MESH_PERF 0x01
|
||||
#define TRANS_MESH_SEND_MESSAGE 0x01
|
||||
#define TRANS_MESH_SEND_MESSAGE_EVT 0x01
|
||||
|
||||
typedef enum {
|
||||
VENDOR_MODEL_PERF_OPERATION_TYPE_GET = 1,
|
||||
VENDOR_MODEL_PERF_OPERATION_TYPE_SET,
|
||||
VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK
|
||||
} ble_mesh_perf_operation_type;
|
||||
|
||||
typedef struct {
|
||||
uint8_t current;
|
||||
uint8_t previous;
|
||||
char *name;
|
||||
} ble_mesh_node_status;
|
||||
|
||||
typedef struct {
|
||||
bool need_ack;
|
||||
uint8_t ttl;
|
||||
uint16_t length;
|
||||
uint16_t test_num;
|
||||
uint16_t address;
|
||||
uint16_t app_idx;
|
||||
uint16_t net_idx;
|
||||
uint32_t opcode;
|
||||
esp_ble_mesh_model_t *model;
|
||||
esp_ble_mesh_dev_role_t device_role;
|
||||
} ble_mesh_test_perf_throughput_data;
|
||||
|
||||
typedef struct {
|
||||
uint32_t statistics;
|
||||
uint32_t test_num;
|
||||
uint16_t test_length;
|
||||
uint16_t node_num;
|
||||
uint16_t *time;
|
||||
uint16_t *package_index;
|
||||
uint8_t ttl;
|
||||
} ble_mesh_performance_statistics_t;
|
||||
extern ble_mesh_performance_statistics_t test_perf_statistics;
|
||||
|
||||
typedef struct {
|
||||
uint32_t statistics;
|
||||
uint32_t package_num;
|
||||
uint16_t *package_index;
|
||||
uint32_t total_package_num;
|
||||
} ble_mesh_node_statistics_t;
|
||||
extern ble_mesh_node_statistics_t ble_mesh_node_statistics;
|
||||
|
||||
extern SemaphoreHandle_t ble_mesh_node_sema;
|
||||
extern ble_mesh_node_status node_status;
|
||||
|
||||
#define SEND_MESSAGE_TIMEOUT (30000/portTICK_PERIOD_MS)
|
||||
|
||||
#define arg_int_to_value(src_msg, dst_msg, message) do { \
|
||||
if (src_msg->count != 0) {\
|
||||
ESP_LOGD(TAG, "\n%s, %s", __func__, message);\
|
||||
dst_msg = src_msg->ival[0];\
|
||||
} \
|
||||
} while(0) \
|
||||
|
||||
#define ble_mesh_node_get_value(index, key, value) do { \
|
||||
uint16_t _index = 0; \
|
||||
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
|
||||
for (_index = 0; _index < NODE_MAX_GROUP_CONFIG; _index) { \
|
||||
if (node_set_prestore_params[_index].key == value) { \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
index = _index; \
|
||||
xSemaphoreGive(ble_mesh_node_sema); \
|
||||
} while(0) \
|
||||
|
||||
#define ble_mesh_node_set_state(status) do { \
|
||||
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
|
||||
node_status.previous = node_status.current; \
|
||||
node_status.current = status; \
|
||||
xSemaphoreGive(ble_mesh_node_sema); \
|
||||
}while(0) \
|
||||
|
||||
#define ble_mesh_node_get_state(status) do { \
|
||||
xSemaphoreTake(ble_mesh_node_sema, portMAX_DELAY); \
|
||||
status = node_status.current; \
|
||||
xSemaphoreGive(ble_mesh_node_sema); \
|
||||
}while(0) \
|
||||
|
||||
#define ble_mesh_callback_check_err_code(err_code, message) do { \
|
||||
if (err_code == ESP_OK) { \
|
||||
ESP_LOGI(TAG, "%s,OK", message); \
|
||||
} else { \
|
||||
ESP_LOGE(TAG, "%s,Fail,%d", message, err_code); \
|
||||
} \
|
||||
}while(0) \
|
||||
|
||||
int ble_mesh_init_node_prestore_params(void);
|
||||
void ble_mesh_deinit_node_prestore_params(void);
|
||||
void ble_mesh_set_node_prestore_params(uint16_t netkey_index, uint16_t unicast_addr);
|
||||
esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id);
|
||||
void ble_mesh_node_statistics_get(void);
|
||||
int ble_mesh_node_statistics_accumulate(uint8_t *data, uint32_t value, uint16_t type);
|
||||
int ble_mesh_node_statistics_init(uint16_t package_num);
|
||||
void ble_mesh_node_statistics_destroy(void);
|
||||
void ble_mesh_create_send_data(char *data, uint16_t byte_num, uint16_t sequence_num, uint32_t opcode);
|
||||
void ble_mesh_test_performance_client_model_get(void);
|
||||
void ble_mesh_test_performance_client_model_get_received_percent(void);
|
||||
void ble_mesh_test_performance_client_model_accumulate_statistics(uint32_t value);
|
||||
int ble_mesh_test_performance_client_model_accumulate_time(uint16_t time, uint8_t *data, uint8_t ack_ttl, uint16_t length);
|
||||
int ble_mesh_test_performance_client_model_init(uint16_t node_num, uint32_t test_num, uint8_t ttl);
|
||||
void ble_mesh_test_performance_client_model_destroy(void);
|
||||
|
||||
#endif //_BLE_MESH_ADAOTER_H_
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Console example - declarations of command registration functions.
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
// Register system functions
|
||||
void register_system(void);
|
||||
|
||||
// Register blutooth
|
||||
void register_bluetooth(void);
|
||||
|
||||
// Register mesh node cmd
|
||||
void ble_mesh_register_mesh_node(void);
|
||||
|
||||
// Register Test Perf client cmd
|
||||
void ble_mesh_register_mesh_test_performance_client(void);
|
||||
|
||||
#if (CONFIG_BLE_MESH_CFG_CLI)
|
||||
// Register mesh config client operation cmd
|
||||
void ble_mesh_register_configuration_client_model(void);
|
||||
#endif
|
||||
|
||||
// Register mesh config server and generic server operation cmd
|
||||
void ble_mesh_register_server(void);
|
||||
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
// Register mesh client operation cmd
|
||||
void ble_mesh_register_gen_onoff_client(void);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_CFG_CLI)
|
||||
// Register mesh config client operation cmd
|
||||
void ble_mesh_register_configuration_client_model(void);
|
||||
#endif
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "ble_mesh_console_lib.h"
|
||||
|
||||
static int hex2num(char c);
|
||||
static int hex2byte(const char *hex);
|
||||
|
||||
static int hex2num(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int hex2byte(const char *hex)
|
||||
{
|
||||
int a, b;
|
||||
a = hex2num(*hex++);
|
||||
if (a < 0) {
|
||||
return -1;
|
||||
}
|
||||
b = hex2num(*hex++);
|
||||
if (b < 0) {
|
||||
return -1;
|
||||
}
|
||||
return (a << 4) | b;
|
||||
}
|
||||
|
||||
int hexstr_2_bin(const char *hex, uint8_t *buf, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
int a;
|
||||
const char *ipos = hex;
|
||||
uint8_t *opos = buf;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
a = hex2byte(ipos);
|
||||
if (a < 0) {
|
||||
return -1;
|
||||
}
|
||||
*opos ++ = a;
|
||||
ipos += 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_value_string(char *value_in, char *buf)
|
||||
{
|
||||
int result = -1;
|
||||
uint8_t loop = 0;
|
||||
uint16_t length = strlen(value_in);
|
||||
|
||||
// address string, need sepcial test
|
||||
for (loop = 0; loop < 17 ; loop++) {
|
||||
if (loop % 3 == 2) {
|
||||
if (value_in[loop] == ':') {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (length > 2) {
|
||||
if (value_in[0] == '0' && value_in[1] == 'x') {
|
||||
buf[(length - 2) / 2] = 0;
|
||||
result = hexstr_2_bin(&value_in[2], (uint8_t *)buf, (length - 2) / 2);
|
||||
length = (length - 2) / 2;
|
||||
} else {
|
||||
strcpy(buf, value_in);
|
||||
result = 0;
|
||||
}
|
||||
} else {
|
||||
strcpy(buf, value_in);
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool str_2_mac(uint8_t *str, uint8_t *dest)
|
||||
{
|
||||
uint8_t loop = 0;
|
||||
uint8_t tmp = 0;
|
||||
uint8_t *src_p = str;
|
||||
|
||||
if (strlen((char *)src_p) != 17) { // must be like 12:34:56:78:90:AB
|
||||
return false;
|
||||
}
|
||||
|
||||
for (loop = 0; loop < 17 ; loop++) {
|
||||
if (loop % 3 == 2) {
|
||||
if (src_p[loop] != ':') {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((src_p[loop] >= '0') && (src_p[loop] <= '9')) {
|
||||
tmp = tmp * 16 + src_p[loop] - '0';
|
||||
} else if ((src_p[loop] >= 'A') && (src_p[loop] <= 'F')) {
|
||||
tmp = tmp * 16 + src_p[loop] - 'A' + 10;
|
||||
} else if ((src_p[loop] >= 'a') && (src_p[loop] <= 'f')) {
|
||||
tmp = tmp * 16 + src_p[loop] - 'a' + 10;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (loop % 3 == 1) {
|
||||
*dest++ = tmp;
|
||||
tmp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_CONSOLE_LIB_H_
|
||||
#define _BLE_MESH_CONSOLE_LIB_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_console.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
|
||||
#ifndef MAC2STR
|
||||
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#endif
|
||||
|
||||
bool str_2_mac(uint8_t *str, uint8_t *dest);
|
||||
int hexstr_2_bin(const char *hex, uint8_t *buf, uint32_t len);
|
||||
int get_value_string(char *value_in, char *buf);
|
||||
|
||||
#endif //_BLE_MESH_CONSOLE_LIB_H_
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_vfs_dev.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "esp_console.h"
|
||||
#include "ble_mesh_console_decl.h"
|
||||
#include "ble_mesh_example_init.h"
|
||||
|
||||
#if CONFIG_STORE_HISTORY
|
||||
|
||||
#define MOUNT_PATH "/data"
|
||||
#define HISTORY_PATH MOUNT_PATH "/history.txt"
|
||||
|
||||
static void initialize_filesystem(void)
|
||||
{
|
||||
static wl_handle_t wl_handle;
|
||||
const esp_vfs_fat_mount_config_t mount_config = {
|
||||
.max_files = 4,
|
||||
.format_if_mount_failed = true
|
||||
};
|
||||
esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(MOUNT_PATH, "storage", &mount_config, &wl_handle);
|
||||
if (err != ESP_OK) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif // CONFIG_STORE_HISTORY
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
esp_err_t res;
|
||||
|
||||
nvs_flash_init();
|
||||
|
||||
// init and enable bluetooth
|
||||
res = bluetooth_init();
|
||||
if (res) {
|
||||
printf("esp32_bluetooth_init failed (ret %d)", res);
|
||||
}
|
||||
|
||||
esp_log_level_set("*", ESP_LOG_INFO);
|
||||
esp_log_level_set("ble_mesh_console", ESP_LOG_INFO);
|
||||
|
||||
esp_console_repl_t *repl = NULL;
|
||||
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
||||
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
||||
#if CONFIG_STORE_HISTORY
|
||||
initialize_filesystem();
|
||||
repl_config.history_save_path = HISTORY_PATH;
|
||||
#endif
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
repl_config.prompt = "esp32c3>";
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
repl_config.prompt = "esp32s3>";
|
||||
#else
|
||||
repl_config.prompt = "esp32>";
|
||||
#endif
|
||||
|
||||
// init console REPL environment
|
||||
repl_config.max_history_len = 1;
|
||||
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
||||
|
||||
/* Register commands */
|
||||
register_system();
|
||||
register_bluetooth();
|
||||
ble_mesh_register_mesh_node();
|
||||
ble_mesh_register_mesh_test_performance_client();
|
||||
ble_mesh_register_server();
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
ble_mesh_register_gen_onoff_client();
|
||||
#endif
|
||||
#if (CONFIG_BLE_MESH_CFG_CLI)
|
||||
ble_mesh_register_configuration_client_model();
|
||||
#endif
|
||||
printf("!!!ready!!!\n");
|
||||
// start console REPL
|
||||
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Console example - various system commands
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_console.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "ble_mesh_console_decl.h"
|
||||
|
||||
#define CONFIG_ESPTOOLPY_PORT "Which is choosen by Users for CMake"
|
||||
|
||||
static void register_free(void);
|
||||
static void register_restart(void);
|
||||
|
||||
void register_system(void)
|
||||
{
|
||||
register_free();
|
||||
register_restart();
|
||||
}
|
||||
|
||||
/** 'restart' command restarts the program */
|
||||
|
||||
static int restart(int argc, char **argv)
|
||||
{
|
||||
printf("%s, %s", __func__, "Restarting");
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
static void register_restart(void)
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "restart",
|
||||
.help = "Restart the program",
|
||||
.hint = NULL,
|
||||
.func = &restart,
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
/** 'free' command prints available heap memory */
|
||||
|
||||
static int free_mem(int argc, char **argv)
|
||||
{
|
||||
printf("freeheap:%" PRIu32 "\n", esp_get_free_heap_size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_free(void)
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "free",
|
||||
.help = "Get the total size of heap memory available",
|
||||
.hint = NULL,
|
||||
.func = &free_mem,
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "ble_mesh_model.h"
|
||||
uint8_t dev_uuid[16] = {0xdd, 0xdd};
|
||||
|
||||
ble_mesh_node_config_params ble_mesh_node_prestore_params[NODE_MAX_GROUP_CONFIG];
|
||||
|
||||
esp_ble_mesh_prov_t prov = {
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
.uuid = dev_uuid,
|
||||
#endif //CONFIG_BLE_MESH_NODE
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
.prov_uuid = dev_uuid,
|
||||
.prov_unicast_addr = 0x0001,
|
||||
.prov_start_address = 0x0005,
|
||||
.prov_attention = 0x00,
|
||||
.prov_algorithm = 0x00,
|
||||
.prov_pub_key_oob = 0x00,
|
||||
.prov_static_oob_val = NULL,
|
||||
.prov_static_oob_len = 0x00,
|
||||
.flags = 0x00,
|
||||
.iv_index = 0x00,
|
||||
#endif //CONFIG_BLE_MESH_PROVISIONER
|
||||
};
|
||||
|
||||
esp_ble_mesh_model_pub_t vendor_model_pub_config;
|
||||
|
||||
// Configuration server model
|
||||
esp_ble_mesh_cfg_srv_t cfg_srv = {
|
||||
.relay = ESP_BLE_MESH_RELAY_ENABLED,
|
||||
.beacon = ESP_BLE_MESH_BEACON_ENABLED,
|
||||
#if defined(CONFIG_BLE_MESH_FRIEND)
|
||||
.friend_state = ESP_BLE_MESH_FRIEND_ENABLED,
|
||||
#else
|
||||
.friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED,
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||
.gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED,
|
||||
#else
|
||||
.gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED,
|
||||
#endif
|
||||
.default_ttl = 7,
|
||||
|
||||
/* 3 transmissions with 20ms interval */
|
||||
.net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20),
|
||||
.relay_retransmit = ESP_BLE_MESH_TRANSMIT(2, 20),
|
||||
};
|
||||
|
||||
// Configuration Client model
|
||||
esp_ble_mesh_client_t cfg_cli;
|
||||
|
||||
esp_ble_mesh_model_t config_client_models[] = {
|
||||
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
|
||||
ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli),
|
||||
};
|
||||
|
||||
esp_ble_mesh_elem_t config_client_elements[] = {
|
||||
ESP_BLE_MESH_ELEMENT(0, config_client_models, ESP_BLE_MESH_MODEL_NONE),
|
||||
};
|
||||
|
||||
esp_ble_mesh_comp_t config_client_comp = {
|
||||
.cid = CID_ESP,
|
||||
.elements = config_client_elements,
|
||||
.element_count = ARRAY_SIZE(config_client_elements),
|
||||
};
|
||||
|
||||
// Generic OnOff Server model
|
||||
esp_ble_mesh_gen_onoff_srv_t onoff_server = {
|
||||
.rsp_ctrl.get_auto_rsp = ESP_BLE_MESH_SERVER_RSP_BY_APP,
|
||||
.rsp_ctrl.set_auto_rsp = ESP_BLE_MESH_SERVER_RSP_BY_APP,
|
||||
};
|
||||
|
||||
// Generic OnOff Client model
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
esp_ble_mesh_client_t gen_onoff_cli;
|
||||
#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI
|
||||
|
||||
//CONFIG VENDOR MODEL TEST PERFORMANCE
|
||||
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000
|
||||
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI 0x2001
|
||||
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET ESP_BLE_MESH_MODEL_OP_3(0x01, CID_ESP)
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET ESP_BLE_MESH_MODEL_OP_3(0x02, CID_ESP)
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK ESP_BLE_MESH_MODEL_OP_3(0x03, CID_ESP)
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS ESP_BLE_MESH_MODEL_OP_3(0x04, CID_ESP)
|
||||
|
||||
esp_ble_mesh_client_op_pair_t test_perf_cli_op_pair[] = {
|
||||
{ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET, ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS},
|
||||
{ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET, ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS},
|
||||
{ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK, ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS},
|
||||
};
|
||||
|
||||
esp_ble_mesh_client_t test_perf_cli = {
|
||||
.op_pair_size = ARRAY_SIZE(test_perf_cli_op_pair),
|
||||
.op_pair = test_perf_cli_op_pair,
|
||||
};
|
||||
|
||||
esp_ble_mesh_model_op_t test_perf_srv_op[] = {
|
||||
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET, 1),
|
||||
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET, 1),
|
||||
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK, 1),
|
||||
ESP_BLE_MESH_MODEL_OP_END,
|
||||
};
|
||||
|
||||
esp_ble_mesh_model_op_t test_perf_cli_op[] = {
|
||||
ESP_BLE_MESH_MODEL_OP(ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, 1),
|
||||
ESP_BLE_MESH_MODEL_OP_END,
|
||||
};
|
||||
|
||||
esp_ble_mesh_model_t config_models[] = {
|
||||
ESP_BLE_MESH_MODEL_CFG_SRV(&cfg_srv),
|
||||
ESP_BLE_MESH_MODEL_CFG_CLI(&cfg_cli),
|
||||
};
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_CFG_SRV_MODEL_H_
|
||||
#define _BLE_MESH_CFG_SRV_MODEL_H_
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#if (CONFIG_BLE_MESH_CFG_CLI)
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
#endif
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI
|
||||
|
||||
#define NODE_MAX_GROUP_CONFIG 3
|
||||
#define CID_ESP 0x02C4
|
||||
|
||||
extern uint8_t dev_uuid[16];
|
||||
|
||||
typedef struct {
|
||||
uint16_t net_idx;
|
||||
uint16_t unicast_addr;
|
||||
} ble_mesh_node_config_params;
|
||||
extern ble_mesh_node_config_params ble_mesh_node_prestore_params[NODE_MAX_GROUP_CONFIG];
|
||||
|
||||
extern esp_ble_mesh_prov_t prov;
|
||||
|
||||
extern esp_ble_mesh_model_pub_t vendor_model_pub_config;
|
||||
|
||||
// Configuration Server model
|
||||
extern esp_ble_mesh_cfg_srv_t cfg_srv;
|
||||
extern esp_ble_mesh_model_t config_server_models[];
|
||||
extern esp_ble_mesh_elem_t config_server_elements[];
|
||||
extern esp_ble_mesh_comp_t config_server_comp;
|
||||
|
||||
// Configuration Client model
|
||||
extern esp_ble_mesh_client_t cfg_cli;
|
||||
extern esp_ble_mesh_model_t config_client_models[];
|
||||
extern esp_ble_mesh_elem_t config_client_elements[];
|
||||
extern esp_ble_mesh_comp_t config_client_comp;
|
||||
|
||||
// Generic OnOff Server model
|
||||
extern esp_ble_mesh_gen_onoff_srv_t onoff_server;
|
||||
extern esp_ble_mesh_model_op_t gen_onoff_srv_model_op_config[];
|
||||
|
||||
// Generic OnOff Client model
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
extern esp_ble_mesh_client_t gen_onoff_cli;
|
||||
extern esp_ble_mesh_model_t gen_onoff_cli_models[];
|
||||
#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI
|
||||
|
||||
//CONFIG VENDOR MODEL TEST PERFORMANCE
|
||||
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000
|
||||
#define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI 0x2001
|
||||
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_GET ESP_BLE_MESH_MODEL_OP_3(0x01, CID_ESP)
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET ESP_BLE_MESH_MODEL_OP_3(0x02, CID_ESP)
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK ESP_BLE_MESH_MODEL_OP_3(0x03, CID_ESP)
|
||||
#define ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS ESP_BLE_MESH_MODEL_OP_3(0x04, CID_ESP)
|
||||
|
||||
extern esp_ble_mesh_client_t test_perf_cli;
|
||||
extern esp_ble_mesh_model_op_t test_perf_srv_op[];
|
||||
extern esp_ble_mesh_model_op_t test_perf_cli_op[];
|
||||
extern esp_ble_mesh_model_t config_models[];
|
||||
|
||||
#if (CONFIG_BLE_MESH_CFG_CLI)
|
||||
void ble_mesh_configuration_client_model_cb(esp_ble_mesh_cfg_client_cb_event_t event,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
void ble_mesh_generic_onoff_client_model_cb(esp_ble_mesh_generic_client_cb_event_t event,
|
||||
esp_ble_mesh_generic_client_cb_param_t *param);
|
||||
#endif
|
||||
|
||||
#if(CONFIG_BLE_MESH_GENERIC_SERVER)
|
||||
void ble_mesh_generic_server_model_cb(esp_ble_mesh_generic_server_cb_event_t event,
|
||||
esp_ble_mesh_generic_server_cb_param_t *param);
|
||||
#endif
|
||||
|
||||
void ble_mesh_vendor_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param);
|
||||
|
||||
#endif //_BLE_MESH_CFG_SRV_MODEL_H_
|
@ -1,405 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
#include "ble_mesh_adapter.h"
|
||||
|
||||
#if (CONFIG_BLE_MESH_CFG_CLI)
|
||||
typedef struct {
|
||||
struct arg_str *action_type;
|
||||
struct arg_str *set_state;
|
||||
struct arg_int *opcode;
|
||||
struct arg_int *count;
|
||||
struct arg_int *feature;
|
||||
struct arg_int *unicast_address;
|
||||
struct arg_int *appkey_index;
|
||||
struct arg_int *mod_id;
|
||||
struct arg_int *addr;
|
||||
struct arg_int *cid;
|
||||
struct arg_int *value;
|
||||
struct arg_int *relay_statue;
|
||||
struct arg_int *relay_transmit;
|
||||
struct arg_int *net_idx;
|
||||
struct arg_end *end;
|
||||
} ble_mesh_client_get_set_state_t;
|
||||
ble_mesh_client_get_set_state_t configuration_client_model_operation;
|
||||
|
||||
void ble_mesh_register_configuration_client_model_command(void);
|
||||
|
||||
void ble_mesh_register_configuration_client_model(void)
|
||||
{
|
||||
ble_mesh_register_configuration_client_model_command();
|
||||
}
|
||||
|
||||
void ble_mesh_configuration_client_model_cb(esp_ble_mesh_cfg_client_cb_event_t event,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param)
|
||||
{
|
||||
uint32_t opcode;
|
||||
ESP_LOGD(TAG, "enter %s, event = %x, error_code = %x", __func__, event, param->error_code);
|
||||
|
||||
if (!param->error_code) {
|
||||
opcode = param->params->opcode;
|
||||
switch (event) {
|
||||
case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT:
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
|
||||
ESP_LOGI(TAG, "CfgClient:beacon,0x%x", param->status_cb.beacon_status.beacon);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
ESP_LOGI(TAG, "CfgClient:page,0x%x,len,0x%x", param->status_cb.comp_data_status.page, param->status_cb.comp_data_status.composition_data->len);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET:
|
||||
ESP_LOGI(TAG, "CfgClient:ttl,0x%x", param->status_cb.default_ttl_status.default_ttl);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET:
|
||||
ESP_LOGI(TAG, "CfgClient:proxy,0x%x", param->status_cb.gatt_proxy_status.gatt_proxy);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_GET:
|
||||
ESP_LOGI(TAG, "CfgClient:relay,0x%x,retransmit,0x%x", param->status_cb.relay_status.relay, param->status_cb.relay_status.retransmit);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
if (param->status_cb.model_pub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CfgClient:PublishGet,OK,0x%x", param->status_cb.model_pub_status.publish_addr);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CfgClient:PublishGet,Fail");
|
||||
}
|
||||
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_GET:
|
||||
ESP_LOGI(TAG, "CfgClient:friend,0x%x", param->status_cb.friend_status.friend_state);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET:
|
||||
if (param->status_cb.heartbeat_pub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatPubGet,OK,destination:0x%x,countlog:0x%x,periodlog:0x%x,ttl:0x%x,features:0x%x,net_idx:0x%x",
|
||||
param->status_cb.heartbeat_pub_status.dst, param->status_cb.heartbeat_pub_status.count, param->status_cb.heartbeat_pub_status.period,
|
||||
param->status_cb.heartbeat_pub_status.ttl, param->status_cb.heartbeat_pub_status.features, param->status_cb.heartbeat_pub_status.net_idx);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatGet,Fail,%d", param->status_cb.heartbeat_pub_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
|
||||
if (param->status_cb.heartbeat_sub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatSubGet,OK,source:0x%x,destination:0x%x, periodlog:0x%x,countlog:0x%x,minhops:0x%x,maxhops:0x%x",
|
||||
param->status_cb.heartbeat_sub_status.src, param->status_cb.heartbeat_sub_status.dst, param->status_cb.heartbeat_sub_status.period,
|
||||
param->status_cb.heartbeat_sub_status.count, param->status_cb.heartbeat_sub_status.min_hops, param->status_cb.heartbeat_sub_status.max_hops);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatSubGet,Fail,%d", param->status_cb.heartbeat_sub_status.status);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "Not supported config client get message opcode");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
|
||||
ESP_LOGI(TAG, "CfgClient:beacon,0x%x", param->status_cb.beacon_status.beacon);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET:
|
||||
ESP_LOGI(TAG, "CfgClient:ttl,0x%x", param->status_cb.default_ttl_status.default_ttl);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET:
|
||||
ESP_LOGI(TAG, "CfgClient:proxy,0x%x", param->status_cb.gatt_proxy_status.gatt_proxy);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_SET:
|
||||
ESP_LOGI(TAG, "CfgClient:relay,0x%x, retransmit: 0x%x", param->status_cb.relay_status.relay, param->status_cb.relay_status.retransmit);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET:
|
||||
if (param->status_cb.model_pub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CfgClient:PublishSet,OK,0x%x", param->status_cb.model_pub_status.publish_addr);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CfgClient:PublishSet,Fail,%d", param->status_cb.model_pub_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD:
|
||||
if (param->status_cb.model_sub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CnfClient:SubAdd,OK,%x,%x", param->status_cb.model_sub_status.element_addr, param->status_cb.model_sub_status.sub_addr);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CnfClient:SubAdd,Fail,%x", param->status_cb.model_sub_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE:
|
||||
if (param->status_cb.model_sub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CnfClient:SubDel,OK,%x,%x", param->status_cb.model_sub_status.element_addr, param->status_cb.model_sub_status.sub_addr);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CnfClient:SubDel,Fail,%x", param->status_cb.model_sub_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE:
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD:
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE:
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE:
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD:
|
||||
if (param->status_cb.netkey_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CfgClient:NetKeyAdd,OK");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CfgClient:NetKeyAdd,Fail,%d", param->status_cb.netkey_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD:
|
||||
if (param->status_cb.appkey_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CnfClient:AddAppkey,OK,%x,%x,%x", param->status_cb.appkey_status.net_idx, param->status_cb.appkey_status.app_idx, param->params->ctx.addr);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CnfClient:AddAppkey,Fail,%x", param->status_cb.appkey_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND:
|
||||
if (param->status_cb.model_app_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CnfClient:AppkeyBind,OK,%x,%x,%x", param->status_cb.model_app_status.app_idx, param->status_cb.model_app_status.model_id, param->params->ctx.addr);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CnfClient:AppkeyBind,Fail,%x", param->status_cb.model_app_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_SET:
|
||||
ESP_LOGI(TAG, "CfgClient:friend: 0x%x", param->status_cb.friend_status.friend_state);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET:
|
||||
if (param->status_cb.heartbeat_pub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatPubSet,OK,destination:0x%x,countlog:0x%x, periodlog:0x%x,ttl:0x%x,features:0x%x,net_idx: 0x%x",
|
||||
param->status_cb.heartbeat_pub_status.dst, param->status_cb.heartbeat_pub_status.count, param->status_cb.heartbeat_pub_status.period,
|
||||
param->status_cb.heartbeat_pub_status.ttl, param->status_cb.heartbeat_pub_status.features, param->status_cb.heartbeat_pub_status.net_idx);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatSet,Fail,%d", param->status_cb.heartbeat_pub_status.status);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET:
|
||||
if (param->status_cb.heartbeat_sub_status.status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatSubSet,OK,source:0x%x,destination:0x%x, periodlog:0x%x,countlog:0x%x,minhops:0x%x,maxhops:0x%x",
|
||||
param->status_cb.heartbeat_sub_status.src, param->status_cb.heartbeat_sub_status.dst, param->status_cb.heartbeat_sub_status.period,
|
||||
param->status_cb.heartbeat_sub_status.count, param->status_cb.heartbeat_sub_status.min_hops, param->status_cb.heartbeat_sub_status.max_hops);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CfgClient:HeartBeatSubSet,Fail,%d", param->status_cb.heartbeat_sub_status.status);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "Not supported config client set message opcode");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
|
||||
ESP_LOGI(TAG, "CnfClient:Publish,OK");
|
||||
break;
|
||||
case ESP_BLE_MESH_CFG_CLIENT_EVT_MAX:
|
||||
ESP_LOGI(TAG, "CnfClient:MaxEvt");
|
||||
break;
|
||||
case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
|
||||
ESP_LOGI(TAG, "CfgClient:TimeOut");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "CfgClient:InvalidEvent");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGI(TAG, "CnfClient:Fail,%d", param->error_code);
|
||||
}
|
||||
ESP_LOGD(TAG, "exit %s", __func__);
|
||||
}
|
||||
|
||||
int ble_mesh_configuration_client_model_operation(int argc, char **argv)
|
||||
{
|
||||
int err = ESP_OK;
|
||||
esp_ble_mesh_elem_t *element = NULL;
|
||||
const uint8_t *app_key = NULL;
|
||||
esp_ble_mesh_cfg_default_ttl_set_t ttl_set;
|
||||
esp_ble_mesh_cfg_gatt_proxy_set_t proxy_set;
|
||||
esp_ble_mesh_cfg_app_key_add_t app_key_add;
|
||||
esp_ble_mesh_cfg_heartbeat_pub_set_t heartbeat_pub_set;
|
||||
esp_ble_mesh_cfg_model_pub_set_t mod_pub_set = {
|
||||
.company_id = 0xFFFF,
|
||||
.cred_flag = false,
|
||||
.publish_period = 0,
|
||||
.publish_retransmit = 0,
|
||||
};
|
||||
esp_ble_mesh_cfg_model_sub_add_t mod_sub_add = {
|
||||
.company_id = 0xFFFF,
|
||||
};
|
||||
esp_ble_mesh_cfg_model_sub_delete_t mod_sub_del = {
|
||||
.company_id = 0xFFFF,
|
||||
};
|
||||
esp_ble_mesh_cfg_relay_set_t relay_set;
|
||||
esp_ble_mesh_client_common_param_t client_common = {
|
||||
.msg_role = ROLE_PROVISIONER,
|
||||
.msg_timeout = 0,
|
||||
.ctx.send_ttl = 7,
|
||||
};
|
||||
esp_ble_mesh_cfg_client_get_state_t get_state = {
|
||||
.comp_data_get.page = 0,
|
||||
.model_pub_get.company_id = 0xFFFF,
|
||||
};
|
||||
esp_ble_mesh_cfg_model_app_bind_t mod_app_bind = {
|
||||
.company_id = 0xFFFF,
|
||||
};
|
||||
|
||||
element = esp_ble_mesh_find_element(esp_ble_mesh_get_primary_element_address());
|
||||
if (!element) {
|
||||
ESP_LOGE(TAG, "Element 0x%04x not exists", esp_ble_mesh_get_primary_element_address());
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
client_common.model = esp_ble_mesh_find_sig_model(element, ESP_BLE_MESH_MODEL_ID_CONFIG_CLI);
|
||||
if (!client_common.model) {
|
||||
ESP_LOGE(TAG, "CfgClient:LoadModel,Fail");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
int nerrors = arg_parse(argc, argv, (void **) &configuration_client_model_operation);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, configuration_client_model_operation.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.opcode->count != 0) {
|
||||
client_common.opcode = configuration_client_model_operation.opcode->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.net_idx->count != 0) {
|
||||
client_common.ctx.net_idx = configuration_client_model_operation.net_idx->ival[0];
|
||||
app_key_add.net_idx = configuration_client_model_operation.net_idx->ival[0];
|
||||
heartbeat_pub_set.net_idx = configuration_client_model_operation.net_idx->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.unicast_address->count != 0) {
|
||||
client_common.ctx.addr = configuration_client_model_operation.unicast_address->ival[0];
|
||||
get_state.model_pub_get.element_addr = configuration_client_model_operation.unicast_address->ival[0];
|
||||
mod_app_bind.element_addr = configuration_client_model_operation.unicast_address->ival[0];
|
||||
mod_sub_add.element_addr = configuration_client_model_operation.unicast_address->ival[0];
|
||||
mod_sub_del.element_addr = configuration_client_model_operation.unicast_address->ival[0];
|
||||
mod_pub_set.element_addr = configuration_client_model_operation.unicast_address->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.appkey_index->count != 0) {
|
||||
client_common.ctx.app_idx = configuration_client_model_operation.appkey_index->ival[0];
|
||||
mod_app_bind.model_app_idx = configuration_client_model_operation.appkey_index->ival[0];
|
||||
app_key_add.app_idx = configuration_client_model_operation.appkey_index->ival[0];
|
||||
mod_pub_set.publish_app_idx = configuration_client_model_operation.appkey_index->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.value->count != 0) {
|
||||
ttl_set.ttl = configuration_client_model_operation.value->ival[0];
|
||||
proxy_set.gatt_proxy = configuration_client_model_operation.value->ival[0];
|
||||
mod_pub_set.publish_ttl = configuration_client_model_operation.value->ival[0];
|
||||
heartbeat_pub_set.ttl = configuration_client_model_operation.value->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.addr->count != 0) {
|
||||
mod_sub_del.sub_addr = configuration_client_model_operation.addr->ival[0];
|
||||
mod_sub_add.sub_addr = configuration_client_model_operation.addr->ival[0];
|
||||
mod_pub_set.publish_addr = configuration_client_model_operation.addr->ival[0];
|
||||
heartbeat_pub_set.dst = configuration_client_model_operation.addr->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.mod_id->count != 0) {
|
||||
mod_app_bind.model_id = configuration_client_model_operation.mod_id->ival[0];
|
||||
mod_sub_add.model_id = configuration_client_model_operation.mod_id->ival[0];
|
||||
mod_sub_del.model_id = configuration_client_model_operation.mod_id->ival[0];
|
||||
get_state.model_pub_get.model_id = configuration_client_model_operation.mod_id->ival[0];;
|
||||
mod_pub_set.model_id = configuration_client_model_operation.mod_id->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.relay_statue->count != 0) {
|
||||
relay_set.relay = configuration_client_model_operation.relay_statue->ival[0];
|
||||
mod_pub_set.publish_period = configuration_client_model_operation.relay_statue->ival[0];
|
||||
heartbeat_pub_set.period = configuration_client_model_operation.relay_statue->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.relay_transmit->count != 0) {
|
||||
relay_set.relay_retransmit = configuration_client_model_operation.relay_transmit->ival[0];
|
||||
mod_pub_set.publish_retransmit = configuration_client_model_operation.relay_transmit->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.cid->count != 0) {
|
||||
mod_app_bind.company_id = configuration_client_model_operation.cid->ival[0];
|
||||
mod_sub_del.company_id = configuration_client_model_operation.cid->ival[0];
|
||||
mod_sub_add.company_id = configuration_client_model_operation.cid->ival[0];
|
||||
mod_pub_set.company_id = configuration_client_model_operation.cid->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.count->count != 0) {
|
||||
heartbeat_pub_set.count = configuration_client_model_operation.count->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.feature->count != 0) {
|
||||
heartbeat_pub_set.feature = configuration_client_model_operation.feature->ival[0];
|
||||
}
|
||||
|
||||
if (configuration_client_model_operation.action_type->count != 0) {
|
||||
if (strcmp(configuration_client_model_operation.action_type->sval[0], "get") == 0) {
|
||||
err = esp_ble_mesh_config_client_get_state(&client_common, &get_state);
|
||||
} else if (strcmp(configuration_client_model_operation.action_type->sval[0], "set") == 0) {
|
||||
if (configuration_client_model_operation.set_state->count != 0) {
|
||||
if (strcmp(configuration_client_model_operation.set_state->sval[0], "appkey") == 0) {
|
||||
app_key = esp_ble_mesh_provisioner_get_local_app_key(app_key_add.net_idx, app_key_add.app_idx);
|
||||
if (app_key == NULL) {
|
||||
ESP_LOGE(TAG, "CnfClient:AddAppkey,Fail,app key or network key NULL");
|
||||
return ESP_FAIL;
|
||||
} else {
|
||||
memcpy(app_key_add.app_key, app_key, 16);
|
||||
}
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&app_key_add);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "appbind") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&mod_app_bind);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "ttl") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&ttl_set);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "proxy") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&proxy_set);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "subadd") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&mod_sub_add);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "subdel") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&mod_sub_del);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "relay") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&relay_set);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "pubset") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&mod_pub_set);
|
||||
} else if (strcmp(configuration_client_model_operation.set_state->sval[0], "reset") == 0) {
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, NULL);
|
||||
}else if(strcmp(configuration_client_model_operation.set_state->sval[0], "hbpub") == 0){
|
||||
err = esp_ble_mesh_config_client_set_state(&client_common, (esp_ble_mesh_cfg_client_set_state_t *)&heartbeat_pub_set);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "ConfigClient:OK");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "ConfigClient:Fail");
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
void ble_mesh_register_configuration_client_model_command(void)
|
||||
{
|
||||
configuration_client_model_operation.action_type = arg_str1("z", NULL, "<action>", "action type");
|
||||
configuration_client_model_operation.set_state = arg_str0("x", NULL, "<state>", "set state");
|
||||
configuration_client_model_operation.opcode = arg_int0("o", NULL, "<opcode>", "message opcode");
|
||||
configuration_client_model_operation.unicast_address = arg_int0("u", NULL, "<address>", "unicast address");
|
||||
configuration_client_model_operation.net_idx = arg_int0("n", NULL, "<network>", "net work index");
|
||||
configuration_client_model_operation.appkey_index = arg_int0("i", NULL, "<index>", "appkey index");
|
||||
configuration_client_model_operation.relay_statue = arg_int0("r", NULL, "<relay>", "relay statue");
|
||||
configuration_client_model_operation.relay_transmit = arg_int0("t", NULL, "<transmit>", "relay transmit");
|
||||
configuration_client_model_operation.cid = arg_int0("c", NULL, "<cid>", "company id");
|
||||
configuration_client_model_operation.value = arg_int0("v", NULL, "<value>", "value");
|
||||
configuration_client_model_operation.addr = arg_int0("a", NULL, "<address>", "address");
|
||||
configuration_client_model_operation.mod_id = arg_int0("m", NULL, "<mod id>", "model id");
|
||||
configuration_client_model_operation.count = arg_int0("b", NULL, "<heartbeat count>", "heartbeat count");
|
||||
configuration_client_model_operation.feature = arg_int0("f", NULL, "<features>", "features");
|
||||
configuration_client_model_operation.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t client_stconfiguration_client_model_operationate_cmd = {
|
||||
.command = "bmccm",
|
||||
.help = "ble mesh configuration client model",
|
||||
.hint = NULL,
|
||||
.func = &ble_mesh_configuration_client_model_operation,
|
||||
.argtable = &configuration_client_model_operation,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&client_stconfiguration_client_model_operationate_cmd));
|
||||
}
|
||||
#endif
|
@ -1,243 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "esp_timer.h"
|
||||
#include "ble_mesh_adapter.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
|
||||
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
typedef struct {
|
||||
struct arg_str *action_type;
|
||||
struct arg_int *op_en;
|
||||
struct arg_int *unicast_address;
|
||||
struct arg_int *onoff_state;
|
||||
struct arg_int *trans_id;
|
||||
struct arg_int *trans_time;
|
||||
struct arg_int *delay;
|
||||
struct arg_int *opcode;
|
||||
struct arg_int *appkey_idx;
|
||||
struct arg_int *role;
|
||||
struct arg_int *net_idx;
|
||||
struct arg_end *end;
|
||||
} ble_mesh_gen_onoff_state_t;
|
||||
static ble_mesh_gen_onoff_state_t gen_onoff_state;
|
||||
|
||||
void ble_mesh_register_gen_onoff_client_command(void);
|
||||
|
||||
void ble_mesh_register_gen_onoff_client(void)
|
||||
{
|
||||
ble_mesh_register_gen_onoff_client_command();
|
||||
}
|
||||
|
||||
void ble_mesh_generic_onoff_client_model_cb(esp_ble_mesh_generic_client_cb_event_t event,
|
||||
esp_ble_mesh_generic_client_cb_param_t *param)
|
||||
{
|
||||
uint32_t opcode = param->params->opcode;
|
||||
|
||||
ESP_LOGD(TAG, "enter %s: event is %d, error code is %d, opcode is 0x%" PRIx32,
|
||||
__func__, event, param->error_code, opcode);
|
||||
|
||||
switch (event) {
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT: {
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET:
|
||||
if (param->error_code == ESP_OK) {
|
||||
ESP_LOGI(TAG, "GenOnOffClient:GetStatus,OK,%d", param->status_cb.onoff_status.present_onoff);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "GenOnOffClient:GetStatus,Fail,%d", param->error_code);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT: {
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET:
|
||||
if (param->error_code == ESP_OK) {
|
||||
ESP_LOGI(TAG, "GenOnOffClient:SetStatus,OK,%d", param->status_cb.onoff_status.present_onoff);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "GenOnOffClient:SetStatus,Fail,%d", param->error_code);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK:
|
||||
if (param->error_code == ESP_OK) {
|
||||
ESP_LOGI(TAG, "GenOnOffClient:SetUNACK,OK");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "GenOnOffClient:SetUNACK,Fail,%d", param->error_code);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT: {
|
||||
if (param->error_code == ESP_OK) {
|
||||
ESP_LOGI(TAG, "GenOnOffClient:Publish,OK");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "GenOnOffClient:Publish,Fail,%d", param->error_code);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
|
||||
ESP_LOGE(TAG, "GenOnOffClient:TimeOut,%d", param->error_code);
|
||||
break;
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX:
|
||||
ESP_LOGE(TAG, "GenONOFFClient:InvalidEvt,%d", param->error_code);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ESP_LOGD(TAG, "exit %s", __func__);
|
||||
}
|
||||
|
||||
void ble_mesh_generic_server_model_cb(esp_ble_mesh_generic_server_cb_event_t event,
|
||||
esp_ble_mesh_generic_server_cb_param_t *param)
|
||||
{
|
||||
uint32_t opcode = param->ctx.recv_op;
|
||||
uint8_t status;
|
||||
|
||||
ESP_LOGD(TAG, "enter %s: event is %d, opcode is 0x%04" PRIx32, __func__, event, opcode);
|
||||
|
||||
switch (event) {
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT:
|
||||
if (opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET) {
|
||||
ESP_LOGI(TAG, "GenOnOffServer:Set,OK,%d", param->value.state_change.onoff_set.onoff);
|
||||
ble_mesh_node_set_state(param->value.state_change.onoff_set.onoff);
|
||||
} else if (opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK) {
|
||||
ESP_LOGI(TAG, "GenOnOffServer:SetUnAck,OK,%d", param->value.state_change.onoff_set.onoff);
|
||||
ble_mesh_node_set_state(param->value.state_change.onoff_set.onoff);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_RECV_GET_MSG_EVT: {
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET:
|
||||
ESP_LOGI(TAG, "GenOnOffServer:Get,OK");
|
||||
ble_mesh_node_get_state(status);
|
||||
esp_ble_mesh_server_model_send_msg(param->model, ¶m->ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS,
|
||||
sizeof(status), &status);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT: {
|
||||
if (opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET || opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK) {
|
||||
esp_ble_mesh_gen_onoff_srv_t *srv = param->model->user_data;
|
||||
if (param->value.set.onoff.op_en == false) {
|
||||
srv->state.onoff = param->value.set.onoff.onoff;
|
||||
} else {
|
||||
/* TODO: Delay and state transition */
|
||||
srv->state.onoff = param->value.set.onoff.onoff;
|
||||
}
|
||||
}
|
||||
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET:
|
||||
ESP_LOGI(TAG, "GenOnOffServer:Set,OK,%d", param->value.set.onoff.onoff);
|
||||
ble_mesh_node_set_state(param->value.set.onoff.onoff);
|
||||
ble_mesh_node_get_state(status);
|
||||
esp_ble_mesh_server_model_send_msg(param->model, ¶m->ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS,
|
||||
sizeof(status), &status);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK:
|
||||
ble_mesh_node_set_state(param->value.set.onoff.onoff);
|
||||
ESP_LOGI(TAG, "GenOnOffServer:SetUnAck,OK,%d", param->value.set.onoff.onoff);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ESP_LOGD(TAG, "exit %s", __func__);
|
||||
}
|
||||
|
||||
int ble_mesh_generic_onoff_client_model(int argc, char **argv)
|
||||
{
|
||||
int err = ESP_OK;
|
||||
esp_ble_mesh_elem_t *element = NULL;
|
||||
esp_ble_mesh_generic_client_set_state_t gen_client_set;
|
||||
esp_ble_mesh_generic_client_get_state_t gen_client_get;
|
||||
esp_ble_mesh_client_common_param_t onoff_common = {
|
||||
.msg_timeout = 0,
|
||||
.ctx.send_ttl = 7,
|
||||
};
|
||||
|
||||
int nerrors = arg_parse(argc, argv, (void **) &gen_onoff_state);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, gen_onoff_state.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
element = esp_ble_mesh_find_element(esp_ble_mesh_get_primary_element_address());
|
||||
if (!element) {
|
||||
ESP_LOGE(TAG, "Element 0x%04x not exists", esp_ble_mesh_get_primary_element_address());
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
onoff_common.model = esp_ble_mesh_find_sig_model(element, ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI);
|
||||
if (!onoff_common.model) {
|
||||
ESP_LOGI(TAG, "GenONOFFClient:LoadModel,Fail");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
arg_int_to_value(gen_onoff_state.appkey_idx, onoff_common.ctx.app_idx, "appkey_index");
|
||||
arg_int_to_value(gen_onoff_state.opcode, onoff_common.opcode, "opcode");
|
||||
arg_int_to_value(gen_onoff_state.role, onoff_common.msg_role, "role");
|
||||
arg_int_to_value(gen_onoff_state.unicast_address, onoff_common.ctx.addr, "address");
|
||||
arg_int_to_value(gen_onoff_state.net_idx, onoff_common.ctx.net_idx, "network key index");
|
||||
arg_int_to_value(gen_onoff_state.op_en, gen_client_set.onoff_set.op_en, "op_en");
|
||||
arg_int_to_value(gen_onoff_state.onoff_state, gen_client_set.onoff_set.onoff, "onoff");
|
||||
arg_int_to_value(gen_onoff_state.trans_id, gen_client_set.onoff_set.tid, "tid");
|
||||
arg_int_to_value(gen_onoff_state.trans_time, gen_client_set.onoff_set.trans_time, "trans_time");
|
||||
arg_int_to_value(gen_onoff_state.delay, gen_client_set.onoff_set.delay, "delay");
|
||||
|
||||
if (gen_onoff_state.action_type->count != 0) {
|
||||
if (strcmp(gen_onoff_state.action_type->sval[0], "get") == 0) {
|
||||
err = esp_ble_mesh_generic_client_get_state(&onoff_common, &gen_client_get);
|
||||
}
|
||||
else if (strcmp(gen_onoff_state.action_type->sval[0], "set") == 0) {
|
||||
err = esp_ble_mesh_generic_client_set_state(&onoff_common, &gen_client_set);
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
void ble_mesh_register_gen_onoff_client_command(void)
|
||||
{
|
||||
gen_onoff_state.action_type = arg_str1("z", NULL, "<action>", "action type");
|
||||
gen_onoff_state.opcode = arg_int0("o", NULL, "<opcode>", "message opcode");
|
||||
gen_onoff_state.appkey_idx = arg_int0("a", NULL, "<appkey>", "appkey index");
|
||||
gen_onoff_state.role = arg_int0("r", NULL, "<role>", "role");
|
||||
gen_onoff_state.unicast_address = arg_int0("u", NULL, "<address>", "unicast address");
|
||||
gen_onoff_state.net_idx = arg_int0("n", NULL, "<netkey index>", "network key index");
|
||||
gen_onoff_state.op_en = arg_int0("e", NULL, "<optional>", "whether optional parameters included");
|
||||
gen_onoff_state.onoff_state = arg_int0("s", NULL, "<state>", "present onoff state");
|
||||
gen_onoff_state.trans_id = arg_int0("i", NULL, "<identifier>", "transaction identifier");
|
||||
gen_onoff_state.trans_time = arg_int0("t", NULL, "<time>", "time to complete state transition");
|
||||
gen_onoff_state.delay = arg_int0("d", NULL, "<delay>", "indicate message execution delay");
|
||||
gen_onoff_state.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t gen_onoff_state_cmd = {
|
||||
.command = "bmgocm",
|
||||
.help = "ble mesh generic onoff client model",
|
||||
.hint = NULL,
|
||||
.func = &ble_mesh_generic_onoff_client_model,
|
||||
.argtable = &gen_onoff_state,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&gen_onoff_state_cmd));
|
||||
}
|
||||
|
||||
#endif
|
@ -1,325 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/FreeRTOSConfig.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
#include "ble_mesh_adapter.h"
|
||||
#include "transaction.h"
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *action_type;
|
||||
struct arg_int *playload_byte;
|
||||
struct arg_int *test_num;
|
||||
struct arg_int *opcode;
|
||||
struct arg_int *unicast_address;
|
||||
struct arg_int *ttl;
|
||||
struct arg_int *app_idx;
|
||||
struct arg_int *net_idx;
|
||||
struct arg_int *dev_role;
|
||||
struct arg_end *end;
|
||||
} ble_mesh_test_perf_client_model_t;
|
||||
ble_mesh_test_perf_client_model_t test_perf_client_model;
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *action_type;
|
||||
struct arg_int *test_size;
|
||||
struct arg_int *node_num;
|
||||
struct arg_int *ttl;
|
||||
struct arg_end *end;
|
||||
} ble_mesh_test_perf_client_model_statistics_t;
|
||||
ble_mesh_test_perf_client_model_statistics_t test_perf_client_model_statistics;
|
||||
|
||||
bool deinit_flag = false;
|
||||
|
||||
void ble_mesh_performance_client_model_command(void);
|
||||
|
||||
void ble_mesh_register_mesh_test_performance_client(void)
|
||||
{
|
||||
ble_mesh_performance_client_model_command();
|
||||
}
|
||||
|
||||
void ble_mesh_vendor_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param)
|
||||
{
|
||||
uint16_t result;
|
||||
uint8_t data[4];
|
||||
uint64_t *start_time = NULL;
|
||||
transaction_t *trans = NULL;
|
||||
|
||||
ESP_LOGD(TAG, "enter %s, event=%x", __func__, event);
|
||||
do {
|
||||
trans = transaction_get(TRANS_TYPE_MESH_PERF, TRANS_MESH_SEND_MESSAGE, trans);
|
||||
if (trans) {
|
||||
start_time = (uint64_t *)trans->input;
|
||||
break;
|
||||
}
|
||||
}while(trans);
|
||||
|
||||
switch (event) {
|
||||
case ESP_BLE_MESH_MODEL_OPERATION_EVT:
|
||||
if (param->model_operation.model != NULL && param->model_operation.model->op != NULL) {
|
||||
if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET) {
|
||||
ESP_LOGI(TAG, "VndSrvModel:SetAck,Success,%d", param->model_operation.ctx->recv_ttl);
|
||||
data[0] = param->model_operation.msg[0];
|
||||
data[1] = param->model_operation.msg[1];
|
||||
data[2] = param->model_operation.msg[2];
|
||||
data[3] = param->model_operation.ctx->recv_ttl;
|
||||
result = ble_mesh_node_statistics_accumulate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET);
|
||||
if (result == 0) {
|
||||
esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx,
|
||||
ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, sizeof(data), data);
|
||||
}
|
||||
} else if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK) {
|
||||
ESP_LOGI(TAG, "VndSrvModel:SetUnAck,Success,%d,%d", param->model_operation.ctx->recv_ttl, param->model_operation.length);
|
||||
result = ble_mesh_node_statistics_accumulate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK);
|
||||
} else if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS) {
|
||||
if (trans) {
|
||||
uint64_t current_time = esp_timer_get_time();
|
||||
result = ble_mesh_test_performance_client_model_accumulate_time(((uint32_t)(current_time - *start_time) / 1000), param->model_operation.msg,
|
||||
param->model_operation.ctx->recv_ttl, param->model_operation.length);
|
||||
transaction_set_events(trans, TRANS_MESH_SEND_MESSAGE_EVT);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_SEND_COMP_EVT:
|
||||
if (param->model_send_comp.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK) {
|
||||
transaction_set_events(trans, TRANS_MESH_SEND_MESSAGE_EVT);
|
||||
}
|
||||
if (param->model_send_comp.err_code == ESP_OK) {
|
||||
ESP_LOGI(TAG, "VndModel:ModelSend,OK");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "VndModel:ModelSend,Fail");
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_PUBLISH_COMP_EVT:
|
||||
ESP_LOGI(TAG, "VndModel:PublishSend,OK,0x%x,%d,", param->model_publish_comp.model->model_id, param->model_publish_comp.model->pub->msg->len);
|
||||
break;
|
||||
case ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT:
|
||||
ESP_LOGI(TAG, "VndModel:PublishReceive,OK,0x%06" PRIx32 ",%d,%d", param->client_recv_publish_msg.opcode, param->client_recv_publish_msg.length, param->client_recv_publish_msg.msg[1]);
|
||||
if (trans) {
|
||||
uint64_t current_time = esp_timer_get_time();
|
||||
result = ble_mesh_test_performance_client_model_accumulate_time(((uint32_t)(current_time - *start_time) / 2000), param->client_recv_publish_msg.msg,
|
||||
param->client_recv_publish_msg.ctx->recv_ttl, param->client_recv_publish_msg.length);
|
||||
transaction_set_events(trans, TRANS_MESH_SEND_MESSAGE_EVT);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT:
|
||||
ESP_LOGI(TAG, "VndModel:PublishUpdate,OK");
|
||||
break;
|
||||
case ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT:
|
||||
ESP_LOGI(TAG, "VndModel:TimeOut,0x%06" PRIx32, param->client_send_timeout.opcode);
|
||||
if (trans) {
|
||||
transaction_set_events(trans, TRANS_MESH_SEND_MESSAGE_EVT);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_EVT_MAX:
|
||||
ESP_LOGI(TAG, "VndModel:MaxEvt");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ble_mesh_test_performance_client_model_throughput(void *params)
|
||||
{
|
||||
uint16_t i;
|
||||
uint8_t *data = NULL;
|
||||
uint64_t start_time;
|
||||
esp_ble_mesh_msg_ctx_t ctx;
|
||||
transaction_t *trans = NULL;
|
||||
ble_mesh_test_perf_throughput_data *profile_context = (ble_mesh_test_perf_throughput_data *)params;
|
||||
esp_err_t result = ESP_OK;
|
||||
|
||||
ctx.net_idx = profile_context->net_idx;
|
||||
ctx.app_idx = profile_context->app_idx;
|
||||
ctx.addr = profile_context->address;
|
||||
ctx.send_ttl = profile_context->ttl;
|
||||
ctx.model = profile_context->model;
|
||||
ctx.send_rel = 0;
|
||||
test_perf_statistics.test_length = profile_context->length;
|
||||
// create send data
|
||||
data = malloc(profile_context->length);
|
||||
if (data == NULL) {
|
||||
ESP_LOGE(TAG, " %s, %d, malloc fail", __func__, __LINE__);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (i = 1; i <= profile_context->test_num; i++) {
|
||||
ble_mesh_create_send_data((char *)data, profile_context->length, i, profile_context->opcode);
|
||||
start_time = esp_timer_get_time();
|
||||
TRANSACTION_INIT(&trans, TRANS_TYPE_MESH_PERF, TRANS_MESH_SEND_MESSAGE,
|
||||
TRANS_MESH_SEND_MESSAGE_EVT, SEND_MESSAGE_TIMEOUT, &start_time, NULL);
|
||||
//tx: data profile_context->length
|
||||
result = esp_ble_mesh_client_model_send_msg(profile_context->model, &ctx, profile_context->opcode,
|
||||
profile_context->length, data, 8000,
|
||||
profile_context->need_ack,
|
||||
profile_context->device_role);
|
||||
|
||||
if (result != ESP_OK) {
|
||||
ESP_LOGE(TAG, "VendorModel:SendPackage,Fail");
|
||||
}
|
||||
|
||||
ble_mesh_test_performance_client_model_accumulate_statistics(profile_context->length);
|
||||
|
||||
if (deinit_flag) {
|
||||
ESP_LOGI(TAG, "Already deinit, stop sending message");
|
||||
break;
|
||||
}
|
||||
|
||||
result = transaction_run(trans);
|
||||
if (result == ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGI(TAG, "Already deinit, transactions abort");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "VendorModel:SendPackage,Finish");
|
||||
|
||||
cleanup:
|
||||
free(params);
|
||||
if (data != NULL) {
|
||||
free(data);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
int ble_mesh_test_performance_client_model(int argc, char **argv)
|
||||
{
|
||||
esp_ble_mesh_elem_t *element = NULL;
|
||||
esp_ble_mesh_model_t *model;
|
||||
esp_err_t result = ESP_OK;
|
||||
ble_mesh_test_perf_throughput_data *profile_data = NULL;
|
||||
uint16_t company_id = CID_ESP;
|
||||
|
||||
int nerrors = arg_parse(argc, argv, (void **) &test_perf_client_model);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, test_perf_client_model.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
element = esp_ble_mesh_find_element(esp_ble_mesh_get_primary_element_address());
|
||||
if (!element) {
|
||||
ESP_LOGE(TAG, "Element 0x%04x not exists", esp_ble_mesh_get_primary_element_address());
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
model = esp_ble_mesh_find_vendor_model(element, company_id, ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_CLI);
|
||||
if (!model) {
|
||||
ESP_LOGE(TAG, "VendorClient:LoadModel,Fail");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (strcmp(test_perf_client_model.action_type->sval[0], "init") == 0) {
|
||||
result = esp_ble_mesh_client_model_init(model);
|
||||
if (result == ESP_OK) {
|
||||
ESP_LOGI(TAG, "VendorClientModel:Init,OK");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "VendorClientModel:Init,Fail,%d", result);
|
||||
}
|
||||
} else if (strcmp(test_perf_client_model.action_type->sval[0], "start") == 0) {
|
||||
profile_data = malloc(sizeof(ble_mesh_test_perf_throughput_data));
|
||||
profile_data->model = model;
|
||||
if (profile_data == NULL) {
|
||||
ESP_LOGE(TAG, " %s, %d malloc fail", __func__, __LINE__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
arg_int_to_value(test_perf_client_model.playload_byte, profile_data->length, "length");
|
||||
arg_int_to_value(test_perf_client_model.opcode, profile_data->opcode, "opcode");
|
||||
arg_int_to_value(test_perf_client_model.unicast_address, profile_data->address, "publish address");
|
||||
arg_int_to_value(test_perf_client_model.ttl, profile_data->ttl, "model ttl");
|
||||
arg_int_to_value(test_perf_client_model.app_idx, profile_data->app_idx, "appkey index");
|
||||
arg_int_to_value(test_perf_client_model.net_idx, profile_data->net_idx, "network key index");
|
||||
arg_int_to_value(test_perf_client_model.dev_role, profile_data->device_role, "device role");
|
||||
arg_int_to_value(test_perf_client_model.test_num, profile_data->test_num, "test number");
|
||||
|
||||
if (profile_data->opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET) {
|
||||
profile_data->need_ack = true;
|
||||
} else {
|
||||
profile_data->need_ack = false;
|
||||
}
|
||||
|
||||
xTaskCreate(ble_mesh_test_performance_client_model_throughput, "MESHTHROUGHPUTSEND", 4048, profile_data, 1, NULL);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ble_mesh_test_performance_client_model_performance(int argc, char **argv)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
int nerrors = arg_parse(argc, argv, (void **) &test_perf_client_model_statistics);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, test_perf_client_model_statistics.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(test_perf_client_model_statistics.action_type->sval[0], "init") == 0) {
|
||||
result = ble_mesh_test_performance_client_model_init(test_perf_client_model_statistics.node_num->ival[0],
|
||||
test_perf_client_model_statistics.test_size->ival[0], test_perf_client_model_statistics.ttl->ival[0]);
|
||||
if (result == 0) {
|
||||
ESP_LOGI(TAG, "VendorPerfTest:InitStatistics,OK");
|
||||
}
|
||||
} else if (strcmp(test_perf_client_model_statistics.action_type->sval[0], "get") == 0) {
|
||||
ble_mesh_test_performance_client_model_get();
|
||||
} else if (strcmp(test_perf_client_model_statistics.action_type->sval[0], "destroy") == 0) {
|
||||
ble_mesh_test_performance_client_model_destroy();
|
||||
ESP_LOGI(TAG, "VendorPerfTest:DestroyStatistics,OK");
|
||||
} else if (strcmp(test_perf_client_model_statistics.action_type->sval[0], "percent") == 0) {
|
||||
ble_mesh_test_performance_client_model_get_received_percent();
|
||||
ESP_LOGI(TAG, "VendorPerfTest:GetPercent,OK");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ble_mesh_performance_client_model_command(void)
|
||||
{
|
||||
test_perf_client_model.action_type = arg_str1("z", NULL, "<action>", "action type");
|
||||
test_perf_client_model.playload_byte = arg_int0("p", NULL, "<byte>", "playload byte");
|
||||
test_perf_client_model.test_num = arg_int0("n", NULL, "<number>", "test number");
|
||||
// set test num default to 1000
|
||||
test_perf_client_model.test_num->ival[0] = 1000;
|
||||
test_perf_client_model.opcode = arg_int0("o", NULL, "<opcode>", "opcode");
|
||||
test_perf_client_model.unicast_address = arg_int0("u", NULL, "<address>", "unicast address");
|
||||
test_perf_client_model.ttl = arg_int0("t", NULL, "<ttl>", "ttl");
|
||||
test_perf_client_model.app_idx = arg_int0("a", NULL, "<appkey>", "appkey index");
|
||||
test_perf_client_model.net_idx = arg_int0("i", NULL, "<network key>", "network key index");
|
||||
test_perf_client_model.dev_role = arg_int0("d", NULL, "<role>", "device role");
|
||||
test_perf_client_model.dev_role->ival[0] = ROLE_PROVISIONER;
|
||||
test_perf_client_model.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t test_perf_client_model_cmd = {
|
||||
.command = "bmtpcvm",
|
||||
.help = "ble mesh test performance client vendor model",
|
||||
.hint = NULL,
|
||||
.func = &ble_mesh_test_performance_client_model,
|
||||
.argtable = &test_perf_client_model,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&test_perf_client_model_cmd));
|
||||
|
||||
test_perf_client_model_statistics.action_type = arg_str1("z", NULL, "<action>", "action type");
|
||||
test_perf_client_model_statistics.test_size = arg_int0("s", NULL, "<test size>", "test size");
|
||||
test_perf_client_model_statistics.node_num = arg_int0("n", NULL, "<node number>", "node number");
|
||||
test_perf_client_model_statistics.ttl = arg_int0("l", NULL, "<test number>", "ttl");
|
||||
test_perf_client_model_statistics.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t test_perf_client_model_performance_cmd = {
|
||||
.command = "bmcperf",
|
||||
.help = "ble mesh client: test performance",
|
||||
.hint = NULL,
|
||||
.func = &ble_mesh_test_performance_client_model_performance,
|
||||
.argtable = &test_perf_client_model_statistics,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&test_perf_client_model_performance_cmd));
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
|
||||
#include "ble_mesh_console_lib.h"
|
||||
#include "ble_mesh_adapter.h"
|
||||
|
||||
void ble_mesh_register_server_operation(void);
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *data;
|
||||
struct arg_int *opcode;
|
||||
struct arg_int *model;
|
||||
struct arg_int *role;
|
||||
struct arg_int *pub_addr;
|
||||
struct arg_int *app_index;
|
||||
struct arg_int *period;
|
||||
struct arg_end *end;
|
||||
} ble_mesh_publish_message;
|
||||
ble_mesh_publish_message msg_publish;
|
||||
|
||||
void ble_mesh_register_server(void)
|
||||
{
|
||||
ble_mesh_register_server_operation();
|
||||
}
|
||||
|
||||
int ble_mesh_module_publish_message(int argc, char **argv)
|
||||
{
|
||||
esp_err_t err;
|
||||
esp_ble_mesh_elem_t *element = NULL;
|
||||
esp_ble_mesh_model_t *model = NULL;
|
||||
uint8_t *data = NULL;
|
||||
uint8_t device_role = ROLE_NODE;
|
||||
uint16_t length = 0;
|
||||
|
||||
ESP_LOGD(TAG, "enter %s", __func__);
|
||||
|
||||
int nerrors = arg_parse(argc, argv, (void **) &msg_publish);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, msg_publish.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
data = malloc(strlen(msg_publish.data->sval[0]));
|
||||
if (data == NULL) {
|
||||
ESP_LOGE(TAG, "ble mesh malloc failed, %d", __LINE__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
} else {
|
||||
get_value_string((char *)msg_publish.data->sval[0], (char *) data);
|
||||
}
|
||||
|
||||
arg_int_to_value(msg_publish.role, device_role, "device role");
|
||||
|
||||
element = esp_ble_mesh_find_element(esp_ble_mesh_get_primary_element_address());
|
||||
if (!element) {
|
||||
ESP_LOGE(TAG, "Element 0x%04x not exists", esp_ble_mesh_get_primary_element_address());
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
model = esp_ble_mesh_find_sig_model(element, msg_publish.model->ival[0]);
|
||||
if (!model) {
|
||||
ESP_LOGE(TAG, "MsgPublish:Load Model Fail");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (msg_publish.role->count != 0) {
|
||||
device_role = msg_publish.role->ival[0];
|
||||
}
|
||||
|
||||
if (msg_publish.pub_addr->count != 0) {
|
||||
model->pub->publish_addr = msg_publish.pub_addr->ival[0];
|
||||
}
|
||||
|
||||
if (msg_publish.period->count != 0) {
|
||||
model->pub->period = msg_publish.period->ival[0];
|
||||
}
|
||||
|
||||
if (msg_publish.app_index->count != 0) {
|
||||
model->pub->app_idx = msg_publish.app_index->ival[0];
|
||||
}
|
||||
|
||||
if (msg_publish.data->count != 0) {
|
||||
length = strlen(msg_publish.data->sval[0]);
|
||||
data = malloc((length + 1) * sizeof(uint8_t));
|
||||
if (data == NULL) {
|
||||
ESP_LOGE(TAG, "ble mesh malloc failed, %d", __LINE__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
} else {
|
||||
get_value_string((char *)msg_publish.data->sval[0], (char *) data);
|
||||
}
|
||||
}
|
||||
|
||||
err = esp_ble_mesh_model_publish(model, msg_publish.opcode->ival[0], length, data, device_role);
|
||||
|
||||
ESP_LOGD(TAG, "exit %s", __func__);
|
||||
free(data);
|
||||
return err;
|
||||
}
|
||||
|
||||
void ble_mesh_register_server_operation(void)
|
||||
{
|
||||
msg_publish.data = arg_str1("d", NULL, "<data>", "message data");
|
||||
msg_publish.opcode = arg_int1("o", NULL, "<opcode>", "operation opcode");
|
||||
msg_publish.model = arg_int1("m", NULL, "<module>", "module published to");
|
||||
msg_publish.role = arg_int1("r", NULL, "<role>", "device role");
|
||||
msg_publish.pub_addr = arg_int1("a", NULL, "<address>", "unicast address");
|
||||
msg_publish.app_index = arg_int1("i", NULL, "<app key>", "app key index");
|
||||
msg_publish.period = arg_int1("p", NULL, "<period>", "period");
|
||||
msg_publish.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t msg_publish_cmd = {
|
||||
.command = "bmpublish",
|
||||
.help = "ble mesh: publish message",
|
||||
.hint = NULL,
|
||||
.func = &ble_mesh_module_publish_message,
|
||||
.argtable = &msg_publish,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&msg_publish_cmd));
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "esp_console.h"
|
||||
#include "ble_mesh_console_lib.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt_device.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "host/ble_hs.h"
|
||||
#endif
|
||||
|
||||
void register_ble_address(void);
|
||||
|
||||
void register_bluetooth(void)
|
||||
{
|
||||
register_ble_address();
|
||||
}
|
||||
|
||||
int get_bd_addr(uint8_t addr[6])
|
||||
{
|
||||
if (addr) {
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
memcpy(addr, esp_bt_dev_get_address(), 6);
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
uint8_t own_addr_type = 0;
|
||||
uint8_t mac[6] = {0};
|
||||
int rc = 0;
|
||||
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
printf("error determining address type; rc=%d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
ble_hs_id_copy_addr(own_addr_type, mac, NULL);
|
||||
|
||||
uint8_t *src = addr;
|
||||
uint8_t *dst = mac + 5;
|
||||
for (uint8_t length = 6; length > 0; length--) {
|
||||
*src++ = *dst--;
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bt_mac(int argc, char** argv)
|
||||
{
|
||||
uint8_t mac[6] = {0};
|
||||
|
||||
get_bd_addr(mac);
|
||||
|
||||
printf("+BTMAC:"MACSTR"\n", MAC2STR(mac));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void register_ble_address(void)
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "btmac",
|
||||
.help = "get BT mac address",
|
||||
.hint = NULL,
|
||||
.func = &bt_mac,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
@ -1,267 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_err.h"
|
||||
#include "transaction.h"
|
||||
#define TAG "TRANS"
|
||||
|
||||
static transaction_t transactions[MAX_TRANSACTION_COUNT];
|
||||
static SemaphoreHandle_t trans_mutex;
|
||||
|
||||
static uint32_t utils_get_system_ts(void)
|
||||
{
|
||||
return esp_log_timestamp();
|
||||
}
|
||||
|
||||
static void transaction_reset(transaction_t *trans)
|
||||
{
|
||||
EventBits_t bits;
|
||||
|
||||
ESP_LOGV(TAG, "transaction reset: %" PRIx32, (uint32_t)trans);
|
||||
// set to inactive state and clear all bits of the transaction
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
trans->type = 0;
|
||||
trans->sub_type = 0;
|
||||
trans->current_bits = 0;
|
||||
bits = xEventGroupGetBits(trans->event_group);
|
||||
xEventGroupClearBits(trans->event_group, bits);
|
||||
trans->state = TRANSACTION_INACTIVE;
|
||||
trans->ret = ESP_OK;
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
}
|
||||
|
||||
void transaction_deinit(transaction_t *trans)
|
||||
{
|
||||
if (trans != NULL) {
|
||||
transaction_reset(trans);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t transaction_set_events(transaction_t *trans, EventBits_t events)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
if (trans) {
|
||||
if (trans->state == TRANSACTION_INACTIVE) {
|
||||
ret = TRANS_RET_STATE_ERR;
|
||||
} else {
|
||||
// if the task (task A) setting current bits is with higher priority than the task (task B) run transaction,
|
||||
// current_bits might not be updated until task A yield (not it's only update in run_transaction function).
|
||||
// If task A set events and immediately use current_bits, current_bits is not correct.
|
||||
// update current_bits here to make sure it's updated
|
||||
trans->current_bits |= events;
|
||||
xEventGroupSetBits(trans->event_group, events);
|
||||
}
|
||||
ESP_LOGD(TAG, "transactions set events: %" PRIx32 ", %x, %" PRIx32 ", %" PRIx32 "; ret: %x", (uint32_t)trans, trans->type, trans->sub_type, events, ret);
|
||||
} else {
|
||||
ret = TRANS_RET_INVALID_TRNSACTION;
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t transaction_test_events(transaction_t *trans, EventBits_t events)
|
||||
{
|
||||
esp_err_t ret = TRANS_RET_TEST_EVENT_FAILED;
|
||||
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
if (trans) {
|
||||
if (trans->state == TRANSACTION_INACTIVE) {
|
||||
ret = TRANS_RET_STATE_ERR;
|
||||
} else {
|
||||
if ((trans->current_bits & events) == events) {
|
||||
ret = ESP_OK;
|
||||
}
|
||||
}
|
||||
ESP_LOGV(TAG, "transactions test events: %" PRIx32 ", %" PRIx32 "; ret: %x", (uint32_t)trans, events, ret);
|
||||
} else {
|
||||
ret = TRANS_RET_INVALID_TRNSACTION;
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t transaction_clear_events(transaction_t *trans, EventBits_t events)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
if (trans) {
|
||||
if (trans->state == TRANSACTION_INACTIVE) {
|
||||
ret = TRANS_RET_STATE_ERR;
|
||||
} else {
|
||||
trans->current_bits &= ~events;
|
||||
xEventGroupClearBits(trans->event_group, events);
|
||||
}
|
||||
ESP_LOGD(TAG, "transactions clear events: %" PRIx32 ", %x, %" PRIx32 ", %" PRIx32 "; ret: %x", (uint32_t)trans, trans->type, trans->sub_type, events, ret);
|
||||
} else {
|
||||
ret = TRANS_RET_INVALID_TRNSACTION;
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t transaction_abort(transaction_t *trans, esp_err_t reason)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
if (trans) {
|
||||
if (trans->state == TRANSACTION_INACTIVE) {
|
||||
ret = TRANS_RET_STATE_ERR;
|
||||
} else {
|
||||
trans->ret = reason;
|
||||
xEventGroupSetBits(trans->event_group, TRANSACTION_ABORT_EVENT);
|
||||
}
|
||||
ESP_LOGD(TAG, "transactions abort: %" PRIx32 ", %x, %" PRIx32 ", %x; ret: %x", (uint32_t)trans, trans->type, trans->sub_type, reason, ret);
|
||||
} else {
|
||||
ret = TRANS_RET_INVALID_TRNSACTION;
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t transaction_init(transaction_t **trans, uint8_t type, uint32_t sub_type, EventBits_t wait_events, uint32_t timeout, void *input, void *output)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t i;
|
||||
|
||||
if ((wait_events & TRANSACTION_EVENT_MASK)
|
||||
&& wait_events != TRANSACTION_TIMEOUT_EVENT) {
|
||||
ret = TRANS_RET_EVENTS_CONFLICT;
|
||||
return ret;
|
||||
}
|
||||
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
for (i = 0; i < MAX_TRANSACTION_COUNT; i++) {
|
||||
if ( transactions[i].state == TRANSACTION_INACTIVE ) {
|
||||
transactions[i].state = TRANSACTION_ACTIVE;
|
||||
*trans = &transactions[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( i == MAX_TRANSACTION_COUNT ) {
|
||||
ret = TRANS_RET_FAILED_TO_ALLOCATE;
|
||||
} else {
|
||||
// init transaction
|
||||
transactions[i].type = type;
|
||||
transactions[i].wait_events = wait_events;
|
||||
transactions[i].sub_type = sub_type;
|
||||
transactions[i].timeout = timeout;
|
||||
transactions[i].ret = ESP_OK;
|
||||
transactions[i].input = input;
|
||||
transactions[i].output = output;
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
ESP_LOGD(TAG, "transaction created: %x, %" PRIx32 ", %" PRIx32 "; ret: %x", type, sub_type, (uint32_t)*trans, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t transaction_run(transaction_t *trans)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint32_t start_time;
|
||||
int32_t wait_time;
|
||||
EventBits_t current_bits;
|
||||
|
||||
if (trans) {
|
||||
start_time = utils_get_system_ts();
|
||||
// wait for wait events
|
||||
while (1) {
|
||||
//TODO: we didn't handle ts overflow
|
||||
wait_time = start_time + trans->timeout - utils_get_system_ts();
|
||||
|
||||
if ( wait_time < 0 ) {
|
||||
ESP_LOGI(TAG, "transaction timeout: %" PRIx32 ", %x, %" PRIx32 ", %" PRIx32 ", %" PRIx32, (uint32_t)trans, trans->type, trans->sub_type, trans->wait_events, trans->current_bits);
|
||||
ret = TRANS_RET_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
|
||||
// trans->event_group and trans->wait_events will not be changed once trans is created, so we don't need protect them
|
||||
current_bits = xEventGroupWaitBits(trans->event_group, trans->wait_events | TRANSACTION_ABORT_EVENT,
|
||||
1, 0, wait_time/portTICK_PERIOD_MS);
|
||||
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
trans->current_bits |= current_bits;
|
||||
|
||||
if (trans->current_bits == trans->wait_events) {
|
||||
// wait succeeded, we copy the trans->ret as ret of run transaction. This value could be changed by
|
||||
ret = trans->ret;
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
break;
|
||||
} else if ( trans->current_bits & TRANSACTION_ABORT_EVENT ) {
|
||||
if ( trans->ret ) {
|
||||
// copy user defined ret value if it's set
|
||||
ret = trans->ret;
|
||||
} else {
|
||||
ret = TRANS_RET_ABORTED;
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
break;
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
}
|
||||
ESP_LOGD(TAG, "transaction run: %" PRIx32 ", %x, %" PRIx32 "; ret: %x", (uint32_t)trans, trans->type, trans->sub_type, ret);
|
||||
// reset after it's finished
|
||||
transaction_reset(trans);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "transaction run: %" PRIx32 "; ret: %x", (uint32_t)trans, ret);
|
||||
ret = TRANS_RET_INVALID_TRNSACTION;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
transaction_t *transaction_get(uint8_t type, uint32_t sub_type, transaction_t *start)
|
||||
{
|
||||
uint8_t i, start_index;
|
||||
transaction_t *trans = NULL;
|
||||
|
||||
if ( start == NULL ) {
|
||||
start_index = 0;
|
||||
} else {
|
||||
start_index = (start - transactions) + 1;
|
||||
}
|
||||
|
||||
xSemaphoreTakeRecursive(trans_mutex, portMAX_DELAY);
|
||||
for (i = start_index; i < MAX_TRANSACTION_COUNT; i++) {
|
||||
if ( transactions[i].state == TRANSACTION_ACTIVE ) {
|
||||
if ( (transactions[i].type == type) && (transactions[i].sub_type & sub_type) ) {
|
||||
trans = &transactions[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
xSemaphoreGiveRecursive(trans_mutex);
|
||||
ESP_LOGV(TAG, "transaction get: %x, %" PRIx32 ", %" PRIx32 ", %" PRIx32, type, sub_type, (uint32_t) start, (uint32_t)trans);
|
||||
return trans;
|
||||
}
|
||||
|
||||
void init_transactions(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
ESP_LOGI(TAG, "init transactions");
|
||||
|
||||
trans_mutex = xSemaphoreCreateRecursiveMutex();
|
||||
|
||||
for (i = 0; i < MAX_TRANSACTION_COUNT; i++) {
|
||||
transactions[i].event_group = xEventGroupCreate();
|
||||
transaction_reset(&transactions[i]);
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_CONSOLE_TRANSACTION_H_
|
||||
#define _BLE_MESH_CONSOLE_TRANSACTION_H_
|
||||
|
||||
/* In esp-idf, bluetooth and wifi stack APIs are async (using callbacks).
|
||||
* transaction module provides a common method to let user transfer async APIs to sync transactions.
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#define MAX_TRANSACTION_COUNT 5
|
||||
|
||||
#define TRANSACTION_TYPE_ALL 0xFF
|
||||
|
||||
#define TRANSACTION_SUB_TYPE_ALL 0xFFFFFFFF
|
||||
|
||||
// The higher 12 bits of event is reversed for event group or transaction module.
|
||||
// Application can only use lower 20 bits of the event.
|
||||
#define TRANSACTION_TIMEOUT_EVENT 0x00100000UL // only wait for timeout
|
||||
#define TRANSACTION_ABORT_EVENT 0x00800000UL // this event is reserved for internal use only
|
||||
#define TRANSACTION_EVENT_MASK 0xFFF00000UL
|
||||
|
||||
|
||||
enum {
|
||||
TRANS_RET_ERROR_START = 0x10000,
|
||||
TRANS_RET_FAILED_TO_ALLOCATE,
|
||||
TRANS_RET_STATE_ERR,
|
||||
TRANS_RET_TEST_EVENT_FAILED,
|
||||
TRANS_RET_EVENTS_CONFLICT, // events bit conflicts with TRANSACTION_ABORT_EVENT
|
||||
TRANS_RET_INVALID_TRNSACTION,
|
||||
TRANS_RET_TIMEOUT,
|
||||
TRANS_RET_ABORTED
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TRANSACTION_INACTIVE,
|
||||
TRANSACTION_ACTIVE,
|
||||
} transaction_state_t;
|
||||
|
||||
typedef struct {
|
||||
/* input data passed to callback */
|
||||
void *input;
|
||||
/* output data from callback */
|
||||
void *output;
|
||||
/* retrun value, can be set by callback or transaction module (like timeout, or other common errors)
|
||||
* transaction_run will return this member by default. */
|
||||
esp_err_t ret;
|
||||
// private member
|
||||
transaction_state_t state;
|
||||
uint8_t type;
|
||||
uint32_t sub_type;
|
||||
uint32_t timeout;
|
||||
EventBits_t wait_events;
|
||||
EventGroupHandle_t event_group;
|
||||
EventBits_t current_bits;
|
||||
} transaction_t;
|
||||
|
||||
|
||||
void init_transactions(void);
|
||||
|
||||
esp_err_t transaction_init(transaction_t **trans, uint8_t type, uint32_t sub_type, EventBits_t wait_events, uint32_t timeout, void *input, void *output);
|
||||
esp_err_t transaction_run(transaction_t *trans);
|
||||
|
||||
transaction_t *transaction_get(uint8_t type, uint32_t sub_type, transaction_t *start);
|
||||
|
||||
esp_err_t transaction_set_events(transaction_t *trans, EventBits_t events);
|
||||
esp_err_t transaction_test_events(transaction_t *trans, EventBits_t events);
|
||||
esp_err_t transaction_clear_events(transaction_t *trans, EventBits_t events);
|
||||
|
||||
esp_err_t transaction_abort(transaction_t *trans, esp_err_t reason);
|
||||
|
||||
#define TRANSACTION_INIT(trans, type, sub_type, wait_events, timeout, input, output) \
|
||||
ESP_ERROR_CHECK(transaction_init(trans, type, sub_type, wait_events, timeout, input, output))
|
||||
|
||||
|
||||
#define transaction_get_first(type, sub_type) transaction_get(type, sub_type, NULL)
|
||||
|
||||
|
||||
/* We declare all transaction type / sub type below */
|
||||
#define TRANS_TYPE_BLE_GAP 0x01
|
||||
#define TRANS_TYPE_BLE_GATTC 0x02
|
||||
#define TRANS_TYPE_BLE_GATTS 0x03
|
||||
#define TRANS_TYPE_WIFI 0x04
|
||||
#define TRANS_TYPE_BT 0x05
|
||||
|
||||
|
||||
#endif /* _BLE_MESH_CONSOLE_TRANSACTION_H_ */
|
@ -1,4 +0,0 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x6000,
|
||||
phy_init, data, phy, 0xf000, 0x1000,
|
||||
factory, app, factory, 0x10000, 2M,
|
|
@ -1,32 +0,0 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_CTRL_BTDM_MODEM_SLEEP=n
|
||||
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
|
||||
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
|
||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
|
||||
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
|
||||
|
||||
# Override some defaults of ESP BLE Mesh
|
||||
CONFIG_BLE_MESH=y
|
||||
CONFIG_BLE_MESH_NODE=y
|
||||
CONFIG_BLE_MESH_PB_GATT=y
|
||||
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB_FILTER_SIZE=3
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
CONFIG_BLE_MESH_MAX_PROV_NODES=80
|
||||
|
||||
# partitions
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
@ -1,32 +0,0 @@
|
||||
# Override some defaults so nimble is enabled
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_CTRL_BTDM_MODEM_SLEEP=n
|
||||
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
|
||||
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_LOG_LEVEL_ERROR=y
|
||||
|
||||
# Override some defaults of ESP BLE Mesh
|
||||
CONFIG_BLE_MESH=y
|
||||
CONFIG_BLE_MESH_NODE=y
|
||||
CONFIG_BLE_MESH_PB_GATT=y
|
||||
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB_FILTER_SIZE=3
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
CONFIG_BLE_MESH_MAX_PROV_NODES=80
|
||||
|
||||
# partitions
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
@ -1,33 +0,0 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# by default in this example
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_CTRL_BTDM_MODEM_SLEEP=n
|
||||
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
|
||||
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
|
||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
|
||||
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
|
||||
|
||||
# Override some defaults of ESP BLE Mesh
|
||||
CONFIG_BLE_MESH=y
|
||||
CONFIG_BLE_MESH_NODE=y
|
||||
CONFIG_BLE_MESH_PB_GATT=y
|
||||
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB=y
|
||||
CONFIG_BLE_MESH_PROVISIONER_RECV_HB_FILTER_SIZE=3
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
CONFIG_BLE_MESH_MAX_PROV_NODES=80
|
||||
|
||||
# partitions
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
@ -1,27 +0,0 @@
|
||||
# ESP32C3-specific
|
||||
##Override some defaults so BT stack is enabled
|
||||
# by default in this example
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DATA_DEVICE=y
|
||||
CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN=y
|
||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
|
||||
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
|
||||
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||
|
||||
# Override some defaults of ESP BLE Mesh
|
||||
CONFIG_BLE_MESH=y
|
||||
CONFIG_BLE_MESH_NODE=y
|
||||
CONFIG_BLE_MESH_PB_GATT=y
|
||||
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
CONFIG_BLE_MESH_MAX_PROV_NODES=80
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
# end of ESP32C3-specific
|
@ -1,30 +0,0 @@
|
||||
# ESP32C6-specific
|
||||
##Override some defaults so BT stack is enabled
|
||||
# by default in this example
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE=y
|
||||
CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN=y
|
||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
|
||||
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
|
||||
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
|
||||
CONFIG_BT_LE_50_FEATURE_SUPPORT=n
|
||||
|
||||
# Override some defaults of ESP BLE Mesh
|
||||
CONFIG_BLE_MESH=y
|
||||
CONFIG_BLE_MESH_NODE=y
|
||||
CONFIG_BLE_MESH_PB_GATT=y
|
||||
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
CONFIG_BLE_MESH_MAX_PROV_NODES=80
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
|
||||
# end of ESP32C6-specific
|
@ -1,30 +0,0 @@
|
||||
# ESP32H2-specific
|
||||
##Override some defaults so BT stack is enabled
|
||||
# by default in this example
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE=y
|
||||
CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN=y
|
||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
|
||||
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
|
||||
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
|
||||
CONFIG_BT_LE_50_FEATURE_SUPPORT=n
|
||||
|
||||
# Override some defaults of ESP BLE Mesh
|
||||
CONFIG_BLE_MESH=y
|
||||
CONFIG_BLE_MESH_NODE=y
|
||||
CONFIG_BLE_MESH_PB_GATT=y
|
||||
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
CONFIG_BLE_MESH_MAX_PROV_NODES=80
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
|
||||
# end of ESP32H2-specific
|
@ -1,27 +0,0 @@
|
||||
# ESP32S3-specific
|
||||
# Override some defaults so BT stack is enabled
|
||||
# by default in this example
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BT_CTRL_SCAN_DUPL_TYPE_DATA_DEVICE=y
|
||||
CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN=y
|
||||
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
|
||||
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
|
||||
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||
|
||||
# Override some defaults of ESP BLE Mesh
|
||||
CONFIG_BLE_MESH=y
|
||||
CONFIG_BLE_MESH_NODE=y
|
||||
CONFIG_BLE_MESH_PB_GATT=y
|
||||
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_PROVISIONER=y
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK=y
|
||||
CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=80
|
||||
CONFIG_BLE_MESH_MAX_PROV_NODES=80
|
||||
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
# end of ESP32S3-specific
|
Loading…
x
Reference in New Issue
Block a user