Skip to content

Commit

Permalink
More accurate logic analysis (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl authored May 20, 2019
1 parent 5aa64df commit 1e18cdb
Showing 72 changed files with 7,025 additions and 1,410 deletions.
6 changes: 5 additions & 1 deletion data/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -56,9 +56,13 @@ jobs:
touch tests/show_gui
cp tests/.coveragerc .
pytest --junitxml=junit/test-results.xml --cov=src --cov-config=.coveragerc tests
displayName: 'Run pytest with coverage'
condition: eq(variables['python.version'], '3.7')
- script: |
coverage xml
coverage html
displayName: 'Run pytest with coverage'
displayName: 'Generate coverage report'
condition: eq(variables['python.version'], '3.7')
- script: pytest --junitxml=junit/test-results.xml tests
6 changes: 3 additions & 3 deletions data/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
numpy; sys_platform != 'win32'
numpy!=1.16.0; sys_platform == 'win32'
numpy>=1.9; sys_platform != 'win32'
numpy>=1.9,!=1.16.0; sys_platform == 'win32'
pyqt5; sys_platform != 'win32' and sys_platform != 'linux'
pyqt5!=5.11.1,!=5.11.2,!=5.11.3; sys_platform == 'win32'
pyqt5!=5.12,!=5.12.1; sys_platform == 'linux'
pyqt5!=5.12,!=5.12.1,!=5.12.2; sys_platform == 'linux'
psutil
pyzmq
cython
65 changes: 65 additions & 0 deletions src/urh/awre/AutoAssigner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import numpy as np

from urh.cythonext import util
from urh.signalprocessing.Message import Message


def auto_assign_participants(messages, participants):
"""
:type messages: list of Message
:type participants: list of Participant
:return:
"""
if len(participants) == 0:
return

if len(participants) == 1:
for message in messages: # type: Message
message.participant = participants[0]
return

# Try to assign participants based on SRC_ADDRESS label and participant address
for msg in filter(lambda m: m.participant is None, messages):
src_address = msg.get_src_address_from_data()
if src_address:
try:
msg.participant = next(p for p in participants if p.address_hex == src_address)
except StopIteration:
pass

# Assign remaining participants based on RSSI of messages
rssis = np.array([msg.rssi for msg in messages], dtype=np.float32)
min_rssi, max_rssi = util.minmax(rssis)
center_spacing = (max_rssi - min_rssi) / (len(participants) - 1)
centers = [min_rssi + i * center_spacing for i in range(0, len(participants))]
rssi_assigned_centers = []

for rssi in rssis:
center_index = np.argmin(np.abs(rssi - centers))
rssi_assigned_centers.append(int(center_index))

participants.sort(key=lambda participant: participant.relative_rssi)
for message, center_index in zip(messages, rssi_assigned_centers):
if message.participant is None:
message.participant = participants[center_index]


def auto_assign_participant_addresses(messages, participants):
"""
:type messages: list of Message
:type participants: list of Participant
:return:
"""
participants_without_address = [p for p in participants if not p.address_hex]

if len(participants_without_address) == 0:
return

for msg in messages:
if msg.participant in participants_without_address:
src_address = msg.get_src_address_from_data()
if src_address:
participants_without_address.remove(msg.participant)
msg.participant.address_hex = src_address
Loading

0 comments on commit 1e18cdb

Please sign in to comment.