diff --git a/src/network/packets.h b/src/network/packets.h index f6c3d9b5..8bb2561d 100644 --- a/src/network/packets.h +++ b/src/network/packets.h @@ -67,4 +67,14 @@ #define PACKET_INSPECTION_DATATYPE_INT 1 #define PACKET_INSPECTION_DATATYPE_FLOAT 2 +// From the SH-2 interface that BNO08x use. +enum class PacketErrorCode : uint8_t { + NOT_APPLICABLE = 0, + POWER_ON_RESET = 1, + INTERNAL_SYSTEM_RESET = 2, + WATCHDOG_TIMEOUT = 3, + EXTERNAL_RESET = 4, + OTHER = 5, +}; + #endif // SLIMEVR_PACKETS_H_ diff --git a/src/sensors/icm20948sensor.cpp b/src/sensors/icm20948sensor.cpp index e3347683..4466b513 100644 --- a/src/sensors/icm20948sensor.cpp +++ b/src/sensors/icm20948sensor.cpp @@ -329,7 +329,10 @@ void ICM20948Sensor::checkSensorTimeout() { addr, currenttime - lastData ); - networkConnection.sendSensorError(this->sensorId, 1); + networkConnection.sendSensorError( + this->sensorId, + static_cast(PacketErrorCode::WATCHDOG_TIMEOUT) + ); lastData = currenttime; } } diff --git a/src/sensors/softfusion/softfusionsensor.h b/src/sensors/softfusion/softfusionsensor.h index 857b24fe..ca563db4 100644 --- a/src/sensors/softfusion/softfusionsensor.h +++ b/src/sensors/softfusion/softfusionsensor.h @@ -199,6 +199,26 @@ class SoftFusionSensor : public Sensor { , m_sensor(I2CImpl(i2cAddress), m_Logger) {} ~SoftFusionSensor() {} + void checkSensorTimeout() { + uint32_t now = millis(); + constexpr uint32_t sensorTimeoutMillis = 2e3; // 2 seconds + if (m_lastRotationUpdateMillis + sensorTimeoutMillis > now) { + return; + } + + working = false; + m_status = SensorStatus::SENSOR_ERROR; + m_Logger.error( + "Sensor timeout I2C Address 0x%02x delaytime: %d ms", + addr, + now - m_lastRotationUpdateMillis + ); + networkConnection.sendSensorError( + this->sensorId, + static_cast(PacketErrorCode::WATCHDOG_TIMEOUT) + ); + } + void motionLoop() override final { sendTempIfNeeded(); @@ -218,9 +238,11 @@ class SoftFusionSensor : public Sensor { ); optimistic_yield(100); if (!m_fusion.isUpdated()) { + checkSensorTimeout(); return; } hadData = true; + m_lastRotationUpdateMillis = millis(); m_fusion.clearUpdated(); } @@ -615,6 +637,7 @@ class SoftFusionSensor : public Sensor { SensorStatus m_status = SensorStatus::SENSOR_OFFLINE; uint32_t m_lastPollTime = micros(); + uint32_t m_lastRotationUpdateMillis = 0; uint32_t m_lastRotationPacketSent = 0; uint32_t m_lastTemperaturePacketSent = 0; };