LCOV - code coverage report
Current view: top level - SITL - SIM_Temperature_TSYS01.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 6 6 100.0 %
Date: 2026-09-09 11:02:08 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "SIM_config.h"
       2             : 
       3             : #if AP_SIM_TEMPERATURE_TSYS01_ENABLED
       4             : 
       5             : #include "SIM_I2CDevice.h"
       6             : 
       7             : /*
       8             :   Simulator for the TSYS01 temperature sensor
       9             : 
      10             : ./Tools/autotest/sim_vehicle.py --gdb --debug -v ArduSub -A --speedup=1
      11             : 
      12             : */
      13             : 
      14             : namespace SITL {
      15             : 
      16             : class TSYS01 : public I2CDevice
      17             : {
      18             : public:
      19             : 
      20             :     void update(const class Aircraft &aircraft) override;
      21             : 
      22             :     int rdwr(I2C::i2c_rdwr_ioctl_data *&data) override;
      23             : 
      24             : private:
      25             : 
      26             :     // should be a call on aircraft:
      27             :     float last_temperature = -1000.0f;
      28             : 
      29             :     enum class State {
      30             :         UNKNOWN = 22,
      31             :         RESET = 23,
      32             :         READ_PROM = 24,
      33             :         IDLE = 25,
      34             :         CONVERTING = 26,
      35             :         CONVERTED = 27,
      36             :     } state = State::RESET;
      37             : 
      38             :     uint32_t state_start_time_ms;
      39             : 
      40      328870 :     void set_state(State new_state) {
      41      328870 :         state = new_state;
      42      328870 :         state_start_time_ms = AP_HAL::millis();
      43      328870 :     }
      44      921334 :     uint32_t time_in_state_ms() const {
      45      921334 :         return AP_HAL::millis() - state_start_time_ms;
      46             :     }
      47             : 
      48             :     float get_sim_temperature() const;
      49             : 
      50             :     float temperature_for_adc(uint32_t adc) const;
      51             :     uint32_t calculate_adc(float temperature) const;
      52             :     uint32_t adc;
      53             : 
      54             :     enum class Command {
      55             :         RESET       = 0x1E,
      56             :         READ_PROM0  = 0xA0,
      57             :         READ_PROM1  = 0xA2,
      58             :         READ_PROM2  = 0xA4,
      59             :         READ_PROM3  = 0xA6,
      60             :         READ_PROM4  = 0xA8,
      61             :         READ_PROM5  = 0xAA,
      62             :         CONVERT     = 0x40,
      63             :         READ_ADC    = 0x00,
      64             :     };
      65             : 
      66             :     // _k[0] is unused
      67             :     static constexpr int32_t _k[] { 0, 40781, 32791, 36016, 24926, 28446 };
      68             : };
      69             : 
      70             : } // namespace SITL
      71             : 
      72             : #endif  // AP_SIM_TEMPERATURE_TSYS01_ENABLED

Generated by: LCOV version 1.14