def decode_class_of_device(cod):
    mdc, sdc = cod >> 8 & 0x1f, cod >> 2 & 0x3f
    if mdc == 0:
        mdc = "Miscellaneous"
        sdc = "{0:06b}".format(sdc)
    elif mdc == 1:
        mdc = "Computer"
        minor_device_class = (
            "Uncategorized",
            "Desktop workstation",
            "Server-class computer",
            "Laptop",
            "Handheld PC/PDA (clam shell)",
            "Palm sized PC/PDA",
            "Wearable computer (Watch sized)")
        try: sdc = minor_device_class[sdc]
        except IndexError: sdc = "{0:06b}".format(sdc)
    elif mdc == 2:
        mdc = "Phone"
        minor_device_class = (
            "Uncategorized",
            "Cellular",
            "Cordless",
            "Smart phone",
            "Wired modem or voice gateway",
            "Common ISDN Access")
        try: sdc = minor_device_class[sdc]
        except IndexError: sdc = "{0:06b}".format(sdc)
    elif mdc == 3:
        mdc = "Access Point"
        minor_device_class = (
            "fully available",
            "1 - 17% utilized",
            "17 - 33% utilized",
            "33 - 50% utilized",
            "50 - 67% utilized",
            "67 - 83% utilized",
            "83 - 99% utilized",
            "no service available")
        try: sdc = minor_device_class[sdc >> 3]
        except IndexError: sdc = "{0:06b}".format(sdc)
    elif mdc == 4:
        mdc = "Audio/Video"
        minor_device_class = (
            "Uncategorized",
            "Wearable Headset Device",
            "Hands-free Device",
            "Reserved",
            "Microphone",
            "Loudspeaker",
            "Headphones",
            "Portable Audio",
            "Car audio",
            "Set-top box",
            "HiFi Audio Device",
            "VCR",
            "Video Camera",
            "Camcorder",
            "Video Monitor",
            "Video Display and Loudspeaker",
            "Video Conferencing",
            "Reserved",
            "Gaming/Toy")
        try: sdc = minor_device_class[sdc]
        except IndexError: sdc = "{0:06b}".format(sdc)
    elif mdc == 5:
        mdc = "Peripheral"
        minor_device_class = (
            "uncategorized",
            "joystick",
            "gamepad",
            "remote control",
            "sensing device",
            "digitizer tablet",
            "card reader",
            "digital pen",
            "handheld scanner",
            "handheld pointer")
        kbd_mouse = ("", " keyboard", " mouse", " keyboard/mouse")[sdc >> 4]
        try: sdc = minor_device_class[sdc & 0x0f]
        except __HOLE__: sdc = "{0:06b}".format(sdc)
        sdc = sdc + kbd_mouse
    elif mdc == 6:
        mdc = "Imaging"
        minor_device_class = {
            0b0001: "display",
            0b0010: "camera",
            0b0100: "scanner",
            0b1000: "printer"}
        sdc = ', '.join([minor_device_class[mask]
                         for mask in minor_device_class
                         if sdc >> 2 & mask])
    elif mdc == 7:
        mdc = "Wearable"
        minor_device_class = (
            "Wrist Watch",
            "Pager",
            "Jacket",
            "Helmet",
            "Glasses")
        try: sdc = minor_device_class[sdc & 0x0f]
        except IndexError: sdc = "{0:06b}".format(sdc)
    elif mdc == 8:
        mdc = "Toy"
        minor_device_class = (
            "Robot",
            "Vehicle",
            "Doll / Action Figure",
            "Controller",
            "Game")
        try: sdc = minor_device_class[sdc & 0x0f]
        except IndexError: sdc = "{0:06b}".format(sdc)
    elif mdc == 9:
        mdc = "Health"
        minor_device_class = (
            "Undefined",
            "Blood Pressure Monitor",
            "Thermometer",
            "Weighing Scale",
            "Glucose Meter",
            "Pulse Oximeter",
            "Heart/Pulse Rate Monitor",
            "Health Data Display",
            "Step Counter",
            "Body Composition Analyzer",
            "Peak Flow Monitor",
            "Medication Monitor",
            "Knee Prosthesis",
            "Ankle Prosthesis",
            "Generic Health Manager",
            "Personal Mobility Device")
        try: sdc = minor_device_class[sdc & 0x0f]
        except IndexError: sdc = "{0:06b}".format(sdc)
    elif mdc == 31:
        mdc = "Uncategorized"
        sdc = "{0:06b}".format(sdc)
    else:
        mdc = "{0:05b}".format(mdc)
        sdc = "{0:06b}".format(sdc)
        
    return "{0} ({1})".format(mdc, sdc)
dataset/ETHPy150Open javgh/greenaddress-pos-tools/nfc/ndef/bt_record.py/decode_class_of_device