Print state as number instead of ??? when debug option is off
Bug: 28632530
Change-Id: I8867d58aa887d912b16a43e01f559f4b2f18f239
diff --git a/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c b/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c
index 981de11..71687e9 100644
--- a/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c
+++ b/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c
@@ -272,6 +272,7 @@
};
enum SensorState {
+ // keep this in sync with getStateName
SENSOR_BOOT,
SENSOR_VERIFY_ID,
SENSOR_INITIALIZING,
@@ -287,15 +288,21 @@
SENSOR_SAVE_CALIBRATION,
SENSOR_NUM_OF_STATE
};
-static const char * getStateName(int32_t s) {
#if DBG_STATE
+#define PRI_STATE "s"
+static const char * getStateName(int32_t s) {
+ // keep this in sync with SensorState
static const char* const l[] = {"BOOT", "VERIFY_ID", "INIT", "IDLE", "PWR_UP",
"PWR-DN", "CFG_CHANGE", "INT1", "INT2", "CALIB", "STEP_CNT", "SYNC", "SAVE_CALIB"};
if (s >= 0 && s < SENSOR_NUM_OF_STATE) {
return l[s];
}
-#endif
return "???";
+#else
+#define PRI_STATE PRIi32
+static int32_t getStateName(int32_t s) {
+ return s;
+#endif
}
enum MagConfigState {
@@ -522,7 +529,7 @@
// Atomic set state, this set the state to arbitrary value, use with caution
#define SET_STATE(s) do{\
- DEBUG_PRINT_IF(DBG_STATE, "set state %s\n", getStateName(s));\
+ DEBUG_PRINT_IF(DBG_STATE, "set state %" PRI_STATE "\n", getStateName(s));\
atomicWriteByte(&(_task->state), (s));\
}while(0)
@@ -531,7 +538,7 @@
#if DBG_STATE
bool ret = atomicCmpXchgByte(&T(state), SENSOR_IDLE, newState);
uint8_t prevState = ret ? SENSOR_IDLE : GET_STATE();
- DEBUG_PRINT("switch state %s->%s, %s\n",
+ DEBUG_PRINT("switch state %" PRI_STATE "->%" PRI_STATE ", %s\n",
getStateName(prevState), getStateName(newState), ret ? "ok" : "failed");
return ret;
#else
@@ -996,7 +1003,7 @@
{
TDECL();
- INFO_PRINT("accPower: on=%d, state=%s\n", on, getStateName(GET_STATE()));
+ INFO_PRINT("accPower: on=%d, state=%" PRI_STATE "\n", on, getStateName(GET_STATE()));
if (trySwitchState(on ? SENSOR_POWERING_UP : SENSOR_POWERING_DOWN)) {
if (on) {
// set ACC power mode to NORMAL
@@ -1019,7 +1026,7 @@
static bool gyrPower(bool on, void *cookie)
{
TDECL();
- INFO_PRINT("gyrPower: on=%d, state=%s\n", on, getStateName(GET_STATE()));
+ INFO_PRINT("gyrPower: on=%d, state=%" PRI_STATE "\n", on, getStateName(GET_STATE()));
if (trySwitchState(on ? SENSOR_POWERING_UP : SENSOR_POWERING_DOWN)) {
if (on) {
@@ -1052,7 +1059,7 @@
static bool magPower(bool on, void *cookie)
{
TDECL();
- INFO_PRINT("magPower: on=%d, state=%s\n", on, getStateName(GET_STATE()));
+ INFO_PRINT("magPower: on=%d, state=%" PRI_STATE "\n", on, getStateName(GET_STATE()));
if (trySwitchState(on ? SENSOR_POWERING_UP : SENSOR_POWERING_DOWN)) {
if (on) {
// set MAG power mode to NORMAL
@@ -1140,7 +1147,7 @@
static bool anyMotionPower(bool on, void *cookie)
{
TDECL();
- DEBUG_PRINT("anyMotionPower: on=%d, oneshot_cnt %d, state=%s\n",
+ DEBUG_PRINT("anyMotionPower: on=%d, oneshot_cnt %d, state=%" PRI_STATE "\n",
on, mTask.active_oneshot_sensor_cnt, getStateName(GET_STATE()));
if (trySwitchState(on ? SENSOR_POWERING_UP : SENSOR_POWERING_DOWN)) {
@@ -1163,7 +1170,7 @@
static bool noMotionPower(bool on, void *cookie)
{
TDECL();
- DEBUG_PRINT("noMotionPower: on=%d, oneshot_cnt %d, state=%s\n",
+ DEBUG_PRINT("noMotionPower: on=%d, oneshot_cnt %d, state=%" PRI_STATE "\n",
on, mTask.active_oneshot_sensor_cnt, getStateName(GET_STATE()));
if (trySwitchState(on ? SENSOR_POWERING_UP : SENSOR_POWERING_DOWN)) {
if (on) {
@@ -1268,7 +1275,7 @@
TDECL();
int odr, osr = 0;
- INFO_PRINT("accSetRate: rate=%ld, latency=%lld, state=%s\n", rate, latency,
+ INFO_PRINT("accSetRate: rate=%ld, latency=%lld, state=%" PRI_STATE "\n", rate, latency,
getStateName(GET_STATE()));
if (trySwitchState(SENSOR_CONFIG_CHANGING)) {
@@ -1327,7 +1334,7 @@
{
TDECL();
int odr, osr = 0;
- INFO_PRINT("gyrSetRate: rate=%ld, latency=%lld, state=%s\n", rate, latency,
+ INFO_PRINT("gyrSetRate: rate=%ld, latency=%lld, state=%" PRI_STATE "\n", rate, latency,
getStateName(GET_STATE()));
if (trySwitchState(SENSOR_CONFIG_CHANGING)) {
@@ -1388,7 +1395,7 @@
if (rate == SENSOR_RATE_ONCHANGE)
rate = SENSOR_HZ(100);
- INFO_PRINT("magSetRate: rate=%ld, latency=%lld, state=%s\n", rate, latency,
+ INFO_PRINT("magSetRate: rate=%ld, latency=%lld, state=%" PRI_STATE "\n", rate, latency,
getStateName(GET_STATE()));
if (trySwitchState(SENSOR_CONFIG_CHANGING)) {