2022-03-03 12:48:56 +03:00
|
|
|
#include "transmitter.h"
|
|
|
|
|
|
|
|
#include "protocols/base.h"
|
2022-10-19 20:27:26 +03:00
|
|
|
#include "registry.h"
|
2022-03-03 12:48:56 +03:00
|
|
|
|
2022-05-08 20:50:20 +03:00
|
|
|
struct SubGhzTransmitter {
|
|
|
|
const SubGhzProtocol* protocol;
|
|
|
|
SubGhzProtocolEncoderBase* protocol_instance;
|
|
|
|
};
|
|
|
|
|
2022-03-03 12:48:56 +03:00
|
|
|
SubGhzTransmitter*
|
|
|
|
subghz_transmitter_alloc_init(SubGhzEnvironment* environment, const char* protocol_name) {
|
|
|
|
SubGhzTransmitter* instance = NULL;
|
2022-10-19 20:27:26 +03:00
|
|
|
const SubGhzProtocolRegistry* protocol_registry_items =
|
|
|
|
subghz_environment_get_protocol_registry(environment);
|
|
|
|
|
|
|
|
const SubGhzProtocol* protocol =
|
|
|
|
subghz_protocol_registry_get_by_name(protocol_registry_items, protocol_name);
|
2022-03-03 12:48:56 +03:00
|
|
|
|
|
|
|
if(protocol && protocol->encoder && protocol->encoder->alloc) {
|
|
|
|
instance = malloc(sizeof(SubGhzTransmitter));
|
|
|
|
instance->protocol = protocol;
|
|
|
|
instance->protocol_instance = instance->protocol->encoder->alloc(environment);
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_transmitter_free(SubGhzTransmitter* instance) {
|
2024-03-19 17:43:52 +03:00
|
|
|
furi_check(instance);
|
2022-03-03 12:48:56 +03:00
|
|
|
instance->protocol->encoder->free(instance->protocol_instance);
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
2022-05-08 20:50:20 +03:00
|
|
|
SubGhzProtocolEncoderBase* subghz_transmitter_get_protocol_instance(SubGhzTransmitter* instance) {
|
2024-03-19 17:43:52 +03:00
|
|
|
furi_check(instance);
|
2022-05-08 20:50:20 +03:00
|
|
|
return instance->protocol_instance;
|
|
|
|
}
|
|
|
|
|
2022-03-03 12:48:56 +03:00
|
|
|
bool subghz_transmitter_stop(SubGhzTransmitter* instance) {
|
2024-03-19 17:43:52 +03:00
|
|
|
furi_check(instance);
|
2022-03-03 12:48:56 +03:00
|
|
|
bool ret = false;
|
|
|
|
if(instance->protocol && instance->protocol->encoder && instance->protocol->encoder->stop) {
|
|
|
|
instance->protocol->encoder->stop(instance->protocol_instance);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-03 18:09:13 +03:00
|
|
|
SubGhzProtocolStatus
|
|
|
|
subghz_transmitter_deserialize(SubGhzTransmitter* instance, FlipperFormat* flipper_format) {
|
2024-03-19 17:43:52 +03:00
|
|
|
furi_check(instance);
|
2023-03-03 18:09:13 +03:00
|
|
|
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
|
2022-03-03 12:48:56 +03:00
|
|
|
if(instance->protocol && instance->protocol->encoder &&
|
|
|
|
instance->protocol->encoder->deserialize) {
|
|
|
|
ret =
|
|
|
|
instance->protocol->encoder->deserialize(instance->protocol_instance, flipper_format);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
LevelDuration subghz_transmitter_yield(void* context) {
|
|
|
|
SubGhzTransmitter* instance = context;
|
|
|
|
return instance->protocol->encoder->yield(instance->protocol_instance);
|
|
|
|
}
|