Exemple #1
0
 def __init__(self, parent):
     super(CommPortPage, self).__init__(parent, 'Communication Port Setting',
                                        'Set the serial port through which BitPim communicates with the phone.')
     self._ports=[{'name': 'auto', 'description': 'BitPim will try to detect the correct port automatically when accessing your phone'}]+\
                  [x for x in comscan.comscan()+usbscan.usbscan() \
                   if x.get('available', False)]
     self._populate()
     self._set_max_size()
 def __init__(self, parent):
     super(CommPortPage, self).__init__(parent, 'Communication Port Setting',
                                        'Set the serial port through which BitPim communicates with the phone.')
     self._ports=[{'name': 'auto', 'description': 'BitPim will try to detect the correct port automatically when accessing your phone'}]+\
                  [x for x in comscan.comscan()+usbscan.usbscan() \
                   if x.get('available', False)]
     self._populate()
     self._set_max_size()
Exemple #3
0
def autoguessports(phonemodule):
    """Returns a list of ports (most likely first) for finding the phone on"""
    # this function also demonsrates the use of list comprehensions :-)
    res = []
    # we only care about available ports
    ports = [(islikelyportscore(port, phonemodule), port)
             for port in comscan.comscan() + usbscan.usbscan() +
             bitflingscan.flinger.scan() if port['available']]
    # sort on score
    ports.sort()
    # return all ones with score >=0
    return [(port['name'], port) for score, port in ports if score >= 0]
Exemple #4
0
def autoguessports(phonemodule):
    """Returns a list of ports (most likely first) for finding the phone on"""
    # this function also demonsrates the use of list comprehensions :-)
    res = []
    # we only care about available ports
    ports = [
        (islikelyportscore(port, phonemodule), port)
        for port in comscan.comscan() + usbscan.usbscan() + bitflingscan.flinger.scan()
        if port["available"]
    ]
    # sort on score
    ports.sort()
    # return all ones with score >=0
    return [(port["name"], port) for score, port in ports if score >= 0]
Exemple #5
0
 def exp_scan(self, context):
     if usb is None:
         return comscan.comscan()
     else:
         return usbscan.usbscan()+comscan.comscan()
def autoguessports(phonemodule):
    """Returns a list of ports (most likely first) for finding the phone on"""
    res=[]
    ports=[(islikelyportscore(port, phonemodule), port) for port in comscan.comscan()+usbscan.usbscan()+bitflingscan.flinger.scan() if port['available']]
    ports.sort()
    return [ (port['name'], port) for score,port in ports if score>=0]
Exemple #7
0
    def detect(self, using_port=None, using_model=None):
        # start the detection process
        # 1st, get the list of available ports
        coms = comscan.comscan() + usbscan.usbscan()
        self.log('coms:' + str(coms))
        available_modem_coms=[x['name'] for x in coms if x['available'] \
                              and x.get('class', None)=='modem']
        if not using_port:
            available_coms = [x['name'] for x in coms if x['available']]
        else:
            available_coms = [using_port]
            available_modem_coms = [
                x for x in available_coms if x in available_modem_coms
            ]
        # loop through each port and gather data
        self.log('Available ports: ' + str(available_coms))
        self.log('Available modem ports: ' + str(available_modem_coms))
        # only try those AT commands on modem ports
        # using threads
        self.__q_on = True
        threads=[threading.Thread(target=self.do_get_data, args=(e,)) \
                 for e in available_modem_coms]
        for t in threads:
            t.start()
        for t in threads:
            t.join()
        self.__q_on = False
        while not self.__q_log.empty():
            q = self.__q_log.get_nowait()
            if isinstance(q, (list, tuple)):
                self.logdata(*q)
            else:
                self.log(q)
        # non-thread version
##        for e in available_modem_coms:
##            self.do_get_data(e)
# go through each phone and ask it
##        pm=phones.phonemodels
        if using_model:
            models = [using_model]
        else:
            models = phones.phonemodels
        found_port = found_model = None
        for model in models:
            self.log('Checking for model: ' + model)
            module = common.importas(phones.module(model))
            # check for detectphone in module.Phone or
            # phone_model and phone_manufacturer in module.Profile
            if hasattr(module.Phone, 'detectphone'):
                if using_port is None:
                    likely_ports=[x['name'] for x in coms if \
                                  x['available'] and \
                                  comdiagnose.islikelyport(x, module)]
                else:
                    likely_ports = [using_port]
                self.log('Likely ports:' + str(likely_ports))
                found_port = getattr(module.Phone,
                                     'detectphone')(coms, likely_ports,
                                                    self.__data, module, self)
                self.log('Detect Phone result: ' + ` self.__data `)
                if found_port is not None:
                    self.log('Phone ' + model + ' returned port:' +
                             ` found_port `)
                    # found it
                    found_model = model
                    break
            found_port = self.__check_profile(module.Profile)
            if found_port is not None:
                found_model = model
                break
        if found_port is None and using_port is None and using_model is None:
            # if we're not looking for a specific model on a specific port,
            # scan for other CDMA phone
            found_port, found_model = self.__check_for_other_cdma()
        if found_port is not None and found_model is not None:
            self.log('Found phone:' + found_model + ' port:' + ` found_port `)
            return {
                'port': found_port,
                'phone_name': found_model,
                'phone_module': phones.module(found_model),
                'phone_esn': self.__data[found_port]['esn']
            }
