From: Antonio Ospite Date: Thu, 24 Dec 2015 09:34:28 +0000 (+0100) Subject: CallDistanceTransceiver.py: make test_send_receive() use the new scheme X-Git-Url: https://git.ao2.it/SaveMySugar/python3-savemysugar.git/commitdiff_plain/66972b0e35845c0094880c35576a9505762a1381 CallDistanceTransceiver.py: make test_send_receive() use the new scheme In test_send_receive() use the new way of passing parameters to CallDistanceTransceiver, and while at it, improve the test adding some randomness. --- 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__":