mirror of
https://github.com/espressif/openthread.git
synced 2026-08-15 23:27:47 +00:00
[ncp] reduce size by searching property handlers (#4409)
The big `switch` generates a lot of code on some compilers. This commit drops the switch way to find getters and setters, instead a binary search is used to find property handlers. This requires all handlers are defined in a sorted array.
This commit is contained in:
@@ -2094,6 +2094,27 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_PHY_RX_SENSITIVITY>(v
|
||||
return mEncoder.WriteInt8(otPlatRadioGetReceiveSensitivity(mInstance));
|
||||
}
|
||||
|
||||
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_PHY_FREQ>(void)
|
||||
{
|
||||
uint32_t freq_khz(0);
|
||||
const uint8_t chan(otLinkGetChannel(mInstance));
|
||||
|
||||
if (chan == 0)
|
||||
{
|
||||
freq_khz = 868300;
|
||||
}
|
||||
else if (chan < 11)
|
||||
{
|
||||
freq_khz = 906000 - (2000 * 1) + 2000 * (chan);
|
||||
}
|
||||
else if (chan < 26)
|
||||
{
|
||||
freq_khz = 2405000 - (5000 * 11) + 5000 * (chan);
|
||||
}
|
||||
|
||||
return mEncoder.WriteUint32(freq_khz);
|
||||
}
|
||||
|
||||
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_PHY_CCA_THRESHOLD>(void)
|
||||
{
|
||||
int8_t threshold;
|
||||
|
||||
+17
-4
@@ -202,14 +202,27 @@ protected:
|
||||
uint32_t mPropKeyOrStatus : 24; ///< 3 bytes for either property key or spinel status.
|
||||
};
|
||||
|
||||
struct HandlerEntry
|
||||
{
|
||||
spinel_prop_key_t mKey;
|
||||
NcpBase::PropertyHandler mHandler;
|
||||
};
|
||||
|
||||
NcpFrameBuffer::FrameTag GetLastOutboundFrameTag(void);
|
||||
|
||||
otError HandleCommand(uint8_t aHeader);
|
||||
|
||||
PropertyHandler FindGetPropertyHandler(spinel_prop_key_t aKey);
|
||||
PropertyHandler FindSetPropertyHandler(spinel_prop_key_t aKey);
|
||||
PropertyHandler FindInsertPropertyHandler(spinel_prop_key_t aKey);
|
||||
PropertyHandler FindRemovePropertyHandler(spinel_prop_key_t aKey);
|
||||
#if __cplusplus >= 201103L
|
||||
static constexpr bool IsHandlerEntriesSorted(const HandlerEntry *aHandlerEntries, size_t aSize);
|
||||
#endif
|
||||
|
||||
static PropertyHandler FindPropertyHandler(const HandlerEntry *aHandlerEntries,
|
||||
size_t aSize,
|
||||
spinel_prop_key_t aKey);
|
||||
static PropertyHandler FindGetPropertyHandler(spinel_prop_key_t aKey);
|
||||
static PropertyHandler FindSetPropertyHandler(spinel_prop_key_t aKey);
|
||||
static PropertyHandler FindInsertPropertyHandler(spinel_prop_key_t aKey);
|
||||
static PropertyHandler FindRemovePropertyHandler(spinel_prop_key_t aKey);
|
||||
|
||||
bool HandlePropertySetForSpecialProperties(uint8_t aHeader, spinel_prop_key_t aKey, otError &aError);
|
||||
otError HandleCommandPropertySet(uint8_t aHeader, spinel_prop_key_t aKey);
|
||||
|
||||
+532
-994
File diff suppressed because it is too large
Load Diff
@@ -230,27 +230,6 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_PHY_FREQ>(void)
|
||||
{
|
||||
uint32_t freq_khz(0);
|
||||
const uint8_t chan(otLinkGetChannel(mInstance));
|
||||
|
||||
if (chan == 0)
|
||||
{
|
||||
freq_khz = 868300;
|
||||
}
|
||||
else if (chan < 11)
|
||||
{
|
||||
freq_khz = 906000 - (2000 * 1) + 2000 * (chan);
|
||||
}
|
||||
else if (chan < 26)
|
||||
{
|
||||
freq_khz = 2405000 - (5000 * 11) + 5000 * (chan);
|
||||
}
|
||||
|
||||
return mEncoder.WriteUint32(freq_khz);
|
||||
}
|
||||
|
||||
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_PHY_CHAN_SUPPORTED>(void)
|
||||
{
|
||||
uint32_t newMask = 0;
|
||||
|
||||
Reference in New Issue
Block a user