diff options
-rw-r--r-- | api/direct_bt/HCITypes.hpp | 6 | ||||
-rw-r--r-- | java/org/direct_bt/BTUtils.java | 29 |
2 files changed, 27 insertions, 8 deletions
diff --git a/api/direct_bt/HCITypes.hpp b/api/direct_bt/HCITypes.hpp index 86ed1ca2..08d59619 100644 --- a/api/direct_bt/HCITypes.hpp +++ b/api/direct_bt/HCITypes.hpp @@ -94,9 +94,9 @@ namespace direct_bt { * @param multiplier recommendation is 6, we use 10 as default for safety. * @return the resulting supervising timeout in 1/10 [ms], suitable for the HCIHandler::le_create_conn() command. */ - constexpr int32_t getHCIConnSupervisorTimeout(const uint16_t conn_latency, const uint16_t conn_interval_max_ms, - const uint16_t min_result_ms=number(HCIConstInt::LE_CONN_MIN_TIMEOUT_MS), - const uint16_t multiplier=10) noexcept + constexpr uint16_t getHCIConnSupervisorTimeout(const uint16_t conn_latency, const uint16_t conn_interval_max_ms, + const uint16_t min_result_ms=number(HCIConstInt::LE_CONN_MIN_TIMEOUT_MS), + const uint16_t multiplier=10) noexcept { return std::max<uint16_t>(min_result_ms, ( 1 + conn_latency ) * conn_interval_max_ms * std::max<uint16_t>(2, multiplier) diff --git a/java/org/direct_bt/BTUtils.java b/java/org/direct_bt/BTUtils.java index 15e54345..5afc34c0 100644 --- a/java/org/direct_bt/BTUtils.java +++ b/java/org/direct_bt/BTUtils.java @@ -102,11 +102,30 @@ public class BTUtils { * @return the resulting supervising timeout in 1/10 [ms], suitable for the {@link BTDevice#connectLE(short, short, short, short, short, short)}. * @see BTDevice#connectLE(short, short, short, short, short, short) */ - public static int getHCIConnSupervisorTimeout(final int conn_latency, final int conn_interval_max_ms, - final int min_result_ms, final int multiplier) { - return Math.max(min_result_ms, - ( 1 + conn_latency ) * conn_interval_max_ms * Math.max(2, multiplier) - ) / 10; + public static short getHCIConnSupervisorTimeout(final int conn_latency, final int conn_interval_max_ms, + final int min_result_ms, final int multiplier) { + return (short) ( Math.max(min_result_ms, + ( 1 + conn_latency ) * conn_interval_max_ms * Math.max(2, multiplier) + ) / 10 ); + } + /** + * Defining the supervising timeout for LE connections to be a multiple of the maximum connection interval as follows: + * <pre> + * ( 1 + conn_latency ) * conn_interval_max_ms * max(2, multiplier) [ms] + * </pre> + * + * If above result is smaller than the given min_result_ms, min_result_ms/10 will be returned. + * + * - Using minimum resulting supervisor timeout of 500ms. + * - Using multiplier of 10 as default for safety. + * + * @param conn_latency the connection latency + * @param conn_interval_max_ms the maximum connection interval in [ms] + * @return the resulting supervising timeout in 1/10 [ms], suitable for the {@link BTDevice#connectLE(short, short, short, short, short, short)}. + * @see BTDevice#connectLE(short, short, short, short, short, short) + */ + public static short getHCIConnSupervisorTimeout(final int conn_latency, final int conn_interval_max_ms) { + return getHCIConnSupervisorTimeout(conn_latency, conn_interval_max_ms, 500 /* min_result_ms */, 10); } /** |