subghz_txrx.h 8.2 KB

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