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

Message builder: Generate signal and decode it.

antirez 3 лет назад
Родитель
Сommit
00819ac612
2 измененных файлов с 16 добавлено и 3 удалено
  1. 3 3
      protocols/b4b1.c
  2. 13 0
      view_build.c

+ 3 - 3
protocols/b4b1.c

@@ -58,14 +58,14 @@ static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fs)
 {
     uint32_t te = 334; // Short pulse duration in microseconds.
 
-    // Sync.
+    // Sync: 1 te pulse, 31 te gap.
     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;
+    data[2] = (data[2]&0xF0) | (fs->fields[1]->uvalue & 0xF);
     for (uint32_t j = 0; j < 24; j++) {
         if (bitmap_get(data,sizeof(data),j)) {
             raw_samples_add(samples,true,te*3);
@@ -76,7 +76,7 @@ static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fs)
         }
     }
 
-    // Terminator
+    // Signal terminator. Just a single short pulse.
     raw_samples_add(samples,true,te);
 }
 

+ 13 - 0
view_build.c

@@ -170,6 +170,19 @@ static void process_input_set_fields(ProtoViewApp *app, InputEvent input) {
                 privdata->cur_field--;
         }
     }
+
+    if (input.type == InputTypeLong && input.key == InputKeyOk) {
+        /* Build the message a fresh raw buffer. */
+        RawSamplesBuffer *rs = raw_samples_alloc();
+        if (privdata->decoder->build_message) {
+            privdata->decoder->build_message(rs,privdata->fieldset);
+            app->signal_decoded = false; // So that the new signal will be
+                                         // accepted as the current signal.
+            scan_for_signal(app,rs);
+            raw_samples_free(rs);
+            ui_show_alert(app,"Done: press back key",3000);
+        }
+    }
 }
 
 /* Handle input for the build message view. */