Пример #1
0
    def Split_IFV(self,oAction:cAction,uResponse:str,oSetting:cInterFaceSettings) -> None:
        # handles the return of Video Information Request
        uTmp:str=oAction.uGlobalDestVar
        if not oSetting.uRetVar==u'':
            oAction.uGlobalDestVar=oSetting.uRetVar

        aResponses:List=uResponse.split(',')
        if len(aResponses)>1:
            oSetting.oResultParser.SetVar2(aResponses[0], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Selection', uAddName=u"_video_input_selection")
            oSetting.oResultParser.SetVar2(aResponses[1], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Resolution', uAddName=u"_video_input_resolution")
        if len(aResponses)>2:
            oSetting.oResultParser.SetVar2(aResponses[2], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Color', uAddName=u"_video_input_color")
        if len(aResponses)>3:
            oSetting.oResultParser.SetVar2(aResponses[3], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Input Bits', uAddName=u"_video_input_bits")
        if len(aResponses)>4:
            oSetting.oResultParser.SetVar2(aResponses[4], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Selection', uAddName=u"_video_output_selection")
        if len(aResponses)>5:
            oSetting.oResultParser.SetVar2(aResponses[5], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Resolution', uAddName=u"_video_output_resolution")
        if len(aResponses)>6:
            oSetting.oResultParser.SetVar2(aResponses[6], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Color', uAddName=u"_video_output_color")
        if len(aResponses)>7:
            oSetting.oResultParser.SetVar2(aResponses[7], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Bits', uAddName=u"_video_output_bits")
        if len(aResponses)>8:
            oSetting.oResultParser.SetVar2(aResponses[8], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Video Output Effect', uAddName=u"_video_output_bits")

        if uTmp!=u'':
            oSetting.uRetVar=uTmp
Пример #2
0
    def ReadAction(self, oAction: cAction) -> None:
        """
        Adds and defaults some common attributes to the action

        :param cAction oAction: Reads an action from the action pars
        """

        oAction.uType = oAction.dActionPars.get(u'type', u'send')
        oAction.uCmd = oAction.dActionPars.get(u'cmd',
                                               u'No cmd action defined')
        oAction.uLocalDestVar = oAction.dActionPars.get(
            u'ldestvar', u'RESULT_' + oAction.uActionName)
        oAction.uGlobalDestVar = oAction.dActionPars.get(
            u'gdestvar', u'RESULT_' + oAction.uActionName)
        oAction.uGetVar = oAction.dActionPars.get(u'getvar', u'')
        oAction.bWaitForResponse = ToBool(
            oAction.dActionPars.get(u'waitforresponse', u'0'))
        oAction.uParseResultOption = oAction.dActionPars.get(
            u'parseoption', self.aIniSettings.uParseResultOption)
        oAction.uParseResultTokenizeString = oAction.dActionPars.get(
            u'parsetoken', self.aIniSettings.uParseResultTokenizeString)
        oAction.uParseResultFlags = oAction.dActionPars.get(
            u'parseflags', self.aIniSettings.uParseResultFlags)
        oAction.uResultEndString = oAction.dActionPars.get(
            u'parseendstring', self.aIniSettings.uResultEndString)

        oAction.dActionPars['interface'] = self.oInterFace.uObjectName
        oAction.dActionPars['configname'] = self.uConfigName

        if oAction.dActionPars.get('varcontext', '') == "codeset":
            oAction.dActionPars["varcontext"] = self.uContext
Пример #3
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

        iTryCount: int = 0
        eRet: eReturnCode = eReturnCode.Error
        uMsg: str
        byMsg: bytes

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

        oSetting.uRetVar = uRetVar

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

        #Logger.info ('Interface '+self.uObjectName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount < self.iMaxTryCount:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                #time.sleep(2)
                try:
                    self.ShowInfo(uMsg=u'Sending Command: "' + uMsg +
                                  u'" to ' + oSetting.aIniSettings.uHost +
                                  ':' + oSetting.aIniSettings.uPort,
                                  uParConfigName=oSetting.uConfigName)
                    uMsg = uMsg.replace('\\n', '\n')
                    uMsg = uMsg.replace('\\r', '\r')
                    byMsg = ToBytes(uMsg)

                    if oAction.bWaitForResponse:
                        #All response comes to receiver thread, so we should hold the queue until vars are set
                        StartWait(self.iWaitMs)

                    oSetting.oTelnet.write(byMsg)
                    eRet = eReturnCode.Success
                    break

                except Exception as e:
                    self.ShowError(uMsg=u'can\'t Send Message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
                    oSetting.Disconnect()
        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #4
0
    def Split_IFA(self,oAction:cAction,uResponse:str,oSetting:cInterFaceSettings) -> None:
        # handles the return of Audio Information Request
        uTmp:str=oAction.uGlobalDestVar
        if not oSetting.uRetVar==u'':
            oAction.uGlobalDestVar=oSetting.uRetVar

        aResponses:List=uResponse.split(',')

        if len(aResponses)>1:
            oSetting.oResultParser.SetVar2(aResponses[0], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Selection', uAddName=u'_audio_input_selection')
            oSetting.oResultParser.SetVar2(aResponses[1], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Codec', uAddName=u'_audio_input_codec')
        if len(aResponses)>2:
            oSetting.oResultParser.SetVar2(aResponses[2], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Frequency', uAddName=u'_audio_input_frequency')
        if len(aResponses)>3:
            oSetting.oResultParser.SetVar2(aResponses[3], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Input Channels', uAddName=u'_audio_input_channels')
        if len(aResponses)>4:
            oSetting.oResultParser.SetVar2(aResponses[4], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Output Effect', uAddName=u'_audio_output_effect')
        if len(aResponses)>5:
            oSetting.oResultParser.SetVar2(aResponses[5], oAction.uLocalDestVar, oAction.uGlobalDestVar, u'Storing Audio Output Channels', uAddName=u'_audio_output_channels')

        if uTmp!=u'':
            oSetting.uRetVar=uTmp
Пример #5
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

        iTryCount: int = 0
        eRet: eReturnCode = eReturnCode.Error

        uRetVar = ReplaceVars(uRetVar)
        oSetting.uRetVar = uRetVar

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

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

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

                    for dLine in aResult:
                        uGlobalDestVarSave: str = oAction.uGlobalDestVar
                        uLocalDestVarSave: str = oAction.uLocalDestVar

                        if u'L' in oAction.uParseResultFlags:
                            aTmpGlobalDestVar: List = ToList(
                                oAction.uGlobalDestVar)
                            aTmpLocalDestVar: List = 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

                    eRet = eReturnCode.Success
                    break
                except Exception as e:
                    self.ShowError(uMsg=u'can\'t Send Message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
            else:
                oSetting.bIsConnected = False

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #6
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

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

        iTryCount = 0
        eRet: eReturnCode = eReturnCode.Error
        #Logger.info ('Interface '+self.sInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount < self.iMaxTryCount:
            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.uObjectName + '/' + oSetting.uConfigName)
                    uMsg = ReplaceVars(uMsg)
                    oAction.uGetVar = ReplaceVars(
                        oAction.uGetVar,
                        self.uObjectName + '/' + oSetting.uConfigName)
                    oAction.uGetVar = ReplaceVars(oAction.uGetVar)

                    oSetting.uMsg = uMsg
                    oSetting.uRetVar = uRetVar
                    oSetting.uRetVar = uRetVar
                    self.ShowInfo(uMsg=u'Sending Command: ' + uMsg + ' to ' +
                                  oSetting.aIniSettings.uHost + ':' +
                                  oSetting.aIniSettings.uPort,
                                  uParConfigName=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(fSeconds=0.01)
                    eRet = eReturnCode.Success
                    break
                except Exception as e:
                    self.ShowError(uMsg=u'Can\'t send message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
                    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")

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #7
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

        iTryCount: int = 0
        eRet: eReturnCode = eReturnCode.Error

        oSetting.uRetVar = uRetVar

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

        while iTryCount < self.iMaxTryCount:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    iStatusCode, uRes = self.SendCommand_Helper(
                        oAction, oSetting, self.uObjectName)
                    if iStatusCode == oAction.iCodeOK:
                        eRet = eReturnCode.Success
                        self.ShowDebug(
                            uMsg=u'Sending Command succeeded: : %d' %
                            iStatusCode,
                            uParConfigName=oSetting.uConfigName)
                        break
                    elif iStatusCode == 0:
                        eRet = eReturnCode.Unknown
                        self.ShowWarning(
                            uMsg=
                            u'Sending Command: Response should be %d, maybe error, maybe success: %d [%s]'
                            % (oAction.iCodeOK, iStatusCode, uRes),
                            uParConfigName=oSetting.uConfigName)
                        break
                    else:
                        eRet = eRet.Error
                        oSetting.bIsConnected = False
                        self.ShowError(
                            uMsg=u'Sending Command failed: %d [%s]' %
                            (iStatusCode, ToUnicode(uRes)),
                            uParConfigName=oSetting.uConfigName)
                except Exception as e:
                    self.ShowError(uMsg=u'can\'t Send Message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
            else:
                if iTryCount == self.iMaxTryCount:
                    self.ShowWarning(
                        uMsg=u'Nothing done,not connected! ->[%s]' %
                        oAction.uActionName,
                        uParConfigName=oSetting.uConfigName)
                oSetting.bIsConnected = False

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #8
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

        iTryCount: int = 0
        eRet: eReturnCode = eReturnCode.Success
        uTmpVar2: str = u""

        if oAction.dActionPars.get('commandname') == "send_string":
            uTmpVar: str = 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

        # noinspection PyUnresolvedReferences
        uParams: str = ReplaceVars(oAction.uParams)
        uParams = ReplaceVars(uParams,
                              self.uObjectName + '/' + oSetting.uConfigName)

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

                    self.ShowDebug(uMsg="Result:" + str(oResult))
                    break
                except Exception as e:
                    self.ShowError(uMsg=u'can\'t Send Message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
            else:
                oSetting.bIsConnected = False

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

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Пример #9
0
    def SendCommand(self,oAction:cAction,oSetting:cInterFaceSettings,uRetVar:str,bNoLogOut:bool=False) -> eReturnCode:
        super().SendCommand(oAction=oAction,oSetting=oSetting,uRetVar=uRetVar,bNoLogOut=bNoLogOut)

        uTst:str
        uFormat:str
        uKey:str

        iTryCount:int       = 0
        eRet:eReturnCode    = eReturnCode.Error
        uMsg:str            = oAction.uCmd

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

        uTst=uMsg[:3]
        if uTst==u'MVL' and uMsg!=u'MVLUP' and uMsg!=u'MVLDOWN' and not uMsg.endswith("QSTN"):
            Var_Int2Hex(uVarName = self.uObjectName+'/'+oSetting.uConfigName+'volumetoset')
        if (uTst==u'CTL' or uTst==u'SWL') and not uMsg.endswith("QSTN"):
            uFormat='{:+03X}'
            uKey = oSetting.aIniSettings.uHost + oSetting.aIniSettings.uPort
            if uKey in self.dDeviceSettings:
                if uTst == u'CTL':
                    uFormat=self.dDeviceSettings[uKey].uVar_CTLFormat
                else:
                    uFormat = self.dDeviceSettings[uKey].uVar_SWLFormat
            Var_Int2Hex(uVarName = self.uObjectName + '/' + oSetting.uConfigName + 'volumetoset', uFormat = uFormat)

        uMsg             = ReplaceVars(uMsg,self.uObjectName+'/'+oSetting.uConfigName)
        uMsg             = ReplaceVars(uMsg)
        oSetting.uMsg    = uMsg
        oSetting.uRetVar = uRetVar

        if uTst == u"NRI":
            uKey = oSetting.aIniSettings.uHost + oSetting.aIniSettings.uPort
            if uKey in self.dDeviceSettings and False:
                self.dDeviceSettings[uKey].WriteVars(uVarPrefix=uRetVar, oAction=oAction)
                return eReturnCode.Success
            else:
                self.dDeviceSettings[uKey] = self.cDeviceSettings(self, oSetting)
                # we write the defaults to var, in case we can't connect to the receiver
                self.dDeviceSettings[uKey].WriteVars(uVarPrefix=uRetVar, oAction=oAction)

        #Logger.info (u'Interface '+self.uObjectName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount<self.iMaxTryCount:
            iTryCount+=1
            oSetting.Connect()

            if oSetting.bIsConnected:
                try:
                    oAction.uGetVar         = ReplaceVars(oAction.uGetVar,self.uObjectName+'/'+oSetting.uConfigName)
                    oAction.uGetVar         = ReplaceVars(oAction.uGetVar)

                    self.ShowInfo (uMsg=u'Sending Command: '+uMsg + ' to '+oSetting.aIniSettings.uHost+':'+oSetting.aIniSettings.uPort,uParConfigName=oSetting.uConfigName)
                    byMsg:bytes = oSetting.CreateEISPHeader(uMsg)
                    if oAction.bWaitForResponse:
                        #All response comes to receiver thread, so we should hold the queue until vars are set
                        if uTst!='NRI':
                            StartWait(self.iWaitMs)
                        else:
                            StartWait(2000)
                    oSetting.oSocket.sendall(byMsg)
                    eRet = eReturnCode.Success
                    break
                except Exception as e:
                    self.ShowError(uMsg = u'Can\'t Send Message',uParConfigName=oSetting.uConfigName,oException=e)
                    eRet = eReturnCode.Error
                    oSetting.Disconnect()
                    if not uRetVar==u'':
                        SetVar(uVarName = uRetVar, oVarValue = u"Error")
            else:
                if iTryCount==self.iMaxTryCount:
                    self.ShowWarning(uMsg=u'Nothing done,not connected! ->[%s]' % oAction.uActionName, uParConfigName=oSetting.uConfigName)
                if uRetVar:
                    SetVar(uVarName = uRetVar, oVarValue = u"?")

        self.CloseSettingConnection(oSetting=oSetting,bNoLogOut=bNoLogOut)
        return eRet