"HEX -> STRING maps + util method for values fetched by SDR "


def map_code_to_value(type_code, type_map):
    "Returns string or 'unsupported' based on given type map and code"
    try:
        return type_map[type_code]
    except KeyError:
        return 'unsupported'


SENSOR_TYPE_MAP = {
    0x01: "temperature",
    0x02: "voltage",
    0x03: "current",
    0x04: "fan",
    0x05: "chassis_intrusion",
    0x06: "security_violation_attempt",
    0x07: "processor",
    0x08: "power_supply",
    0x09: "power_unit",
    0xA: "cooling_device",
    0xB: "other_unit_based_sensor",
    0xC: "memory",
    0xD: "drive_slot",
    0xE: "post_memory",
    0xF: "firmware_progress",
    0x10: "evt_logging_disable",
    0x11: "watchdog_1",
    0x12: "sys_event",
    0x13: "crit_interrupt",
    0x14: "button",
    0x15: "module_board",
    0x16: "microcontroller_coprocessor",
    0x17: "add_in_card",
    0x18: "chassis",
    0x19: "chipset",
    0x1A: "other_fru",
    0x1B: "cable_interconnect",
    0x1C: "terminator",
    0x1D: "system_boot",
    0x1E: "boot_error",
    0x1F: "base_os_boot",
    0x20: "os_stop",
    0x21: "slot_connector",
    0x22: "acpi_pwr_state",
    0x23: "watchdog_2",
    0x24: "platform_alert",
    0x25: "entity_presence",
    0x26: "monitor_asic",
    0x27: "lan",
    0x28: "management_sys_health",
    0x29: "battery",
    0x2A: "session_audit",
    0x2B: "ver_change",
    0x2C: "fru_state"
}
RATE_UNIT_MAP = {
    0b000: "none",
    0b001: "per uS",
    0b010: "per ms",
    0b011: "per s",
    0b100: "per min",
    0b101: "per hr",
    0b110: "per day"
}
UNIT_MAP = {
    0: 'unspecified',
    1: 'degrees C',
    2: 'degrees F',
    3: 'degrees K',
    4: 'Volts',
    5: 'Amperes',
    6: 'Watts',
    7: 'Joules',
    8: 'Coulombs',
    9: 'VA',
    10: 'Nits',
    11: 'lumen',
    12: 'lux',
    13: 'Candela',
    14: 'kPa',
    15: 'PSI',
    16: 'Newton',
    17: 'CFM',
    18: 'RPM',
    19: 'Hz',
    20: 'microsecond',
    21: 'milisecond',
    22: 'second',
    23: 'minute',
    24: 'hour',
    25: 'day',
    26: 'week',
    27: 'mil',
    28: 'inches',
    29: 'feet',
    30: 'cu in',
    31: 'cu feet',
    32: 'mm',
    33: 'cm',
    34: 'm',
    35: 'cu cm',
    36: 'cu m',
    37: 'liters',
    38: 'fluid ounce',
    39: 'radians',
    40: 'steradians',
    41: 'revolutions',
    42: 'cycles',
    43: 'gravities',
    44: 'ounce',
    45: 'pound',
    46: 'ft-lb',
    47: 'oz-in',
    48: 'gauss',
    49: 'gilberts',
    50: 'henry',
    51: 'milihenry',
    52: 'farad',
    53: 'microfarad',
    54: 'ohms',
    55: 'siemens',
    56: 'mole',
    57: 'becquerel',
    58: 'PPM',
    59: 'reserved',
    60: 'Decibels',
    61: 'DbA',
    62: 'DbC',
    63: 'gray',
    64: 'sievert',
    65: 'color temp deg K',
    66: 'bit',
    67: 'kilobit',
    68: 'megabit',
    69: 'gigabit',
    70: 'byte',
    71: 'kilobyte',
    72: 'megabyte',
    73: 'gigabyte',
    74: 'word',
    75: 'dword',
    76: 'qword',
    77: 'line',
    78: 'hit',
    79: 'miss',
    80: 'retry',
    81: 'reset',
    82: 'overrun',
    83: 'underrun',
    84: 'collision',
    85: 'packets',
    86: 'messages',
    87: 'characters',
    88: 'error',
    89: 'correctable error',
    90: 'ucorrectable error',
    91: 'fatal error',
    92: 'grams'
}
