infrared_app_brute_force.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @file infrared_app_brute_force.h
  3. * Infrared: Brute Force class description
  4. */
  5. #pragma once
  6. #include <unordered_map>
  7. #include <memory>
  8. #include <flipper_format/flipper_format.h>
  9. /** Class handles brute force mechanic */
  10. class InfraredAppBruteForce {
  11. /** Universal database filename */
  12. const char* universal_db_filename;
  13. /** Current record name (POWER, MUTE, VOL+, etc).
  14. * This is the name of signal to brute force. */
  15. std::string current_record;
  16. /** Flipper File Format instance */
  17. FlipperFormat* ff;
  18. /** Data about every record - index in button panel view
  19. * and amount of signals, which is need for correct
  20. * progress bar displaying. */
  21. typedef struct {
  22. /** Index of record in button panel view model */
  23. int index;
  24. /** Amount of signals of that type (POWER, MUTE, etc) */
  25. int amount;
  26. } Record;
  27. /** Container to hold Record info.
  28. * 'key' is record name, because we have to search by both, index and name,
  29. * but index search has place once per button press, and should not be
  30. * noticed, but name search should occur during entering universal menu,
  31. * and will go through container for every record in file, that's why
  32. * more critical to have faster search by record name.
  33. */
  34. std::unordered_map<std::string, Record> records;
  35. public:
  36. /** Calculate messages. Walk through the file ('universal_db_name')
  37. * and calculate amount of records of certain type. */
  38. bool calculate_messages();
  39. /** Start brute force */
  40. bool start_bruteforce(int index, int& record_amount);
  41. /** Stop brute force */
  42. void stop_bruteforce();
  43. /** Send next signal during brute force */
  44. bool send_next_bruteforce();
  45. /** Add record to container of records */
  46. void add_record(int index, const char* name);
  47. /** Initialize class, set db file */
  48. InfraredAppBruteForce(const char* filename)
  49. : universal_db_filename(filename) {
  50. }
  51. /** Deinitialize class */
  52. ~InfraredAppBruteForce() {
  53. }
  54. };