unleashed-firmware/applications/main/subghz/helpers/subghz_txrx.h

347 lines
8.6 KiB
C
Raw Normal View History

#pragma once
2023-05-09 19:16:52 +00:00
2023-05-09 16:10:56 +00:00
#include "subghz_types.h"
2023-05-09 19:16:52 +00:00
#include <lib/subghz/subghz_worker.h>
#include <lib/subghz/subghz_setting.h>
#include <lib/subghz/receiver.h>
#include <lib/subghz/transmitter.h>
2023-05-09 15:24:25 +00:00
#include <lib/subghz/protocols/raw.h>
2023-06-18 17:25:40 +00:00
#include <lib/subghz/devices/devices.h>
typedef struct SubGhzTxRx SubGhzTxRx;
2023-05-09 18:38:25 +00:00
typedef void (*SubGhzTxRxNeedSaveCallback)(void* context);
2023-05-09 16:50:01 +00:00
typedef enum {
SubGhzTxRxStartTxStateOk,
SubGhzTxRxStartTxStateErrorOnlyRx,
SubGhzTxRxStartTxStateErrorParserOthers,
} SubGhzTxRxStartTxState;
2023-05-09 18:38:25 +00:00
/**
* Allocate SubGhzTxRx
*
* @return SubGhzTxRx* pointer to SubGhzTxRx
*/
2023-05-09 14:30:01 +00:00
SubGhzTxRx* subghz_txrx_alloc();
2023-05-09 18:38:25 +00:00
/**
* Free SubGhzTxRx
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_free(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Check if the database is loaded
*
* @param instance Pointer to a SubGhzTxRx
* @return bool True if the database is loaded
*/
2023-05-09 18:54:56 +00:00
bool subghz_txrx_is_database_loaded(SubGhzTxRx* instance);
2023-05-09 14:30:01 +00:00
2023-05-09 18:38:25 +00:00
/**
* Set preset
*
* @param instance Pointer to a SubGhzTxRx
* @param preset_name Name of preset
* @param frequency Frequency in Hz
* @param preset_data Data of preset
* @param preset_data_size Size of preset data
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_set_preset(
SubGhzTxRx* instance,
const char* preset_name,
uint32_t frequency,
uint8_t* preset_data,
size_t preset_data_size);
2023-05-09 18:38:25 +00:00
/**
* Get name of preset
*
* @param instance Pointer to a SubGhzTxRx
* @param preset String of preset
* @return const char* Name of preset
*/
2023-05-09 18:54:56 +00:00
const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset);
2023-05-09 18:38:25 +00:00
/**
* Get of preset
*
* @param instance Pointer to a SubGhzTxRx
* @return SubGhzRadioPreset Preset
*/
2023-05-09 16:10:56 +00:00
SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance);
2023-05-09 12:11:54 +00:00
2023-05-09 18:38:25 +00:00
/**
* Get string frequency and modulation
*
* @param instance Pointer to a SubGhzTxRx
* @param frequency Pointer to a string frequency
* @param modulation Pointer to a string modulation
*/
2023-05-09 18:54:56 +00:00
void subghz_txrx_get_frequency_and_modulation(
2023-05-09 16:10:56 +00:00
SubGhzTxRx* instance,
2023-05-09 10:34:54 +00:00
FuriString* frequency,
FuriString* modulation,
bool long_name);
2023-05-09 18:38:25 +00:00
/**
* Start TX CC1101
*
* @param instance Pointer to a SubGhzTxRx
* @param flipper_format Pointer to a FlipperFormat
* @return SubGhzTxRxStartTxState
*/
2023-05-09 16:50:01 +00:00
SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format);
2023-05-09 18:38:25 +00:00
/**
* Start RX CC1101
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_rx_start(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Stop TX/RX CC1101
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_stop(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Set sleep mode CC1101
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_sleep(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Update frequency CC1101 in automatic mode (hopper)
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_hopper_update(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Get state hopper
*
* @param instance Pointer to a SubGhzTxRx
* @return SubGhzHopperState
*/
2023-05-09 16:10:56 +00:00
SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Set state hopper
*
* @param instance Pointer to a SubGhzTxRx
* @param state State hopper
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state);
2023-05-09 18:38:25 +00:00
/**
* Unpause hopper
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 18:54:56 +00:00
void subghz_txrx_hopper_unpause(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Set pause hopper
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:33:45 +00:00
void subghz_txrx_hopper_pause(SubGhzTxRx* instance);
2023-05-09 16:10:56 +00:00
2023-05-09 18:38:25 +00:00
/**
* Speaker on
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_speaker_on(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Speaker off
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_speaker_off(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Speaker mute
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_speaker_mute(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Speaker unmute
*
* @param instance Pointer to a SubGhzTxRx
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_speaker_unmute(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Set state speaker
*
* @param instance Pointer to a SubGhzTxRx
* @param state State speaker
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState state);
2023-05-09 18:38:25 +00:00
/**
* Get state speaker
*
* @param instance Pointer to a SubGhzTxRx
* @return SubGhzSpeakerState
*/
2023-05-09 16:10:56 +00:00
SubGhzSpeakerState subghz_txrx_speaker_get_state(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* load decoder by name protocol
*
* @param instance Pointer to a SubGhzTxRx
* @param name_protocol Name protocol
* @return bool True if the decoder is loaded
*/
2023-05-09 16:10:56 +00:00
bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol);
2023-05-09 18:38:25 +00:00
/**
* Get decoder
*
* @param instance Pointer to a SubGhzTxRx
* @return SubGhzProtocolDecoderBase* Pointer to a SubGhzProtocolDecoderBase
*/
2023-05-09 16:10:56 +00:00
SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Set callback for save data
*
* @param instance Pointer to a SubGhzTxRx
* @param callback Callback for save data
* @param context Context for callback
*/
2023-05-09 18:54:56 +00:00
void subghz_txrx_set_need_save_callback(
2023-05-09 16:10:56 +00:00
SubGhzTxRx* instance,
SubGhzTxRxNeedSaveCallback callback,
void* context);
2023-05-09 18:38:25 +00:00
/**
* Get pointer to a load data key
*
* @param instance Pointer to a SubGhzTxRx
* @return FlipperFormat*
*/
2023-05-09 18:54:56 +00:00
FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Get pointer to a SugGhzSetting
*
* @param instance Pointer to a SubGhzTxRx
* @return SubGhzSetting*
*/
2023-05-09 16:10:56 +00:00
SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Is it possible to save this protocol
*
* @param instance Pointer to a SubGhzTxRx
* @return bool True if it is possible to save this protocol
*/
2023-05-09 18:54:56 +00:00
bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance);
2023-05-09 18:38:25 +00:00
/**
* Is it possible to send this protocol
*
* @param instance Pointer to a SubGhzTxRx
* @return bool True if it is possible to send this protocol
*/
2023-05-09 18:54:56 +00:00
bool subghz_txrx_protocol_is_transmittable(SubGhzTxRx* instance, bool check_type);
2023-05-09 12:22:08 +00:00
2023-05-09 18:38:25 +00:00
/**
* Set filter, what types of decoder to use
*
* @param instance Pointer to a SubGhzTxRx
* @param filter Filter
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter);
2023-05-09 12:58:56 +00:00
2023-05-09 18:38:25 +00:00
/**
* Set callback for receive data
*
* @param instance Pointer to a SubGhzTxRx
* @param callback Callback for receive data
* @param context Context for callback
*/
2023-05-09 16:10:56 +00:00
void subghz_txrx_set_rx_calback(
SubGhzTxRx* instance,
SubGhzReceiverCallback callback,
void* context);
2023-05-09 18:38:25 +00:00
/**
* Set callback for Raw decoder, end of data transfer
*
* @param instance Pointer to a SubGhzTxRx
* @param callback Callback for Raw decoder, end of data transfer
* @param context Context for callback
*/
2023-05-09 18:54:56 +00:00
void subghz_txrx_set_raw_file_encoder_worker_callback_end(
2023-05-09 16:10:56 +00:00
SubGhzTxRx* instance,
2023-05-09 15:24:25 +00:00
SubGhzProtocolEncoderRAWCallbackEnd callback,
void* context);
2023-06-18 17:25:40 +00:00
/* Checking if an external radio device is connected
*
* @param instance Pointer to a SubGhzTxRx
* @param name Name of external radio device
* @return bool True if is connected to the external radio device
*/
bool subghz_txrx_radio_device_is_external_connected(SubGhzTxRx* instance, const char* name);
2023-06-18 17:25:40 +00:00
/* Set the selected radio device to use
*
* @param instance Pointer to a SubGhzTxRx
* @param radio_device_type Radio device type
* @return SubGhzRadioDeviceType Type of installed radio device
*/
SubGhzRadioDeviceType
subghz_txrx_radio_device_set(SubGhzTxRx* instance, SubGhzRadioDeviceType radio_device_type);
/* Get the selected radio device to use
*
* @param instance Pointer to a SubGhzTxRx
* @return SubGhzRadioDeviceType Type of installed radio device
*/
SubGhzRadioDeviceType subghz_txrx_radio_device_get(SubGhzTxRx* instance);
/* Get RSSI the selected radio device to use
*
* @param instance Pointer to a SubGhzTxRx
* @return float RSSI
*/
float subghz_txrx_radio_device_get_rssi(SubGhzTxRx* instance);
/* Get name the selected radio device to use
*
* @param instance Pointer to a SubGhzTxRx
* @return const char* Name of installed radio device
*/
const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
/* Get get intelligence whether frequency the selected radio device to use
*
* @param instance Pointer to a SubGhzTxRx
* @return bool True if the frequency is valid
*/
bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency);
bool subghz_txrx_radio_device_is_tx_alowed(SubGhzTxRx* instance, uint32_t frequency);
2023-05-09 16:10:56 +00:00
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state);
bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance);
2023-05-30 19:21:47 +00:00
void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance);
2023-05-19 22:15:36 +00:00
2023-05-09 16:10:56 +00:00
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw