예제 #1
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        iRet = 1

        if oAction.uCCF_Code != u"":
            oAction.oIRCode = CCfToAndroidIR(oAction.uCCF_Code,
                                             ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd = ReplaceVars(oAction.uCmd)

        self.ShowInfo(u'Sending Command: ' + uCmd + u' to ' +
                      oSetting.uConfigName)

        oSetting.Connect()
        if oSetting.bIsConnected:
            try:
                Logger.debug("Sending IR Commend to IRBLASTER")
                irblaster.transmit(oAction.oIRCode.iFrequency,
                                   oAction.oIRCode.aPattern)
            except Exception as e:
                self.ShowWarning(u'Can\'t send message: ' + e.message,
                                 oSetting.uConfigName)
        else:
            Logger.debug("Not Connected")
        return iRet
예제 #2
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        iTryCount = 0
        iRet = 1

        oSetting.uRetVar = uRetVar

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    iStatusCode, uRes = self.SendCommand_Helper(
                        oAction, oSetting, self.uInterFaceName)
                    if iStatusCode == 200:
                        iRet = 0
                        self.ShowDebug(
                            u'Sending Command succeeded: : %d' % (iStatusCode),
                            oSetting.uConfigName)
                        break
                    elif iStatusCode == 0:
                        iRet = 200
                        self.ShowWarning(
                            u'Sending Command: Response should be 200, maybe error, maybe success: %d [%s]'
                            % (iStatusCode, uRes), oSetting.uConfigName)
                        break
                    else:
                        iRet = 1
                        oSetting.bIsConnected = False
                        self.ShowError(
                            u'Sending Command failed: %d [%s]' %
                            (iStatusCode, ToUnicode(uRes)),
                            oSetting.uConfigName)
                except Exception as e:
                    self.ShowError(u'can\'t Send Message',
                                   oSetting.uConfigName, e)
                    iRet = 1
            else:
                if iTryCount == 2:
                    self.ShowWarning(
                        u'Nothing done,not connected! ->[%s]' %
                        (oAction.uActionName), oSetting.uConfigName)
                oSetting.bIsConnected = False
        if not bNoLogOut:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)

        self.iLastRet = iRet
        return iRet
예제 #3
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        iTryCount = 0
        iRet = 1

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        oSetting.uRetVar = uRetVar

        uMsg = oAction.uCmd
        uMsg = ReplaceVars(uMsg,
                           self.uInterFaceName + '/' + oSetting.uConfigName)
        uMsg = ReplaceVars(uMsg)

        #Logger.info ('Interface '+self.uInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                #time.sleep(2)
                try:
                    self.ShowInfo(
                        u'Sending Command: "' + uMsg + u'" to ' +
                        oSetting.aInterFaceIniSettings.uHost + ':' +
                        oSetting.aInterFaceIniSettings.uPort,
                        oSetting.uConfigName)
                    uMsg = uMsg.replace('\\n', '\n')
                    uMsg = uMsg.replace('\\r', '\r')
                    #Bypass unicode bug in python 2.7
                    uMsg = str(uMsg)
                    if oAction.bWaitForResponse == True:
                        #All response comes to receiver thread, so we should hold the queue until vars are set
                        StartWait(self.iWaitMs)

                    oSetting.oTelnet.write(uMsg)
                    iRet = 0
                    break
                except Exception as e:
                    self.ShowError(u'can\'t Send Message',
                                   oSetting.uConfigName, e)
                    iRet = 1
                    oSetting.Disconnect()
        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
