Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add op_state and fault_code in the BMS section #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,9 @@ void Commands::processPacket(QByteArray data)
val.wh_cnt_dis_total = vb.vbPopFrontDouble32Auto();
}

val.fault_code = vb.vbPopFrontUint8();
val.op_state = vb.vbPopFrontUint8();

val.updateTimeStamp();

emit bmsValuesRx(val);
Expand Down Expand Up @@ -2672,6 +2675,63 @@ QString Commands::faultToStr(mc_fault_code fault)
return "Unknown fault";
}

QString Commands::bmsFaultToStr(bms_fault_code fault)
{
switch (fault) {
case BMS_FAULT_CODE_NONE: return "NONE";
case BMS_FAULT_CODE_PACK_OVER_VOLTAGE: return "PACK_OVER_VOLTAGE";
case BMS_FAULT_CODE_PACK_UNDER_VOLTAGE: return "PACK_UNDER_VOLTAGE";
case BMS_FAULT_CODE_LOAD_OVER_VOLTAGE: return "LOAD_OVER_VOLTAGE";
case BMS_FAULT_CODE_LOAD_UNDER_VOLTAGE: return "LOAD_UNDER_VOLTAGE";
case BMS_FAULT_CODE_CHARGER_OVER_VOLTAGE: return "CHARGER_OVER_VOLTAGE";
case BMS_FAULT_CODE_CHARGER_UNDER_VOLTAGE: return "CHARGER_UNDER_VOLTAGE";
case BMS_FAULT_CODE_CELL_HARD_OVER_VOLTAGE: return "CELL_HARD_OVER_VOLTAGE";
case BMS_FAULT_CODE_CELL_HARD_UNDER_VOLTAGE: return "CELL_HARD_UNDER_VOLTAGE";
case BMS_FAULT_CODE_CELL_SOFT_OVER_VOLTAGE: return "CELL_SOFT_OVER_VOLTAGE";
case BMS_FAULT_CODE_CELL_SOFT_UNDER_VOLTAGE: return "CELL_SOFT_UNDER_VOLTAGE";
case BMS_FAULT_CODE_MAX_UVP_OVP_ERRORS: return "MAX_UVP_OVP_ERRORS";
case BMS_FAULT_CODE_MAX_UVT_OVT_ERRORS: return "MAX_UVT_OVT_ERRORS";
case BMS_FAULT_CODE_OVER_CURRENT: return "OVER_CURRENT";
case BMS_FAULT_CODE_OVER_TEMP_BMS: return "OVER_TEMP_BMS";
case BMS_FAULT_CODE_UNDER_TEMP_BMS: return "UNDER_TEMP_BMS";
case BMS_FAULT_CODE_DISCHARGE_OVER_TEMP_CELLS: return "DISCHARGE_OVER_TEMP_CELLS";
case BMS_FAULT_CODE_DISCHARGE_UNDER_TEMP_CELLS: return "DISCHARGE_UNDER_TEMP_CELLS";
case BMS_FAULT_CODE_CHARGE_OVER_TEMP_CELLS: return "CHARGE_OVER_TEMP_CELLS";
case BMS_FAULT_CODE_CHARGE_UNDER_TEMP_CELLS: return "CHARGE_UNDER_TEMP_CELLS";
case BMS_FAULT_CODE_PRECHARGE_TIMEOUT: return "PRECHARGE_TIMEOUT";
case BMS_FAULT_CODE_DISCHARGE_RETRY: return "DISCHARGE_RETRY";
case BMS_FAULT_CODE_CHARGE_RETRY: return "CHARGE_RETRY";
case BMS_FAULT_CODE_CAN_DELAYED_POWER_DOWN: return "CAN_DELAYED_POWER_DOWN";
case BMS_FAULT_CODE_NOT_USED_TIMEOUT: return "NOT_USED_TIMEOUT";
case BMS_FAULT_CODE_CHARGER_DISCONNECT: return "CHARGER_DISCONNECT";
case BMS_FAULT_CODE_CHARGER_CURRENT_THRESHOLD_TIMEOUT: return "CHARGER_CURRENT_THRESHOLD_TIMEOUT";
}
return "Unknown BMS fault";

}

