mirror of
https://github.com/espressif/openthread.git
synced 2026-08-21 01:49:52 +00:00
[mac] add ComputeLinkMargin() (#8063)
This commit adds a helper method in `Mac` to compute link margin from a given received signal strength (in dBm) using the radio noise floor.
This commit is contained in:
@@ -275,7 +275,8 @@ bool otLinkIsRadioFilterEnabled(otInstance *aInstance)
|
||||
|
||||
uint8_t otLinkConvertRssToLinkQuality(otInstance *aInstance, int8_t aRss)
|
||||
{
|
||||
return LinkQualityInfo::ConvertRssToLinkQuality(AsCoreType(aInstance).Get<Mac::Mac>().GetNoiseFloor(), aRss);
|
||||
return LinkQualityInfo::ConvertLinkMarginToLinkQuality(
|
||||
AsCoreType(aInstance).Get<Mac::Mac>().ComputeLinkMargin(aRss));
|
||||
}
|
||||
|
||||
int8_t otLinkConvertLinkQualityToRss(otInstance *aInstance, uint8_t aLinkQuality)
|
||||
|
||||
@@ -2134,6 +2134,11 @@ void Mac::ResetRetrySuccessHistogram()
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE
|
||||
|
||||
uint8_t Mac::ComputeLinkMargin(int8_t aRss) const
|
||||
{
|
||||
return LinkQualityInfo::ConvertRssToLinkMargin(GetNoiseFloor(), aRss);
|
||||
}
|
||||
|
||||
// LCOV_EXCL_START
|
||||
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
|
||||
+11
-1
@@ -546,7 +546,17 @@ public:
|
||||
* @returns The noise floor value in dBm.
|
||||
*
|
||||
*/
|
||||
int8_t GetNoiseFloor(void) { return mLinks.GetNoiseFloor(); }
|
||||
int8_t GetNoiseFloor(void) const { return mLinks.GetNoiseFloor(); }
|
||||
|
||||
/**
|
||||
* This method computes the link margin for a given a received signal strength value using noise floor.
|
||||
*
|
||||
* @param[in] aRss The received signal strength in dBm.
|
||||
*
|
||||
* @returns The link margin for @p aRss in dB based on noise floor.
|
||||
*
|
||||
*/
|
||||
uint8_t ComputeLinkMargin(int8_t aRss) const;
|
||||
|
||||
/**
|
||||
* This method returns the current CCA (Clear Channel Assessment) failure rate.
|
||||
|
||||
@@ -620,7 +620,7 @@ public:
|
||||
* @returns The noise floor value in dBm.
|
||||
*
|
||||
*/
|
||||
int8_t GetNoiseFloor(void)
|
||||
int8_t GetNoiseFloor(void) const
|
||||
{
|
||||
return
|
||||
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||
|
||||
@@ -684,7 +684,7 @@ int8_t SubMac::GetRssi(void) const
|
||||
return rssi;
|
||||
}
|
||||
|
||||
int8_t SubMac::GetNoiseFloor(void)
|
||||
int8_t SubMac::GetNoiseFloor(void) const
|
||||
{
|
||||
return Get<Radio>().GetReceiveSensitivity();
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ public:
|
||||
* @returns The noise floor value in dBm.
|
||||
*
|
||||
*/
|
||||
int8_t GetNoiseFloor(void);
|
||||
int8_t GetNoiseFloor(void) const;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
||||
/**
|
||||
|
||||
@@ -236,7 +236,7 @@ public:
|
||||
* @returns The radio receive sensitivity value in dBm.
|
||||
*
|
||||
*/
|
||||
int8_t GetReceiveSensitivity(void);
|
||||
int8_t GetReceiveSensitivity(void) const;
|
||||
|
||||
#if OPENTHREAD_RADIO
|
||||
/**
|
||||
@@ -656,7 +656,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
otInstance *GetInstancePtr(void) { return reinterpret_cast<otInstance *>(&InstanceLocator::GetInstance()); }
|
||||
otInstance *GetInstancePtr(void) const { return reinterpret_cast<otInstance *>(&InstanceLocator::GetInstance()); }
|
||||
|
||||
Callbacks mCallbacks;
|
||||
};
|
||||
@@ -695,7 +695,7 @@ inline otRadioCaps Radio::GetCaps(void)
|
||||
return otPlatRadioGetCaps(GetInstancePtr());
|
||||
}
|
||||
|
||||
inline int8_t Radio::GetReceiveSensitivity(void)
|
||||
inline int8_t Radio::GetReceiveSensitivity(void) const
|
||||
{
|
||||
return otPlatRadioGetReceiveSensitivity(GetInstancePtr());
|
||||
}
|
||||
@@ -870,7 +870,7 @@ inline otRadioCaps Radio::GetCaps(void)
|
||||
return OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_CSMA_BACKOFF | OT_RADIO_CAPS_TRANSMIT_RETRIES;
|
||||
}
|
||||
|
||||
inline int8_t Radio::GetReceiveSensitivity(void)
|
||||
inline int8_t Radio::GetReceiveSensitivity(void) const
|
||||
{
|
||||
return -110;
|
||||
}
|
||||
|
||||
@@ -254,9 +254,7 @@ Error LinkMetrics::AppendReport(Message &aMessage, const Message &aRequestMessag
|
||||
values.mPduCountValue = aRequestMessage.GetPsduCount();
|
||||
values.mLqiValue = aRequestMessage.GetAverageLqi();
|
||||
// Linearly scale Link Margin from [0, 130] to [0, 255]
|
||||
values.mLinkMarginValue =
|
||||
LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(), aRequestMessage.GetAverageRss()) *
|
||||
255 / 130;
|
||||
values.mLinkMarginValue = Get<Mac::Mac>().ComputeLinkMargin(aRequestMessage.GetAverageRss()) * 255 / 130;
|
||||
// Linearly scale rss from [-130, 0] to [0, 255]
|
||||
values.mRssiValue = (aRequestMessage.GetAverageRss() + 130) * 255 / 130;
|
||||
|
||||
@@ -280,9 +278,7 @@ Error LinkMetrics::AppendReport(Message &aMessage, const Message &aRequestMessag
|
||||
values.mPduCountValue = seriesInfo->GetPduCount();
|
||||
values.mLqiValue = seriesInfo->GetAverageLqi();
|
||||
// Linearly scale Link Margin from [0, 130] to [0, 255]
|
||||
values.mLinkMarginValue =
|
||||
LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(), seriesInfo->GetAverageRss()) *
|
||||
255 / 130;
|
||||
values.mLinkMarginValue = Get<Mac::Mac>().ComputeLinkMargin(seriesInfo->GetAverageRss()) * 255 / 130;
|
||||
// Linearly scale RSSI from [-130, 0] to [0, 255]
|
||||
values.mRssiValue = (seriesInfo->GetAverageRss() + 130) * 255 / 130;
|
||||
SuccessOrExit(error = AppendReportSubTlvToMessage(aMessage, values));
|
||||
|
||||
@@ -3090,7 +3090,7 @@ void Mle::HandleParentResponse(RxInfo &aRxInfo)
|
||||
// Link Margin
|
||||
SuccessOrExit(error = Tlv::Find<LinkMarginTlv>(aRxInfo.mMessage, linkMarginFromTlv));
|
||||
|
||||
linkMargin = LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(), linkInfo->GetRss());
|
||||
linkMargin = Get<Mac::Mac>().ComputeLinkMargin(linkInfo->GetRss());
|
||||
|
||||
if (linkMargin > linkMarginFromTlv)
|
||||
{
|
||||
|
||||
@@ -763,8 +763,7 @@ Error MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo,
|
||||
SuccessOrExit(error = message->AppendMleFrameCounterTlv());
|
||||
|
||||
// always append a link margin, regardless of whether or not it was requested
|
||||
linkMargin = LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(),
|
||||
aMessageInfo.GetThreadLinkInfo()->GetRss());
|
||||
linkMargin = Get<Mac::Mac>().ComputeLinkMargin(aMessageInfo.GetThreadLinkInfo()->GetRss());
|
||||
|
||||
SuccessOrExit(error = message->AppendLinkMarginTlv(linkMargin));
|
||||
|
||||
@@ -1224,17 +1223,17 @@ exit:
|
||||
|
||||
Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
const ThreadLinkInfo *linkInfo = aRxInfo.mMessageInfo.GetThreadLinkInfo();
|
||||
uint8_t linkMargin = LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(), linkInfo->GetRss());
|
||||
Mac::ExtAddress extAddr;
|
||||
uint16_t sourceAddress = Mac::kShortAddrInvalid;
|
||||
LeaderData leaderData;
|
||||
RouteTlv route;
|
||||
uint32_t partitionId;
|
||||
Router * router;
|
||||
uint8_t routerId;
|
||||
uint8_t routerCount;
|
||||
Error error = kErrorNone;
|
||||
const ThreadLinkInfo *linkInfo = aRxInfo.mMessageInfo.GetThreadLinkInfo();
|
||||
uint8_t linkMargin = Get<Mac::Mac>().ComputeLinkMargin(linkInfo->GetRss());
|
||||
Mac::ExtAddress extAddr;
|
||||
uint16_t sourceAddress = Mac::kShortAddrInvalid;
|
||||
LeaderData leaderData;
|
||||
RouteTlv route;
|
||||
uint32_t partitionId;
|
||||
Router * router;
|
||||
uint8_t routerId;
|
||||
uint8_t routerCount;
|
||||
|
||||
aRxInfo.mMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr);
|
||||
|
||||
@@ -1780,8 +1779,7 @@ bool MleRouter::HasNeighborWithGoodLinkQuality(void) const
|
||||
bool haveNeighbor = true;
|
||||
uint8_t linkMargin;
|
||||
|
||||
linkMargin =
|
||||
LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(), mParent.GetLinkInfo().GetLastRss());
|
||||
linkMargin = Get<Mac::Mac>().ComputeLinkMargin(mParent.GetLinkInfo().GetLastRss());
|
||||
|
||||
if (linkMargin >= OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN)
|
||||
{
|
||||
@@ -1795,8 +1793,7 @@ bool MleRouter::HasNeighborWithGoodLinkQuality(void) const
|
||||
continue;
|
||||
}
|
||||
|
||||
linkMargin =
|
||||
LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(), router.GetLinkInfo().GetLastRss());
|
||||
linkMargin = Get<Mac::Mac>().ComputeLinkMargin(router.GetLinkInfo().GetLastRss());
|
||||
|
||||
if (linkMargin >= OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user