subghz_txrx.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #pragma once
  2. #include "subghz_types.h"
  3. #include <lib/subghz/subghz_worker.h>
  4. #include <lib/subghz/subghz_setting.h>
  5. #include <lib/subghz/receiver.h>
  6. #include <lib/subghz/transmitter.h>
  7. #include <lib/subghz/protocols/raw.h>
  8. typedef struct SubGhzTxRx SubGhzTxRx;
  9. typedef void (*SubGhzTxRxNeedSaveCallback)(void* context);
  10. typedef enum {
  11. SubGhzTxRxStartTxStateOk,
  12. SubGhzTxRxStartTxStateErrorOnlyRx,
  13. SubGhzTxRxStartTxStateErrorParserOthers,
  14. } SubGhzTxRxStartTxState;
  15. /**
  16. * Allocate SubGhzTxRx
  17. *
  18. * @return SubGhzTxRx* pointer to SubGhzTxRx
  19. */
  20. SubGhzTxRx* subghz_txrx_alloc();
  21. /**
  22. * Free SubGhzTxRx
  23. *
  24. * @param instance Pointer to a SubGhzTxRx
  25. */
  26. void subghz_txrx_free(SubGhzTxRx* instance);
  27. /**
  28. * Check if the database is loaded
  29. *
  30. * @param instance Pointer to a SubGhzTxRx
  31. * @return bool True if the database is loaded
  32. */
  33. bool subghz_txrx_is_database_loaded(SubGhzTxRx* instance);
  34. /**
  35. * Set preset
  36. *
  37. * @param instance Pointer to a SubGhzTxRx
  38. * @param preset_name Name of preset
  39. * @param frequency Frequency in Hz
  40. * @param preset_data Data of preset
  41. * @param preset_data_size Size of preset data
  42. */
  43. void subghz_txrx_set_preset(
  44. SubGhzTxRx* instance,
  45. const char* preset_name,
  46. uint32_t frequency,
  47. uint8_t* preset_data,
  48. size_t preset_data_size);
  49. /**
  50. * Get name of preset
  51. *
  52. * @param instance Pointer to a SubGhzTxRx
  53. * @param preset String of preset
  54. * @return const char* Name of preset
  55. */
  56. const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset);
  57. /**
  58. * Get of preset
  59. *
  60. * @param instance Pointer to a SubGhzTxRx
  61. * @return SubGhzRadioPreset Preset
  62. */
  63. SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance);
  64. /**
  65. * Get string frequency and modulation
  66. *
  67. * @param instance Pointer to a SubGhzTxRx
  68. * @param frequency Pointer to a string frequency
  69. * @param modulation Pointer to a string modulation
  70. */
  71. void subghz_txrx_get_frequency_and_modulation(
  72. SubGhzTxRx* instance,
  73. FuriString* frequency,
  74. FuriString* modulation);
  75. /**
  76. * Start TX CC1101
  77. *
  78. * @param instance Pointer to a SubGhzTxRx
  79. * @param flipper_format Pointer to a FlipperFormat
  80. * @return SubGhzTxRxStartTxState
  81. */
  82. SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format);
  83. /**
  84. * Start RX CC1101
  85. *
  86. * @param instance Pointer to a SubGhzTxRx
  87. */
  88. void subghz_txrx_rx_start(SubGhzTxRx* instance);
  89. /**
  90. * Stop TX/RX CC1101
  91. *
  92. * @param instance Pointer to a SubGhzTxRx
  93. */
  94. void subghz_txrx_stop(SubGhzTxRx* instance);
  95. /**
  96. * Set sleep mode CC1101
  97. *
  98. * @param instance Pointer to a SubGhzTxRx
  99. */
  100. void subghz_txrx_sleep(SubGhzTxRx* instance);
  101. /**
  102. * Update frequency CC1101 in automatic mode (hopper)
  103. *
  104. * @param instance Pointer to a SubGhzTxRx
  105. */
  106. void subghz_txrx_hopper_update(SubGhzTxRx* instance);
  107. /**
  108. * Get state hopper
  109. *
  110. * @param instance Pointer to a SubGhzTxRx
  111. * @return SubGhzHopperState
  112. */
  113. SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance);
  114. /**
  115. * Set state hopper
  116. *
  117. * @param instance Pointer to a SubGhzTxRx
  118. * @param state State hopper
  119. */
  120. void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state);
  121. /**
  122. * Unpause hopper
  123. *
  124. * @param instance Pointer to a SubGhzTxRx
  125. */
  126. void subghz_txrx_hopper_unpause(SubGhzTxRx* instance);
  127. /**
  128. * Set pause hopper
  129. *
  130. * @param instance Pointer to a SubGhzTxRx
  131. */
  132. void subghz_txrx_hopper_pause(SubGhzTxRx* instance);
  133. /**
  134. * Speaker on
  135. *
  136. * @param instance Pointer to a SubGhzTxRx
  137. */
  138. void subghz_txrx_speaker_on(SubGhzTxRx* instance);
  139. /**
  140. * Speaker off
  141. *
  142. * @param instance Pointer to a SubGhzTxRx
  143. */
  144. void subghz_txrx_speaker_off(SubGhzTxRx* instance);
  145. /**
  146. * Speaker mute
  147. *
  148. * @param instance Pointer to a SubGhzTxRx
  149. */
  150. void subghz_txrx_speaker_mute(SubGhzTxRx* instance);
  151. /**
  152. * Speaker unmute
  153. *
  154. * @param instance Pointer to a SubGhzTxRx
  155. */
  156. void subghz_txrx_speaker_unmute(SubGhzTxRx* instance);
  157. /**
  158. * Set state speaker
  159. *
  160. * @param instance Pointer to a SubGhzTxRx
  161. * @param state State speaker
  162. */
  163. void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState state);
  164. /**
  165. * Get state speaker
  166. *
  167. * @param instance Pointer to a SubGhzTxRx
  168. * @return SubGhzSpeakerState
  169. */
  170. SubGhzSpeakerState subghz_txrx_speaker_get_state(SubGhzTxRx* instance);
  171. /**
  172. * load decoder by name protocol
  173. *
  174. * @param instance Pointer to a SubGhzTxRx
  175. * @param name_protocol Name protocol
  176. * @return bool True if the decoder is loaded
  177. */
  178. bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol);
  179. /**
  180. * Get decoder
  181. *
  182. * @param instance Pointer to a SubGhzTxRx
  183. * @return SubGhzProtocolDecoderBase* Pointer to a SubGhzProtocolDecoderBase
  184. */
  185. SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance);
  186. /**
  187. * Set callback for save data
  188. *
  189. * @param instance Pointer to a SubGhzTxRx
  190. * @param callback Callback for save data
  191. * @param context Context for callback
  192. */
  193. void subghz_txrx_set_need_save_callback(
  194. SubGhzTxRx* instance,
  195. SubGhzTxRxNeedSaveCallback callback,
  196. void* context);
  197. /**
  198. * Get pointer to a load data key
  199. *
  200. * @param instance Pointer to a SubGhzTxRx
  201. * @return FlipperFormat*
  202. */
  203. FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance);
  204. /**
  205. * Get pointer to a SugGhzSetting
  206. *
  207. * @param instance Pointer to a SubGhzTxRx
  208. * @return SubGhzSetting*
  209. */
  210. SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance);
  211. /**
  212. * Is it possible to save this protocol
  213. *
  214. * @param instance Pointer to a SubGhzTxRx
  215. * @return bool True if it is possible to save this protocol
  216. */
  217. bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance);
  218. /**
  219. * Is it possible to send this protocol
  220. *
  221. * @param instance Pointer to a SubGhzTxRx
  222. * @return bool True if it is possible to send this protocol
  223. */
  224. bool subghz_txrx_protocol_is_transmittable(SubGhzTxRx* instance, bool check_type);
  225. /**
  226. * Set filter, what types of decoder to use
  227. *
  228. * @param instance Pointer to a SubGhzTxRx
  229. * @param filter Filter
  230. */
  231. void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter);
  232. /**
  233. * Set callback for receive data
  234. *
  235. * @param instance Pointer to a SubGhzTxRx
  236. * @param callback Callback for receive data
  237. * @param context Context for callback
  238. */
  239. void subghz_txrx_set_rx_calback(
  240. SubGhzTxRx* instance,
  241. SubGhzReceiverCallback callback,
  242. void* context);
  243. /**
  244. * Set callback for Raw decoder, end of data transfer
  245. *
  246. * @param instance Pointer to a SubGhzTxRx
  247. * @param callback Callback for Raw decoder, end of data transfer
  248. * @param context Context for callback
  249. */
  250. void subghz_txrx_set_raw_file_encoder_worker_callback_end(
  251. SubGhzTxRx* instance,
  252. SubGhzProtocolEncoderRAWCallbackEnd callback,
  253. void* context);