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.8KB

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