You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainClass.cpp 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // Created by robin on 8/8/15.
  3. //
  4. #include <iostream>
  5. #include <sysexits.h>
  6. #include <DBO/Result.h>
  7. #include <DataAccess/LibNfc.h>
  8. #include <DataAccess/FreeFareDevice.h>
  9. #include "CommandLineParser.h"
  10. #include "MainClass.h"
  11. MainClass::MainClass(int argc, char *argv[])
  12. : _argc(argc)
  13. , _argv(argv)
  14. {
  15. }
  16. int MainClass::main()
  17. {
  18. std::cout << "LibNfc version: " << LibNfc::getVersion() << std::endl;
  19. LibNfc libNfc;
  20. auto init = libNfc.init();
  21. if (!init) {
  22. init.print();
  23. return 1;
  24. }
  25. auto devices = libNfc.getDevices();
  26. if (!devices) {
  27. devices.print();
  28. return 2;
  29. }
  30. if (devices.getData().size() == 0) {
  31. std::cerr << "No NFC device found" << std::endl;
  32. return 3;
  33. }
  34. std::cout << "Found " << devices.getData().size() << " devices: " << std::endl;
  35. for (size_t i = 0; i < devices.getData().size(); ++i) {
  36. std::cout << devices.getData()[i]->getConnStr() << std::endl;
  37. }
  38. auto device = devices.getData()[0];
  39. auto open = device->open();
  40. if (!open) {
  41. open.print();
  42. return 4;
  43. }
  44. FreeFareDevice freeFareDevice(device);
  45. auto tags = freeFareDevice.getTags();
  46. if (!tags) {
  47. tags.print();
  48. return 5;
  49. }
  50. std::cout << "Found " << tags.getData().size() << " tags:" << std::endl;
  51. for (size_t i = 0; i < tags.getData().size(); ++i) {
  52. auto tag = tags.getData()[i];
  53. std::cout << "UID: " << tag->getUid() << std::endl;
  54. }
  55. device->close();
  56. libNfc.clean();
  57. return 0;
  58. }