-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread Scan Network command handling for end devices #15105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,8 @@ void initNetworkCommissioningThreadDriver(void) | |
#endif | ||
} | ||
|
||
NetworkCommissioning::ThreadScanResponse * scanResult; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasoning why this works here is that the also gotcha for the s. Will do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, no need to change that then. |
||
otScanResponseIterator<NetworkCommissioning::ThreadScanResponse> mScanResponseIter(scanResult); | ||
} // namespace | ||
// Fully instantiate the generic implementation class in whatever compilation unit includes this file. | ||
template class GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>; | ||
|
@@ -359,11 +361,55 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnThreadAttachFinishe | |
template <class ImplClass> | ||
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_StartThreadScan(ThreadDriver::ScanCallback * callback) | ||
{ | ||
// TODO END scan feature + _OnNetworkScanFinished callback for response | ||
// There is another ongoing scan request, reject the new one. | ||
// If there is another ongoing scan request, reject the new one. | ||
VerifyOrReturnError(mpScanCallback == nullptr, CHIP_ERROR_INCORRECT_STATE); | ||
mpScanCallback = callback; | ||
return CHIP_NO_ERROR; | ||
CHIP_ERROR err = MapOpenThreadError(otLinkActiveScan(mOTInst, 0, /* all channels */ | ||
0, /* default value `kScanDurationDefault` = 300 ms. */ | ||
selissia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_OnNetworkScanFinished, this)); | ||
return err; | ||
} | ||
|
||
template <class ImplClass> | ||
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnNetworkScanFinished(otActiveScanResult * aResult, void * aContext) | ||
{ | ||
reinterpret_cast<GenericThreadStackManagerImpl_OpenThread *>(aContext)->_OnNetworkScanFinished(aResult); | ||
} | ||
|
||
template <class ImplClass> | ||
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnNetworkScanFinished(otActiveScanResult * aResult) | ||
{ | ||
if (aResult == nullptr) // scan completed | ||
{ | ||
if (mpScanCallback != nullptr) | ||
{ | ||
DeviceLayer::SystemLayer().ScheduleLambda([this]() { | ||
mpScanCallback->OnFinished(NetworkCommissioning::Status::kSuccess, CharSpan(), &mScanResponseIter); | ||
mpScanCallback = nullptr; | ||
}); | ||
} | ||
} | ||
else | ||
{ | ||
ChipLogProgress( | ||
DeviceLayer, | ||
"Thread Network: %s Panid 0x%" PRIx16 " Channel %" PRIu16 " RSSI %" PRId16 " LQI %" PRIu16 " Version %" PRIu16, | ||
aResult->mNetworkName.m8, aResult->mPanId, aResult->mChannel, aResult->mRssi, aResult->mLqi, aResult->mVersion); | ||
|
||
NetworkCommissioning::ThreadScanResponse scanResponse = { 0 }; | ||
|
||
scanResponse.panId = aResult->mPanId; // why is scanResponse.panID 64b | ||
scanResponse.channel = aResult->mChannel; // why is scanResponse.channel 16b | ||
scanResponse.version = aResult->mVersion; | ||
scanResponse.rssi = aResult->mRssi; | ||
scanResponse.lqi = aResult->mLqi; | ||
scanResponse.extendedAddress = Encoding::BigEndian::Get64(aResult->mExtAddress.m8); | ||
scanResponse.extendedPanId = Encoding::BigEndian::Get64(aResult->mExtendedPanId.m8); | ||
scanResponse.networkNameLen = strnlen(aResult->mNetworkName.m8, OT_NETWORK_NAME_MAX_SIZE); | ||
memcpy(scanResponse.networkName, aResult->mNetworkName.m8, scanResponse.networkNameLen); | ||
|
||
mScanResponseIter.Add(&scanResponse); | ||
} | ||
} | ||
|
||
template <class ImplClass> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
static constexpr
not to occupy memory for that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did add the
constexpr
first, but the compiler was complaining that I wasn't assigning a constant value withsizeof(T).
Let me try adding static also that might have been my mistake. If that works I'll add