Skip to content

Commit

Permalink
#156 - fault type asbtraction start
Browse files Browse the repository at this point in the history
  • Loading branch information
bracyw committed Oct 6, 2024
1 parent faae121 commit 54febe4
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Fault } from '../indiv-fault/fault.model';
import { FaultType, FaultTypeModel } from './fault-type.model';

export class BMSFaultType implements FaultTypeModel {
subscribeToFaults(): Fault<FaultTypeModel> {
// TODO
throw new Error('Method not implemented.');
}
name = FaultType.BMS;
recordedFaults: Fault<FaultTypeModel>[] = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Fault } from '../indiv-fault/fault.model';
/**
* Represents a type of fault (e.g. BMS, TPU, Charger),
* with a name (which would mach the previous examples)
* and a list of recorded faults so far.
*
* It also gives the ability to subscribe to it's list of recored faults
* which will allow for the subscriber to be updated everytime a new fault is recieved.
*/
export interface FaultTypeModel {
name: FaultType;
recordedFaults: Array<Fault<FaultTypeModel>>;
subscribeToFaults(): Fault<FaultTypeModel>;
}

export enum FaultType {
BMS = 'BMS',
Charger = 'Charger'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BMSFaultType } from '../fault-type/bms-fault-type.model';
import { Fault } from './fault.model';

export class BMSFault implements Fault<BMSFaultType> {
name: String;
timeTriggered: number;
format(): { type: String; name: String; timeTriggered: number } {
throw new Error('Method not implemented.');
}
constructor() {
this.name = 'hello';
this.timeTriggered = 101011;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { FaultTypeModel } from '../fault-type/fault-type.model';

export interface Fault<T extends FaultTypeModel> {
name: String;
timeTriggered: number;
format(): { type: String; name: String; timeTriggered: number };
}

export type AllFaultEnums = BMS_FAULTS_VALUES;

enum BMS_FAULTS_VALUES {
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 CHARGER_FAULT_VALUES {
COMM_TIMEOUT_FAULT = 'Comm Timeout',
HARDWARE_FAILURE_FAULT = 'Hardware Failure',
OVER_TEMP_FAULT = 'Over Temp',
VOLTAGE_WRONG_FAULT = 'Voltage Wrong',
WRONG_BAT_CONNECT_FAULT = 'Wrong Battery Connect'
}

0 comments on commit 54febe4

Please sign in to comment.