Commit b47ac969 authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

cache improve

parent 44aa2ba6
......@@ -59,11 +59,13 @@ bool static_cache_get(cache_item_t * ptr_kv)
int idx;
if (_binary_search(ptr_set, *ptr_kv, &idx))
{
//found
*ptr_kv = ptr_set->ptr_items[idx];
return true;
}
else
{
//not found
return false;
}
}
......@@ -87,6 +89,7 @@ void static_cache_insert(const cache_item_t kv)
}
else
{
// move items and place new one
for (int i = ptr_set->length - 1; i >= idx; --i)
{
ptr_set->ptr_items[i + 1] = ptr_set->ptr_items[i];
......@@ -105,6 +108,7 @@ void static_cache_erase(const cache_item_t kv)
int idx;
if (_binary_search(ptr_set, kv, &idx))
{
// found delete and move remaining
for (int i = idx; i < ptr_set->length - 1; ++i)
{
ptr_set->ptr_items[i] = ptr_set->ptr_items[i + 1];
......@@ -112,3 +116,9 @@ void static_cache_erase(const cache_item_t kv)
--ptr_set->length;
}
}
cache_item_t static_cache_convert(uint32_t scalar)
{
cache_item_t kv = {.scalar = scalar};
return kv;
}
......@@ -10,15 +10,22 @@
// cache item type
typedef struct
#pragma pack(push,1)
typedef union
{
uint32_t key : 24;
uint32_t value : 8;
struct
{
uint32_t key : 24;
uint32_t value : 8;
};
uint32_t scalar;
} cache_item_t;
#pragma pack(pop)
bool static_cache_get(cache_item_t * ptr_kv);
void static_cache_insert(const cache_item_t kv);
void static_cache_erase(const cache_item_t kv);
cache_item_t static_cache_convert(uint32_t scalar);
#endif /* STATIC_CACHE_H_ */
......@@ -16,21 +16,27 @@
typedef union
{
#pragma pack(push,1)
struct
{
uint32_t user_id : 24;
uint32_t panel0 : 1;
uint32_t panel1 : 1;
uint32_t panel2 : 1;
uint32_t is_valid : 1;
uint32_t : 4; // reserved for future
uint32_t : 5; // reserved for future
};
cache_item_t item;
#pragma pack(pop)
cache_item_t as_cache_item;
uint32_t as_bitvalue;
}term_cache_item_t; // 4B
static bool _learn_mode_panel[3] = {false,false,false};
static uint32_t _learn_enable_user_id = 7632370;
static void terminal_user_authorized(uint8_t panel_id)
{
// TODO
DEBUGSTR("auth OK\n");
panel_unlock(panel_id, BEEP_ON_SUCCESS, OK_LED_ON_SUCCESS);
}
......@@ -38,31 +44,37 @@ static void terminal_user_not_authorized(uint8_t panel_id)
{
//TODO
(void)panel_id;
DEBUGSTR("auth FAIL\n");
}
static void terminal_user_identified(uint32_t user_id, uint8_t panel_id)
{
#ifdef DEVEL_BOARD
if (user_id == 7632370)
if (user_id == _learn_enable_user_id)
{
terminal_user_authorized(panel_id);
_learn_mode_panel[panel_id] = !_learn_mode_panel[panel_id];
return;
}
#endif
term_cache_item_t user;
user.user_id = user_id;
if (static_cache_get(&user.item))
if (_learn_mode_panel[panel_id])
{
if ((user.panel2 << 2 | user.panel1 << 1 | user.panel0) & (1 << panel_id))
user.as_bitvalue |= _BIT(panel_id) << 24;
static_cache_insert(user.as_cache_item);
}
else if (static_cache_get(&user.as_cache_item))
{
if ((user.panel2 << 2 | user.panel1 << 1 | user.panel0) & _BIT(panel_id))
{
terminal_user_authorized(panel_id);
return;
}
}
terminal_user_not_authorized(panel_id);
else
{
terminal_user_not_authorized(panel_id);
}
}
static void terminal_task(void *pvParameters)
......@@ -88,6 +100,17 @@ void terminal_init(void)
}
xTaskCreate(terminal_task, "term_tsk", configMINIMAL_STACK_SIZE + 128, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
#ifdef DEVEL_BOARD
static_cache_insert(static_cache_convert(0x7 << 24 | 814204));
static_cache_insert(static_cache_convert(0x7 << 24 | 814199));
static_cache_insert(static_cache_convert(0x7 << 24 | 814185));
static_cache_insert(static_cache_convert(0x7 << 24 | 814190));
static_cache_insert(static_cache_convert(0x7 << 24 | 7577396));
static_cache_insert(static_cache_convert(0x7 << 24 | 7575678));
static_cache_insert(static_cache_convert(0x7 << 24 | 7573990));
static_cache_insert(static_cache_convert(0x7 << 24 | 7627526));
#endif
}
void terminal_reconfigure(panel_conf_t * panel_cfg, uint8_t panel_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment