Skip to content

Commit

Permalink
Integrate Simulator Tab (jopohl#395)
Browse files Browse the repository at this point in the history
* enable simulator tab

* save simulated participant in project

* add link for checksum label and make it configurable

* handle checksum label change for simulator label

* fix crash when editing field types with active simulator labels

* allow assigning multiple source/destination at once

* remove unused event

* use default line color for arrows

* cleanup code

* refactor bootstrapping of device settings and sniff widget
add button for opening sniff dialog in simulator dialog

* reformat code

* enhance bootstrapping to keep initial project manager settings

* highlight simulated participants in flow graph

* more verbose logging

* reformat file

* fix initial gain settings

* reformat code

* also save antenna index

* unify sniffer settings

* add signal selection to sniff widget to take values from signal

* add default argument

* fix missing refresh when adding items to scene with participant assigned

* catch error when saving xml

* refactor SimulatorProtocolLabel

* Improve handling of checksum labels

* travis: generate coverage data for all python > 3.4

* replace print calls with logger calls

* refactor goto action

* refactor simulator message

* refactor simulator rule

* rename to SimulatorExternalProgramAction

* add tooltip for value type

* improve performance of protocol sniffer

* improve performance of protocol sniffer even further

* directly emit signal and do not use timer

* add unittest for protocol sniffer

* add test for clear action

* add test for settings proxy

* add test for accepting sniffed messages

* make test more generic

* repair test

* catch none error

* fix typo

* refactor dialog creation

* add test for simulation flow

* refactor read_receiving_queue

* fix unittest

* increase timeout for ci

* improve sniffer performance especially when reaching end of buffer

* catch error

* add timeout for windows

* improve condition

* move run command and parse command to util and refactor methods

* add validate command method and refactor run_command

* fix imports

* improve validate check

* proper renaming

* rename log messages accordingly

* cleanup method

* add external program support for simulator

* fix if condition

* travis ci: use sudo for all builds

* revert

* add wait for ci

* improve test

* fix shebang

* refactor run command

* fix enabled repeat status and add wait for sync send

* pad send buffer with zeros if not enough data present

* catch exceptions when closing errors

* Revert "pad send buffer with zeros if not enough data present"

This reverts commit b5ea80a.

* remove timeout and return zeros properly in callback

* prevent calling gnuradio installed check too often

* rename repeat -> copies

* mark get live vs static labels

* Get live from simulation -> Live Input

* use shlex for calling programs

* fix valid check

* catch empty list error

* check if commmand is available before running

* windows support

* catch value error

* improve windows support

* adapt unittests

* Revert "adapt unittests"

This reverts commit 97d8a2c.

* get and store default programs on windows

* improve condition and pipe stderr

* also pipe stderr

* add validity check when assigning multiple message sources/destinations

* remove Create new message type based on this message

* Rename External Program Action -> Trigger Command

* fix unittest

* increase timeout for ci

* get external command action to work

* add timeout for sync send devices

* fix windows test

* fix call

* improve logging view

* make use of filter

* append participants instead of overwriting to prevent key errors

* add sip version str

* travis: test revent pyqt5

* Revert "travis: test revent pyqt5"

This reverts commit df1b403.

* proper naming + add context menu action for set value type

* support batch assigning of value type index

* fix method name

* adapt unittest to new logic

* add copy and paste for simulator scene

* show transcript

* support bit and hex view for transcript

* Fix display error in simulator

* improve logging

* catch index error

* improve condition

* show signals in modulation dialog created from simulator dialog

* fix filtering for KDE users

* add comment

* improve performance of filtering rows

* remove redundant update

* fix empty frame visible status to handle larger protocol files

* fix sending finished status

* fix unittest

* enhance modulation API do not cache result to avoid memory leak

* increase wait for devices timeout

* Fix memory leak for send dialog

* fix data loss for tree views

* Fix sample rates for AirSpy
- R2: 10M only
- Mini: 6M only

* set delete on close attribute

* Fix sample rates for AirSpy
- R2: 10M only
- Mini: 6M only

* Fix sample rates for AirSpy
- R2: 10M only
- Mini: 6M only

* Fix sample rates for AirSpy
- R2: 10M only
- Mini: 6M only

* allow capture full rx in simulator and make it possible to save rx data

* do not add gr device for continuous send mode

* fix property

* Some UI improvements

* improve performance of fsk modulation

* Fixed handle width

* improve performance of ask modulation

* improve performance of psk modulation

* fix unittest

* improve gfsk performance

* remove old modulation implementation

* increase timeout for ci

* use sudo by default for travis

* use fsk for test

* remove prange as it can lead to errors in continous modulation

* short async wait

* use spawn on all platforms

* increase timeout for ci

* decrease modulator buffer size

* make fsk parallel

* improve data types

* centralize setting of CONTINUOUS_BUFFER_SIZE_MB

* add log message

* add reset link for filtering

* new simulator default timeout

* catch index error

* catch error

* use shared memory for send buffer

* remove auto assign decodings

* remove dup variable

* rename sendbuffersize to rx chunk size and remove var dup

* READ_SAMPLES->SYNC_RX_CHUNK_SIZE

* fix data type in send config and remove pause in simulation

* improve hackrf send callback

* Tab prio changed

* improve sending backend

* fix lime send

* fix usrp send

* improve continous send mode for usrp

* improve code

* pad limesdr with zeros if needed

* fix log error

* enter continuous send dialog earlier

* add missing set_bandwidth_status call for RTLSDR

* save gains and antenna index per rx/tx

* show modulation profiles only when requested in options

* decrease complexity

* add edit labels action to context menu in simulator message table

* improve performance of auto detect freq

* add sleep action

* fix unittests + remove redundant test

* add counter action

* add parent to timers + increase coverage for cfc

* improve test

* use sip to delete dialogs

* improve tests

* set dialog to none

* add log message

* remove unneeded base class

* remove redundant test

* do not inherit qttestcase without reason

* stop sniffer in test

* reformat test files

* add a short wait after teardown

* give each app a unique name

* fix travis conf

* name concurrency setting in coveragerc

* remove xml setting

* improve condition

* add combine

* coverage only for python 3.6

* install pytest cov and coveralls only for python 3.6

* remove concurrency setting

* update coveragerc

* add tests for decoding dialog

* Added external programm for decoding/encoding Homematic that does a dirty trick:
After "decryption" the CRC is recalculated and the corresponding field will be overwritten if the CRC was correct before. In this way you can directly see whether the Homematic message is correct without switching to a intermediate layer (before decryption).

* fix selection error in Decoding dialog and move test to TestExternalDecodings.py

* beautify simulation scene

* show shown rows labels always and not only for filter

* prevent auto default

* clear transcript only on start and add crc log

* Minor stuff:
* Timeout Sim in ms
* CRC Label check fixed
* transcript format improved

* improve loading of txt support transcript and hex

* fix close all disbled status

* prepare open in analysis

* implement logic for open in analysis button

* refactor transcript newline

* enhance order of close event

* improve logging output

* increase align depth

* only color got string in log

* update userguide
  • Loading branch information
jopohl authored Feb 28, 2018
1 parent cb42ddd commit 6c1ae0e
Show file tree
Hide file tree
Showing 154 changed files with 47,122 additions and 22,752 deletions.
21 changes: 12 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
os: linux
language: python
dist: trusty
sudo: false
sudo: required

env:
global:
Expand All @@ -11,7 +11,6 @@ env:
matrix:
include:
- python: 3.4_with_system_site_packages
sudo: required
- python: 3.5
- python: 3.6

Expand All @@ -36,32 +35,36 @@ install:
else
pip3 install pyqt5!=5.10 && pip3 install -r data/requirements.txt; # PyQt5 is only installable via pip for Python >= 3.5
fi
- pip3 install pytest-cov coveralls
- if [[ $TRAVIS_PYTHON_VERSION == "3.6"* ]]; then
pip3 install pytest-cov coveralls;
else
pip3 install pytest;
fi
- sh -e /etc/init.d/xvfb start
- sleep 5

before_script:
- touch tests/show_gui
- python3 -c "from PyQt5.QtCore import QT_VERSION_STR; from PyQt5.Qt import PYQT_VERSION_STR; print('QT Version:', QT_VERSION_STR); print('PyQt Version:', PYQT_VERSION_STR)"
- python3 -c "from PyQt5.QtCore import QT_VERSION_STR; from PyQt5.Qt import PYQT_VERSION_STR; from sip import SIP_VERSION_STR; print('QT Version:', QT_VERSION_STR); print('PyQt Version:', PYQT_VERSION_STR); print('SIP version:', SIP_VERSION_STR)"

script:
- python3 src/urh/cythonext/build.py &> /tmp/build_log.txt
- if [[ $TRAVIS_PYTHON_VERSION != "3.4"* ]]; then
- if [[ $TRAVIS_PYTHON_VERSION == "3.6"* ]]; then
pytest -s --cov-report= --cov=src/urh --cov-config tests/.coveragerc tests 2> /tmp/test_errors.txt;
else
pytest tests 2> /tmp/test_errors.txt;
pytest -s tests 2> /tmp/test_errors.txt;
fi
- pip3 install .
- urh --version
- urh autoclose

after_failure:
- cat /tmp/build_log.txt
- cat /tmp/test_errors.txt
- cat /tmp/build_log.txt

after_success:
- if [[ $TRAVIS_PYTHON_VERSION != "3.4"* ]]; then
- if [[ $TRAVIS_PYTHON_VERSION == "3.6"* ]]; then
coveralls --rcfile=tests/.coveragerc;
else
echo "coverage upload only for python > 3.4";
echo "coverage upload only for python 3.6";
fi
2 changes: 1 addition & 1 deletion data/decodings/homematic.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char **argv)
enc[i/8] = str2byte(&string[i]);
max = i/8;
memcpy(&dec, &enc, 256);

