Skip to content

Commit

Permalink
add timestamp to protocol sniffer output (#392)
Browse files Browse the repository at this point in the history
* add timestamp to protocol sniffer

* add microseconds

* * monospaced font
* Order View changed
* Checkbox timestamp added

* centralize monospaced font setting

* make it posssible to toggle timestamps + add test
  • Loading branch information
jopohl authored Jan 22, 2018
1 parent f4c44fd commit befefa2
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 171 deletions.
184 changes: 98 additions & 86 deletions data/ui/send_recv.ui
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
<rect>
<x>0</x>
<y>0</y>
<width>664</width>
<height>1343</height>
<width>624</width>
<height>1550</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -84,7 +84,7 @@ QGroupBox::indicator:checked {
}</string>
</property>
<property name="title">
<string>Sniff settings</string>
<string>Sniff settin&amp;gs</string>
</property>
<property name="flat">
<bool>true</bool>
Expand All @@ -107,38 +107,31 @@ QGroupBox::indicator:checked {
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0" columnminimumwidth="150,0">
<item row="3" column="0">
<widget class="QLabel" name="label_sniff_Tolerance">
<property name="text">
<string>Error Tolerance:</string>
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0">
<item row="2" column="1">
<widget class="QSpinBox" name="spinbox_sniff_BitLen">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_sniff_Center">
<property name="text">
<string>Center:</string>
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spinbox_sniff_Noise">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinbox_sniff_Center">
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-3.140000000000000</double>
</property>
<property name="maximum">
<double>1.000000000000000</double>
<double>3.140000000000000</double>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_sniff_viewtype">
<property name="text">
<string>View:</string>
Expand All @@ -164,36 +157,19 @@ QGroupBox::indicator:checked {
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinbox_sniff_Center">
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spinbox_sniff_Noise">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-3.140000000000000</double>
</property>
<property name="maximum">
<double>3.140000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinbox_sniff_BitLen">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="comboBox_sniff_encoding"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_sniff_OutputFile">
<property name="text">
<string>Write bitstream to file:</string>
<double>1.000000000000000</double>
</property>
</widget>
</item>
Expand All @@ -204,32 +180,6 @@ QGroupBox::indicator:checked {
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_sniff_encoding">
<property name="text">
<string>Encoding:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="comboBox_sniff_viewtype">
<item>
<property name="text">
<string>Bit</string>
</property>
</item>
<item>
<property name="text">
<string>Hex</string>
</property>
</item>
<item>
<property name="text">
<string>ASCII</string>
</property>
</item>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinbox_sniff_ErrorTolerance">
<property name="maximum">
Expand All @@ -240,14 +190,28 @@ QGroupBox::indicator:checked {
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_sniff_OutputFile">
<property name="text">
<string>Write bitstream to file:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_sniff_Center">
<property name="text">
<string>Center:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_sniff_BitLength">
<property name="text">
<string>Bit Length:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QLineEdit" name="lineEdit_sniff_OutputFile">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -273,6 +237,53 @@ QGroupBox::indicator:checked {
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_sniff_Tolerance">
<property name="text">
<string>Error Tolerance:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="comboBox_sniff_viewtype">
<item>
<property name="text">
<string>Bit</string>
</property>
</item>
<item>
<property name="text">
<string>Hex</string>
</property>
</item>
<item>
<property name="text">
<string>ASCII</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_sniff_Timestamp">
<property name="text">
<string>Show timestamp</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_sniff_encoding">
<property name="text">
<string>Encoding:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="comboBox_sniff_encoding"/>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -660,7 +671,7 @@ QGroupBox::indicator:checked {
}</string>
</property>
<property name="title">
<string>Device settings</string>
<string>De&amp;vice settings</string>
</property>
<property name="flat">
<bool>true</bool>
Expand Down Expand Up @@ -1272,8 +1283,8 @@ QGroupBox::indicator:checked {
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>groupBoxDeviceSettings</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>cbDevice</tabstop>
<tabstop>lineEditDeviceArgs</tabstop>
<tabstop>comboBoxChannel</tabstop>
Expand All @@ -1299,23 +1310,24 @@ QGroupBox::indicator:checked {
<tabstop>spinbox_sniff_BitLen</tabstop>
<tabstop>spinbox_sniff_ErrorTolerance</tabstop>
<tabstop>combox_sniff_Modulation</tabstop>
<tabstop>comboBox_sniff_viewtype</tabstop>
<tabstop>comboBox_sniff_encoding</tabstop>
<tabstop>comboBox_sniff_viewtype</tabstop>
<tabstop>checkBox_sniff_Timestamp</tabstop>
<tabstop>lineEdit_sniff_OutputFile</tabstop>
<tabstop>btnStart</tabstop>
<tabstop>btnStop</tabstop>
<tabstop>btnSave</tabstop>
<tabstop>btnClear</tabstop>
<tabstop>btnAccept</tabstop>
<tabstop>graphicsViewReceive</tabstop>
<tabstop>txtEditErrors</tabstop>
<tabstop>graphicsView_sniff_Preview</tabstop>
<tabstop>txtEd_sniff_Preview</tabstop>
<tabstop>graphicsViewSend</tabstop>
<tabstop>sliderYscale</tabstop>
<tabstop>btnAccept</tabstop>
<tabstop>graphicsViewContinuousSend</tabstop>
<tabstop>graphicsViewFFT</tabstop>
<tabstop>graphicsViewSpectrogram</tabstop>
<tabstop>graphicsView_sniff_Preview</tabstop>
<tabstop>graphicsViewSend</tabstop>
<tabstop>txtEditErrors</tabstop>
<tabstop>sliderYscale</tabstop>
<tabstop>graphicsViewReceive</tabstop>
</tabstops>
<resources>
<include location="urh.qrc"/>
Expand Down
36 changes: 26 additions & 10 deletions src/urh/controller/ProtocolSniffDialogController.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import numpy as np
from PyQt5.QtCore import pyqtSlot, pyqtSignal
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QCompleter, QDirModel
from PyQt5.QtGui import QIcon, QFontDatabase
from PyQt5.QtWidgets import QCompleter, QDirModel, QApplication
from urh.ui.painting.SniffSceneManager import SniffSceneManager

from urh import constants
from urh.controller.SendRecvDialogController import SendRecvDialogController
from urh.plugins.NetworkSDRInterface.NetworkSDRInterfacePlugin import NetworkSDRInterfacePlugin
from urh.signalprocessing.ProtocolSniffer import ProtocolSniffer
from urh.ui.painting.LiveSceneManager import LiveSceneManager
from urh.util import util


class ProtocolSniffDialogController(SendRecvDialogController):
Expand Down Expand Up @@ -63,6 +64,7 @@ def __init__(self, project_manager, noise,
self.ui.comboBox_sniff_encoding.setCurrentIndex(encoding_index)

self.ui.comboBox_sniff_viewtype.setCurrentIndex(constants.SETTINGS.value('default_view', 0, int))
self.ui.txtEd_sniff_Preview.setFont(util.get_monospace_font())

@property
def device(self):
Expand All @@ -82,6 +84,10 @@ def device(self, value):
def view_type(self):
return self.ui.comboBox_sniff_viewtype.currentIndex()

@property
def include_timestamps(self):
return self.ui.checkBox_sniff_Timestamp.isChecked()

def create_connects(self):
super().create_connects()
self.ui.btnAccept.clicked.connect(self.on_btn_accept_clicked)
Expand All @@ -97,6 +103,7 @@ def create_connects(self):
self.ui.comboBox_sniff_viewtype.currentIndexChanged.connect(self.on_view_type_changed)
self.ui.lineEdit_sniff_OutputFile.editingFinished.connect(self.on_line_edit_output_file_editing_finished)
self.ui.comboBox_sniff_encoding.currentIndexChanged.connect(self.on_combobox_sniff_encoding_index_changed)
self.ui.checkBox_sniff_Timestamp.clicked.connect(self.on_checkbox_sniff_timestamp_clicked)

def set_device_ui_items_visibility(self, device_name: str, adjust_gains=True):
super().set_device_ui_items_visibility(device_name, adjust_gains)
Expand Down Expand Up @@ -139,27 +146,32 @@ def on_device_started(self):
@pyqtSlot()
def on_noise_edited(self):
self.sniffer.signal._noise_threshold = self.ui.spinbox_sniff_Noise.value()
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type))
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type,
include_timestamps=self.include_timestamps))

@pyqtSlot()
def on_center_edited(self):
self.sniffer.signal.qad_center = self.ui.spinbox_sniff_Center.value()
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type))
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type,
include_timestamps=self.include_timestamps))

