Пример #1
0
def test_encode():
    # Test v1 path
    v1_bytes = packet.encode(get_v1_dic())
    eq_(len(v1_bytes), 128)

    # Test v2 path
    v2_bytes = packet.encode(get_v2_dic())
    eq_(len(v2_bytes), packet.V2_LEN + packet.VERSION_LEN + packet.CRC_LEN)
Пример #2
0
def convert_v1_card_to_v2(nfc, card):
    with nfc_comm.Connection(nfc) as conn:
        v1_fields = card.dic['fields']
        v2_fields = packet.v1_to_v2(v1_fields)
        LOG.info('Converting v1 tag to v2. v1 tag %s\nv2 tag %s', v1_fields,
                 v2_fields)
        card.write(conn, packet.encode(v2_fields))
Пример #3
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('--version', default=2, nargs='?', type=int)
    options = parser.parse_args()

    nfc = nfc_comm.NFC()
    readers = nfc.get_readers()
    if len(readers) == 0:
        print('Cannot find NFC reader.')
        return 2

    reader_status = nfc_comm.ReaderStatus(nfc.get_status_change()[0])
    if not reader_status.is_card_present():
        print('No card present.')
        return 2

    print('Found card.')

    cards = nfc_comm.get_cards(nfc)
    if len(cards) == 0:
        print('Card is not NTAG203.')
        return 2

    print('Card is NTAG203.')
    card = cards[0]

    with nfc_comm.Connection(nfc) as conn:
        if options.version == 1:
            defaults = packet.v1_defaults()
        else:
            defaults = packet.v2_defaults(1)
        pprint(defaults)
        card.write(conn, packet.encode(defaults))
Пример #4
0
def rpc_write_tag(fields):
    LOG.info("rpc_write_tag: %s", fields)
    data_bytes = packet.encode(fields)
    LOG.debug("write bytes %s", nfc_comm.fmt_bytes(data_bytes))
    with nfc_comm.NFC() as nfc, nfc_comm.Connection(nfc) as conn:
        cards = nfc_comm.get_cards(nfc)
        card = cards[0]
        card.write(conn, data_bytes)
Пример #5
0
def test_v2_defaults_are_invertible():
    # While we're at it, let's just check that all of the defaults
    # can make the round trip through encoding and decoding.
    orig = packet.v2_defaults(1)
    eq_(orig, packet.decode(packet.encode(orig)))
Пример #6
0
def test_v1_encode_decode_roundtrip():
    dic_with_version = dict(get_v1_dic())
    dic_with_version['version'] = 1

    pkt_bytes = packet.encode(dic_with_version)
    eq_(packet.decode(pkt_bytes), dic_with_version)