Discussion:
[Bitpim-devel] TM520 Phonebook read routine
Chris Poon
2004-02-19 08:41:13 UTC
Permalink
Took me a while, but I think we can move the getphonebook routine to
the com_lg module, as long as it calls another function to handle
the initialization (I called it pbinit inside com_lgtm520). The init
routine will just return the number of entries in the phonebook so that
the getphonebook routine can display the info in the log pane...

Patches to come...
Roger Binns
2004-02-19 09:00:42 UTC
Permalink
Post by Chris Poon
Took me a while, but I think we can move the getphonebook routine to
the com_lg module, as long as it calls another function to handle
the initialization (I called it pbinit inside com_lgtm520). The init
routine will just return the number of entries in the phonebook so that
the getphonebook routine can display the info in the log pane...
Patches to come...
You need to hoist the method out of com_lgvx4400.py as well so they
share the common code in com_lg.

When you get bored with that, there is also the saving phonebook
routine to do. On that phone I think you have to send a pbstartsyncrequest
at the begining and pbendsyncrequest at the end. The latter results in
the phone rebooting, and if you don't call it, the phone reboots after
a minute of idle time anyway. Fortunately the VX4400 and VX6000 don't
need it.

Roger
Chris Poon
2004-02-20 17:09:18 UTC
Permalink
I did hoist the getphonebook method out of the VX4400, and given how
the initialization is different, I have changed it a bit so that the
TM520-specific code is moved out of the getphonebook function. It seems
that the TM520 will always reboot the phone after PhoneBook sync so
you don't really need to explicitly switch to BREW mode (and doing so
actually break things with the TM520). I have included the snippet of
the code relating to getphonebook here for now as I'm not quite done
with the rest of the changes.

def pbinit(self):
req=self.protocolclass.pbstartsyncrequest()
self.sendpbcommand(req, self.protocolclass.pbstartsyncresponse)

req=self.protocolclass.pbinitrequest()
res=self.sendpbcommand(req, self.protocolclass.pbinitresponse)

count = res.numentries

req=self.protocolclass.pbinforequest()
res=self.sendpbcommand(req, self.protocolclass.pbnextentryresponse) ##
NOT inforesponse

return count

def pregetpb(self,result):
index={}
try:
buf=prototypes.buffer(self.getfilecontents("pim/midiringer.dat"))
except com_brew.BrewNoSuchFileException:
# file may not exist
return index
g=self.protocolclass.ringindex()
g.readfrombuffer(buf)
for i in g.items:
if i.name != "default":
index[i.index+1]=i.name[len('ringer/'):]
return index

def getphonebook(self,result):
"""Reads the phonebook data. The L{getfundamentals} information will
already be in result."""
pbook={}
# Bug in the phone. if you repeatedly read the phone book it starts
# returning a random number as the number of entries. We get around
# this by switching into brew mode which clears that.
#self.mode=self.MODENONE
#self.setmode(self.MODEBREW)

result['intermediate'] = self.pregetpb(result)
self.log("Reading number of phonebook entries")

numentries=self.pbinit()
self.log("There are %d entries" % (numentries,))
for i in range(0, numentries):
### Read current entry
req=self.protocolclass.pbreadentryrequest()
res=self.sendpbcommand(req, self.protocolclass.pbreadentryresponse)
self.log("Read entry "+`i`+" - "+res.entry.name)
entry=self.extractphonebookentry(res.entry, result)
pbook[i]=entry
self.progress(i, numentries, res.entry.name)
#### Advance to next entry
req=self.protocolclass.pbnextentryrequest()
self.sendpbcommand(req, self.protocolclass.pbnextentryresponse)

self.progress(numentries, numentries, "Phone book read completed")
result['phonebook']=pbook
cats=[]
for i in result['groups']:
if result['groups'][i]['name']!='No Group':
cats.append(result['groups'][i]['name'])
result['categories']=cats
del result['intermediate']
print "returning keys",result.keys()
return pbook

PS - with the TM520, phonebook sync must be the last operation if you
selected multiple things with Get Phone Data. Is that the case with
the VX4400? The reason being that TM520 will always reboot after getting
the phonebook so you have to do everything else before that (ringtones
and calendar)
Roger Binns
2004-02-20 22:29:38 UTC
Permalink
Post by Chris Poon
buf=prototypes.buffer(self.getfilecontents("pim/midiringer.dat"))
That should be done in the getfundamentals code.
Post by Chris Poon
PS - with the TM520, phonebook sync must be the last operation if you
selected multiple things with Get Phone Data. Is that the case with
the VX4400? The reason being that TM520 will always reboot after getting
the phonebook so you have to do everything else before that (ringtones
and calendar)
When writing the phonebook is done last. That is because you may be
updating ringtones/wallpapers and the ids need to be known first.

I could change the reading to be in "reverse" order as well. The
4400/6000 do not need the start/end sync commands. However if you
do supply the start sync, the screen goes into a synchronisation
mode, and you have to reboot afterwards either through an explicit
end sync command, or by there being one minute of no activity.

Roger

Loading...