def setUpClass(cls) -> None: super(TestGattWrites, cls).setUpClass() cls.periph = cls.dev1 cls.central = cls.dev2 cls.periph.client.preferred_mtu_size = cls.periph.max_mtu_size cls.write_size = cls.periph.client.preferred_mtu_size - 3 cls.service_uuid = Uuid128("00112233-4455-6677-8899-aabbccddeeff") cls.write_char_uuid = cls.service_uuid.new_uuid_from_base(0x0000) cls.write_no_resp_char_uuid = cls.service_uuid.new_uuid_from_base( 0x0001) cls._setup_database() cls._setup_connection() # Up minimum log level to increase throughput (less writing to console) cls.prev_log_level = logging.root.level logging.root.setLevel("INFO")
def nrf_uuid_to_uuid(self, nrf_uuid): """ :type nrf_uuid: BLEUUID :rtype: Uuid """ if nrf_uuid.base.type == 0: raise ValueError("UUID Not registered: {}".format(nrf_uuid)) if nrf_uuid.base.type == nrf_types.BLEUUIDBase.BLE_UUID_TYPE_BLE: return Uuid16(nrf_uuid.get_value()) base = None for uuid_base in self.registered_vs_uuids: if nrf_uuid.base.type == uuid_base.type: base = uuid_base if base is None: raise ValueError("Unable to find registered 128-bit uuid: {}".format(nrf_uuid)) return Uuid128.combine_with_base(nrf_uuid.value, base.base)
from blatann.gatt import gatts from blatann.uuid import Uuid128 PERIPHERAL_NAME = "Periph Test" # Miscellaneous service, used for testing MATH_SERVICE_UUID = Uuid128("deadbeef-0011-2345-6679-ab12ccd4f550") # Hex conversion characteristic. A central writes a byte sequence to this characteristic # and the peripheral will convert it to its hex representation. e.g. "0123" -> "30313233" HEX_CONVERT_CHAR_UUID = MATH_SERVICE_UUID.new_uuid_from_base(0xbeaa) # Counting characteristic. The peripheral will periodically send out a notification on this characteristic # With a monotonically-increasing, 4-byte little-endian number COUNTING_CHAR_UUID = MATH_SERVICE_UUID.new_uuid_from_base("1234") # Properties for the hex conversion and counting characteristics HEX_CONVERT_CHAR_PROPERTIES = gatts.GattsCharacteristicProperties( read=True, notify=True, indicate=True, write=True, max_length=128, variable_length=True) COUNTING_CHAR_PROPERTIES = gatts.GattsCharacteristicProperties( read=False, notify=True, max_length=4, variable_length=False) # Time service, report's the current time. Also demonstrating another wait to create a UUID _TIME_SERVICE_BASE_UUID = "beef0000-0123-4567-89ab-cdef01234567" TIME_SERVICE_UUID = Uuid128.combine_with_base("dead", _TIME_SERVICE_BASE_UUID)
from blatann.gatt import gatts from blatann.uuid import Uuid128 PERIPHERAL_NAME = "Periph Test" # Miscellaneous service, used for testing MATH_SERVICE_UUID = Uuid128("deadbeef-0011-2345-6679-ab12ccd4f550") # Hex conversion characteristic. A central writes a byte sequence to this characteristic # and the peripheral will convert it to its hex representation. e.g. "0123" -> "30313233" HEX_CONVERT_CHAR_UUID = MATH_SERVICE_UUID.new_uuid_from_base(0xbeaa) # Counting characteristic. The peripheral will periodically send out a notification on this characteristic # With a monotonically-increasing, 4-byte little-endian number COUNTING_CHAR_UUID = MATH_SERVICE_UUID.new_uuid_from_base("1234") # Properties for the hex conversion and counting characteristics _HEX_CONVERT_USER_DESC = gatts.GattsUserDescriptionProperties("Hex Converter") HEX_CONVERT_CHAR_PROPERTIES = gatts.GattsCharacteristicProperties( read=True, notify=True, indicate=True, write=True, max_length=128, variable_length=True, user_description=_HEX_CONVERT_USER_DESC) _COUNTING_CHAR_USER_DESC = gatts.GattsUserDescriptionProperties("Counter") COUNTING_CHAR_PROPERTIES = gatts.GattsCharacteristicProperties( read=False, notify=True,
from blatann.uuid import Uuid128 NORDIC_UART_SERVICE_UUID = Uuid128("6E400001-B5A3-F393-E0A9-E50E24DCCA9E") # TX and RX characteristics are from the perspective of the client. The server will receive on TX and transmit on RX NORDIC_UART_TX_CHARACTERISTIC_UUID = NORDIC_UART_SERVICE_UUID.new_uuid_from_base( 0x0002) NORDIC_UART_RX_CHARACTERISTIC_UUID = NORDIC_UART_SERVICE_UUID.new_uuid_from_base( 0x0003) # Slight deviation from Nordic's implementation so the client can read the server's characteristic size NORDIC_UART_FEATURE_CHARACTERISTIC_UUID = NORDIC_UART_SERVICE_UUID.new_uuid_from_base( 0x0004)