Beispiel #1
0
    def test_mtu(self):
        requested_mtu = 150
        max_supported_mtu = Settings.current().mtu

        self.assertTrue(Settings.current().mtu >= requested_mtu)

        self.peripheral.start(self.adv_name)
        self.central.start(self.adv_name, requested_mtu)

        self.assertEqual(self.peripheral.mtu_req, requested_mtu)
        self.assertEqual(self.central.mtu_rsp, max_supported_mtu)

        common_supported_mtu = min(max_supported_mtu, requested_mtu)
        self.assertEqual(self.central.new_mtu, common_supported_mtu)

        self.central.stop()
Beispiel #2
0
    def setUp(self):
        settings = Settings.current()

        central = setup_adapter(
            settings.serial_ports[0],
            False,
            settings.baud_rate,
            settings.retransmission_interval,
            settings.response_timeout,
            settings.driver_log_level,
        )

        self.central = Central(central)

        peripheral = setup_adapter(
            settings.serial_ports[1],
            False,
            settings.baud_rate,
            settings.retransmission_interval,
            settings.response_timeout,
            settings.driver_log_level,
        )

        # Advertising name used by peripheral and central
        # to find peripheral and connect with it
        self.adv_name = "".join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(20))
        self.peripheral = Peripheral(peripheral)
Beispiel #3
0
    def test_mtu_invalid(self):
        requested_mtu = 250

        self.assertTrue(Settings.current().mtu < requested_mtu)

        self.peripheral.start(self.adv_name)
        with self.assertRaises(NordicSemiException):
            self.central.start(self.adv_name, requested_mtu)

        self.central.stop()
Beispiel #4
0
def setup_adapter(
    port,
    auto_flash,
    baud_rate,
    retransmission_interval,
    response_timeout,
    driver_log_level,
):
    settings = Settings.current()

    driver = BLEDriver(
        serial_port=port,
        auto_flash=auto_flash,
        baud_rate=baud_rate,
        retransmission_interval=retransmission_interval,
        response_timeout=response_timeout,
        log_severity_level=driver_log_level,
    )

    adapter = BLEAdapter(driver)
    adapter.default_mtu = settings.mtu
    adapter.open()
    if settings.nrf_family == "NRF51":
        adapter.driver.ble_enable(
            BLEEnableParams(
                vs_uuid_count=1,
                service_changed=0,
                periph_conn_count=1,
                central_conn_count=1,
                central_sec_count=0,
            ))
    elif settings.nrf_family == "NRF52":
        gatt_cfg = BLEConfigConnGatt()
        gatt_cfg.att_mtu = adapter.default_mtu
        gatt_cfg.tag = Settings.CFG_TAG
        adapter.driver.ble_cfg_set(BLEConfig.conn_gatt, gatt_cfg)

        if hasattr(settings, "event_length"):
            gap_cfg = BLEConfigConnGap()
            gap_cfg.event_length = settings.event_length
            adapter.driver.ble_cfg_set(BLEConfig.conn_gap, gap_cfg)

        adapter.driver.ble_enable()

    return adapter
Beispiel #5
0
    def test_programming(self):
        settings = Settings.current()

        serial_ports = BLEDriver.enum_serial_ports()

        # Check that from enumeration matches
        # kits provided from settings
        found_ports = list(map(lambda port: port.port, serial_ports))

        for serial_port in settings.serial_ports:
            self.assertIn(serial_port, found_ports)

        for serial_port in serial_ports:
            if serial_port.port in settings.serial_ports:
                serial_number = serial_port.serial_number
                logger.info("%s/%s deleting existing firmware",
                            serial_port.port, serial_number)

                flasher = Flasher(serial_port=serial_port.port)
                flasher.erase()

                self.assertFalse(
                    flasher.fw_check(),
                    "#{} must be programmed because it is erased".format(
                        serial_number),
                )

                flasher.fw_flash()
                logger.info("%s/%s programmed", serial_port.port,
                            serial_number)

                self.assertTrue(
                    flasher.fw_check(),
                    "#{} is programmed, shall not be programmed again".format(
                        serial_number),
                )

                # Try to use the device with leading zeroes in serial number removed
                flasher = Flasher(snr=serial_port.serial_number.lstrip('0'))
                flasher.reset()

                logger.info("%s/%s programmed successfully", serial_port.port,
                            serial_number)
Beispiel #6
0
            for _ in range(20))
        self.peripheral = Peripheral(peripheral)

    def test_rssi(self):
        self.peripheral.start(self.adv_name)
        self.central.start(self.adv_name)

        rssi = self.central.rssi_q.get(timeout=2)
        logger.info("conn_handle: %d rssi: %d", rssi["conn_handle"],
                    rssi["rssi"])

        self.assertTrue(rssi["rssi"] < 0)
        self.assertEqual(self.central.conn_handle, rssi["conn_handle"])
        self.central.stop()

    def tearDown(self):
        self.central.adapter.close()
        self.peripheral.adapter.close()


def test_suite():
    return unittest.TestLoader().loadTestsFromName(__name__)


if __name__ == "__main__":
    logging.basicConfig(
        level=Settings.current().log_level,
        format="%(asctime)s [%(thread)d/%(threadName)s] %(message)s",
    )
    unittest.main(argv=Settings.clean_args())
import unittest
import logging

from driver_setup import Settings

import test_driver_open_close


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(test_driver_open_close.test_suite())
    return suite


if __name__ == '__main__':
    logging.basicConfig(level=Settings.current().log_level)
    unittest.main(defaultTest='test_suite', argv=Settings.clean_args())