Esempio n. 1
0
 def doPreview(self):
     dbg("doPreview")
     self.state = PREVIEW
     self.__cancelLater()
     self.callLater = reactor.callLater(20, self.transport.loseConnection)
     #self.callLater.addErrback(log.err)
     self.__doCommand(2)
Esempio n. 2
0
    def registerListener(klass, address, listener):
        if not address in klass.listeners:
            klass.listeners[address] = list()

        if listener not in klass.listeners[address]:
            dbg("adding listener")
            klass.listeners[address].append(listener)
Esempio n. 3
0
    def registerListener(klass, address, listener):
        if not address in klass.listeners:
            klass.listeners[address] = list()

        if listener not in klass.listeners[address]:
            dbg("adding listener")
            klass.listeners[address].append(listener)
Esempio n. 4
0
 def doPreview(self):
   dbg("doPreview")
   self.state = PREVIEW
   self.__cancelLater()
   self.callLater = reactor.callLater(20, self.transport.loseConnection)
   #self.callLater.addErrback(log.err)
   self.__doCommand(2)
Esempio n. 5
0
 def set(self, option, value):
     dbg("set %s->%s" % (option, value) )
     if option=="size":
             self.doSetSize(value)
             from airi.api import UpdateManager
             UpdateManager.propagate(self.address, {"size": value})
     else:
             dbg("ignored")
Esempio n. 6
0
 def doSCO(self, enable):
     if not getattr(bluetooth, "SCOReader", None):
         dbg("sco not supported in this platform")
         return
     if enable:
         return self.enableSCO()
     else:
         return self.disableSCO()
Esempio n. 7
0
 def doSCO(self, enable):
     if not getattr(bluetooth, "SCOReader", None):
         dbg("sco not supported in this platform")
         return
     if enable:
         return self.enableSCO()
     else:
         return self.disableSCO()
Esempio n. 8
0
 def set(self, option, value):
   dbg("set %s->%s" % (option, value) )
   if option=="size":
       self.doSetSize(value)
       from airi.api import UpdateManager
       UpdateManager.propagate(self.address, {"size": value})
   else:
       dbg("ignored")
Esempio n. 9
0
 def welcomeCheck():
     while len(self.buffer) > 0 and self.buffer.find('\n') > -1:
         welcome, self.buffer = self.buffer.split('\n', 1)
         dbg("welcome", welcome)
         welcome = welcome.strip().lower().strip('\x00')
         for k, v in WELCOME.iteritems():
             if welcome.find(v) > -1:
                 return k
Esempio n. 10
0
 def welcomeCheck():
     while len(self.buffer) > 0 and self.buffer.find('\n') > -1:
         welcome, self.buffer = self.buffer.split('\n', 1)
         dbg("welcome", welcome)
         welcome = welcome.strip().lower().strip('\x00')
         for k, v in WELCOME.iteritems():
             if welcome.find(v) > -1:
                 return k
Esempio n. 11
0
 def internalDoCommand(self):
     if len(self.pending) == 0:
         return
     command, value, timeout = self.pending.pop(0)
     if callable(value):
         value = value()
     dbg("doCommand $%s%s" % (command, value))
     self.transport.write("$%s%s\n\r" % (command, value))
     self.callLater = reactor.callLater(timeout, self.internalDoCommand)
Esempio n. 12
0
 def internalDoCommand(self):
     if len(self.pending) == 0:
         return
     command, value, timeout = self.pending.pop(0)
     if callable(value):
         value = value()
     dbg("doCommand $%s%s" % (command, value))
     self.transport.write("$%s%s\n\r" % (command, value))
     self.callLater = reactor.callLater(timeout, self.internalDoCommand)
Esempio n. 13
0
 def set(self, option, value):
     dbg("set %s-> %s" % (option, value))
     if option == "size":
         self.doCommand(option, SIZES[value])
     elif option == "flash":
         self.doCommand(option, "0" if not value else "1")
     elif option == "pan" or option == "exposure":
         self.doCommand(option, value.upper())
     else:
         dbg("ignored")
Esempio n. 14
0
 def doSetSize(self, size=None):
     self.state = ECHO
     self.__cancelLater()
     if not size:
         camera=settings.getCamera(self.address)
         size = "QVGA" #default
         if camera:
             size = camera.get("size", size)
     dbg("doSetSize(%s)", size)
     self.__doCommand(SIZES[size])
     self.callLater = reactor.callLater(2, self.doPreview)
Esempio n. 15
0
 def doSetSize(self, size=None):
   self.state = ECHO
   self.__cancelLater()
   if not size:
     camera=settings.getCamera(self.address)
     size = "QVGA" #default
     if camera:
       size = camera.get("size", size)
   dbg("doSetSize(%s)", size)
   self.__doCommand(SIZES[size])
   self.callLater = reactor.callLater(2, self.doPreview)
Esempio n. 16
0
 def set(self, option, value):
     dbg("set %s-> %s" % (option, value))
     if option == "size":
         self.doCommand(option, SIZES[value])
     elif option == "flash" or option == "stream":
         self.doCommand(option, "0" if not value else "1")
     elif option == "pan" or option == "exposure":
         self.doCommand(option, value.upper())
     elif option == "voice":
         self.doSCO(value)
     else:
         dbg("ignored")
