Skip to content

Commit

Permalink
Add support for BLE extended advertisements (#30)
Browse files Browse the repository at this point in the history
* Add support for BLE extended advertisements

* Add RI_ADV_EXTENDED_ENABLED=1

* Add support for ADV_RPRT2 format, configure max ext adv len, refactoring

* Add support for ADV_RPRT2 format, configure max ext adv len, refactoring
  • Loading branch information
TheSomeMan authored Oct 21, 2024
1 parent dd29ebf commit 8395d9f
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ Mkfile.old
dkms.conf
output/
build/
cmake-build*
.idea/
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.7)

set(RI_COMM_BLE_PAYLOAD_MAX_LENGTH 48)

if(${ESP_PLATFORM})

string(APPEND CMAKE_C_FLAGS " -DRUUVI_ESP")
Expand All @@ -21,6 +23,9 @@ idf_component_register(
ruuvi.endpoints.c
)

target_compile_definitions(${COMPONENT_LIB} PRIVATE RI_ADV_EXTENDED_ENABLED=1 RI_COMM_BLE_PAYLOAD_MAX_LENGTH=${RI_COMM_BLE_PAYLOAD_MAX_LENGTH})
target_compile_definitions(__idf_ruuvi.endpoints.c PRIVATE RI_ADV_EXTENDED_ENABLED=1 RI_COMM_BLE_PAYLOAD_MAX_LENGTH=${RI_COMM_BLE_PAYLOAD_MAX_LENGTH})

else()

project(ruuvi_comm_tester)
Expand All @@ -39,15 +44,15 @@ set(COMPONENTS components)
set(RUUVI_LIB_SOURCES
src/lib/api.c
src/lib/parser.c
src/lib/dbuscontroller.c
src/lib/formated_output.c
src/lib/dbuscontroller.c
src/lib/formated_output.c
${COMPONENTS}/ruuvi.endpoints.c/src/ruuvi_endpoint_ca_uart.c
)

