From c1e59eba4eb68feedf9fa4202e6e2915dd514b24 Mon Sep 17 00:00:00 2001 From: wyattb Date: Mon, 12 Aug 2024 13:46:29 -0400 Subject: [PATCH] #172 - added support for BMS faults --- .../fault-display/fault-display.component.ts | 113 ++++++++++++++++-- .../enumerations/identifier-data-type.ts | 3 +- scylla-server/src/socket/mock-proxy-client.ts | 9 +- scylla-server/src/utils/data.utils.ts | 3 +- 4 files changed, 118 insertions(+), 10 deletions(-) diff --git a/angular-client/src/pages/charging-page/components/fault-display/fault-display.component.ts b/angular-client/src/pages/charging-page/components/fault-display/fault-display.component.ts index 558ebf21..6faedea7 100644 --- a/angular-client/src/pages/charging-page/components/fault-display/fault-display.component.ts +++ b/angular-client/src/pages/charging-page/components/fault-display/fault-display.component.ts @@ -2,6 +2,32 @@ import { Component } from '@angular/core'; import Storage from 'src/services/storage.service'; import { IdentifierDataType } from 'src/utils/enumerations/identifier-data-type'; +enum BMS_FAULTS_TYPES { + CELLS_NOT_BALANCING = 1, + CELL_VOLTAGE_TOO_LOW = 2, + CELL_VOLTAGE_TOO_HIGH = 4, + PACK_TOO_HOT = 8, + OPEN_WIRING_FAULT = 16, + INTERNAL_SOFTWARE_FAULT = 32, + INTERNAL_THERMAL_ERROR = 64, + INTERNAL_CELL_COMM_FAULT = 128, + CURRENT_SENSOR_FAULT = 256, + CHARGE_READING_MISMATCH = 512, + LOW_CELL_VOLTAGE = 1024, + WEAK_PACK_FAULT = 2048, + EXTERNAL_CAN_FAULT = 4096, + DISCHARGE_LIMIT_ENFORCEMENT_FAULT = 8192, + CHARGER_SAFETY_RELAY = 16384, + BATTERY_THERMISTOR = 32768, + CHARGER_CAN_FAULT = 65536, + CHARGER_LIMIT_ENFORCEMENT_FAULT = 131072 +} + +enum FaultType { + BMS, + Charger +} + @Component({ selector: 'fault-display', templateUrl: './fault-display.component.html', @@ -19,27 +45,34 @@ export default class FaultDisplay { ngOnInit() { this.storage.get(IdentifierDataType.COMM_TIMEOUT_FAULT).subscribe((value) => { - this.addFault(value.values[0], 'Comm Timeout'); + this.addFault(value.values[0], 'Comm Timeout', FaultType.Charger); }); this.storage.get(IdentifierDataType.HARDWARE_FAILURE_FAULT).subscribe((value) => { - this.addFault(value.values[0], 'Hardware Failure'); + this.addFault(value.values[0], 'Hardware Failure', FaultType.Charger); }); this.storage.get(IdentifierDataType.OVER_TEMP_FAULT).subscribe((value) => { - this.addFault(value.values[0], 'Over Temp'); + this.addFault(value.values[0], 'Over Temp', FaultType.Charger); }); this.storage.get(IdentifierDataType.VOLTAGE_WRONG_FAULT).subscribe((value) => { - this.addFault(value.values[0], 'Voltage Wrong'); + this.addFault(value.values[0], 'Voltage Wrong', FaultType.Charger); }); this.storage.get(IdentifierDataType.WRONG_BAT_CONNECT_FAULT).subscribe((value) => { - this.addFault(value.values[0], 'Wrong Battery Connect'); + this.addFault(value.values[0], 'Wrong Battery Connect', FaultType.Charger); + }); + + /** + * This is based on the shepard enum for faults: + * https://github.com/Northeastern-Electric-Racing/ShepherdBMS-2/blob/6eb3f863ed131a15bdf98665532cb7807bbd2920/Core/Inc/datastructs.h#L39 + */ + this.storage.get(IdentifierDataType.BMS_FAULTS).subscribe((value) => { + this.addFault(value.values[0], 'MASSIVE L, Should not be a fault hahaha', FaultType.BMS); }); } - // /** * Adds the fault name, with the current time to the faults array, if the faultValue is NOT 0. * Shifts through the fault array to keep only the most recent 50 faults. @@ -47,12 +80,78 @@ export default class FaultDisplay { * @param faultValue an string with an integer value. * @param faultName the name of the fault, to be displayed. */ - addFault(faultValue: string, faultName: string) { + addFault(faultValue: string, faultName: string, faultType: FaultType) { if (parseInt(faultValue) !== 0) { + if (faultType === FaultType.BMS) { + faultName = this.getBMSFaultName(parseInt(faultValue)); + } + // current implementation doesn't need a specified case for charger faults + // (they have indiv binary id's) if (this.faults.length >= 50) { this.faults.pop(); } this.faults.unshift({ faultName, time: new Date().toLocaleTimeString() }); } } + + getBMSFaultName(faultValue: number): string { + let faultName = ''; + switch (faultValue) { + case BMS_FAULTS_TYPES.CELLS_NOT_BALANCING: + faultName = 'Cells Not Balancing'; + break; + case BMS_FAULTS_TYPES.CELL_VOLTAGE_TOO_LOW: + faultName = 'Cell Voltage too Low'; + break; + case BMS_FAULTS_TYPES.CELL_VOLTAGE_TOO_HIGH: + faultName = 'Cell Voltage too High'; + break; + case BMS_FAULTS_TYPES.PACK_TOO_HOT: + faultName = ' Pack too Hot'; + break; + case BMS_FAULTS_TYPES.OPEN_WIRING_FAULT: + faultName = 'Open Wiring Fault'; + break; + case BMS_FAULTS_TYPES.INTERNAL_SOFTWARE_FAULT: + faultName = 'Internal Software Fault'; + break; + case BMS_FAULTS_TYPES.INTERNAL_THERMAL_ERROR: + faultName = 'Internal Thermal Error'; + break; + case BMS_FAULTS_TYPES.INTERNAL_CELL_COMM_FAULT: + faultName = 'Internal Cell Comm Fault'; + break; + case BMS_FAULTS_TYPES.CURRENT_SENSOR_FAULT: + faultName = 'Current Sensor Fault'; + break; + case BMS_FAULTS_TYPES.CHARGE_READING_MISMATCH: + faultName = 'Charge Reading Mismatch'; + break; + case BMS_FAULTS_TYPES.LOW_CELL_VOLTAGE: + faultName = 'Low Cell Voltage'; + break; + case BMS_FAULTS_TYPES.WEAK_PACK_FAULT: + faultName = 'Weak Pack Fault'; + break; + case BMS_FAULTS_TYPES.EXTERNAL_CAN_FAULT: + faultName = 'External Can Fault'; + break; + case BMS_FAULTS_TYPES.DISCHARGE_LIMIT_ENFORCEMENT_FAULT: + faultName = 'Discharge Limit Enforcement Fault'; + break; + case BMS_FAULTS_TYPES.CHARGER_SAFETY_RELAY: + faultName = 'Charger Safety Relay'; + break; + case BMS_FAULTS_TYPES.BATTERY_THERMISTOR: + faultName = 'Battery Thermistor'; + break; + case BMS_FAULTS_TYPES.CHARGER_CAN_FAULT: + faultName = 'Charger Can Fault'; + break; + case BMS_FAULTS_TYPES.CHARGER_LIMIT_ENFORCEMENT_FAULT: + faultName = 'Charger Limit Enforcement Fault'; + break; + } + return faultName; + } } diff --git a/angular-client/src/utils/enumerations/identifier-data-type.ts b/angular-client/src/utils/enumerations/identifier-data-type.ts index f2996d9f..ef71be97 100644 --- a/angular-client/src/utils/enumerations/identifier-data-type.ts +++ b/angular-client/src/utils/enumerations/identifier-data-type.ts @@ -17,6 +17,7 @@ export enum IdentifierDataType { OVER_TEMP_FAULT = 'Box-F_OverTemp', VOLTAGE_WRONG_FAULT = 'Box-F_OverVoltage', WRONG_BAT_CONNECT_FAULT = 'Box-F_WrongBatConnect', + BMS_FAULTS = 'Status-Faults', VIEWERS = 'Viewers', SPEED = 'State-Speed', TORQUE = 'Torque', @@ -30,7 +31,7 @@ export enum IdentifierDataType { CHARGE_CURRENT_LIMIT = 'Pack-CCL', DISCHARGE_CURRENT_LIMIT = 'Pack-DCL', XYZAccel = 'XYZAcceleration', - STATUS = 'Status-Balancing', + STATUS_BALANCING = 'Status-Balancing', BMS_MODE = 'Status-State', VOLTS_HIGH = 'Cells-Volts_High_Value', VOLTS_LOW = 'Cells-Volts_Low_Value', diff --git a/scylla-server/src/socket/mock-proxy-client.ts b/scylla-server/src/socket/mock-proxy-client.ts index ebdc7e94..370dec8a 100644 --- a/scylla-server/src/socket/mock-proxy-client.ts +++ b/scylla-server/src/socket/mock-proxy-client.ts @@ -32,7 +32,7 @@ const baseMockData: MockData[] = [ max: 100 }, { - name: DataType.STATUS, + name: DataType.STATUS_BALANCING, unit: Unit.BINARY, vals: [0], min: 0, @@ -227,6 +227,13 @@ const baseMockData: MockData[] = [ vals: [0], min: 0, max: 1 + }, + { + name: DataType.BMS_FAULTS, + unit: Unit.HEX, + vals: [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072], + min: 0, + max: 131072 } ]; diff --git a/scylla-server/src/utils/data.utils.ts b/scylla-server/src/utils/data.utils.ts index f2ef63a2..82247c8d 100644 --- a/scylla-server/src/utils/data.utils.ts +++ b/scylla-server/src/utils/data.utils.ts @@ -17,6 +17,7 @@ export enum DataType { OVER_TEMP_FAULT = 'Box-F_OverTemp', VOLTAGE_WRONG_FAULT = 'Box-F_OverVoltage', WRONG_BAT_CONNECT_FAULT = 'Box-F_WrongBatConnect', + BMS_FAULTS = 'Status-Faults', VIEWERS = 'Viewers', SPEED = 'State-Speed', TORQUE = 'Torque', @@ -30,7 +31,7 @@ export enum DataType { CHARGE_CURRENT_LIMIT = 'Pack-CCL', DISCHARGE_CURRENT_LIMIT = 'Pack-DCL', XYZAccel = 'XYZAcceleration', - STATUS = 'Status-Balancing', + STATUS_BALANCING = 'Status-Balancing', BMS_MODE = 'Status-State', VOLTS_HIGH = 'Cells-Volts_High_Value', VOLTS_LOW = 'Cells-Volts_Low_Value',