-
Notifications
You must be signed in to change notification settings - Fork 0
/
DalyBMS.h
73 lines (63 loc) · 1.66 KB
/
DalyBMS.h
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
#include "Arduino.h"
#include <SoftwareSerial.h>
#ifndef DalyBMS_H
#define DalyBMS_H
// Input how many cells you expect to have
#ifndef NUM_CELLS
#define NUM_CELLS 21
#endif
#ifndef NUM_TEMP_PROBES
#define NUM_TEMP_PROBES 4
#endif
#ifndef BMS_DEBUG
#define BMS_DEBUG false
#endif
typedef struct
{
byte command;
byte checksum; //Given to us from module. Checked against the rolling calculated A/B checksums.
} DalyBMSPacket;
typedef struct
{
boolean charge;
boolean discharge;
} MOSFET_STATUS;
const byte header[2] = {0xA5, 0x40};
const byte end = 0x77;
class DalyBMS
{
public:
DalyBMS();
void begin(SoftwareSerial *serialPort);
boolean update(uint16_t maxWait = 1000);
float *getCells() { return cells; }
uint32_t getBalanceState() { return balanceState; }
float getPackVoltage() { return packVoltage; }
float getPackCurrent() { return packCurrent; }
float getCellMaxVoltage() { return cellMax; }
float getCellMinVoltage() { return cellMin; }
float getCellDiff() { return cellDiff; }
byte getNumProbes() { return NUM_TEMP_PROBES; }
float *getProbeData() { return probes; }
MOSFET_STATUS getMOSFETStatus() { return MOSFETStatus; }
private:
SoftwareSerial *BMSSerial;
DalyBMSPacket outdata;
DalyBMSPacket indata;
bool checkStatus(byte status);
bool requestResponse(uint16_t maxWait);
float cells[NUM_CELLS];
byte buffer[8];
uint32_t balanceState;
float packVoltage;
float packCurrent;
float cellMax;
float cellMin;
float cellDiff;
MOSFET_STATUS MOSFETStatus;
float probes[NUM_TEMP_PROBES];
void printHex(byte x);
void clear();
byte next();
};
#endif