Skip to content

Commit ef3e7a2

Browse files
committed
samples: cli: add BLE user config
Implemented dummy user config handler (returns not implemented) Signed-off-by: Krzysztof Taborowski <krzysztof.taborowski@nordicsemi.no>
1 parent e8d17ce commit ef3e7a2

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

samples/sid_end_device/include/cli/app_shell.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@
229229
#define CMD_SID_SET_OPTION_LP_SET_ARG_OPTIONAL 1
230230
#define CMD_SID_OPTION_GSI_ARG_REQUIRED 1
231231
#define CMD_SID_OPTION_GSI_ARG_OPTIONAL 0
232+
#define CMD_SID_OPTION_BLE_CFG_DESCRIPTION \
233+
"set <cfg_type> [inactivity_timeout]\n" \
234+
"Set BLE user config (SID_OPTION_BLE_USER_CONFIG).\n" \
235+
"<cfg_type> 0=ADV, 1=CONN, 2=ADV_AND_CONN, 3=INACTIVITY_TIMEOUT.\n" \
236+
"For cfg_type 3, <inactivity_timeout> (seconds) is required."
237+
#define CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED 2
238+
#define CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL 1
232239
#define CMD_SID_LAST_STATUS_ARG_REQUIRED 1
233240
#define CMD_SID_LAST_STATUS_ARG_OPTIONAL 0
234241
#define CMD_SID_CONN_REQUEST_ARG_REQUIRED 2
@@ -271,6 +278,7 @@ int cmd_sid_option_c(const struct shell *shell, int32_t argc, const char **argv)
271278
int cmd_sid_option_ml(const struct shell *shell, int32_t argc, const char **argv);
272279
int cmd_sid_option_gc(const struct shell *shell, int32_t argc, const char **argv);
273280
int cmd_sid_option_sid_id(const struct shell *shell, int32_t argc, const char **argv);
281+
int cmd_sid_option_ble_cfg_set(const struct shell *shell, int32_t argc, const char **argv);
274282

275283
int cmd_sid_last_status(const struct shell *shell, int32_t argc, const char **argv);
276284
int cmd_sid_conn_request(const struct shell *shell, int32_t argc, const char **argv);

samples/sid_end_device/src/cli/app_shell.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <sid_api.h>
1818
#include <sid_900_cfg.h>
19+
#include <sid_ble_config_ifc.h>
1920
#include <sid_hal_memory_ifc.h>
2021

2122
#include <cli/app_shell.h>
@@ -79,6 +80,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
7980
CMD_SID_SET_OPTION_GC_ARG_REQUIRED, CMD_SID_SET_OPTION_GC_ARG_OPTIONAL),
8081
SHELL_CMD_ARG(-gsi, NULL, CMD_SID_OPTION_GSI_DESCRIPTION, cmd_sid_option_sid_id,
8182
CMD_SID_OPTION_GSI_ARG_REQUIRED, CMD_SID_OPTION_GSI_ARG_OPTIONAL),
83+
SHELL_CMD_ARG(-ble_cfg, NULL, CMD_SID_OPTION_BLE_CFG_DESCRIPTION,
84+
cmd_sid_option_ble_cfg_set, CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED,
85+
CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL),
8286

8387
SHELL_SUBCMD_SET_END);
8488

@@ -989,6 +993,71 @@ int cmd_sid_option_gc(const struct shell *shell, int32_t argc, const char **argv
989993
return 0;
990994
}
991995

