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:
@@ -149,7 +149,7 @@ void subghz_scene_signal_settings_on_enter(void* context) {
|
|||||||
|
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||||
FuriString* tmp_string = furi_string_alloc();
|
FuriString* tmp_text = furi_string_alloc_set_str("");
|
||||||
|
|
||||||
uint32_t tmp_counter_mode = 0;
|
uint32_t tmp_counter_mode = 0;
|
||||||
counter_mode = 0xff;
|
counter_mode = 0xff;
|
||||||
@@ -161,10 +161,10 @@ void subghz_scene_signal_settings_on_enter(void* context) {
|
|||||||
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
|
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
|
||||||
FURI_LOG_E(TAG, "Error open file %s", file_path);
|
FURI_LOG_E(TAG, "Error open file %s", file_path);
|
||||||
} else {
|
} else {
|
||||||
flipper_format_read_string(fff_data_file, "Protocol", tmp_string);
|
flipper_format_read_string(fff_data_file, "Protocol", tmp_text);
|
||||||
// compare available protocols names, load CounterMode value from file and setup variable_item_list values_count
|
// compare available protocols names, load CounterMode value from file and setup variable_item_list values_count
|
||||||
for(uint8_t i = 0; i < PROTOCOLS_COUNT i++) {
|
for(uint8_t i = 0; i < PROTOCOLS_COUNT i++) {
|
||||||
if(!strcmp(furi_string_get_cstr(tmp_string), protocols[i].name)) {
|
if(!strcmp(furi_string_get_cstr(tmp_text), protocols[i].name)) {
|
||||||
mode_count = protocols[i].mode_count;
|
mode_count = protocols[i].mode_count;
|
||||||
if(flipper_format_read_uint32(fff_data_file, "CounterMode", &tmp_counter_mode, 1)) {
|
if(flipper_format_read_uint32(fff_data_file, "CounterMode", &tmp_counter_mode, 1)) {
|
||||||
counter_mode = (uint8_t)tmp_counter_mode;
|
counter_mode = (uint8_t)tmp_counter_mode;
|
||||||
@@ -176,40 +176,14 @@ void subghz_scene_signal_settings_on_enter(void* context) {
|
|||||||
}
|
}
|
||||||
FURI_LOG_D(TAG, "Current CounterMode value %li", counter_mode);
|
FURI_LOG_D(TAG, "Current CounterMode value %li", counter_mode);
|
||||||
|
|
||||||
furi_string_free(tmp_string);
|
|
||||||
flipper_format_file_close(fff_data_file);
|
flipper_format_file_close(fff_data_file);
|
||||||
flipper_format_free(fff_data_file);
|
flipper_format_free(fff_data_file);
|
||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
|
||||||
//Create and Enable/Disable variable_item_list depent from current CounterMode value
|
|
||||||
VariableItemList* variable_item_list = subghz->variable_item_list;
|
|
||||||
int32_t value_index;
|
|
||||||
VariableItem* item;
|
|
||||||
|
|
||||||
variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
|
||||||
variable_item_list_reset(subghz->variable_item_list);
|
|
||||||
|
|
||||||
variable_item_list_set_enter_callback(
|
|
||||||
variable_item_list,
|
|
||||||
subghz_scene_signal_settings_variable_item_list_enter_callback,
|
|
||||||
subghz);
|
|
||||||
|
|
||||||
item = variable_item_list_add(
|
|
||||||
variable_item_list,
|
|
||||||
"Counter Mode",
|
|
||||||
mode_count,
|
|
||||||
subghz_scene_signal_settings_counter_mode_changed,
|
|
||||||
subghz);
|
|
||||||
value_index = value_index_int32(counter_mode, counter_mode_value, mode_count);
|
|
||||||
|
|
||||||
variable_item_set_current_value_index(item, value_index);
|
|
||||||
variable_item_set_current_value_text(item, counter_mode_text[value_index]);
|
|
||||||
variable_item_set_locked(item, (counter_mode == 0xff), "Not available\nfor this\nprotocol !");
|
|
||||||
|
|
||||||
// ### Counter edit section ###
|
// ### Counter edit section ###
|
||||||
FuriString* tmp_text = furi_string_alloc_set_str("");
|
|
||||||
FuriString* textCnt = furi_string_alloc_set_str("");
|
FuriString* textCnt = furi_string_alloc_set_str("");
|
||||||
byte_input_text = furi_string_alloc_set_str("Enter ");
|
byte_input_text = furi_string_alloc_set_str("Enter ");
|
||||||
|
furi_string_reset(tmp_text);
|
||||||
|
|
||||||
bool counter_not_available = true;
|
bool counter_not_available = true;
|
||||||
SubGhzProtocolDecoderBase* decoder = subghz_txrx_get_decoder(subghz->txrx);
|
SubGhzProtocolDecoderBase* decoder = subghz_txrx_get_decoder(subghz->txrx);
|
||||||
@@ -228,7 +202,9 @@ void subghz_scene_signal_settings_on_enter(void* context) {
|
|||||||
|
|
||||||
int8_t place = furi_string_search_str(tmp_text, "Cnt:??", 0);
|
int8_t place = furi_string_search_str(tmp_text, "Cnt:??", 0);
|
||||||
if(place > 0) {
|
if(place > 0) {
|
||||||
FURI_LOG_D(TAG, "Founded Cnt:???? - counter not available for this protocol");
|
counter_mode = 0xff;
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG, "Founded Cnt:???? - Counter mode and edit not available for this protocol");
|
||||||
} else {
|
} else {
|
||||||
place = furi_string_search_str(tmp_text, "Cnt:", 0);
|
place = furi_string_search_str(tmp_text, "Cnt:", 0);
|
||||||
if(place > 0) {
|
if(place > 0) {
|
||||||
@@ -292,6 +268,31 @@ void subghz_scene_signal_settings_on_enter(void* context) {
|
|||||||
furi_assert(byte_ptr);
|
furi_assert(byte_ptr);
|
||||||
furi_assert(byte_count > 0);
|
furi_assert(byte_count > 0);
|
||||||
|
|
||||||
|
//Create and Enable/Disable variable_item_list depent from current values
|
||||||
|
VariableItemList* variable_item_list = subghz->variable_item_list;
|
||||||
|
int32_t value_index;
|
||||||
|
VariableItem* item;
|
||||||
|
|
||||||
|
// variable_item_list_set_selected_item(subghz->variable_item_list, 0);
|
||||||
|
// variable_item_list_reset(subghz->variable_item_list);
|
||||||
|
|
||||||
|
variable_item_list_set_enter_callback(
|
||||||
|
variable_item_list,
|
||||||
|
subghz_scene_signal_settings_variable_item_list_enter_callback,
|
||||||
|
subghz);
|
||||||
|
|
||||||
|
item = variable_item_list_add(
|
||||||
|
variable_item_list,
|
||||||
|
"Counter Mode",
|
||||||
|
mode_count,
|
||||||
|
subghz_scene_signal_settings_counter_mode_changed,
|
||||||
|
subghz);
|
||||||
|
value_index = value_index_int32(counter_mode, counter_mode_value, mode_count);
|
||||||
|
|
||||||
|
variable_item_set_current_value_index(item, value_index);
|
||||||
|
variable_item_set_current_value_text(item, counter_mode_text[value_index]);
|
||||||
|
variable_item_set_locked(item, (counter_mode == 0xff), "Not available\nfor this\nprotocol !");
|
||||||
|
|
||||||
item = variable_item_list_add(variable_item_list, "Edit Counter", 1, NULL, subghz);
|
item = variable_item_list_add(variable_item_list, "Edit Counter", 1, NULL, subghz);
|
||||||
variable_item_set_current_value_index(item, 0);
|
variable_item_set_current_value_index(item, 0);
|
||||||
variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_text));
|
variable_item_set_current_value_text(item, furi_string_get_cstr(tmp_text));
|
||||||
@@ -346,7 +347,7 @@ bool subghz_scene_signal_settings_on_event(void* context, SceneManagerEvent even
|
|||||||
// the same for 32 bit Counter
|
// the same for 32 bit Counter
|
||||||
tmp_counter = furi_hal_subghz_get_rolling_counter_mult();
|
tmp_counter = furi_hal_subghz_get_rolling_counter_mult();
|
||||||
|
|
||||||
furi_hal_subghz_set_rolling_counter_mult(0xFFFFFFFF);
|
furi_hal_subghz_set_rolling_counter_mult(0xFFFFFFF);
|
||||||
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
|
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
|
||||||
subghz_txrx_stop(subghz->txrx);
|
subghz_txrx_stop(subghz->txrx);
|
||||||
|
|
||||||
@@ -358,7 +359,7 @@ bool subghz_scene_signal_settings_on_event(void* context, SceneManagerEvent even
|
|||||||
|
|
||||||
counter32 = __bswap32(counter32);
|
counter32 = __bswap32(counter32);
|
||||||
|
|
||||||
furi_hal_subghz_set_rolling_counter_mult(counter32);
|
furi_hal_subghz_set_rolling_counter_mult((counter32 & 0xFFFFFFF));
|
||||||
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
|
subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx));
|
||||||
subghz_txrx_stop(subghz->txrx);
|
subghz_txrx_stop(subghz->txrx);
|
||||||
|
|
||||||
|
|||||||
@@ -218,15 +218,60 @@ static bool subghz_protocol_secplus_v1_encode(SubGhzProtocolEncoderSecPlus_v1* i
|
|||||||
uint32_t acc = 0;
|
uint32_t acc = 0;
|
||||||
|
|
||||||
//increment the counter
|
//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
|
//update data
|
||||||
instance->generic.data &= 0xFFFFFFFF00000000;
|
instance->generic.data &= 0xFFFFFFFF00000000;
|
||||||
instance->generic.data |= rolling;
|
instance->generic.data |= rolling;
|
||||||
|
|
||||||
if(rolling == 0xFFFFFFFF) {
|
|
||||||
rolling = 0xE6000000;
|
|
||||||
}
|
|
||||||
if(fixed > 0xCFD41B90) {
|
if(fixed > 0xCFD41B90) {
|
||||||
FURI_LOG_E(TAG, "Encode wrong fixed data");
|
FURI_LOG_E(TAG, "Encode wrong fixed data");
|
||||||
return false;
|
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");
|
furi_string_cat_printf(output, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// use 'Cntr:' instead of 'Cnt:' to exclude this protocol counter from Counter edit
|
|
||||||
furi_string_cat_printf(
|
furi_string_cat_printf(
|
||||||
output,
|
output,
|
||||||
"Sn:0x%08lX\r\n"
|
"Sn:0x%08lX\r\n"
|
||||||
"Cntr:%03lX "
|
"Cnt:%08lX "
|
||||||
"SwID:0x%X\r\n",
|
"SwID:0x%X\r\n",
|
||||||
instance->generic.serial,
|
instance->generic.serial,
|
||||||
instance->generic.cnt,
|
instance->generic.cnt,
|
||||||
@@ -620,7 +664,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou
|
|||||||
furi_string_cat_printf(
|
furi_string_cat_printf(
|
||||||
output,
|
output,
|
||||||
"Sn:0x%08lX\r\n"
|
"Sn:0x%08lX\r\n"
|
||||||
"Cntr:%03lX "
|
"Cnt:%08lX "
|
||||||
"SwID:0x%X\r\n",
|
"SwID:0x%X\r\n",
|
||||||
instance->generic.serial,
|
instance->generic.serial,
|
||||||
instance->generic.cnt,
|
instance->generic.cnt,
|
||||||
|
|||||||
@@ -402,36 +402,50 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i
|
|||||||
uint8_t roll_2[9] = {0};
|
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
|
// 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);
|
// 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)
|
// 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) &
|
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)) {
|
||||||
instance->generic.cnt = 0;
|
instance->generic.cnt = 0;
|
||||||
} else {
|
} 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 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(instance->generic.cnt == 0) {
|
||||||
if((uint32_t)furi_hal_subghz_get_rolling_counter_mult() < (uint32_t)0xE500000) {
|
if(furi_hal_subghz_get_rolling_counter_mult() < (int32_t)0xE500000) {
|
||||||
instance->generic.cnt = 0xE500000;
|
instance->generic.cnt = 0xE500000;
|
||||||
} else {
|
} else {
|
||||||
if((uint32_t)furi_hal_subghz_get_rolling_counter_mult() > (uint32_t)0xFFFFFFF) {
|
if(furi_hal_subghz_get_rolling_counter_mult() >= (int32_t)0xFFFFFFF) {
|
||||||
instance->generic.cnt = 0xFFFFFFF;
|
instance->generic.cnt = 0xFFFFFFF;
|
||||||
} else {
|
} else {
|
||||||
instance->generic.cnt +=
|
instance->generic.cnt += multicntr;
|
||||||
((furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if we have not special cases - so work as standart mode
|
// if we have not special cases - so work as standart mode
|
||||||
if((instance->generic.cnt + (furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF)) >
|
if((instance->generic.cnt + multicntr) > 0xFFFFFFF) {
|
||||||
0xFFFFFFF) {
|
|
||||||
instance->generic.cnt = 0xE500000;
|
instance->generic.cnt = 0xE500000;
|
||||||
} else {
|
} else {
|
||||||
instance->generic.cnt +=
|
instance->generic.cnt += multicntr;
|
||||||
((furi_hal_subghz_get_rolling_counter_mult() & 0xFFFFFFF));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} 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 {
|
||||||
|
instance->generic.cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t rolling = subghz_protocol_blocks_reverse_key(instance->generic.cnt, 28);
|
uint32_t rolling = subghz_protocol_blocks_reverse_key(instance->generic.cnt, 28);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user