Esempio n. 1
0
def test_volume_data():

    from random import choice, randint
    import string

    no_of_transmissions = randint(100, 200)
    test_data = ''
    received = Event()

    def data_received_server(data):
        assert data == test_data
        bts.send(test_data)

    def data_received_client(data):
        assert data == test_data
        received.set()

    bts = BluetoothServer(data_received_server, device = "hci0")
    btc = BluetoothClient(bta0.address, data_received_client, device = "hci1")

    for test_no in range(no_of_transmissions):
        test_data = ''.join(choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(randint(30,100)))
        print(test_data)
        btc.send(test_data)
        assert received.wait(1)
        received.clear()
        
    btc.disconnect()
    bts.stop()
Esempio n. 2
0
def test_client_connect_disconnect():

    client_connected = Event()
    client_disconnected = Event()

    def when_client_connects():
        client_connected.set()

    def when_client_disconnects():
        client_disconnected.set()

    bts = BluetoothServer(None)
    btc = BluetoothClient(bta0.address, None, device = "hci1", auto_connect = False)
    bts.when_client_connects = when_client_connects
    bts.when_client_disconnects = when_client_disconnects

    btc.connect()
    assert btc.connected
    assert bts.client_address == btc.client_address
    assert client_connected.wait(1)
    
    btc.disconnect()
    assert not btc.connected
    assert client_disconnected.wait(1)

    bts.stop()
Esempio n. 3
0
def test_client_alt_values():
    def data_received(data):
        pass

    bts = BluetoothServer(None, port=2, encoding=None)
    btc = BluetoothClient(bta0.address,
                          data_received,
                          device="hci1",
                          auto_connect=False,
                          port=2,
                          encoding=None)

    assert btc.data_received_callback == data_received
    assert btc.device == "hci1"
    assert btc.client_address == bta1.address
    assert not btc.connected
    assert btc.port == 2
    assert btc.encoding == None

    btc.connect()
    assert btc.connected

    btc.disconnect()
    assert not btc.connected

    bts.stop()
Esempio n. 4
0
def test_client_default_values():
    def data_received(data):
        pass

    bts = BluetoothServer(data_received, device = "hci1")
    btc = BluetoothClient(bta1.address, data_received)
    
    assert btc.data_received_callback == data_received
    assert btc.device == "hci0"
    assert btc.server == bta1.address
    assert btc.client_address == bta0.address
    assert btc.connected
    assert btc.port == 1
    assert btc.encoding == "utf-8"

    btc.disconnect()
    bts.stop()
Esempio n. 5
0
def sendIP():
    """
    Repeatedly sends the string containing IP address to target. 
    Requires the MAC address of the target to be hardcoded.
    Receives back IP address from target and saves it for UDP 
    connection
    Blocks until we connect with base station 
    """
    global flag
    flag = True
    c = BluetoothClient('B8:27:EB:2A:46:91',
                        data_received,
                        power_up_device=True)
    while flag:
        c.send(client_IP)
        time.sleep(1)
    c.disconnect()
Esempio n. 6
0
def test_send_receive():

    data_received_at_server = Event()
    data_received_at_client = Event()
    
    def data_received_server(data):
        assert data == "hiserver"
        data_received_at_server.set()

    def data_received_client(data):
        assert data == "hiclient"
        data_received_at_client.set()

    bts = BluetoothServer(data_received_server, device = "hci0")
    btc = BluetoothClient(bta0.address, data_received_client, device = "hci1")

    btc.send("hiserver")
    assert data_received_at_server.wait(1)
    bts.send("hiclient")
    assert data_received_at_server.wait(1)
    
    btc.disconnect()
    bts.stop()
Esempio n. 7
0
    command(bd_press, bdx, bdy)
    command(bd_release, bdx, bdy)
    command(bd_press, bdx, bdy)
    command(bd_release, bdx, bdy)


@skywriter.tap()
def tap(position):
    print('Tap!', position)
    bdx, bdy = direction[position]
    if position == sky_centre:
        command(bd_release, bdx, bdy)
    else:
        command(bd_press, bdx, bdy)


@skywriter.touch()
def touch(position):
    print('Touch!', position)
    bdx, bdy = direction[position]
    if position == sky_centre:
        command(bd_release, bdx, bdy)
    else:
        command(bd_press, bdx, bdy)


try:
    pause()
finally:
    c.disconnect()