示例#1
0
    def __init__(self, dlgid, modo='local', server='comms'):
        self.modo = modo
        self.dlgid = dlgid
        self.bdr = ''
        self.server = server
        self.datasource = ''

        bd = BDSPY(self.modo)
        self.datasource = bd.find_data_source(self.dlgid)
        if self.datasource == 'GDA':
            self.bdr = BDGDA(self.modo, server)
        elif self.datasource == 'GDA_TAHONA':
            self.bdr = BDGDA_TAHONA(self.modo, server)
        elif self.datasource == 'BDOSE_PQ':
            self.bdr = BDOSE_PQ(self.modo, server)
        elif self.datasource == 'BDOSE_PZ':
            self.bdr = BDOSE_PZ(self.modo, server)
        elif self.datasource == 'BDOSE_TQ':
            self.bdr = BDOSE_TQ(self.modo, server)
        elif self.datasource == 'DLGDB':
            self.bdr = DLGDB(self.modo, server)
        else:
            self.datasource = 'DS_ERROR'
            log(module=__name__,
                server=server,
                function='__init__',
                level='INFO',
                dlgid='PROC00',
                msg='ERROR: DLGID={0}:DS={1} NOT implemented'.format(
                    dlgid, self.datasource))

        return
示例#2
0
    def __init__ (self, dlgid, modo = 'local', server='comms'):
        '''
        El objeto que creo es un puntero a la BD generico
        Luego de find_data_source, puedo saber en que BD real esta definido el datalooger.
        Este lo dejo en el parametro bdr que va a apuntar a la clase de la base de datos
        donde realmente esta definido el datalogger.
        Las consultas se mapean a metodos de esta clase.
        '''
        self.modo = modo
        self.dlgid = dlgid
        self.bdr = ''
        self.server = server
        self.datasource = ''

        log(module=__name__, function='__init__', dlgid=self.dlgid, msg='start')

        bd = BDSPY(self.modo)
        self.datasource = bd.find_data_source(self.dlgid)
        if self.datasource == 'GDA':
            self.bdr = BDGDA(self.modo, server)
        elif self.datasource == 'GDA_TAHONA':
            self.bdr = BDGDA_TAHONA(self.modo, server)
        elif self.datasource == 'BDOSE_PQ':
            self.bdr = BDOSE_PQ(self.modo, server)
        elif self.datasource == 'BDOSE_PZ':
            self.bdr = BDOSE_PZ(self.modo, server)
        elif self.datasource == 'BDOSE_TQ':
            self.bdr = BDOSE_TQ(self.modo, server)
        elif self.datasource == 'DLGDB':
            self.bdr = DLGDB(self.modo, server)
        else:
            self.datasource = 'DS_ERROR'
            log(module=__name__, server=server, function='__init__', level='INFO', dlgid='PROC00', msg='ERROR: DLGID={0}:DS={1} NOT implemented'.format(dlgid, self.datasource))

        return
示例#3
0
    def process(self):
        '''
        Define la logica de procesar los frames de SCAN
        Primero hago una conexion a la BDSPY.
        - Si el dlgid esta definido, OK
        - Si no esta pero si el uid, le mando al datalogger que se reconfigure
           con el dlg asociado al uid.
        - Si no esta el dlgid ni el uid, ERROR
        '''

        bd = BDSPY(Config['MODO']['modo'])
        # Primero vemos que el dlgid este definido sin importar su uid
        if bd.dlg_is_defined(self.dlgid):
            log(module=__name__,
                function='process',
                dlgid=self.dlgid,
                msg='SCAN OK')
            self.send_response('SCAN_OK')
        # Si no esta definido, busco si hay algun uid y a que dlgid corresponde
        elif bd.uid_is_defined(self.uid):
            new_dlgid = bd.get_dlgid_from_uid(self.uid)
            log(module=__name__,
                function='process',
                dlgid=self.dlgid,
                msg='bdconf NEW_DLGID={}'.format(new_dlgid))
            self.send_response('DLGID=%s' % new_dlgid)
        else:
            log(module=__name__,
                function='process',
                dlgid=self.dlgid,
                msg='DLGID/UID not Defined !!')
            self.send_response('NOTDEFINED')

        return
示例#4
0
    def find_datasource( self, dlgid ):
        # Si ya tengo el datasource no tengo que consultar a la BD.
        if self.datasource != '':
            return

        bd = BDSPY(self.modo, self.server )
        self.datasource = bd.find_data_source(dlgid)
        return
