LCOV - code coverage report
Current view: top level - SITL - SIM_Temperature_TSYS03.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_TSYS03_ENABLED
       4             : 
       5             : #include "SIM_I2CDevice.h"
       6             : 
       7             : /*
       8             :   Simulator for the TSYS03 temperature sensor
       9             : 
      10             : ./Tools/autotest/sim_vehicle.py --gdb --debug -v ArduCopter -f Callisto -A --speedup=1
      11             : param set TEMP1_TYPE 4
      12             : param fetch
      13             : param set TEMP1_BUS 2
      14             : param set TEMP1_SRC 3
      15             : param set TEMP1_SRC_ID 1
      16             : graph BATTERY_STATUS.temperature*0.01
      17             : reboot
      18             : 
      19             : arm throttle
      20             : rc 3 2000
      21             : 
      22             : fly around, check BAT[0].temperature
      23             : 
      24             : */
      25             : 
      26             : namespace SITL {
      27             : 
      28             : class TSYS03 : public I2CDevice
      29             : {
      30             : public:
      31             : 
      32             :     void update(const class Aircraft &aircraft) override;
      33             : 
      34             :     int rdwr(I2C::i2c_rdwr_ioctl_data *&data) override;
      35             : 
      36             : private:
      37             : 
      38             :     int rdwr_handle_read(I2C::i2c_rdwr_ioctl_data *&data);
      39             :     int rdwr_handle_write(I2C::i2c_rdwr_ioctl_data *&data);
      40             : 
      41             :     // should be a call on aircraft:
      42             :     float last_temperature_degC = -1000.0f;
      43             : 
      44             :     enum class State {
      45             :         UNKNOWN = 22,
      46             :         RESET = 23,
      47             :         READ_SERIAL = 24,
      48             :         IDLE = 25,
      49             :         CONVERTING = 26,
      50             :         CONVERTED = 27,
      51             :     } state = State::RESET;
      52             : 
      53             :     uint32_t state_start_time_ms;
      54             : 
      55        2009 :     void set_state(State new_state) {
      56        2009 :         state = new_state;
      57        2009 :         state_start_time_ms = AP_HAL::millis();
      58        2009 :     }
      59       10045 :     uint32_t time_in_state_ms() const {
      60       10045 :         return AP_HAL::millis() - state_start_time_ms;
      61             :     }
      62             : 
      63             :     float get_sim_temperature_degC(const class Aircraft &aircraft) const;
      64             : 
      65             :     float temperature_for_adc(uint16_t adc) const;
      66             :     uint16_t calculate_adc(float temperature) const;
      67             :     uint32_t adc;
      68             : 
      69             :     enum class Command {
      70             :         RESET       = 0x1E,
      71             :         READ_SERIAL = 0x0A,
      72             :         CONVERT     = 0x46,
      73             :         READ_ADC    = 0x00,
      74             :     };
      75             : 
      76             :     static constexpr uint8_t serial[] { 0xAB, 0xCD, 0xEF };
      77             : };
      78             : 
      79             : } // namespace SITL
      80             : 
      81             : #endif  // AP_SIM_TSYS03_ENABLED

Generated by: LCOV version 1.14