from enum import Enum


class MessageType(Enum):
    COMMAND = 0x00
    RESPONSE = 0x01
    NOTIFICATION = 0x02
    RESERVED = 0x03


class OperationResult(Enum):
    SUCCESS = 0
    ERROR = 1


class MessageCode(Enum):
    SET_READER_POWER_CONTROL = 0x01
    GET_READER_INFORMATION = 0x03
    GET_REGION = 0x06
    SET_REGION = 0x07
    SET_SYSTEM_RESET = 0x08
    # GET_TYPE_SELECT_PARAMETERS = 0x0B
    # SET_TYPE_SELECT_PARAMETERS = 0x0C
    GET_SELECTION_ENABLES = 0x8E
    SET_SELECTION_ENABLES = 0x8F
    GET_SELECTION_FILTER = 0xAE
    SET_SELECTION_FILTER = 0xAF
    GET_TYPE_QUERY_RELATED_PARAMETERS = 0x0D
    SET_TYPE_QUERY_RELATED_PARAMETERS = 0x0E
    GET_CURRENT_RF_CHANNEL = 0x11
    SET_CURRENT_RF_CHANNEL = 0x12
    GET_FH_LBT_PARAMETERS = 0x13
    SET_FH_LBT_PARAMETERS = 0x14
    GET_TX_POWER = 0x15
    SET_TX_POWER = 0x16
    RF_CW_SIGNAL_CONTROL = 0x17
    READ_TPE_CUIII = 0x22
    READ_TPE_CUIII_RSSI = 0x23
    READ_TPE_CUIII_TID = 0x25
    READ_TPE_C_TAG_DATA = 0x29
    READ_TPE_C_TAG_LONG_DATA = 0x2A
    RCP_CMD_GET_TX_PWR_RAW = 0x2C
    RCP_CMD_SET_TX_PWR_RAW = 0x2D
    GET_SESSION = 0x2E
    SET_SESSION = 0x2F
    GET_FREQUENCY_HOPPING_TABLE = 0x30
    SET_FREQUENCY_HOPPING_TABLE = 0x31
    GET_MODULATION = 0x32
    SET_MODULATION = 0x33
    GET_ANTI_COLLISION_MODE = 0x34
    SET_ANTI_COLLISION_MODE = 0x35
    START_AUTO_READ2 = 0x36
    STOP_AUTO_READ2 = 0x37
    START_AUTO_READ_RSSI = 0x38
    STOP_AUTO_READ_RSSI = 0x39
    WRITE_TYPE_C_TAG_DATA = 0x46
    BLOCK_WRITE_TYPE_C_TAG_DATA = 0x47
    BLOCK_ERASE_TYPE_C_TAG_DATA = 0x48
    BLOCK_PERMALOCK_TYPE_C_TAG = 0x83
    KILL_RECOM_TYPE_C_TAG = 0x65
    LOCK_TYPE_C_TAG = 0x82
    ANTENNA_CHECK = 0xAC
    GET_TEMPERATURE = 0xB7
    GET_RSSI = 0xC5
    SCAN_RSSI = 0xC6
    GET_DTC_RESULT = 0xCA
    UPDATE_REGISTRY = 0xD2
    GET_REGISTRY_ITEM = 0xD4
    COMMAND_FAILURE = 0xFF
    SET_OPTIMUM_FREQUENCY_HOPPING_TABLE = 0xE4
    GET_FREQUENCY_HOPPING_MODE = 0xE5
    SET_FREQUENCY_HOPPING_MODE = 0xE6
    GET_TX_LEAKAGE_RSSI_LEVEL_SMART_HOPPING_MODE = 0xE7
    SET_TX_LEAKAGE_RSSI_LEVEL_SMART_HOPPING_MODE = 0xE8
    SMART_READ_FAST_LEAKAGE_CAL = 0xEC
    REQUEST_FAST_LEAKAGE_CAL = 0xED
    ERROR = 0xFF


