def _log(self, action, handle_or_char, value, value_length): if not self._debug: return if action == "Write": data_as_hex = " ".join([ "{:02x}".format(b) for b in [value[i] for i in range_(value_length)] ]) elif action == "Subscribe": data_as_hex = "" else: data_as_hex = " ".join([ "{:02x}".format(ord(b)) for b in self._response_2_string_buffer(value) ]) if isinstance(handle_or_char, (uuid.UUID, string_types)): handle = self.get_handle(handle_or_char) elif isinstance(handle_or_char, int): handle = handle_or_char else: # Assume it is a Pointer to a GattCharacteristic... try: handle = self.get_handle(self.get_uuid(handle_or_char)) except: handle = -1 log.debug("{0:<6s} 0x{1:04x}: {2}".format(action, handle, data_as_hex))
def write_gatt_char_by_uuid(self, characteristic, command, length): """Write the desired data to the MetaWear board using pygatt backend. :param uuid.UUID characteristic: The UUID to the characteristic to write to. :param POINTER(c_ubyte) command: Data to send. :param int length: Number of characters in the command. """ data_to_send = bytearray([command[i] for i in range_(length)]) self.requester.char_write(str(self.get_uuid(characteristic)), data_to_send)
def write_gatt_char_by_uuid(self, characteristic, command, length): """Write the desired data to the MetaWear board using pybluez/gattlib backend. :param uuid.UUID characteristic_uuid: Characteristic UUID to write to. :param str data_to_send: Data to send. """ characteristic_uuid = self.get_uuid(characteristic) handle = self.get_handle(characteristic_uuid) data_to_send = bytes(bytearray([command[i] for i in range_(length)])) if not isinstance(data_to_send, string_types): data_to_send = data_to_send.decode('latin1') self.requester.write_by_handle_async(handle, data_to_send, self._response)