Exemple #1
0
    def get_tag_metadata(self):
        tag_meta = None
        tags = self.parent.rfid.get_tags()
        if tags is not None:
            tags = tags[0]
        if tags:
            if tags['number'] == 1:
                serial = tags['serial_number'][0]
                data = self.parent.rfid.read_block(array_to_string(serial), 0)
                if data:
                    data = list(data[0]['bytes'])
                    if data[1] in TIPOS_TAGS:
                        tipo_tag = TIPOS_TAGS[data[1]]
                    else:
                        tipo_tag = TIPOS_TAGS[COD_TAG_DESCONOCIDO]

                    tag_meta = {'serial': self._get_normalized_serial(serial),
                                'token': self._get_normalized_token(data[0]),
                                'tipo': tipo_tag,
                                'longitud': data[2:],
                                'clase': CLASE_ICODE2,
                                'reception_level':
                                tags['reception_level'][0][0]
                                }
        return tag_meta
Exemple #2
0
 def get_map(self):
     response = self.parent.rfid.get_tags()[0]
     dmp = []
     if response is not None and response['number'] == 1:
         serial = array_to_string(response['serial_number'][0])
         retries = 5
         bloques = []
         while retries > 0:
             rfid_data = self.parent.rfid.read_blocks(serial, 0, 27)
             if rfid_data is None or rfid_data[3] == MSG_ERROR:
                 retries -= 1
                 continue
             retries = 0
             for block in rfid_data[0]:
                 bloques.extend(block['bytes'])
             for i in range(0, 28):
                 offset = i * 4
                 bloque = bloques[offset:offset + 4]
                 hexa = array_to_printable_string(bloque, ' ')
                 hexa2 = hexa3 = ''
                 for c in bloque:
                     # Me fijo si es imprimible
                     if c >= 32 and c <= 126:
                         hexa2 += chr(c)
                     else:
                         hexa2 += '.'
                     hexa3 += str(c).zfill(3) + ' '
                 dmp.append('Block %02d: %s | %s | %s' %
                            (i, hexa, hexa2, hexa3))
     return dumps(dmp, encoding='latin-1')
Exemple #3
0
    def _get_tag_response(self, response, index=0, multi=False):
        tag = None
        tipo = NO_TAG
        serial = response['serial_number'][index]
        if multi:
            data = self.parent.rfid.get_multitag_data()
        else:
            func = self.parent.rfid.get_tag_data
            data = func(array_to_string(serial),
                        comprobar_token=COMPROBAR_TOKEN)

        if data is not None:
            if data['tipo_tag'] in TIPOS_TAGS:
                tipo_tag = TIPOS_TAGS[data['tipo_tag']]
            else:
                tipo_tag = TIPOS_TAGS[COD_TAG_DESCONOCIDO]

            if tipo_tag in TAGS_ADMIN:
                tipo = TAG_ADMIN
            else:
                if data['user_data'] == "":
                    tipo = TAG_VACIO
                else:
                    tipo = TAG_DATOS
            tag = {
                "serial": self._get_normalized_serial(serial),
                "token": self._get_normalized_token(data['token']),
                "datos": b64encode(data['user_data']),
                "tipo": tipo_tag,
                "clase": CLASE_ICODE2,
                "reception_level": response['reception_level'][index][0]
            }
        return tipo, tag
Exemple #4
0
    def _get_tag_response(self, response, index=0, multi=False):
        tag = None
        tipo = NO_TAG
        serial = response['serial_number'][index]
        if multi:
            data = self.parent.rfid.get_multitag_data()
        else:
            func = self.parent.rfid.get_tag_data
            data = func(array_to_string(serial),
                        comprobar_token=COMPROBAR_TOKEN)

        if data is not None:
            if data['tipo_tag'] in TIPOS_TAGS:
                tipo_tag = TIPOS_TAGS[data['tipo_tag']]
            else:
                tipo_tag = TIPOS_TAGS[COD_TAG_DESCONOCIDO]

            if tipo_tag in TAGS_ADMIN:
                tipo = TAG_ADMIN
            else:
                if data['user_data'] == "":
                    tipo = TAG_VACIO
                else:
                    tipo = TAG_DATOS
            tag = {"serial": self._get_normalized_serial(serial),
                   "token": self._get_normalized_token(data['token']),
                   "datos": b64encode(data['user_data']),
                   "tipo": tipo_tag,
                   "clase": CLASE_ICODE2,
                   "reception_level": response['reception_level'][index][0]
                   }
        return tipo, tag
