- fixes
This commit is contained in:
parent
6afb7f9f12
commit
4db0350dfe
|
|
@ -384,10 +384,10 @@ def run_probe():
|
||||||
break
|
break
|
||||||
|
|
||||||
# Process tasks and measure spent time
|
# Process tasks and measure spent time
|
||||||
start_time = time.monotonic()
|
start_time = utils.get_monotonic_time()
|
||||||
|
|
||||||
for t in TASK_LIST.tasks:
|
for t in TASK_LIST.tasks:
|
||||||
if t["scheduled_time"] <= time.monotonic():
|
if t["scheduled_time"] <= utils.get_monotonic_time():
|
||||||
if t["command"] == "call":
|
if t["command"] == "call":
|
||||||
try:
|
try:
|
||||||
# Remove sheduled time
|
# Remove sheduled time
|
||||||
|
|
@ -405,7 +405,7 @@ def run_probe():
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
utils.log_error(message="Unexpected error.", err=err)
|
utils.log_error(message="Unexpected error.", err=err)
|
||||||
|
|
||||||
spent_time = time.monotonic() - start_time
|
spent_time = utils.get_monotonic_time() - start_time
|
||||||
|
|
||||||
# Wait 1 minute
|
# Wait 1 minute
|
||||||
if spent_time < 60:
|
if spent_time < 60:
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import smtplib
|
||||||
import socket
|
import socket
|
||||||
import sox
|
import sox
|
||||||
import io
|
import io
|
||||||
|
import time
|
||||||
|
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.application import MIMEApplication
|
from email.mime.application import MIMEApplication
|
||||||
|
|
@ -28,6 +29,12 @@ the_log = None
|
||||||
# 1 minute network timeout
|
# 1 minute network timeout
|
||||||
NETWORK_TIMEOUT = 15
|
NETWORK_TIMEOUT = 15
|
||||||
|
|
||||||
|
start_system_time = time.time()
|
||||||
|
start_monotonic_time = time.monotonic()
|
||||||
|
|
||||||
|
def get_monotonic_time():
|
||||||
|
return time.monotonic() - start_monotonic_time + start_system_time
|
||||||
|
|
||||||
|
|
||||||
def open_log_file(path: str, mode: str):
|
def open_log_file(path: str, mode: str):
|
||||||
global the_log
|
global the_log
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,14 @@ class LogcatEventSource(multiprocessing.Process):
|
||||||
process_poll.register(process_logcat.stdout, select.POLLIN)
|
process_poll.register(process_logcat.stdout, select.POLLIN)
|
||||||
|
|
||||||
# Monitoring start time
|
# Monitoring start time
|
||||||
current_timestamp = time.monotonic()
|
current_timestamp = utils.get_monotonic_time()
|
||||||
|
|
||||||
# Read logcat output line by line
|
# Read logcat output line by line
|
||||||
while self.terminate_flag.value == 0:
|
while self.terminate_flag.value == 0:
|
||||||
# Check if time limit is hit
|
# Check if time limit is hit
|
||||||
if time.monotonic() - current_timestamp > self.timelimit:
|
if utils.get_monotonic_time() - current_timestamp > self.timelimit:
|
||||||
break
|
break
|
||||||
current_timestamp = time.monotonic()
|
current_timestamp = utils.get_monotonic_time()
|
||||||
|
|
||||||
# Look for available data on stdout
|
# Look for available data on stdout
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -280,12 +280,12 @@ def gsm_monitor(file_to_play: str, file_to_record: str, on_start, on_finish, on_
|
||||||
utils.log(f'Playing device resolved to {AUDIO_DEV_PLAY}')
|
utils.log(f'Playing device resolved to {AUDIO_DEV_PLAY}')
|
||||||
|
|
||||||
# Monitoring start time
|
# Monitoring start time
|
||||||
timestamp_start = time.monotonic()
|
timestamp_start = utils.get_monotonic_time()
|
||||||
|
|
||||||
# Call start time
|
# Call start time
|
||||||
timestamp_call = None
|
timestamp_call = None
|
||||||
if ROLE == Role.Caller:
|
if ROLE == Role.Caller:
|
||||||
timestamp_call = time.monotonic()
|
timestamp_call = utils.get_monotonic_time()
|
||||||
|
|
||||||
# Should call to be stopped ?
|
# Should call to be stopped ?
|
||||||
force_call_stop = False
|
force_call_stop = False
|
||||||
|
|
@ -295,7 +295,7 @@ def gsm_monitor(file_to_play: str, file_to_record: str, on_start, on_finish, on_
|
||||||
# Read logcat output line by line
|
# Read logcat output line by line
|
||||||
while True:
|
while True:
|
||||||
# Check if time limit is hit
|
# Check if time limit is hit
|
||||||
if time.monotonic() - timestamp_start > TIME_LIMIT_MONITORING:
|
if utils.get_monotonic_time() - timestamp_start > TIME_LIMIT_MONITORING:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Check if limit of calls hit
|
# Check if limit of calls hit
|
||||||
|
|
@ -304,7 +304,7 @@ def gsm_monitor(file_to_play: str, file_to_record: str, on_start, on_finish, on_
|
||||||
|
|
||||||
# Check if call hit maximum length - smth goes weird, exit from the script
|
# Check if call hit maximum length - smth goes weird, exit from the script
|
||||||
if timestamp_call:
|
if timestamp_call:
|
||||||
if time.monotonic() - timestamp_call > TIME_LIMIT_CALL:
|
if util.get_monotonic_time() - timestamp_call > TIME_LIMIT_CALL:
|
||||||
utils.log_verbose(f'Call time limit ({TIME_LIMIT_CALL}s). Stop the call.')
|
utils.log_verbose(f'Call time limit ({TIME_LIMIT_CALL}s). Stop the call.')
|
||||||
timestamp_call = None
|
timestamp_call = None
|
||||||
|
|
||||||
|
|
@ -419,7 +419,7 @@ def gsm_monitor(file_to_play: str, file_to_record: str, on_start, on_finish, on_
|
||||||
utils.log_verbose(f'Detected call start notification from the mobile helper app, trying to start audio.')
|
utils.log_verbose(f'Detected call start notification from the mobile helper app, trying to start audio.')
|
||||||
|
|
||||||
# Save call start time
|
# Save call start time
|
||||||
timestamp_call = time.monotonic()
|
timestamp_call = utils.get_monotonic_time()
|
||||||
|
|
||||||
# Is audio failed
|
# Is audio failed
|
||||||
audio_failed = False
|
audio_failed = False
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@ import utils
|
||||||
import json
|
import json
|
||||||
from crontab import CronTab
|
from crontab import CronTab
|
||||||
|
|
||||||
start_system_time = time.time()
|
|
||||||
start_monotonic_time = time.monotonic()
|
|
||||||
|
|
||||||
|
|
||||||
class Phone:
|
class Phone:
|
||||||
identifier: int = 0
|
identifier: int = 0
|
||||||
|
|
@ -112,20 +109,20 @@ class TaskList:
|
||||||
|
|
||||||
# https://crontab.guru is good for crontab strings generation
|
# https://crontab.guru is good for crontab strings generation
|
||||||
# Use monotonic time source!
|
# Use monotonic time source!
|
||||||
current_time = time.monotonic()
|
current_time = utils.get_monotonic_time()
|
||||||
for task in self.tasks:
|
for task in self.tasks:
|
||||||
if 'scheduled_time' not in task and 'schedule' in task:
|
if 'scheduled_time' not in task and 'schedule' in task:
|
||||||
# No schedule flag, so time to schedule
|
# No schedule flag, so time to schedule
|
||||||
try:
|
try:
|
||||||
cron_string = task['schedule'].strip()
|
cron_string = task['schedule'].strip()
|
||||||
if cron_string == '* * * * *':
|
if cron_string == '* * * * *':
|
||||||
task['scheduled_time'] = time.monotonic() - 0.001 # To ensure further comparison will not be affected by precision errors
|
task['scheduled_time'] = utils.get_monotonic_time() - 0.001 # To ensure further comparison will not be affected by precision errors
|
||||||
else:
|
else:
|
||||||
cron = CronTab(task['schedule'])
|
cron = CronTab(task['schedule'])
|
||||||
task['scheduled_time'] = current_time + cron.next(default_utc=True)
|
task['scheduled_time'] = current_time + cron.next(default_utc=True)
|
||||||
|
|
||||||
# Just to help in further log reading & debugging - show the scheduled time in readable form
|
# Just to help in further log reading & debugging - show the scheduled time in readable form
|
||||||
task['scheduled_time_str'] = time.ctime(task['scheduled_time'] - start_monotonic_time + start_system_time)
|
task['scheduled_time_str'] = time.ctime(task['scheduled_time'])
|
||||||
except:
|
except:
|
||||||
utils.log_error("Error", sys.exc_info()[0])
|
utils.log_error("Error", sys.exc_info()[0])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue