hitl_tester.test_cases.bms.test_smbus
| Test | Read all SMBus registers |
|---|---|
| GitHub Issue(s) | turnaroundfactor/HITL#307 |
| Description | A quick test to make sure the smbus is working. |
Used in these test plans:
- smbus_test ⠀⠀⠀(bms/smbus_test.plan)
Example Command (warning: test plan may run other test cases):
./hitl_tester.py smbus_test -DDEFAULT_SOC_PERCENT=0.8 -DDEFAULT_TEMPERATURE_C=15
1""" 2| Test | Read all SMBus registers | 3| :------------------- | :---------------------------------------------- | 4| GitHub Issue(s) | turnaroundfactor/HITL#307 | 5| Description | A quick test to make sure the smbus is working. | 6""" 7 8import time 9 10import pytest 11 12from hitl_tester.modules.bms import smbus_types 13from hitl_tester.modules.bms.bms_hw import BMSHardware 14from hitl_tester.modules.bms.bms_serial import serial_monitor 15from hitl_tester.modules.bms.plateset import Plateset 16from hitl_tester.modules.bms.smbus import SMBus 17from hitl_tester.modules.bms.smbus_types import SMBusReg 18from hitl_tester.modules.bms_types import BMSFlags 19from hitl_tester.modules.logger import logger 20 21DEFAULT_SOC_PERCENT = 0.80 22DEFAULT_TEMPERATURE_C = 15 23 24_bms = BMSHardware(pytest.flags) # type: ignore[arg-type] 25_smbus = SMBus() 26 27if hasattr(pytest, "flags") and isinstance(pytest.flags, BMSFlags) and "cell_simulators" in pytest.flags.config: 28 _bms.init() 29 _plateset = Plateset() 30 31 logger.write_info_to_report("Powering down cell sims") 32 for cell in _bms.cells.values(): 33 cell.disengage_safety_protocols = True 34 cell.volts = 0.0001 35 time.sleep(5) 36 logger.write_info_to_report("Powering up cell sims") 37 for cell in _bms.cells.values(): 38 cell.state_of_charge = DEFAULT_SOC_PERCENT 39 cell.disengage_safety_protocols = False 40 logger.write_info_to_report("Setting temperature to 15°C") 41 _plateset.thermistor1 = DEFAULT_TEMPERATURE_C 42 _plateset.thermistor2 = DEFAULT_TEMPERATURE_C 43 logger.write_debug_to_report("Waiting for BMS to initialize...") 44 time.sleep(10) 45 46 47def test_smbus(): 48 """ 49 | Requirement | Read all registers | 50 | :------------------- | :----------------------------------- | 51 | GitHub Issue | turnaroundfactor/HITL#307 | 52 | Pass / Fail Criteria | No errors raised | 53 | Estimated Duration | 1 second | 54 """ 55 _smbus.write_register(SMBusReg.MANUFACTURING_ACCESS, smbus_types.BMSCommands.FAULT_ENABLE) 56 _smbus.write_register(SMBusReg.AT_RATE, smbus_types.BMSCommands.FAULT_ENABLE) 57 58 for register in SMBusReg: 59 data = _smbus.read_register(register) 60 logger.write_info_to_report(f"{register.fname}: {data}") 61 62 63def test_loop_smbus(): 64 """ 65 | Requirement | Run a full smbus test repeatedly, outputting serial | 66 | :------------------- | :-------------------------------------------------- | 67 | GitHub Issue | turnaroundfactor/battery-benchtop-rev1#274 | 68 | Instructions | Output SMBus and serial in a loop | 69 | Pass / Fail Criteria | No errors raised | 70 | Estimated Duration | 0 seconds | 71 """ 72 while True: 73 test_smbus() 74 logger.write_debug_to_report("Waiting for serial...") 75 logger.write_debug_to_report(str(serial_monitor.read())) 76 time.sleep(5)
DEFAULT_SOC_PERCENT =
0.8
DEFAULT_TEMPERATURE_C =
15
def
test_smbus():
48def test_smbus(): 49 """ 50 | Requirement | Read all registers | 51 | :------------------- | :----------------------------------- | 52 | GitHub Issue | turnaroundfactor/HITL#307 | 53 | Pass / Fail Criteria | No errors raised | 54 | Estimated Duration | 1 second | 55 """ 56 _smbus.write_register(SMBusReg.MANUFACTURING_ACCESS, smbus_types.BMSCommands.FAULT_ENABLE) 57 _smbus.write_register(SMBusReg.AT_RATE, smbus_types.BMSCommands.FAULT_ENABLE) 58 59 for register in SMBusReg: 60 data = _smbus.read_register(register) 61 logger.write_info_to_report(f"{register.fname}: {data}")
| Requirement | Read all registers |
|---|---|
| GitHub Issue | turnaroundfactor/HITL#307 |
| Pass / Fail Criteria | No errors raised |
| Estimated Duration | 1 second |
def
test_loop_smbus():
64def test_loop_smbus(): 65 """ 66 | Requirement | Run a full smbus test repeatedly, outputting serial | 67 | :------------------- | :-------------------------------------------------- | 68 | GitHub Issue | turnaroundfactor/battery-benchtop-rev1#274 | 69 | Instructions | Output SMBus and serial in a loop | 70 | Pass / Fail Criteria | No errors raised | 71 | Estimated Duration | 0 seconds | 72 """ 73 while True: 74 test_smbus() 75 logger.write_debug_to_report("Waiting for serial...") 76 logger.write_debug_to_report(str(serial_monitor.read())) 77 time.sleep(5)
| Requirement | Run a full smbus test repeatedly, outputting serial |
|---|---|
| GitHub Issue | turnaroundfactor/battery-benchtop-rev1#274 |
| Instructions | Output SMBus and serial in a loop |
| Pass / Fail Criteria | No errors raised |
| Estimated Duration | 0 seconds |