subghz_i.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #pragma once
  2. #include "subghz.h"
  3. #include "views/receiver.h"
  4. #include "views/transmitter.h"
  5. #include "views/subghz_frequency_analyzer.h"
  6. #include "views/subghz_read_raw.h"
  7. #include "views/subghz_test_static.h"
  8. #include "views/subghz_test_carrier.h"
  9. #include "views/subghz_test_packet.h"
  10. #include <furi.h>
  11. #include <furi_hal.h>
  12. #include <gui/gui.h>
  13. #include <dialogs/dialogs.h>
  14. #include <gui/scene_manager.h>
  15. #include <notification/notification_messages.h>
  16. #include <gui/view_dispatcher.h>
  17. #include <gui/modules/submenu.h>
  18. #include <gui/modules/popup.h>
  19. #include <gui/modules/text_input.h>
  20. #include <gui/modules/widget.h>
  21. #include <subghz/scenes/subghz_scene.h>
  22. #include <lib/subghz/subghz_worker.h>
  23. #include <lib/subghz/receiver.h>
  24. #include <lib/subghz/transmitter.h>
  25. #include "subghz_history.h"
  26. #include "subghz_setting.h"
  27. #include <gui/modules/variable_item_list.h>
  28. #include <lib/toolbox/path.h>
  29. #define SUBGHZ_MAX_LEN_NAME 64
  30. /** SubGhzNotification state */
  31. typedef enum {
  32. SubGhzNotificationStateStarting,
  33. SubGhzNotificationStateIDLE,
  34. SubGhzNotificationStateTx,
  35. SubGhzNotificationStateRx,
  36. SubGhzNotificationStateRxDone,
  37. } SubGhzNotificationState;
  38. /** SubGhzTxRx state */
  39. typedef enum {
  40. SubGhzTxRxStateIDLE,
  41. SubGhzTxRxStateRx,
  42. SubGhzTxRxStateTx,
  43. SubGhzTxRxStateSleep,
  44. } SubGhzTxRxState;
  45. /** SubGhzHopperState state */
  46. typedef enum {
  47. SubGhzHopperStateOFF,
  48. SubGhzHopperStateRunnig,
  49. SubGhzHopperStatePause,
  50. SubGhzHopperStateRSSITimeOut,
  51. } SubGhzHopperState;
  52. /** SubGhzRxKeyState state */
  53. typedef enum {
  54. SubGhzRxKeyStateIDLE,
  55. SubGhzRxKeyStateNoSave,
  56. SubGhzRxKeyStateNeedSave,
  57. SubGhzRxKeyStateBack,
  58. SubGhzRxKeyStateStart,
  59. SubGhzRxKeyStateAddKey,
  60. SubGhzRxKeyStateExit,
  61. SubGhzRxKeyStateRAWLoad,
  62. SubGhzRxKeyStateRAWSave,
  63. } SubGhzRxKeyState;
  64. /** SubGhzLoadKeyState state */
  65. typedef enum {
  66. SubGhzLoadKeyStateUnknown,
  67. SubGhzLoadKeyStateOK,
  68. SubGhzLoadKeyStateParseErr,
  69. SubGhzLoadKeyStateOnlyRx,
  70. } SubGhzLoadKeyState;
  71. struct SubGhzTxRx {
  72. SubGhzWorker* worker;
  73. SubGhzEnvironment* environment;
  74. SubGhzReceiver* receiver;
  75. SubGhzTransmitter* transmitter;
  76. SubGhzProtocolDecoderBase* decoder_result;
  77. FlipperFormat* fff_data;
  78. uint32_t frequency;
  79. FuriHalSubGhzPreset preset;
  80. SubGhzHistory* history;
  81. uint16_t idx_menu_chosen;
  82. SubGhzTxRxState txrx_state;
  83. SubGhzHopperState hopper_state;
  84. uint8_t hopper_timeout;
  85. uint8_t hopper_idx_frequency;
  86. SubGhzRxKeyState rx_key_state;
  87. };
  88. typedef struct SubGhzTxRx SubGhzTxRx;
  89. struct SubGhz {
  90. Gui* gui;
  91. NotificationApp* notifications;
  92. SubGhzTxRx* txrx;
  93. SceneManager* scene_manager;
  94. ViewDispatcher* view_dispatcher;
  95. Submenu* submenu;
  96. Popup* popup;
  97. TextInput* text_input;
  98. Widget* widget;
  99. DialogsApp* dialogs;
  100. string_t file_path;
  101. string_t file_path_tmp;
  102. char file_name_tmp[SUBGHZ_MAX_LEN_NAME];
  103. SubGhzNotificationState state_notifications;
  104. SubGhzViewReceiver* subghz_receiver;
  105. SubGhzViewTransmitter* subghz_transmitter;
  106. VariableItemList* variable_item_list;
  107. SubGhzFrequencyAnalyzer* subghz_frequency_analyzer;
  108. SubGhzReadRAW* subghz_read_raw;
  109. SubGhzTestStatic* subghz_test_static;
  110. SubGhzTestCarrier* subghz_test_carrier;
  111. SubGhzTestPacket* subghz_test_packet;
  112. string_t error_str;
  113. SubGhzSetting* setting;
  114. };
  115. typedef enum {
  116. SubGhzViewIdMenu,
  117. SubGhzViewIdReceiver,
  118. SubGhzViewIdPopup,
  119. SubGhzViewIdTextInput,
  120. SubGhzViewIdWidget,
  121. SubGhzViewIdTransmitter,
  122. SubGhzViewIdVariableItemList,
  123. SubGhzViewIdFrequencyAnalyzer,
  124. SubGhzViewIdReadRAW,
  125. SubGhzViewIdStatic,
  126. SubGhzViewIdTestCarrier,
  127. SubGhzViewIdTestPacket,
  128. } SubGhzViewId;
  129. bool subghz_set_preset(SubGhz* subghz, const char* preset);
  130. void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation);
  131. void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset);
  132. uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency);
  133. void subghz_rx_end(SubGhz* subghz);
  134. void subghz_sleep(SubGhz* subghz);
  135. bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format);
  136. void subghz_tx_stop(SubGhz* subghz);
  137. void subghz_dialog_message_show_only_rx(SubGhz* subghz);
  138. bool subghz_key_load(SubGhz* subghz, const char* file_path);
  139. bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len);
  140. bool subghz_save_protocol_to_file(
  141. SubGhz* subghz,
  142. FlipperFormat* flipper_format,
  143. const char* dev_file_name);
  144. bool subghz_load_protocol_from_file(SubGhz* subghz);
  145. bool subghz_rename_file(SubGhz* subghz);
  146. bool subghz_delete_file(SubGhz* subghz);
  147. void subghz_file_name_clear(SubGhz* subghz);
  148. bool subghz_path_is_file(string_t path);
  149. uint32_t subghz_random_serial(void);
  150. void subghz_hopper_update(SubGhz* subghz);