Commit 78b59620 authored by Jakob Moser's avatar Jakob Moser
Browse files

Merge branch 'backend/nfc' into 'master'

Add basic runnable module to ID cards

See merge request moser/poolpay!8
parents 1bd1928f 31187839
Loading
Loading
Loading
Loading

poolpay/card/README.md

0 → 100644
+14 −0
Original line number Diff line number Diff line
# PoolPay Card Interface

This package contains code to interface with NFC cards, namely Pool Cards.

It forms part of the larger PoolPay application, but can also be run as a standalone module (primarily for experimenting purposes).

## Run as standalone module

Execute the following lines in the base repository directory:

```bash
source venv/bin/activate
python3 -m poolpay.card id
```
+49 −0
Original line number Diff line number Diff line
import argparse

from poolpay.card.CardReader import CardReader
from poolpay.card.Mfrc522CardReader import Mfrc522CardReader

READERS = {
    "mfrc522": Mfrc522CardReader,
}

DEFAULT_READER = "mfrc522"


def action_id(reader: CardReader) -> None:
    card_id = reader.read_id()
    print("Card ID (base 10)", card_id)
    print("Card ID (base 16)", [hex(i) for i in card_id])


ACTIONS = {"id": action_id}


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(
        prog="poolpay.card", description="Experimental util to interface with NFC cards"
    )
    parser.add_argument(
        "action",
        choices=["id"],
        help="the action to be done (currently, must always be 'id')",
    )
    parser.add_argument(
        "-u",
        "--using",
        choices=READERS.keys(),
        default=DEFAULT_READER,
        help="the reader class to be used",
    )

    return parser.parse_args()


# Parse the command line arguments
args = parse_args()

# Retrieve the requested reader class from the dictionary and create an instance
reader = READERS[args.using]()

# Call the selected action
ACTIONS[args.action](reader)