mirror of
https://github.com/espressif/openthread.git
synced 2026-08-17 07:59:51 +00:00
Cleanup error code usage. Avoid raising errors when value is unchanged. (#787)
This change is attempting to address two issues:
1. Returning `kThreadError_Busy`, when `kThreadError_Already`,
`kThreadError_InvalidState`, or even the lazy
`kThreadError_Failed` would be more-appropriate/less-misleading.
2. Setters returning an error when the value to be changed is already
set to the requested value.
Number one hurts debuggability. Number two makes the code more fragile.
The cases where both intersect can be maddening.
This change replaces cases inappropriately returning
`kThreadError_Busy` with a better, more specific error code. It also
makes some "setter" functions (Including `otInterfaceUp()` and
`otThreadStart()`) return success if the value is already set.
This commit is contained in:
committed by
Jonathan Hui
parent
2d5c4c58f2
commit
104ca6d10d
@@ -175,43 +175,35 @@ void cc2538RadioInit(void)
|
||||
// SRCMATCH.PEND_DATAREQ_ONLY(1), RFCORE_XREG_FRMCTRL1_PENDING_OR(0)
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateDisabled)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
sState = kStateSleep;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateDisabled || sState == kStateSleep)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
sState = kStateDisabled;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
bool otPlatRadioIsEnabled(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return (sState != kStateDisabled) ? true : false;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
if (!otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
sState = kStateSleep;
|
||||
}
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
if (otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
sState = kStateDisabled;
|
||||
}
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSleep(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateReceive)
|
||||
@@ -226,7 +218,7 @@ ThreadError otPlatRadioSleep(otInstance *aInstance)
|
||||
|
||||
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateDisabled)
|
||||
@@ -243,7 +235,7 @@ ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
|
||||
ThreadError otPlatRadioTransmit(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateReceive)
|
||||
|
||||
@@ -371,43 +371,35 @@ void platformRadioInit(void)
|
||||
sAckFrame.mPsdu = sAckMessage.mPsdu;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateDisabled)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
sState = kStateSleep;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateDisabled || sState == kStateSleep)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
sState = kStateDisabled;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
bool otPlatRadioIsEnabled(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return (sState != kStateDisabled) ? true : false;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
if (!otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
sState = kStateSleep;
|
||||
}
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
if (otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
sState = kStateDisabled;
|
||||
}
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSleep(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateReceive)
|
||||
@@ -421,7 +413,7 @@ ThreadError otPlatRadioSleep(otInstance *aInstance)
|
||||
|
||||
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateDisabled)
|
||||
@@ -437,7 +429,7 @@ ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
|
||||
ThreadError otPlatRadioTransmit(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateReceive)
|
||||
|
||||
Reference in New Issue
Block a user