예제 #4
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        if oAction.uCCF_Code:
            oAction.uCmd = CCF2ITach(oAction.uCCF_Code,
                                     ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd = ReplaceVars(oAction.uCmd,
                           self.uInterFaceName + u'/' + oSetting.uConfigName)
        uCmd = ReplaceVars(uCmd)
        self.ShowInfo(
            u'Sending Command: ' + uCmd + u' to ' +
            oSetting.aInterFaceIniSettings.uHost + ':' +
            oSetting.aInterFaceIniSettings.uPort, oSetting.uConfigName)

        oSetting.Connect()
        iRet = 1
        if oSetting.bIsConnected:
            uMsg = uCmd + u'\r\n'
            try:
                if PY2:
                    oSetting.oSocket.sendall(uMsg)
                else:
                    oSetting.oSocket.sendall(ToBytes(uMsg))
                self.sResponse = oSetting.oSocket.recv(self.iBufferSize)
                Logger.debug(u'Interface ' + self.uInterFaceName +
                             ': resonse:' + self.sResponse)
                self.ShowDebug(u'Response' + self.sResponse,
                               oSetting.uConfigName)
                if 'completeir' in self.sResponse:
                    iRet = 0
                else:
                    iRet = 1
            except Exception as e:
                self.ShowError(u'can\'t Send Message', u'', e)
                iRet = 1
        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
예제 #5
0
    def SendCommand(self,oAction,oSetting,uRetVar,bNoLogOut=False):
        cBaseInterFace.SendCommand(self,oAction,oSetting,uRetVar,bNoLogOut)

        iRet=1

        if oAction.uCCF_Code != u"":
            oAction.uCmd=CCfToKeene(oAction.uCCF_Code,ToInt(oAction.uRepeatCount))
            oAction.uCCF_Code = u""

        uCmd=ReplaceVars(oAction.uCmd)

        self.ShowInfo(u'Sending Command: '+uCmd + u' to '+oSetting.aInterFaceIniSettings.uHost+':'+oSetting.aInterFaceIniSettings.uPort,oSetting.uConfigName)

        oSetting.Connect()
        if oSetting.bIsConnected:
            uMsg=uCmd+u'\r\n'
            try:
                uMsg=ReplaceVars(uMsg,self.uInterFaceName+'/'+oSetting.uConfigName)
                if PY2:
                    oSetting.oSocket.sendto(uMsg, (oSetting.aInterFaceIniSettings.uHost, int(oSetting.aInterFaceIniSettings.uPort)))
                else:
                    oSetting.oSocket.sendto(ToBytes(uMsg), (oSetting.aInterFaceIniSettings.uHost, int(oSetting.aInterFaceIniSettings.uPort)))
                self.sResponse, addr =  oSetting.oSocket.recvfrom(self.iBufferSize)
                if not PY2:
                    self.sResponse = ToUnicode(self.sResponse)
                self.ShowDebug(u'Response'+self.sResponse,oSetting.uConfigName)
                if 'ACK' in self.sResponse:
                    iRet=0
                else:
                    iRet=1
            except Exception as e:
                if e.message!="timed out":
                    self.ShowError(u'Can\'t send message',oSetting.uConfigName,e)
                else:
                    self.ShowWarning(u'Can\'t send message: time out',oSetting.uConfigName)

                iRet=1
        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose==0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose!=-1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(oSetting.FktDisconnect, oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
예제 #6
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)
        uCmd = oAction.uCmd
        uCmd = (uCmd + "       ")[:8]
        self.ShowInfo(
            u'Sending Command: ' + uCmd + u' to ' +
            oSetting.aInterFaceIniSettings.uHost + ':' +
            oSetting.aInterFaceIniSettings.uPort, oSetting.uConfigName)

        oSetting.Connect()
        iRet = 1
        if oSetting.bIsConnected:
            uMsg = uCmd + u'\r'
            try:
                uMsg = ReplaceVars(
                    uMsg, self.uInterFaceName + '/' + oSetting.uConfigName)
                uMsg = ReplaceVars(uMsg)
                oSetting.oSocket.sendall(uMsg)
                self.sResponse = oSetting.oSocket.recv(self.iBufferSize)
                Logger.debug(u'Interface ' + self.uInterFaceName +
                             ': resonse:' + self.sResponse)
                self.ShowDebug(u'Response' + self.sResponse,
                               oSetting.uConfigName)

                if 'OK' in self.sResponse:
                    iRet = 0
                else:
                    iRet = 1
            except Exception as e:
                self.ShowError(u'Cant Send Message', u'', e)
                iRet = 1
        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)

        self.iLastRet = iRet
        return iRet
