PyXR

c:\projects\bitpim\src \ phones \ com_etsi.py



0001 ### BITPIM
0002 ###
0003 ### Copyright (C) 2005 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_etsi.py 3927 2007-01-22 03:15:22Z rogerb $
0009 
0010 """Communicate with a GSM phones using AT commands"""
0011 
0012 # system modules
0013 
0014 # BitPim modules
0015 import com_phone
0016 import commport
0017 import prototypes
0018 import p_etsi
0019 
0020 class Phone(com_phone.Phone):
0021     """ Talk to generic GSM phones
0022     """
0023     desc='GSM'
0024     protocolclass=p_etsi
0025 
0026     def __init__(self, logtarget, commport):
0027         super(Phone,self).__init__(logtarget, commport)
0028         self.mode=self.MODENONE
0029 
0030     def sendATcommand(self, request, responseclass, ignoreerror=False):
0031         """Similar to the sendpbcommand in com_sanyo and com_lg, except that
0032         a list of responses is returned, one per line of information returned
0033         from the phone"""
0034 
0035         buffer=prototypes.buffer()
0036         
0037         request.writetobuffer(buffer, logtitle="GSM sendATcommand")
0038         data=buffer.getvalue()
0039 
0040         try:
0041             response_lines=self.comm.sendatcommand(data, ignoreerror=ignoreerror)
0042         except commport.ATError:
0043             raise
0044         except:
0045             self.comm.success=False
0046             self.mode=self.MODENONE
0047             self.raisecommsdnaexception("sending AT command")
0048 
0049         self.comm.success=True
0050 
0051         if responseclass is None:
0052             return response_lines
0053 
0054         reslist=[]
0055         for line in response_lines:
0056             res=responseclass()
0057             buffer=prototypes.buffer(line)
0058             res.readfrombuffer(buffer, logtitle="GSM receive AT response")
0059             reslist.append(res)
0060         return reslist
0061         
0062     def _setmodemodem(self):
0063         self.log("_setmodemodem")
0064         
0065         # Just try waking phone up first
0066         try:
0067             self.comm.sendatcommand("Z")
0068             self.comm.sendatcommand('E0V1')
0069             return True
0070         except:
0071             pass
0072 
0073         # Should be in modem mode.  Wake up the interface
0074         for baud in (0, 115200, 19200, 230400):
0075             self.log("Baud="+`baud`)
0076             if baud:
0077                 if not self.comm.setbaudrate(baud):
0078                     continue
0079             try:
0080                 self.comm.sendatcommand("Z")
0081                 self.comm.sendatcommand('E0V1')
0082                 return True
0083             except:
0084                 pass
0085         return False
0086 
0087     def get_esn(self):
0088         req=self.protocolclass.esnrequest()
0089         res=self.sendATcommand(req, self.protocolclass.esnresponse)
0090         try:
0091             return res[0].esn
0092         except:
0093             return ''
0094 
0095     def get_sim_id(self):
0096         req=self.protocolclass.SIM_ID_Req()
0097         try:
0098             res=self.sendATcommand(req, self.protocolclass.single_value_resp)
0099             return res[0].value
0100         except:
0101             return None
0102 
0103     def get_manufacturer_id(self):
0104         return self.sendATcommand(self.protocolclass.manufacturer_id_req(),
0105                                   self.protocolclass.single_value_resp)[0].value
0106 
0107     def get_model_id(self):
0108         return self.sendATcommand(self.protocolclass.model_id_req(),
0109                                   self.protocolclass.single_value_resp)[0].value
0110 
0111     def get_firmware_version(self):
0112         return self.sendATcommand(self.protocolclass.firmware_version_req(),
0113                                   self.protocolclass.single_value_resp)[0].value
0114 
0115 #-------------------------------------------------------------------------------
0116 
0117 class Profile(com_phone.Profile):
0118     BP_Calendar_Version=3
0119 

Generated by PyXR 0.9.4