SITL: add simulator for Rotoye battery monitor

Also correct temperature from generic battery simulator
This commit is contained in:
Peter Barker 2020-11-11 15:03:49 +11:00 committed by Peter Barker
parent 4be9b4171b
commit d436e5b5d1
6 changed files with 63 additions and 2 deletions

View File

@ -16,7 +16,7 @@ SITL::SIM_BattMonitor_SMBus::SIM_BattMonitor_SMBus() :
add_register("Manufacture Name", SMBusBattDevReg::MANUFACTURE_NAME, O_RDONLY);
add_register("Manufacture Data", SMBusBattDevReg::MANUFACTURE_DATA, O_RDONLY);
set_register(SMBusBattDevReg::TEMP, (int16_t)(15 + 273.15));
set_register(SMBusBattDevReg::TEMP, (int16_t)((15 + 273.15)*10));
// see update for voltage
// see update for current
// TODO: remaining capacity

View File

@ -1,5 +1,7 @@
#include "SIM_I2CDevice.h"
#pragma once
namespace SITL {
class SMBusBattDevReg : public I2CRegEnum {

View File

@ -1,5 +1,7 @@
#include "SIM_BattMonitor_SMBus.h"
#pragma once
namespace SITL {
class SMBusBattGenericDevReg : public SMBusBattDevReg {

View File

@ -0,0 +1,20 @@
#include "SIM_BattMonitor_SMBus_Rotoye.h"
SITL::Rotoye::Rotoye() :
SIM_BattMonitor_SMBus_Generic()
{
add_register("External Temperature", SMBusBattRotoyeDevReg::TEMP_EXT, O_RDONLY);
set_register(SMBusBattRotoyeDevReg::SERIAL, (uint16_t)39);
}
void SITL::Rotoye::update(const class Aircraft &aircraft)
{
SIM_BattMonitor_SMBus_Generic::update(aircraft);
const uint32_t now = AP_HAL::millis();
if (now - last_temperature_update_ms > 1000) {
last_temperature_update_ms = now;
set_register(SMBusBattRotoyeDevReg::TEMP_EXT, int16_t(be16toh(word[SMBusBattRotoyeDevReg::TEMP]) + 100)); // it's a little warmer inside.... (10 degrees here)
}
}

View File

@ -0,0 +1,35 @@
#include "SIM_BattMonitor_SMBus_Generic.h"
#include <AP_Common/Bitmask.h>
/*
Testing:
param set BATT_MONITOR 19
reboot
*/
namespace SITL {
class SMBusBattRotoyeDevReg : public SMBusBattGenericDevReg {
public:
static const uint8_t TEMP_EXT = 0x07;
};
class Rotoye : public SIM_BattMonitor_SMBus_Generic
{
public:
Rotoye();
uint8_t cellcount() const override { return 3; }
void update(const class Aircraft &aircraft) override;
private:
uint32_t last_temperature_update_ms;
};
} // namespace SITL

View File

@ -24,6 +24,7 @@
#include "SIM_ToshibaLED.h"
#include "SIM_MaxSonarI2CXL.h"
#include "SIM_BattMonitor_SMBus_Maxell.h"
#include "SIM_BattMonitor_SMBus_Rotoye.h"
#include <signal.h>
@ -45,6 +46,7 @@ static IgnoredI2CDevice ignored;
static ToshibaLED toshibaled;
static MaxSonarI2CXL maxsonari2cxl;
static Maxell maxell;
static Rotoye rotoye;
struct i2c_device_at_address {
uint8_t bus;
@ -57,7 +59,7 @@ struct i2c_device_at_address {
{ 1, 0x40, ignored }, // KellerLD
{ 1, 0x70, maxsonari2cxl },
{ 1, 0x76, ignored }, // MS56XX
{ 2, 0x0B, maxell },
{ 2, 0x0B, rotoye },
};
void I2C::init()