Skip to content

Commit

Permalink
improve sdr check fix #811 (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl authored Nov 2, 2020
1 parent 611ef15 commit 217a814
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion data/inno.iss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AppPublisher=Johannes Pohl
AppPublisherURL=https://github.com/jopohl/urh
AppSupportURL=https://github.com/jopohl/urh
AppUpdatesURL=https://github.com/jopohl/urh
DefaultDirName={pf}\Universal Radio Hacker
DefaultDirName={commonpf}\Universal Radio Hacker
DisableProgramGroupPage=yes
LicenseFile=..\LICENSE
OutputDir=..\dist
Expand Down
12 changes: 7 additions & 5 deletions src/urh/dev/native/ExtensionHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ def compiler_has_function(compiler, function_name, libraries, library_dirs, incl
try:
try:
file_name = os.path.join(tmp_dir, '{}.c'.format(function_name))
f = open(file_name, 'w')
f.write('int main(void) {\n')
f.write(' %s();\n' % function_name)
f.write('}\n')
f.close()
with open(file_name, 'w') as f:
# declare function in order to prevent Clang 12 error (https://github.com/jopohl/urh/issues/811)
f.write('void %s();\n' % function_name)
f.write('int main(void) {\n')
f.write(' %s();\n' % function_name)
f.write('}\n')

# Redirect stderr to /dev/null to hide any error messages from the compiler.
devnull = open(os.devnull, 'w')
old_stderr = os.dup(sys.stderr.fileno())
Expand Down
35 changes: 18 additions & 17 deletions src/urh/signalprocessing/ContinuousModulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ def __init__(self, messages, modulators, num_repeats=-1):
self.modulators = modulators
self.num_repeats = num_repeats # -1 or 0 = infinite

self.ring_buffer = RingBuffer(int(settings.CONTINUOUS_BUFFER_SIZE_MB * 10 ** 6) // 8, dtype=Modulator.get_dtype())
self.ring_buffer = RingBuffer(int(settings.CONTINUOUS_BUFFER_SIZE_MB * 1e6) // 8, dtype=Modulator.get_dtype())

self.current_message_index = Value("L", 0)

self.abort = Value("i", 0)
self.process = Process(target=self.modulate_continuously, args=(self.num_repeats, ))
self.process.daemon = True
self.process = Process(target=self.modulate_continuously, args=(self.num_repeats, ), daemon=True)

@property
def is_running(self):
Expand All @@ -40,34 +39,34 @@ def is_running(self):
def start(self):
self.abort.value = 0
try:
self.process = Process(target=self.modulate_continuously, args=(self.num_repeats, ))
self.process.daemon = True
self.process = Process(target=self.modulate_continuously, args=(self.num_repeats, ), daemon=True)
self.process.start()
except RuntimeError as e:
logger.debug(str(e))
logger.exception(e)

def stop(self, clear_buffer=True):
self.abort.value = 1
if clear_buffer:
self.ring_buffer.clear()
if not self.process.is_alive():
return

try:
self.process.join(0.1)
except RuntimeError as e:
logger.debug(str(e))

if self.process.is_alive():
self.process.terminate()
self.process.join()
try:
self.process.join(1.5)
except RuntimeError as e:
logger.exception(e)
self.process.terminate()

if clear_buffer:
self.ring_buffer.clear()

logger.debug("Stopped continuous modulation")

def modulate_continuously(self, num_repeats):
rng = iter(int, 1) if num_repeats <= 0 else range(0, num_repeats) # <= 0 = forever
for _ in rng:
if self.abort.value:
return

start = self.current_message_index.value

for i in range(start, len(self.messages)):
if self.abort.value:
return
Expand All @@ -82,5 +81,7 @@ def modulate_continuously(self, num_repeats):

# Wait till there is space in buffer
time.sleep(self.WAIT_TIMEOUT)

self.ring_buffer.push(modulated)

self.current_message_index.value = 0
1 change: 1 addition & 0 deletions src/urh/simulator/Simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def process_message(self):
received_msg.decoder = new_message.decoder
received_msg.message_type = new_message.message_type

self.log_message("Message {}: Check whether received data matches".format(msg.index()))
check_result, error_msg = self.check_message(received_msg, new_message, retry=retry,
msg_index=msg.index())

Expand Down
2 changes: 1 addition & 1 deletion tests/test_continuous_modulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_modulate_continuously(self):
self.assertTrue(continuous_modulator.ring_buffer.is_empty)
continuous_modulator.start()
self.assertTrue(continuous_modulator.process.is_alive())
time.sleep(1.5)
time.sleep(2)
self.assertFalse(continuous_modulator.ring_buffer.is_empty)
continuous_modulator.stop()
self.assertFalse(continuous_modulator.process.is_alive())
Expand Down

0 comments on commit 217a814

Please sign in to comment.