예제 #7
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        uCmd = ReplaceVars(oAction.uCmd)
        uCmd = ReplaceVars(uCmd,
                           self.uInterFaceName + '/' + oSetting.uConfigName)

        self.ShowInfo(
            u'Sending Command: %s to %s (%s:%s)' %
            (uCmd, oSetting.aInterFaceIniSettings.uWidgetName,
             oSetting.uConfigName, oSetting.aInterFaceIniSettings.uStream))
        oSetting.Connect()

        iRet = 1
        if oSetting.bIsConnected:
            try:
                iRet, sValue = oSetting.oWidgetPlayer.StatusControl(
                    uCmd, oSetting.aInterFaceIniSettings.uStream)
                iRet = 0
            except Exception as e:
                self.ShowError(u'can\'t Send Message', u'', e)
                iRet = 1
        return iRet
예제 #8
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        uCmd = oAction.uCmd
        uPrefix = u''

        if uCmd == u'*':
            uCmd = oAction.dActionPars['commandname']

        # call the function to pass string to eventghost
        if oAction.uType == u'command':
            uPrefix = u'c'
        elif oAction.uType == u'event':
            uPrefix = u'e' + oSetting.aInterFaceIniSettings.uPreFix
        elif oAction.uType == u'key':
            uPrefix = u'k'
        elif oAction.uType == u'macro':
            uPrefix = u'a'
        elif oAction.uType == u'mouse':
            uPrefix = u'm'
        else:
            Logger.warning(u'Invalid type: ' + oAction.uType)

        iTryCount = 0
        iRet = 1

        uCmd = ReplaceVars(oAction.uCmd)
        uCmd = ReplaceVars(uCmd,
                           self.uInterFaceName + '/' + oSetting.uConfigName)

        self.ShowInfo(
            u'Sending Command: ' + uPrefix + uCmd + u' to ' +
            oSetting.aInterFaceIniSettings.uHost + ':' +
            oSetting.aInterFaceIniSettings.uPort, oSetting.uConfigName)

        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            # we need to verify if we are really connected, as the connection might have died
            # and .sendall will not return on error in this case
            #bIsConnected=oSetting.IsConnected()

            if oSetting.bIsConnected:
                uMsg = uPrefix + uCmd + u'\n'
                try:
                    StartWait(self.iWaitMs)
                    if PY2:
                        oSetting.oSocket.sendall(uMsg)
                    else:
                        oSetting.oSocket.sendall(ToBytes(uMsg))
                    iRet = 0
                    break
                except Exception as e:
                    self.ShowError(u'can\'t Send Message',
                                   oSetting.uConfigName, e)
                    oSetting.Disconnect()
                    iRet = 1

        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
예제 #9
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        iTryCount = 0
        iRet = 1
        #Logger.info ('Interface '+self.sInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            # we need to verify if we are really connected, as the connection might have died
            # and .sendall will not return on error in this case
            #bIsConnected=oSetting.IsConnected()

            if oSetting.bIsConnected:
                uMsg = oAction.uCmd
                try:

                    uMsg = ReplaceVars(
                        uMsg, self.uInterFaceName + '/' + oSetting.uConfigName)
                    uMsg = ReplaceVars(uMsg)
                    oAction.uGetVar = ReplaceVars(
                        oAction.uGetVar,
                        self.uInterFaceName + '/' + oSetting.uConfigName)
                    oAction.uGetVar = ReplaceVars(oAction.uGetVar)

                    oSetting.uMsg = uMsg
                    oSetting.uRetVar = uRetVar
                    oSetting.uRetVar = uRetVar
                    self.ShowInfo(
                        u'Sending Command: ' + uMsg + ' to ' +
                        oSetting.aInterFaceIniSettings.uHost + ':' +
                        oSetting.aInterFaceIniSettings.uPort,
                        oSetting.uConfigName)
                    #All response comes to receiver thread, so we should hold the queue until vars are set
                    if oSetting.oAction.bWaitForResponse:
                        StartWait(self.iWaitMs)
                    oSetting.oWebSocket.send(uMsg)
                    fSleep(0.01)
                    iRet = 0
                    break
                except Exception as e:
                    self.ShowError(u'Can\'t send message',
                                   oSetting.uConfigName, e)
                    iRet = 1
                    oSetting.Disconnect()
                    oSetting.bOnError = True
                    if not uRetVar == u'':
                        SetVar(uVarName=uRetVar, oVarValue=u"Error")
            else:
                if not uRetVar == u'':
                    SetVar(uVarName=uRetVar, oVarValue=u"Error")

        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
