<commit_before>import usb.core

class PIC_USB(object):
    def __init__(self, product_id):
        super(PIC_USB, self).__init__()
        self.SET_STATE = 0
        self.GET_VALS = 1
        self.GET_ROCKET_INFO = 2
        self.DEBUG_UART_BUFFERS = 3
        self.GET_QUAD_INFO = 4

        self.vendor_id = 0x6666
        self.product_id = product_id
        self.dev = usb.core.find(idVendor=self.vendor_id, idProduct=self.product_id)
        if self.dev is None:
            raise ValueError('No USB device found with idVendor=0x{0:04x} and idProduct=0x{1:04x}.'.format(self.vendor_id, self.product_id))
        try:
            self.dev.set_configuration()
        except usb.core.USBError, e:
            print("ERR:\nError connecting to found device.\n" 
                "If permissions issue, try adding this device to /etc/udev/rules.d/usb_prototype_devices.rules. Do so by adding the following line--\n"
                "SUBSYSTEM==\"usb\", ATTRS{{idVendor}}==\"{:04x}\", ATTRS{{idProduct}}==\"{:04x}\", MODE==\"0666\"\n\n".format(self.vendor_id, self.product_id))
            raise(e)

    def close(self):
        self.dev = None

    @staticmethod
    def parse16(ret, start_index):
        return int(ret[start_index])+int(ret[start_index + 1])*256

    @staticmethod
    def parse32(ret, start_index):
        return int(ret[start_index]) + int(ret[start_index + 1]) * 2**8 + int(ret[start_index + 2]) * 2**16 + int(ret[start_index + 3]) * 2**24

    # Handlers
    def set_state(self, state):
        try:
            self.dev.ctrl_transfer(0x40, self.SET_STATE, int(state))
        except usb.core.USBError:
            print "Could not send SET_STATE vendor request."

    def get_vals(self):<commit_msg>Added generic number parsing function to rocket control's vendor request Python library.<commit_after>import usb.core

class PIC_USB(object):
    def __init__(self, product_id):
        super(PIC_USB, self).__init__()
        self.SET_STATE = 0
        self.GET_VALS = 1
        self.GET_ROCKET_INFO = 2
        self.DEBUG_UART_BUFFERS = 3
        self.GET_QUAD_INFO = 4

        self.vendor_id = 0x6666
        self.product_id = product_id
        self.dev = usb.core.find(idVendor=self.vendor_id, idProduct=self.product_id)
        if self.dev is None:
            raise ValueError('No USB device found with idVendor=0x{0:04x} and idProduct=0x{1:04x}.'.format(self.vendor_id, self.product_id))
        try:
            self.dev.set_configuration()
        except usb.core.USBError, e:
            print("ERR:\nError connecting to found device.\n" 
                "If permissions issue, try adding this device to /etc/udev/rules.d/usb_prototype_devices.rules. Do so by adding the following line--\n"
                "SUBSYSTEM==\"usb\", ATTRS{{idVendor}}==\"{:04x}\", ATTRS{{idProduct}}==\"{:04x}\", MODE==\"0666\"\n\n".format(self.vendor_id, self.product_id))
            raise(e)

    def close(self):
        self.dev = None

    @staticmethod
    def parse16(ret, start_index):
        return int(ret[start_index])+int(ret[start_index + 1])*256

    @staticmethod
    def parse32(ret, start_index):
        return int(ret[start_index]) + int(ret[start_index + 1]) * 2**8 + int(ret[start_index + 2]) * 2**16 + int(ret[start_index + 3]) * 2**24

    @staticmethod
    def parse_gen(ret, start_index, end_index):
        running_sum = 0 
        selection = ret[start_index:end_index + 1]
        for i, val in enumerate(selection):
            running_sum += int(val) * (2 ** (8* i))
        return running_sum

    # Handlers
    def set_state(self, state):
        try:
            self.dev.ctrl_transfer(0x40, self.SET_STATE, int(state))
        except usb.core.USBError:
            print "Could not send SET_STATE vendor request."

    def get_vals(self):
{'fraction_non_alphanumeric': 0.12780565091101134, 'fraction_numerical': 0.026406126221283337, 'mean_word_length': 2.617956064947469, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2201891', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1251, 'n_words': 266}