include_directories(
/usr/include
/usr/include/dbus-1.0
/usr/lib/x86_64-linux-gnu/dbus-1.0/include
/usr/include
/usr/include/dbus-1.0
/usr/lib/x86_64-linux-gnu/dbus-1.0/include
src
src/app
src/lib
Expand All @@ -68,6 +73,8 @@ set_target_properties(${ProjectId} PROPERTIES

target_compile_definitions(${ProjectId} PUBLIC
_DEFAULT_SOURCE
RI_ADV_EXTENDED_ENABLED=1
RI_COMM_BLE_PAYLOAD_MAX_LENGTH=${RI_COMM_BLE_PAYLOAD_MAX_LENGTH}
)

target_compile_options(${ProjectId} PUBLIC
Expand All @@ -81,7 +88,7 @@ target_compile_options(${ProjectId} PUBLIC

target_link_libraries(${ProjectId}
pthread
dbus-1
dbus-1
)

endif()
61 changes: 34 additions & 27 deletions src/app/comm_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
#define MAX_PARAMS_NUM_SIZE 255
#define IS_PAYLOAD_SET(x) (x->is_set)

#define DEFAULT_FLTR_ID_NUM 0
#define DEFAULT_FLTR_TAGS_NUM 1
#define DEFAULT_CODED_PHY_NUM 2
#define DEFAULT_EXT_PAYLOAD_NUM 3
#define DEFAULT_SCAN_PHY_NUM 4
#define DEFAULT_CH_37_NUM 5
#define DEFAULT_CH_38_NUM 6
#define DEFAULT_CH_39_NUM 7
#define DEFAULT_FLTR_ID_NUM 0
#define DEFAULT_FLTR_TAGS_NUM 1
#define DEFAULT_USE_CODED_PHY_NUM 2
#define DEFAULT_USE_2M_PHY_NUM 3
#define DEFAULT_USE_1M_PHY_NUM 4
#define DEFAULT_CH_37_NUM 5
#define DEFAULT_CH_38_NUM 6
#define DEFAULT_CH_39_NUM 7

static void
help(void)
Expand All @@ -47,11 +47,12 @@ help(void)
print_logmsgnofuncnoarg("-c7 : set channel 37 value\n");
print_logmsgnofuncnoarg("-c8 : set channel 38 value\n");
print_logmsgnofuncnoarg("-c9 : set channel 39 value\n");
print_logmsgnofuncnoarg("-m <max_adv_len>: set max extended advertisement len\n");
print_logmsgnofuncnoarg("-gi : get device id\n");
print_logmsgnofuncnoarg("-l <ms> : turn on LED for <ms>\n");
print_logmsgnofuncnoarg("-o : disable report output\n");
print_logmsgnofuncnoarg("-r : run receiver mode\n");
print_logmsgnofuncnoarg("-b : run receiver in backgroung mode\n");
print_logmsgnofuncnoarg("-b : run receiver in background mode\n");
print_logmsgnofuncnoarg("-h : help\n");
}

Expand All @@ -72,23 +73,23 @@ typedef struct
{
comm_tester_param_input_t fltr_id;
comm_tester_param_input_t fltr_tags_state;
comm_tester_param_input_t coded_phy_state;
comm_tester_param_input_t ext_payload_state;
comm_tester_param_input_t scan_phy_state;
comm_tester_param_input_t use_coded_phy_state;
comm_tester_param_input_t use_2m_phy_state;
comm_tester_param_input_t use_1m_phy_state;
comm_tester_param_input_t ch_37_state;
comm_tester_param_input_t ch_38_state;
comm_tester_param_input_t ch_39_state;
comm_tester_param_input_t max_adv_len;
uint32_t all_state;
} comm_tester_input_t;

comm_tester_input_t in;
comm_tester_param_input_t *in_array[] = {
&in.fltr_id, &in.fltr_tags_state, &in.coded_phy_state, &in.ext_payload_state,
&in.scan_phy_state, &in.ch_37_state, &in.ch_38_state, &in.ch_39_state,
};
comm_tester_input_t in = { 0 };
comm_tester_param_input_t *in_array[] = { &in.fltr_id, &in.fltr_tags_state, &in.use_coded_phy_state,
&in.use_2m_phy_state, &in.use_1m_phy_state, &in.ch_37_state,
&in.ch_38_state, &in.ch_39_state };

uint32_t cmd_array[] = {
RE_CA_UART_SET_FLTR_ID, RE_CA_UART_SET_FLTR_TAGS, RE_CA_UART_SET_CODED_PHY, RE_CA_UART_SET_EXT_PAYLOAD,
RE_CA_UART_SET_FLTR_ID, RE_CA_UART_SET_FLTR_TAGS, RE_CA_UART_SET_CODED_PHY, RE_CA_UART_SET_SCAN_2MB_PHY,
RE_CA_UART_SET_SCAN_1MB_PHY, RE_CA_UART_SET_CH_37, RE_CA_UART_SET_CH_38, RE_CA_UART_SET_CH_39,
};

Expand Down Expand Up @@ -149,19 +150,25 @@ main(int argc, char *argv[])
break;
case 'p':
case 'P':
param_num = DEFAULT_CODED_PHY_NUM;
param_num = DEFAULT_USE_CODED_PHY_NUM;
break;
case 's':
case 'S':
param_num = DEFAULT_SCAN_PHY_NUM;
param_num = DEFAULT_USE_1M_PHY_NUM;
break;
case 'e':
case 'E':
param_num = DEFAULT_EXT_PAYLOAD_NUM;
param_num = DEFAULT_USE_2M_PHY_NUM;
break;
case 'l':
case 'L':
led_ctrl = atoi(argv[i + 1]);
break;
case 'm':
case 'M':
in.max_adv_len.payload = atoi(argv[i + 1]);
in.max_adv_len.is_set = PAYLOAD_INPUT_YES;
break;
case 'g':
case 'G':
switch (argv[i][2])
Expand Down Expand Up @@ -237,19 +244,19 @@ main(int argc, char *argv[])
{
if (terminal_open(deviceCom, false, terminal_task_priority) == 0)
{

if (in.all_state >= MAX_PARAMS_NUM_SIZE)
{
res = api_send_all(
res = (int)api_send_all(
RE_CA_UART_SET_ALL,
(uint16_t)in_array[DEFAULT_FLTR_ID_NUM]->payload,
(uint8_t)in_array[DEFAULT_FLTR_TAGS_NUM]->payload,
(uint8_t)in_array[DEFAULT_CODED_PHY_NUM]->payload,
(uint8_t)in_array[DEFAULT_EXT_PAYLOAD_NUM]->payload,
(uint8_t)in_array[DEFAULT_SCAN_PHY_NUM]->payload,
(uint8_t)in_array[DEFAULT_USE_CODED_PHY_NUM]->payload,
(uint8_t)in_array[DEFAULT_USE_2M_PHY_NUM]->payload,
(uint8_t)in_array[DEFAULT_USE_1M_PHY_NUM]->payload,
(uint8_t)in_array[DEFAULT_CH_37_NUM]->payload,
(uint8_t)in_array[DEFAULT_CH_38_NUM]->payload,
(uint8_t)in_array[DEFAULT_CH_39_NUM]->payload);
(uint8_t)in_array[DEFAULT_CH_39_NUM]->payload,
(uint8_t)in.max_adv_len.payload);
}
else
{
Expand Down
Loading

0 comments on commit 8395d9f

Please sign in to comment.