Correct implementation of phone number encoding

This commit is contained in:
Simon Larsson
2020-07-04 10:49:13 +02:00
parent 96e1577bc2
commit 16613028d9
2 changed files with 18 additions and 5 deletions
+6 -2
View File
@@ -19,8 +19,12 @@ program. Much easier than getting it from the CRT!
* Check if all 5 alarms must be sent every time
* Split up DATA1 packets if too long
* Test everything more extensively (most tests have been comparing to
data from the original Timex software)
* Redo the protocol documentation
data from the original Timex software) - set up unit tests
* Work on the protocol documentation
More specific work:
* Implement phone number type/letter support
## "Timex Notebook Adapter"
+12 -3
View File
@@ -40,6 +40,7 @@ class TimexTodo:
return bytes(data)
class TimexPhoneNumber:
# TODO: Do not store numbers as integers, leading zeros will be removed
def __init__(self, number=1, label=""):
self.number=number
self.label=label
@@ -49,13 +50,21 @@ class TimexPhoneNumber:
self.number, self.label)
def __bytes__(self):
# Encoded as four bits per digit and LSD first, always 10 digits
digits = [ord(x)-ord('0') for x in "{:010d}".format(self.number)[::-1]]
data = [d[0]<<4|d[1] for d in zip(digits[0::2], digits[1::2]) ]
# TODO: This only works with numbers 10 digits or less, and no type indication
# Convert to digits
digits = [ord(x)-ord('0') for x in "{:d}".format(self.number)]
# Pad with F
t = [15]*12 # Make a "template" filled with F
t[-2-len(digits):-2] = digits # Replace part of template
# Smush it up
data = [d[1]<<4|d[0] for d in zip(t[0::2], t[1::2]) ]
data = data + pack4to3(str2timex(self.label))
data = [len(data)+1] + data
return bytes(data)
class TimexAnniversary:
def __init__(self, month=0, day=0, label=""):
self.month=month