From a0eea0517e72b86db9008ce3aa5178251d0b7555 Mon Sep 17 00:00:00 2001 From: Jose Velazquez Date: Tue, 15 Mar 2022 15:31:36 -0600 Subject: [PATCH] Adding timestamps to messages generated in ProtocolSniffer --- src/urh/dev/native/Device.py | 4 ++-- src/urh/signalprocessing/ProtocolSniffer.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/urh/dev/native/Device.py b/src/urh/dev/native/Device.py index 37a04f9588..cd0ad92303 100644 --- a/src/urh/dev/native/Device.py +++ b/src/urh/dev/native/Device.py @@ -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: @@ -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 diff --git a/src/urh/signalprocessing/ProtocolSniffer.py b/src/urh/signalprocessing/ProtocolSniffer.py index 494bc84bde..2ada115203 100644 --- a/src/urh/signalprocessing/ProtocolSniffer.py +++ b/src/urh/signalprocessing/ProtocolSniffer.py @@ -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) @@ -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 @@ -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