/*
* byte[] Dec = new byte[Enc.Length];
* Dec[0] = Enc[0]; //Packet length
Expand Down
Binary file added data/decodings/homematic_complete
Binary file not shown.
223 changes: 223 additions & 0 deletions data/decodings/homematic_complete.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
#include <stdio.h>
#include <string.h>

typedef unsigned char byte;
typedef unsigned short uint16;

uint16 crc(byte *data, int len)
{
byte i, x, crcdata;
uint16 crcReg = 0xFFFF;
for (x = 0; x < len; x++)
{
crcdata = data[x];
for (i = 0; i < 8; i++)
{
if (((crcReg & 0x8000) >> 8) ^ (crcdata & 0x80))
crcReg = (crcReg << 1) ^ 0x8005;
else
crcReg = (crcReg << 1);
crcdata <<= 1;
}
}
return crcReg;
}

byte str2byte(char str[8])
{
int ret = 0, i;
for(i = 0; i < 8; i++)
if (str[i]=='1') ret |= (1<<(7-i));
return ret;
}

void print_binary(byte inpt)
{
int i;
for(i = 0; i < 8; i++)
if (inpt & (1<<(7-i))) putchar('1');
else putchar('0');
}

int find_preamble_start_in_bit(char *string, int len)
{
char homematic_sync[]="11101001110010101110100111001010";
for(int i = 0, j = 0; i < len; i++)
{
if(string[i]==homematic_sync[j])
{
j++;
if(j == 32 && i>= 63) return i-63;
}
else j = 0;
}
return -1; //not found
}

void xor_lfsr(char *string)
{
int i, j, x, len = strlen(string);
byte polynomial[9] = {0, 0, 0, 1, 0, 0, 0, 0, 1};
byte lfsr_state[9];
byte first_bit;

// Init with 8x 1 Bit
memset(lfsr_state, 1, 9);
for(j = 0; j < 8; j++)
if(string[j]=='1')
string[j]='0';
else
string[j]='1';

for(x = 8; x < len-7; x += 8)
{
for(i = 0; i < 8; i++)
{
first_bit = 255;
for(j = 8; j >= 0; j--)
if(polynomial[j] && lfsr_state[j])
{
if(first_bit == 255)
first_bit = 1;
else
first_bit = (first_bit==1) ? 0 : 1;
}
if(first_bit == 255)
first_bit = 0;

// Clock
for(j = 8; j >= 0; j--)
lfsr_state[j] = lfsr_state[j-1];
lfsr_state[0] = first_bit;
}

// Xor
for(j = 0; j < 8; j++)
if(lfsr_state[j+1] == 1)
if(string[x+j]=='1')
string[x+j]='0';
else
string[x+j]='1';
}
}

int main(int argc, char **argv)
{
int i, j, max, offset, len;
byte dec[256]={0}, enc[256]={0}, crc_ok;
char string[2048]={0};
uint16 crcvalue;
offset = 8; // Preamble + Sync

// Copy data (argv[2]) to string if length is ok, shorten to multiple of 8 bit
if (strlen(argv[2]) > 256*8 || strlen(argv[2]) < 4) return -1;
len = strlen(argv[2]);

i = find_preamble_start_in_bit(argv[2], len);
if(i < 0) return 0; // preamble+sync not found or wrong length

len = (len-i)-(len-i)%8;
memcpy(string, argv[2]+i, len);

if (argc>2)
{
if (argv[1][0]=='d')
{
// Apply datawhitening
xor_lfsr(string+64);

// Pack to bytes
for (i = 0; i < strlen(string)-3; i+=8)
enc[i/8] = str2byte(&string[i]);
max = i/8;
memcpy(&dec, &enc, 256);

// Check CRC
crcvalue = crc(&dec[8], max-2-8);
crc_ok = 0;
if( ((crcvalue >> 8) & 0xFF) == dec[max-2] && (crcvalue & 0xFF) == dec[max-1]) crc_ok = 1;

/*
* byte[] Dec = new byte[Enc.Length];
* Dec[0] = Enc[0]; //Packet length
* Dec[1] = (byte)((~Enc[1]) ^ 0x89);
* int j;
* for (j = 2; j < Dec[0]; j++)
* Dec[j] = (byte)((Enc[j-1] + 0xdc) ^ Enc[j]);
* Dec[j] = (byte)(Enc[j] ^ Dec[2]);
*/

