mirror of
https://github.com/espressif/openthread.git
synced 2026-08-22 10:29:52 +00:00
[announce-sender] change SendAnnounce() to return void (#4941)
- Move "start" log to common method. - Use default param value instead of duplicate method.
This commit is contained in:
@@ -54,14 +54,9 @@ AnnounceBeginServer::AnnounceBeginServer(Instance &aInstance)
|
||||
IgnoreError(Get<Coap::Coap>().AddResource(mAnnounceBegin));
|
||||
}
|
||||
|
||||
otError AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask)
|
||||
void AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod)
|
||||
{
|
||||
return SendAnnounce(aChannelMask, kDefaultCount, kDefaultPeriod);
|
||||
}
|
||||
|
||||
otError AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod)
|
||||
{
|
||||
return AnnounceSenderBase::SendAnnounce(Mac::ChannelMask(aChannelMask), aCount, aPeriod, kDefaultJitter);
|
||||
AnnounceSenderBase::SendAnnounce(Mac::ChannelMask(aChannelMask), aCount, aPeriod, kDefaultJitter);
|
||||
}
|
||||
|
||||
void AnnounceBeginServer::HandleRequest(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
||||
@@ -83,7 +78,7 @@ void AnnounceBeginServer::HandleRequest(Coap::Message &aMessage, const Ip6::Mess
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(aMessage, MeshCoP::Tlv::kCount, count));
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, MeshCoP::Tlv::kPeriod, period));
|
||||
|
||||
IgnoreError(SendAnnounce(mask, count, period));
|
||||
SendAnnounce(mask, count, period);
|
||||
|
||||
if (aMessage.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
|
||||
{
|
||||
|
||||
@@ -57,16 +57,6 @@ public:
|
||||
*/
|
||||
explicit AnnounceBeginServer(Instance &aInstance);
|
||||
|
||||
/**
|
||||
* This method begins the MLE Announce transmission process using Count=3 and Period=1s.
|
||||
*
|
||||
* @param[in] aChannelMask The channels to use for transmission.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully started the transmission process.
|
||||
*
|
||||
*/
|
||||
otError SendAnnounce(uint32_t aChannelMask);
|
||||
|
||||
/**
|
||||
* This method begins the MLE Announce transmission process.
|
||||
*
|
||||
@@ -77,7 +67,7 @@ public:
|
||||
* @retval OT_ERROR_NONE Successfully started the transmission process.
|
||||
*
|
||||
*/
|
||||
otError SendAnnounce(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod);
|
||||
void SendAnnounce(uint32_t aChannelMask, uint8_t aCount = kDefaultCount, uint16_t aPeriod = kDefaultPeriod);
|
||||
|
||||
private:
|
||||
enum
|
||||
|
||||
@@ -57,18 +57,13 @@ AnnounceSenderBase::AnnounceSenderBase(Instance &aInstance, Timer::Handler aHand
|
||||
{
|
||||
}
|
||||
|
||||
otError AnnounceSenderBase::SendAnnounce(Mac::ChannelMask aChannelMask,
|
||||
uint8_t aCount,
|
||||
uint32_t aPeriod,
|
||||
uint16_t aJitter)
|
||||
void AnnounceSenderBase::SendAnnounce(Mac::ChannelMask aChannelMask, uint8_t aCount, uint32_t aPeriod, uint16_t aJitter)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aPeriod != 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aJitter < aPeriod, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aPeriod != 0, OT_NOOP);
|
||||
VerifyOrExit(aJitter < aPeriod, OT_NOOP);
|
||||
|
||||
aChannelMask.Intersect(Get<Mac::Mac>().GetSupportedChannelMask());
|
||||
VerifyOrExit(!aChannelMask.IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(!aChannelMask.IsEmpty(), OT_NOOP);
|
||||
|
||||
mChannelMask = aChannelMask;
|
||||
mCount = aCount;
|
||||
@@ -78,8 +73,11 @@ otError AnnounceSenderBase::SendAnnounce(Mac::ChannelMask aChannelMask,
|
||||
|
||||
mTimer.Start(Random::NonCrypto::AddJitter(mPeriod, mJitter));
|
||||
|
||||
otLogInfoMle("Starting periodic MLE Announcements tx, mask %s, count %u, period %u, jitter %u",
|
||||
aChannelMask.ToString().AsCString(), aCount, aPeriod, aJitter);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
return;
|
||||
}
|
||||
|
||||
void AnnounceSenderBase::HandleTimer(void)
|
||||
@@ -102,7 +100,7 @@ void AnnounceSenderBase::HandleTimer(void)
|
||||
|
||||
OT_ASSERT(error == OT_ERROR_NONE);
|
||||
|
||||
IgnoreError(Get<Mle::MleRouter>().SendAnnounce(mChannel, false));
|
||||
Get<Mle::MleRouter>().SendAnnounce(mChannel, false);
|
||||
|
||||
mTimer.Start(Random::NonCrypto::AddJitter(mPeriod, mJitter));
|
||||
|
||||
@@ -165,10 +163,7 @@ void AnnounceSender::CheckState(void)
|
||||
|
||||
VerifyOrExit(!IsRunning() || (period != GetPeriod()) || (GetChannelMask() != channelMask), OT_NOOP);
|
||||
|
||||
IgnoreError(SendAnnounce(channelMask, 0, period, kMaxJitter));
|
||||
|
||||
otLogInfoMle("Starting periodic MLE Announcements tx, period %u, mask %s", period,
|
||||
channelMask.ToString().AsCString());
|
||||
SendAnnounce(channelMask, 0, period, kMaxJitter);
|
||||
|
||||
exit:
|
||||
return;
|
||||
|
||||
@@ -75,11 +75,8 @@ protected:
|
||||
* @param[in] aPeriod The time between two successive MLE Announce transmissions (in milliseconds).
|
||||
* @param[in] aJitter Maximum random jitter added to @aPeriod per transmission (in milliseconds).
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully started the transmission process.
|
||||
* @retval OT_ERROR_INVALID_ARGS @p aChanelMask is empty, or @p aPeriod is zero or smaller than @aJitter.
|
||||
*
|
||||
*/
|
||||
otError SendAnnounce(Mac::ChannelMask aChannelMask, uint8_t aCount, uint32_t aPeriod, uint16_t aJitter);
|
||||
void SendAnnounce(Mac::ChannelMask aChannelMask, uint8_t aCount, uint32_t aPeriod, uint16_t aJitter);
|
||||
|
||||
/**
|
||||
* This method stops the ongoing MLE Announce transmissions.
|
||||
|
||||
@@ -823,7 +823,7 @@ void Mle::InformPreviousChannel(void)
|
||||
#endif
|
||||
|
||||
mAlternatePanId = Mac::kPanIdBroadcast;
|
||||
IgnoreError(Get<AnnounceBeginServer>().SendAnnounce(1 << mAlternateChannel));
|
||||
Get<AnnounceBeginServer>().SendAnnounce(1 << mAlternateChannel);
|
||||
|
||||
exit:
|
||||
return;
|
||||
@@ -2441,16 +2441,16 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce)
|
||||
void Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce)
|
||||
{
|
||||
Ip6::Address destination;
|
||||
|
||||
destination.SetToLinkLocalAllNodesMulticast();
|
||||
|
||||
return SendAnnounce(aChannel, aOrphanAnnounce, destination);
|
||||
SendAnnounce(aChannel, aOrphanAnnounce, destination);
|
||||
}
|
||||
|
||||
otError Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination)
|
||||
void Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
ChannelTlv channel;
|
||||
@@ -2494,8 +2494,6 @@ exit:
|
||||
{
|
||||
message->Free();
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Mle::SendOrphanAnnounce(void)
|
||||
@@ -2510,7 +2508,7 @@ otError Mle::SendOrphanAnnounce(void)
|
||||
|
||||
SuccessOrExit(error = channelMask.GetNextChannel(mAnnounceChannel));
|
||||
|
||||
IgnoreError(SendAnnounce(mAnnounceChannel, true));
|
||||
SendAnnounce(mAnnounceChannel, true);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -3802,10 +3800,10 @@ void Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo &aMessa
|
||||
}
|
||||
else if (localTimestamp->Compare(timestamp) < 0)
|
||||
{
|
||||
IgnoreError(SendAnnounce(channel, false));
|
||||
SendAnnounce(channel, false);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MLE_SEND_UNICAST_ANNOUNCE_RESPONSE
|
||||
IgnoreError(SendAnnounce(channel, false, aMessageInfo.GetPeerAddr()));
|
||||
SendAnnounce(channel, false, aMessageInfo.GetPeerAddr());
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
||||
@@ -421,11 +421,8 @@ public:
|
||||
* @param[in] aChannel The channel to use when transmitting.
|
||||
* @param[in] aOrphanAnnounce To indicate if MLE Announce is sent from an orphan end device.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully generated an MLE Announce message.
|
||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers to generate the MLE Announce message.
|
||||
*
|
||||
*/
|
||||
otError SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce);
|
||||
void SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce);
|
||||
|
||||
/**
|
||||
* This method causes the Thread interface to detach from the Thread network.
|
||||
@@ -1731,7 +1728,7 @@ private:
|
||||
otError SendChildIdRequest(void);
|
||||
otError SendOrphanAnnounce(void);
|
||||
bool PrepareAnnounceState(void);
|
||||
otError SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination);
|
||||
void SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination);
|
||||
uint32_t Reattach(void);
|
||||
|
||||
bool IsBetterParent(uint16_t aRloc16,
|
||||
|
||||
Reference in New Issue
Block a user