mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 22:57:46 +00:00
[commissioner] simplify energy list parsing in report handler (#12666)
This commit updates `Commissioner::HandleTmf<kUriEnergyReport>()` to read the energy list data directly into a local array instead of using a dedicated TLV class. The report handler now uses `Tlv::FindTlvValueOffsetRange()` to locate the TLV value, which works correctly whether the TLV is encoded as a standard or extended TLV. With this change, the `EnergyListTlv` class definition is replaced with a simple typedef to `TlvInfo`.
This commit is contained in:
@@ -1070,8 +1070,9 @@ exit:
|
||||
|
||||
template <> void Commissioner::HandleTmf<kUriEnergyReport>(Coap::Msg &aMsg)
|
||||
{
|
||||
uint32_t mask;
|
||||
EnergyListTlv energyListTlv;
|
||||
uint32_t mask;
|
||||
OffsetRange valueOffsetRange;
|
||||
uint8_t results[kMaxEnergyScanResults];
|
||||
|
||||
VerifyOrExit(aMsg.IsConfirmable());
|
||||
|
||||
@@ -1079,9 +1080,11 @@ template <> void Commissioner::HandleTmf<kUriEnergyReport>(Coap::Msg &aMsg)
|
||||
|
||||
SuccessOrExit(ChannelMaskTlv::FindIn(aMsg.mMessage, mask));
|
||||
|
||||
SuccessOrExit(Tlv::FindTlv(aMsg.mMessage, Tlv::kEnergyList, sizeof(energyListTlv), energyListTlv));
|
||||
SuccessOrExit(Tlv::FindTlvValueOffsetRange(aMsg.mMessage, Tlv::kEnergyList, valueOffsetRange));
|
||||
valueOffsetRange.ShrinkLength(sizeof(results));
|
||||
aMsg.mMessage.ReadBytes(valueOffsetRange, results);
|
||||
|
||||
mEnergyReportCallback.InvokeIfSet(mask, energyListTlv.GetEnergyList(), energyListTlv.GetEnergyListLength());
|
||||
mEnergyReportCallback.InvokeIfSet(mask, results, static_cast<uint8_t>(valueOffsetRange.GetLength()));
|
||||
|
||||
SuccessOrExit(Get<Tmf::Agent>().SendAckResponse(aMsg));
|
||||
|
||||
|
||||
@@ -382,6 +382,8 @@ private:
|
||||
static constexpr uint32_t kJoinerSessionTimeoutMillis =
|
||||
1000 * OPENTHREAD_CONFIG_COMMISSIONER_JOINER_SESSION_TIMEOUT; // Expiration time for active Joiner session
|
||||
|
||||
static constexpr uint8_t kMaxEnergyScanResults = OPENTHREAD_CONFIG_TMF_ENERGY_SCAN_MAX_RESULTS;
|
||||
|
||||
enum ResignMode : uint8_t
|
||||
{
|
||||
kSendKeepAliveToResign,
|
||||
|
||||
@@ -724,48 +724,9 @@ private:
|
||||
} OT_TOOL_PACKED_BEGIN;
|
||||
|
||||
/**
|
||||
* Implements Energy List TLV generation and parsing.
|
||||
* Defines Energy List TLV constants and types.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class EnergyListTlv : public Tlv, public TlvInfo<Tlv::kEnergyList>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the TLV.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetType(kEnergyList);
|
||||
SetLength(sizeof(*this) - sizeof(Tlv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not the TLV appears to be well-formed.
|
||||
*
|
||||
* @retval TRUE If the TLV appears to be well-formed.
|
||||
* @retval FALSE If the TLV does not appear to be well-formed.
|
||||
*/
|
||||
bool IsValid(void) const { return true; }
|
||||
|
||||
/**
|
||||
* Returns a pointer to the start of energy measurement list.
|
||||
*
|
||||
* @returns A pointer to the start start of energy energy measurement list.
|
||||
*/
|
||||
const uint8_t *GetEnergyList(void) const { return mEnergyList; }
|
||||
|
||||
/**
|
||||
* Returns the length of energy measurement list.
|
||||
*
|
||||
* @returns The length of energy measurement list.
|
||||
*/
|
||||
uint8_t GetEnergyListLength(void) const { return Min(kMaxListLength, GetLength()); }
|
||||
|
||||
private:
|
||||
static constexpr uint8_t kMaxListLength = OPENTHREAD_CONFIG_TMF_ENERGY_SCAN_MAX_RESULTS;
|
||||
|
||||
uint8_t mEnergyList[kMaxListLength];
|
||||
} OT_TOOL_PACKED_END;
|
||||
typedef TlvInfo<Tlv::kEnergyList> EnergyListTlv;
|
||||
|
||||
/**
|
||||
* Defines Provisioning TLV constants and types.
|
||||
|
||||
Reference in New Issue
Block a user