996+
int cmd_sid_option_ble_cfg_set(const struct shell *shell, int32_t argc, const char **argv)
997+
{
998+
CHECK_ARGUMENT_COUNT(argc, CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED,
999+
CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL);
1000+
1001+
if (strcmp(argv[1], "set") != 0) {
1002+
shell_error(shell, "First argument must be 'set'");
1003+
return -EINVAL;
1004+
}
1005+
1006+
long cfg_type_raw = 0l;
1007+
char *end = NULL;
1008+
cfg_type_raw = strtol(argv[2], &end, 0);
1009+
if (end == argv[2] || !IN_RANGE(cfg_type_raw, SID_BLE_USER_CFG_ADV,
1010+
SID_BLE_USER_CFG_INACTIVITY_TIMEOUT)) {
1011+
shell_error(shell, "cfg_type must be 0..3 (ADV, CONN, ADV_AND_CONN, INACTIVITY_TIMEOUT)");
1012+
return -EINVAL;
1013+
}
1014+
1015+
/* Use valid BLE defaults to avoid SID_ERROR_INCOMPATIBLE_PARAMS (-12).
1016+
* Adv: same ranges as app_ble_config (interval in 0.625ms, timeout in 10ms).
1017+
* Conn: interval in 1.25ms units, min <= max; timeout in 10ms.
1018+
*/
1019+
struct sid_ble_user_config cfg = {
1020+
.adv_param = {
1021+
.type = AMA_SERVICE,
1022+
.fast_enabled = true,
1023+
.slow_enabled = true,
1024+
.fast_interval = 256,
1025+
.fast_timeout = 3000,
1026+
.slow_interval = 1600,
1027+
.slow_timeout = 0,
1028+
},
1029+
.conn_param = {
1030+
.min_conn_interval = 6, /* 7.5 ms */
1031+
.max_conn_interval = 3200, /* 4000 ms */
1032+
.slave_latency = 0,
1033+
.conn_sup_timeout = 400, /* 4000 ms */
1034+
},
1035+
.is_set = true,
1036+
.cfg_type = (enum sid_ble_user_config_type)cfg_type_raw,
1037+
.inactivity_timeout = 0,
1038+
};
1039+
1040+
if (cfg.cfg_type == SID_BLE_USER_CFG_INACTIVITY_TIMEOUT) {
1041+
if (argc < 4) {
1042+
shell_error(shell, "inactivity_timeout required for cfg_type 3");
1043+
return -EINVAL;
1044+
}
1045+
unsigned long timeout = strtoul(argv[3], &end, 0);
1046+
if (end == argv[3] || timeout > UINT32_MAX) {
1047+
shell_error(shell, "Invalid inactivity_timeout");
1048+
return -EINVAL;
1049+
}
1050+
cfg.inactivity_timeout = (uint32_t)timeout;
1051+
}
1052+
1053+
int err = cmd_sid_option_set(SID_OPTION_BLE_USER_CONFIG, &cfg, sizeof(cfg));
1054+
if (err) {
1055+
shell_error(shell, "event err %d", err);
1056+
}
1057+
1058+
return 0;
1059+
}
1060+
9921061
int cmd_sid_last_status(const struct shell *shell, int32_t argc, const char **argv)
9931062
{
9941063
CHECK_ARGUMENT_COUNT(argc, CMD_SID_LAST_STATUS_ARG_REQUIRED,

subsys/sal/sid_pal/src/sid_ble_adapter.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include <sid_error.h>
12+
#include <sid_ble_config_ifc.h>
1213
#include <sid_pal_ble_adapter_ifc.h>
1314
#include <sid_ble_service.h>
1415
#include <sid_ble_ama_service.h>
@@ -48,10 +49,12 @@ static sid_error_t ble_adapter_deinit(void);
4849
static sid_error_t ble_adapter_get_rssi(int8_t *rssi);
4950
static sid_error_t ble_adapter_get_tx_pwr(int16_t *tx_power);
5051
static sid_error_t ble_adapter_set_tx_pwr(int16_t tx_power);
52+
static sid_error_t ble_adapter_user_config(sid_ble_user_config_t *cfg);
5153

5254
static struct sid_pal_ble_adapter_interface ble_ifc = {
5355
.init = ble_adapter_init,
5456
.start_service = ble_adapter_start_service,
57+
.user_config = ble_adapter_user_config,
5558
.set_adv_data = ble_adapter_set_adv_data,
5659
.start_adv = ble_adapter_start_advertisement,
5760
.stop_adv = ble_adapter_stop_advertisement,
@@ -379,6 +382,13 @@ static sid_error_t ble_adapter_send_data(sid_ble_cfg_service_identifier_t id, ui
379382
return SID_ERROR_NONE;
380383
}
381384

385+
static sid_error_t ble_adapter_user_config(sid_ble_user_config_t *cfg)
386+
{
387+
ARG_UNUSED(cfg);
388+
LOG_DBG("BLE user config: not implemented");
389+
return SID_ERROR_NOSUPPORT;
390+
}
391+
382392
static sid_error_t ble_adapter_set_callback(const sid_pal_ble_adapter_callbacks_t *cb)
383393
{
384394
LOG_DBG("Sidewalk -> BLE");

0 commit comments

Comments
 (0)