예제 #10
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        iTryCount = 0
        iRet = 1

        uRetVar = ReplaceVars(uRetVar)
        oSetting.uRetVar = uRetVar

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        dCmd = ToDic(oAction.uCmd)
        uCmd = dCmd["method"]
        dParams = dCmd["params"]

        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    self.ShowDebug("Sending elv max command: %s" % uCmd)
                    oFunc = self.dInterfaceFunctions.get(uCmd)
                    aResult = []
                    if oFunc is not None:
                        aResult = oFunc(oSetting=oSetting,
                                        oAction=oAction,
                                        dParams=dParams)
                    else:
                        self.ShowError("Function not implemented: %s" % uCmd)

                    for dLine in aResult:

                        uGlobalDestVarSave = oAction.uGlobalDestVar
                        uLocalDestVarSave = oAction.uLocalDestVar

                        if oAction.uGetVar.startswith('ORCAMULTI'):
                            aTmpGlobalDestVar = ToList(oAction.uGlobalDestVar)
                            aTmpLocalDestVar = ToList(oAction.uLocalDestVar)
                            oAction.uGlobalDestVar = "".join(
                                '"' + e + dLine.uVarSuffix + '",'
                                for e in aTmpGlobalDestVar)[:-1]
                            oAction.uLocalDestVar = "".join(
                                '"' + e + dLine.uVarSuffix + '",'
                                for e in aTmpLocalDestVar)[:-1]
                        else:
                            oAction.uGlobalDestVar = oAction.uGlobalDestVar + dLine.uVarSuffix
                            oAction.uLocalDestVar = oAction.uLocalDestVar + dLine.uVarSuffix

                        uCmd, uRetVal = self.ParseResult(
                            oAction, dLine.dValue, oSetting)
                        oAction.uGlobalDestVar = uGlobalDestVarSave
                        oAction.uLocalDestVar = uLocalDestVarSave

                    break
                except Exception as e:
                    self.ShowError(u'can\'t Send Message',
                                   oSetting.uConfigName, e)
                    iRet = 1
            else:
                oSetting.bIsConnected = False

        self.iLastRet = iRet

        if not bNoLogOut:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
예제 #11
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        iTryCount = 0
        iRet = 1

        if oAction.dActionPars.get('commandname') == "send_string":
            uTmpVar = GetVar(uVarName='inputstring')
            uTmpVar2 = uTmpVar
            uTmpVar = uTmpVar.replace(" ", "%s")
            SetVar(uVarName='inputstring', oVarValue=uTmpVar)

        uRetVar = ReplaceVars(uRetVar)
        oSetting.uRetVar = uRetVar

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        uParams = ReplaceVars(oAction.uParams)
        uParams = ReplaceVars(uParams,
                              self.uInterFaceName + '/' + oSetting.uConfigName)

        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    self.ShowDebug("Sending adb command: %s:%s" %
                                   (oAction.uCmd, uParams))
                    oMethod = getattr(oSetting.oDevice.oADB_Commands,
                                      oAction.uCmd)
                    oResult = oMethod(uParams)
                    uCmd, uRetVal = self.ParseResult(oAction, oResult,
                                                     oSetting)
                    self.ShowDebug(u'Parsed Resonse:' + uRetVal)
                    if not uRetVar == u'':
                        uRetVal = uRetVal.replace("\n", "")
                        uRetVal = uRetVal.replace("\r", "")
                        SetVar(uVarName=uRetVar, oVarValue=uRetVal)

                    self.ShowDebug("Result:" + str(oResult))
                    break
                except Exception as e:
                    self.ShowError(u'can\'t Send Message',
                                   oSetting.uConfigName, e)
                    iRet = 1
            else:
                oSetting.bIsConnected = False

        if oAction.dActionPars.get('commandname') == "send_string":
            SetVar(uVarName='inputstring', oVarValue=uTmpVar2)

        self.iLastRet = iRet

        if not bNoLogOut:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet