Преглед на файлове

Implement signal creation for PT remotes.

antirez преди 3 години
родител
ревизия
f75067cc45
променени са 7 файла, в които са добавени 36 реда и са изтрити 14 реда
  1. 1 1
      app.c
  2. 2 2
      app.h
  3. 1 1
      data_feed.c
  4. 27 5
      protocols/b4b1.c
  5. 1 1
      raw_samples.c
  6. 0 0
      raw_samples.h
  7. 4 4
      signal.c

+ 1 - 1
app.c

@@ -245,7 +245,7 @@ static void timer_callback(void *ctx) {
     }
     if (delta < RawSamples->total/2) return;
     app->signal_last_scan_idx = RawSamples->idx;
-    scan_for_signal(app);
+    scan_for_signal(app,RawSamples);
 }
 
 /* This is the navigation callback we use in the view dispatcher used

+ 2 - 2
app.h

@@ -21,7 +21,7 @@
 #include <lib/subghz/receiver.h>
 #include <lib/subghz/transmitter.h>
 #include <lib/subghz/registry.h>
-#include "app_buffer.h"
+#include "raw_samples.h"
 
 #define TAG "ProtoView"
 #define PROTOVIEW_RAW_VIEW_DEFAULT_SCALE 100 // 100us is 1 pixel by default
@@ -251,7 +251,7 @@ void radio_tx_signal(ProtoViewApp *app, FuriHalSubGhzAsyncTxCallback data_feeder
 /* signal.c */
 uint32_t duration_delta(uint32_t a, uint32_t b);
 void reset_current_signal(ProtoViewApp *app);
-void scan_for_signal(ProtoViewApp *app);
+void scan_for_signal(ProtoViewApp *app,RawSamplesBuffer *source);
 bool bitmap_get(uint8_t *b, uint32_t blen, uint32_t bitpos);
 void bitmap_set(uint8_t *b, uint32_t blen, uint32_t bitpos, bool val);
 void bitmap_copy(uint8_t *d, uint32_t dlen, uint32_t doff, uint8_t *s, uint32_t slen, uint32_t soff, uint32_t count);

+ 1 - 1
data_feed.c

@@ -6,7 +6,7 @@
 #include <furi/core/string.h>
 #include <lib/subghz/registry.h>
 #include <lib/subghz/protocols/base.h>
-#include "app_buffer.h"
+#include "raw_samples.h"
 
 #define TAG "PROTOVIEW-protocol"
 

+ 27 - 5
protocols/b4b1.c

@@ -42,20 +42,42 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
     info->pulses_count = off - info->start_off;
 
     fieldset_add_bytes(info->fieldset,"id",d,5);
-    fieldset_add_int(info->fieldset,"button",d[2]&0xf,4);
+    fieldset_add_uint(info->fieldset,"button",d[2]&0xf,4);
     return true;
 }
 
+/* Give fields and defaults for the signal creator. */
 static void get_fields(ProtoViewFieldSet *fieldset) {
     uint8_t default_id[3]= {0xAB, 0xCD, 0xE0};
     fieldset_add_bytes(fieldset,"id",default_id,5);
-    fieldset_add_int(fieldset,"button",1,4);
+    fieldset_add_uint(fieldset,"button",1,4);
 }
 
-static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fields)
+/* Create a signal. */
+static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fs)
 {
-    UNUSED(samples);
-    UNUSED(fields);
+    uint32_t te = 334; // Short pulse duration in microseconds.
+
+    // Sync.
+    raw_samples_add(samples,true,te);
+    raw_samples_add(samples,false,te*31);
+
+    // ID + button state
+    uint8_t data[3];
+    memcpy(data,fs->fields[0]->bytes,3);
+    data[3] = (data[3]&0xF0) | fs->fields[1]->uvalue;
+    for (uint32_t j = 0; j < 24; j++) {
+        if (bitmap_get(data,sizeof(data),j)) {
+            raw_samples_add(samples,true,te*3);
+            raw_samples_add(samples,false,te);
+        } else {
+            raw_samples_add(samples,true,te);
+            raw_samples_add(samples,false,te*3);
+        }
+    }
+
+    // Terminator
+    raw_samples_add(samples,true,te);
 }
 
 ProtoViewDecoder B4B1Decoder = {

+ 1 - 1
app_buffer.c → raw_samples.c

@@ -5,7 +5,7 @@
 #include <furi/core/string.h>
 #include <furi.h>
 #include <furi_hal.h>
-#include "app_buffer.h"
+#include "raw_samples.h"
 
 /* Allocate and initialize a samples buffer. */
 RawSamplesBuffer *raw_samples_alloc(void) {

+ 0 - 0
app_buffer.h → raw_samples.h


+ 4 - 4
signal.c

@@ -145,15 +145,15 @@ void notify_signal_detected(ProtoViewApp *app, bool decoded) {
         notification_message(app->notification, &unknown_seq);
 }
 
-/* Search the buffer with the stored signal (last N samples received)
+/* Search the source buffer with the stored signal (last N samples received)
  * in order to find a coherent signal. If a signal that does not appear to
  * be just noise is found, it is set in DetectedSamples global signal
  * buffer, that is what is rendered on the screen. */
-void scan_for_signal(ProtoViewApp *app) {
-    /* We need to work on a copy: the RawSamples buffer is populated
+void scan_for_signal(ProtoViewApp *app, RawSamplesBuffer *source) {
+    /* We need to work on a copy: the source buffer may be populated
      * by the background thread receiving data. */
     RawSamplesBuffer *copy = raw_samples_alloc();
-    raw_samples_copy(copy,RawSamples);
+    raw_samples_copy(copy,source);
 
     /* Try to seek on data that looks to have a regular high low high low
      * pattern. */