0001 ### BITPIM 0002 ### 0003 ### Copyright (C) 2006 Joe Pham <djpham@bitpim.org> 0004 ### 0005 ### This program is free software; you can redistribute it and/or modify 0006 ### it under the terms of the BitPim license as detailed in the LICENSE file. 0007 ### 0008 ### $Id: com_moto.py 3641 2006-11-08 02:43:05Z sawecw $ 0009 0010 """Communicate with Motorola CDMA phones using AT commands""" 0011 0012 import commport 0013 import com_moto 0014 import com_brew 0015 0016 class Phone(com_moto.Phone, com_brew.BrewProtocol): 0017 _switch_mode_cmd='\x44\x58\xf4\x7e' 0018 0019 def __init__(self, logtarget, commport): 0020 com_moto.Phone.__init__(self, logtarget, commport) 0021 com_brew.BrewProtocol.__init__(self) 0022 0023 def _setmodephonebooktobrew(self): 0024 self.setmode(self.MODEMODEM) 0025 self.setmode(self.MODEBREW) 0026 return True 0027 0028 def _setmodemodemtobrew(self): 0029 self.log('Switching from modem to BREW') 0030 try: 0031 self.comm.sendatcommand('$QCDMG') 0032 return True 0033 except: 0034 pass 0035 # give it another try 0036 self.log('Retry switching from modem to BREW') 0037 try: 0038 self.comm.sendatcommand('$QCDMG') 0039 return True 0040 except commport.ATError: 0041 return False 0042 except: 0043 if __debug__: 0044 self.log('Got an excepetion') 0045 return False 0046 0047 def _setmodebrew(self): 0048 # switch from None to BREW 0049 self.log('Switching from None to BREW') 0050 # do it the long, but sure, way: 1st try to switch to modem 0051 if not self._setmodemodem(): 0052 # can't switch to modem, give up 0053 return False 0054 # then switch from modem to BREW 0055 return self._setmodemodemtobrew() 0056 0057 def _setmodebrewtomodem(self): 0058 self.log('Switching from BREW to modem') 0059 try: 0060 self.comm.write(self._switch_mode_cmd, False) 0061 self.comm.readsome(numchars=5, log=False) 0062 return True 0063 except: 0064 pass 0065 # give it a 2nd try 0066 try: 0067 self.comm.write(self._switch_mode_cmd, False) 0068 self.comm.readsome(numchars=5, log=False) 0069 return True 0070 except: 0071 return False 0072 0073 def _setmodemodem(self): 0074 # ask parent to do it 0075 if super(Phone,self)._setmodemodem(): 0076 return True 0077 # could be in BREW mode, try switch over 0078 self.log('trying to switch from BREW mode') 0079 if not self._setmodebrewtomodem(): 0080 return False 0081 try: 0082 self.comm.sendatcommand('E0V1') 0083 self.set_mode(self.protocolclass.MODE_MODEM) 0084 return True 0085 except: 0086 return False 0087 0088 # Ringtones & wallpaper sutff------------------------------------------------------------ 0089 def _read_media(self, index_key, fundamentals): 0090 """Read the contents of media files and return""" 0091 _media={} 0092 for _key,_entry in fundamentals.get(index_key, {}).items(): 0093 if _entry.get('filename', None): 0094 # this one associates with a file, try to read it 0095 try: 0096 _media[_entry['name']]=self.getfilecontents(_entry['filename'], 0097 True) 0098 except (com_brew.BrewNoSuchFileException, 0099 com_brew.BrewBadPathnameException, 0100 com_brew.BrewNameTooLongException, 0101 com_brew.BrewAccessDeniedException): 0102 self.log("Failed to read media file: %s"%_entry['name']) 0103 except: 0104 self.log('Failed to read media file.') 0105 if __debug__: 0106 raise 0107 return _media 0108 0109 def getringtones(self, fundamentals): 0110 """Retrieve ringtones data""" 0111 self.log('Reading ringtones') 0112 self.setmode(self.MODEPHONEBOOK) 0113 self.setmode(self.MODEBREW) 0114 try: 0115 fundamentals['ringtone']=self._read_media('ringtone-index', 0116 fundamentals) 0117 except: 0118 if __debug__: 0119 raise 0120 self.setmode(self.MODEMODEM) 0121 return fundamentals 0122 0123 def getwallpapers(self, fundamentals): 0124 """Retrieve wallpaper data""" 0125 self.log('Reading wallpapers') 0126 self.setmode(self.MODEPHONEBOOK) 0127 self.setmode(self.MODEBREW) 0128 try: 0129 fundamentals['wallpapers']=self._read_media('wallpaper-index', 0130 fundamentals) 0131 except: 0132 if __debug__: 0133 raise 0134 self.setmode(self.MODEMODEM) 0135 return fundamentals 0136 0137 class Profile(com_moto.Profile): 0138 pass 0139
Generated by PyXR 0.9.4