(self, data)
return dev_name, data_dict
Parse scan response data.
        Note: the data will come in a format like the following:
        [data_length, data_type, data..., data_length, data_type, data...]

        data -- the args['data'] list from _ble_evt_scan_response.

        Returns a name and a dictionary containing the parsed data in pairs of
        field_name': value.
Parse scan response data.
        Note: the data will come in a format like the following:
        [data_length, data_type, data..., data_length, data_type, data...]
Parse scan response data . Note : the data will come in a format like the following : [ data_length data_type data ... data_length data_type data ... ]
def _scan_rsp_data(self, data):
        """
        Parse scan response data.
        Note: the data will come in a format like the following:
        [data_length, data_type, data..., data_length, data_type, data...]

        data -- the args['data'] list from _ble_evt_scan_response.

        Returns a name and a dictionary containing the parsed data in pairs of
        field_name': value.
        """
        # Result stored here
        data_dict = {
            # 'name': value,
        }
        bytes_left_in_field = 0
        field_name = None
        field_value = []
        # Iterate over data bytes to put in field
        dev_name = ""
        for b in data:
            if bytes_left_in_field == 0:
                # New field
                bytes_left_in_field = b
                field_value = []
            else:
                field_value.append(b)
                bytes_left_in_field -= 1
                if bytes_left_in_field == 0:
                    # End of field
                    field_name = (
                        constants.scan_response_data_type[field_value[0]])
                    field_value = field_value[1:]
                    # Field type specific formats
                    if (field_name == 'complete_local_name' or
                            field_name == 'shortened_local_name'):
                        try:
                            dev_name = bytearray(field_value).decode("utf-8")
                        except:
                            log.debug("Failed to decode data as UTF8, "
                                      "returning verbatim")
                        else:
                            data_dict[field_name] = dev_name
                    elif (field_name ==
                          'complete_list_128-bit_service_class_uuids'):
                        if len(field_value) % 16 == 0:  # 16 bytes
                            data_dict[field_name] = []
                            for i in range(0, int(len(field_value) / 16)):
                                service_uuid = (
                                    "0x%s" %
                                    bgapi_address_to_hex(
                                        field_value[i * 16:i * 16 + 16]))
                                data_dict[field_name].append(service_uuid)
                        else:
                            log.warning("Expected a service class UUID of 16\
                                        bytes. Instead received %d bytes",
                                        len(field_value))
                    else:
                        data_dict[field_name] = bytearray(field_value)
        return dev_name, data_dict
def _scan_rsp_data ( self , data ) : # Result stored here data_dict = { # 'name': value, } bytes_left_in_field = 0 field_name = None field_value = [ ] # Iterate over data bytes to put in field dev_name = "" for b in data : if bytes_left_in_field == 0 : # New field bytes_left_in_field = b field_value = [ ] else : field_value . append ( b ) bytes_left_in_field -= 1 if bytes_left_in_field == 0 : # End of field field_name = ( constants . scan_response_data_type [ field_value [ 0 ] ] ) field_value = field_value [ 1 : ] # Field type specific formats if ( field_name == 'complete_local_name' or field_name == 'shortened_local_name' ) : try : dev_name = bytearray ( field_value ) . decode ( "utf-8" ) except : log . debug ( "Failed to decode data as UTF8, " "returning verbatim" ) else : data_dict [ field_name ] = dev_name elif ( field_name == 'complete_list_128-bit_service_class_uuids' ) : if len ( field_value ) % 16 == 0 : # 16 bytes data_dict [ field_name ] = [ ] for i in range ( 0 , int ( len ( field_value ) / 16 ) ) : service_uuid = ( "0x%s" % bgapi_address_to_hex ( field_value [ i * 16 : i * 16 + 16 ] ) ) data_dict [ field_name ] . append ( service_uuid ) else : log . warning ( "Expected a service class UUID of 16\
                                        bytes. Instead received %d bytes" , len ( field_value ) ) else : data_dict [ field_name ] = bytearray ( field_value ) return dev_name , data_dict