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

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