Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Jun 3, 2022
2 parents 287defd + 8b54436 commit be4dec7
Show file tree
Hide file tree
Showing 24 changed files with 946 additions and 280 deletions.
9 changes: 5 additions & 4 deletions applications/ibutton/ibutton.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,12 @@ bool ibutton_save_key(iButton* ibutton, const char* key_name) {
bool result = false;

do {
// First remove key if it was saved (we rename the key)
ibutton_delete_key(ibutton);

// Set full file name, for new key
// Check if we has old key
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
// First remove old key
ibutton_delete_key(ibutton);

// Remove old key name from path
size_t filename_start = string_search_rchar(ibutton->file_path, '/');
string_left(ibutton->file_path, filename_start);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void LfRfidAppSceneReadSuccess::on_enter(LfRfidApp* app, bool /* need_restore */
case LfrfidKeyType::KeyIoProxXSF:
line_1_text->set_text("HEX:", 65, 23, 0, AlignRight, AlignBottom, FontSecondary);
line_2l_text->set_text("FC:", 65, 35, 0, AlignRight, AlignBottom, FontSecondary);
line_2r_text->set_text("V:", 95, 35, 0, AlignRight, AlignBottom, FontSecondary);
line_2r_text->set_text(":", 95, 35, 0, AlignRight, AlignBottom, FontSecondary);
line_3_text->set_text("Card:", 65, 47, 0, AlignRight, AlignBottom, FontSecondary);

for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
Expand Down
13 changes: 0 additions & 13 deletions applications/lfrfid/scene/lfrfid_app_scene_save_data.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
#include "lfrfid_app_scene_save_data.h"
#include <dolphin/dolphin.h>

static void print_buffer(const uint8_t* buffer) {
for(uint8_t i = 0; i < LFRFID_KEY_SIZE; i++) {
printf("%02X", buffer[i]);
}
}

void LfRfidAppSceneSaveData::on_enter(LfRfidApp* app, bool need_restore) {
auto byte_input = app->view_controller.get<ByteInputVM>();
RfidKey& key = app->worker.key;

printf("k: ");
print_buffer(key.get_data());
printf(" o: ");
print_buffer(old_key_data);
printf(" n: ");
print_buffer(new_key_data);
printf("\r\n");
if(need_restore) printf("restored\r\n");

if(need_restore) {
Expand Down
20 changes: 20 additions & 0 deletions applications/subghz/helpers/subghz_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ typedef enum {
SubGhzCustomEventManagerSet,
SubGhzCustomEventManagerSetRAW,

//SubmenuIndex
SubmenuIndexPricenton,
SubmenuIndexNiceFlo12bit,
SubmenuIndexNiceFlo24bit,
SubmenuIndexCAME12bit,
SubmenuIndexCAME24bit,
SubmenuIndexCAMETwee,
SubmenuIndexNeroSketch,
SubmenuIndexNeroRadio,
SubmenuIndexGateTX,
SubmenuIndexDoorHan_315_00,
SubmenuIndexDoorHan_433_92,
SubmenuIndexLinear_300_00,
SubmenuIndexLiftMaster_315_00,
SubmenuIndexLiftMaster_390_00,
SubmenuIndexSecPlus_v2_310_00,
SubmenuIndexSecPlus_v2_315_00,
SubmenuIndexSecPlus_v2_390_00,

//SubGhzCustomEvent
SubGhzCustomEventSceneDeleteSuccess = 100,
SubGhzCustomEventSceneDelete,
SubGhzCustomEventSceneDeleteRAW,
Expand Down
10 changes: 8 additions & 2 deletions applications/subghz/scenes/subghz_scene_delete_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ bool subghz_scene_delete_success_on_event(void* context, SceneManagerEvent event

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventSceneDeleteSuccess) {
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) {
if(scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneReadRAW)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
} else if(scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
} else {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
return true;
}
Expand Down
12 changes: 7 additions & 5 deletions applications/subghz/scenes/subghz_scene_read_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
break;

case SubGhzCustomEventViewReadRAWErase:
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
if(subghz_scene_read_raw_update_filename(subghz)) {
string_set(subghz->file_path_tmp, subghz->file_path);
subghz_delete_file(subghz);
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) {
if(subghz_scene_read_raw_update_filename(subghz)) {
string_set(subghz->file_path_tmp, subghz->file_path);
subghz_delete_file(subghz);
}
}
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
notification_message(subghz->notifications, &sequence_reset_rgb);
return true;
break;
Expand All @@ -184,7 +186,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW);
return true;
} else {
furi_crash("SugGhz: RAW file name update error.");
furi_crash("SubGhz: RAW file name update error.");
}
break;

Expand Down
28 changes: 4 additions & 24 deletions applications/subghz/scenes/subghz_scene_set_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@

#define TAG "SubGhzSetType"

enum SubmenuIndex {
SubmenuIndexPricenton,
SubmenuIndexNiceFlo12bit,
SubmenuIndexNiceFlo24bit,
SubmenuIndexCAME12bit,
SubmenuIndexCAME24bit,
SubmenuIndexCAMETwee,
SubmenuIndexNeroSketch,
SubmenuIndexNeroRadio,
SubmenuIndexGateTX,
SubmenuIndexDoorHan_315_00,
SubmenuIndexDoorHan_433_92,
SubmenuIndexFirefly_300_00,
SubmenuIndexLiftMaster_315_00,
SubmenuIndexLiftMaster_390_00,
SubmenuIndexSecPlus_v2_310_00,
SubmenuIndexSecPlus_v2_315_00,
SubmenuIndexSecPlus_v2_390_00,
};

bool subghz_scene_set_type_submenu_gen_data_protocol(
void* context,
const char* protocol_name,
Expand Down Expand Up @@ -117,8 +97,8 @@ void subghz_scene_set_type_on_enter(void* context) {
subghz);
submenu_add_item(
subghz->submenu,
"Firefly_300",
SubmenuIndexFirefly_300_00,
"Linear_300",
SubmenuIndexLinear_300_00,
subghz_scene_set_type_submenu_callback,
subghz);
submenu_add_item(
Expand Down Expand Up @@ -256,11 +236,11 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
generated_protocol = true;
}
break;
case SubmenuIndexFirefly_300_00:
case SubmenuIndexLinear_300_00:
key = (key & 0x3FF);
if(subghz_scene_set_type_submenu_gen_data_protocol(
subghz,
SUBGHZ_PROTOCOL_FIREFLY_NAME,
SUBGHZ_PROTOCOL_LINEAR_NAME,
key,
10,
300000000,
Expand Down
6 changes: 3 additions & 3 deletions applications/subghz/subghz_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
string_set_str(modulation, "FM");
} else {
furi_crash("SugGhz: Modulation is incorrect.");
furi_crash("SubGhz: Modulation is incorrect.");
}
}
}
Expand All @@ -71,7 +71,7 @@ void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset) {
uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) {
furi_assert(subghz);
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
furi_crash("SugGhz: Incorrect RX frequency.");
furi_crash("SubGhz: Incorrect RX frequency.");
}
furi_assert(
subghz->txrx->txrx_state != SubGhzTxRxStateRx &&
Expand All @@ -92,7 +92,7 @@ uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) {
static bool subghz_tx(SubGhz* subghz, uint32_t frequency) {
furi_assert(subghz);
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
furi_crash("SugGhz: Incorrect TX frequency.");
furi_crash("SubGhz: Incorrect TX frequency.");
}
furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
furi_hal_subghz_idle();
Expand Down
16 changes: 8 additions & 8 deletions applications/unit_tests/subghz/subghz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ MU_TEST(subghz_decoder_star_line_test) {
"Test decoder " SUBGHZ_PROTOCOL_STAR_LINE_NAME " error\r\n");
}

MU_TEST(subghz_decoder_firefly_test) {
MU_TEST(subghz_decoder_linear_test) {
mu_assert(
subghz_decoder_test("/ext/unit_tests/subghz/firefly_raw.sub", SUBGHZ_PROTOCOL_FIREFLY_NAME),
"Test decoder " SUBGHZ_PROTOCOL_FIREFLY_NAME " error\r\n");
subghz_decoder_test("/ext/unit_tests/subghz/linear_raw.sub", SUBGHZ_PROTOCOL_LINEAR_NAME),
"Test decoder " SUBGHZ_PROTOCOL_LINEAR_NAME " error\r\n");
}

MU_TEST(subghz_decoder_megacode_test) {
Expand Down Expand Up @@ -398,10 +398,10 @@ MU_TEST(subghz_encoder_keelog_test) {
"Test encoder " SUBGHZ_PROTOCOL_KEELOQ_NAME " error\r\n");
}

MU_TEST(subghz_encoder_firefly_test) {
MU_TEST(subghz_encoder_linear_test) {
mu_assert(
subghz_encoder_test("/ext/unit_tests/subghz/firely.sub"),
"Test encoder " SUBGHZ_PROTOCOL_FIREFLY_NAME " error\r\n");
subghz_encoder_test("/ext/unit_tests/subghz/linear.sub"),
"Test encoder " SUBGHZ_PROTOCOL_LINEAR_NAME " error\r\n");
}

MU_TEST(subghz_encoder_megacode_test) {
Expand Down Expand Up @@ -454,7 +454,7 @@ MU_TEST_SUITE(subghz) {
MU_RUN_TEST(subghz_decoder_somfy_keytis_test);
MU_RUN_TEST(subghz_decoder_somfy_telis_test);
MU_RUN_TEST(subghz_decoder_star_line_test);
MU_RUN_TEST(subghz_decoder_firefly_test);
MU_RUN_TEST(subghz_decoder_linear_test);
MU_RUN_TEST(subghz_decoder_megacode_test);
MU_RUN_TEST(subghz_decoder_secplus_v1_test);
MU_RUN_TEST(subghz_decoder_secplus_v2_test);
Expand All @@ -466,7 +466,7 @@ MU_TEST_SUITE(subghz) {
MU_RUN_TEST(subghz_encoder_gate_tx_test);
MU_RUN_TEST(subghz_encoder_nice_flo_test);
MU_RUN_TEST(subghz_encoder_keelog_test);
MU_RUN_TEST(subghz_encoder_firefly_test);
MU_RUN_TEST(subghz_encoder_linear_test);
MU_RUN_TEST(subghz_encoder_megacode_test);
MU_RUN_TEST(subghz_encoder_holtek_test);
MU_RUN_TEST(subghz_encoder_secplus_v1_test);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Filetype: Flipper SubGhz Key File
Version: 1
Frequency: 300000000
Preset: FuriHalSubGhzPresetOok650Async
Protocol: Firefly
Protocol: Linear
Bit: 10
Key: 00 00 00 00 00 00 01 E4
File renamed without changes.
4 changes: 2 additions & 2 deletions firmware/targets/f7/furi_hal/furi_hal_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_gfsk_9_99kb_async_regs);
furi_hal_subghz_load_patable(furi_hal_subghz_preset_gfsk_async_patable);
} else {
furi_crash("SugGhz: Missing config.");
furi_crash("SubGhz: Missing config.");
}
furi_hal_subghz_preset = preset;
}
Expand Down Expand Up @@ -564,7 +564,7 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
} else if(value >= 778999847 && value <= 928000000) {
furi_hal_subghz_set_path(FuriHalSubGhzPath868);
} else {
furi_crash("SugGhz: Incorrect frequency during set.");
furi_crash("SubGhz: Incorrect frequency during set.");
}
return value;
}
Expand Down
42 changes: 42 additions & 0 deletions lib/subghz/blocks/encoder.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
#include "encoder.h"
#include "math.h"
#include <furi/check.h>

#define TAG "SubGhzBlockEncoder"

void subghz_protocol_blocks_set_bit_array(
bool bit_value,
uint8_t data_array[],
size_t set_index_bit,
size_t max_size_array) {
furi_assert(set_index_bit < max_size_array * 8);
bit_write(data_array[set_index_bit >> 3], 7 - (set_index_bit & 0x7), bit_value);
}

bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_index_bit) {
return bit_read(data_array[read_index_bit >> 3], 7 - (read_index_bit & 0x7));
}