Exemple #5
0
    def get_tag_metadata(self):
        tag_meta = None
        tags = self.parent.rfid.get_tags()
        if tags is not None:
            tags = tags[0]
        if tags:
            if tags['number'] == 1:
                serial = tags['serial_number'][0]
                data = self.parent.rfid.read_block(array_to_string(serial), 0)
                if data:
                    data = list(data[0]['bytes'])
                    if data[1] in TIPOS_TAGS:
                        tipo_tag = TIPOS_TAGS[data[1]]
                    else:
                        tipo_tag = TIPOS_TAGS[COD_TAG_DESCONOCIDO]

                    tag_meta = {
                        'serial': self._get_normalized_serial(serial),
                        'token': self._get_normalized_token(data[0]),
                        'tipo': tipo_tag,
                        'longitud': data[2:],
                        'clase': CLASE_ICODE2,
                        'reception_level': tags['reception_level'][0][0]
                    }
        return tag_meta
Exemple #6
0
 def get_map(self):
     response = self.parent.rfid.get_tags()[0]
     dmp = []
     if response is not None and response['number'] == 1:
         serial = array_to_string(response['serial_number'][0])
         retries = 5
         bloques = []
         while retries > 0:
             rfid_data = self.parent.rfid.read_blocks(serial, 0, 27)
             if rfid_data is None or rfid_data[3] == MSG_ERROR:
                 retries -= 1
                 continue
             retries = 0
             for block in rfid_data[0]:
                 bloques.extend(block['bytes'])
             for i in range(0, 28):
                 offset = i * 4
                 bloque = bloques[offset:offset + 4]
                 hexa = array_to_printable_string(bloque, ' ')
                 hexa2 = hexa3 = ''
                 for c in bloque:
                     # Me fijo si es imprimible
                     if c >= 32 and c <= 126:
                         hexa2 += chr(c)
                     else:
                         hexa2 += '.'
                     hexa3 += str(c).zfill(3) + ' '
                 dmp.append('Block %02d: %s | %s | %s' % (i, hexa, hexa2,
                                                          hexa3))
     return dumps(dmp, encoding='latin-1')
Exemple #7
0
def dar_masa_via_controller():
    from msa.core.ipc.server.armve_service import ARMVEDBus
    from msa.core.ipc.server.armve_controller import ARMVEController
    class MockDbus(ARMVEDBus):
        def __init__(self):
            self._conn = False
            self.buffer = None
            self.printing = False
            self._fan_auto_mode = True
            self.controller = ARMVEController(self)
            self._last_temp = 0
            self._off_counter = 0
            self._last_speed = -1
            self._ac_power_source = True
            # Registro eventos a despachar
            self._init_map()
            # Abro el canal e inicializo
            self.precache_data()
            self._locations = []
            self.connect_and_load()
    mock = MockDbus()
    tag = b64encode(get_tag())
    while True:
        mock.controller.guardar_tag("TAG_RECUENTO", tag, False, True)
        blocks_to_write = [[0, 0, 0, 0]] * 26
        tags = mock.rfid.get_tags()
        serial_number = tags[0]['serial_number'][0]
        mock.rfid.write_blocks(array_to_string(serial_number), 0, 25, blocks_to_write)
        sleep(0.3)
Exemple #8
0
 def set_tipo(self, serial, tipo):
     if tipo not in TIPOS_TAGS_REV:
         return
     serial = array_to_string(serial)
     tipo = TIPOS_TAGS_REV[tipo]
     metadata = list(self.parent.rfid.read_block(serial, 0)[0]['bytes'])
     metadata[1] = tipo
     self.parent.rfid.write_block(serial, 0, metadata)
Exemple #9
0
 def set_tipo(self, serial, tipo):
     if tipo not in TIPOS_TAGS_REV:
         return
     serial = array_to_string(serial)
     tipo = TIPOS_TAGS_REV[tipo]
     metadata = list(self.parent.rfid.read_block(serial, 0)[0]['bytes'])
     metadata[1] = tipo
     self.parent.rfid.write_block(serial, 0, metadata)
Exemple #10
0
def dar_masa():
    channel = init_channel()
    rfid = RFID(channel)
    fan = FanCoolers(channel)
    fan.set_speed(0)

    tags = rfid.get_tags()
    serial_number = tags[0]['serial_number'][0]
    todo_bien = True
    tag = get_tag()
    while todo_bien:
        rfid.write_tag(array_to_string(serial_number), 4, TOKEN, tag)
        rfid_data = rfid.get_tag_data(serial_number)
        todo_bien = rfid_data is not None
Exemple #11
0
def borrar_tag():
    channel = init_channel()
    rfid = RFID(channel)

    rfid.register_new_tag()
    while True:
        esperar_evento(rfid, DEV_RFID, EVT_RFID_NEW_TAG)

        tags = rfid.get_tags()[0]
        if tags['number']:
            serial_number = tags['serial_number'][0]
            print "!!!->SERIAL", serial_number
            serial_number = array_to_string(serial_number)
            rfid.write_blocks(serial_number, 0, 27, [[0, 0, 0, 0]] * 27)

    rfid.unregister_new_tag()