Esempio n. 17
0
 def doSetup(self):
     dbg("doSetup")
     nsets = settings.getCamera(self.address)
     sets = self.defaults
     size = self.size
     if nsets:
         sets.update(nsets)
     dbg(sets)
     self.callLater = reactor.callLater(4, self.internalDoCommand)
     self.doCommand("date",
                     lambda: datetime.utcnow().strftime("%Y%m%dT%H%M%SZ"))
     self.doCommand("size", SIZES[sets["size"]])
     self.doCommand("flash", "0" if not sets["flash"] else "1")
     self.doCommand("pan", sets["pan"].upper()[0])
Esempio n. 18
0
 def doSetup(self):
     dbg("doSetup")
     nsets = settings.getCamera(self.address)
     sets = self.defaults
     size = self.size
     if nsets:
         sets.update(nsets)
     dbg(sets)
     self.callLater = reactor.callLater(1, self.internalDoCommand)
     self.doCommand("date",
                    lambda: datetime.utcnow().strftime("%Y%m%dT%H%M%SZ"))
     self.doCommand("size", SIZES[sets["size"]])
     self.doCommand("stream", "1" if sets["stream"] else "0")
     self.doCommand("flash", "0" if not sets["flash"] else "1")
     self.doCommand("pan", sets["pan"].upper()[0])
Esempio n. 19
0
    def doINIT(self):

        def welcomeCheck():
            while len(self.buffer) > 0 and self.buffer.find('\n') > -1:
                welcome, self.buffer = self.buffer.split('\n', 1)
                dbg("welcome", welcome)
                welcome = welcome.strip().lower().strip('\x00')
                for k, v in WELCOME.iteritems():
                    if welcome.find(v) > -1:
                        return k

        dbg("doINIT", self.buffer)
        if self.buffer.find("\n") == -1:
            dbg("Welcome not received")
            if not self.callLater:
                self.callLater = reactor.callLater(3, self.invalidCamera)
            self.callLater.reset(2)
            return

        kind = welcomeCheck()
        if not kind:
            if not self.callLater:
                self.callLater = reactor.callLater(3, self.invalidCamera)
            self.callLater.reset(2)
            return

        self.kind = kind
        log.msg("Connected to a %s camera" % self.kind)
        dbg("still in buffer", len(self.buffer))
        self.state = IDLE
        settings.setCameraSetting(self.address, "address", self.address)
        settings.setCameraSetting(self.address, "type", self.kind)
        settings.setCameraSetting(self.address, "name", "NN")
        settings.setCameraSetting(self.address, "last",
                                    strftime("%m/%d/%Y %H:%M:%S", localtime()))
        settings.save()
        self.client = TYPES[self.kind]["class"](self)
        if self.callLater:
            self.callLater.cancel()
            self.callLater = None
Esempio n. 20
0
    def doINIT(self):
        def welcomeCheck():
            while len(self.buffer) > 0 and self.buffer.find('\n') > -1:
                welcome, self.buffer = self.buffer.split('\n', 1)
                dbg("welcome", welcome)
                welcome = welcome.strip().lower().strip('\x00')
                for k, v in WELCOME.iteritems():
                    if welcome.find(v) > -1:
                        return k

        dbg("doINIT", self.buffer)
        if self.buffer.find("\n") == -1:
            dbg("Welcome not received")
            if not self.callLater:
                self.callLater = reactor.callLater(3, self.invalidCamera)
            self.callLater.reset(2)
            return

        kind = welcomeCheck()
        if not kind:
            if not self.callLater:
                self.callLater = reactor.callLater(3, self.invalidCamera)
            self.callLater.reset(2)
            return

        self.kind = kind
        log.msg("Connected to a %s camera" % self.kind)
        dbg("still in buffer", len(self.buffer))
        self.state = IDLE
        settings.setCameraSetting(self.address, "address", self.address)
        settings.setCameraSetting(self.address, "type", self.kind)
        settings.setCameraSetting(self.address, "name", "NN")
        settings.setCameraSetting(self.address, "last",
                                    strftime("%m/%d/%Y %H:%M:%S", localtime()))
        settings.save()
        self.client = TYPES[self.kind]["class"](self)
        if self.callLater:
            self.callLater.cancel()
            self.callLater = None
Esempio n. 21
0
 def __init__(self, address):
     dbg("new camera instance for (%s)", address)
     setattr(self, "client", None)
     setattr(self, "buffer", "")
     self.address = address
Esempio n. 22
0
 def __init__(self, address):
     dbg("new camera instance for (%s)", address)
     setattr(self, "client", None)
     setattr(self, "buffer", "")
     self.address = address
Esempio n. 23
0
 def doCommandMode(self):
     dbg("doCommandMode")
     self.state = COMMAND_MODE
     self.__doCommand(1)
     self.__cancelLater()
     self.callLater = reactor.callLater(1, self.doSetSize)
Esempio n. 24
0
 def disconnect(self):
     dbg("AIRi.disconnect")
Esempio n. 25
0
 def disconnect(self):
     dbg("AIRi.disconnect")
     self.disableSCO()
Esempio n. 26
0
 def doCommandMode(self):
   dbg("doCommandMode")
   self.state = COMMAND_MODE
   self.__doCommand(1)
   self.__cancelLater()
   self.callLater = reactor.callLater(1, self.doSetSize)
Esempio n. 27
0
 def disconnect(self):
   dbg("OptiEyes.disconnect")
   self.__doCommand(1)
Esempio n. 28
0
 def disconnect(self):
     dbg("AIRi.disconnect")
     self.disableSCO()
Esempio n. 29
0
 def disconnect(self):
     dbg("OptiEyes.disconnect")
     self.__doCommand(1)