[posix-host] add otPlatRadioGetState() (#4504)
This commit implements otPlatRadioGetState() on POSIX platforms,
including simulation and posix-host app.
This is for debugging purpose.
diff --git a/examples/platforms/posix/radio.c b/examples/platforms/posix/radio.c
index 51e0c91..5d1d6f4 100644
--- a/examples/platforms/posix/radio.c
+++ b/examples/platforms/posix/radio.c
@@ -826,6 +826,13 @@
return POSIX_RECEIVE_SENSITIVITY;
}
+otRadioState otPlatRadioGetState(otInstance *aInstance)
+{
+ OT_UNUSED_VARIABLE(aInstance);
+
+ return sState;
+}
+
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
otError otPlatRadioSetCoexEnabled(otInstance *aInstance, bool aEnabled)
{
diff --git a/src/posix/platform/radio_spinel.cpp b/src/posix/platform/radio_spinel.cpp
index 1ec7ca0..2f8048e 100644
--- a/src/posix/platform/radio_spinel.cpp
+++ b/src/posix/platform/radio_spinel.cpp
@@ -1598,6 +1598,16 @@
return channelMask;
}
+otRadioState RadioSpinel::GetState(void) const
+{
+ static const otRadioState sOtRadioStateMap[] = {
+ OT_RADIO_STATE_DISABLED, OT_RADIO_STATE_SLEEP, OT_RADIO_STATE_RECEIVE,
+ OT_RADIO_STATE_TRANSMIT, OT_RADIO_STATE_TRANSMIT,
+ };
+
+ return sOtRadioStateMap[mState];
+}
+
} // namespace PosixApp
} // namespace ot
@@ -1963,3 +1973,9 @@
OT_UNUSED_VARIABLE(aInstance);
return sRadioSpinel.GetRadioChannelMask(true);
}
+
+otRadioState otPlatRadioGetState(otInstance *aInstance)
+{
+ OT_UNUSED_VARIABLE(aInstance);
+ return sRadioSpinel.GetState();
+}
diff --git a/src/posix/platform/radio_spinel.hpp b/src/posix/platform/radio_spinel.hpp
index 05d0b66..76761ae 100644
--- a/src/posix/platform/radio_spinel.hpp
+++ b/src/posix/platform/radio_spinel.hpp
@@ -227,6 +227,14 @@
*/
int8_t GetReceiveSensitivity(void) const { return mRxSensitivity; }
+ /**
+ * This method gets current state of the radio.
+ *
+ * @return Current state of the radio.
+ *
+ */
+ otRadioState GetState(void) const;
+
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
/**
* Enable the radio coex.