1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

finish subghz fixes

This commit is contained in:
MX
2025-12-10 23:56:22 +03:00
parent d10a601109
commit caad1ef268
3 changed files with 121 additions and 62 deletions

View File

@@ -218,15 +218,60 @@ static bool subghz_protocol_secplus_v1_encode(SubGhzProtocolEncoderSecPlus_v1* i
uint32_t acc = 0;
//increment the counter
rolling += 2;
//rolling += 2; - old way
// Experemental case - we dont know counter size exactly, so just will be think that it is in range of 0xE6000000 - 0xFFFFFFFF
// one case when we have mult = 0xFFFFFFFF - its when we reset counter before applying new cnt value
// so at first step we reset cnt to 0 and now we sure here will be second step (set new cnt value);
// at second step check what user set for new Cnt (and correct it if cnt less than 0xE6000000 or more than 0xFFFFFFFF)
int32_t multicntr = (furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF);
// Adjust for negative multiplier
if(furi_hal_subghz_get_rolling_counter_mult() < 0) {
multicntr = furi_hal_subghz_get_rolling_counter_mult();
}
if(multicntr == 1) {
multicntr = 2; // to keep old behaviour when mult = 1
}
// Check for OFEX (overflow experimental) mode
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
if((furi_hal_subghz_get_rolling_counter_mult() == (int32_t)0xFFFFFFF) & (rolling != 0)) {
rolling = 0;
} else {
// if cnt was reset to 0 on previous step and user want new Cnt then set it to 0xE6000000 or 0xFFFFFFFF or new user value
if(rolling == 0) {
if((furi_hal_subghz_get_rolling_counter_mult()) < (int32_t)0x6000000) {
rolling = 0xE6000000;
} else {
if((furi_hal_subghz_get_rolling_counter_mult()) >= (int32_t)0xFFFFFFF) {
rolling = 0xFFFFFFFF;
} else {
rolling = 0xE0000000;
rolling += multicntr;
}
}
} else {
// if we have not special cases - so work as standart mode
if((rolling + multicntr) > 0xFFFFFFFF) {
rolling = 0xE6000000;
} else {
rolling += multicntr;
}
}
}
} else {
// OFEX (overflow experimental) mode
if((rolling + 0x1) > 0xFFFFFFFF) {
rolling = 0xE6000000;
} else if(rolling >= 0xE6000000 && rolling != 0xFFFFFFFE) {
rolling = 0xFFFFFFFE;
} else {
rolling++;
}
}
//update data
instance->generic.data &= 0xFFFFFFFF00000000;
instance->generic.data |= rolling;
if(rolling == 0xFFFFFFFF) {
rolling = 0xE6000000;
}
if(fixed > 0xCFD41B90) {
FURI_LOG_E(TAG, "Encode wrong fixed data");
return false;
@@ -597,11 +642,10 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou
furi_string_cat_printf(output, "\r\n");
}
// use 'Cntr:' instead of 'Cnt:' to exclude this protocol counter from Counter edit
furi_string_cat_printf(
output,
"Sn:0x%08lX\r\n"
"Cntr:%03lX "
"Cnt:%08lX "
"SwID:0x%X\r\n",
instance->generic.serial,
instance->generic.cnt,
@@ -620,7 +664,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou
furi_string_cat_printf(
output,
"Sn:0x%08lX\r\n"
"Cntr:%03lX "
"Cnt:%08lX "
"SwID:0x%X\r\n",
instance->generic.serial,
instance->generic.cnt,

View File

@@ -402,34 +402,48 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i
uint8_t roll_2[9] = {0};
// Experemental case - we dont know counter size exactly, so just will be think that it is in range of 0xE500000 - 0xFFFFFFF
// one case when we have mult = 0xFFFFFFFF - its when we reset counter before aplaying new cnt value
// one case when we have mult = 0xFFFFFFFF - its when we reset counter before applying new cnt value
// so at first step we reset cnt to 0 and now we sure here will be second step (set new cnt value);
// at second step check what user set for new Cnt (and correct it if cnt less than 0xE500000 or more than 0xFFFFFFF)
if(((int32_t)furi_hal_subghz_get_rolling_counter_mult() == (int32_t)0xFFFFFFFF) &
(instance->generic.cnt != 0)) {
instance->generic.cnt = 0;
} else {
// if cnt was reset to 0 on previous step and user want new Cnt then set it to 0xE500000 or 0xFFFFFFF or new user value
if(instance->generic.cnt == 0) {
if((uint32_t)furi_hal_subghz_get_rolling_counter_mult() < (uint32_t)0xE500000) {
instance->generic.cnt = 0xE500000;
} else {
if((uint32_t)furi_hal_subghz_get_rolling_counter_mult() > (uint32_t)0xFFFFFFF) {
instance->generic.cnt = 0xFFFFFFF;
int32_t multicntr = (furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF);
// Adjust for negative multiplier
if(furi_hal_subghz_get_rolling_counter_mult() < 0) {
multicntr = furi_hal_subghz_get_rolling_counter_mult();
}
// Check for OFEX (overflow experimental) mode
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
if((furi_hal_subghz_get_rolling_counter_mult() == (int32_t)0xFFFFFFF) &
(instance->generic.cnt != 0)) {
instance->generic.cnt = 0;
} else {
// if cnt was reset to 0 on previous step and user want new Cnt then set it to 0xE500000 or 0xFFFFFFF or new user value
if(instance->generic.cnt == 0) {
if(furi_hal_subghz_get_rolling_counter_mult() < (int32_t)0xE500000) {
instance->generic.cnt = 0xE500000;
} else {
instance->generic.cnt +=
((furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF));
if(furi_hal_subghz_get_rolling_counter_mult() >= (int32_t)0xFFFFFFF) {
instance->generic.cnt = 0xFFFFFFF;
} else {
instance->generic.cnt += multicntr;
}
}
} else {
// if we have not special cases - so work as standart mode
if((instance->generic.cnt + multicntr) > 0xFFFFFFF) {
instance->generic.cnt = 0xE500000;
} else {
instance->generic.cnt += multicntr;
}
}
}
} else {
// OFEX (overflow experimental) mode
if((instance->generic.cnt + 0x1) > 0xFFFFFFF) {
instance->generic.cnt = 0xE500000;
} else if(instance->generic.cnt >= 0xE500000 && instance->generic.cnt != 0xFFFFFFE) {
instance->generic.cnt = 0xFFFFFFE;
} else {
// if we have not special cases - so work as standart mode
if((instance->generic.cnt + (furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF)) >
0xFFFFFFF) {
instance->generic.cnt = 0xE500000;
} else {
instance->generic.cnt +=
((furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF));
}
instance->generic.cnt++;
}
}