Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_AssetFilterStore.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Nov 29, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
14
15#include <optional>
16
27public:
32
38 bool isReady();
39
46
50 uint8_t getFilterCount();
51
55 AssetFilter getFilter(uint8_t index);
56
60 std::optional<uint8_t> findFilterIndex(uint8_t filterId);
61
65 uint16_t getMasterVersion();
66
70 uint32_t getMasterCrc();
71
75 constexpr static uint8_t MAX_FILTER_IDS = 8;
76
82 constexpr static size_t FILTER_BUFFER_SIZE = 520;
83
88
89private:
98 uint8_t* _filters[MAX_FILTER_IDS] = {};
99
103 uint8_t _filtersCount = 0;
104
109 uint16_t _masterVersion = 0;
110
116 uint32_t _masterCrc;
117
124
137 uint8_t* allocateFilter(uint8_t filterId, size_t stateDataSize);
138
144 bool deallocateFilter(uint8_t filterId);
145
152 void deallocateFilterByIndex(uint8_t parsingFilterIndex);
153
159 CS_TYPE getStateType(uint16_t filterDataSize);
160
164 uint16_t getStateSize(uint16_t filterDataSize);
165
171 CS_TYPE getNthStateType(uint8_t index);
172
176 uint8_t* findFilter(uint8_t filterId);
177
182
183 // -------------------------------------------------------------
184 // ---------------------- Command interface --------------------
185 // -------------------------------------------------------------
186
201
211
225
230
231 void onTick();
232
233 // -------------------------------------------------------------
234 // ---------------------- Utility functions --------------------
235 // -------------------------------------------------------------
236
242
246 void endInProgress(uint16_t newMasterVersion, uint32_t newMasterCrc);
247
252
257
269 cs_ret_code_t commit(uint16_t masterVersion, uint32_t masterCrc, bool store);
270
277
287
295
302
307
312
317
318public:
323};
Keeps up the asset filters.
Definition: cs_AssetFilterStore.h:26
void handleGetFilterSummariesCommand(cs_result_t &result)
Writes the filter summary in the result.
CS_TYPE getNthStateType(uint8_t index)
Used to loop over all asset filter state types.
bool validateFilters()
Checks for all filters if the allocated filter data size is equal to the computed size based on its c...
CS_TYPE getStateType(uint16_t filterDataSize)
Get the State type, given the filter data size.
uint8_t * allocateFilter(uint8_t filterId, size_t stateDataSize)
Allocates RAM for a filter of given size, and adds it to the filters array.
uint32_t _masterCrc
CRC over all the filter IDs and CRCs.
Definition: cs_AssetFilterStore.h:116
bool deallocateFilter(uint8_t filterId)
Same as deallocateFilterByIndex, but looks up the filter by the filterId.
uint32_t getMasterCrc()
Get the current master CRC.
std::optional< uint8_t > findFilterIndex(uint8_t filterId)
Returns the index of the filter with given filterId, if any.
void handleEvent(event_t &evt)
Internal usage.
uint8_t _filtersCount
Number of allocated filters in the filters array.
Definition: cs_AssetFilterStore.h:103
uint16_t _masterVersion
Keeps track of the version of the filters.
Definition: cs_AssetFilterStore.h:109
void computeFilterCrcs()
Computes the CRC of the filters, and sets it in the filter.
uint32_t computeMasterCrc()
Calculate the master CRC and return it (not stored).
void startInProgress()
To be called when about to modify filters.
cs_ret_code_t handleUploadFilterCommand(const asset_filter_cmd_upload_filter_t &cmdData)
Handle an upload command.
uint8_t getFilterCount()
Get the number of filters.
AssetFilter getFilter(uint8_t index)
Get the Nth filter.
cs_ret_code_t init()
set _filterModificationInProgress to false.
uint16_t getMasterVersion()
Get the current master version.
static constexpr uint8_t MAX_FILTER_IDS
Max number of filters.
Definition: cs_AssetFilterStore.h:75
cs_ret_code_t handleCommitFilterChangesCommand(const asset_filter_cmd_commit_filter_changes_t &cmdData)
Commit the filters.
cs_ret_code_t handleRemoveFilterCommand(const asset_filter_cmd_remove_filter_t &cmdData)
Removes given filter immediately.
void loadFromFlash(CS_TYPE type)
Load filters of a specific type (size) from flash.
bool isInProgress()
Whether changes are in progress.
void sendInProgressStatus()
Send an internal event when isInProgress() may have changed.
cs_ret_code_t commit(uint16_t masterVersion, uint32_t masterCrc, bool store)
Commit current filters.
void deallocateFilterByIndex(uint8_t parsingFilterIndex)
Deallocates the filter at given index in the filters array.
size_t getTotalHeapAllocatedSize()
Returns the total amount of heap allocated for the filters.
static constexpr size_t FILTER_BUFFER_SIZE
Max total size that the filters take up in RAM.
Definition: cs_AssetFilterStore.h:82
uint16_t getStateSize(uint16_t filterDataSize)
Get the size required for State, given the filter data size.
void inProgressTimeout()
Called when the modification in progress is timed out.
uint8_t * findFilter(uint8_t filterId)
Returns a pointer to the filter with given filterId, or nullptr if not found.
uint8_t * _filters[MAX_FILTER_IDS]
List of pointers to the allocated buffers for the filters.
Definition: cs_AssetFilterStore.h:98
void endInProgress(uint16_t newMasterVersion, uint32_t newMasterCrc)
To be called when filters are no longer being modified.
void loadFromFlash()
Load filters and version from flash.
static constexpr int MODIFICATION_IN_PROGRESS_TIMEOUT_SECONDS
Time after last edit command (upload, remove), until "modification in progress" times out.
Definition: cs_AssetFilterStore.h:87
uint16_t _modificationInProgressCountdown
When this value is not 0, the filters are being modified.
Definition: cs_AssetFilterStore.h:123
void markFiltersCommitted()
Sets flags.committed to true.
bool isReady()
Returns true if this object is ready to be used.
void storeFilters()
Store filters to flash.
Class that contains all data required for an asset filter:
Definition: cs_AssetFilter.h:19
Helper class to manage decoupling of components.
Definition: cs_Component.h:35
Event listener.
Definition: cs_EventListener.h:17
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
CS_TYPE
Types:
Definition: cs_Types.h:79
Definition: cs_AssetFilterPackets.h:34
Definition: cs_AssetFilterPackets.h:29
Definition: cs_AssetFilterPackets.h:20
Definition: cs_PacketsInternal.h:46