Line data Source code
1 : /* 2 : * Status.hpp 3 : * 4 : * A small class for error codes. 5 : * Created on: 21 Jun 2022 6 : * Author(s): Jorn Reniers, Volkan Kumtepeli 7 : */ 8 : 9 : #pragma once 10 : 11 : #include <cstdint> 12 : 13 : namespace slide { 14 : enum class Status : int_fast8_t //!< -128 to 127 = 1 byte. 15 : { 16 : ReachedCurrentLimit = -6, 17 : ReachedVoltageLimit, 18 : ReachedTimeLimit, 19 : ReachedSmallCurrent, //!< Not sure if this is an error? 20 : Invalid_Vset, 21 : SafeVoltage, 22 : //!< Upper part is from cycler! 23 : Success, //!< = 0 24 : Vmin_violation, 25 : Vmax_violation, 26 : VMIN_violation, 27 : VMAX_violation, 28 : VMINsafety_violation, //!< 0.99 VMIN 29 : VMAXsafety_violation, //!< 1.01 VMAX 30 : V_not_calculated, 31 : SOC_limits_violation, 32 : Invalid_states, 33 : Invalid_SUs, 34 : ParallelUnit_failed, //!< throw 14. 35 : RedistributeCurrent_failed, 36 : timeStep_CC_failed, 37 : setVoltage_not_defined, 38 : Unknown_problem = 127, 39 : 40 : //!< Auxillary definitions: 41 : Critical = VMIN_violation, //!< Non-critical status definition. 42 : NotSafe = VMINsafety_violation 43 : 44 : }; 45 : 46 : const char *getStatusMessage(Status status); 47 3745 : bool inline isStatusSuccessful(Status status) { return status == Status::Success; } 48 : bool inline isStatusFailed(Status status) { return !isStatusSuccessful(status); } 49 15845192 : bool inline isStatusOK(Status status) { return (status < Status::Critical); } 50 15328422 : bool inline isStatusBad(Status status) { return !isStatusOK(status); } 51 : bool inline isStatusWarning(Status status) { return ((status != Status::Success) && isStatusOK(status)); } //!< Not successful but voltage is in limits. 52 : bool inline isStatusSafe(Status status) { return status < Status::NotSafe; } 53 : bool inline isLimitsReached(Status status) { return status < Status::ReachedTimeLimit; } 54 : 55 : bool inline isStatusVoltageLimitsViolated(Status status) { return (Status::Success < status && status <= Status::VMAXsafety_violation); } 56 : 57 : bool inline isCCLimitReached(Status status) { return status == Status::ReachedVoltageLimit || status == Status::ReachedTimeLimit; } 58 : bool inline isCVLimitReached(Status status) { return status == Status::ReachedCurrentLimit || status == Status::ReachedTimeLimit; } 59 : bool inline isCurrentLimitReached(Status status) { return status == Status::ReachedCurrentLimit; } 60 : bool inline isVoltageLimitReached(Status status) { return status == Status::ReachedVoltageLimit; } 61 : 62 : 63 : inline const char *getStatusMessage(Status status) 64 : { 65 : switch (status) { 66 : case Status::VMIN_violation: 67 : return "VMIN is violated!"; 68 : case Status::Vmin_violation: 69 : return "Vmin is violated!"; 70 : case Status::Success: 71 : return "Success! Yay!"; 72 : case Status::Vmax_violation: 73 : return "Vmax is violated!"; 74 : case Status::VMAX_violation: 75 : return "VMAX is violated!"; 76 : case Status::V_not_calculated: 77 : return "V could not be calculated at all!"; 78 : case Status::SOC_limits_violation: 79 : return "SOC_limits_violation!"; 80 : case Status::Invalid_states: 81 : return "Invalid_states!"; 82 : case Status::Invalid_SUs: 83 : return "Invalid_SUs!"; 84 : case Status::ReachedCurrentLimit: 85 : return "ReachedCurrentLimit!"; 86 : case Status::ReachedVoltageLimit: 87 : return "ReachedVoltageLimit!"; 88 : case Status::ReachedTimeLimit: 89 : return "ReachedTimeLimit!"; 90 : case Status::ReachedSmallCurrent: 91 : return "ReachedSmallCurrent!"; 92 : case Status::Invalid_Vset: 93 : return "Invalid_Vset!"; 94 : case Status::SafeVoltage: 95 : return "SafeVoltage!"; 96 : case Status::ParallelUnit_failed: 97 : return "ParallelUnit_failed!"; 98 : case Status::RedistributeCurrent_failed: 99 : return "RedistributeCurrent_failed!"; 100 : case Status::timeStep_CC_failed: 101 : return "timeStep_CC_failed!"; 102 : case Status::setVoltage_not_defined: 103 : return "setVoltage is not defined for this class!"; 104 : case Status::Unknown_problem: 105 : return "Unknown problem!"; 106 : default: 107 : return "Unkown status?!"; 108 : } 109 : } 110 : } // namespace slide