flipperzero-firmware/applications/subghz/subghz_history.c
Skorpionm 6f7bcdf9a7
[FL-1755, FL-1756] added LL_DeInit timers, removed Analyze scene, redesigned astomatic frequency change mechanism, updated subghz read scene interface (#677)
* SubGhz: Fix Timer hopping
* SubGhz: add display of received packages and their maximum number. redesigned interface, the maximum number of received packages increased to 50
* SubGhz: add clearing history on exit read scene, jump after saving the key into the history of received signals
* SubGhz: Fix honoring the width of the icon for transmitter scene
* RFID: Fix [FL-1755] freeze after key emulation
* SubGhz: drop analyze scene and views
* SubGhz: fix save scene
* Input, GUI: new event delivery scheme that groups event for complementarity.
* Gui: update View Dispatcher documentation
* Gui: remove dead code, wait till all input events are delivered in ViewDispatcher in queue mode.
* Gui: update comment in ViewDispatcher
* FuriHal: fix incorrect clock disable invocation
* FuriHal: proper include
* SubGhz: properly reset history in receiver view
* Gui: correct view switch order and non-complementary events discarding

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-30 23:05:09 +03:00

158 lines
5.5 KiB
C

#include "subghz_history.h"
#include <lib/subghz/protocols/subghz_protocol_keeloq.h>
#include <lib/subghz/protocols/subghz_protocol_star_line.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include <furi.h>
#include <m-string.h>
#define SUBGHZ_HISTORY_MAX 50
typedef struct SubGhzHistoryStruct SubGhzHistoryStruct;
struct SubGhzHistoryStruct {
const char* name;
const char* manufacture_name;
uint8_t type_protocol;
uint8_t code_count_bit;
uint64_t code_found;
uint16_t te;
FuriHalSubGhzPreset preset;
uint32_t real_frequency;
};
struct SubGhzHistory {
uint32_t last_update_timestamp;
uint16_t last_index_write;
uint64_t code_last_found;
SubGhzHistoryStruct history[SUBGHZ_HISTORY_MAX];
SubGhzProtocolCommonLoad data;
};
SubGhzHistory* subghz_history_alloc(void) {
SubGhzHistory* instance = furi_alloc(sizeof(SubGhzHistory));
return instance;
}
void subghz_history_free(SubGhzHistory* instance) {
furi_assert(instance);
free(instance);
}
void subghz_history_set_frequency_preset(
SubGhzHistory* instance,
uint16_t idx,
uint32_t frequency,
FuriHalSubGhzPreset preset) {
furi_assert(instance);
if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return;
instance->history[idx].preset = preset;
instance->history[idx].real_frequency = frequency;
}
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].real_frequency;
}
FuriHalSubGhzPreset subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].preset;
}
void subghz_history_clean(SubGhzHistory* instance) {
furi_assert(instance);
instance->last_index_write = 0;
instance->code_last_found = 0;
}
uint16_t subghz_history_get_item(SubGhzHistory* instance) {
furi_assert(instance);
return instance->last_index_write;
}
uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].type_protocol;
}
const char* subghz_history_get_name(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].name;
}
SubGhzProtocolCommonLoad* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
instance->data.code_found = instance->history[idx].code_found;
instance->data.code_count_bit = instance->history[idx].code_count_bit;
instance->data.param1 = instance->history[idx].te;
return &instance->data;
}
void subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output) {
furi_assert(instance);
string_printf(output, "%02u/%02u", instance->last_index_write, SUBGHZ_HISTORY_MAX);
}
void subghz_history_get_text_item_menu(SubGhzHistory* instance, string_t output, uint16_t idx) {
if(instance->history[idx].code_count_bit < 33) {
string_printf(
output,
"%s %lX",
instance->history[idx].name,
(uint32_t)(instance->history[idx].code_found & 0xFFFFFFFF));
} else {
string_t str_buff;
string_init(str_buff);
if(strcmp(instance->history[idx].name, "KeeLoq") == 0) {
string_set(str_buff, "KL ");
string_cat(str_buff, instance->history[idx].manufacture_name);
} else if(strcmp(instance->history[idx].name, "Star Line") == 0) {
string_set(str_buff, "SL ");
string_cat(str_buff, instance->history[idx].manufacture_name);
} else {
string_set(str_buff, instance->history[idx].name);
}
string_printf(
output,
"%s %lX%08lX",
string_get_cstr(str_buff),
(uint32_t)(instance->history[idx].code_found >> 32),
(uint32_t)(instance->history[idx].code_found & 0xFFFFFFFF));
string_clear(str_buff);
}
}
void subghz_history_add_to_history(SubGhzHistory* instance, void* context) {
furi_assert(instance);
furi_assert(context);
SubGhzProtocolCommon* protocol = context;
if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return;
if((instance->code_last_found == (protocol->code_last_found & 0xFFFF0FFFFFFFFFFF)) &&
((millis() - instance->last_update_timestamp) < 500)) {
instance->last_update_timestamp = millis();
return;
}
instance->code_last_found = protocol->code_last_found & 0xFFFF0FFFFFFFFFFF;
instance->last_update_timestamp = millis();
instance->history[instance->last_index_write].te = 0;
instance->history[instance->last_index_write].manufacture_name = NULL;
instance->history[instance->last_index_write].name = protocol->name;
instance->history[instance->last_index_write].code_count_bit = protocol->code_last_count_bit;
instance->history[instance->last_index_write].code_found = protocol->code_last_found;
if(strcmp(protocol->name, "KeeLoq") == 0) {
instance->history[instance->last_index_write].manufacture_name =
subghz_protocol_keeloq_get_manufacture_name(protocol);
} else if(strcmp(protocol->name, "Star Line") == 0) {
instance->history[instance->last_index_write].manufacture_name =
subghz_protocol_star_line_get_manufacture_name(protocol);
} else if(strcmp(protocol->name, "Princeton") == 0) {
instance->history[instance->last_index_write].te =
subghz_protocol_princeton_get_te(protocol);
}
instance->history[instance->last_index_write].type_protocol = protocol->type_protocol;
instance->last_index_write++;
}