Ejemplo n.º 1
0
 def on_driver_event(self, nrf_driver, event):
     if isinstance(event, nrf_events.GapEvtConnected):
         conn_params = peer.ConnectionParameters(
             event.conn_params.min_conn_interval_ms,
             event.conn_params.max_conn_interval_ms,
             event.conn_params.conn_sup_timeout_ms,
             event.conn_params.slave_latency)
         if event.role == nrf_events.BLEGapRoles.periph:
             self.client.peer_connected(event.conn_handle, event.peer_addr,
                                        conn_params)
         else:
             if self.connecting_peripheral.peer_address != event.peer_addr:
                 logger.warning(
                     "Mismatching address between connecting peripheral and peer event: "
                     "{} vs {}".format(self.connecting_peripheral.address,
                                       event.peer_addr))
             else:
                 self.connected_peripherals[
                     self.connecting_peripheral.
                     peer_address] = self.connecting_peripheral
                 self.connecting_peripheral.peer_connected(
                     event.conn_handle, event.peer_addr, conn_params)
             self.connecting_peripheral = None
     if isinstance(event, nrf_events.GapEvtTimeout):
         if event.src == nrf_events.BLEGapTimeoutSrc.conn:
             self.connecting_peripheral = None
     if isinstance(event, nrf_events.GapEvtDisconnected):
         for peer_address, p in self.connected_peripherals.items():
             if p.conn_handle == event.conn_handle:
                 del self.connected_peripherals[peer_address]
                 return
Ejemplo n.º 2
0
    def set_default_peripheral_connection_params(self, min_interval_ms, max_interval_ms, timeout_ms, slave_latency=0):
        """
        Sets the default connection parameters for all subsequent connection attempts to peripherals.
        Refer to the Bluetooth specifications for the valid ranges

        :param min_interval_ms: The minimum desired connection interval, in milliseconds
        :param max_interval_ms: The maximum desired connection interval, in milliseconds
        :param timeout_ms: The connection timeout period, in milliseconds
        :param slave_latency: The connection slave latency
        """
        self._default_conn_params = peer.ConnectionParameters(min_interval_ms, max_interval_ms,
                                                              timeout_ms, slave_latency)