Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions
BMS.c File Reference
#include "../../../Inc/Systems/External/BMS.h"
#include "../../../Inc/Systems/PrintHelpers.h"
#include <stdio.h>
#include "../../../Inc/Systems/Comms/Can/Can.h"
Include dependency graph for BMS.c:

Go to the source code of this file.

Functions

void initBms (Bms *bms, int hz, const char *dbcFn)
 Initializes the BMS with the given frequency. More...
 
void assignBmsValue (Bms *bms, int id, float value, const char *name)
 
int bmsTransferFunction (Bms *bms, CAN_Message *canData)
 
void updateBms (void *bms)
 Transfers raw BMS data to a BmsData structure. More...
 
void updateBmsTest (void *bms, const char *canDataFn)
 Updates the BMS data. More...
 

Function Documentation

◆ assignBmsValue()

void assignBmsValue ( Bms bms,
int  id,
float  value,
const char *  name 
)

Definition at line 26 of file BMS.c.

26 {
27 switch (id) {
28 // TODO: Remember to update +1712
29 case 0:
30 if (strcmp(name, "Pack_Current") == 0) {
31 bms->packCurrent = value;
32 } else if (strcmp(name, "Pack_Inst_Voltage") == 0) {
33 bms->packVoltage = value;
34 } else if (strcmp(name, "Pack_SOC") == 0) {
35 bms->stateOfCharge = value;
36 } else if (strcmp(name, "Relay_State") == 0) {
37 /*bms->relayState = (int)value;*/
38 } else if (strcmp(name, "CRC_Checksum") == 0) {
39 // TODO: Deal with this
40
41 /*bms->crcChecksum = (int)value;*/
42 }
43 break;
44 case 1:
45 if (strcmp(name, "Pack_DCL") == 0) {
46 /*bms->packDCL = value;*/
47 } else if (strcmp(name, "Pack_CCL") == 0) {
48 /*bms->packCCL = value;*/
49 } else if (strcmp(name, "High_Temperature") == 0) {
50 /*bms->highTemperature = value;*/
51 } else if (strcmp(name, "Low_Temperature") == 0) {
52 /*bms->lowTemperature = value;*/
53 } else if (strcmp(name, "CRC_Checksum") == 0) {
54 /*bms->crcChecksum = (int)value;*/
55 }
56 break;
57 default:
58 // Handle invalid signal case if needed
59 break;
60 }
61}
float stateOfCharge
Definition: BMS.h:21
float packVoltage
Definition: BMS.h:19
float packCurrent
Definition: BMS.h:20

◆ bmsTransferFunction()

int bmsTransferFunction ( Bms bms,
CAN_Message canData 
)

Definition at line 63 of file BMS.c.

63 {
64// int index = canData->messageId;
65// Message* message = &bms->dbc->messages[index-1712];
66//
67// // Check if the message ID matches the expected one
68// if (message == NULL && message->id != canData->messageId) {
69// return 0; // Message ID not found or doesn't match
70// }
71//
72// // Decode signals within the message
73// for (int i = 0; i < message->signal_count; i++) {
74// Signal* signal = &message->signals[i];
75// float value = extractSignalValue(signal, canData->data);
76// assignBmsValue(bms, message->id, value, signal->name);
77// }
78// return 1;
79 return 1;
80}

◆ initBms()

void initBms ( Bms bms,
int  hz,
const char *  dbcFn 
)

Initializes the BMS with the given frequency.

Parameters
bmsPointer to the Bms structure to initialize.
hzThe frequency in Hertz at which the BMS operates.
dbcFnThe filename of the dbc file to use to interpret the can data.

Definition at line 7 of file BMS.c.

7 {
8 if (bms == NULL) return;
9
10 initExternalSystem(&bms->extSystem, "Bms", hz, 0);
11
12 bms->packVoltage = 0.0f;
13 bms->packCurrent = 0.0f;
14 bms->stateOfCharge = 0.0f;
15 bms->cellVoltageMin = 0.0f;
16 bms->cellVoltageMax = 0.0f;
17 bms->cellTemperatureMin = 0.0f;
18 bms->cellTemperatureMax = 0.0f;
19 bms->totalPackCapacity = 0.0f;
20 bms->remainingPackCapacity = 0.0f;
21 bms->packHealth = 0.0f;
22 bms->chargeStatus = IDLE;
24}
void updateBms(void *bms)
Transfers raw BMS data to a BmsData structure.
Definition: BMS.c:83
@ IDLE
Definition: BMS.h:12
void initExternalSystem(ExternalSystem *external, const char *name, int hz, ExternalType type)
Definition: ExternalSystem.c:3
float cellVoltageMin
Definition: BMS.h:22
float cellVoltageMax
Definition: BMS.h:23
float cellTemperatureMax
Definition: BMS.h:25
ExternalSystem extSystem
Definition: BMS.h:16
BmsChargeStatus chargeStatus
Definition: BMS.h:29
float totalPackCapacity
Definition: BMS.h:26
float cellTemperatureMin
Definition: BMS.h:24
float remainingPackCapacity
Definition: BMS.h:27
float packHealth
Definition: BMS.h:28
Updateable updateable
Definition: System.h:18
void(* update)(void *self)
Definition: Updateable.h:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateBms()

void updateBms ( void *  bms)

Transfers raw BMS data to a BmsData structure.

Parameters
rawDataPointer to the array of raw data.
Returns
The converted BmsData structure.

Updates the BMS data.

Parameters
bmsPointer to the Bms structure to update.

Definition at line 83 of file BMS.c.

83 {
84// Bms* myBms = (Bms*) bms;
85 printf("BMS Update Not implemented\n");
86 // CanMessage canData = fetchCanData(...);
87 // parseCanData(&canData, canDataFn);
88 //
89 // // Call the transfer function to decode the message
90 // if (!bmsTransferFunction(myBms, &canData)) {
91 // printf("Error: Transfer function failed.\n");
92 // }
93}
Here is the caller graph for this function:

◆ updateBmsTest()

void updateBmsTest ( void *  bms,
const char *  canDataFn 
)

Updates the BMS data.

Warning
For testing and debugging use only
Parameters
bmsPointer to the Bms structure to update.
canDataFnName of file containing can data.

Definition at line 96 of file BMS.c.

96 {
97// Bms* myBms = (Bms*) bms;
98// CanMessage canData;
99// parseCanData(&canData, canDataFn);
100//
101// // Call the transfer function to decode the message
102// if (!bmsTransferFunction(myBms, &canData)) {
103// printf("Update Test Error: Transfer function failed.\n");
104// }
105}
Here is the caller graph for this function: