mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-15 00:08:11 -07:00
Merging OFW | Suffering | Part 1 | Wont build as is
I honestly dont even know anymore...
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "math.h"
|
||||
#include <core/check.h>
|
||||
|
||||
#include "furi.h"
|
||||
|
||||
#define TAG "SubGhzBlockEncoder"
|
||||
|
||||
void subghz_protocol_blocks_set_bit_array(
|
||||
@@ -17,21 +19,32 @@ bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_inde
|
||||
return bit_read(data_array[read_index_bit >> 3], 7 - (read_index_bit & 0x7));
|
||||
}
|
||||
|
||||
size_t subghz_protocol_blocks_get_upload(
|
||||
size_t subghz_protocol_blocks_get_upload_from_bit_array(
|
||||
uint8_t data_array[],
|
||||
size_t count_bit_data_array,
|
||||
LevelDuration* upload,
|
||||
size_t max_size_upload,
|
||||
uint32_t duration_bit) {
|
||||
size_t index_bit = 0;
|
||||
uint32_t duration_bit,
|
||||
SubGhzProtocolBlockAlignBit align_bit) {
|
||||
size_t bias_bit = 0;
|
||||
size_t size_upload = 0;
|
||||
uint32_t duration = duration_bit;
|
||||
|
||||
if(align_bit == SubGhzProtocolBlockAlignBitRight) {
|
||||
if(count_bit_data_array & 0x7) {
|
||||
bias_bit = 8 - (count_bit_data_array & 0x7);
|
||||
}
|
||||
}
|
||||
size_t index_bit = bias_bit;
|
||||
|
||||
bool last_bit = subghz_protocol_blocks_get_bit_array(data_array, index_bit++);
|
||||
for(size_t i = 1; i < count_bit_data_array; i++) {
|
||||
for(size_t i = 1 + bias_bit; i < count_bit_data_array + bias_bit; i++) {
|
||||
if(last_bit == subghz_protocol_blocks_get_bit_array(data_array, index_bit)) {
|
||||
duration += duration_bit;
|
||||
} else {
|
||||
furi_assert(max_size_upload > size_upload);
|
||||
if(size_upload > max_size_upload) {
|
||||
furi_crash("SubGhz: Encoder buffer overflow");
|
||||
}
|
||||
upload[size_upload++] = level_duration_make(
|
||||
subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration);
|
||||
last_bit = !last_bit;
|
||||
@@ -42,4 +55,4 @@ size_t subghz_protocol_blocks_get_upload(
|
||||
upload[size_upload++] = level_duration_make(
|
||||
subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration);
|
||||
return size_upload;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,11 @@ typedef struct {
|
||||
|
||||
} SubGhzProtocolBlockEncoder;
|
||||
|
||||
typedef enum {
|
||||
SubGhzProtocolBlockAlignBitLeft,
|
||||
SubGhzProtocolBlockAlignBitRight,
|
||||
} SubGhzProtocolBlockAlignBit;
|
||||
|
||||
/**
|
||||
* Set data bit when encoding HEX array.
|
||||
* @param bit_value The value of the bit to be set
|
||||
@@ -47,13 +52,15 @@ bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_inde
|
||||
* @param upload Pointer to a LevelDuration
|
||||
* @param max_size_upload upload size, check not to overflow
|
||||
* @param duration_bit duration 1 bit
|
||||
* @param align_bit alignment of useful bits in an array
|
||||
*/
|
||||
size_t subghz_protocol_blocks_get_upload(
|
||||
size_t subghz_protocol_blocks_get_upload_from_bit_array(
|
||||
uint8_t data_array[],
|
||||
size_t count_bit_data_array,
|
||||
LevelDuration* upload,
|
||||
size_t max_size_upload,
|
||||
uint32_t duration_bit);
|
||||
uint32_t duration_bit,
|
||||
SubGhzProtocolBlockAlignBit align_bit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#define SUBGHZ_PROTOCOL_BIN_RAW_NAME "BinRAW"
|
||||
|
||||
typedef struct SubGhzProtocolDecoderBinRAW SubGhzProtocolDecoderBinRAW;
|
||||
typedef struct SubGhzProtocolEncoderBinRAW SubGhzProtocolEncoderBinRAW;
|
||||
|
||||
extern const SubGhzProtocolDecoder subghz_protocol_bin_raw_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_bin_raw_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_bin_raw;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolEncoderBinRAW.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolEncoderBinRAW* pointer to a SubGhzProtocolEncoderBinRAW instance
|
||||
*/
|
||||
void* subghz_protocol_encoder_bin_raw_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolEncoderBinRAW.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderBinRAW instance
|
||||
*/
|
||||
void subghz_protocol_encoder_bin_raw_free(void* context);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderBinRAW instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_encoder_bin_raw_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Forced transmission stop.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderBinRAW instance
|
||||
*/
|
||||
void subghz_protocol_encoder_bin_raw_stop(void* context);
|
||||
|
||||
/**
|
||||
* Getting the level and duration of the upload to be loaded into DMA.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderBinRAW instance
|
||||
* @return LevelDuration
|
||||
*/
|
||||
LevelDuration subghz_protocol_encoder_bin_raw_yield(void* context);
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderBinRAW.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolDecoderBinRAW* pointer to a SubGhzProtocolDecoderBinRAW instance
|
||||
*/
|
||||
void* subghz_protocol_decoder_bin_raw_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolDecoderBinRAW.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderBinRAW instance
|
||||
*/
|
||||
void subghz_protocol_decoder_bin_raw_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder SubGhzProtocolDecoderBinRAW.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderBinRAW instance
|
||||
*/
|
||||
void subghz_protocol_decoder_bin_raw_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderBinRAW instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void subghz_protocol_decoder_bin_raw_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderBinRAW instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t subghz_protocol_decoder_bin_raw_get_hash_data(void* context);
|
||||
|
||||
void subghz_protocol_decoder_bin_raw_data_input_rssi(
|
||||
SubGhzProtocolDecoderBinRAW* instance,
|
||||
float rssi);
|
||||
|
||||
/**
|
||||
* Serialize data SubGhzProtocolDecoderBinRAW.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderBinRAW 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_bin_raw_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data SubGhzProtocolDecoderBinRAW.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderBinRAW instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_bin_raw_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderBinRAW instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void subghz_protocol_decoder_bin_raw_get_string(void* context, FuriString* output);
|
||||
@@ -196,12 +196,13 @@ static bool
|
||||
break;
|
||||
}
|
||||
|
||||
instance->encoder.size_upload = subghz_protocol_blocks_get_upload(
|
||||
instance->encoder.size_upload = subghz_protocol_blocks_get_upload_from_bit_array(
|
||||
upload_hex_data,
|
||||
upload_hex_count_bit,
|
||||
instance->encoder.upload,
|
||||
instance->encoder.size_upload,
|
||||
subghz_protocol_chamb_code_const.te_short);
|
||||
subghz_protocol_chamb_code_const.te_short,
|
||||
SubGhzProtocolBlockAlignBitLeft);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
#include "kinggates_stylo_4k.h"
|
||||
#include "keeloq_common.h"
|
||||
|
||||
#include "../subghz_keystore.h"
|
||||
#include "../blocks/const.h"
|
||||
#include "../blocks/decoder.h"
|
||||
#include "../blocks/encoder.h"
|
||||
#include "../blocks/generic.h"
|
||||
#include "../blocks/math.h"
|
||||
|
||||
#define TAG "SubGhzProtocoKingGates_stylo_4k"
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_kinggates_stylo_4k_const = {
|
||||
.te_short = 400,
|
||||
.te_long = 1100,
|
||||
.te_delta = 140,
|
||||
.min_count_bit_for_found = 89,
|
||||
};
|
||||
|
||||
struct SubGhzProtocolDecoderKingGates_stylo_4k {
|
||||
SubGhzProtocolDecoderBase base;
|
||||
|
||||
SubGhzBlockDecoder decoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
|
||||
uint64_t data;
|
||||
uint16_t header_count;
|
||||
SubGhzKeystore* keystore;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderKingGates_stylo_4k {
|
||||
SubGhzProtocolEncoderBase base;
|
||||
|
||||
SubGhzProtocolBlockEncoder encoder;
|
||||
SubGhzBlockGeneric generic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
KingGates_stylo_4kDecoderStepReset = 0,
|
||||
KingGates_stylo_4kDecoderStepCheckPreambula,
|
||||
KingGates_stylo_4kDecoderStepCheckStartBit,
|
||||
KingGates_stylo_4kDecoderStepSaveDuration,
|
||||
KingGates_stylo_4kDecoderStepCheckDuration,
|
||||
} KingGates_stylo_4kDecoderStep;
|
||||
|
||||
const SubGhzProtocolDecoder subghz_protocol_kinggates_stylo_4k_decoder = {
|
||||
.alloc = subghz_protocol_decoder_kinggates_stylo_4k_alloc,
|
||||
.free = subghz_protocol_decoder_kinggates_stylo_4k_free,
|
||||
|
||||
.feed = subghz_protocol_decoder_kinggates_stylo_4k_feed,
|
||||
.reset = subghz_protocol_decoder_kinggates_stylo_4k_reset,
|
||||
|
||||
.get_hash_data = subghz_protocol_decoder_kinggates_stylo_4k_get_hash_data,
|
||||
.serialize = subghz_protocol_decoder_kinggates_stylo_4k_serialize,
|
||||
.deserialize = subghz_protocol_decoder_kinggates_stylo_4k_deserialize,
|
||||
.get_string = subghz_protocol_decoder_kinggates_stylo_4k_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_kinggates_stylo_4k_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_kinggates_stylo_4k = {
|
||||
.name = SUBGHZ_PROTOCOL_KINGGATES_STYLO_4K_NAME,
|
||||
.type = SubGhzProtocolTypeDynamic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||
|
||||
.decoder = &subghz_protocol_kinggates_stylo_4k_decoder,
|
||||
.encoder = &subghz_protocol_kinggates_stylo_4k_encoder,
|
||||
};
|
||||
|
||||
void* subghz_protocol_decoder_kinggates_stylo_4k_alloc(SubGhzEnvironment* environment) {
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance =
|
||||
malloc(sizeof(SubGhzProtocolDecoderKingGates_stylo_4k));
|
||||
instance->base.protocol = &subghz_protocol_kinggates_stylo_4k;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
instance->keystore = subghz_environment_get_keystore(environment);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance = context;
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_reset(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance = context;
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepReset;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance = context;
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case KingGates_stylo_4kDecoderStepReset:
|
||||
if((level) && DURATION_DIFF(duration, subghz_protocol_kinggates_stylo_4k_const.te_short) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta) {
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepCheckPreambula;
|
||||
instance->header_count++;
|
||||
}
|
||||
break;
|
||||
case KingGates_stylo_4kDecoderStepCheckPreambula:
|
||||
if((!level) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_kinggates_stylo_4k_const.te_short) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta)) {
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepReset;
|
||||
break;
|
||||
}
|
||||
if((instance->header_count > 2) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_kinggates_stylo_4k_const.te_long * 2) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta * 2)) {
|
||||
// Found header
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepCheckStartBit;
|
||||
} else {
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepReset;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
case KingGates_stylo_4kDecoderStepCheckStartBit:
|
||||
if((level) &&
|
||||
DURATION_DIFF(duration, subghz_protocol_kinggates_stylo_4k_const.te_short * 2) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta * 2) {
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepSaveDuration;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
case KingGates_stylo_4kDecoderStepSaveDuration:
|
||||
if(!level) {
|
||||
if(duration >= ((uint32_t)subghz_protocol_kinggates_stylo_4k_const.te_long * 3)) {
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_kinggates_stylo_4k_const.min_count_bit_for_found) {
|
||||
instance->generic.data = instance->data;
|
||||
instance->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 = KingGates_stylo_4kDecoderStepReset;
|
||||
instance->decoder.decode_data = 0;
|
||||
instance->data = 0;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->header_count = 0;
|
||||
break;
|
||||
} else {
|
||||
instance->decoder.te_last = duration;
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepCheckDuration;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepReset;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
break;
|
||||
case KingGates_stylo_4kDecoderStepCheckDuration:
|
||||
if(level) {
|
||||
if((DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_kinggates_stylo_4k_const.te_short) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_kinggates_stylo_4k_const.te_long) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta * 2)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepSaveDuration;
|
||||
} else if(
|
||||
(DURATION_DIFF(
|
||||
instance->decoder.te_last, subghz_protocol_kinggates_stylo_4k_const.te_long) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta * 2) &&
|
||||
(DURATION_DIFF(duration, subghz_protocol_kinggates_stylo_4k_const.te_short) <
|
||||
subghz_protocol_kinggates_stylo_4k_const.te_delta)) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepSaveDuration;
|
||||
} else {
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepReset;
|
||||
instance->header_count = 0;
|
||||
}
|
||||
if(instance->decoder.decode_count_bit == 53) {
|
||||
instance->data = instance->decoder.decode_data;
|
||||
instance->decoder.decode_data = 0;
|
||||
}
|
||||
} else {
|
||||
instance->decoder.parser_step = KingGates_stylo_4kDecoderStepReset;
|
||||
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_kinggates_stylo_4k_remote_controller(
|
||||
SubGhzBlockGeneric* instance,
|
||||
uint64_t data,
|
||||
SubGhzKeystore* keystore) {
|
||||
/**
|
||||
* 9500us 12*(400/400) 2200/800|1-bit|0-bit|
|
||||
* _ _ _ __ ___ _
|
||||
* ________| |_| |_..._| |_____| |_| |___| |.....
|
||||
*
|
||||
* 1-bit 400/1100 us
|
||||
* 0-bit 1100/400 us
|
||||
*
|
||||
* The package consists of 89 bits of data, LSB first
|
||||
* Data - 1C9037F0C80000 CE280BA00
|
||||
* S[3] S[2] 1 key S[1] S[0] 2 byte always 0 Hop[3] Hop[2] Hop[1] Hop[0] 0
|
||||
* 11100100 10000001 1 0111 11110000 11001000 00000000 00000000 11001110 00101000 00001011 10100000 0000
|
||||
*
|
||||
* Encryption - keeloq Simple Learning
|
||||
* key C S[3] CNT
|
||||
* Decrypt - 0xEC270B9C => 0x E C 27 0B9C
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t hop = subghz_protocol_blocks_reverse_key(data >> 4, 32);
|
||||
uint64_t fix = subghz_protocol_blocks_reverse_key(instance->data, 53);
|
||||
bool ret = false;
|
||||
uint32_t decrypt = 0;
|
||||
instance->btn = (fix >> 17) & 0x0F;
|
||||
instance->serial = ((fix >> 5) & 0xFFFF0000) | (fix & 0xFFFF);
|
||||
|
||||
for
|
||||
M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) {
|
||||
if(manufacture_code->type == KEELOQ_LEARNING_SIMPLE) {
|
||||
decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key);
|
||||
if(((decrypt >> 28) == instance->btn) && (((decrypt >> 24) & 0x0F) == 0x0C) &&
|
||||
(((decrypt >> 16) & 0xFF) == (instance->serial & 0xFF))) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ret) {
|
||||
instance->cnt = decrypt & 0xFFFF;
|
||||
} else {
|
||||
instance->btn = 0;
|
||||
instance->serial = 0;
|
||||
instance->cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_decoder_kinggates_stylo_4k_get_hash_data(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance = context;
|
||||
return subghz_protocol_blocks_get_hash_data(
|
||||
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_kinggates_stylo_4k_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance = context;
|
||||
bool res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
for(size_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
key_data[sizeof(uint64_t) - i - 1] = (instance->data >> (i * 8)) & 0xFF;
|
||||
}
|
||||
|
||||
if(res && !flipper_format_write_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Unable to add Data");
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
|
||||
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_kinggates_stylo_4k_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance = context;
|
||||
bool ret = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_kinggates_stylo_4k_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;
|
||||
}
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
if(!flipper_format_read_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Missing Data");
|
||||
break;
|
||||
}
|
||||
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
instance->data = instance->data << 8 | key_data[i];
|
||||
}
|
||||
ret = true;
|
||||
} while(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderKingGates_stylo_4k* instance = context;
|
||||
subghz_protocol_kinggates_stylo_4k_remote_controller(
|
||||
&instance->generic, instance->data, instance->keystore);
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s\r\n"
|
||||
"Key:0x%llX%07llX %dbit\r\n"
|
||||
"Sn:0x%08lX Btn:0x%01X\r\n"
|
||||
"Cnt:0x%04lX\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data,
|
||||
instance->data,
|
||||
instance->generic.data_count_bit,
|
||||
instance->generic.serial,
|
||||
instance->generic.btn,
|
||||
instance->generic.cnt);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#include "base.h"
|
||||
|
||||
#define SUBGHZ_PROTOCOL_KINGGATES_STYLO_4K_NAME "KingGates Stylo4k"
|
||||
|
||||
typedef struct SubGhzProtocolDecoderKingGates_stylo_4k SubGhzProtocolDecoderKingGates_stylo_4k;
|
||||
typedef struct SubGhzProtocolEncoderKingGates_stylo_4k SubGhzProtocolEncoderKingGates_stylo_4k;
|
||||
|
||||
extern const SubGhzProtocolDecoder subghz_protocol_kinggates_stylo_4k_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_kinggates_stylo_4k_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_kinggates_stylo_4k;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderKingGates_stylo_4k.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolDecoderKingGates_stylo_4k* pointer to a SubGhzProtocolDecoderKingGates_stylo_4k instance
|
||||
*/
|
||||
void* subghz_protocol_decoder_kinggates_stylo_4k_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolDecoderKingGates_stylo_4k.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderKingGates_stylo_4k instance
|
||||
*/
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_free(void* context);
|
||||
|
||||
/**
|
||||
* Reset decoder SubGhzProtocolDecoderKingGates_stylo_4k.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderKingGates_stylo_4k instance
|
||||
*/
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_reset(void* context);
|
||||
|
||||
/**
|
||||
* Parse a raw sequence of levels and durations received from the air.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderKingGates_stylo_4k instance
|
||||
* @param level Signal level true-high false-low
|
||||
* @param duration Duration of this level in, us
|
||||
*/
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_feed(void* context, bool level, uint32_t duration);
|
||||
|
||||
/**
|
||||
* Getting the hash sum of the last randomly received parcel.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderKingGates_stylo_4k instance
|
||||
* @return hash Hash sum
|
||||
*/
|
||||
uint8_t subghz_protocol_decoder_kinggates_stylo_4k_get_hash_data(void* context);
|
||||
|
||||
/**
|
||||
* Serialize data SubGhzProtocolDecoderKingGates_stylo_4k.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderKingGates_stylo_4k 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_kinggates_stylo_4k_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize data SubGhzProtocolDecoderKingGates_stylo_4k.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderKingGates_stylo_4k instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_decoder_kinggates_stylo_4k_deserialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Getting a textual representation of the received data.
|
||||
* @param context Pointer to a SubGhzProtocolDecoderKingGates_stylo_4k instance
|
||||
* @param output Resulting text
|
||||
*/
|
||||
void subghz_protocol_decoder_kinggates_stylo_4k_get_string(void* context, FuriString* output);
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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);
|
||||
@@ -14,6 +14,9 @@
|
||||
|
||||
#define TAG "SubGhzProtocolNiceFlorS"
|
||||
|
||||
#define NICE_ONE_COUNT_BIT 72
|
||||
#define NICE_ONE_NAME "Nice One"
|
||||
|
||||
static const SubGhzBlockConst subghz_protocol_nice_flor_s_const = {
|
||||
.te_short = 500,
|
||||
.te_long = 1000,
|
||||
@@ -28,6 +31,7 @@ struct SubGhzProtocolDecoderNiceFlorS {
|
||||
SubGhzBlockGeneric generic;
|
||||
|
||||
const char* nice_flor_s_rainbow_table_file_name;
|
||||
uint64_t data;
|
||||
};
|
||||
|
||||
struct SubGhzProtocolEncoderNiceFlorS {
|
||||
@@ -243,6 +247,64 @@ LevelDuration subghz_protocol_encoder_nice_flor_s_yield(void* context) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Read bytes from rainbow table
|
||||
// * @param p array[10] P0-P1|P2-P3-P4-P5-P6-P7-P8-P9-P10
|
||||
// * @return crc
|
||||
// */
|
||||
// static uint32_t subghz_protocol_nice_one_crc(uint8_t* p) {
|
||||
// uint8_t crc = 0;
|
||||
// uint8_t crc_data = 0xff;
|
||||
// for(uint8_t i = 4; i < 68; i++) {
|
||||
// if(subghz_protocol_blocks_get_bit_array(p, i)) {
|
||||
// crc = crc_data ^ 1;
|
||||
// } else {
|
||||
// crc = crc_data;
|
||||
// }
|
||||
// crc_data >>= 1;
|
||||
// if((crc & 0x01)) {
|
||||
// crc_data ^= 0x97;
|
||||
// }
|
||||
// }
|
||||
// crc = 0;
|
||||
// for(uint8_t i = 0; i < 8; i++) {
|
||||
// crc <<= 1;
|
||||
// if((crc_data >> i) & 0x01) crc = crc | 1;
|
||||
// }
|
||||
// return crc;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Read bytes from rainbow table
|
||||
// * @param p array[10] P0-P1|P2-P3-P4-P5-P6-P7-XX-XX-XX
|
||||
// * @param num_parcel parcel number 0..15
|
||||
// * @param hold_bit 0 - the button was only pressed, 1 - the button was held down
|
||||
// */
|
||||
// static void subghz_protocol_nice_one_get_data(uint8_t* p, uint8_t num_parcel, uint8_t hold_bit) {
|
||||
// uint8_t k = 0;
|
||||
// uint8_t crc = 0;
|
||||
// p[1] = (p[1] & 0x0f) | ((0x0f ^ (p[0] & 0x0F) ^ num_parcel) << 4);
|
||||
// if(num_parcel < 4) {
|
||||
// k = 0x8f;
|
||||
// } else {
|
||||
// k = 0x80;
|
||||
// }
|
||||
|
||||
// if(!hold_bit) {
|
||||
// hold_bit = 0;
|
||||
// } else {
|
||||
// hold_bit = 0x10;
|
||||
// }
|
||||
// k = num_parcel ^ k;
|
||||
// p[7] = k;
|
||||
// p[8] = hold_bit ^ (k << 4);
|
||||
|
||||
// crc = subghz_protocol_nice_one_crc(p);
|
||||
|
||||
// p[8] |= crc >> 4;
|
||||
// p[9] = crc << 4;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Read bytes from rainbow table
|
||||
* @param file_name Full path to rainbow table the file
|
||||
@@ -427,10 +489,14 @@ void subghz_protocol_decoder_nice_flor_s_feed(void* context, bool level, uint32_
|
||||
subghz_protocol_nice_flor_s_const.te_delta) {
|
||||
//Found STOP bit
|
||||
instance->decoder.parser_step = NiceFlorSDecoderStepReset;
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_nice_flor_s_const.min_count_bit_for_found) {
|
||||
instance->generic.data = instance->decoder.decode_data;
|
||||
if((instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_nice_flor_s_const.min_count_bit_for_found) ||
|
||||
(instance->decoder.decode_count_bit == NICE_ONE_COUNT_BIT)) {
|
||||
instance->generic.data = instance->data;
|
||||
instance->data = instance->decoder.decode_data;
|
||||
instance->decoder.decode_data = instance->generic.data;
|
||||
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
||||
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
@@ -464,6 +530,11 @@ void subghz_protocol_decoder_nice_flor_s_feed(void* context, bool level, uint32_
|
||||
} else {
|
||||
instance->decoder.parser_step = NiceFlorSDecoderStepReset;
|
||||
}
|
||||
if(instance->decoder.decode_count_bit ==
|
||||
subghz_protocol_nice_flor_s_const.min_count_bit_for_found) {
|
||||
instance->data = instance->decoder.decode_data;
|
||||
instance->decoder.decode_data = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -477,6 +548,7 @@ static void subghz_protocol_nice_flor_s_remote_controller(
|
||||
SubGhzBlockGeneric* instance,
|
||||
const char* file_name) {
|
||||
/*
|
||||
* Protocol Nice Flor-S
|
||||
* Packet format Nice Flor-s: START-P0-P1-P2-P3-P4-P5-P6-P7-STOP
|
||||
* P0 (4-bit) - button positional code - 1:0x1, 2:0x2, 3:0x4, 4:0x8;
|
||||
* P1 (4-bit) - batch repetition number, calculated by the formula:
|
||||
@@ -497,6 +569,24 @@ static void subghz_protocol_nice_flor_s_remote_controller(
|
||||
* data => 0x1c5783607f7b3 key serial cnt
|
||||
* decrypt => 0x10436c6820444 => 0x1 0436c682 0444
|
||||
*
|
||||
* Protocol Nice One
|
||||
* Generally repeats the Nice Flor-S protocol, but there are a few changes
|
||||
* Packet format first 52 bytes repeat Nice Flor-S protocol
|
||||
* The additional 20 bytes contain the code of the pressed button,
|
||||
* the button hold bit and the CRC of the entire message.
|
||||
* START-P0-P1-P2-P3-P4-P5-P6-P7-P8-P9-P10-STOP
|
||||
* P7 (byte) - if (n<4) k=0x8f : k=0x80; P7= k^n;
|
||||
* P8 (byte) - if (hold bit) b=0x00 : b=0x10; P8= b^(k<<4) | 4 hi bit crc
|
||||
* P10 (4-bit) - 4 lo bit crc
|
||||
* key+b crc
|
||||
* data => 0x1724A7D9A522F 899 D6 hold bit = 0 - just pressed the button
|
||||
* data => 0x1424A7D9A522F 8AB 03 hold bit = 1 - button hold
|
||||
*
|
||||
* A small button hold counter (0..15) is stored between each press,
|
||||
* i.e. if 1 press of the button stops counter 6, then the next press
|
||||
* of the button will start from the value 7 (hold bit = 0), 8 (hold bit = 1)...
|
||||
* further up to 15 with overflow
|
||||
*
|
||||
*/
|
||||
if(!file_name) {
|
||||
instance->cnt = 0;
|
||||
@@ -523,7 +613,15 @@ bool subghz_protocol_decoder_nice_flor_s_serialize(
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderNiceFlorS* instance = context;
|
||||
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
bool res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
if(instance->generic.data_count_bit == NICE_ONE_COUNT_BIT) {
|
||||
if(res &&
|
||||
!flipper_format_write_uint32(flipper_format, "Data", (uint32_t*)&instance->data, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Data");
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_nice_flor_s_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
@@ -534,11 +632,25 @@ bool subghz_protocol_decoder_nice_flor_s_deserialize(void* context, FlipperForma
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit !=
|
||||
subghz_protocol_nice_flor_s_const.min_count_bit_for_found) {
|
||||
if((instance->generic.data_count_bit !=
|
||||
subghz_protocol_nice_flor_s_const.min_count_bit_for_found) &&
|
||||
(instance->generic.data_count_bit != NICE_ONE_COUNT_BIT)) {
|
||||
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||
break;
|
||||
}
|
||||
if(instance->generic.data_count_bit == NICE_ONE_COUNT_BIT) {
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
uint32_t temp = 0;
|
||||
if(!flipper_format_read_uint32(flipper_format, "Data", (uint32_t*)&temp, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Data");
|
||||
break;
|
||||
}
|
||||
instance->data = (uint64_t)temp;
|
||||
}
|
||||
|
||||
ret = true;
|
||||
} while(false);
|
||||
return ret;
|
||||
@@ -550,20 +662,33 @@ void subghz_protocol_decoder_nice_flor_s_get_string(void* context, FuriString* o
|
||||
|
||||
subghz_protocol_nice_flor_s_remote_controller(
|
||||
&instance->generic, instance->nice_flor_s_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 %dbit\r\n"
|
||||
"Key:0x%lX%08lX\r\n"
|
||||
"Sn:%05lX\r\n"
|
||||
"Cnt:%04lX Btn:%02X\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
instance->generic.serial,
|
||||
instance->generic.cnt,
|
||||
instance->generic.btn);
|
||||
if(instance->generic.data_count_bit == NICE_ONE_COUNT_BIT) {
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %dbit\r\n"
|
||||
"Key:0x%013llX%llX\r\n"
|
||||
"Sn:%05lX\r\n"
|
||||
"Cnt:%04lX Btn:%02X\r\n",
|
||||
NICE_ONE_NAME,
|
||||
instance->generic.data_count_bit,
|
||||
instance->generic.data,
|
||||
instance->data,
|
||||
instance->generic.serial,
|
||||
instance->generic.cnt,
|
||||
instance->generic.btn);
|
||||
} else {
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %dbit\r\n"
|
||||
"Key:0x%013llX\r\n"
|
||||
"Sn:%05lX\r\n"
|
||||
"Cnt:%04lX Btn:%02X\r\n",
|
||||
instance->generic.protocol_name,
|
||||
instance->generic.data_count_bit,
|
||||
instance->generic.data,
|
||||
instance->generic.serial,
|
||||
instance->generic.cnt,
|
||||
instance->generic.btn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,50 @@
|
||||
#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_pocsag,
|
||||
&subghz_protocol_smc5326, &subghz_protocol_holtek_th12x,
|
||||
&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_pocsag,
|
||||
&subghz_protocol_smc5326,
|
||||
&subghz_protocol_holtek_th12x,
|
||||
&subghz_protocol_linear_delta3,
|
||||
&subghz_protocol_dooya,
|
||||
&subghz_protocol_alutech_at_4n,
|
||||
&subghz_protocol_kinggates_stylo_4k,
|
||||
};
|
||||
|
||||
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"
|
||||
@@ -39,6 +40,9 @@
|
||||
#include "pocsag.h"
|
||||
#include "smc5326.h"
|
||||
#include "holtek_ht12x.h"
|
||||
#include "dooya.h"
|
||||
#include "alutech_at_4n.h"
|
||||
#include "kinggates_stylo_4k.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -606,7 +606,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"Sn:0x%08lX\r\n"
|
||||
"Cnt:0x%03lX\r\n"
|
||||
"Cnt:0x%03lX "
|
||||
"Sw_id:0x%X\r\n",
|
||||
instance->generic.serial,
|
||||
instance->generic.cnt,
|
||||
@@ -625,7 +625,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"Sn:0x%08lX\r\n"
|
||||
"Cnt:0x%03lX\r\n"
|
||||
"Cnt:0x%03lX "
|
||||
"Sw_id:0x%X\r\n",
|
||||
instance->generic.serial,
|
||||
instance->generic.cnt,
|
||||
|
||||
@@ -55,25 +55,40 @@ const SubGhzProtocolDecoder subghz_protocol_somfy_keytis_decoder = {
|
||||
.get_string = subghz_protocol_decoder_somfy_keytis_get_string,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_somfy_keytis_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_somfy_keytis = {
|
||||
.name = SUBGHZ_PROTOCOL_SOMFY_KEYTIS_NAME,
|
||||
.type = SubGhzProtocolTypeDynamic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_868 | SubGhzProtocolFlag_AM |
|
||||
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save,
|
||||
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
|
||||
|
||||
.decoder = &subghz_protocol_somfy_keytis_decoder,
|
||||
.encoder = &subghz_protocol_somfy_keytis_encoder,
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_somfy_keytis_encoder = {
|
||||
.alloc = subghz_protocol_encoder_somfy_keytis_alloc,
|
||||
.free = subghz_protocol_encoder_somfy_keytis_free,
|
||||
|
||||
.deserialize = subghz_protocol_encoder_somfy_keytis_deserialize,
|
||||
.stop = subghz_protocol_encoder_somfy_keytis_stop,
|
||||
.yield = subghz_protocol_encoder_somfy_keytis_yield,
|
||||
};
|
||||
|
||||
void* subghz_protocol_encoder_somfy_keytis_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolEncoderSomfyKeytis* instance = malloc(sizeof(SubGhzProtocolEncoderSomfyKeytis));
|
||||
|
||||
instance->base.protocol = &subghz_protocol_somfy_keytis;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
|
||||
instance->encoder.repeat = 10;
|
||||
instance->encoder.size_upload = 512;
|
||||
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
|
||||
instance->encoder.is_running = false;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void* subghz_protocol_decoder_somfy_keytis_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolDecoderSomfyKeytis* instance = malloc(sizeof(SubGhzProtocolDecoderSomfyKeytis));
|
||||
@@ -83,6 +98,13 @@ void* subghz_protocol_decoder_somfy_keytis_alloc(SubGhzEnvironment* environment)
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_somfy_keytis_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSomfyKeytis* instance = context;
|
||||
free(instance->encoder.upload);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_decoder_somfy_keytis_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderSomfyKeytis* instance = context;
|
||||
@@ -100,6 +122,330 @@ void subghz_protocol_decoder_somfy_keytis_reset(void* context) {
|
||||
NULL);
|
||||
}
|
||||
|
||||
static bool
|
||||
subghz_protocol_somfy_keytis_gen_data(SubGhzProtocolEncoderSomfyKeytis* instance, uint8_t btn) {
|
||||
UNUSED(btn);
|
||||
uint64_t data = instance->generic.data ^ (instance->generic.data >> 8);
|
||||
instance->generic.btn = (data >> 48) & 0xF;
|
||||
instance->generic.cnt = (data >> 24) & 0xFFFF;
|
||||
instance->generic.serial = data & 0xFFFFFF;
|
||||
|
||||
if(instance->generic.cnt < 0xFFFF) {
|
||||
instance->generic.cnt++;
|
||||
} else if(instance->generic.cnt >= 0xFFFF) {
|
||||
instance->generic.cnt = 0;
|
||||
}
|
||||
|
||||
uint8_t frame[10];
|
||||
frame[0] = (0xA << 4) | instance->generic.btn;
|
||||
frame[1] = 0xF << 4;
|
||||
frame[2] = instance->generic.cnt >> 8;
|
||||
frame[3] = instance->generic.cnt;
|
||||
frame[4] = instance->generic.serial >> 16;
|
||||
frame[5] = instance->generic.serial >> 8;
|
||||
frame[6] = instance->generic.serial;
|
||||
frame[7] = 0xC4;
|
||||
frame[8] = 0x00;
|
||||
frame[9] = 0x19;
|
||||
|
||||
uint8_t checksum = 0;
|
||||
for(uint8_t i = 0; i < 7; i++) {
|
||||
checksum = checksum ^ frame[i] ^ (frame[i] >> 4);
|
||||
}
|
||||
checksum &= 0xF;
|
||||
|
||||
frame[1] |= checksum;
|
||||
|
||||
for(uint8_t i = 1; i < 7; i++) {
|
||||
frame[i] ^= frame[i - 1];
|
||||
}
|
||||
data = 0;
|
||||
for(uint8_t i = 0; i < 7; ++i) {
|
||||
data <<= 8;
|
||||
data |= frame[i];
|
||||
}
|
||||
instance->generic.data = data;
|
||||
data = 0;
|
||||
for(uint8_t i = 7; i < 10; ++i) {
|
||||
data <<= 8;
|
||||
data |= frame[i];
|
||||
}
|
||||
instance->generic.data_2 = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_somfy_keytis_create_data(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
uint32_t serial,
|
||||
uint8_t btn,
|
||||
uint16_t cnt,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSomfyKeytis* instance = context;
|
||||
instance->generic.serial = serial;
|
||||
instance->generic.cnt = cnt;
|
||||
instance->generic.data_count_bit = 80;
|
||||
bool res = subghz_protocol_somfy_keytis_gen_data(instance, btn);
|
||||
if(res) {
|
||||
res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating an upload from data.
|
||||
* @param instance Pointer to a SubGhzProtocolEncoderKeeloq instance
|
||||
* @return true On success
|
||||
*/
|
||||
static bool subghz_protocol_encoder_somfy_keytis_get_upload(
|
||||
SubGhzProtocolEncoderSomfyKeytis* instance,
|
||||
uint8_t btn) {
|
||||
furi_assert(instance);
|
||||
|
||||
//gen new key
|
||||
if(subghz_protocol_somfy_keytis_gen_data(instance, btn)) {
|
||||
//ToDo if you need to add a callback to automatically update the data on the display
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
//Send header
|
||||
//Wake up
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)9415); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)89565); // 0
|
||||
//Hardware sync
|
||||
for(uint8_t i = 0; i < 12; ++i) {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short * 4); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short * 4); // 0
|
||||
}
|
||||
//Software sync
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)4550); // 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
|
||||
//Send key data MSB manchester
|
||||
|
||||
for(uint8_t i = instance->generic.data_count_bit - 24; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data, i - 1)) {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 00
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
}
|
||||
|
||||
} else {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_HIGH) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 11
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(uint8_t i = 24; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data_2, i - 1)) {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 00
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
}
|
||||
|
||||
} else {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_HIGH) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 11
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Inter-frame silence
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration +=
|
||||
(uint32_t)subghz_protocol_somfy_keytis_const.te_short * 3;
|
||||
} else {
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short * 3);
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < 2; ++i) {
|
||||
//Hardware sync
|
||||
for(uint8_t i = 0; i < 6; ++i) {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short * 4); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short * 4); // 0
|
||||
}
|
||||
//Software sync
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)4550); // 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
|
||||
//Send key data MSB manchester
|
||||
|
||||
for(uint8_t i = instance->generic.data_count_bit - 24; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data, i - 1)) {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 00
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
}
|
||||
|
||||
} else {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_HIGH) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 11
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(uint8_t i = 24; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data_2, i - 1)) {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 00
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
}
|
||||
|
||||
} else {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_HIGH) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 11
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short); // 0
|
||||
}
|
||||
}
|
||||
}
|
||||
//Inter-frame silence
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration +=
|
||||
(uint32_t)subghz_protocol_somfy_keytis_const.te_short * 3;
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_keytis_const.te_short * 3);
|
||||
}
|
||||
}
|
||||
|
||||
//Inter-frame silence
|
||||
instance->encoder.upload[index - 1].duration +=
|
||||
(uint32_t)30415 - (uint32_t)subghz_protocol_somfy_keytis_const.te_short * 3;
|
||||
|
||||
size_t size_upload = index;
|
||||
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_encoder_somfy_keytis_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSomfyKeytis* instance = context;
|
||||
bool res = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Deserialize error");
|
||||
break;
|
||||
}
|
||||
|
||||
//optional parameter parameter
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
subghz_protocol_encoder_somfy_keytis_get_upload(instance, instance->generic.btn);
|
||||
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
for(size_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF;
|
||||
}
|
||||
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Unable to add Key");
|
||||
break;
|
||||
}
|
||||
|
||||
instance->encoder.is_running = true;
|
||||
|
||||
res = true;
|
||||
} while(false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_somfy_keytis_stop(void* context) {
|
||||
SubGhzProtocolEncoderSomfyKeytis* instance = context;
|
||||
instance->encoder.is_running = false;
|
||||
}
|
||||
|
||||
LevelDuration subghz_protocol_encoder_somfy_keytis_yield(void* context) {
|
||||
SubGhzProtocolEncoderSomfyKeytis* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Сhecksum calculation.
|
||||
* @param data Вata for checksum calculation
|
||||
|
||||
@@ -11,6 +11,58 @@ extern const SubGhzProtocolDecoder subghz_protocol_somfy_keytis_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_somfy_keytis_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_somfy_keytis;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolEncoderSomfyKeytis.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolEncoderSomfyKeytis* pointer to a SubGhzProtocolEncoderSomfyKeytis instance
|
||||
*/
|
||||
void* subghz_protocol_encoder_somfy_keytis_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolEncoderSomfyKeytis.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyKeytis instance
|
||||
*/
|
||||
void subghz_protocol_encoder_somfy_keytis_free(void* context);
|
||||
|
||||
/**
|
||||
* Key generation from simple data.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyKeytis instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param serial Serial number, 24 bit
|
||||
* @param btn Button number, 8 bit
|
||||
* @param cnt Counter value, 16 bit
|
||||
* @param preset Modulation, SubGhzRadioPreset
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_somfy_keytis_create_data(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
uint32_t serial,
|
||||
uint8_t btn,
|
||||
uint16_t cnt,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyKeytis instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_encoder_somfy_keytis_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Forced transmission stop.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyKeytis instance
|
||||
*/
|
||||
void subghz_protocol_encoder_somfy_keytis_stop(void* context);
|
||||
|
||||
/**
|
||||
* Getting the level and duration of the upload to be loaded into DMA.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyKeytis instance
|
||||
* @return LevelDuration
|
||||
*/
|
||||
LevelDuration subghz_protocol_encoder_somfy_keytis_yield(void* context);
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderSomfyKeytis.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
|
||||
@@ -55,24 +55,301 @@ const SubGhzProtocolDecoder subghz_protocol_somfy_telis_decoder = {
|
||||
};
|
||||
|
||||
const SubGhzProtocolEncoder subghz_protocol_somfy_telis_encoder = {
|
||||
.alloc = NULL,
|
||||
.free = NULL,
|
||||
.alloc = subghz_protocol_encoder_somfy_telis_alloc,
|
||||
.free = subghz_protocol_encoder_somfy_telis_free,
|
||||
|
||||
.deserialize = NULL,
|
||||
.stop = NULL,
|
||||
.yield = NULL,
|
||||
.deserialize = subghz_protocol_encoder_somfy_telis_deserialize,
|
||||
.stop = subghz_protocol_encoder_somfy_telis_stop,
|
||||
.yield = subghz_protocol_encoder_somfy_telis_yield,
|
||||
};
|
||||
|
||||
const SubGhzProtocol subghz_protocol_somfy_telis = {
|
||||
.name = SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME,
|
||||
.type = SubGhzProtocolTypeDynamic,
|
||||
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_868 | SubGhzProtocolFlag_AM |
|
||||
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save,
|
||||
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
|
||||
|
||||
.decoder = &subghz_protocol_somfy_telis_decoder,
|
||||
.encoder = &subghz_protocol_somfy_telis_encoder,
|
||||
};
|
||||
|
||||
void* subghz_protocol_encoder_somfy_telis_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolEncoderSomfyTelis* instance = malloc(sizeof(SubGhzProtocolEncoderSomfyTelis));
|
||||
|
||||
instance->base.protocol = &subghz_protocol_somfy_telis;
|
||||
instance->generic.protocol_name = instance->base.protocol->name;
|
||||
|
||||
instance->encoder.repeat = 10;
|
||||
instance->encoder.size_upload = 512;
|
||||
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
|
||||
instance->encoder.is_running = false;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_somfy_telis_free(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSomfyTelis* instance = context;
|
||||
free(instance->encoder.upload);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
static bool
|
||||
subghz_protocol_somfy_telis_gen_data(SubGhzProtocolEncoderSomfyTelis* instance, uint8_t btn) {
|
||||
UNUSED(btn);
|
||||
uint64_t data = instance->generic.data ^ (instance->generic.data >> 8);
|
||||
instance->generic.btn = (data >> 44) & 0xF; // ctrl
|
||||
instance->generic.cnt = (data >> 24) & 0xFFFF; // rolling code
|
||||
instance->generic.serial = data & 0xFFFFFF; // address
|
||||
|
||||
if(instance->generic.cnt < 0xFFFF) {
|
||||
instance->generic.cnt++;
|
||||
} else if(instance->generic.cnt >= 0xFFFF) {
|
||||
instance->generic.cnt = 0;
|
||||
}
|
||||
|
||||
uint8_t frame[7];
|
||||
frame[0] = data >> 48;
|
||||
frame[1] = instance->generic.btn << 4;
|
||||
frame[2] = instance->generic.cnt >> 8;
|
||||
frame[3] = instance->generic.cnt;
|
||||
frame[4] = instance->generic.serial >> 16;
|
||||
frame[5] = instance->generic.serial >> 8;
|
||||
frame[6] = instance->generic.serial;
|
||||
|
||||
uint8_t checksum = 0;
|
||||
for(uint8_t i = 0; i < 7; i++) {
|
||||
checksum = checksum ^ frame[i] ^ (frame[i] >> 4);
|
||||
}
|
||||
checksum &= 0xF;
|
||||
|
||||
frame[1] |= checksum;
|
||||
|
||||
for(uint8_t i = 1; i < 7; i++) {
|
||||
frame[i] ^= frame[i - 1];
|
||||
}
|
||||
data = 0;
|
||||
for(uint8_t i = 0; i < 7; ++i) {
|
||||
data <<= 8;
|
||||
data |= frame[i];
|
||||
}
|
||||
instance->generic.data = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_somfy_telis_create_data(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
uint32_t serial,
|
||||
uint8_t btn,
|
||||
uint16_t cnt,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSomfyTelis* instance = context;
|
||||
instance->generic.serial = serial;
|
||||
instance->generic.cnt = cnt;
|
||||
instance->generic.data_count_bit = 56;
|
||||
bool res = subghz_protocol_somfy_telis_gen_data(instance, btn);
|
||||
if(res) {
|
||||
res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating an upload from data.
|
||||
* @param instance Pointer to a SubGhzProtocolEncoderKeeloq instance
|
||||
* @return true On success
|
||||
*/
|
||||
static bool subghz_protocol_encoder_somfy_telis_get_upload(
|
||||
SubGhzProtocolEncoderSomfyTelis* instance,
|
||||
uint8_t btn) {
|
||||
furi_assert(instance);
|
||||
|
||||
//gen new key
|
||||
if(subghz_protocol_somfy_telis_gen_data(instance, btn)) {
|
||||
//ToDo if you need to add a callback to automatically update the data on the display
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
//Send header
|
||||
//Wake up
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)9415); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)89565); // 0
|
||||
//Hardware sync
|
||||
for(uint8_t i = 0; i < 2; ++i) {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short * 4); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short * 4); // 0
|
||||
}
|
||||
//Software sync
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)4550); // 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
|
||||
//Send key data MSB manchester
|
||||
|
||||
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data, i - 1)) {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 00
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 1
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 1
|
||||
}
|
||||
|
||||
} else {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_HIGH) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 11
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Inter-frame silence
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration += (uint32_t)30415;
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)30415);
|
||||
}
|
||||
|
||||
//Retransmission
|
||||
for(uint8_t i = 0; i < 2; i++) {
|
||||
//Hardware sync
|
||||
for(uint8_t i = 0; i < 7; ++i) {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short * 4); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short * 4); // 0
|
||||
}
|
||||
//Software sync
|
||||
instance->encoder.upload[index++] = level_duration_make(true, (uint32_t)4550); // 1
|
||||
instance->encoder.upload[index++] =
|
||||
level_duration_make(false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
|
||||
//Send key data MSB manchester
|
||||
|
||||
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
|
||||
if(bit_read(instance->generic.data, i - 1)) {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 00
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 1
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 1
|
||||
}
|
||||
|
||||
} else {
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_HIGH) {
|
||||
instance->encoder.upload[index - 1].duration *= 2; // 11
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
true, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 1
|
||||
instance->encoder.upload[index++] = level_duration_make(
|
||||
false, (uint32_t)subghz_protocol_somfy_telis_const.te_short); // 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Inter-frame silence
|
||||
if(instance->encoder.upload[index - 1].level == LEVEL_DURATION_LEVEL_LOW) {
|
||||
instance->encoder.upload[index - 1].duration += (uint32_t)30415;
|
||||
} else {
|
||||
instance->encoder.upload[index++] = level_duration_make(false, (uint32_t)30415);
|
||||
}
|
||||
}
|
||||
|
||||
size_t size_upload = index;
|
||||
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool subghz_protocol_encoder_somfy_telis_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolEncoderSomfyTelis* instance = context;
|
||||
bool res = false;
|
||||
do {
|
||||
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Deserialize error");
|
||||
break;
|
||||
}
|
||||
|
||||
//optional parameter parameter
|
||||
flipper_format_read_uint32(
|
||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||
|
||||
subghz_protocol_encoder_somfy_telis_get_upload(instance, instance->generic.btn);
|
||||
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
for(size_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF;
|
||||
}
|
||||
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Unable to add Key");
|
||||
break;
|
||||
}
|
||||
|
||||
instance->encoder.is_running = true;
|
||||
|
||||
res = true;
|
||||
} while(false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_protocol_encoder_somfy_telis_stop(void* context) {
|
||||
SubGhzProtocolEncoderSomfyTelis* instance = context;
|
||||
instance->encoder.is_running = false;
|
||||
}
|
||||
|
||||
LevelDuration subghz_protocol_encoder_somfy_telis_yield(void* context) {
|
||||
SubGhzProtocolEncoderSomfyTelis* 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_somfy_telis_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
SubGhzProtocolDecoderSomfyTelis* instance = malloc(sizeof(SubGhzProtocolDecoderSomfyTelis));
|
||||
@@ -299,9 +576,9 @@ static void subghz_protocol_somfy_telis_check_remote_controller(SubGhzBlockGener
|
||||
*/
|
||||
|
||||
uint64_t data = instance->data ^ (instance->data >> 8);
|
||||
instance->btn = (data >> 44) & 0xF;
|
||||
instance->cnt = (data >> 24) & 0xFFFF;
|
||||
instance->serial = data & 0xFFFFFF;
|
||||
instance->btn = (data >> 44) & 0xF; // ctrl
|
||||
instance->cnt = (data >> 24) & 0xFFFF; // rolling code
|
||||
instance->serial = data & 0xFFFFFF; // address
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +586,7 @@ static void subghz_protocol_somfy_telis_check_remote_controller(SubGhzBlockGener
|
||||
* @param btn Button number, 4 bit
|
||||
*/
|
||||
static const char* subghz_protocol_somfy_telis_get_name_button(uint8_t btn) {
|
||||
const char* name_btn[0x10] = {
|
||||
const char* name_btn[16] = {
|
||||
"Unknown",
|
||||
"My",
|
||||
"Up",
|
||||
@@ -368,7 +645,6 @@ void subghz_protocol_decoder_somfy_telis_get_string(void* context, FuriString* o
|
||||
SubGhzProtocolDecoderSomfyTelis* instance = context;
|
||||
|
||||
subghz_protocol_somfy_telis_check_remote_controller(&instance->generic);
|
||||
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s %db\r\n"
|
||||
|
||||
@@ -11,6 +11,58 @@ extern const SubGhzProtocolDecoder subghz_protocol_somfy_telis_decoder;
|
||||
extern const SubGhzProtocolEncoder subghz_protocol_somfy_telis_encoder;
|
||||
extern const SubGhzProtocol subghz_protocol_somfy_telis;
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolEncoderSomfyTelis.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
* @return SubGhzProtocolEncoderSomfyTelis* pointer to a SubGhzProtocolEncoderSomfyTelis instance
|
||||
*/
|
||||
void* subghz_protocol_encoder_somfy_telis_alloc(SubGhzEnvironment* environment);
|
||||
|
||||
/**
|
||||
* Free SubGhzProtocolEncoderSomfyTelis.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
|
||||
*/
|
||||
void subghz_protocol_encoder_somfy_telis_free(void* context);
|
||||
|
||||
/**
|
||||
* Key generation from simple data.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param serial Serial number, 24 bit
|
||||
* @param btn Button number, 8 bit
|
||||
* @param cnt Counter value, 16 bit
|
||||
* @param preset Modulation, SubGhzRadioPreset
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_somfy_telis_create_data(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
uint32_t serial,
|
||||
uint8_t btn,
|
||||
uint16_t cnt,
|
||||
SubGhzRadioPreset* preset);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @return true On success
|
||||
*/
|
||||
bool subghz_protocol_encoder_somfy_telis_deserialize(void* context, FlipperFormat* flipper_format);
|
||||
|
||||
/**
|
||||
* Forced transmission stop.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
|
||||
*/
|
||||
void subghz_protocol_encoder_somfy_telis_stop(void* context);
|
||||
|
||||
/**
|
||||
* Getting the level and duration of the upload to be loaded into DMA.
|
||||
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
|
||||
* @return LevelDuration
|
||||
*/
|
||||
LevelDuration subghz_protocol_encoder_somfy_telis_yield(void* context);
|
||||
|
||||
/**
|
||||
* Allocate SubGhzProtocolDecoderSomfyTelis.
|
||||
* @param environment Pointer to a SubGhzEnvironment instance
|
||||
|
||||
@@ -39,6 +39,7 @@ static const uint32_t subghz_frequency_list[] = {
|
||||
330000000,
|
||||
345000000,
|
||||
348000000,
|
||||
350000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
387000000,
|
||||
@@ -75,10 +76,10 @@ static const uint32_t subghz_frequency_list[] = {
|
||||
};
|
||||
|
||||
static const uint32_t subghz_hopper_frequency_list[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
330000000,
|
||||
390000000,
|
||||
433420000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
|
||||
@@ -70,7 +70,7 @@ bool subghz_tx_rx_worker_rx(SubGhzTxRxWorker* instance, uint8_t* data, uint8_t*
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
//waiting for reception to complete
|
||||
while(furi_hal_gpio_read(&gpio_cc1101_g0)) {
|
||||
while(furi_hal_gpio_read(furi_hal_subghz.cc1101_g0_pin)) {
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "RX cc1101_g0 timeout");
|
||||
@@ -104,14 +104,16 @@ void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t si
|
||||
furi_hal_subghz_write_packet(data, size);
|
||||
furi_hal_subghz_tx(); //start send
|
||||
instance->status = SubGhzTxRxWorkerStatusTx;
|
||||
while(!furi_hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be set -> sync transmitted
|
||||
while(!furi_hal_gpio_read(
|
||||
furi_hal_subghz.cc1101_g0_pin)) { // Wait for GDO0 to be set -> sync transmitted
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "TX !cc1101_g0 timeout");
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(furi_hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be cleared -> end of packet
|
||||
while(furi_hal_gpio_read(
|
||||
furi_hal_subghz.cc1101_g0_pin)) { // Wait for GDO0 to be cleared -> end of packet
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "TX cc1101_g0 timeout");
|
||||
@@ -134,7 +136,7 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetGFSK9_99KbAsync);
|
||||
//furi_hal_subghz_load_preset(FuriHalSubGhzPresetMSK99_97KbAsync);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
furi_hal_subghz_set_frequency_and_path(instance->frequency);
|
||||
furi_hal_subghz_flush_rx();
|
||||
|
||||
@@ -90,6 +90,7 @@ typedef enum {
|
||||
SubGhzProtocolFlag_Save = (1 << 7),
|
||||
SubGhzProtocolFlag_Load = (1 << 8),
|
||||
SubGhzProtocolFlag_Send = (1 << 9),
|
||||
SubGhzProtocolFlag_BinRAW = (1 << 10),
|
||||
} SubGhzProtocolFlag;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user