forked from Michel2/pytimex
Fix phone numbers, charset and DATA1 splits
* Phone numbers are not stored as strings anymore * Charset has some new symbols (Please find better substitution characters) * Number of DATA1 packets must be in START2 header - fixed!
This commit is contained in:
@@ -41,8 +41,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=""):
|
||||
def __init__(self, number="1", label=""):
|
||||
self.number=number
|
||||
self.label=label
|
||||
|
||||
@@ -53,7 +52,8 @@ class TimexPhoneNumber:
|
||||
def __bytes__(self):
|
||||
# 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)]
|
||||
conv_table = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'C':10,'F':11,'H':12,'P':13,'W':14,' ':15}
|
||||
digits = [conv_table[x] for x in str(self.number)]
|
||||
# Pad with F
|
||||
t = [15]*12 # Make a "template" filled with F
|
||||
t[-2-len(digits):-2] = digits # Replace part of template
|
||||
@@ -101,6 +101,7 @@ class TimexTimezone:
|
||||
def __str__(self):
|
||||
return "Time zone with offset UTC{:+} named \"{}\", {} hour format".format(offset, name, format)
|
||||
|
||||
|
||||
class TimexAlarm:
|
||||
def __init__(self, hour=0, minute=0, month=0, day=0, label="", audible=True):
|
||||
self.hour = hour
|
||||
@@ -128,6 +129,7 @@ class TimexAlarm:
|
||||
return "Alarm at {:02d}:{:02d} on the {} of {}, label \"{}\", {}".format(
|
||||
self.hour, self.minute, self.day, monthNamesAbbr[self.month], self.label, audible_str)
|
||||
|
||||
|
||||
class TimexData:
|
||||
def __init__(self):
|
||||
self.appointments = []
|
||||
@@ -228,7 +230,7 @@ class TimexData:
|
||||
len(self.phonenumbers)>0 or
|
||||
len(self.anniversaries)>0
|
||||
):
|
||||
data += bytes(makeSTART2(1))
|
||||
data += bytes(makeSTART2(DATA1_num_packets(self.appointments, self.todos, self.phonenumbers, self.anniversaries)))
|
||||
data += bytes(makeDATA1(self.appointments, self.todos, self.phonenumbers, self.anniversaries))
|
||||
data += bytes(makeEND1())
|
||||
|
||||
|
||||
+21
-5
@@ -1,6 +1,7 @@
|
||||
# Currently only implemented for model 70.
|
||||
|
||||
from crccheck.crc import CrcArc
|
||||
from math import ceil
|
||||
|
||||
# Create character conversion table (to be verified)
|
||||
# Called at first call of str2timex
|
||||
@@ -19,8 +20,10 @@ char_conv = None
|
||||
def make_char_conv():
|
||||
global char_conv
|
||||
|
||||
# All lowercase characters. Using colon (:) for divide symbol and at (@) for bell symbol
|
||||
dst = "0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./;\\:=@?"
|
||||
# All lowercase characters. Using semicolon (;) for divide symbol and at (@) for bell symbol
|
||||
# Underscore, underscored check mark, left arrow, right arrow, big block, small square/terminator
|
||||
# Small square can be used only on unpacked strings, since on packed strings it is interpreted as a string terminator.
|
||||
dst = "0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:\\;=@?ABCDEF"
|
||||
src = range(len(dst))
|
||||
char_conv = {k:v for k,v in zip(dst,src)}
|
||||
|
||||
@@ -144,11 +147,24 @@ def makeDATA1payload(appts, todos, phones, anniversaries, appt_alarm=0xFF):
|
||||
return payload
|
||||
|
||||
# Takes lists of TimexAppointment, TimexTodo, TimexPhoneNumber
|
||||
# and TimexAnniversary objects
|
||||
def makeDATA1(appts, todos, phones, anniversaries):
|
||||
# and TimexAnniversary objects. Makes DATA1 payload and splits
|
||||
# it up as required
|
||||
def makeDATA1(appts, todos, phones, anniversaries, appt_alarm=0xff):
|
||||
payload = makeDATA1payload(appts, todos, phones, anniversaries, appt_alarm=appt_alarm)
|
||||
data1packets = []
|
||||
index = 0
|
||||
while (payload):
|
||||
index += 1
|
||||
data1packets += makepkg([0x61, index]+payload[:27])
|
||||
payload = payload[27:]
|
||||
|
||||
return data1packets
|
||||
|
||||
# Returns number of packets required for DATA1
|
||||
def DATA1_num_packets(appts, todos, phones, anniversaries, appt_alarm=0xff):
|
||||
data = makeDATA1payload(appts, todos, phones, anniversaries, appt_alarm=appt_alarm)
|
||||
|
||||
return makepkg([0x61, 0x01]+data)
|
||||
return ceil(len(data)/27)
|
||||
|
||||
# Takes lists of TimexAppointment, TimexTodo, TimexPhoneNumber
|
||||
# and TimexAnniversary objects
|
||||
|
||||
Reference in New Issue
Block a user