|
foxBMS-UnitTests
1.0.0
The foxBMS Unit Tests API Documentation
|
Go to the documentation of this file.
71 #define MXM_VOLTAGE_READ_ARRAY_LENGTH (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE + 3u)
173 #define MXM_DELAY_BALANCING 10000u
208 uint8_t *volt_rx_buffer,
209 uint16_t volt_rx_buffer_len,
212 uint16_t *voltages_target,
214 uint32_t full_scale_reference_mV);
237 uint8_t *volt_rx_buffer,
238 uint16_t volt_rx_buffer_len,
454 for (uint8_t i_po = 2u; i_po < (msg_len - 2u); i_po = i_po + 2u) {
456 uint8_t calculatedModuleNumberInDaisyChain = numberOfSatellites - ((uint16_t)(i_po / 2u) - 1u) - 1u;
457 uint8_t stringNumber = 0u;
458 uint16_t moduleNumber = 0u;
466 uint8_t mask = 1u << c;
467 if ((uint8_t)(mask & pInstance->
rxBuffer[i_po]) > 0u) {
468 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 1;
470 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 0;
474 uint8_t mask = 1u << (c - 8u);
475 if ((uint8_t)(mask & pInstance->
rxBuffer[i_po + 1u]) > 0u) {
476 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 1;
478 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 0;
506 uint8_t stringNumber = 0u;
507 uint16_t moduleNumber = 0u;
544 uint8_t *volt_rx_buffer,
545 uint16_t volt_rx_buffer_len,
548 uint16_t *voltages_target,
550 uint32_t full_scale_reference_mV) {
551 uint8_t number_of_connected_devices =
552 (volt_rx_buffer_len - 2u - 2u) /
556 for (uint8_t i = 2u; i < (volt_rx_buffer_len - 2u); i = i + 2u) {
557 uint8_t calculated_module_number = number_of_connected_devices - ((uint16_t)(i / 2u) - 1u) - 1u;
558 uint16_t calculated_module_position = 0u;
567 calculated_module_position = calculated_module_number;
573 uint16_t calculated_array_position = calculated_module_position + meas_offset;
576 volt_rx_buffer[i + 1u],
577 &voltages_target[calculated_array_position],
579 full_scale_reference_mV);
585 uint8_t *volt_rx_buffer,
586 uint16_t volt_rx_buffer_len,
593 uint8_t cell_offset = 0;
597 }
else if ((volt_rx_buffer_len % 2u) != 0u) {
607 switch (volt_rx_buffer[1]) {
809 uint8_t test_buffer[100];
810 uint16_t test_buffer_len = 100;
847 test_buffer[2] = 0xFCu;
848 test_buffer[3] = 0xFFu;
849 test_buffer[4] = 0x00u;
850 test_buffer[5] = 0x00u;
851 test_buffer[6] = 0xFCu;
852 test_buffer[7] = 0xFFu;
853 test_buffer[8] = 0x42u;
854 test_buffer[9] = 0x44u;
855 test_buffer_len = 10u;
874 test_buffer[2] = 0xFCu;
875 test_buffer[3] = 0xFFu;
876 test_buffer[4] = 0x00u;
877 test_buffer[5] = 0x00u;
878 test_buffer[6] = 0xFCu;
879 test_buffer[7] = 0xFFu;
880 test_buffer[8] = 0x42u;
881 test_buffer[9] = 0x44u;
882 test_buffer_len = 10;
901 test_buffer[2] = 0xFCu;
902 test_buffer[3] = 0xFFu;
903 test_buffer[4] = 0x42u;
904 test_buffer[5] = 0x44u;
923 test_buffer[2] = 0xFCu;
924 test_buffer[3] = 0xFFu;
925 test_buffer[4] = 0x42u;
926 test_buffer[5] = 0x44u;
945 test_buffer[2] = 0xFCu;
946 test_buffer[3] = 0xFFu;
947 test_buffer[4] = 0x42u;
948 test_buffer[5] = 0x44u;
967 test_buffer[2] = 0xFCu;
968 test_buffer[3] = 0xFFu;
969 test_buffer[4] = 0x42u;
970 test_buffer[5] = 0x44u;
989 test_buffer[2] = 0xFCu;
990 test_buffer[3] = 0xFFu;
991 test_buffer[4] = 0x42u;
992 test_buffer[5] = 0x44u;
1011 test_buffer[2] = 0xFCu;
1012 test_buffer[3] = 0xFFu;
1013 test_buffer[4] = 0x42u;
1014 test_buffer[5] = 0x44u;
1015 test_buffer_len = 6;
1033 test_buffer[2] = 0xFCu;
1034 test_buffer[3] = 0xFFu;
1035 test_buffer[4] = 0x42u;
1036 test_buffer[5] = 0x44u;
1037 test_buffer_len = 6;
1055 test_buffer[2] = 0xFCu;
1056 test_buffer[3] = 0xFFu;
1057 test_buffer[4] = 0x42u;
1058 test_buffer[5] = 0x44u;
1059 test_buffer_len = 6;
1077 test_buffer[2] = 0xFCu;
1078 test_buffer[3] = 0xFFu;
1079 test_buffer[4] = 0x42u;
1080 test_buffer[5] = 0x44u;
1081 test_buffer_len = 6;
1099 test_buffer[2] = 0xFCu;
1100 test_buffer[3] = 0xFFu;
1101 test_buffer[4] = 0x42u;
1102 test_buffer[5] = 0x44u;
1103 test_buffer_len = 6;
1121 test_buffer[2] = 0xFCu;
1122 test_buffer[3] = 0xFFu;
1123 test_buffer[4] = 0x42u;
1124 test_buffer[5] = 0x44u;
1125 test_buffer_len = 6;
1143 test_buffer[2] = 0xFCu;
1144 test_buffer[3] = 0xFFu;
1145 test_buffer[4] = 0x42u;
1146 test_buffer[5] = 0x44u;
1147 test_buffer_len = 6;
1203 uint8_t stringNumber = 0u;
1204 uint16_t moduleNumber = 0u;
1209 if (moduleNumber == 0u) {
1229 uint8_t stringNumber = 0u;
1230 uint16_t moduleNumber = 0u;
1425 if (
STD_OK == database_retval) {
1460 if (mxm_moduleBalancingIndex < pState->highest5xDevice) {
1833 switch (pInstance->
state) {
1919 #ifdef UNITY_UNIT_TEST
1943 uint8_t *volt_rx_buffer,
1944 uint16_t volt_rx_buffer_len,
@ MXM_CONVERSION_BLOCK_VOLTAGE
Implementation of the tasks used by the system, headers.
#define MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE
Maximum number of cells per module.
void MXM_MonRegistryParseVersionIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength)
Parse Version into the registry.
static uint8_t mxm_moduleBalancingIndex
Module index in the daisy chain.
uint8_t mxmVoltageCellCounter
MXM_5X_INSTANCE_s * pInstance5X
static STD_RETURN_TYPE_e must_check_return MXM_PreInitSelfCheck(MXM_MONITORING_INSTANCE_s *pState)
Execute all preinit selfchecks.
bool TEST_MXM_HandleStateReadall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_REG_NAME_e registerName, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
enum MXM_CONVERSION_TYPE MXM_CONVERSION_TYPE_e
STD_RETURN_TYPE_e addressSpaceChecker
STD_RETURN_TYPE_e must_check_return MXM_CRC8SelfTest()
Test the CRC8-algorithm with a known pattern.
static bool must_check_return MXM_HandleStateReadall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_REG_NAME_e registerName, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a READALL.
#define BS_NR_OF_MODULES
number of modules in battery pack
STD_RETURN_TYPE_e parseVoltageReadall
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
uint32_t moduleVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
@ MXM_STATEMACH_5X_41B_FMEA_CHECK
#define BATTERY_MANAGEMENT_READALL
READALL message (read single register of all daisy-chain devices)
STD_RETURN_TYPE_e fmeaStatusASCI
STD_RETURN_TYPE_e must_check_return MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck(void)
runs a selfcheck for the address space check
static STD_RETURN_TYPE_e must_check_return MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
Test the MXM_ParseVoltageReadall()-function.
static uint32_t mxm_previousTime
Timers used to guarantee that balancing is performed periodically.
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
#define DATA_WRITE_DATA(...)
MXM_5X_COMMAND_PAYLOAD_s batteryCmdBuffer
STD_RETURN_TYPE_e TEST_MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
static void MXM_GetDataFrom5XStateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Retrieves data from lower statemachine and writes it to the rx buffer.
uint8_t rxBuffer[MXM_RX_BUFFER_LENGTH]
#define BS_NR_OF_CELLS_PER_MODULE
number of battery cells per battery module (parallel cells are counted as one)
static void MXM_StateMachineOperation(MXM_MONITORING_INSTANCE_s *pState)
State-Machine implementation for operation state.
#define BATTERY_MANAGEMENT_HELLOALL
HELLOALL message.
#define MXM_MAXIMUM_NR_OF_AUX_PER_MODULE
Maximum number of AUX ports per module.
static MXM_MONINTORING_STATE_e must_check_return MXM_MonGetVoltages(MXM_MONITORING_INSTANCE_s *pState, MXM_REG_NAME_e regAddress)
Encapsulation for reading voltages from a register.
static uint8_t mxm_oddCellsNeedBalancing
Odd cells group needs to be balanced.
#define MXM_MAXIMUM_NR_OF_MODULES
Maximum number of modules.
@ MXM_5X_STATE_UNPROCESSED
@ MXM_STATEMACH_5X_WRITEALL
static void MXM_HandleStateWriteall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a WRITEALL.
static uint8_t mxm_oddCellsBalancingProcessed
Odd cells group balancing done.
@ MXM_MEASURE_CELL_VOLTAGE
@ MXM_CONVERSION_UNIPOLAR
@ MXM_MEASURE_BLOCK_VOLTAGE
DATA_BLOCK_HEADER_s header
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
void MXM_MonRegistryParseIdIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength, MXM_REG_NAME_e type)
Parse ID (1 or 2) into the registry.
Temperature Sensor Interface on Slave Unit driver header.
@ MXM_STATEMACH_5X_WRITE_DEVICE
#define MXM_VOLTAGE_READ_ARRAY_LENGTH
DATA_BLOCK_HEADER_s header
MXM_REG_NAME_e regAddress
int16_t TSI_GetTemperature(uint16_t adcVoltage_mV)
translate a voltage to a temperature
static void MXM_ParseVoltageLineReadall(uint8_t *volt_rx_buffer, uint16_t volt_rx_buffer_len, uint8_t meas_offset, MXM_CONVERSION_TYPE_e conversionType, uint16_t *voltages_target, MXM_MEASURE_TYPE_e meas_type, uint32_t full_scale_reference_mV)
Parse voltage values from a READALL receive buffer into an array.
MXM_STATEMACHINE_STATES_e state
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
#define must_check_return
Allows functions to generate warnings in GCC for unused returns.
static STD_RETURN_TYPE_e MXM_ConstructBalancingBuffer(void)
Fill the balancing datastructure.
static DATA_BLOCK_BALANCING_CONTROL_s mxm_balancingControl
Balancing control.
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
static STD_RETURN_TYPE_e MXM_ParseVoltageReadall(uint8_t *volt_rx_buffer, uint16_t volt_rx_buffer_len, MXM_DATA_STORAGE_s *datastorage, MXM_CONVERSION_TYPE_e conversionType)
Parse a RX buffer containing voltage values.
STD_RETURN_TYPE_e MXM_5XSetStateRequest(MXM_5X_INSTANCE_s *pInstance5x, MXM_STATEMACHINE_5X_e state, MXM_5X_COMMAND_PAYLOAD_s commandPayload, MXM_5X_STATE_REQUEST_STATUS_e *processed)
Set state request for the Battery Management Statemachine.
STD_RETURN_TYPE_e MXM_5XGetNumberOfSatellitesGood(MXM_5X_INSTANCE_s *pInstance)
Get the value of MXM_5X_INSTANCE::numberOfSatellitesIsGood.
STD_RETURN_TYPE_e TEST_MXM_ParseVoltagesIntoDB(MXM_MONITORING_INSTANCE_s *pInstance)
static const MXM_REG_NAME_e mxm_voltageCellAddresses[MXM_VOLTAGE_READ_ARRAY_LENGTH]
Mapping of voltage registers.
STD_RETURN_TYPE_e firstSetBit
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
#define BATTERY_MANAGEMENT_TX_LENGTH_READALL
Battery Management Protocol lengths of TX buffer.
static DATA_BLOCK_OPEN_WIRE_s mxm_openwire
Local data structure for openwire results.
void MXM_StateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Battery monitoring driver for MAX1785x battery monitoring ICs.
void TEST_MXM_ProcessOpenWire(MXM_MONITORING_INSTANCE_s *pInstance, DATA_BLOCK_OPEN_WIRE_s *pDataOpenWire)
STD_RETURN_TYPE_e MXM_MonRegistryConnectDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t numberOfDevices)
Mark devices as connected in the registry and set the address.
void TEST_MXM_HandleStateWriteall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
enum MXM_REG_NAME MXM_REG_NAME_e
MAX1785x register names.
@ DATA_BLOCK_ID_BALANCING_CONTROL
uint8_t balancingState[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
MXM_STATEMACHINE_OPERATION_STATES_e operationSubstate
uint8_t MXM_5XGetNumberOfSatellites(MXM_5X_INSTANCE_s *pInstance)
Get number of satellites.
#define DATA_READ_DATA(...)
void MXM_MonRegistryInit(MXM_MONITORING_INSTANCE_s *pState)
Initialize monitoring registry.
uint8_t openwire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES *(BS_NR_OF_CELLS_PER_MODULE+1)]
MXM_DATA_STORAGE_s localVoltages
Local storage for cell-voltages.
bool firstMeasurementDone
@ MXM_STATEMACH_5X_READALL
static uint8_t mxm_evenCellsNeedBalancing
Even cells group needs to be balanced.
STD_RETURN_TYPE_e MXM_5XGetRXBuffer(MXM_5X_INSTANCE_s *pInstance, uint8_t *rxBuffer, uint16_t rxBufferLength)
Copy RX buffer into variable.
#define NULL_PTR
Null pointer.
STD_RETURN_TYPE_e TEST_MXM_ParseVoltageReadall(uint8_t *volt_rx_buffer, uint16_t volt_rx_buffer_len, MXM_DATA_STORAGE_s *datastorage, MXM_CONVERSION_TYPE_e conversionType)
MXM_DC_BYTE_e MXM_5XGetLastDCByte(MXM_5X_INSTANCE_s *pInstance)
Returns the last received DC byte.
static uint32_t mxm_currentTime
Timers used to guarantee that balancing is performed periodically.
uint16_t cellVoltages[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE]
static uint8_t mxm_evenCellsBalancingProcessed
Even cells group balancing done.
uint16_t auxVoltages[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_AUX_PER_MODULE]
static void MXM_ProcessOpenWire(MXM_MONITORING_INSTANCE_s *pInstance, DATA_BLOCK_OPEN_WIRE_s *pDataOpenWire)
Processes the retrieved information on openwire.
Functions in order to have a registry of monitoring ICs.
MXM_5X_STATE_REQUEST_STATUS_e requestStatus5x
MXM_MONINTORING_STATE_e TEST_MXM_MonGetVoltages(MXM_MONITORING_INSTANCE_s *pInstance, MXM_REG_NAME_e regAddress)
enum MXM_MEASURE_TYPE MXM_MEASURE_TYPE_e
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
uint16_t blockVoltages[MXM_MAXIMUM_NR_OF_MODULES]
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
static STD_RETURN_TYPE_e MXM_ParseVoltagesIntoDB(MXM_MONITORING_INSTANCE_s *pInstance)
Copies measured voltage data into the database.
uint16_t mxm_cellsToBalance
Mask to control balacing.
DATA_BLOCK_HEADER_s header
static DATA_BLOCK_CELL_VOLTAGE_s mxm_cellVoltages
Local cell voltage data block.
MXM_SELFCHECK_s selfCheck
DATA_BLOCK_HEADER_s header
static DATA_BLOCK_CELL_TEMPERATURE_s mxm_cellTemperatures
Local cell temperature data block.
STD_RETURN_TYPE_e resultSelfCheck
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS]
#define MXM_DELAY_BALANCING
Delay in milliseconds before the balancing status is updated.
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
STD_RETURN_TYPE_e extractValueFromRegister