Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve sdr check fix #811 #812

Merged
merged 10 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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