Skip to content

Commit

Permalink
Add nRF connection to test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
EliHaugu committed Nov 5, 2024
1 parent 5eb31db commit 6c3690b
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions server/server_comm/test_runner/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.shortcuts import get_object_or_404
from django.urls import reverse
from flow_parser import FlowParser
from test_runner.nrf_scripts.nrf_connect import run_check_connection
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
Expand Down Expand Up @@ -91,15 +92,61 @@ def check_device_connections(self, flow_id):
"message": "Failed to check device connections",
}

def get_nrf_devices(self, devices):
"""
TODO: Placeholder function, logic for deciding what is an nrf device
"""
return devices

def connect_ble_nrf_devices(self, flow_id):
"""
Connect select device(s) in command nodes to nrf kit
"""
# TODO: does the user need to make category "Android" for this to work
# what if they wanna categorize differently?
# not all BLE/android devices should be connected, no? who should be?
# TODO: how do we check UUIDs? need to know if service/characteristic

protocol = 'https' if self.request.is_secure() else 'http'
base_url = f"{protocol}://{self.request.get_host()}"
get_devices_url = f"""
{base_url}{reverse('devices')}
"""
response = requests.get(get_devices_url)

if response.status_code == 200:
devices = response.json()
else:
return {
"status": "error",
"message": "Failed to get devices",
"response": response,
}

nrf_devices = self.get_nrf_devices(devices)

for device in nrf_devices:
dev_id = device.device_id
mac = device.communication_ids.get("mac_address")
res = run_check_connection(dev_id, mac)

if res.get("status") == "error":
raise RuntimeError(
f"{res.get("message")}\n{res.get("response")}"
)
return {
"status": "success",
"message": "Connected all nRF devices",
"response": "",
}

def test_setup(self, flow_id):
"""
Set up and assert device connections for the test flow.
"""
self.check_device_connections(flow_id)

# TODO Connect android device(s) in command nodes to nrf kit (LIL-90)

# TODO Assert that connection is setup (LIL-90)
self.connect_ble_nrf_devices(flow_id)

def run_node(self, node):
"""
Expand All @@ -112,6 +159,7 @@ def run_node(self, node):
result = True
elif node.node_type == Node.ACTION:
try:
# TODO: HOW DO WE RUN NRF SCRIPTS?
exec(node.function)
result = True
except Exception as e:
Expand Down

0 comments on commit 6c3690b

Please sign in to comment.