Package phones ::
Module com_phone
|
|
1
2
3
4
5
6
7
8
9
10
11 """Generic phone stuff that all models inherit from"""
12
13
14 import common
15 import commport
16 import copy
17 import field_color
18 import re
19 import sys
20 import time
21 import prototypes
22
23
24
25
26
27 modeignoreerrortypes=[ commport.CommTimeout,common.CommsDeviceNeedsAttention ]
28 try:
29 import pywintypes
30 modeignoreerrortypes.append(pywintypes.error)
31 except:
32 pass
33
34
35 modeignoreerrortypes=tuple(modeignoreerrortypes)
36
37
39 """Base class for all phones"""
40
41 MODENONE="modenone"
42 MODEMODEM="modemodem"
43
44 desc="Someone forget to set desc in derived class"
45
46 - def __init__(self, logtarget, commport):
47 self.logtarget=logtarget
48 self.comm=commport
49 self.mode=self.MODENONE
50 self.__msg=None
51
53 self.comm.close()
54 self.comm=None
55
57 "Log a message"
58 if self.logtarget:
59 self.logtarget.log("%s: %s" % (self.desc, str))
60
61 - def logdata(self, str, data, klass=None):
62 "Log some data with option data object/class for the analyser"
63 if self.logtarget:
64 self.logtarget.logdata("%s: %s" % (self.desc, str), data, klass)
65
66 - def alert(self, message, wait):
67 """Raises an alert in the main thread
68
69 @param message: The message to display
70 @param wait: Should this function block until the user confirms the message
71 """
72 assert not wait
73 assert self.logtarget
74 self.logtarget.log("<!= alert wait=%s =!>%s: %s" % (`wait`, self.desc, message))
75
77 "Update the progress meter"
78 if self.logtarget:
79 self.logtarget.progress(pos, max, desc)
80
82 "Raise a comms DeviceNeedsAttention Exception"
83 self.mode=self.MODENONE
84 self.comm.shouldloop=True
85 raise common.CommsDeviceNeedsAttention( "The phone is not responding while "+str+".\n\nSee the help for troubleshooting tips", self.desc+" on "+self.comm.port)
86
88 self.mode=self.MODENONE
89 raise klass(str, self.desc+" on "+self.comm.port)
90
92 "Ensure the phone is in the right mode"
93 if self.mode==desiredmode: return
94
95 strmode=None
96 strdesiredmode=None
97 for v in dir(self):
98 if len(v)>len('MODE') and v[:4]=='MODE':
99 if self.mode==getattr(self, v):
100 strmode=v[4:]
101 if desiredmode==getattr(self,v):
102 strdesiredmode=v[4:]
103 if strmode is None:
104 raise Exception("No mode for %s" %(self.mode,))
105 if strdesiredmode is None:
106 raise Exception("No desired mode for %s" %(desiredmode,))
107 strmode=strmode.lower()
108 strdesiredmode=strdesiredmode.lower()
109
110 for func in ( '_setmode%sto%s' % (strmode, strdesiredmode),
111 '_setmode%s' % (strdesiredmode,)):
112 if hasattr(self,func):
113 try:
114 res=getattr(self, func)()
115 except modeignoreerrortypes:
116 res=False
117 if res:
118 self.mode=desiredmode
119 self.log("Now in "+strdesiredmode+" mode")
120 return
121
122
123 self.mode=self.MODENONE
124 while self.comm.IsAuto():
125 self.comm.NextAutoPort()
126 return self.setmode(desiredmode)
127 self.raisecommsdnaexception("transitioning mode from %s to %s" \
128 % (strmode, strdesiredmode))
129
130
132 for baud in (0, 115200, 38400, 19200, 230400):
133 if baud:
134 if not self.comm.setbaudrate(baud):
135 continue
136 self.comm.write("AT\r\n")
137 try:
138 self.comm.readsome()
139 return True
140 except modeignoreerrortypes:
141 pass
142 return False
143
144 - def readobject(self, filename, object_class, logtitle=None,
145 uselocalfs=False):
155
156 - def writeobject(self, filename, obj, logtitle=None,
157 uselocalfs=False):
165
166 getmemo=NotImplemented
167 gettodo=NotImplemented
168 getsms=NotImplemented
169 getcallhistory=NotImplemented
170 getplaylist=NotImplemented
171 gett9db=NotImplemented
172
174
175 BP_Calendar_Version=2
176
177 WALLPAPER_WIDTH=100
178 WALLPAPER_HEIGHT=100
179 MAX_WALLPAPER_BASENAME_LENGTH=64
180 WALLPAPER_FILENAME_CHARS="abcdefghijklmnopqrstuvwxyz0123456789 ."
181 WALLPAPER_CONVERT_FORMAT="bmp"
182
183 MAX_RINGTONE_BASENAME_LENGTH=64
184 RINGTONE_FILENAME_CHARS="abcdefghijklmnopqrstuvwxyz0123456789 ."
185 DIALSTRING_CHARS="[^0-9PT#*]"
186
187 field_color_data=field_color.default_field_info
188
189 autodetect_delay=0
190
191
192 reboot_delay=0
193
194
195 usbids=(
196 )
197
198 deviceclasses=("modem", "serial")
199
202
203 _supportedsyncs=(
204 )
205
206 - def SyncQuery(self, source, action, actiontype):
213
214
215 ringtoneorigins=()
216
217
218
219
220 excluded_ringtone_origins=()
221
222
223 excluded_wallpaper_origins=('video',)
224
225
226 stockimageorigins={
227 "images": {'meta-help': 'General images'},
228 "mms": {'meta-help': 'Multimedia Messages'},
229 "drm": {'meta-help': 'DRM protected images'},
230 "camera": {'meta-help': 'Camera images'},
231 "camera-fullsize": {'meta-help': 'Fullsize camera images'},
232 "video": {'meta-help': 'Video clips'},
233 "images(sd)": {'meta-help': 'General images stored on removable media'},
234 "video(sd)": {'meta-help': 'Video clips stored on removable media'},
235 "picture ids": {'meta-help': 'Images used for contact/group Picture ID'},
236 }
237
238 stockimagetargets={
239
240
241 "wallpaper": {'meta-help': 'Display as wallpaper'},
242 "pictureid": {'meta-help': 'Display as picture id for a caller'},
243 "outsidelcd": {'meta-help': 'Display on outside screen'},
244 "fullscreen": {'meta-help': 'Fullscreen such as startup screen'},
245 }
246
247
248
249
250
251 imageorigins={}
252 imageorigins.update(common.getkv(stockimageorigins, "images"))
253 imageorigins.update(common.getkv(stockimageorigins, "mms"))
254 imageorigins.update(common.getkv(stockimageorigins, "camera"))
255 imageorigins["<developerneedstoupdate>"]={'meta-help': "The developer needs to update this phone profile"}
256
260
262 if False:
263
264
265
266 targets={}
267 targets.update(common.getkv(self.stockimagetargets, "wallpaper",
268 {'width': 77, 'height': 177, 'format': "BMP"}))
269 targets.update(common.getkv(self.stockimagetargets, "outsidelcd",
270 {'width': 77, 'height': 77, 'format': "JPEG"}))
271 return targets
272
273 convert_format_map={'bmp': 'BMP',
274 'jpg': 'JPEG',
275 'png': 'PNG'}
276 return common.getkv(self.stockimagetargets, "wallpaper",
277 {'width': self.WALLPAPER_WIDTH,
278 'height': self.WALLPAPER_HEIGHT,
279 'format': convert_format_map[self.WALLPAPER_CONVERT_FORMAT]})
280
281
282
283 - def QueryAudio(self, origin, currentextension, audiofileinfo):
284 """Query for MP3 file support
285
286 Raise an exception if you cannot support the ringtone or any conversion of
287 it.
288
289 @param audiofileinfo: A L{fileinfo.AudioFileInfo} object specifying file's audio properties
290 @param currentextension: The extension currently used by the file
291
292 @return: ("file extension", audiofile object). The file extension
293 (excluding the leading dot) to make the file use. The audiofile
294 object can be what was passed in unaltered meaning the file is
295 fine as is, or make a new one to specify how the file should
296 be converted. Note there is a MAXSIZE attribute if you need
297 to limit file size.
298 """
299
300 return (currentextension, audiofileinfo)
301
303 """Convert the phone number into something the phone understands
304 uses DIALSTRING_CHARS to compare phone number with and strips
305 all other characters from the string
306 """
307 return re.sub(self.DIALSTRING_CHARS, "", str)
308
309
311
314
317
320
323
326
329
332
335
338
341
342 - def getfilecontents(self, name):
343 self.__raisefna("filesystem (getfilecontents)")
344