Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

also consider participant address (next to RSSI) when auto assigning #512

Merged
merged 1 commit into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- auto assign destination when dropping messages to simulator
- show participant address in participant legend if present
- auto assign participant address when clicking analyze button in analysis based on SRC address label
- also consider participant address (next to RSSI) when auto assigning participants in analysis [#512](https://github.com/jopohl/urh/pull/512)

### Bugfixes
- antenna selection is not saved when reopening dialog [#494](https://github.com/jopohl/urh/pull/494)
Expand Down
22 changes: 22 additions & 0 deletions src/urh/signalprocessing/Message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time

from urh.signalprocessing.Encoding import Encoding
from urh.signalprocessing.FieldType import FieldType
from urh.signalprocessing.MessageType import MessageType
from urh.signalprocessing.Participant import Participant
from urh.signalprocessing.ProtocoLabel import ProtocolLabel
Expand Down Expand Up @@ -356,6 +357,27 @@ def get_duration(self, sample_rate: int) -> float:

return (self.bit_sample_pos[-1] - self.bit_sample_pos[0]) / sample_rate

def get_src_address_from_data(self, decoded=True):
"""
Return the SRC address of a message if SRC_ADDRESS label is present in message type of the message
Return None otherwise

:param decoded:
:return:
"""
src_address_label = next((lbl for lbl in self.message_type if lbl.field_type
and lbl.field_type.function == FieldType.Function.SRC_ADDRESS), None)
if src_address_label:
start, end = self.get_label_range(src_address_label, view=1, decode=decoded)
if decoded:
src_address = self.decoded_hex_str[start:end]
else:
src_address = self.plain_hex_str[start:end]
else:
src_address = None

return src_address

@staticmethod
def __bit_chains_to_hex(bit_chains) -> array.array:
"""
Expand Down
26 changes: 14 additions & 12 deletions src/urh/signalprocessing/ProtocolAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,20 +680,25 @@ def auto_assign_participants(self, participants):
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, self.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 self.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 = 0
diff = 999
for i, center in enumerate(centers):
if abs(center - rssi) < diff:
center_index = i
diff = abs(center - rssi)
rssi_assigned_centers.append(center_index)
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(self.messages, rssi_assigned_centers):
Expand All @@ -713,11 +718,8 @@ def auto_assign_participant_addresses(self, participants):

for msg in self.messages:
if msg.participant in participants_without_address:
src_address_label = next((lbl for lbl in msg.message_type if lbl.field_type
and lbl.field_type.function == FieldType.Function.SRC_ADDRESS), None)
if src_address_label:
start, end = msg.get_label_range(src_address_label, view=1, decode=True)
src_address = msg.decoded_hex_str[start:end]
src_address = msg.get_src_address_from_data()
if src_address:
participants_without_address.remove(msg.participant)
msg.participant.address_hex = src_address

Expand Down