From efd763d0553c97b896f45bb0742e75d15538df8f Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Tue, 5 Sep 2023 17:24:21 +0300 Subject: [PATCH] - try to finish answering nodes properly --- src/agent_gsm.py | 6 ++++++ src/bt_call_controller.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/agent_gsm.py b/src/agent_gsm.py index 1dd67ba..46ad42a 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -21,6 +21,7 @@ from agent_config import AgentConfig from bt_controller import Bluetoothctl import bt_signal from bt_signal import SignalBoundaries +from bt_call_controller import INTERRUPT_SIGNAL import bt_call_controller @@ -424,12 +425,17 @@ def remove_pid_on_exit(): def receive_signal(signal_number, frame): + global INTERRUPT_SIGNAL + # Delete PID file remove_pid_on_exit() # Debugging info print(f'Got signal {signal_number} from {frame}') + # This it to break BT play controller + INTERRUPT_SIGNAL = True + # Exit raise SystemExit('Exiting') return diff --git a/src/bt_call_controller.py b/src/bt_call_controller.py index 93d644e..b9c9938 100644 --- a/src/bt_call_controller.py +++ b/src/bt_call_controller.py @@ -22,6 +22,7 @@ CALL_ADDED = multiprocessing.Value('b', False) CALL_REMOVED = multiprocessing.Value('b', False) CALL_LOCK = threading.Lock() +INTERRUPT_SIGNAL = multiprocessing.Value('b', False) # Call state change event class CallState(bt_phone.Observer): @@ -94,13 +95,17 @@ def dial_number(number: str, play_file: str): # Answer the call def answer_call(play_file: str): - global CALL_PATH, CALL_LOCK, CALL_ADDED + global CALL_PATH, CALL_LOCK, CALL_ADDED, INTERRUPT_SIGNAL utils.log('Waiting for incoming call...') # Wait for incoming call - while not CALL_ADDED.value: - time.sleep(0.1) + while not CALL_ADDED.value and not INTERRUPT_SIGNAL.value(): + time.sleep(0.01) + if INTERRUPT_SIGNAL.value(): + utils.log(f'Interrupt signal detected, exiting.') + return + utils.log(f'Found incoming call {CALL_PATH}') # CALL_LOCK.release()