0001 ### BITPIM 0002 ### 0003 ### Copyright (C) 2005 Joe Pham <djpham@bitpim.org> 0004 ### Copyright (C) 2006 Simon Capper <scapper@sbcglobal.net> 0005 ### 0006 ### This program is free software; you can redistribute it and/or modify 0007 ### it under the terms of the BitPim license as detailed in the LICENSE file. 0008 ### 0009 ### $Id: com_lgc2000.py 3927 2007-01-22 03:15:22Z rogerb $ 0010 0011 """Communicate with the LG C2000 cell phone. This is crappy phone if you want to connect it to 0012 your PC, I would not recommend it. 0013 The serial interface is buggy, the phone crashes with the slightest reasons and sometimes this 0014 requires battery removal to fix . eg. AT+CPBS="LD" followed by AT+CPBR for call history retrieval. 0015 and refuses to accept file uploads although the commands are reported as supported. 0016 """ 0017 0018 # standard modules 0019 import base64 0020 import sha 0021 import time 0022 0023 # BitPim modules 0024 import bpcalendar 0025 import common 0026 import commport 0027 import com_lgg4015 0028 import guihelper 0029 import helpids 0030 import memo 0031 import nameparser 0032 import p_lgc2000 0033 import prototypes 0034 import sms 0035 0036 class Phone(com_lgg4015.Phone): 0037 """ Talk to the LG C2000 Phone""" 0038 0039 desc='LG-C2000' 0040 helpid=helpids.ID_PHONE_LGC2000 0041 protocolclass=p_lgc2000 0042 serialsname='lgc2000' 0043 0044 def __init__(self, logtarget, commport): 0045 super(Phone,self).__init__(logtarget, commport) 0046 self.mode=self.MODENONE 0047 0048 def getfundamentals(self, results): 0049 0050 """Gets information fundamental to interoperating with the phone and UI. 0051 0052 Currently this is: 0053 0054 - 'uniqueserial' a unique serial number representing the phone 0055 - 'groups' the phonebook groups 0056 0057 This method is called before we read the phonebook data or before we 0058 write phonebook data. 0059 """ 0060 # use a hash of ESN and other stuff (being paranoid) 0061 self.setmode(self.MODEMODEM) 0062 self.log("Retrieving fundamental phone information") 0063 self.log("Reading phone serial number") 0064 results['uniqueserial']=sha.new(self.get_sim_id()).hexdigest() 0065 # now read groups 0066 self.log("Reading group information") 0067 results['groups']=self._get_groups() 0068 # All done 0069 self.log("Fundamentals retrieved") 0070 return results 0071 0072 # this function does not work !!!! 0073 def getwallpapers(self, result): 0074 self.log('Reading wallpaper index') 0075 self.setmode(self.MODEMODEM) 0076 self.charset_ascii() 0077 self._wallpaper_mode() 0078 media={} 0079 media_index=self._get_wallpaper_index() 0080 0081 # Set the media type to be pic (wallpaper) 0082 self.charset_ascii() 0083 self._wallpaper_mode() 0084 # and read the list 0085 res={} 0086 self._get_image_index(self.protocolclass.MIN_WALLPAPER_INDEX, self.protocolclass.MAX_WALLPAPER_INDEX, 0087 res, 0, 'wallpaper') 0088 0089 # dummy data for wallpaper 0090 _dummy_data=file(guihelper.getresourcefile('wallpaper.png'),'rb').read() 0091 for e in res.values(): 0092 media[e['name']]=_dummy_data 0093 0094 # Set the media type to be photo 0095 self.charset_ascii() 0096 self._photo_mode() 0097 # and read the list 0098 res={} 0099 self._get_image_index(self.protocolclass.MIN_PHOTO_INDEX, self.protocolclass.MAX_PHOTO_INDEX, 0100 res, 0, 'camera') 0101 # read the files out of the phone 0102 for e in res.values(): 0103 data=self._get_media_file(e['name']) 0104 if data != False: 0105 print "get OK" 0106 media[e['name']]=data 0107 else: 0108 print "get failed" 0109 media[e['name']]=_dummy_data 0110 0111 result['wallpapers']=media 0112 result['wallpaper-index']=media_index 0113 return result 0114 0115 def _photo_mode(self): 0116 _req=self.protocolclass.media_selector_set() 0117 _req.media_type=self.protocolclass.MEDIA_PHOTO 0118 self.sendATcommand(_req, None) 0119 0120 def _get_image_index(self, min, max, res, res_offset, origin): 0121 _req=self.protocolclass.media_list_req() 0122 _req.start_index=min 0123 _req.end_index=max 0124 _res=self.sendATcommand(_req, self.protocolclass.media_list_resp) 0125 for i,e in enumerate(_res): 0126 res[i+res_offset]={ 'name': e.file_name, 'origin': origin, 'size':e.size } 0127 0128 def _get_wallpaper_index(self): 0129 """ Return the wallpaper index""" 0130 res={} 0131 # Set the media type to be pic (wallpaper) 0132 self.charset_ascii() 0133 self._wallpaper_mode() 0134 # and read the list 0135 self._get_image_index(self.protocolclass.MIN_WALLPAPER_INDEX, self.protocolclass.MAX_WALLPAPER_INDEX, 0136 res, 0, 'wallpaper') 0137 # Set the media type to be photo 0138 self.charset_ascii() 0139 self._photo_mode() 0140 # and read the list 0141 # this command only seems to retrieve the first photo in the phone, so it is kindof useless 0142 self._get_image_index(self.protocolclass.MIN_PHOTO_INDEX, self.protocolclass.MAX_PHOTO_INDEX, 0143 res, self.protocolclass.MAX_WALLPAPER_INDEX, 'camera') 0144 return res 0145 0146 # this function only retrieves the beginning of the file 0147 # the phone sends a chunk of data follow by the '@' sign. 0148 # I have not found a way to make it send the rest of the file 0149 # the data that is sent is valid after being decoded 0150 def _get_media_file(self, file_name): 0151 """ Read a media file 0152 """ 0153 if not file_name: 0154 return False 0155 self.log('Writing media %s'%file_name) 0156 _cmd='AT+DDLU=0,"%s"\r' % file_name 0157 self.comm.write(str(_cmd)) 0158 # strip for the start of the response 0159 self.comm.readuntil('>') 0160 self.comm.read(1) 0161 # read the raw file data 0162 _data64=self.comm.readuntil('@') 0163 # convert to binary 0164 data=base64.decodestring(_data64[:-1]) 0165 if self.comm.read(10)!='\n\r\r\n\r\nOK\r\n': 0166 return False 0167 # need to figure out how to make phone send rest of file 0168 return data 0169 0170 #------------------------------------------------------------------------------- 0171 parent_profile=com_lgg4015.Profile 0172 class Profile(parent_profile): 0173 0174 serialsname=Phone.serialsname 0175 0176 WALLPAPER_WIDTH=128 0177 WALLPAPER_HEIGHT=128 0178 MAX_WALLPAPER_BASENAME_LENGTH=19 0179 WALLPAPER_FILENAME_CHARS="abcdefghijklmnopqrstuvwxyz0123456789_ ." 0180 WALLPAPER_CONVERT_FORMAT="jpg" 0181 MAX_RINGTONE_BASENAME_LENGTH=19 0182 RINGTONE_FILENAME_CHARS="abcdefghijklmnopqrstuvwxyz0123456789_ ." 0183 RINGTONE_LIMITS= { 0184 'MAXSIZE': 20480 0185 } 0186 # use for auto-detection 0187 phone_manufacturer='LGE' 0188 phone_model='C2000' 0189 0190 usbids=( ( 0x10AB, 0x10C5, 1), 0191 ( 0x067b, 0x2303, None), # VID=Prolific, PID=USB to serial 0192 ) 0193 deviceclasses=("serial",) 0194 0195 def __init__(self): 0196 parent_profile.__init__(self) 0197 0198 _supportedsyncs=( 0199 ('phonebook', 'read', None), # all phonebook reading 0200 ('phonebook', 'write', 'OVERWRITE'), # only overwriting phonebook 0201 ('calendar', 'read', None), # all calendar reading 0202 ('calendar', 'write', 'OVERWRITE'), # only overwriting calendar 0203 # these features appear to be crippled, they seem to work from looking at the 0204 # responses from the phone, but the phone crashes and none of the transfered 0205 # data appears on the phone 0206 #('ringtone', 'read', None), # all ringtone reading 0207 #('ringtone', 'write', 'OVERWRITE'), 0208 #('wallpaper', 'read', None), # all wallpaper reading 0209 #('wallpaper', 'write', 'OVERWRITE'), 0210 ('memo', 'read', None), # all memo list reading 0211 ('memo', 'write', 'OVERWRITE'), # all memo list writing 0212 ('sms', 'read', None), # all SMS list reading 0213 # this phone hangs when you try to read the call history, even though it "claims" to 0214 # support the commands when you query it using AT+CLAC, I only tested with the call history 0215 # empty. 0216 # ('call_history', 'read', None), 0217 ) 0218 0219 def convertphonebooktophone(self, helper, data): 0220 return data 0221
Generated by PyXR 0.9.4