Skip to content

Commit

Permalink
Adding timestamps to messages generated in ProtocolSniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Velazquez authored and PepsConti committed Oct 14, 2022
1 parent 7be0da6 commit a0eea05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/urh/dev/native/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def read_receiving_queue(self):
try:
byte_buffer = self.parent_data_conn.recv_bytes()

if (self.__first_data_timestamp == 0):
if self.__first_data_timestamp == 0:
self.__first_data_timestamp = time.time()
calculating_timestamp = True
else:
Expand All @@ -700,7 +700,7 @@ def read_receiving_queue(self):
samples = self.bytes_to_iq(byte_buffer)
n_samples = len(samples)

if (calculating_timestamp):
if calculating_timestamp:
# Timestamp accurate correction
self.__first_data_timestamp -= n_samples / self.sample_rate

Expand Down
14 changes: 12 additions & 2 deletions src/urh/signalprocessing/ProtocolSniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def device_name(self, value: str):
self.__init_buffer()

def sniff(self):
self.__livesignal_buffer_timestamp = 0
self.is_running = True
self.rcv_device.start()
self.sniff_thread = Thread(target=self.check_for_data, daemon=True)
Expand Down Expand Up @@ -176,6 +177,12 @@ def __demodulate_data(self, data):
if len(data) == 0:
return

if self.__livesignal_buffer_timestamp == 0:
self.__livesignal_buffer_timestamp = self.rcv_device.data_timestamp

livesignal_buffer_timestamp = self.__livesignal_buffer_timestamp
self.__livesignal_buffer_timestamp += len(data) / self.rcv_device.sample_rate

power_spectrum = data.real ** 2.0 + data.imag ** 2.0
is_above_noise = np.sqrt(np.mean(power_spectrum)) > self.signal.noise_threshold

Expand Down Expand Up @@ -211,13 +218,16 @@ def __demodulate_data(self, data):
self.signal.bits_per_symbol, self.signal.center_spacing)

bit_data, pauses, bit_sample_pos = self._ppseq_to_bits(ppseq, samples_per_symbol,
self.signal.bits_per_symbol, write_bit_sample_pos=False)
self.signal.bits_per_symbol, write_bit_sample_pos=True)

i = 0
for bits, pause in zip(bit_data, pauses):
message_timestamp = livesignal_buffer_timestamp + (bit_sample_pos[i][0] / self.rcv_device.sample_rate)
message = Message(bits, pause, samples_per_symbol=samples_per_symbol, message_type=self.default_message_type,
decoder=self.decoder)
decoder=self.decoder, timestamp=message_timestamp)
self.messages.append(message)
self.message_sniffed.emit(len(self.messages) - 1)
i += 1

def stop(self):
self.is_running = False
Expand Down

0 comments on commit a0eea05

Please sign in to comment.