Skip to content

Commit

Permalink
[options] add an option to control power calibration (#2590)
Browse files Browse the repository at this point in the history
This commit adds an option to enable/disable the power calibration
functionality in otbr.

The recently introduced ThreadHost API `SetChannelMaxPowers` depends
on the radio platform API `otPlatRadioSetChannelTargetPower` which may
not be enabled on some platforms/products. In those cases, we will
have undefined symbols error. This commit adds a build option to
disable the power calibration function in otbr. On those
platforms/products who don't enable
`otPlatRadioSetChannelTargetPower`, they should turn off this option
as well.
  • Loading branch information
Irving-cl authored Nov 12, 2024
1 parent 6111b06 commit ef7bb73
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
7 changes: 7 additions & 0 deletions etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,10 @@ if (OTBR_LINK_METRICS_TELEMETRY)
else()
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_LINK_METRICS_TELEMETRY=0)
endif()

option(OTBR_POWER_CALIBRATION "Enable Power Calibration" ON)
if (OTBR_POWER_CALIBRATION)
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_POWER_CALIBRATION=1)
else()
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_POWER_CALIBRATION=0)
endif()
2 changes: 2 additions & 0 deletions src/ncp/ncp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void NcpHost::GetChannelMasks(const ChannelMasksReceiver &aReceiver, const Async
mTaskRunner.Post([aErrReceiver](void) { aErrReceiver(OT_ERROR_NOT_IMPLEMENTED, "Not implemented!"); });
}

#if OTBR_ENABLE_POWER_CALIBRATION
void NcpHost::SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver)
{
Expand All @@ -202,6 +203,7 @@ void NcpHost::SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMa
// TODO: Implement SetChannelMaxPowers under NCP mode.
mTaskRunner.Post([aReceiver](void) { aReceiver(OT_ERROR_NOT_IMPLEMENTED, "Not implemented!"); });
}
#endif

void NcpHost::AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback)
{
Expand Down
20 changes: 14 additions & 6 deletions src/ncp/ncp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,22 @@ class NcpHost : public MainloopProcessor, public ThreadHost, public NcpNetworkPr
void SetThreadEnabled(bool aEnabled, const AsyncResultReceiver aReceiver) override;
void SetCountryCode(const std::string &aCountryCode, const AsyncResultReceiver &aReceiver) override;
void GetChannelMasks(const ChannelMasksReceiver &aReceiver, const AsyncResultReceiver &aErrReceiver) override;
#if OTBR_ENABLE_POWER_CALIBRATION
void SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver) override;
void AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback) override;
CoprocessorType GetCoprocessorType(void) override { return OT_COPROCESSOR_NCP; }
const char *GetCoprocessorVersion(void) override;
const char *GetInterfaceName(void) const override { return mConfig.mInterfaceName; }
void Init(void) override;
void Deinit(void) override;
#endif
void AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback) override;
CoprocessorType GetCoprocessorType(void) override
{
return OT_COPROCESSOR_NCP;
}
const char *GetCoprocessorVersion(void) override;
const char *GetInterfaceName(void) const override
{
return mConfig.mInterfaceName;
}
void Init(void) override;
void Deinit(void) override;

// MainloopProcessor methods
void Update(MainloopContext &aMainloop) override;
Expand Down
2 changes: 2 additions & 0 deletions src/ncp/rcp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ void RcpHost::GetChannelMasks(const ChannelMasksReceiver &aReceiver, const Async
}
}

#if OTBR_ENABLE_POWER_CALIBRATION
void RcpHost::SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver)
{
Expand Down Expand Up @@ -549,6 +550,7 @@ void RcpHost::SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMa
exit:
mTaskRunner.Post([aReceiver, error, errorMsg](void) { aReceiver(error, errorMsg); });
}
#endif // OTBR_ENABLE_POWER_CALIBRATION

void RcpHost::DisableThreadAfterDetach(void *aContext)
{
Expand Down
2 changes: 2 additions & 0 deletions src/ncp/rcp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ class RcpHost : public MainloopProcessor, public ThreadHost, public OtNetworkPro
void SetThreadEnabled(bool aEnabled, const AsyncResultReceiver aReceiver) override;
void SetCountryCode(const std::string &aCountryCode, const AsyncResultReceiver &aReceiver) override;
void GetChannelMasks(const ChannelMasksReceiver &aReceiver, const AsyncResultReceiver &aErrReceiver) override;
#if OTBR_ENABLE_POWER_CALIBRATION
void SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver) override;
#endif
void AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback) override;

CoprocessorType GetCoprocessorType(void) override
Expand Down
2 changes: 2 additions & 0 deletions src/ncp/thread_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class ThreadHost : virtual public NetworkProperties
*/
virtual void GetChannelMasks(const ChannelMasksReceiver &aReceiver, const AsyncResultReceiver &aErrReceiver) = 0;

#if OTBR_ENABLE_POWER_CALIBRATION
/**
* Sets the max power of each channel.
*
Expand All @@ -201,6 +202,7 @@ class ThreadHost : virtual public NetworkProperties
*/
virtual void SetChannelMaxPowers(const std::vector<ChannelMaxPower> &aChannelMaxPowers,
const AsyncResultReceiver &aReceiver) = 0;
#endif

/**
* This method adds a event listener for Thread state changes.
Expand Down

0 comments on commit ef7bb73

Please sign in to comment.