Package phones :: Module com_lgc2000
[hide private]
[frames] | no frames]

Source Code for Module phones.com_lgc2000

  1  ### BITPIM 
  2  ### 
  3  ### Copyright (C) 2005 Joe Pham <djpham@bitpim.org> 
  4  ### Copyright (C) 2006 Simon Capper <scapper@sbcglobal.net> 
  5  ### 
  6  ### This program is free software; you can redistribute it and/or modify 
  7  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  8  ### 
  9  ### $Id: com_lgc2000.py 3927 2007-01-22 03:15:22Z rogerb $ 
 10   
 11  """Communicate with the LG C2000 cell phone. This is crappy phone if you want to connect it to 
 12  your PC, I would not recommend it. 
 13  The serial interface is buggy, the phone crashes with the slightest reasons and sometimes this 
 14  requires battery removal to fix . eg. AT+CPBS="LD" followed by AT+CPBR for call history retrieval. 
 15  and refuses to accept file uploads although the commands are reported as supported. 
 16  """ 
 17   
 18  # standard modules 
 19  import base64 
 20  import sha 
 21  import time 
 22   
 23  # BitPim modules 
 24  import bpcalendar 
 25  import common 
 26  import commport 
 27  import com_lgg4015 
 28  import guihelper 
 29  import helpids 
 30  import memo 
 31  import nameparser 
 32  import p_lgc2000 
 33  import prototypes 
 34  import sms 
 35   
