projects
/
SaveMySugar
/
python3-savemysugar.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
README.md: improve wording when explaining how to measure parameters
[SaveMySugar/python3-savemysugar.git]
/
src
/
savemysugar
/
CallDistanceTransceiver.py
diff --git
a/src/savemysugar/CallDistanceTransceiver.py
b/src/savemysugar/CallDistanceTransceiver.py
index
f9760bb
..
f218bcc
100755
(executable)
--- 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)
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):
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
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):
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 '.'
# received a '.'
- time.sleep(
call_setup_time + (ring_time + ring_uncertainty)
)
- el
se
:
+ time.sleep(
setup_time + self.transceiver.dot_time.dist
)
+ el
if self.ring_count == 2
:
# received a '/'
# 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 += 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__":
if __name__ == "__main__":