Просмотр исходного кода

Try to scan more often, but only scan if needed.

antirez 3 лет назад
Родитель
Сommit
0e85d13d83
3 измененных файлов с 20 добавлено и 4 удалено
  1. 2 0
      TODO
  2. 16 4
      app.c
  3. 2 0
      app.h

+ 2 - 0
TODO

@@ -5,3 +5,5 @@ Core improvements
 - CC1101 synchronous mode with protocol hopping?
 - CC1101 synchronous mode with protocol hopping?
 - Protocols decoded can register actions, for instance to generate
 - Protocols decoded can register actions, for instance to generate
   sub files with modified signal and so forth.
   sub files with modified signal and so forth.
+- Optimize memory usage storing raw samples in a bitfield: 15 bits
+  duration, 1 bit level.

+ 16 - 4
app.c

@@ -122,6 +122,7 @@ ProtoViewApp* protoview_app_alloc() {
 
 
     // Signal found and visualization defaults
     // Signal found and visualization defaults
     app->signal_bestlen = 0;
     app->signal_bestlen = 0;
+    app->signal_last_scan_idx = 0;
     app->signal_decoded = false;
     app->signal_decoded = false;
     app->us_scale = PROTOVIEW_RAW_VIEW_DEFAULT_SCALE;
     app->us_scale = PROTOVIEW_RAW_VIEW_DEFAULT_SCALE;
     app->signal_offset = 0;
     app->signal_offset = 0;
@@ -202,6 +203,20 @@ void protoview_app_free(ProtoViewApp *app) {
  * function is to scan for signals and set DetectedSamples. */
  * function is to scan for signals and set DetectedSamples. */
 static void timer_callback(void *ctx) {
 static void timer_callback(void *ctx) {
     ProtoViewApp *app = ctx;
     ProtoViewApp *app = ctx;
+    uint32_t delta, lastidx = app->signal_last_scan_idx;
+
+    /* scan_for_signal(), called by this function, deals with a
+     * circular buffer. To never miss anything, even if a signal spawns
+     * cross-boundaries, it is enough if we scan each time the buffer fills
+     * for 50% more compared to the last scan. Thanks to this check we
+     * can avoid scanning too many times to just find the same data. */
+    if (lastidx < RawSamples->idx) {
+        delta = RawSamples->idx - lastidx;
+    } else {
+        delta = RawSamples->total - lastidx + RawSamples->idx;
+    }
+    if (delta < RawSamples->total/2) return;
+    app->signal_last_scan_idx = RawSamples->idx;
     scan_for_signal(app);
     scan_for_signal(app);
 }
 }
 
 
@@ -209,12 +224,9 @@ int32_t protoview_app_entry(void* p) {
     UNUSED(p);
     UNUSED(p);
     ProtoViewApp *app = protoview_app_alloc();
     ProtoViewApp *app = protoview_app_alloc();
 
 
-    printf("%llu\n", (unsigned long long) DWT->CYCCNT);
-    printf("%llu\n", (unsigned long long) DWT->CYCCNT);
-
     /* Create a timer. We do data analysis in the callback. */
     /* Create a timer. We do data analysis in the callback. */
     FuriTimer *timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, app);
     FuriTimer *timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, app);
-    furi_timer_start(timer, furi_kernel_get_tick_frequency() / 4);
+    furi_timer_start(timer, furi_kernel_get_tick_frequency() / 8);
 
 
     /* Start listening to signals immediately. */
     /* Start listening to signals immediately. */
     radio_begin(app);
     radio_begin(app);

+ 2 - 0
app.h

@@ -114,6 +114,8 @@ struct ProtoViewApp {
     /* Generic app state. */
     /* Generic app state. */
     int running;             /* Once false exists the app. */
     int running;             /* Once false exists the app. */
     uint32_t signal_bestlen; /* Longest coherent signal observed so far. */
     uint32_t signal_bestlen; /* Longest coherent signal observed so far. */
+    uint32_t signal_last_scan_idx; /* Index of the buffer last time we
+                                      performed the scan. */
     bool signal_decoded;     /* Was the current signal decoded? */
     bool signal_decoded;     /* Was the current signal decoded? */
     ProtoViewMsgInfo signal_info; /* Decoded message, if signal_decoded true. */
     ProtoViewMsgInfo signal_info; /* Decoded message, if signal_decoded true. */
     bool direct_sampling_enabled; /* This special view needs an explicit
     bool direct_sampling_enabled; /* This special view needs an explicit