QString Commands::bmsOpStateToStr(bms_op_state opState)
{
switch (opState) {
case BMS_OP_STATE_UNKNOWN: return "UNKNOWN";
case BMS_OP_STATE_INIT: return "INIT";
case BMS_OP_STATE_CHARGING: return "CHARGING";
case BMS_OP_STATE_PRE_CHARGE: return "PRE_CHARGE";
case BMS_OP_STATE_LOAD_ENABLED: return "LOAD_ENABLED";
case BMS_OP_STATE_BATTERY_DEAD: return "BATTERY_DEAD";
case BMS_OP_STATE_IDLE: return "IDLE";
case BMS_OP_STATE_EXTERNAL: return "EXTERNAL";
case BMS_OP_STATE_ERROR: return "ERROR";
case BMS_OP_STATE_ERROR_PRECHARGE: return "ERROR_PRECHARGE";
case BMS_OP_STATE_BALANCING: return "BALANCING";
case BMS_OP_STATE_CHARGED: return "CHARGED";
case BMS_OP_STATE_FORCEON: return "FORCEON";

}
return "Unknown fault";

}

QByteArray Commands::bmReadMemWait(uint32_t addr, quint16 size, int timeoutMs)
{
bmReadMem(addr, size);
Expand Down
2 changes: 2 additions & 0 deletions commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Commands : public QObject
void setLimitedCompatibilityCommands(QVector<int> compatibilityCommands);

Q_INVOKABLE static QString faultToStr(mc_fault_code fault);
Q_INVOKABLE static QString bmsFaultToStr(bms_fault_code fault);
Q_INVOKABLE static QString bmsOpStateToStr(bms_op_state opState);

Q_INVOKABLE QByteArray bmReadMemWait(uint32_t addr, quint16 size, int timeoutMs = 3000);
Q_INVOKABLE int bmWriteMemWait(uint32_t addr, QByteArray data, int timeoutMs = 3000);
Expand Down
52 changes: 52 additions & 0 deletions datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,52 @@ typedef enum {
FAULT_CODE_ENCODER_FAULT
} mc_fault_code;

typedef enum {
BMS_FAULT_CODE_NONE = 0,
BMS_FAULT_CODE_PACK_OVER_VOLTAGE,
BMS_FAULT_CODE_PACK_UNDER_VOLTAGE,
BMS_FAULT_CODE_LOAD_OVER_VOLTAGE,
BMS_FAULT_CODE_LOAD_UNDER_VOLTAGE,
BMS_FAULT_CODE_CHARGER_OVER_VOLTAGE,
BMS_FAULT_CODE_CHARGER_UNDER_VOLTAGE,
BMS_FAULT_CODE_CELL_HARD_OVER_VOLTAGE,
BMS_FAULT_CODE_CELL_HARD_UNDER_VOLTAGE,
BMS_FAULT_CODE_CELL_SOFT_OVER_VOLTAGE,
BMS_FAULT_CODE_CELL_SOFT_UNDER_VOLTAGE,
BMS_FAULT_CODE_MAX_UVP_OVP_ERRORS,
BMS_FAULT_CODE_MAX_UVT_OVT_ERRORS,
BMS_FAULT_CODE_OVER_CURRENT,
BMS_FAULT_CODE_OVER_TEMP_BMS,
BMS_FAULT_CODE_UNDER_TEMP_BMS,
BMS_FAULT_CODE_DISCHARGE_OVER_TEMP_CELLS,
BMS_FAULT_CODE_DISCHARGE_UNDER_TEMP_CELLS,
BMS_FAULT_CODE_CHARGE_OVER_TEMP_CELLS,
BMS_FAULT_CODE_CHARGE_UNDER_TEMP_CELLS,
BMS_FAULT_CODE_PRECHARGE_TIMEOUT,
BMS_FAULT_CODE_DISCHARGE_RETRY,
BMS_FAULT_CODE_CHARGE_RETRY,
BMS_FAULT_CODE_CAN_DELAYED_POWER_DOWN,
BMS_FAULT_CODE_NOT_USED_TIMEOUT,
BMS_FAULT_CODE_CHARGER_DISCONNECT,
BMS_FAULT_CODE_CHARGER_CURRENT_THRESHOLD_TIMEOUT
} bms_fault_state;

typedef enum {
BMS_OP_STATE_UNKNOWN = 0,
BMS_OP_STATE_INIT, // 1
BMS_OP_STATE_CHARGING, // 2
BMS_OP_STATE_PRE_CHARGE, // 3
BMS_OP_STATE_LOAD_ENABLED, // 4
BMS_OP_STATE_BATTERY_DEAD, // 5
BMS_OP_STATE_IDLE, // 6
BMS_OP_STATE_EXTERNAL, // 7
BMS_OP_STATE_ERROR, // 8
BMS_OP_STATE_ERROR_PRECHARGE, // 9
BMS_OP_STATE_BALANCING, // 10
BMS_OP_STATE_CHARGED, // 11
BMS_OP_STATE_FORCEON, // 12
} bms_op_state;

typedef enum {
DISP_POS_MODE_NONE = 0,
DISP_POS_MODE_INDUCTANCE,
Expand Down Expand Up @@ -736,6 +782,8 @@ struct BMS_VALUES {
Q_PROPERTY(double wh_cnt_chg_total MEMBER wh_cnt_chg_total)
Q_PROPERTY(double ah_cnt_dis_total MEMBER ah_cnt_dis_total)
Q_PROPERTY(double wh_cnt_dis_total MEMBER wh_cnt_dis_total)
Q_PROPERTY(int fault_code MEMBER fault_code)
Q_PROPERTY(int op_state MEMBER op_state)

public:
BMS_VALUES() {
Expand All @@ -755,6 +803,8 @@ struct BMS_VALUES {
wh_cnt_chg_total = 0.0;
ah_cnt_dis_total = 0.0;
wh_cnt_dis_total = 0.0;
fault_code = 0;
op_state = 0.0;
updateTime = -1;
}

Expand Down Expand Up @@ -793,6 +843,8 @@ struct BMS_VALUES {
double wh_cnt_chg_total;
double ah_cnt_dis_total;
double wh_cnt_dis_total;
int fault_code;
int op_state;
qint64 updateTime;
};

Expand Down
2 changes: 2 additions & 0 deletions pages/pagebms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ void PageBms::bmsValuesRx(BMS_VALUES val)
ui->valTable->item(13, 0)->setText(QString("%1 Wh").arg(val.wh_cnt_chg_total, 0, 'f', 3));
ui->valTable->item(14, 0)->setText(QString("%1 Ah").arg(val.ah_cnt_dis_total, 0, 'f', 3));
ui->valTable->item(15, 0)->setText(QString("%1 Wh").arg(val.wh_cnt_dis_total, 0, 'f', 3));
ui->valTable->item(16, 0)->setText(Commands::bmsFaultToStr(bms_fault_code(val.fault_code)));
ui->valTable->item(17, 0)->setText(Commands::bmsOpStateToStr(bms_op_state(val.op_state)));
}

void PageBms::reloadCellBars(int cells)
Expand Down
20 changes: 20 additions & 0 deletions pages/pagebms.ui
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@
<string>Wh Discharge Total</string>
</property>
</row>
<row>
<property name="text">
<string>Fault Code</string>
</property>
</row>
<row>
<property name="text">
<string>Operational State</string>
</property>
</row>
<column>
<property name="text">
<string>Value</string>
Expand Down Expand Up @@ -247,6 +257,16 @@
<string/>
</property>
</item>
<item row="16" column="0">
<property name="text">
<string/>
</property>
</item>
<item row="17" column="0">
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
<item>
Expand Down
Loading