From 54febe441abfa43eda5433c7806a253818f623e3 Mon Sep 17 00:00:00 2001 From: wyattb Date: Sun, 6 Oct 2024 18:36:36 -0400 Subject: [PATCH] #156 - fault type asbtraction start --- .../shared/fault-type/bms-fault-type.model.ts | 11 ++++++ .../shared/fault-type/fault-type.model.ts | 19 ++++++++++ .../shared/indiv-fault/bms-fault.model.ts | 14 +++++++ .../shared/indiv-fault/fault.model.ts | 38 +++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 angular-client/src/pages/fault-page/shared/fault-type/bms-fault-type.model.ts create mode 100644 angular-client/src/pages/fault-page/shared/fault-type/fault-type.model.ts create mode 100644 angular-client/src/pages/fault-page/shared/indiv-fault/bms-fault.model.ts create mode 100644 angular-client/src/pages/fault-page/shared/indiv-fault/fault.model.ts diff --git a/angular-client/src/pages/fault-page/shared/fault-type/bms-fault-type.model.ts b/angular-client/src/pages/fault-page/shared/fault-type/bms-fault-type.model.ts new file mode 100644 index 00000000..278c48b4 --- /dev/null +++ b/angular-client/src/pages/fault-page/shared/fault-type/bms-fault-type.model.ts @@ -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 { + // TODO + throw new Error('Method not implemented.'); + } + name = FaultType.BMS; + recordedFaults: Fault[] = []; +} diff --git a/angular-client/src/pages/fault-page/shared/fault-type/fault-type.model.ts b/angular-client/src/pages/fault-page/shared/fault-type/fault-type.model.ts new file mode 100644 index 00000000..3fae7eab --- /dev/null +++ b/angular-client/src/pages/fault-page/shared/fault-type/fault-type.model.ts @@ -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>; + subscribeToFaults(): Fault; +} + +export enum FaultType { + BMS = 'BMS', + Charger = 'Charger' +} diff --git a/angular-client/src/pages/fault-page/shared/indiv-fault/bms-fault.model.ts b/angular-client/src/pages/fault-page/shared/indiv-fault/bms-fault.model.ts new file mode 100644 index 00000000..ab379ca7 --- /dev/null +++ b/angular-client/src/pages/fault-page/shared/indiv-fault/bms-fault.model.ts @@ -0,0 +1,14 @@ +import { BMSFaultType } from '../fault-type/bms-fault-type.model'; +import { Fault } from './fault.model'; + +export class BMSFault implements Fault { + name: String; + timeTriggered: number; + format(): { type: String; name: String; timeTriggered: number } { + throw new Error('Method not implemented.'); + } + constructor() { + this.name = 'hello'; + this.timeTriggered = 101011; + } +} diff --git a/angular-client/src/pages/fault-page/shared/indiv-fault/fault.model.ts b/angular-client/src/pages/fault-page/shared/indiv-fault/fault.model.ts new file mode 100644 index 00000000..7a87df60 --- /dev/null +++ b/angular-client/src/pages/fault-page/shared/indiv-fault/fault.model.ts @@ -0,0 +1,38 @@ +import { FaultTypeModel } from '../fault-type/fault-type.model'; + +export interface Fault { + 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' +}