subghz_txrx.h 9.3 KB

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