Example #1
0
File: test.py Project: sunzu/vot.ar
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"
Example #2
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"
Example #3
0
def loop():
    """Loop de pruebas de los comandos."""
    channel = StringIO()
    device = Device(channel)

    print "Enviando comandos de bateria"
    batt = PowerManager(channel)
    print "\nEnviando Comando consulta fuente de bateria actual (7.1)"
    batt.get_power_source()
    #read_and_process(device, channel)

    print "\nEnviando Comando consulta baterias conectadas (7.2)"
    batt.get_connected_batteries()
    read_and_process(device, channel)

    print "\nEnviando Comando consulta estado de funcionamiento (7.3)"
    batt.get_status()
    read_and_process(device, channel)

    print "\nEnviando Comando consulta de parametros de diseño (7.4)"
    batt.get_params()
    read_and_process(device, channel)

    print "\nEnviando Comando consulta funcionamiento convertidor DC/DC (7.5)"
    batt.check_voltages()
    read_and_process(device, channel)

    print "\n Enviando comando seleccion de modo de control de modo de alimentacion (7.6)"
    batt.power_source_control_mode()
    read_and_process(device, channel)

    print "\n Enviando comando de control de modo de alimentacion (7.7)"
    batt.power_source_control(True, True, True, True)
    read_and_process(device, channel)

    print "\nRegistrando evento bateria descargandose (7.8)"
    batt.register_battery_discharge()
    read_and_process(device, channel)

    print "\nRegistrando evento bateria nivel minimo (7.9)"
    batt.register_battery_level_min()
    read_and_process(device, channel)

    print "\nRegistrando evento bateria nivel critico (7.10)"
    batt.register_battery_level_critical()
    read_and_process(device, channel)

    print "\nRegistrando evento bateria nivel maximo (7.11)"
    batt.register_battery_level_max()
    read_and_process(device, channel)

    print "\nRegistrando evento switch AC (7.12)"
    batt.register_switch_ac()
    read_and_process(device, channel)

    print "\nRegistrando evento Bateria Desconectada (7.13)"
    batt.register_battery_unplugged()
    read_and_process(device, channel)

    print "\nRegistrando evento Bateria Agotada (7.14)"
    batt.register_battery_empty()
    read_and_process(device, channel)
    return

    print "\n---------\nEnviando comandos de impresion"
    printer = Printer(channel)

    print "\nEnviando comando consulta estado sensores (8.1)"
    printer.get_status()
    read_and_process(device, channel)

    print "\nEnviando comando mover motor (8.2)"
    printer.move(500)
    read_and_process(device, channel)

    print "\nEnviando comando (8.3)"
    printer.load_buffer("\x00\x01" * 500)
    read_and_process(device, channel)

    print "\nEnviando comando (8.4)"
    printer.do_print()
    read_and_process(device, channel)

    print "\nEnviando comando (8.5)"
    printer.clear_buffer()
    read_and_process(device, channel)

    print "\nEnviando comando (8.6)"
    printer.paper_eject()
    read_and_process(device, channel)

    print "\nEnviando comando (8.7)"
    printer.paper_start()
    read_and_process(device, channel)

    print "\nEnviando comando (8.8)"
    printer.get_autofeed()
    read_and_process(device, channel)

    print "\nEnviando comando (8.9)"
    printer.set_autofeed(-120)
    read_and_process(device, channel)

    print "\nEnviando comando (8.10)"
    printer.register_paper_inserted()
    read_and_process(device, channel)

    print "\nEnviando comando (8.11)"
    printer.register_paper_out_1()
    read_and_process(device, channel)

    print "\nEnviando comando (8.12)"
    printer.register_paper_out_2()
    read_and_process(device, channel)

    print "\nEnviando comando (8.13)"
    printer.register_lever_open
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de RFID"
    rfid = RFID(channel)

    print "\nEnviando comando obtener tags (9.1)"
    rfid.get_tags()
    read_and_process(device, channel)

    print "\nEnviando comando seleccionar tag(9.2)"
    rfid.select_tag("\x00\x01\x02\x03\x04\x05\x06\x07")
    read_and_process(device, channel)

    print "\nEnviando comando leer bloque(9.3)"
    rfid.read_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1)
    read_and_process(device, channel)

    print "\nEnviando comando leer multiples bloques (9.4)"
    rfid.read_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 5)
    read_and_process(device, channel)

    print "\nEnviando comando escribir bloque (9.5)"
    rfid.write_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1, "\x00\x01\x02\x03")
    read_and_process(device, channel)

    print "\nEnviando comando escribir bloques (9.6)"
    blocks = [
        "\x00\x01\x02\x03",
        "\x00\x01\x02\x03",
        "\x00\x01\x02\x03",
        "\x00\x01\x02\x03"
    ]
    rfid.write_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 4, blocks)
    read_and_process(device, channel)

    print "\nEnviando comando consulta tag solo lectura (9.7)"
    rfid.is_read_only("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 4)
    read_and_process(device, channel)

    print "\nEnviando comando establecer tag de solo lectura (9.8)"
    rfid.set_read_only_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1)
    read_and_process(device, channel)

    print "\nEnviando comando establecer tag de solo lectura (9.9)"
    rfid.set_read_only_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 5)
    read_and_process(device, channel)

    print "\nEnviando comando limpiar buffer(9.10)"
    rfid.clear_buffer()
    read_and_process(device, channel)

    print "\nEnviando comando consulta nivel de potencia antena (9.11)"
    rfid.get_antenna_level()
    read_and_process(device, channel)

    print "\nEnviando comando establecer nivel de potencia antena (9.12)"
    rfid.set_antenna_level(255)
    read_and_process(device, channel)

