def ble_get_local_address(self): """Function defined in BleInterface.""" addr = Melody._convert_melody_address_to_standard( self._get_config('LOCAL_ADDR')[1]) addr_type = True if self._get_config( 'BLE_CONFIG')[3] == 'ON' else False return BleInterface.Bdaddr(addr, addr_type)
def ble_get_local_address(self): """Function defined in BleInterface. """ command = '+SRBLEADDR' if self._query(command) is EDD_RESULT_SUCCESS: regex = r"\+SRBLEADDR: \"([\w|:]{17})\",(\d)" response = self._serial.serial_search_regex(regex) return BleInterface.Bdaddr(response[0], int(response[1])) return None
def ble_create_session(self, bdaddr): """Function defined in BleInterface. """ command = '+SRBLECFG' args = ['"' + bdaddr.addr + '"'] if self._write(command, args) is EDD_RESULT_SUCCESS: regex = r"\+SRBLECFG: (\d+),([0|1]),\"([\w|:]{17})\"(,(\d),(\d+))?" response = self._serial.serial_search_regex(regex) return BleInterface.BleSession( int(response[0]), BleInterface.Bdaddr(response[2], bdaddr.addr_type)) return None
def ble_get_local_address(self): """Function defined in BleInterface. """ if not self._enable_bluetooth(): return None command = '+SRBTADDR' if self._query(command) is EUL_RESULT_SUCCESS: regex = r"\+SRBTADDR: \"([\w|:]{17})\"" response = self._serial.serial_search_regex(regex) return BleInterface.Bdaddr( Euler._convert_euler_address_to_standard(response[0]), BleInterface.LE_BDADDR_TYPE_PUBLIC) return None
def test_ble_session_02(dut): """Verify DUT can list all the BLE sessions. """ # GIVEN a = dut.ble_create_session( BleInterface.Bdaddr('20:FA:BB:00:00:AA', BleInterface.LE_BDADDR_TYPE_PUBLIC)) assert a is not None b = dut.ble_create_session( BleInterface.Bdaddr('11:22:33:44:55:66', BleInterface.LE_BDADDR_TYPE_PRIVATE)) assert b is not None c = dut.ble_create_session( BleInterface.Bdaddr('77:88:99:AA:BB:CC', BleInterface.LE_BDADDR_TYPE_PRIVATE)) assert c is not None # WHEN list = dut.ble_get_all_sessions() # THEN assert a in list assert b in list assert c in list
def test_ble_session_01(dut): """Verify DUT can create up to 16 BLE sessions. """ # GIVEN 'N/A' # WHEN for i in range(0, 15): addr = '20:FA:BB:00:00:{:02X}'.format(i) session = dut.ble_create_session( BleInterface.Bdaddr(addr, BleInterface.LE_BDADDR_TYPE_PUBLIC)) assert session.session_id == (i + 1) assert session.bdaddr.addr == addr # THEN 'N/A'
def ble_get_all_sessions(self): """Function defined in BleInterface. """ command = '+SRBLECFG' if self._query(command) is EDD_RESULT_SUCCESS: regex = r"\+SRBLECFG: (\d+),([0|1]),\"([\w|:]{17})\"(,(\d),(\d+))?" responses = self._serial.serial_search_regex_all(regex) sessions = [] for resp in responses: sessions.append( BleInterface.BleSession( int(resp[0]), BleInterface.Bdaddr( resp[2], BleInterface.LE_BDADDR_TYPE_UNKNOWN))) return sessions return None
def ble_create_session(self, bdaddr): """Function defined in BleInterface. """ if not self._enable_bluetooth(): return None command = '+SRBLECFG' args = ['"' + bdaddr.addr + '"'] if self._write(command, args) is EUL_RESULT_SUCCESS: regex = r"\+SRBLECFG: (\d+),([0|1]),\"(%s)\",(\d+)" % ( Euler._convert_standard_address_to_euler(bdaddr.addr)) response = self._serial.serial_search_regex(regex) return BleInterface.BleSession( int(response[0]), BleInterface.Bdaddr( Euler._convert_euler_address_to_standard(response[2]), bdaddr.addr_type)) return None
def ble_get_all_sessions(self): """Function defined in BleInterface. """ if not self._enable_bluetooth(): return None command = '+SRBLECFG' if self._query(command) is EUL_RESULT_SUCCESS: regex = r"\+SRBLECFG: (\d+),([0|1]),\"([\w|:]{17})\",(\d+)" sessions = [] responses = self._serial.serial_search_regex_all(regex) for resp in responses: sessions.append( BleInterface.BleSession( int(resp[0]), BleInterface.Bdaddr( Euler._convert_euler_address_to_standard(resp[2]), BleInterface.LE_BDADDR_TYPE_UNKNOWN))) return sessions return None
def ble_wait_for_connection(self, timeout=10): """Function defined in GapInterface.""" regex = r"OPEN_OK (\d4) BLE (\w{12})" + BC127_EOL response = self._serial.serial_search_regex(regex, timeout) if response: link_id = int(response[0], 16) bdaddr = BleInterface.Bdaddr( self._convert_melody_address_to_standard(response[1]), BleInterface.LE_BDADDR_TYPE_UNKNOWN) session_id = self._ble_sessions_get_session_from_bdaddr(bdaddr) if session_id: # virtual BLE session already exists self._ble_sessions_set_session_link_id(session_id, link_id) else: # need to create a new virtual BLE session new_session = self.ble_create_session(bdaddr) self._ble_sessions_set_session_link_id(new_session.session_id, link_id) return True return False