class ErrorCode(Enum):
    # EPC G2v2 Error Message
    OTHER_ERROR = 0x00
    NOT_SUPPORTED = 0x01
    INSUFFICIENT_PRIVILEGES = 0x02
    MEMORY_OVERRUN = 0x03
    MEMORY_LOCKED = 0x04
    CRYPTO_SUITE_ERROR = 0x05
    COMMAND_NOT_ENCAPSULATED = 0x06
    RESPONSE_BUFFER_OVERFLOW = 0x07
    SECURITY_TIMEOUT = 0x08
    INSUFFICIENT_POWER = 0x0B
    NON_SPECIFIC_ERROR = 0x0F
    # Vendor Specific Error
    SENSOR_SCHEDULING_CONFIGURATION = 0x11
    TAG_BUSY = 0x12
    MEASUREMENT_TYPE_NOT_SUPPORTED = 0x13
    # Protocol Error
    NO_TAG_DETECTED = 0x80
    HANDLE_ACQUISITION_FAILURE = 0x81
    ACCESS_PASSWORD_FAILURE = 0x82
    KILL_PASSWORD_FAILURE = 0x83
    # Modem Error
    CRC_ERROR = 0x90
    RX_TIMEOUT = 0x91
    # Registry
    REGISTRY_UPDATE_FAILURE = 0xA0
    REGISTRY_ERASE_FAILURE = 0xA1
    REGISTRY_WRITE_FAILURE = 0xA2
    REGISTRY_NOT_EXIST = 0xA3
    # Peripheral
    UART_FAILURE = 0xB0
    SPI_FAILURE = 0xB1
    I2C_FAILURE = 0xB2
    GPIO_FAILURE = 0xB3
    # Custom error
    NOT_SUPPORTED_COMMAND = 0xE0
    UNDEFINED_COMMAND = 0xE1
    INVALID_PARAMETER = 0xE2
    TOO_HIGH_PARAMETER = 0xE3
    TOO_LOW_PARAMETER = 0xE4
    FAILURE_AUTOMATIC_READ_OPERATION = 0xE5
    NOT_AUTOMATIC_READ_MODE = 0xE6
    FAILURE_TO_GET_LAST_RESPONSE = 0xE7
    FAILURE_TO_CONTROL_TEST = 0xE8
    FAILURE_TO_RESET_READER = 0xE9
    RFIDBLOCK_CONTROL_FAILURE = 0xEA
    AUTOMATIC_READ_IN_OPERATION = 0xEB
    UNDEFINED_OTHER_ERROR = 0xF0
    FAILURE_TO_VERIFY_WRITE_OPERATION = 0xF1
    ABNORMAL_ANTENNA = 0xFC
    NONE_ERROR = 0xFF


class Region(Enum):
    Korea = 0x11
    US_Wide = 0x21
    US_Narrow = 0x22
    Europe = 0x31
    Japan = 0x41
    China = 0x52
    Brazil = 0x61


class ReaderInfoType(Enum):
    MODEL = 0x00
    FW_VERSION = 0x01
    MANUFACTURER = 0x02
    DETAIL = 0xB0


class MessageConstants(Enum):
    PREAMBLE = 0xBB
    ENDMARK = 0x7E


class ParamModulation(Enum):
    FM0 = 0
    MILLER_2 = 1
    MILLER_4 = 2
    MILLER_8 = 3


class ParamDR(Enum):
    DR_8 = 0
    DR_64_DIV_3 = 1


class ParamSel(Enum):
    ALL_0 = 0
    ALL_1 = 1
    NSL = 2
    SL = 3


class ParamSession(Enum):
    S0 = 0
    S1 = 1
    S2 = 2
    S3 = 3


class ParamTarget(Enum):
    A = 0
    B = 1


class ParamSelectTarget(Enum):
    S0 = 0
    S1 = 1
    S2 = 2
    S3 = 3
    SL = 4


