Skorp subghz capture refactoring (#569)

* SubGhz: changing the operation of the capture timer, and the logic of the work of parsers
* Add toolbox lib. Move levels to toolbox. Subghz switch to levels.
* Subghz: update worker signatures
* SubGhz: pluggable level duration implementations.
* SubGhz : test drawing pictures in Gui
* SubGhz: Added a callback with the parser structure as argument
* SubGhz: copy protocol data to model
* SubGhz: refactoing code
* SubGhz: cleanup and format sources
* SubGhz: remove comments

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
Skorpionm
2021-07-07 23:49:45 +04:00
committed by GitHub
parent a7283280ef
commit 4ce41a3e6f
21 changed files with 328 additions and 150 deletions

View File

@@ -21,22 +21,18 @@ struct SubGhzWorker {
* @param duration received signal duration
* @param context
*/
void subghz_worker_rx_callback(
ApiHalSubGhzCaptureLevel level,
uint32_t duration,
void* context) {
void subghz_worker_rx_callback(bool level, uint32_t duration, void* context) {
SubGhzWorker* instance = context;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
LevelPair pair = {.level = level, .duration = duration};
LevelDuration level_duration = level_duration_make(level, duration);
if(instance->overrun) {
instance->overrun = false;
pair.level = ApiHalSubGhzCaptureLevelOverrun;
level_duration = level_duration_reset();
}
size_t ret =
xStreamBufferSendFromISR(instance->stream, &pair, sizeof(LevelPair), &xHigherPriorityTaskWoken);
if(sizeof(LevelPair) != ret) instance->overrun = true;
xStreamBufferSendFromISR(instance->stream, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken);
if(sizeof(LevelDuration) != ret) instance->overrun = true;
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
@@ -48,15 +44,17 @@ void subghz_worker_rx_callback(
static int32_t subghz_worker_thread_callback(void* context) {
SubGhzWorker* instance = context;
LevelPair pair;
LevelDuration level_duration;
while(instance->running) {
int ret = xStreamBufferReceive(instance->stream, &pair, sizeof(LevelPair), 10);
if(ret == sizeof(LevelPair)) {
if(pair.level == ApiHalSubGhzCaptureLevelOverrun) {
int ret = xStreamBufferReceive(instance->stream, &level_duration, sizeof(LevelDuration), 10);
if(ret == sizeof(LevelDuration)) {
if(level_duration_is_reset(level_duration)) {
printf(".");
if (instance->overrun_callback) instance->overrun_callback(instance->context);
} else {
if (instance->pair_callback) instance->pair_callback(instance->context, pair);
bool level = level_duration_get_level(level_duration);
uint32_t duration = level_duration_get_duration(level_duration);
if (instance->pair_callback) instance->pair_callback(instance->context, level, duration);
}
}
}
@@ -73,7 +71,7 @@ SubGhzWorker* subghz_worker_alloc() {
furi_thread_set_context(instance->thread, instance);
furi_thread_set_callback(instance->thread, subghz_worker_thread_callback);
instance->stream = xStreamBufferCreate(sizeof(LevelPair) * 1024, sizeof(LevelPair));
instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
return instance;
}