|
16 | 16 |
|
17 | 17 | #include <sid_api.h> |
18 | 18 | #include <sid_900_cfg.h> |
| 19 | +#include <sid_ble_config_ifc.h> |
19 | 20 | #include <sid_hal_memory_ifc.h> |
20 | 21 |
|
21 | 22 | #include <cli/app_shell.h> |
@@ -79,6 +80,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE( |
79 | 80 | CMD_SID_SET_OPTION_GC_ARG_REQUIRED, CMD_SID_SET_OPTION_GC_ARG_OPTIONAL), |
80 | 81 | SHELL_CMD_ARG(-gsi, NULL, CMD_SID_OPTION_GSI_DESCRIPTION, cmd_sid_option_sid_id, |
81 | 82 | 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), |
82 | 86 |
|
83 | 87 | SHELL_SUBCMD_SET_END); |
84 | 88 |
|
@@ -989,6 +993,71 @@ int cmd_sid_option_gc(const struct shell *shell, int32_t argc, const char **argv |
989 | 993 | return 0; |
990 | 994 | } |
991 | 995 |
|
| 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 | + |
992 | 1061 | int cmd_sid_last_status(const struct shell *shell, int32_t argc, const char **argv) |
993 | 1062 | { |
994 | 1063 | CHECK_ARGUMENT_COUNT(argc, CMD_SID_LAST_STATUS_ARG_REQUIRED, |
|
0 commit comments