@pyqtSlot()
def on_bit_len_edited(self):
self.sniffer.signal.bit_len = self.ui.spinbox_sniff_BitLen.value()
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type))
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type,
include_timestamps=self.include_timestamps))

@pyqtSlot()
def on_tolerance_edited(self):
self.sniffer.signal.tolerance = self.ui.spinbox_sniff_ErrorTolerance.value()
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type))
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type,
include_timestamps=self.include_timestamps))

@pyqtSlot(int)
def on_modulation_changed(self, new_index: int):
self.sniffer.signal.silent_set_modulation_type(new_index)
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type))
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type,
include_timestamps=self.include_timestamps))

@pyqtSlot()
def on_start_clicked(self):
Expand All @@ -180,14 +192,14 @@ def on_clear_clicked(self):

@pyqtSlot(int)
def on_data_sniffed(self, from_index: int):
new_data = self.sniffer.decoded_to_string(self.view_type, start=from_index)
new_data = self.sniffer.decoded_to_string(self.view_type, start=from_index, include_timestamps=self.include_timestamps)
if new_data.strip():
self.ui.txtEd_sniff_Preview.appendPlainText(new_data)
self.ui.txtEd_sniff_Preview.verticalScrollBar().setValue(self.ui.txtEd_sniff_Preview.verticalScrollBar().maximum())

@pyqtSlot(int)
def on_view_type_changed(self, new_index: int):
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(new_index))
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(new_index, include_timestamps=self.include_timestamps))

@pyqtSlot()
def on_btn_accept_clicked(self):
Expand All @@ -213,4 +225,8 @@ def on_combobox_sniff_encoding_index_changed(self, index: int):
if self.sniffer.decoder != self.encodings[index]:
self.sniffer.set_decoder_for_messages(self.encodings[index])
self.sniffer.decoder = self.encodings[index]
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type))
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type, include_timestamps=self.include_timestamps))

@pyqtSlot(bool)
def on_checkbox_sniff_timestamp_clicked(self, checked: bool):
self.ui.txtEd_sniff_Preview.setPlainText(self.sniffer.decoded_to_string(self.view_type, include_timestamps=checked))
Loading

0 comments on commit befefa2

Please sign in to comment.