Updating OFW

This commit is contained in:
VerstreuteSeele
2022-12-20 20:35:25 +01:00
parent 270aa4059c
commit 60cb4a971e
26 changed files with 975 additions and 116 deletions
+9 -25
View File
@@ -8,6 +8,8 @@
#define TAG "SubGhzProtocolHormannHSM"
#define HORMANN_HSM_PATTERN 0xFF000000003
static const SubGhzBlockConst subghz_protocol_hormann_const = {
.te_short = 500,
.te_long = 1000,
@@ -101,20 +103,13 @@ static bool subghz_protocol_encoder_hormann_get_upload(SubGhzProtocolEncoderHorm
furi_assert(instance);
size_t index = 0;
size_t size_upload = 3 + (instance->generic.data_count_bit * 2 + 2) * 20 + 1;
size_t size_upload = (instance->generic.data_count_bit * 2 + 2) * 20 + 1;
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
instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)subghz_protocol_hormann_const.te_short * 64);
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_hormann_const.te_short * 64);
instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)subghz_protocol_hormann_const.te_short * 64);
instance->encoder.repeat = 10; //original remote does 10 repeats
for(size_t repeat = 0; repeat < 20; repeat++) {
@@ -209,6 +204,10 @@ void subghz_protocol_decoder_hormann_free(void* context) {
free(instance);
}
static bool subghz_protocol_decoder_hormann_check_pattern(SubGhzProtocolDecoderHormann* instance) {
return (instance->decoder.decode_data & HORMANN_HSM_PATTERN) == HORMANN_HSM_PATTERN;
}
void subghz_protocol_decoder_hormann_reset(void* context) {
furi_assert(context);
SubGhzProtocolDecoderHormann* instance = context;
@@ -221,25 +220,9 @@ void subghz_protocol_decoder_hormann_feed(void* context, bool level, uint32_t du
switch(instance->decoder.parser_step) {
case HormannDecoderStepReset:
if((level) && (DURATION_DIFF(duration, subghz_protocol_hormann_const.te_short * 64) <
subghz_protocol_hormann_const.te_delta * 64)) {
instance->decoder.parser_step = HormannDecoderStepFoundStartHeader;
}
break;
case HormannDecoderStepFoundStartHeader:
if((!level) && (DURATION_DIFF(duration, subghz_protocol_hormann_const.te_short * 64) <
subghz_protocol_hormann_const.te_delta * 64)) {
instance->decoder.parser_step = HormannDecoderStepFoundHeader;
} else {
instance->decoder.parser_step = HormannDecoderStepReset;
}
break;
case HormannDecoderStepFoundHeader:
if((level) && (DURATION_DIFF(duration, subghz_protocol_hormann_const.te_short * 24) <
subghz_protocol_hormann_const.te_delta * 24)) {
instance->decoder.parser_step = HormannDecoderStepFoundStartBit;
} else {
instance->decoder.parser_step = HormannDecoderStepReset;
}
break;
case HormannDecoderStepFoundStartBit:
@@ -254,7 +237,8 @@ void subghz_protocol_decoder_hormann_feed(void* context, bool level, uint32_t du
break;
case HormannDecoderStepSaveDuration:
if(level) { //save interval
if(duration >= (subghz_protocol_hormann_const.te_short * 5)) {
if(duration >= (subghz_protocol_hormann_const.te_short * 5) &&
subghz_protocol_decoder_hormann_check_pattern(instance)) {
instance->decoder.parser_step = HormannDecoderStepFoundStartBit;
if(instance->decoder.decode_count_bit >=
subghz_protocol_hormann_const.min_count_bit_for_found) {
+51
View File
@@ -125,3 +125,54 @@ bool saved_struct_load(const char* path, void* data, size_t size, uint8_t magic,
return result;
}
bool saved_struct_get_payload_size(
const char* path,
uint8_t magic,
uint8_t version,
size_t* payload_size) {
furi_assert(path);
furi_assert(payload_size);
SavedStructHeader header;
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
bool result = false;
do {
if(!storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) {
FURI_LOG_E(
TAG, "Failed to read \"%s\". Error: %s", path, storage_file_get_error_desc(file));
break;
}
uint16_t bytes_count = storage_file_read(file, &header, sizeof(SavedStructHeader));
if(bytes_count != sizeof(SavedStructHeader)) {
FURI_LOG_E(TAG, "Failed to read header");
break;
}
if((header.magic != magic) || (header.version != version)) {
FURI_LOG_E(
TAG,
"Magic(%d != %d) or Version(%d != %d) mismatch of file \"%s\"",
header.magic,
magic,
header.version,
version,
path);
break;
}
uint64_t file_size = storage_file_size(file);
*payload_size = file_size - sizeof(SavedStructHeader);
result = true;
} while(false);
storage_file_close(file);
storage_file_free(file);
furi_record_close(RECORD_STORAGE);
return result;
}
+6
View File
@@ -12,6 +12,12 @@ bool saved_struct_load(const char* path, void* data, size_t size, uint8_t magic,
bool saved_struct_save(const char* path, void* data, size_t size, uint8_t magic, uint8_t version);
bool saved_struct_get_payload_size(
const char* path,
uint8_t magic,
uint8_t version,
size_t* payload_size);
#ifdef __cplusplus
}
#endif