Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Macros | Functions
BMSTest.c File Reference
#include "../../../Inc/Systems/External/BMS.h"
#include "test.h"
#include <assert.h>
#include <math.h>
#include <stdbool.h>
Include dependency graph for BMSTest.c:

Go to the source code of this file.

Macros

#define FLOAT_ERROR   1e-5
 
#define BmsHz   500
 

Functions

bool floatEqual (float a, float b)
 
bool equal (Bms *bms1, Bms *bms2)
 
void bms_main ()
 

Macro Definition Documentation

◆ BmsHz

#define BmsHz   500

Definition at line 30 of file BMSTest.c.

◆ FLOAT_ERROR

#define FLOAT_ERROR   1e-5

Definition at line 9 of file BMSTest.c.

Function Documentation

◆ bms_main()

void bms_main ( )

Definition at line 32 of file BMSTest.c.

32 {
33 TEST(bms_init, {
34 Bms bms;
35 initBms(&bms, BmsHz, "Tests/Systems/External/Orion_CANBUS.dbc");
36 ASSERT(bms.chargeStatus == IDLE, "bms is idle", "bms is not idle");
37 ASSERT_EQ(bms.packVoltage, 0, "pack voltage", "expected pack voltage");
38 ASSERT_EQ(bms.packCurrent, 0, "pack current", "expected pack current");
39 })
40
41 Bms expectedBms;
42 initBms(&expectedBms, BmsHz, "Tests/Systems/External/Orion_CANBUS.dbc");
43 expectedBms.packVoltage = 600.0f;
44 expectedBms.packVoltage = 400.0f;
45 expectedBms.stateOfCharge = 80.0f;
46
47 TEST(bms_update, {
48 Bms bms;
49 initBms(&bms, BmsHz, "Tests/Systems/External/Orion_CANBUS.dbc");
50 updateBmsTest(&bms, "Tests/Systems/External/BmsFakeCanData.txt");
51 // FIXME Should this be equal or !equal? Original had it as equal is a failure
52 ASSERT(!equal(&bms, &expectedBms), "bms doesn't equal expected bms", "bms equals expected bms");
53 })
54}
#define BmsHz
Definition: BMSTest.c:30
bool equal(Bms *bms1, Bms *bms2)
Definition: BMSTest.c:14
void updateBmsTest(void *bms, const char *canDataFn)
Updates the BMS data.
Definition: BMS.c:96
@ IDLE
Definition: BMS.h:12
void initBms(Bms *bms, int hz, const char *dbcFn)
Initializes the BMS with the given frequency.
Definition: BMS.c:7
Definition: BMS.h:15
float packVoltage
Definition: BMS.h:19
BmsChargeStatus chargeStatus
Definition: BMS.h:29
float packCurrent
Definition: BMS.h:20
#define TEST(NAME, BODY)
Definition: test.h:19
#define ASSERT_EQ(GOT, WANT, GOT_LABEL, WANT_LABEL)
Definition: test.h:32
#define ASSERT(BOOL, OK, ERR)
Definition: test.h:27
Here is the call graph for this function:

◆ equal()

bool equal ( Bms bms1,
Bms bms2 
)

Definition at line 14 of file BMSTest.c.

14 {
15 if (!floatEqual(bms1->packVoltage, bms2->packVoltage)) return false;
16 if (!floatEqual(bms1->packCurrent, bms2->packCurrent)) return false;
17 if (!floatEqual(bms1->stateOfCharge, bms2->stateOfCharge)) return false;
18 if (!floatEqual(bms1->cellVoltageMin, bms2->cellVoltageMin)) return false;
19 if (!floatEqual(bms1->cellVoltageMax, bms2->cellVoltageMax)) return false;
20 if (!floatEqual(bms1->cellTemperatureMin, bms2->cellTemperatureMin)) return false;
21 if (!floatEqual(bms1->cellTemperatureMax, bms2->cellTemperatureMax)) return false;
22 if (!floatEqual(bms1->totalPackCapacity, bms2->totalPackCapacity)) return false;
23 if (!floatEqual(bms1->remainingPackCapacity, bms2->remainingPackCapacity)) return false;
24 if (!floatEqual(bms1->packHealth, bms2->packHealth)) return false;
25 // TODO: Add charge status
26
27 return true;
28}
bool floatEqual(float a, float b)
Definition: BMSTest.c:10
float cellVoltageMin
Definition: BMS.h:22
float stateOfCharge
Definition: BMS.h:21
float cellVoltageMax
Definition: BMS.h:23
float cellTemperatureMax
Definition: BMS.h:25
float totalPackCapacity
Definition: BMS.h:26
float cellTemperatureMin
Definition: BMS.h:24
float remainingPackCapacity
Definition: BMS.h:27
float packHealth
Definition: BMS.h:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ floatEqual()

bool floatEqual ( float  a,
float  b 
)

Definition at line 10 of file BMSTest.c.

10 {
11 return fabs(a - b) < FLOAT_ERROR;
12}
#define FLOAT_ERROR
Definition: BMSTest.c:9
Here is the caller graph for this function: