X-Git-Url: https://git.ao2.it/SaveMySugar/python3-savemysugar.git/blobdiff_plain/88fce7811221c360966eb3af691a719930a2514d..337e26941d8fb2aba2fc76c486e269005f9986b2:/src/measure_call_setup_time.py?ds=sidebyside diff --git a/src/measure_call_setup_time.py b/src/measure_call_setup_time.py index 6268145..57bf49a 100755 --- a/src/measure_call_setup_time.py +++ b/src/measure_call_setup_time.py @@ -28,9 +28,8 @@ class Ring(object): def on_ring(): if Ring.time == -1: - print("First ring") Ring.time = time.time() - raise StopIteration("We just want the first ring") + raise StopIteration("Got the ring we were waiting for") def measure_call_setup_time(ingoing_port, outgoing_port, destination_number): @@ -48,8 +47,8 @@ def measure_call_setup_time(ingoing_port, outgoing_port, destination_number): for i in range(5): print() - print("Attempt: %s" % (i + 1)) - outgoing_modem.send_command("ATDT" + destination_number) + print("Call: %s" % (i + 1)) + outgoing_modem.send_command("ATDT" + destination_number + ";") dial_time = time.time() # Wait for the receiver to get a ring before terminating the call @@ -61,26 +60,16 @@ def measure_call_setup_time(ingoing_port, outgoing_port, destination_number): hangup_time = time.time() - # When dialing with an analog modem I noticed that if calls are - # separated one from another they take less time to set up, this - # may be due to how an analog modem works: getting it on-hook and - # off-hook takes quite some time. - inter_call_sleep = 5.2 - print("After hangup sleeping %.2f sec..." % inter_call_sleep) - time.sleep(inter_call_sleep) - call_setup_time = Ring.time - dial_time min_call_setup_time = min(min_call_setup_time, call_setup_time) max_call_setup_time = max(max_call_setup_time, call_setup_time) avg_call_setup_time = cumulative_average(avg_call_setup_time, i + 1, call_setup_time) - uncertainty = (max_call_setup_time - min_call_setup_time) / 2. print("Call setup time: %f" % call_setup_time) print("Min call setup time: %f" % min_call_setup_time) print("Max call setup time: %f" % max_call_setup_time) print("Average call setup time: %f" % avg_call_setup_time) - print("Call setup time uncertainty: %f" % uncertainty) print() call_time = hangup_time - dial_time @@ -90,8 +79,17 @@ def measure_call_setup_time(ingoing_port, outgoing_port, destination_number): print("Min call time: %f" % min_call_time) print("Max call time: %f" % max_call_time) print() + Ring.time = -1 + # When dialing with an analog modem I noticed that if calls are + # separated one from another they take less time to set up, this + # may be due to how an analog modem works: getting it on-hook and + # off-hook takes quite some time. + inter_call_sleep = 5.2 + print("Sleeping %.2f sec before the next call..." % inter_call_sleep) + time.sleep(inter_call_sleep) + def main(): import sys