From cb40a452985de5fe8816c642ce8d24832cd5cab7 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 7 Apr 2023 09:26:38 -0700 Subject: [PATCH] [joiner] use `Clamp()` function to calculate priority from RSS (#8937) --- src/core/meshcop/joiner.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 9894b9385..fc6ac92c6 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -238,20 +238,8 @@ uint8_t Joiner::CalculatePriority(int8_t aRssi, bool aSteeringDataAllowsAny) aRssi = -127; } - // Limit the RSSI to range (-128, 0), i.e. -128 < aRssi < 0. - - if (aRssi <= -128) - { - priority = -127; - } - else if (aRssi >= 0) - { - priority = -1; - } - else - { - priority = aRssi; - } + // Clamp the RSSI to range [-127, -1] + priority = Clamp(aRssi, -127, -1); // Assign higher priority to networks with an exact match of Joiner // ID in the Steering Data (128 < priority < 256) compared to ones