示例#5
0
    def process(self):
        '''
        Define la logica de procesar los frames de SCAN
        Primero hago una conexion a la BDSPY.
        - Si el dlgid esta definido, OK
        - Si no esta pero si el uid, le mando al datalogger que se reconfigure
           con el dlg asociado al uid.
        - Si no esta el dlgid ni el uid, ERROR
        '''
        log(module=__name__, function='process', dlgid=self.dlgid, msg='start')

        bd = BDSPY(Config['MODO']['modo'])
        uid = self.payload_dict.get('UID', 'ERROR')
        # Primero vemos que el dlgid este definido sin importar su uid
        if bd.dlg_is_defined(self.dlgid):
            log(module=__name__, function='process', dlgid=self.dlgid, msg='SCAN OK')
            # Actualizo el uid c/vez que me conecto si el dlgid coincide
            bd.update_uid(self.dlgid, uid)
            self.response_pload = 'STATUS:OK'
            self.send_response()
        # Si no esta definido, busco si hay algun uid y a que dlgid corresponde
        elif bd.uid_is_defined(uid):
            new_dlgid = bd.get_dlgid_from_uid(uid)
            self.response_pload = 'STATUS:RECONF;DLGID:{}'.format(new_dlgid)
            log(module=__name__, function='process', dlgid=self.dlgid, msg='bdconf NEW_DLGID={}'.format(new_dlgid))
            self.send_response()
        else:
            self.response_pload = 'STATUS:UNDEF'
            self.send_response()
            log(module=__name__, function='process', dlgid=self.dlgid, msg='DLGID/UID not Defined !!')

        return
示例#6
0
    def process(self):
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='start')
        # Veo si esta autorizado y actualizo el uid
        bd = BDSPY(Config['MODO']['modo'])
        if not bd.check_auth(self.dlgid, self.uid):
            self.response = 'NOT_ALLOWED'
            self.send_response()
            return

        # Leo toda la configuracion desde la BD en un dict
        bd = BD(modo=Config['MODO']['modo'], dlgid=self.dlgid)
        dcnf = bd.read_dlg_conf()
        if dcnf == {}:
            log(module=__name__,
                function='process',
                dlgid=self.dlgid,
                msg='ERROR: No hay datos en la BD')
            self.response = 'ERROR'
            self.send_response()
            return

        # Proceso c/modulo
        d = self.PV_process_conf_parametros_base(dcnf)
        self.PV_process_conf_parametros_analog(dcnf)
        self.PV_process_conf_parametros_digital(dcnf)
        self.PV_process_conf_parametros_counter(dcnf)
        self.PV_process_conf_parametros_doutput(dcnf)

        # Actualizo la BD con los datos.
        # Creo un registo inicialiado en la redis.
        bd.bdr.update(self.dlgid, d)
        redis_db = Redis(self.dlgid).create_rcd()
        self.send_response()
        return
示例#7
0
    def process(self):
        '''
        El procesamiento consiste ver si en la BDSPY hay una entrada con el DLGID y el UID.
        '''
        log(module=__name__,
            function='process',
            level='SELECT',
            dlgid=self.dlgid,
            msg='dlgid={0},uid={1}'.format(self.dlgid, self.uid))
        bd = BDSPY(modo=Config['MODO']['modo'])

        if bd.dlg_is_defined(self.dlgid):
            '''
            Comprende los casos ( DLGID OK, UID OK ) y
            ( DLGID OK, UID err )
            En este ultimo, arregla en la BD el UID. 
            '''
            bd.update_uid(self.dlgid, self.uid)
            pload = 'CLASS:AUTH;STATUS:OK'
            u_send_response('INIT', pload)
            log(module=__name__,
                function='send_response',
                dlgid=self.dlgid,
                msg='PLOAD={0}'.format(pload))

        elif bd.uid_is_defined(self.uid):
            dlgid_from_bd = bd.get_dlgid_from_uid(self.uid)
            pload = 'CLASS:AUTH;STATUS:RECONF;DLGID:{}'.format(dlgid_from_bd)
            u_send_response('INIT', pload)
            log(module=__name__,
                function='send_response',
                dlgid=self.dlgid,
                msg='PLOAD={0}'.format(pload))

        else:
            '''
            No encontramos el DLGID ni un UID que permita recuperarnos.
            ERROR
            '''
            pload = 'CLASS:AUTH;STATUS:ERROR_DS'
            u_send_response('INIT', pload)
            log(module=__name__,
                function='send_response',
                dlgid=self.dlgid,
                msg='PLOAD={0}'.format(pload))

        return