#     print "\nEnviando comando establecer led de encendido maquina ON/OFF (9.13)"
#     rfid.set_power_led(True)
#     read_and_process(device, channel)

    print "\nEnviando evento new tag"
    rfid.register_new_tag(100)
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de Backlight"
    backlight = Backlight(channel)

    print "\nEnviando comando obtener brillo (10.1)"
    backlight.get_brighthess()
    read_and_process(device, channel)

    print "\nEnviando comando establecer brillo (10.2)"
    backlight.set_brighthess(100, True)
    read_and_process(device, channel)

    print "\nEnviando obtener Backlight encendido/apagado (10.3)"
    backlight.get_status()
    read_and_process(device, channel)

    print "\nEnviando obtener Backlight encendido/apagado (10.4)"
    backlight.set_status(True)
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de Fan Coolers"
    fan = FanCoolers(channel)

    print "\nEnviando comando obtener velocidad (11.1)"
    fan.get_speed()
    read_and_process(device, channel)

    print "\nEnviando comando obtener velocidad (11.2)"
    fan.set_speed(50)
    read_and_process(device, channel)


    print "\n---------\nEnviando comandos de PIR"
    pir = PIR(channel)

    print "\nEnviando comando obtener velocidad (12.1)"
    pir.register_detected()
    read_and_process(device, channel)

    print "\nEnviando comando obtener velocidad (12.2)"
    pir.register_not_detected()
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de Buzzer"
    buzzer = Buzzer(channel)

    print "\nEnviando comando obtener velocidad (11.1)"
    buzzer.buzz("\x00\x50")
    read_and_process(device, channel)
