-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule_Battery_Management_System.cpp
106 lines (79 loc) · 2.39 KB
/
Module_Battery_Management_System.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "Module_Battery_Management_System.h"
Module_Battery_Management_System::Module_Battery_Management_System()
: BasicPOCModule(getClassName(), 0x42), bq(this, componentList){
}
void Module_Battery_Management_System::init() {
//TODO
}
void Module_Battery_Management_System::selfTest() {
//TODO
}
const uint16_t Module_Battery_Management_System::getId() const {
//See PoC Module Table
return 0x020;
}
const string Module_Battery_Management_System::getClassName() const {
return "Battery Management System";
}
Module_Battery_Management_System::Cell::Cell(unsigned int number) : number(number) {
}
unsigned int Module_Battery_Management_System::Cell::getNumber() {
return number;
}
double Module_Battery_Management_System::Cell::getVoltage() {
//TODO
return 0.0;
}
void Module_Battery_Management_System::Cell::setMaxVoltage(double maxVoltage) {
this->maxVoltage = maxVoltage;
}
double Module_Battery_Management_System::Cell::getMaxVoltage() {
return maxVoltage;
}
void Module_Battery_Management_System::Cell::setMaxCapacity(double maxCapacity) {
this->maxCapacity = maxCapacity;
}
double Module_Battery_Management_System::Cell::getMaxCapacity() {
return maxCapacity;
}
void Module_Battery_Management_System::Cell::setMinVoltage(double minVoltage) {
this->minVoltage = minVoltage;
}
double Module_Battery_Management_System::Cell::getMinVoltage() {
return minVoltage;
}
bool Module_Battery_Management_System::Cell::getIsActive() {
return isActive;
}
void Module_Battery_Management_System::Cell::activate() {
isActive = true;
}
void Module_Battery_Management_System::Cell::deactivate() {
isActive = false;
}
double Module_Battery_Management_System::getBatteryCapacityLeft() {
double capacityLeft = 0;
for (auto e = cells.begin(); e != cells.end(); e++) {
if ((*e)->getIsActive()) {
//TODO Battery is no Capacitor lul
capacityLeft += (*e)->getVoltage() / (*e)->getMaxVoltage() * (*e)->getMaxCapacity();
}
}
return capacityLeft;
}
double Module_Battery_Management_System::getBatteryMaxCapacity() {
double totalCapacity = 0;
for (auto e = cells.begin(); e != cells.end(); e++) {
if ((*e)->getIsActive()) {
totalCapacity += (*e)->getMaxCapacity();
}
}
return totalCapacity;
}
double Module_Battery_Management_System::getBatteryState() {
return getBatteryCapacityLeft() / getBatteryMaxCapacity();
}
double Module_Battery_Management_System::getCurrentDraw() {
//TODO
return 0.0;
}