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

Source Code for Module phones.com_moto_cdma

  1  ### BITPIM 
  2  ### 
  3  ### Copyright (C) 2006 Joe Pham <djpham@bitpim.org> 
  4  ### 
  5  ### This program is free software; you can redistribute it and/or modify 
  6  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  7  ### 
  8  ### $Id: com_moto.py 3641 2006-11-08 02:43:05Z sawecw $ 
  9   
 10  """Communicate with Motorola CDMA phones using AT commands""" 
 11   
 12  import commport 
 13  import com_moto 
 14  import com_brew 
 15   
16 -class Phone(com_moto.Phone, com_brew.BrewProtocol):
17 _switch_mode_cmd='\x44\x58\xf4\x7e' 18
19 - def __init__(self, logtarget, commport):
20 com_moto.Phone.__init__(self, logtarget, commport) 21 com_brew.BrewProtocol.__init__(self)
22
23 - def _setmodephonebooktobrew(self):
24 self.setmode(self.MODEMODEM) 25 self.setmode(self.MODEBREW) 26 return True
27
28 - def _setmodemodemtobrew(self):
29 self.log('Switching from modem to BREW') 30 try: 31 self.comm.sendatcommand('$QCDMG') 32 return True 33 except: 34 pass 35 # give it another try 36 self.log('Retry switching from modem to BREW') 37 try: 38 self.comm.sendatcommand('$QCDMG') 39 return True 40 except commport.ATError: 41 return False 42 except: 43 if __debug__: 44 self.log('Got an excepetion') 45 return False
46
47 - def _setmodebrew(self):
48 # switch from None to BREW 49 self.log('Switching from None to BREW') 50 # do it the long, but sure, way: 1st try to switch to modem 51 if not self._setmodemodem(): 52 # can't switch to modem, give up 53 return False 54 # then switch from modem to BREW 55 return self._setmodemodemtobrew()
56
57 - def _setmodebrewtomodem(self):
58 self.log('Switching from BREW to modem') 59 try: 60 self.comm.write(self._switch_mode_cmd, False) 61 self.comm.readsome(numchars=5, log=False) 62 return True 63 except: 64 pass 65 # give it a 2nd try 66 try: 67 self.comm.write(self._switch_mode_cmd, False) 68 self.comm.readsome(numchars=5, log=False) 69 return True 70 except: 71 return False
72
73 - def _setmodemodem(self):
74 # ask parent to do it 75 if super(Phone,self)._setmodemodem(): 76 return True 77 # could be in BREW mode, try switch over 78 self.log('trying to switch from BREW mode') 79 if not self._setmodebrewtomodem(): 80 return False 81 try: 82 self.comm.sendatcommand('E0V1') 83 self.set_mode(self.protocolclass.MODE_MODEM) 84 return True 85 except: 86 return False
87 88 # Ringtones & wallpaper sutff------------------------------------------------------------
89 - def _read_media(self, index_key, fundamentals):
90 """Read the contents of media files and return""" 91 _media={} 92 for _key,_entry in fundamentals.get(index_key, {}).items(): 93 if _entry.get('filename', None): 94 # this one associates with a file, try to read it 95 try: 96 _media[_entry['name']]=self.getfilecontents(_entry['filename'], 97 True) 98 except (com_brew.BrewNoSuchFileException, 99 com_brew.BrewBadPathnameException, 100 com_brew.BrewNameTooLongException, 101 com_brew.BrewAccessDeniedException): 102 self.log("Failed to read media file: %s"%_entry['name']) 103 except: 104 self.log('Failed to read media file.') 105 if __debug__: 106 raise 107 return _media
108
109 - def getringtones(self, fundamentals):
110 """Retrieve ringtones data""" 111 self.log('Reading ringtones') 112 self.setmode(self.MODEPHONEBOOK) 113 self.setmode(self.MODEBREW) 114 try: 115 fundamentals['ringtone']=self._read_media('ringtone-index', 116 fundamentals) 117 except: 118 if __debug__: 119 raise 120 self.setmode(self.MODEMODEM) 121 return fundamentals
122
123 - def getwallpapers(self, fundamentals):
124 """Retrieve wallpaper data""" 125 self.log('Reading wallpapers') 126 self.setmode(self.MODEPHONEBOOK) 127 self.setmode(self.MODEBREW) 128 try: 129 fundamentals['wallpapers']=self._read_media('wallpaper-index', 130 fundamentals) 131 except: 132 if __debug__: 133 raise 134 self.setmode(self.MODEMODEM) 135 return fundamentals
136
137 -class Profile(com_moto.Profile):
138 pass
139