X-Git-Url: https://git.ao2.it/SaveMySugar/python3-savemysugar.git/blobdiff_plain/e971070b0f5b089547adedcb0517831195115fcc..ad407cd783f7a685e85788980bd32608e8837791:/src/savemysugar/CallDistanceTransceiver.py?ds=inline diff --git a/src/savemysugar/CallDistanceTransceiver.py b/src/savemysugar/CallDistanceTransceiver.py index f9760bb..f218bcc 100755 --- a/src/savemysugar/CallDistanceTransceiver.py +++ b/src/savemysugar/CallDistanceTransceiver.py @@ -383,34 +383,63 @@ class CallDistanceTransceiver(object): def test_send_receive(): logging.basicConfig(level=logging.DEBUG) - call_setup_time = 2 - call_setup_uncertainty = 0.4 - ring_time = 1 - ring_uncertainty = 0.3 + call_setup_time_min = 0 + call_setup_time_max = 0.01 + ring_time_min = 0 + ring_time_max = 0 + + import random class DummyModem(object): - """Always receive a '.' and then a '/', which result in 'E '.""" + """Always receive a '.', a '/' and then EOM, which results in 'E '.""" def __init__(self): self.ring_count = 0 + # Take trasmission times from a transceiver + self.transceiver = None + + random.seed(None) + def send_command(self, command): pass def get_response(self, response): - if self.ring_count % 2: + # pylint: disable=unused-argument + + setup_time = random.uniform(self.transceiver.call_setup_time_min, + self.transceiver.call_setup_time_max) + + if self.ring_count == 0: + # dummy ring + pass + elif self.ring_count == 1: # received a '.' - time.sleep(call_setup_time + (ring_time + ring_uncertainty)) - else: + time.sleep(setup_time + self.transceiver.dot_time.dist) + elif self.ring_count == 2: # received a '/' - time.sleep(call_setup_time + (ring_time + ring_uncertainty) * 4) + time.sleep(setup_time + self.transceiver.wordspace_time.dist) + else: + # received an 'EOM' + time.sleep(setup_time + self.transceiver.eom_time.dist) self.ring_count += 1 + self.ring_count %= 4 + + modem = DummyModem() + + xcv = CallDistanceTransceiver(modem, + call_setup_time_min, call_setup_time_max, + ring_time_min, ring_time_max, True) + + modem.transceiver = xcv - xcv = CallDistanceTransceiver(DummyModem(), call_setup_time, - call_setup_uncertainty, ring_time, - ring_uncertainty) - xcv.receive_loop() + while True: + xcv.receive_loop() + modem.ring_count = 0 + print() + print("Message received!") + print("\"%s\"" % xcv.get_text(), flush=True) if __name__ == "__main__":