// Decrypt
dec[offset+0] = enc[offset+0];

dec[offset+1] = (~enc[offset+1])^0x89;
for(i = offset+2; i < max; i++)
dec[i] = (enc[i-1]+0xdc) ^ enc[i];
dec[offset+i] = enc[offset+i] ^ dec[offset+2];

// Recompute CRC and overwrite with FAKE-CRC, if CRC was OK before
if(crc_ok)
{
crcvalue = crc(&dec[8], max-2-8);
dec[max-1] = crcvalue & 0xFF;
dec[max-2] = (crcvalue >> 8) & 0xFF;
}
else
{
dec[max-1] = 0x0F; // Set magic code for wrong CRC
dec[max-2] = 0xD0;
}

for(i = 0; i < max; i++)
print_binary(dec[i]);
}
else
{
// Pack to bytes
for (i = 0; i < strlen(string)-3; i+=8)
dec[i/8] = str2byte(&string[i]);
max = i/8;
memcpy(&enc, &dec, 256);

/*
* byte[] Dec = new byte[Enc.Length];
* Dec[0] = Enc[0]; //Packet length
* Dec[1] = (byte)((~Enc[1]) ^ 0x89);
* int j;
* for (j = 2; j < Dec[0]; j++)
* Dec[j] = (byte)((Enc[j-1] + 0xdc) ^ Enc[j]);
* Dec[j] = (byte)(Enc[j] ^ Dec[2]);
*/

// Encrypt
enc[offset+0] = dec[offset+0];

enc[offset+1] = ~(dec[offset+1]^0x89);
for(i = offset+2; i < max; i++)
enc[i] = (enc[i-1]+0xdc) ^ dec[i];
enc[offset+i] = dec[offset+i] ^ dec[offset+2];

// Overwrite with correct CRC
crcvalue = crc(&enc[8], max-2-8);
enc[max-1] = crcvalue & 0xFF;
enc[max-2] = (crcvalue >> 8) & 0xFF;

// Convert to string
memset(string, 0, 2048);
for(i = 0; i < max; i++)
{
for(j = 0; j < 8; j++)
if(enc[i] & (1<<(7-j))) string[i*8+j]='1';
else string[i*8+j]='0';
}
// Apply datawhitening
xor_lfsr(string+64);

// Print bits and duplicate last bit
printf("%s%c\n", string, string[strlen(string)-1]);
}
}
else printf("Usage: %s <d/e> <bit sequence>\n\td - decode\n\te - encode\n\tbit sequence as string of 0 and 1.\n", argv[0]);

return 0;
}
5 changes: 3 additions & 2 deletions data/ui/analysis.ui
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="lFilterShown">
<widget class="QLabel" name="lblShownRows">
<property name="text">
<string>shown: 42/108</string>
</property>
Expand Down Expand Up @@ -798,7 +798,8 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
<string>...</string>
</property>
<property name="icon">
<iconset theme="document-open"/>
<iconset theme="document-open">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand Down
5 changes: 3 additions & 2 deletions data/ui/generator.ui
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
</font>
</property>
<property name="text">
<string>Generated data</string>
<string>Generated Data</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
Expand Down Expand Up @@ -664,7 +664,8 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
<string>...</string>
</property>
<property name="icon">
<iconset theme="document-open"/>
<iconset theme="document-open">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand Down
Loading

0 comments on commit 6c1ae0e

Please sign in to comment.