36 -class Phone(com_lgg4015.Phone):
37 """ Talk to the LG C2000 Phone""" 38 39 desc='LG-C2000' 40 helpid=helpids.ID_PHONE_LGC2000 41 protocolclass=p_lgc2000 42 serialsname='lgc2000' 43
44 - def __init__(self, logtarget, commport):
45 super(Phone,self).__init__(logtarget, commport) 46 self.mode=self.MODENONE
47
48 - def getfundamentals(self, results):
49 50 """Gets information fundamental to interoperating with the phone and UI. 51 52 Currently this is: 53 54 - 'uniqueserial' a unique serial number representing the phone 55 - 'groups' the phonebook groups 56 57 This method is called before we read the phonebook data or before we 58 write phonebook data. 59 """ 60 # use a hash of ESN and other stuff (being paranoid) 61 self.setmode(self.MODEMODEM) 62 self.log("Retrieving fundamental phone information") 63 self.log("Reading phone serial number") 64 results['uniqueserial']=sha.new(self.get_sim_id()).hexdigest() 65 # now read groups 66 self.log("Reading group information") 67 results['groups']=self._get_groups() 68 # All done 69 self.log("Fundamentals retrieved") 70 return results
71 72 # this function does not work !!!!
73 - def getwallpapers(self, result):
74 self.log('Reading wallpaper index') 75 self.setmode(self.MODEMODEM) 76 self.charset_ascii() 77 self._wallpaper_mode() 78 media={} 79 media_index=self._get_wallpaper_index() 80 81 # Set the media type to be pic (wallpaper) 82 self.charset_ascii() 83 self._wallpaper_mode() 84 # and read the list 85 res={} 86 self._get_image_index(self.protocolclass.MIN_WALLPAPER_INDEX, self.protocolclass.MAX_WALLPAPER_INDEX, 87 res, 0, 'wallpaper') 88 89 # dummy data for wallpaper 90 _dummy_data=file(guihelper.getresourcefile('wallpaper.png'),'rb').read() 91 for e in res.values(): 92 media[e['name']]=_dummy_data 93 94 # Set the media type to be photo 95 self.charset_ascii() 96 self._photo_mode() 97 # and read the list 98 res={} 99 self._get_image_index(self.protocolclass.MIN_PHOTO_INDEX, self.protocolclass.MAX_PHOTO_INDEX, 100 res, 0, 'camera') 101 # read the files out of the phone 102 for e in res.values(): 103 data=self._get_media_file(e['name']) 104 if data != False: 105 print "get OK" 106 media[e['name']]=data 107 else: 108 print "get failed" 109 media[e['name']]=_dummy_data 110 111 result['wallpapers']=media 112 result['wallpaper-index']=media_index 113 return result
114
115 - def _photo_mode(self):
116 _req=self.protocolclass.media_selector_set() 117 _req.media_type=self.protocolclass.MEDIA_PHOTO 118 self.sendATcommand(_req, None)
119
120 - def _get_image_index(self, min, max, res, res_offset, origin):
121 _req=self.protocolclass.media_list_req() 122 _req.start_index=min 123 _req.end_index=max 124 _res=self.sendATcommand(_req, self.protocolclass.media_list_resp) 125 for i,e in enumerate(_res): 126 res[i+res_offset]={ 'name': e.file_name, 'origin': origin, 'size':e.size }
127
128 - def _get_wallpaper_index(self):
129 """ Return the wallpaper index""" 130 res={} 131 # Set the media type to be pic (wallpaper) 132 self.charset_ascii() 133 self._wallpaper_mode() 134 # and read the list 135 self._get_image_index(self.protocolclass.MIN_WALLPAPER_INDEX, self.protocolclass.MAX_WALLPAPER_INDEX, 136 res, 0, 'wallpaper') 137 # Set the media type to be photo 138 self.charset_ascii() 139 self._photo_mode() 140 # and read the list 141 # this command only seems to retrieve the first photo in the phone, so it is kindof useless 142 self._get_image_index(self.protocolclass.MIN_PHOTO_INDEX, self.protocolclass.MAX_PHOTO_INDEX, 143 res, self.protocolclass.MAX_WALLPAPER_INDEX, 'camera') 144 return res
145 146 # this function only retrieves the beginning of the file 147 # the phone sends a chunk of data follow by the '@' sign. 148 # I have not found a way to make it send the rest of the file 149 # the data that is sent is valid after being decoded
150 - def _get_media_file(self, file_name):
151 """ Read a media file 152 """ 153 if not file_name: 154 return False 155 self.log('Writing media %s'%file_name) 156 _cmd='AT+DDLU=0,"%s"\r' % file_name 157 self.comm.write(str(_cmd)) 158 # strip for the start of the response 159 self.comm.readuntil('>') 160 self.comm.read(1) 161 # read the raw file data 162 _data64=self.comm.readuntil('@') 163 # convert to binary 164 data=base64.decodestring(_data64[:-1]) 165 if self.comm.read(10)!='\n\r\r\n\r\nOK\r\n': 166 return False 167 # need to figure out how to make phone send rest of file 168 return data
169 170 #------------------------------------------------------------------------------- 171 parent_profile=com_lgg4015.Profile
172 -class Profile(parent_profile):
173 174 serialsname=Phone.serialsname 175 176 WALLPAPER_WIDTH=128 177 WALLPAPER_HEIGHT=128 178 MAX_WALLPAPER_BASENAME_LENGTH=19 179 WALLPAPER_FILENAME_CHARS="abcdefghijklmnopqrstuvwxyz0123456789_ ." 180 WALLPAPER_CONVERT_FORMAT="jpg" 181 MAX_RINGTONE_BASENAME_LENGTH=19 182 RINGTONE_FILENAME_CHARS="abcdefghijklmnopqrstuvwxyz0123456789_ ." 183 RINGTONE_LIMITS= { 184 'MAXSIZE': 20480 185 } 186 # use for auto-detection 187 phone_manufacturer='LGE' 188 phone_model='C2000' 189 190 usbids=( ( 0x10AB, 0x10C5, 1), 191 ( 0x067b, 0x2303, None), # VID=Prolific, PID=USB to serial 192 ) 193 deviceclasses=("serial",) 194
195 - def __init__(self):
196 parent_profile.__init__(self)
197 198 _supportedsyncs=( 199 ('phonebook', 'read', None), # all phonebook reading 200 ('phonebook', 'write', 'OVERWRITE'), # only overwriting phonebook 201 ('calendar', 'read', None), # all calendar reading 202 ('calendar', 'write', 'OVERWRITE'), # only overwriting calendar 203 # these features appear to be crippled, they seem to work from looking at the 204 # responses from the phone, but the phone crashes and none of the transfered 205 # data appears on the phone 206 #('ringtone', 'read', None), # all ringtone reading 207 #('ringtone', 'write', 'OVERWRITE'), 208 #('wallpaper', 'read', None), # all wallpaper reading 209 #('wallpaper', 'write', 'OVERWRITE'), 210 ('memo', 'read', None), # all memo list reading 211 ('memo', 'write', 'OVERWRITE'), # all memo list writing 212 ('sms', 'read', None), # all SMS list reading 213 # this phone hangs when you try to read the call history, even though it "claims" to 214 # support the commands when you query it using AT+CLAC, I only tested with the call history 215 # empty. 216 # ('call_history', 'read', None), 217 ) 218
219 - def convertphonebooktophone(self, helper, data):
220 return data
221