Example #4
0
def loop():
    """Loop de pruebas de los comandos."""
    channel = StringIO()
    device = Device(channel)

    print "Enviando comandos de bateria"
    batt = PowerManager(channel)
    print "\nEnviando Comando consulta fuente de bateria actual (7.1)"
    batt.get_power_source()
    #read_and_process(device, channel)

    print "\nEnviando Comando consulta baterias conectadas (7.2)"
    batt.get_connected_batteries()
    read_and_process(device, channel)

    print "\nEnviando Comando consulta estado de funcionamiento (7.3)"
    batt.get_status()
    read_and_process(device, channel)

    print "\nEnviando Comando consulta de parametros de diseño (7.4)"
    batt.get_params()
    read_and_process(device, channel)

    print "\nEnviando Comando consulta funcionamiento convertidor DC/DC (7.5)"
    batt.check_voltages()
    read_and_process(device, channel)

    print "\n Enviando comando seleccion de modo de control de modo de alimentacion (7.6)"
    batt.power_source_control_mode()
    read_and_process(device, channel)

    print "\n Enviando comando de control de modo de alimentacion (7.7)"
    batt.power_source_control(True, True, True, True)
    read_and_process(device, channel)

    print "\nRegistrando evento bateria descargandose (7.8)"
    batt.register_battery_discharge()
    read_and_process(device, channel)

    print "\nRegistrando evento bateria nivel minimo (7.9)"
    batt.register_battery_level_min()
    read_and_process(device, channel)

    print "\nRegistrando evento bateria nivel critico (7.10)"
    batt.register_battery_level_critical()
    read_and_process(device, channel)

    print "\nRegistrando evento bateria nivel maximo (7.11)"
    batt.register_battery_level_max()
    read_and_process(device, channel)

    print "\nRegistrando evento switch AC (7.12)"
    batt.register_switch_ac()
    read_and_process(device, channel)

    print "\nRegistrando evento Bateria Desconectada (7.13)"
    batt.register_battery_unplugged()
    read_and_process(device, channel)

    print "\nRegistrando evento Bateria Agotada (7.14)"
    batt.register_battery_empty()
    read_and_process(device, channel)
    return

    print "\n---------\nEnviando comandos de impresion"
    printer = Printer(channel)

    print "\nEnviando comando consulta estado sensores (8.1)"
    printer.get_status()
    read_and_process(device, channel)

    print "\nEnviando comando mover motor (8.2)"
    printer.move(500)
    read_and_process(device, channel)

    print "\nEnviando comando (8.3)"
    printer.load_buffer("\x00\x01" * 500)
    read_and_process(device, channel)

    print "\nEnviando comando (8.4)"
    printer.do_print()
    read_and_process(device, channel)

    print "\nEnviando comando (8.5)"
    printer.clear_buffer()
    read_and_process(device, channel)

    print "\nEnviando comando (8.6)"
    printer.paper_eject()
    read_and_process(device, channel)

    print "\nEnviando comando (8.7)"
    printer.paper_start()
    read_and_process(device, channel)

    print "\nEnviando comando (8.8)"
    printer.get_autofeed()
    read_and_process(device, channel)

    print "\nEnviando comando (8.9)"
    printer.set_autofeed(-120)
    read_and_process(device, channel)

    print "\nEnviando comando (8.10)"
    printer.register_paper_inserted()
    read_and_process(device, channel)

    print "\nEnviando comando (8.11)"
    printer.register_paper_out_1()
    read_and_process(device, channel)

    print "\nEnviando comando (8.12)"
    printer.register_paper_out_2()
    read_and_process(device, channel)

    print "\nEnviando comando (8.13)"
    printer.register_lever_open
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de RFID"
    rfid = RFID(channel)

    print "\nEnviando comando obtener tags (9.1)"
    rfid.get_tags()
    read_and_process(device, channel)

    print "\nEnviando comando seleccionar tag(9.2)"
    rfid.select_tag("\x00\x01\x02\x03\x04\x05\x06\x07")
    read_and_process(device, channel)

    print "\nEnviando comando leer bloque(9.3)"
    rfid.read_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1)
    read_and_process(device, channel)

    print "\nEnviando comando leer multiples bloques (9.4)"
    rfid.read_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 5)
    read_and_process(device, channel)

    print "\nEnviando comando escribir bloque (9.5)"
    rfid.write_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1, "\x00\x01\x02\x03")
    read_and_process(device, channel)

    print "\nEnviando comando escribir bloques (9.6)"
    blocks = [
        "\x00\x01\x02\x03", "\x00\x01\x02\x03", "\x00\x01\x02\x03",
        "\x00\x01\x02\x03"
    ]
    rfid.write_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 4, blocks)
    read_and_process(device, channel)

    print "\nEnviando comando consulta tag solo lectura (9.7)"
    rfid.is_read_only("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 4)
    read_and_process(device, channel)

    print "\nEnviando comando establecer tag de solo lectura (9.8)"
    rfid.set_read_only_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1)
    read_and_process(device, channel)

    print "\nEnviando comando establecer tag de solo lectura (9.9)"
    rfid.set_read_only_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 5)
    read_and_process(device, channel)

    print "\nEnviando comando limpiar buffer(9.10)"
    rfid.clear_buffer()
    read_and_process(device, channel)

    print "\nEnviando comando consulta nivel de potencia antena (9.11)"
    rfid.get_antenna_level()
    read_and_process(device, channel)

    print "\nEnviando comando establecer nivel de potencia antena (9.12)"
    rfid.set_antenna_level(255)
    read_and_process(device, channel)

    #     print "\nEnviando comando establecer led de encendido maquina ON/OFF (9.13)"
    #     rfid.set_power_led(True)
    #     read_and_process(device, channel)

    print "\nEnviando evento new tag"
    rfid.register_new_tag(100)
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de Backlight"
    backlight = Backlight(channel)

    print "\nEnviando comando obtener brillo (10.1)"
    backlight.get_brighthess()
    read_and_process(device, channel)

    print "\nEnviando comando establecer brillo (10.2)"
    backlight.set_brighthess(100, True)
    read_and_process(device, channel)

    print "\nEnviando obtener Backlight encendido/apagado (10.3)"
    backlight.get_status()
    read_and_process(device, channel)

    print "\nEnviando obtener Backlight encendido/apagado (10.4)"
    backlight.set_status(True)
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de Fan Coolers"
    fan = FanCoolers(channel)

    print "\nEnviando comando obtener velocidad (11.1)"
    fan.get_speed()
    read_and_process(device, channel)

    print "\nEnviando comando obtener velocidad (11.2)"
    fan.set_speed(50)
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de PIR"
    pir = PIR(channel)

    print "\nEnviando comando obtener velocidad (12.1)"
    pir.register_detected()
    read_and_process(device, channel)

    print "\nEnviando comando obtener velocidad (12.2)"
    pir.register_not_detected()
    read_and_process(device, channel)

    print "\n---------\nEnviando comandos de Buzzer"
    buzzer = Buzzer(channel)

    print "\nEnviando comando obtener velocidad (11.1)"
    buzzer.buzz("\x00\x50")
    read_and_process(device, channel)