Exemple #8
0
    def detect(self, using_port=None, using_model=None):
        # start the detection process
        # 1st, get the list of available ports
        coms=comscan.comscan()+usbscan.usbscan()
        self.log('coms:'+str(coms))
        available_modem_coms=[x['name'] for x in coms if x['available'] \
                              and x.get('class', None)=='modem']
        if not using_port:
            available_coms=[x['name'] for x in coms if x['available']]
        else:
            available_coms=[using_port]
            available_modem_coms=[x for x in available_coms if x in available_modem_coms]
        # loop through each port and gather data
        self.log('Available ports: '+str(available_coms))
        self.log('Available modem ports: '+str(available_modem_coms))
        # only try those AT commands on modem ports
        # using threads
        self.__q_on=True
        threads=[threading.Thread(target=self.do_get_data, args=(e,)) \
                 for e in available_modem_coms]
        for t in threads:
            t.start()
        for t in threads:
            t.join()
        self.__q_on=False
        while not self.__q_log.empty():
            q=self.__q_log.get_nowait()
            if isinstance(q, (list, tuple)):
                self.logdata(*q)
            else:
                self.log(q)
        # non-thread version
##        for e in available_modem_coms:
##            self.do_get_data(e)
        # go through each phone and ask it
##        pm=phones.phonemodels
        if using_model:
            models=[using_model]
        else:
            models=phones.phonemodels
        found_port=found_model=None
        for model in models:
            self.log('Checking for model: '+model)
            module=common.importas(phones.module(model))
            # check for detectphone in module.Phone or
            # phone_model and phone_manufacturer in module.Profile
            if hasattr(module.Phone, 'detectphone'):
                if using_port is None:
                    likely_ports=[x['name'] for x in coms if \
                                  x['available'] and \
                                  comdiagnose.islikelyport(x, module)]
                else:
                    likely_ports=[using_port]
                self.log('Likely ports:'+str(likely_ports))
                found_port=getattr(module.Phone, 'detectphone')(coms,
                                                                likely_ports,
                                                                self.__data,
                                                                module,
                                                                self)
                self.log('Detect Phone result: '+`self.__data`)
                if found_port is not None:
                    self.log('Phone '+model+' returned port:'+`found_port`)
                    # found it
                    found_model=model
                    break
            found_port=self.__check_profile(module.Profile)
            if found_port is not None:
                found_model=model
                break
        if found_port is None and using_port is None and using_model is None:
            # if we're not looking for a specific model on a specific port,
            # scan for other CDMA phone
            found_port, found_model=self.__check_for_other_cdma()
        if found_port is not None and found_model is not None:
            self.log('Found phone:'+found_model+' port:'+`found_port`)
            return { 'port': found_port, 'phone_name': found_model,
                     'phone_module': phones.module(found_model),
                     'phone_esn': self.__data[found_port]['esn'] }
	def exp_scan(self, context):

        if usb is None:

            return comscan.comscan()

        else:

            return usbscan.usbscan()+comscan.comscan()

	def exp_getversion(self, context):

        return version.description

	def exp_deviceopen(self, port, baud, timeout, hardwareflow, softwareflow, context):

        return self.stashhandle(context, commport.CommConnection(None, port, baud, timeout,
                                                                 hardwareflow, softwareflow))

	def exp_deviceclose(self, handle, context):

        comm=self.gethandle(context, handle)

        comm.close()

        del self.handles[handle]

        return True

	def exp_devicesetbaudrate(self, handle, rate, context):

        return self.gethandle(context, handle).setbaudrate(rate)

	def exp_devicesetdtr(self, handle, dtr, context):

        return self.gethandle(context, handle).setdtr(dtr)

	def exp_devicesetrts(self, handle, rts, context):

        return self.gethandle(context, handle).setrts(rts)

	def exp_devicewrite(self, handle, data, context):

        self.gethandle(context, handle).write(data.data)

        return len(data.data)

	def exp_devicesendatcommand(self, handle, atcommand, ignoreerror, context):

        "Special handling for empty lists and exceptions"

        try:

            res=self.gethandle(context, handle).sendatcommand(atcommand.data, ignoreerror=ignoreerror)

            if len(res)==0:

                res=1

        except:

            res=0

        return res

	def exp_devicereaduntil(self, handle, char, numfailures, context):

        return Binary(self.gethandle(context, handle).readuntil(char.data, numfailures=numfailures))

	def exp_deviceread(self, handle, numchars, context):

        return Binary(self.gethandle(context, handle).read(numchars))

	def exp_devicereadsome(self, handle, numchars, context):

        if numchars==-1:

            numchars=None

        return Binary(self.gethandle(context, handle).readsome(log=True,numchars=numchars))

	def exp_devicewritethenreaduntil(self, handle, data, char, numfailures, context):

        return Binary(self.gethandle(context, handle).writethenreaduntil(data.data, False, char.data, False, False, numfailures))


def run(args):

    theApp=wx.PySimpleApp()

    menu=wx.Menu()

    menu.Append(ID_EXIT, "Exit")

    mw=MainWindow(None, -1, "BitFling")

    taskwin=MyTaskBarIcon(mw, menu)

    mw.taskwin=taskwin

    theApp.MainLoop()

if __name__ == '__main__':

    run()


try:

    import native.usb as usb

except ImportError:

    usb=None


if guihelper.IsMSWindows(): parentclass=wx.TaskBarIcon

else: parentclass=wx.Frame


if __name__ == '__main__':

    run()