mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Merge branch 'fz-dev' into dev
This commit is contained in:
@@ -6,6 +6,7 @@ struct SubGhzEnvironment {
|
||||
const SubGhzProtocolRegistry* protocol_registry;
|
||||
const char* came_atomo_rainbow_table_file_name;
|
||||
const char* nice_flor_s_rainbow_table_file_name;
|
||||
const char* alutech_at_4n_rainbow_table_file_name;
|
||||
};
|
||||
|
||||
SubGhzEnvironment* subghz_environment_alloc() {
|
||||
@@ -57,6 +58,21 @@ const char*
|
||||
return instance->came_atomo_rainbow_table_file_name;
|
||||
}
|
||||
|
||||
void subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
SubGhzEnvironment* instance,
|
||||
const char* filename) {
|
||||
furi_assert(instance);
|
||||
|
||||
instance->alutech_at_4n_rainbow_table_file_name = filename;
|
||||
}
|
||||
|
||||
const char*
|
||||
subghz_environment_get_alutech_at_4n_rainbow_table_file_name(SubGhzEnvironment* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
return instance->alutech_at_4n_rainbow_table_file_name;
|
||||
}
|
||||
|
||||
void subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
SubGhzEnvironment* instance,
|
||||
const char* filename) {
|
||||
|
||||
@@ -52,6 +52,23 @@ void subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
*/
|
||||
const char* subghz_environment_get_came_atomo_rainbow_table_file_name(SubGhzEnvironment* instance);
|
||||
|
||||
/**
|
||||
* Set filename to work with Alutech at-4n.
|
||||
* @param instance Pointer to a SubGhzEnvironment instance
|
||||
* @param filename Full path to the file
|
||||
*/
|
||||
void subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
SubGhzEnvironment* instance,
|
||||
const char* filename);
|
||||
|
||||
/**
|
||||
* Get filename to work with Alutech at-4n.
|
||||
* @param instance Pointer to a SubGhzEnvironment instance
|
||||
* @return Full path to the file
|
||||
*/
|
||||
const char*
|
||||
subghz_environment_get_alutech_at_4n_rainbow_table_file_name(SubGhzEnvironment* instance);
|
||||
|
||||
/**
|
||||
* Set filename to work with Nice Flor-S.
|
||||
* @param instance Pointer to a SubGhzEnvironment instance
|
||||
|
||||
455
lib/subghz/protocols/alutech_at_4n.c
Normal file
455
lib/subghz/protocols/alutech_at_4n.c
Normal file
@@ -0,0 +1,455 @@
|
||||
#include "alutech_at_4n.h"
|
||||
#include "../blocks/const.h"
|
||||
#include "../blocks/decoder.h"
|
||||
#include "../blocks/encoder.h"
|
||||
#include "../blocks/generic.h"
|
||||
#include "../blocks/math.h"
|
||||
|
||||
#define TAG "SubGhzProtocoAlutech_at_4n"
|
||||
|
||||
#define SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE 0xFFFFFFFF
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_alutech_at_4n_const = {
|
||||
.te_short = 400,
|
||||
.te_long = 800,
|
||||
.te_delta = 140,
|
||||
.min_count_bit_for_found = 72,
|
||||
};
|
||||
|
||||
struct SubGhzProtocolDecoderAlutech_at_4n {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
|
||||
uint64_t data;
|
||||
uint32_t crc;
|
||||
uint16_t header_count;
|
||||
|
||||
const char* alutech_at_4n_rainbow_table_file_name;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderAlutech_at_4n {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Alutech_at_4nDecoderStepReset = 0,
|
||||
Alutech_at_4nDecoderStepCheckPreambula,
|
||||
Alutech_at_4nDecoderStepSaveDuration,
|
||||
Alutech_at_4nDecoderStepCheckDuration,
|
||||
} Alutech_at_4nDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder subghz_protocol_alutech_at_4n_decoder = {
|
||||
.alloc = subghz_protocol_decoder_alutech_at_4n_alloc,
|
||||
.free = subghz_protocol_decoder_alutech_at_4n_free,
|
||||
|
||||
.feed = subghz_protocol_decoder_alutech_at_4n_feed,
|
||||
.reset = subghz_protocol_decoder_alutech_at_4n_reset,
|
||||
|
||||
.get_hash_data = subghz_protocol_decoder_alutech_at_4n_get_hash_data,
|
||||
.serialize = subghz_protocol_decoder_alutech_at_4n_serialize,
|
||||
.deserialize = subghz_protocol_decoder_alutech_at_4n_deserialize,
|
||||
.get_string = subghz_protocol_decoder_alutech_at_4n_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_alutech_at_4n_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_alutech_at_4n = {
|
||||
.name = SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME,
|
||||
.type = SubGhzProtocolTypeDynamic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &subghz_protocol_alutech_at_4n_decoder,
|
||||
.encoder = &subghz_protocol_alutech_at_4n_encoder,
|
||||
};
|
||||
|
||||
/**
|
||||
* Read bytes from rainbow table
|
||||
* @param file_name Full path to rainbow table the file
|
||||
* @param number_alutech_at_4n_magic_data number in the array
|
||||
* @return alutech_at_4n_magic_data
|
||||
*/
|
||||
static uint32_t subghz_protocol_alutech_at_4n_get_magic_data_in_file(
|
||||
const char* file_name,
|
||||
uint8_t number_alutech_at_4n_magic_data) {
|
||||
if(!strcmp(file_name, "")) return SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
|
||||
|
||||
uint8_t buffer[sizeof(uint32_t)] = {0};
|
||||
uint32_t address = number_alutech_at_4n_magic_data * sizeof(uint32_t);
|
||||
uint32_t alutech_at_4n_magic_data = 0;
|
||||
|
||||
if(subghz_keystore_raw_get_data(file_name, address, buffer, sizeof(uint32_t))) {
|
||||
for(size_t i = 0; i < sizeof(uint32_t); i++) {
|
||||
alutech_at_4n_magic_data = (alutech_at_4n_magic_data << 8) | buffer[i];
|
||||
}
|
||||
} else {
|
||||
alutech_at_4n_magic_data = SUBGHZ_NO_ALUTECH_AT_4N_RAINBOW_TABLE;
|
||||
}
|
||||
return alutech_at_4n_magic_data;
|
||||
}
|
||||
|
||||
static uint8_t subghz_protocol_alutech_at_4n_crc(uint64_t data) {
|
||||
uint8_t* p = (uint8_t*)&data;
|
||||
uint8_t crc = 0xff;
|
||||
for(uint8_t y = 0; y < 8; y++) {
|
||||
crc = crc ^ p[y];
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
if((crc & 0x80) != 0) {
|
||||
crc <<= 1;
|
||||
crc ^= 0x31;
|
||||
} else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
static uint8_t subghz_protocol_alutech_at_4n_decrypt_data_crc(uint8_t data) {
|
||||
uint8_t crc = data;
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
if((crc & 0x80) != 0) {
|
||||
crc <<= 1;
|
||||
crc ^= 0x31;
|
||||
} else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
static uint64_t subghz_protocol_alutech_at_4n_decrypt(uint64_t data, const char* file_name) {
|
||||
uint8_t* p = (uint8_t*)&data;
|
||||
uint32_t data1 = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
|
||||
uint32_t data2 = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
|
||||
uint32_t data3 = 0;
|
||||
uint32_t magic_data[] = {
|
||||
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 0),
|
||||
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 1),
|
||||
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 2),
|
||||
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 3),
|
||||
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 4),
|
||||
subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 5)};
|
||||
|
||||
uint32_t i = magic_data[0];
|
||||
do {
|
||||
data2 = data2 -
|
||||
((magic_data[1] + (data1 << 4)) ^ ((magic_data[2] + (data1 >> 5)) ^ (data1 + i)));
|
||||
data3 = data2 + i;
|
||||
i += magic_data[3];
|
||||
data1 =
|
||||
data1 - ((magic_data[4] + (data2 << 4)) ^ ((magic_data[5] + (data2 >> 5)) ^ data3));
|
||||
} while(i != 0);
|
||||
|
||||
p[0] = (uint8_t)(data1 >> 24);
|
||||
p[1] = (uint8_t)(data1 >> 16);
|
||||
p[3] = (uint8_t)data1;
|
||||
p[4] = (uint8_t)(data2 >> 24);
|
||||
p[5] = (uint8_t)(data2 >> 16);
|
||||
p[2] = (uint8_t)(data1 >> 8);
|
||||
p[6] = (uint8_t)(data2 >> 8);
|
||||
p[7] = (uint8_t)data2;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// static uint64_t subghz_protocol_alutech_at_4n_encrypt(uint64_t data, const char* file_name) {
|
||||
// uint8_t* p = (uint8_t*)&data;
|
||||
// uint32_t data1 = 0;
|
||||
// uint32_t data2 = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
|
||||
// uint32_t data3 = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
|
||||
// uint32_t magic_data[] = {
|
||||
// subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 6),
|
||||
// subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 4),
|
||||
// subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 5),
|
||||
// subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 1),
|
||||
// subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 2),
|
||||
// subghz_protocol_alutech_at_4n_get_magic_data_in_file(file_name, 0)};
|
||||
|
||||
// do {
|
||||
// data1 = data1 + magic_data[0];
|
||||
// data2 = data2 + ((magic_data[1] + (data3 << 4)) ^
|
||||
// ((magic_data[2] + (data3 >> 5)) ^ (data1 + data3)));
|
||||
// data3 = data3 + ((magic_data[3] + (data2 << 4)) ^
|
||||
// ((magic_data[4] + (data2 >> 5)) ^ (data1 + data2)));
|
||||
// } while(data1 != magic_data[5]);
|
||||
// p[0] = (uint8_t)(data2 >> 24);
|
||||
// p[1] = (uint8_t)(data2 >> 16);
|
||||
// p[3] = (uint8_t)data2;
|
||||
// p[4] = (uint8_t)(data3 >> 24);
|
||||
// p[5] = (uint8_t)(data3 >> 16);
|
||||
// p[2] = (uint8_t)(data2 >> 8);
|
||||
// p[6] = (uint8_t)(data3 >> 8);
|
||||
// p[7] = (uint8_t)data3;
|
||||
|
||||
// return data;
|
||||
// }
|
||||
|
||||
void* subghz_protocol_decoder_alutech_at_4n_alloc(SubGhzEnvironment* environment) {
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance =
|
||||
malloc(sizeof(SubGhzProtocolDecoderAlutech_at_4n));
|
||||
instance->base.protocol = &subghz_protocol_alutech_at_4n;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
instance->alutech_at_4n_rainbow_table_file_name =
|
||||
subghz_environment_get_alutech_at_4n_rainbow_table_file_name(environment);
|
||||
if(instance->alutech_at_4n_rainbow_table_file_name) {
|
||||
FURI_LOG_I(
|
||||
TAG, "Loading rainbow table from %s", instance->alutech_at_4n_rainbow_table_file_name);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_alutech_at_4n_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
|
||||
instance->alutech_at_4n_rainbow_table_file_name = NULL;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_alutech_at_4n_reset(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepReset;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_alutech_at_4n_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case Alutech_at_4nDecoderStepReset:
|
||||
if((level) && DURATION_DIFF(duration, subghz_protocol_alutech_at_4n_const.te_short) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta) {
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepCheckPreambula;
|
||||
instance->header_count++;
|
||||
}
|
||||
break;
|
||||
case Alutech_at_4nDecoderStepCheckPreambula:
|
||||
if((!level) && (DURATION_DIFF(duration, subghz_protocol_alutech_at_4n_const.te_short) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta)) {
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepReset;
|
||||
break;
|
||||
}
|
||||
if((instance->header_count > 2) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_alutech_at_4n_const.te_short * 10) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta * 10)) {
|
||||
// Found header
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
} else {
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepReset;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
case Alutech_at_4nDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepCheckDuration;
|
||||
}
|
||||
break;
|
||||
case Alutech_at_4nDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(duration >= ((uint32_t)subghz_protocol_alutech_at_4n_const.te_short * 2 +
|
||||
subghz_protocol_alutech_at_4n_const.te_delta)) {
|
||||
//add last bit
|
||||
if(DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_alutech_at_4n_const.te_short) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
} else if(
|
||||
DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_alutech_at_4n_const.te_long) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta * 2) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
}
|
||||
|
||||
// Found end TX
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepReset;
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_alutech_at_4n_const.min_count_bit_for_found) {
|
||||
if(instance->generic.data != instance->data) {
|
||||
instance->generic.data = instance->data;
|
||||
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
instance->crc = instance->decoder.decode_data;
|
||||
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_alutech_at_4n_const.te_short) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_alutech_at_4n_const.te_long) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
if(instance->decoder.decode_count_bit == 64) {
|
||||
instance->data = instance->decoder.decode_data;
|
||||
instance->decoder.decode_data = 0;
|
||||
}
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_alutech_at_4n_const.te_long) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_alutech_at_4n_const.te_short) <
|
||||
subghz_protocol_alutech_at_4n_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
if(instance->decoder.decode_count_bit == 64) {
|
||||
instance->data = instance->decoder.decode_data;
|
||||
instance->decoder.decode_data = 0;
|
||||
}
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepReset;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = Alutech_at_4nDecoderStepReset;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a SubGhzBlockGeneric* instance
|
||||
* @param file_name Full path to rainbow table the file
|
||||
*/
|
||||
static void subghz_protocol_alutech_at_4n_remote_controller(
|
||||
SubGhzBlockGeneric* instance,
|
||||
uint8_t crc,
|
||||
const char* file_name) {
|
||||
/**
|
||||
* Message format 72bit LSB first
|
||||
* data crc
|
||||
* XXXXXXXXXXXXXXXX CC
|
||||
*
|
||||
* For analysis, you need to turn the package MSB
|
||||
* in decoded messages format
|
||||
*
|
||||
* crc1 serial cnt key
|
||||
* cc SSSSSSSS XXxx BB
|
||||
*
|
||||
* crc1 is calculated from the lower part of cnt
|
||||
* key 1=0xff, 2=0x11, 3=0x22, 4=0x33, 5=0x44
|
||||
*
|
||||
*/
|
||||
|
||||
bool status = false;
|
||||
uint64_t data = subghz_protocol_blocks_reverse_key(instance->data, 64);
|
||||
crc = subghz_protocol_blocks_reverse_key(crc, 8);
|
||||
|
||||
if(crc == subghz_protocol_alutech_at_4n_crc(data)) {
|
||||
data = subghz_protocol_alutech_at_4n_decrypt(data, file_name);
|
||||
status = true;
|
||||
}
|
||||
|
||||
if(status && ((uint8_t)(data >> 56) ==
|
||||
subghz_protocol_alutech_at_4n_decrypt_data_crc((uint8_t)((data >> 8) & 0xFF)))) {
|
||||
instance->btn = (uint8_t)data & 0xFF;
|
||||
instance->cnt = (uint16_t)(data >> 8) & 0xFFFF;
|
||||
instance->serial = (uint32_t)(data >> 24) & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
if(!status) {
|
||||
instance->btn = 0;
|
||||
instance->cnt = 0;
|
||||
instance->serial = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_decoder_alutech_at_4n_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
|
||||
return (uint8_t)instance->crc;
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_alutech_at_4n_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
|
||||
bool res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
if(res && !flipper_format_write_uint32(flipper_format, "CRC", &instance->crc, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add CRC");
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
|
||||
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_alutech_at_4n_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
|
||||
bool ret = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_alutech_at_4n_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_uint32(flipper_format, "CRC", (uint32_t*)&instance->crc, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing CRC");
|
||||
break;
|
||||
}
|
||||
ret = true;
|
||||
} while(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_alutech_at_4n_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
|
||||
subghz_protocol_alutech_at_4n_remote_controller(
|
||||
&instance->generic, instance->crc, instance->alutech_at_4n_rainbow_table_file_name);
|
||||
uint32_t code_found_hi = instance->generic.data >> 32;
|
||||
uint32_t code_found_lo = instance->generic.data & 0x00000000ffffffff;
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %d\r\n"
|
||||
"Key:0x%08lX%08lX%02X\r\n"
|
||||
"Sn:0x%08lX Btn:0x%01X\r\n"
|
||||
"Cnt:0x%03lX\r\n",
|
||||
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
(uint8_t)instance->crc,
|
||||
instance->generic.serial,
|
||||
instance->generic.btn,
|
||||
instance->generic.cnt);
|
||||
}
|
||||
74
lib/subghz/protocols/alutech_at_4n.h
Normal file
74
lib/subghz/protocols/alutech_at_4n.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#include "base.h"
|
||||
|
||||
#define SUBGHZ_PROTOCOL_ALUTECH_AT_4N_NAME "Alutech at-4n"
|
||||
|
||||
typedef struct SubGhzProtocolDecoderAlutech_at_4n SubGhzProtocolDecoderAlutech_at_4n;
|
||||
typedef struct SubGhzProtocolEncoderAlutech_at_4n SubGhzProtocolEncoderAlutech_at_4n;
|
||||
|
||||
extern const SubGhzProtocolDecoder subghz_protocol_alutech_at_4n_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_alutech_at_4n_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_alutech_at_4n;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderAlutech_at_4n.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolDecoderAlutech_at_4n* pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
*/
|
||||
void* subghz_protocol_decoder_alutech_at_4n_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolDecoderAlutech_at_4n.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
*/
|
||||
void subghz_protocol_decoder_alutech_at_4n_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder SubGhzProtocolDecoderAlutech_at_4n.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
*/
|
||||
void subghz_protocol_decoder_alutech_at_4n_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void subghz_protocol_decoder_alutech_at_4n_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t subghz_protocol_decoder_alutech_at_4n_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data SubGhzProtocolDecoderAlutech_at_4n.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_alutech_at_4n_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data SubGhzProtocolDecoderAlutech_at_4n.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_alutech_at_4n_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderAlutech_at_4n instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void subghz_protocol_decoder_alutech_at_4n_get_string(void* context, FuriString* output);
|
||||
447
lib/subghz/protocols/dooya.c
Normal file
447
lib/subghz/protocols/dooya.c
Normal file
@@ -0,0 +1,447 @@
|
||||
#include "dooya.h"
|
||||
#include "../blocks/const.h"
|
||||
#include "../blocks/decoder.h"
|
||||
#include "../blocks/encoder.h"
|
||||
#include "../blocks/generic.h"
|
||||
#include "../blocks/math.h"
|
||||
|
||||
#define TAG "SubGhzProtocolDooya"
|
||||
|
||||
#define DOYA_SINGLE_CHANNEL 0xFF
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_dooya_const = {
|
||||
.te_short = 366,
|
||||
.te_long = 733,
|
||||
.te_delta = 120,
|
||||
.min_count_bit_for_found = 40,
|
||||
};
|
||||
|
||||
struct SubGhzProtocolDecoderDooya {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderDooya {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
DooyaDecoderStepReset = 0,
|
||||
DooyaDecoderStepFoundStartBit,
|
||||
DooyaDecoderStepSaveDuration,
|
||||
DooyaDecoderStepCheckDuration,
|
||||
} DooyaDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder subghz_protocol_dooya_decoder = {
|
||||
.alloc = subghz_protocol_decoder_dooya_alloc,
|
||||
.free = subghz_protocol_decoder_dooya_free,
|
||||
|
||||
.feed = subghz_protocol_decoder_dooya_feed,
|
||||
.reset = subghz_protocol_decoder_dooya_reset,
|
||||
|
||||
.get_hash_data = subghz_protocol_decoder_dooya_get_hash_data,
|
||||
.serialize = subghz_protocol_decoder_dooya_serialize,
|
||||
.deserialize = subghz_protocol_decoder_dooya_deserialize,
|
||||
.get_string = subghz_protocol_decoder_dooya_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_dooya_encoder = {
|
||||
.alloc = subghz_protocol_encoder_dooya_alloc,
|
||||
.free = subghz_protocol_encoder_dooya_free,
|
||||
|
||||
.deserialize = subghz_protocol_encoder_dooya_deserialize,
|
||||
.stop = subghz_protocol_encoder_dooya_stop,
|
||||
.yield = subghz_protocol_encoder_dooya_yield,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_dooya = {
|
||||
.name = SUBGHZ_PROTOCOL_DOOYA_NAME,
|
||||
.type = SubGhzProtocolTypeStatic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_AM |
|
||||
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save |
|
||||
SubGhzProtocolFlag_Send,
|
||||
|
||||
.decoder = &subghz_protocol_dooya_decoder,
|
||||
.encoder = &subghz_protocol_dooya_encoder,
|
||||
};
|
||||
|
||||
void* subghz_protocol_encoder_dooya_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolEncoderDooya* instance = malloc(sizeof(SubGhzProtocolEncoderDooya));
|
||||
|
||||
instance->base.protocol = &subghz_protocol_dooya;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
|
||||
instance->encoder.repeat = 10;
|
||||
instance->encoder.size_upload = 128;
|
||||
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
|
||||
instance->encoder.is_running = false;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_dooya_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderDooya* instance = context;
|
||||
free(instance->encoder.upload);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating an upload from data.
|
||||
* @param instance Pointer to a SubGhzProtocolEncoderDooya instance
|
||||
* @return true On success
|
||||
*/
|
||||
static bool subghz_protocol_encoder_dooya_get_upload(SubGhzProtocolEncoderDooya* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
size_t index = 0;
|
||||
size_t size_upload = (instance->generic.data_count_bit * 2) + 2;
|
||||
if(size_upload > instance->encoder.size_upload) {
|
||||
FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer.");
|
||||
return false;
|
||||
} else {
|
||||
instance->encoder.size_upload = size_upload;
|
||||
}
|
||||
|
||||
//Send header
|
||||
if(bit_read(instance->generic.data, 0)) {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false,
|
||||
(uint32_t)subghz_protocol_dooya_const.te_long * 12 +
|
||||
subghz_protocol_dooya_const.te_long);
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false,
|
||||
(uint32_t)subghz_protocol_dooya_const.te_long * 12 +
|
||||
subghz_protocol_dooya_const.te_short);
|
||||
}
|
||||
|
||||
//Send start bit
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)subghz_protocol_dooya_const.te_short * 13);
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_dooya_const.te_long * 2);
|
||||
|
||||
//Send key data
|
||||
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data, i - 1)) {
|
||||
//send bit 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)subghz_protocol_dooya_const.te_long);
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_dooya_const.te_short);
|
||||
} else {
|
||||
//send bit 0
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)subghz_protocol_dooya_const.te_short);
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_dooya_const.te_long);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_encoder_dooya_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderDooya* instance = context;
|
||||
bool res = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Deserialize error");
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_dooya_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
//optional parameter parameter
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
if(!subghz_protocol_encoder_dooya_get_upload(instance)) break;
|
||||
instance->encoder.is_running = true;
|
||||
|
||||
res = true;
|
||||
} while(false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_dooya_stop(void* context) {
|
||||
SubGhzProtocolEncoderDooya* instance = context;
|
||||
instance->encoder.is_running = false;
|
||||
}
|
||||
|
||||
LevelDuration subghz_protocol_encoder_dooya_yield(void* context) {
|
||||
SubGhzProtocolEncoderDooya* instance = context;
|
||||
|
||||
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
|
||||
instance->encoder.is_running = false;
|
||||
return level_duration_reset();
|
||||
}
|
||||
|
||||
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
|
||||
|
||||
if(++instance->encoder.front == instance->encoder.size_upload) {
|
||||
instance->encoder.repeat--;
|
||||
instance->encoder.front = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* subghz_protocol_decoder_dooya_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolDecoderDooya* instance = malloc(sizeof(SubGhzProtocolDecoderDooya));
|
||||
instance->base.protocol = &subghz_protocol_dooya;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_dooya_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderDooya* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_dooya_reset(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderDooya* instance = context;
|
||||
instance->decoder.parser_step = DooyaDecoderStepReset;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_dooya_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderDooya* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case DooyaDecoderStepReset:
|
||||
if((!level) && (DURATION_DIFF(duration, subghz_protocol_dooya_const.te_long * 12) <
|
||||
subghz_protocol_dooya_const.te_delta * 20)) {
|
||||
instance->decoder.parser_step = DooyaDecoderStepFoundStartBit;
|
||||
}
|
||||
break;
|
||||
|
||||
case DooyaDecoderStepFoundStartBit:
|
||||
if(!level) {
|
||||
if(DURATION_DIFF(duration, subghz_protocol_dooya_const.te_long * 2) <
|
||||
subghz_protocol_dooya_const.te_delta * 3) {
|
||||
instance->decoder.parser_step = DooyaDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
} else {
|
||||
instance->decoder.parser_step = DooyaDecoderStepReset;
|
||||
}
|
||||
} else if(
|
||||
DURATION_DIFF(duration, subghz_protocol_dooya_const.te_short * 13) <
|
||||
subghz_protocol_dooya_const.te_delta * 5) {
|
||||
break;
|
||||
} else {
|
||||
instance->decoder.parser_step = DooyaDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case DooyaDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = DooyaDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = DooyaDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
|
||||
case DooyaDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(duration >= (subghz_protocol_dooya_const.te_long * 4)) {
|
||||
//add last bit
|
||||
if(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_dooya_const.te_short) <
|
||||
subghz_protocol_dooya_const.te_delta) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
} else if(
|
||||
DURATION_DIFF(instance->decoder.te_last, subghz_protocol_dooya_const.te_long) <
|
||||
subghz_protocol_dooya_const.te_delta * 2) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
} else {
|
||||
instance->decoder.parser_step = DooyaDecoderStepReset;
|
||||
break;
|
||||
}
|
||||
instance->decoder.parser_step = DooyaDecoderStepFoundStartBit;
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_dooya_const.min_count_bit_for_found) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
break;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_dooya_const.te_short) <
|
||||
subghz_protocol_dooya_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_dooya_const.te_long) <
|
||||
subghz_protocol_dooya_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = DooyaDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_dooya_const.te_long) <
|
||||
subghz_protocol_dooya_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_dooya_const.te_short) <
|
||||
subghz_protocol_dooya_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = DooyaDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = DooyaDecoderStepReset;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = DooyaDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analysis of received data
|
||||
* @param instance Pointer to a SubGhzBlockGeneric* instance
|
||||
*/
|
||||
static void subghz_protocol_somfy_telis_check_remote_controller(SubGhzBlockGeneric* instance) {
|
||||
/*
|
||||
* serial s/m ch key
|
||||
* long press down X * E1DC030533, 40b 111000011101110000000011 0000 0101 0011 0011
|
||||
*
|
||||
* short press down 3 * E1DC030533, 40b 111000011101110000000011 0000 0101 0011 0011
|
||||
* 3 * E1DC03053C, 40b 111000011101110000000011 0000 0101 0011 1100
|
||||
*
|
||||
* press stop X * E1DC030555, 40b 111000011101110000000011 0000 0101 0101 0101
|
||||
*
|
||||
* long press up X * E1DC030511, 40b 111000011101110000000011 0000 0101 0001 0001
|
||||
*
|
||||
* short press up 3 * E1DC030511, 40b 111000011101110000000011 0000 0101 0001 0001
|
||||
* 3 * E1DC03051E, 40b 111000011101110000000011 0000 0101 0001 1110
|
||||
*
|
||||
* serial: 3 byte serial number
|
||||
* s/m: single (b0000) / multi (b0001) channel console
|
||||
* ch: channel if single (always b0101) or multi
|
||||
* key: 0b00010001 - long press up
|
||||
* 0b00011110 - short press up
|
||||
* 0b00110011 - long press down
|
||||
* 0b00111100 - short press down
|
||||
* 0b01010101 - press stop
|
||||
* 0b01111001 - press up + down
|
||||
* 0b10000000 - press up + stop
|
||||
* 0b10000001 - press down + stop
|
||||
* 0b11001100 - press P2
|
||||
*
|
||||
*/
|
||||
|
||||
instance->serial = (instance->data >> 16);
|
||||
if((instance->data >> 12) & 0x0F) {
|
||||
instance->cnt = (instance->data >> 8) & 0x0F;
|
||||
} else {
|
||||
instance->cnt = DOYA_SINGLE_CHANNEL;
|
||||
}
|
||||
instance->btn = instance->data & 0xFF;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_decoder_dooya_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderDooya* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_dooya_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderDooya* instance = context;
|
||||
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_dooya_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderDooya* instance = context;
|
||||
bool ret = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_dooya_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
ret = true;
|
||||
} while(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button name.
|
||||
* @param btn Button number, 8 bit
|
||||
*/
|
||||
static const char* subghz_protocol_dooya_get_name_button(uint8_t btn) {
|
||||
const char* btn_name;
|
||||
switch(btn) {
|
||||
case 0b00010001:
|
||||
btn_name = "Up_Long";
|
||||
break;
|
||||
case 0b00011110:
|
||||
btn_name = "Up_Short";
|
||||
break;
|
||||
case 0b00110011:
|
||||
btn_name = "Down_Long";
|
||||
break;
|
||||
case 0b00111100:
|
||||
btn_name = "Down_Short";
|
||||
break;
|
||||
case 0b01010101:
|
||||
btn_name = "Stop";
|
||||
break;
|
||||
case 0b01111001:
|
||||
btn_name = "Up+Down";
|
||||
break;
|
||||
case 0b10000000:
|
||||
btn_name = "Up+Stop";
|
||||
break;
|
||||
case 0b10000001:
|
||||
btn_name = "Down+Stop";
|
||||
break;
|
||||
case 0b11001100:
|
||||
btn_name = "P2";
|
||||
break;
|
||||
default:
|
||||
btn_name = "Unknown";
|
||||
break;
|
||||
}
|
||||
return btn_name;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_dooya_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderDooya* instance = context;
|
||||
|
||||
subghz_protocol_somfy_telis_check_remote_controller(&instance->generic);
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %dbit\r\n"
|
||||
"Key:0x%010llX\r\n"
|
||||
"Sn:0x%08lX\r\n"
|
||||
"Btn:%s\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
instance->generic.data,
|
||||
instance->generic.serial,
|
||||
subghz_protocol_dooya_get_name_button(instance->generic.btn));
|
||||
if(instance->generic.cnt == DOYA_SINGLE_CHANNEL) {
|
||||
furi_string_cat_printf(output, "Ch:Single\r\n");
|
||||
} else {
|
||||
furi_string_cat_printf(output, "Ch:%lu\r\n", instance->generic.cnt);
|
||||
}
|
||||
}
|
||||
107
lib/subghz/protocols/dooya.h
Normal file
107
lib/subghz/protocols/dooya.h
Normal file
@@ -0,0 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#define SUBGHZ_PROTOCOL_DOOYA_NAME "Dooya"
|
||||
|
||||
typedef struct SubGhzProtocolDecoderDooya SubGhzProtocolDecoderDooya;
|
||||
typedef struct SubGhzProtocolEncoderDooya SubGhzProtocolEncoderDooya;
|
||||
|
||||
extern const SubGhzProtocolDecoder subghz_protocol_dooya_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_dooya_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_dooya;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolEncoderDooya.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolEncoderDooya* pointer to a SubGhzProtocolEncoderDooya instance
|
||||
*/
|
||||
void* subghz_protocol_encoder_dooya_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolEncoderDooya.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderDooya instance
|
||||
*/
|
||||
void subghz_protocol_encoder_dooya_free(void* context);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderDooya instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_encoder_dooya_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Forced transmission stop.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderDooya instance
|
||||
*/
|
||||
void subghz_protocol_encoder_dooya_stop(void* context);
|
||||
|
||||
/**
|
||||
* Getting the level and duration of the upload to be loaded into DMA.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderDooya instance
|
||||
* @return LevelDuration
|
||||
*/
|
||||
LevelDuration subghz_protocol_encoder_dooya_yield(void* context);
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderDooya.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolDecoderDooya* pointer to a SubGhzProtocolDecoderDooya instance
|
||||
*/
|
||||
void* subghz_protocol_decoder_dooya_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolDecoderDooya.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderDooya instance
|
||||
*/
|
||||
void subghz_protocol_decoder_dooya_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder SubGhzProtocolDecoderDooya.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderDooya instance
|
||||
*/
|
||||
void subghz_protocol_decoder_dooya_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderDooya instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void subghz_protocol_decoder_dooya_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderDooya instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t subghz_protocol_decoder_dooya_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data SubGhzProtocolDecoderDooya.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderDooya instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_dooya_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data SubGhzProtocolDecoderDooya.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderDooya instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_dooya_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderDooya instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void subghz_protocol_decoder_dooya_get_string(void* context, FuriString* output);
|
||||
@@ -520,11 +520,14 @@ void subghz_protocol_decoder_keeloq_feed(void* context, bool level, uint32_t dur
|
||||
subghz_protocol_keeloq_const.te_delta)) {
|
||||
// Found end TX
|
||||
instance->decoder.parser_step = KeeloqDecoderStepReset;
|
||||
if(instance->decoder.decode_count_bit >=
|
||||
subghz_protocol_keeloq_const.min_count_bit_for_found) {
|
||||
if((instance->decoder.decode_count_bit >=
|
||||
subghz_protocol_keeloq_const.min_count_bit_for_found) &&
|
||||
(instance->decoder.decode_count_bit <=
|
||||
subghz_protocol_keeloq_const.min_count_bit_for_found + 2)) {
|
||||
if(instance->generic.data != instance->decoder.decode_data) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
instance->generic.data_count_bit =
|
||||
subghz_protocol_keeloq_const.min_count_bit_for_found;
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
@@ -541,6 +544,8 @@ void subghz_protocol_decoder_keeloq_feed(void* context, bool level, uint32_t dur
|
||||
if(instance->decoder.decode_count_bit <
|
||||
subghz_protocol_keeloq_const.min_count_bit_for_found) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
} else {
|
||||
instance->decoder.decode_count_bit++;
|
||||
}
|
||||
instance->decoder.parser_step = KeeloqDecoderStepSaveDuration;
|
||||
} else if(
|
||||
@@ -551,6 +556,8 @@ void subghz_protocol_decoder_keeloq_feed(void* context, bool level, uint32_t dur
|
||||
if(instance->decoder.decode_count_bit <
|
||||
subghz_protocol_keeloq_const.min_count_bit_for_found) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
} else {
|
||||
instance->decoder.decode_count_bit++;
|
||||
}
|
||||
instance->decoder.parser_step = KeeloqDecoderStepSaveDuration;
|
||||
} else {
|
||||
|
||||
359
lib/subghz/protocols/linear_delta3.c
Normal file
359
lib/subghz/protocols/linear_delta3.c
Normal file
@@ -0,0 +1,359 @@
|
||||
#include "linear_delta3.h"
|
||||
|
||||
#include "../blocks/const.h"
|
||||
#include "../blocks/decoder.h"
|
||||
#include "../blocks/encoder.h"
|
||||
#include "../blocks/generic.h"
|
||||
#include "../blocks/math.h"
|
||||
|
||||
#define TAG "SubGhzProtocolLinearDelta3"
|
||||
|
||||
#define DIP_PATTERN "%c%c%c%c%c%c%c%c"
|
||||
#define DATA_TO_DIP(dip) \
|
||||
(dip & 0x0080 ? '1' : '0'), (dip & 0x0040 ? '1' : '0'), (dip & 0x0020 ? '1' : '0'), \
|
||||
(dip & 0x0010 ? '1' : '0'), (dip & 0x0008 ? '1' : '0'), (dip & 0x0004 ? '1' : '0'), \
|
||||
(dip & 0x0002 ? '1' : '0'), (dip & 0x0001 ? '1' : '0')
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_linear_delta3_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 2000,
|
||||
.te_delta = 150,
|
||||
.min_count_bit_for_found = 8,
|
||||
};
|
||||
|
||||
struct SubGhzProtocolDecoderLinearDelta3 {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
|
||||
uint32_t last_data;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderLinearDelta3 {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
LinearDecoderStepReset = 0,
|
||||
LinearDecoderStepSaveDuration,
|
||||
LinearDecoderStepCheckDuration,
|
||||
} LinearDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder subghz_protocol_linear_delta3_decoder = {
|
||||
.alloc = subghz_protocol_decoder_linear_delta3_alloc,
|
||||
.free = subghz_protocol_decoder_linear_delta3_free,
|
||||
|
||||
.feed = subghz_protocol_decoder_linear_delta3_feed,
|
||||
.reset = subghz_protocol_decoder_linear_delta3_reset,
|
||||
|
||||
.get_hash_data = subghz_protocol_decoder_linear_delta3_get_hash_data,
|
||||
.serialize = subghz_protocol_decoder_linear_delta3_serialize,
|
||||
.deserialize = subghz_protocol_decoder_linear_delta3_deserialize,
|
||||
.get_string = subghz_protocol_decoder_linear_delta3_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_linear_delta3_encoder = {
|
||||
.alloc = subghz_protocol_encoder_linear_delta3_alloc,
|
||||
.free = subghz_protocol_encoder_linear_delta3_free,
|
||||
|
||||
.deserialize = subghz_protocol_encoder_linear_delta3_deserialize,
|
||||
.stop = subghz_protocol_encoder_linear_delta3_stop,
|
||||
.yield = subghz_protocol_encoder_linear_delta3_yield,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_linear_delta3 = {
|
||||
.name = SUBGHZ_PROTOCOL_LINEAR_DELTA3_NAME,
|
||||
.type = SubGhzProtocolTypeStatic,
|
||||
.flag = SubGhzProtocolFlag_315 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
|
||||
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
|
||||
|
||||
.decoder = &subghz_protocol_linear_delta3_decoder,
|
||||
.encoder = &subghz_protocol_linear_delta3_encoder,
|
||||
};
|
||||
|
||||
void* subghz_protocol_encoder_linear_delta3_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolEncoderLinearDelta3* instance =
|
||||
malloc(sizeof(SubGhzProtocolEncoderLinearDelta3));
|
||||
|
||||
instance->base.protocol = &subghz_protocol_linear_delta3;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
|
||||
instance->encoder.repeat = 10;
|
||||
instance->encoder.size_upload = 16;
|
||||
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
|
||||
instance->encoder.is_running = false;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_linear_delta3_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderLinearDelta3* instance = context;
|
||||
free(instance->encoder.upload);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating an upload from data.
|
||||
* @param instance Pointer to a SubGhzProtocolEncoderLinearDelta3 instance
|
||||
* @return true On success
|
||||
*/
|
||||
static bool
|
||||
subghz_protocol_encoder_linear_delta3_get_upload(SubGhzProtocolEncoderLinearDelta3* instance) {
|
||||
furi_assert(instance);
|
||||
size_t index = 0;
|
||||
size_t size_upload = (instance->generic.data_count_bit * 2);
|
||||
if(size_upload > instance->encoder.size_upload) {
|
||||
FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer.");
|
||||
return false;
|
||||
} else {
|
||||
instance->encoder.size_upload = size_upload;
|
||||
}
|
||||
|
||||
//Send key data
|
||||
for(uint8_t i = instance->generic.data_count_bit; i > 1; i--) {
|
||||
if(bit_read(instance->generic.data, i - 1)) {
|
||||
//send bit 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)subghz_protocol_linear_delta3_const.te_short);
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_linear_delta3_const.te_short * 7);
|
||||
} else {
|
||||
//send bit 0
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)subghz_protocol_linear_delta3_const.te_long);
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_linear_delta3_const.te_long);
|
||||
}
|
||||
}
|
||||
//Send end bit
|
||||
if(bit_read(instance->generic.data, 0)) {
|
||||
//send bit 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)subghz_protocol_linear_delta3_const.te_short);
|
||||
//Send PT_GUARD
|
||||
instance->encoder.upload[index] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_linear_delta3_const.te_short * 73);
|
||||
} else {
|
||||
//send bit 0
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(true, (uint32_t)subghz_protocol_linear_delta3_const.te_long);
|
||||
//Send PT_GUARD
|
||||
instance->encoder.upload[index] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_linear_delta3_const.te_short * 70);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_encoder_linear_delta3_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderLinearDelta3* instance = context;
|
||||
bool res = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Deserialize error");
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_linear_delta3_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
//optional parameter parameter
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
if(!subghz_protocol_encoder_linear_delta3_get_upload(instance)) break;
|
||||
instance->encoder.is_running = true;
|
||||
|
||||
res = true;
|
||||
} while(false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_linear_delta3_stop(void* context) {
|
||||
SubGhzProtocolEncoderLinearDelta3* instance = context;
|
||||
instance->encoder.is_running = false;
|
||||
}
|
||||
|
||||
LevelDuration subghz_protocol_encoder_linear_delta3_yield(void* context) {
|
||||
SubGhzProtocolEncoderLinearDelta3* instance = context;
|
||||
|
||||
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
|
||||
instance->encoder.is_running = false;
|
||||
return level_duration_reset();
|
||||
}
|
||||
|
||||
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
|
||||
|
||||
if(++instance->encoder.front == instance->encoder.size_upload) {
|
||||
instance->encoder.repeat--;
|
||||
instance->encoder.front = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* subghz_protocol_decoder_linear_delta3_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance =
|
||||
malloc(sizeof(SubGhzProtocolDecoderLinearDelta3));
|
||||
instance->base.protocol = &subghz_protocol_linear_delta3;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_linear_delta3_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_linear_delta3_reset(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance = context;
|
||||
instance->decoder.parser_step = LinearDecoderStepReset;
|
||||
instance->last_data = 0;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_linear_delta3_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance = context;
|
||||
switch(instance->decoder.parser_step) {
|
||||
case LinearDecoderStepReset:
|
||||
if((!level) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_linear_delta3_const.te_short * 70) <
|
||||
subghz_protocol_linear_delta3_const.te_delta * 24)) {
|
||||
//Found header Linear
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->decoder.parser_step = LinearDecoderStepSaveDuration;
|
||||
}
|
||||
break;
|
||||
case LinearDecoderStepSaveDuration:
|
||||
if(level) {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = LinearDecoderStepCheckDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = LinearDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
case LinearDecoderStepCheckDuration:
|
||||
if(!level) {
|
||||
if(duration >= (subghz_protocol_linear_delta3_const.te_short * 10)) {
|
||||
instance->decoder.parser_step = LinearDecoderStepReset;
|
||||
if(DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_linear_delta3_const.te_short) <
|
||||
subghz_protocol_linear_delta3_const.te_delta) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
} else if(
|
||||
DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_linear_delta3_const.te_long) <
|
||||
subghz_protocol_linear_delta3_const.te_delta) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
}
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_linear_delta3_const.min_count_bit_for_found) {
|
||||
if((instance->last_data == instance->decoder.decode_data) &&
|
||||
instance->last_data) {
|
||||
instance->generic.serial = 0x0;
|
||||
instance->generic.btn = 0x0;
|
||||
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
instance->decoder.parser_step = LinearDecoderStepSaveDuration;
|
||||
instance->last_data = instance->decoder.decode_data;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if((DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_linear_delta3_const.te_short) <
|
||||
subghz_protocol_linear_delta3_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_linear_delta3_const.te_short * 7) <
|
||||
subghz_protocol_linear_delta3_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = LinearDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_linear_delta3_const.te_long) <
|
||||
subghz_protocol_linear_delta3_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_linear_delta3_const.te_long) <
|
||||
subghz_protocol_linear_delta3_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = LinearDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = LinearDecoderStepReset;
|
||||
}
|
||||
|
||||
} else {
|
||||
instance->decoder.parser_step = LinearDecoderStepReset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_decoder_linear_delta3_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8));
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_linear_delta3_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance = context;
|
||||
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_linear_delta3_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance = context;
|
||||
bool ret = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_linear_delta3_const.min_count_bit_for_found) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
ret = true;
|
||||
} while(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_linear_delta3_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderLinearDelta3* instance = context;
|
||||
|
||||
uint32_t data = instance->generic.data & 0xFF;
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %dbit\r\n"
|
||||
"Key:0x%lX\r\n"
|
||||
"DIP:" DIP_PATTERN "\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
data,
|
||||
DATA_TO_DIP(data));
|
||||
}
|
||||
111
lib/subghz/protocols/linear_delta3.h
Normal file
111
lib/subghz/protocols/linear_delta3.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#define SUBGHZ_PROTOCOL_LINEAR_DELTA3_NAME "LinearDelta3"
|
||||
|
||||
typedef struct SubGhzProtocolDecoderLinearDelta3 SubGhzProtocolDecoderLinearDelta3;
|
||||
typedef struct SubGhzProtocolEncoderLinearDelta3 SubGhzProtocolEncoderLinearDelta3;
|
||||
|
||||
extern const SubGhzProtocolDecoder subghz_protocol_linear_delta3_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_linear_delta3_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_linear_delta3;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolEncoderLinearDelta3.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolEncoderLinearDelta3* pointer to a SubGhzProtocolEncoderLinearDelta3 instance
|
||||
*/
|
||||
void* subghz_protocol_encoder_linear_delta3_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolEncoderLinearDelta3.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderLinearDelta3 instance
|
||||
*/
|
||||
void subghz_protocol_encoder_linear_delta3_free(void* context);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderLinearDelta3 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_encoder_linear_delta3_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Forced transmission stop.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderLinearDelta3 instance
|
||||
*/
|
||||
void subghz_protocol_encoder_linear_delta3_stop(void* context);
|
||||
|
||||
/**
|
||||
* Getting the level and duration of the upload to be loaded into DMA.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderLinearDelta3 instance
|
||||
* @return LevelDuration
|
||||
*/
|
||||
LevelDuration subghz_protocol_encoder_linear_delta3_yield(void* context);
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderLinearDelta3.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolDecoderLinearDelta3* pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
*/
|
||||
void* subghz_protocol_decoder_linear_delta3_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolDecoderLinearDelta3.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
*/
|
||||
void subghz_protocol_decoder_linear_delta3_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder SubGhzProtocolDecoderLinearDelta3.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
*/
|
||||
void subghz_protocol_decoder_linear_delta3_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void subghz_protocol_decoder_linear_delta3_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t subghz_protocol_decoder_linear_delta3_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data SubGhzProtocolDecoderLinearDelta3.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_linear_delta3_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data SubGhzProtocolDecoderLinearDelta3.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_linear_delta3_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderLinearDelta3 instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void subghz_protocol_decoder_linear_delta3_get_string(void* context, FuriString* output);
|
||||
@@ -1,21 +1,48 @@
|
||||
#include "protocol_items.h"
|
||||
|
||||
const SubGhzProtocol* subghz_protocol_registry_items[] = {
|
||||
&subghz_protocol_gate_tx, &subghz_protocol_keeloq, &subghz_protocol_star_line,
|
||||
&subghz_protocol_nice_flo, &subghz_protocol_came, &subghz_protocol_faac_slh,
|
||||
&subghz_protocol_nice_flor_s, &subghz_protocol_came_twee, &subghz_protocol_came_atomo,
|
||||
&subghz_protocol_nero_sketch, &subghz_protocol_ido, &subghz_protocol_kia,
|
||||
&subghz_protocol_hormann, &subghz_protocol_nero_radio, &subghz_protocol_somfy_telis,
|
||||
&subghz_protocol_somfy_keytis, &subghz_protocol_scher_khan, &subghz_protocol_princeton,
|
||||
&subghz_protocol_raw, &subghz_protocol_linear, &subghz_protocol_secplus_v2,
|
||||
&subghz_protocol_secplus_v1, &subghz_protocol_megacode, &subghz_protocol_holtek,
|
||||
&subghz_protocol_chamb_code, &subghz_protocol_power_smart, &subghz_protocol_marantec,
|
||||
&subghz_protocol_bett, &subghz_protocol_doitrand, &subghz_protocol_phoenix_v2,
|
||||
&subghz_protocol_honeywell_wdb, &subghz_protocol_magellan, &subghz_protocol_intertechno_v3,
|
||||
&subghz_protocol_clemsa, &subghz_protocol_ansonic, &subghz_protocol_smc5326,
|
||||
&subghz_protocol_gate_tx,
|
||||
&subghz_protocol_keeloq,
|
||||
&subghz_protocol_star_line,
|
||||
&subghz_protocol_nice_flo,
|
||||
&subghz_protocol_came,
|
||||
&subghz_protocol_faac_slh,
|
||||
&subghz_protocol_nice_flor_s,
|
||||
&subghz_protocol_came_twee,
|
||||
&subghz_protocol_came_atomo,
|
||||
&subghz_protocol_nero_sketch,
|
||||
&subghz_protocol_ido,
|
||||
&subghz_protocol_kia,
|
||||
&subghz_protocol_hormann,
|
||||
&subghz_protocol_nero_radio,
|
||||
&subghz_protocol_somfy_telis,
|
||||
&subghz_protocol_somfy_keytis,
|
||||
&subghz_protocol_scher_khan,
|
||||
&subghz_protocol_princeton,
|
||||
&subghz_protocol_raw,
|
||||
&subghz_protocol_linear,
|
||||
&subghz_protocol_secplus_v2,
|
||||
&subghz_protocol_secplus_v1,
|
||||
&subghz_protocol_megacode,
|
||||
&subghz_protocol_holtek,
|
||||
&subghz_protocol_chamb_code,
|
||||
&subghz_protocol_power_smart,
|
||||
&subghz_protocol_marantec,
|
||||
&subghz_protocol_bett,
|
||||
&subghz_protocol_doitrand,
|
||||
&subghz_protocol_phoenix_v2,
|
||||
&subghz_protocol_honeywell_wdb,
|
||||
&subghz_protocol_magellan,
|
||||
&subghz_protocol_intertechno_v3,
|
||||
&subghz_protocol_clemsa,
|
||||
&subghz_protocol_ansonic,
|
||||
&subghz_protocol_smc5326,
|
||||
&subghz_protocol_holtek_th12x,
|
||||
&subghz_protocol_linear_delta3,
|
||||
&subghz_protocol_dooya,
|
||||
&subghz_protocol_alutech_at_4n,
|
||||
};
|
||||
|
||||
const SubGhzProtocolRegistry subghz_protocol_registry = {
|
||||
.items = subghz_protocol_registry_items,
|
||||
.size = COUNT_OF(subghz_protocol_registry_items)};
|
||||
.size = COUNT_OF(subghz_protocol_registry_items)};
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "gate_tx.h"
|
||||
#include "raw.h"
|
||||
#include "linear.h"
|
||||
#include "linear_delta3.h"
|
||||
#include "secplus_v2.h"
|
||||
#include "secplus_v1.h"
|
||||
#include "megacode.h"
|
||||
@@ -38,6 +39,8 @@
|
||||
#include "ansonic.h"
|
||||
#include "smc5326.h"
|
||||
#include "holtek_ht12x.h"
|
||||
#include "dooya.h"
|
||||
#include "alutech_at_4n.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
Reference in New Issue
Block a user