size_t subghz_protocol_blocks_get_upload(
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;
size_t size_upload = 0;
uint32_t duration = duration_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++) {
if(last_bit == subghz_protocol_blocks_get_bit_array(data_array, index_bit)) {
duration += duration_bit;
} else {
furi_assert(max_size_upload > size_upload);
upload[size_upload++] = level_duration_make(
subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration);
last_bit = !last_bit;
duration = duration_bit;
}
index_bit++;
}
upload[size_upload++] = level_duration_make(
subghz_protocol_blocks_get_bit_array(data_array, index_bit - 1), duration);
return size_upload;
}
36 changes: 36 additions & 0 deletions lib/subghz/blocks/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,39 @@ typedef struct {
LevelDuration* upload;

} SubGhzProtocolBlockEncoder;

/**
* Set data bit when encoding HEX array.
* @param bit_value The value of the bit to be set
* @param data_array Pointer to a HEX array
* @param set_index_bit Number set a bit in the array starting from the left
* @param max_size_array array size, check not to overflow
*/
void subghz_protocol_blocks_set_bit_array(
bool bit_value,
uint8_t data_array[],
size_t set_index_bit,
size_t max_size_array);

/**
* Get data bit when encoding HEX array.
* @param data_array Pointer to a HEX array
* @param read_index_bit Number get a bit in the array starting from the left
* @return bool value bit
*/
bool subghz_protocol_blocks_get_bit_array(uint8_t data_array[], size_t read_index_bit);

/**
* Generating an upload from data.
* @param data_array Pointer to a HEX array
* @param count_bit_data_array How many bits in the array are processed
* @param upload Pointer to a LevelDuration
* @param max_size_upload upload size, check not to overflow
* @param duration_bit duration 1 bit
*/
size_t subghz_protocol_blocks_get_upload(
uint8_t data_array[],
size_t count_bit_data_array,
LevelDuration* upload,
size_t max_size_upload,
uint32_t duration_bit);
2 changes: 1 addition & 1 deletion lib/subghz/protocols/came_twee.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static LevelDuration
break;

default:
furi_crash("SugGhz: ManchesterEncoderResult is incorrect.");
furi_crash("SubGhz: ManchesterEncoderResult is incorrect.");
break;
}
return level_duration_make(data.level, data.duration);
Expand Down
Loading

0 comments on commit be4dec7

Please sign in to comment.