示例#8
0
    def process(self):
        '''
        Define la logica de procesar los frames de INIT:GENERAL
        PLOAD=CLASS:GLOBAL;NACH:5;NDCH:3;NCNT:3;SIMPWD:DEFAULT;IMEI:860585004367917;SIMID:895980161423091055;CSQ:87;WRST:0x00;BASE:0x32;AN:0xCB;DG:0x1A;CNT:0x47;RG:0xF7;PSE:0x73;OUT:0xB2
        Leo toda la configuracion en un dict y luego lo paso a los diferentes modulos que calculan los ckecksum
        de c/seccion.
        Si algun checksum no coincide voy agregandolo a la respuesta al server.
        '''
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='start')

        # Veo si esta autorizado y actualizo el uid
        uid = self.payload_dict.get('UID', '0000')
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='DEBUG dlgid={0},uid={1}'.format(self.dlgid, uid))

        if uid != '000':
            log(module=__name__,
                function='process',
                dlgid=self.dlgid,
                level='SELECT',
                msg='DEBUG UID Not default'.format(self.dlgid, uid))
            bd = BDSPY(modo=Config['MODO']['modo'])
            if not bd.check_auth(self.dlgid, uid):
                self.response_pload += ':NOT_ALLOWED'
                self.send_response()
                return
        '''
        La configuracion del dlg de la base de datos ya fue leida en la clase superior RAW_INIT y se encuentra
        en self.dlgbdconf_dict
        '''
        # Parametros administrativos:
        simpwd = self.payload_dict.get('SIMPWD', 'ERROR')
        wrst = self.payload_dict.get('WRST', 'ERROR')
        d = dict()
        try:
            d['IPADDRESS'] = cgi.escape(os.environ["REMOTE_ADDR"])
        except:
            d['IPADDRESS'] = '0.0.0.0'

        d['RCVDLINE'] = os.environ['QUERY_STRING']
        d['FIRMWARE'] = self.version
        d['IMEI'] = self.payload_dict.get('IMEI', 'ERROR')
        d['CSQ'] = self.payload_dict.get('CSQ', 'ERROR')
        d['SIMID'] = self.payload_dict.get('SIMID', 'ERROR')
        d['COMMITED_CONF'] = 0

        # Actualizo la BD con estos datos.
        bd = BD(modo=Config['MODO']['modo'], dlgid=self.dlgid)
        bd.bdr.update(self.dlgid, d)
        # Creo un registo inicialiado en la redis.
        redis_db = Redis(self.dlgid).create_rcd()

        # Analizo los checksums individuales
        # Checksum parametros base
        #log(module=__name__, function='process', dlgid=self.dlgid, level='SELECT',msg='DEBUG_base')
        a = int(self.payload_dict.get('BASE', '0'), 16)
        b = self.PV_checksum_base(self.dlgbdconf_dict)
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='CKS_BASE: dlg={0}, bd={1}'.format(hex(a), hex(b)))
        if a != b:
            self.response_pload += ';BASE'

        # checksum parametros analog
        #log(module=__name__, function='process', dlgid=self.dlgid, level='SELECT', msg='DEBUG_analog')
        a = int(self.payload_dict.get('AN', '0'), 16)
        b = self.PV_checksum_analog(self.dlgbdconf_dict)
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='CKS_AN: dlg={0}, bd={1}'.format(hex(a), hex(b)))
        if a != b:
            self.response_pload += ';ANALOG'

        # chechsum parametros digital
        a = int(self.payload_dict.get('DG', '0'), 16)
        b = self.PV_checksum_digital(self.dlgbdconf_dict)
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='CKS_DG: dlg={0}, bd={1}'.format(hex(a), hex(b)))
        if a != b:
            self.response_pload += ';DIGITAL'

        # chechsum parametros contadores
        a = int(self.payload_dict.get('CNT', '0'), 16)
        b = self.PV_checksum_counters(self.dlgbdconf_dict)
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='CKS_CNT: dlg={0}, bd={1}'.format(hex(a), hex(b)))
        if a != b:
            self.response_pload += ';COUNTERS'

        # chechsum parametros range
        a = int(self.payload_dict.get('RG', '0'), 16)
        b = self.PV_checksum_range(self.dlgbdconf_dict)
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='CKS_RANGE: dlg={0}, bd={1}'.format(hex(a), hex(b)))
        if a != b:
            self.response_pload += ';RANGE'

        # chechsum parametros psensor
        a = int(self.payload_dict.get('PSE', '0'), 16)
        b = self.PV_checksum_psensor(self.dlgbdconf_dict)
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='CKS_PSENS: dlg={0}, bd={1}'.format(hex(a), hex(b)))
        if a != b:
            self.response_pload += ';PSENSOR'

        # chechsum parametros aplicacion
        a = int(self.payload_dict.get('APP', '0'), 16)
        b = self.PV_checksum_aplicacion(self.dlgbdconf_dict)
        log(module=__name__,
            function='process',
            dlgid=self.dlgid,
            level='SELECT',
            msg='CKS_APP: dlg={0}, bd={1}'.format(hex(a), hex(b)))
        if a != b:
            self.response_pload += ';APLICACION'

        self.send_response()
        return