Exemple #12
0
def borrar_tag():
    channel = init_channel()
    rfid = RFID(channel)

    rfid.register_new_tag()
    while True:
        esperar_evento(rfid, DEV_RFID, EVT_RFID_NEW_TAG)

        tags = rfid.get_tags()[0]
        if tags['number']:
            serial_number = tags['serial_number'][0]
            print "!!!->SERIAL", serial_number
            serial_number = array_to_string(serial_number)
            rfid.write_blocks(serial_number, 0, 27, [[0, 0, 0, 0]] * 27)

    rfid.unregister_new_tag()
Exemple #13
0
    def desde_qr(cls, datos):
        """Devuelve un recuento a partir de la informacion de un qr."""
        # tipo de qr
        token = datos[1:3]
        if not datos.startswith('R') or token != TOKEN:
            raise TipoQrErroneo()

        datos = datos[1:]
        len_datos = int(datos[2:4], 16)
        datos_recuento = datos[4:]
        if len_datos != len(datos_recuento):
            len_datos = int(datos[2:5], 16)
            datos_recuento = datos[5:]
            if len_datos != len(datos_recuento):
                raise QRMalformado()
        datos_recuento = array_to_string(serial_16_to_8(datos_recuento))
        recuento = Recuento.desde_tag(datos_recuento, con_dnis=True)

        return recuento
Exemple #14
0
    def desde_qr(cls, datos):
        """Devuelve un recuento a partir de la informacion de un qr."""
        # tipo de qr
        token = datos[1:3]
        if not datos.startswith('R') or token != TOKEN:
            raise TipoQrErroneo()

        datos = datos[1:]
        len_datos = int(datos[2:4], 16)
        datos_recuento = datos[4:]
        if len_datos != len(datos_recuento):
            len_datos = int(datos[2:5], 16)
            datos_recuento = datos[5:]
            if len_datos != len(datos_recuento):
                raise QRMalformado()
        datos_recuento = array_to_string(serial_16_to_8(datos_recuento))
        recuento = Recuento.desde_tag(datos_recuento, con_dnis=True)

        return recuento
Exemple #15
0
 def write(self, serial, tipo, data, marcar_ro):
     success = False
     serial = array_to_string(serial)
     tipo = TIPOS_TAGS_REV[tipo]
     header_data = self.parent.rfid.read_block(serial, 0)
     if header_data is not None and header_data[3] != MSG_ERROR:
         retries_left = 3
         while not success and retries_left:
             multi_tag = self.parent.rfid.write_tag(serial, tipo, TOKEN,
                                                    data)
             success = self._check_data(serial, data, tipo, multi_tag)
             retries_left -= 1
         if success and marcar_ro:
             if multi_tag:
                 tags = self.parent.rfid.get_tags()[0]['serial_number']
                 for serial in tags:
                     self.parent.rfid.quemar_tag(serial)
             else:
                 self.parent.rfid.quemar_tag(serial)
     return success
Exemple #16
0
 def write(self, serial, tipo, data, marcar_ro):
     success = False
     serial = array_to_string(serial)
     tipo = TIPOS_TAGS_REV[tipo]
     header_data = self.parent.rfid.read_block(serial, 0)
     if header_data is not None and header_data[3] != MSG_ERROR:
         retries_left = 3
         while not success and retries_left:
             multi_tag = self.parent.rfid.write_tag(serial, tipo, TOKEN,
                                                    data)
             success = self._check_data(serial, data, tipo, multi_tag)
             retries_left -= 1
         if success and marcar_ro:
             if multi_tag:
                 tags = self.parent.rfid.get_tags()[0]['serial_number']
                 for serial in tags:
                     self.parent.rfid.quemar_tag(serial)
             else:
                 self.parent.rfid.quemar_tag(serial)
     return success
