001package com.ctre.phoenix;
002
003import java.util.HashMap;
004
005/**
006 * All the codes available to CTRE products
007 */
008public enum ErrorCode {
009        OK(0),                                          //!< No Error - Function executed as expected
010
011        //CAN-Related
012        CAN_MSG_STALE(1),
013        CAN_TX_FULL(-1),
014        TxFailed(-1),                           //!< Could not transmit the CAN frame.
015        InvalidParamValue(-2),  //!< Caller passed an invalid param
016        CAN_INVALID_PARAM(-2),
017        RxTimeout(-3),                          //!< CAN frame has not been received within specified period of time.
018        CAN_MSG_NOT_FOUND(-3),
019        TxTimeout(-4),                          //!< Not used.
020        CAN_NO_MORE_TX_JOBS(-4),
021        UnexpectedArbId(-5),            //!< Specified Device ID is invalid.
022        CAN_NO_SESSIONS_AVAIL(-5),
023        BufferFull(+6),                 //!< Caller attempted to insert data into a buffer that is full.
024        CAN_OVERFLOW(-6),
025        SensorNotPresent(-7),           //!< Sensor is not present
026        FirmwareTooOld (-8),
027
028
029        //General
030        GeneralError(-100),             //!< User Specified General Error
031        GENERAL_ERROR(-100),
032
033        //Signal
034        SIG_NOT_UPDATED(-200),
035        SigNotUpdated(-200),                    //!< Have not received an value response for signal.
036        NotAllPIDValuesUpdated(-201),
037
038        //Gadgeteer Port Error Codes
039        //These include errors between ports and modules
040        GEN_PORT_ERROR(-300),
041        PORT_MODULE_TYPE_MISMATCH(-301),
042        //Gadgeteer Module Error Codes
043        //These apply only to the module units themselves
044        GEN_MODULE_ERROR(-400),
045        MODULE_NOT_INIT_SET_ERROR(-401),
046        MODULE_NOT_INIT_GET_ERROR(-402),
047
048
049        //API
050        WheelRadiusTooSmall(-500),
051        TicksPerRevZero(-501),
052        DistanceBetweenWheelsTooSmall(-502),
053        GainsAreNotSet(-503),
054        DoubleVoltageCompensatingWPI(-505),
055
056        //Higher Level
057        IncompatibleMode(-600),
058        InvalidHandle(-601),            //!< Handle does not match stored map of handles
059
060
061        //CAN Related
062        PulseWidthSensorNotPresent (10),        //!< Special Code for "isSensorPresent"
063
064        //General
065        GeneralWarning(100),
066        FeatureNotSupported(101),
067        NotImplemented(102),
068        FirmVersionCouldNotBeRetrieved (103),
069        FeaturesNotAvailableYet(104),
070        ControlModeNotValid(105),
071
072        ControlModeNotSupportedYet(106),
073        CascadedPIDNotSupportedYet(107),
074        AuxiliaryPIDNotSupportedYet(107),
075        RemoteSensorsNotSupportedYet(108),
076        MotProfFirmThreshold(109),
077        MotProfFirmThreshold2(110),
078        
079        //Simulation
080        SimDeviceNotFound(200),
081        SimPhysicsTypeNotSupported(201),
082        SimDeviceAlreadyExists(202);
083
084        //---------------------- Integral To Enum operators -----------//
085    public final int value; //!< Hold the integral value of an enum instance.
086    /** private c'tor for above declarations */
087        private ErrorCode(int initValue) {this.value = initValue;       }
088    /** Keep singleton map to quickly lookup enum via int */
089    private static HashMap<Integer, ErrorCode> _map = null;
090        /** static c'tor, prepare the map */
091    static {
092        _map = new HashMap<Integer, ErrorCode>();
093                for (ErrorCode type : ErrorCode.values()) {
094                        _map.put(type.value, type);
095                }
096    }
097    /** public lookup to convert int to enum */
098        public static ErrorCode valueOf(int value) {
099                ErrorCode retval = _map.get(value);
100                if (retval != null)
101                        return retval;
102                return GeneralError;
103        }
104
105        /** @return the first nonzero error code */
106        public static ErrorCode worstOne(ErrorCode errorCode1, ErrorCode errorCode2) {
107                if (errorCode1.value != 0)
108                        return errorCode1;
109                return errorCode2;
110        }
111
112        /** @return the first nonzero error code */
113        public static ErrorCode worstOne(ErrorCode errorCode1, ErrorCode errorCode2, ErrorCode errorCode3) {
114                if (errorCode1.value != 0)
115                        return errorCode1;
116                if (errorCode2.value != 0)
117                        return errorCode2;
118                return errorCode3;
119        }
120
121        /** @return the first nonzero error code */
122        public static ErrorCode worstOne(ErrorCode errorCode1, ErrorCode errorCode2, ErrorCode errorCode3,
123                        ErrorCode errorCode4) {
124                if (errorCode1.value != 0)
125                        return errorCode1;
126                if (errorCode2.value != 0)
127                        return errorCode2;
128                if (errorCode3.value != 0)
129                        return errorCode3;
130                return errorCode4;
131        }
132};