class ParamSelectAction(Enum):
    MATCH_A_NOMATCH_B = 0
    MATCH_A_NOMATCH_NOCHANGE = 1
    MATCH_NOCHANGE_NOMATCH_B = 2
    MATCH_TOGGLE_NOMATCH_NOCHANGE = 3
    MATCH_B_NOMATCH_A = 4
    MATCH_B_NOMATCH_NOCHANGE = 5
    MATCH_NOCHANGE_NOMATCH_A = 6
    MATCH_NOCHANGE_NOMATCH_TOGGLE = 7


class AntiCollisionMode(Enum):
    MULTI_TAG = 3
    SINGLE_TAG = 32
    UNIQUE_RECOGNITION = 16
    MANUAL = 0


class Registry(Enum):
    VERSION = 0
    FW = 1
    BAND = 2
    ANTI_COLLISION = 3
    MODULATION = 4
    QUERY = 5
    PARTNUMBER = 6
    DEV = 7
    FW_VERSION = 8
    LEAK_MODE = 9
    SESSION = 10
    SERIAL = 11
    BEEP = 12
    GPADC = 13
    Q = 14
    ANTENNA = 15
    FH_MODE = 16
    MODULATION_RAW = 17
    SUPPORT_REGION = 18
    GAIN = 19
    REPORT = 20
    TX_KR_HIGH_GAIN = 21
    TX_KR_LOW_GAIN = 22
    FH_LBT_KR = 23
    FH_TABLE_KR = 24
    POWER_TABLE_KR_HIGH = 25
    POWER_TABLE_KR_LOW = 26
    FB_PARAMTER_KR_HIGH = 27
    FB_PARAMTER_KR_LOW = 28
    RSSI_OFFSET_KR = 29
    CH_OFFSET_KR = 30
    TX_US_HIGH = 31
    TX_US_LOW = 32
    FH_LBT_US = 33
    FH_TABLE_US = 34
    POWER_TABLE_US_HIGH = 35
    POWER_TABLE_US_LOW = 36
    FB_PARAMTER_US_HIGH = 37
    FB_PARAMTER_US_LOW = 38
    RSSI_OFFSET_US = 39
    CH_OFFSET_US = 40
    TX_JP_HIGH = 41
    TX_JP_LOW = 42
    FH_LBT_JP = 43
    FH_TABLE_JP = 44
    POWER_TABLE_JP_HIGH = 45
    POWER_TABLE_JP_LOW = 46
    FB_PARAMTER_JP_HIGH = 47
    FB_PARAMTER_JP_LOW = 48
    RSSI_OFFSET_JP = 49
    CH_OFFSET_JP = 50
    TX_EU_HIGH = 51
    TX_EU_LOW = 52
    FH_LBT_EU = 53
    FH_TABLE_EU = 54
    POWER_TABLE_EU_HIGH = 55
    POWER_TABLE_EU_LOW = 56
    FB_PARAMTER_EU_HIGH = 57
    FB_PARAMTER_EU_LOW = 58
    RSSI_OFFSET_EU = 59
    CH_OFFSET_EU = 60
    FH_TABLE_US2 = 61
    FH_TABLE_CH = 62
    TX_BR_HIGH = 63
    TX_BR_LOW = 64
    FH_LBT_BR = 65
    FH_TABLE_BR = 66
    RSSI_OFFSET_BR = 67
    CH_OFFSET_BR = 68
    TX_CH_HIGH = 69
    TX_CH_LOW = 70
    ANT_SEQUENCE = 71
    FREQUENCY_TABLE = 72


class TagType(Enum):
    TYPE_B = 0x01
    TYPE_C = 0x02


class ParamMemory(Enum):
    RESERVED = 0
    EPC = 1
    TID = 2
    USER = 3


class ParamFhLbtMode(Enum):
    FH_ONLY = 0x0100
    FH_WITH_LBT = 0x0201
    LBT_ONLY = 0x0001
    LBT_WITH_FH = 0x0102
