Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 13b683e

Browse files
authored
Merge pull request #338 from robszewczyk/bug/power-usage-on-init
Fix high power usage in the unprovisioned state
2 parents 3849e90 + 46c3a03 commit 13b683e

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/adaptations/device-layer/include/Weave/DeviceLayer/OpenThread/GenericThreadStackManagerImpl_OpenThread.ipp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,25 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnPlatformEvent(const
150150
{
151151
if (event->Type == DeviceEventType::kThreadStateChange)
152152
{
153-
#if WEAVE_DETAIL_LOGGING
154-
155153
Impl()->LockThreadStack();
156154

155+
#if WEAVE_DETAIL_LOGGING
156+
157157
LogOpenThreadStateChange(mOTInst, event->ThreadStateChange.OpenThread.Flags);
158158

159+
#endif // WEAVE_DETAIL_LOGGING
160+
161+
// The API we provide to enable/disable thread controls both the Thread
162+
// stack and the IP6 stack within OpenThread. In order to properly
163+
// initialize OpenThread, we need to enable IP6 in OT, and we can
164+
// disable it once the OT stack is up and running and signaling events.
165+
if ((otThreadGetDeviceRole(mOTInst) == OT_DEVICE_ROLE_DISABLED) && otIp6IsEnabled(mOTInst))
166+
{
167+
otIp6SetEnabled(mOTInst, false);
168+
}
169+
159170
Impl()->UnlockThreadStack();
160171

161-
#endif // WEAVE_DETAIL_LOGGING
162172
}
163173
}
164174

@@ -182,11 +192,27 @@ WEAVE_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetThreadEnabl
182192
Impl()->LockThreadStack();
183193

184194
bool isEnabled = (otThreadGetDeviceRole(mOTInst) != OT_DEVICE_ROLE_DISABLED);
195+
bool isIp6Enabled = otIp6IsEnabled(mOTInst);
196+
197+
if (val && !isIp6Enabled)
198+
{
199+
otErr = otIp6SetEnabled(mOTInst, val);
200+
VerifyOrExit(otErr == OT_ERROR_NONE, );
201+
}
202+
185203
if (val != isEnabled)
186204
{
187205
otErr = otThreadSetEnabled(mOTInst, val);
206+
VerifyOrExit(otErr == OT_ERROR_NONE, );
188207
}
189208

209+
if (!val && isIp6Enabled)
210+
{
211+
otErr = otIp6SetEnabled(mOTInst, val);
212+
VerifyOrExit(otErr == OT_ERROR_NONE, );
213+
}
214+
215+
exit:
190216
Impl()->UnlockThreadStack();
191217

192218
return MapOpenThreadError(otErr);

0 commit comments

Comments
 (0)