Exemple #17
0
def test_rfid(channel=None, quemar=False):
    if channel is None:
        channel = init_channel()
        agent = Agent(channel)
        agent.unregister_events()
        channel.flushInput()
        channel.flushOutput()

    rfid = RFID(channel)
    device = Device(channel)

    print "!!!!-> limpiando buffer de RFID"
    inicio = time()
    rfid.clear_buffer()

    print "!!!!-> tiempo transcurrido de clear_buffer", time() - inicio

    tags = rfid.get_tags()
    if tags[0]['number'] == 0:
        rfid.register_new_tag()
        print 'esperando evento...'
        esperar_evento(device, DEV_RFID, EVT_RFID_NEW_TAG)
        print 'gotcha!'
        tags = rfid.get_tags()

    serial_number = tags[0]['serial_number'][0]
    print "!!!->SERIAL", serial_number
    serial_number = array_to_string(serial_number)
    #rfid.select_tag(serial_number)
    #serial_number = "\x00"*8
    blocks = rfid.read_blocks(serial_number, 0, 4)
    print "!!!-> read blocks:", blocks_to_string(blocks[0])
    blocks_to_write = ["hola", "lipe", "chau", "chan", "pato", "mono",
                        "juan", "gato", "casa", "masa", "pasa", "gabi",
                        "aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff",
                        "gggg", "hhhh", "iiii", "jjjj", "kkkk", "llll",
                        "mmmm", "nnnn", "oooo"]
    rfid.write_blocks(serial_number, 0, 26, blocks_to_write)
    blocks = rfid.read_blocks(serial_number, 0, 26)
    read_blocks = blocks_to_string(blocks[0])
    if read_blocks == blocks_to_write:
        print "!!!!-> test de escritura de bloques pasado"
    else:
        print "!!!!-> test de escritura de bloques NO pasado!!!!!!"

    blocks_to_write.reverse()

    for i, block_to_write in enumerate(blocks_to_write):
        rfid.write_block(serial_number, i, block_to_write)
    blocks = rfid.read_blocks(serial_number, 0, 26)
    read_blocks = blocks_to_string(blocks[0])
    if read_blocks == blocks_to_write:
        print "!!!!-> test de escritura de bloque pasado"
    else:
        print "!!!!-> test de escritura de bloque NO pasado!!!!!!"
    if quemar:
        write_status = rfid.is_read_only(serial_number, 0, 26)
        rfid.set_read_only_blocks(serial_number, 0, 20)
        rfid.set_read_only_block(serial_number, 26)
        write_status = rfid.is_read_only(serial_number, 0, 27)
        write_status = [block.byte for block in write_status[0]]
        expected = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 0, 0, 0, 0, 0, 1, 0]
        if write_status == expected:
            print "test de quemado OK"
        else:
            print "test de quemado FAIL"
    else:
        print "ojo que no estoy quemando"
Exemple #18
0
def test_rfid(channel=None, quemar=False):
    if channel is None:
        channel = init_channel()
        agent = Agent(channel)
        agent.unregister_events()
        channel.flushInput()
        channel.flushOutput()

    rfid = RFID(channel)
    device = Device(channel)

    print "!!!!-> limpiando buffer de RFID"
    inicio = time()
    rfid.clear_buffer()

    print "!!!!-> tiempo transcurrido de clear_buffer", time() - inicio

    tags = rfid.get_tags()
    if tags[0]['number'] == 0:
        rfid.register_new_tag()
        print 'esperando evento...'
        esperar_evento(device, DEV_RFID, EVT_RFID_NEW_TAG)
        print 'gotcha!'
        tags = rfid.get_tags()

    serial_number = tags[0]['serial_number'][0]
    print "!!!->SERIAL", serial_number
    serial_number = array_to_string(serial_number)
    #rfid.select_tag(serial_number)
    #serial_number = "\x00"*8
    blocks = rfid.read_blocks(serial_number, 0, 4)
    print "!!!-> read blocks:", blocks_to_string(blocks[0])
    blocks_to_write = [
        "hola", "lipe", "chau", "chan", "pato", "mono", "juan", "gato", "casa",
        "masa", "pasa", "gabi", "aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff",
        "gggg", "hhhh", "iiii", "jjjj", "kkkk", "llll", "mmmm", "nnnn", "oooo"
    ]
    rfid.write_blocks(serial_number, 0, 26, blocks_to_write)
    blocks = rfid.read_blocks(serial_number, 0, 26)
    read_blocks = blocks_to_string(blocks[0])
    if read_blocks == blocks_to_write:
        print "!!!!-> test de escritura de bloques pasado"
    else:
        print "!!!!-> test de escritura de bloques NO pasado!!!!!!"

    blocks_to_write.reverse()

    for i, block_to_write in enumerate(blocks_to_write):
        rfid.write_block(serial_number, i, block_to_write)
    blocks = rfid.read_blocks(serial_number, 0, 26)
    read_blocks = blocks_to_string(blocks[0])
    if read_blocks == blocks_to_write:
        print "!!!!-> test de escritura de bloque pasado"
    else:
        print "!!!!-> test de escritura de bloque NO pasado!!!!!!"
    if quemar:
        write_status = rfid.is_read_only(serial_number, 0, 26)
        rfid.set_read_only_blocks(serial_number, 0, 20)
        rfid.set_read_only_block(serial_number, 26)
        write_status = rfid.is_read_only(serial_number, 0, 27)
        write_status = [block.byte for block in write_status[0]]
        expected = [
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
            0, 0, 0, 0, 1, 0
        ]
        if write_status == expected:
            print "test de quemado OK"
        else:
            print "test de quemado FAIL"
    else:
        print "ojo que no estoy quemando"