Ver Fonte

Decoded signal square wave WIP.

antirez há 3 anos atrás
pai
commit
f885491bc9
6 ficheiros alterados com 57 adições e 20 exclusões
  1. 5 2
      app.c
  2. 4 1
      app.h
  3. 16 5
      signal.c
  4. 8 2
      ui.c
  5. 23 9
      view_info.c
  6. 1 1
      view_raw_signal.c

+ 5 - 2
app.c

@@ -132,6 +132,7 @@ ProtoViewApp* protoview_app_alloc() {
     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;
+    app->msg_info = NULL;
 
 
     //init Worker & Protocol
     //init Worker & Protocol
     app->txrx = malloc(sizeof(ProtoViewTxRx));
     app->txrx = malloc(sizeof(ProtoViewTxRx));
@@ -258,12 +259,14 @@ int32_t protoview_app_entry(void* p) {
                 /* Exit the app. */
                 /* Exit the app. */
                 app->running = 0;
                 app->running = 0;
             } else if (input.type == InputTypeShort &&
             } else if (input.type == InputTypeShort &&
-                       input.key == InputKeyRight)
+                       input.key == InputKeyRight &&
+                       get_current_subview(app) == 0)
             {
             {
                 /* Go to the next view. */
                 /* Go to the next view. */
                 app_switch_view(app,AppNextView);
                 app_switch_view(app,AppNextView);
             } else if (input.type == InputTypeShort &&
             } else if (input.type == InputTypeShort &&
-                       input.key == InputKeyLeft)
+                       input.key == InputKeyLeft &&
+                       get_current_subview(app) == 0)
             {
             {
                 /* Go to the previous view. */
                 /* Go to the previous view. */
                 app_switch_view(app,AppPrevView);
                 app_switch_view(app,AppPrevView);

+ 4 - 1
app.h

@@ -130,7 +130,7 @@ struct ProtoViewApp {
     uint32_t signal_last_scan_idx; /* Index of the buffer last time we
     uint32_t signal_last_scan_idx; /* Index of the buffer last time we
                                       performed the scan. */
                                       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 *msg_info; /* Decoded message info if not NULL. */
     bool direct_sampling_enabled; /* This special view needs an explicit
     bool direct_sampling_enabled; /* This special view needs an explicit
                                      acknowledge to work. */
                                      acknowledge to work. */
 
 
@@ -180,6 +180,8 @@ bool bitmap_match_bits(uint8_t *b, uint32_t blen, uint32_t bitpos, const char *b
 uint32_t bitmap_seek_bits(uint8_t *b, uint32_t blen, uint32_t startpos, uint32_t maxbits, const char *bits);
 uint32_t bitmap_seek_bits(uint8_t *b, uint32_t blen, uint32_t startpos, uint32_t maxbits, const char *bits);
 uint32_t convert_from_line_code(uint8_t *buf, uint64_t buflen, uint8_t *bits, uint32_t len, uint32_t offset, const char *zero_pattern, const char *one_pattern);
 uint32_t convert_from_line_code(uint8_t *buf, uint64_t buflen, uint8_t *bits, uint32_t len, uint32_t offset, const char *zero_pattern, const char *one_pattern);
 uint32_t convert_from_diff_manchester(uint8_t *buf, uint64_t buflen, uint8_t *bits, uint32_t len, uint32_t off, bool previous);
 uint32_t convert_from_diff_manchester(uint8_t *buf, uint64_t buflen, uint8_t *bits, uint32_t len, uint32_t off, bool previous);
+void init_msg_info(ProtoViewMsgInfo *i, ProtoViewApp *app);
+void free_msg_info(ProtoViewMsgInfo *i);
 
 
 /* view_*.c */
 /* view_*.c */
 void render_view_raw_pulses(Canvas *const canvas, ProtoViewApp *app);
 void render_view_raw_pulses(Canvas *const canvas, ProtoViewApp *app);
@@ -195,6 +197,7 @@ void view_exit_direct_sampling(ProtoViewApp *app);
 void view_exit_settings(ProtoViewApp *app);
 void view_exit_settings(ProtoViewApp *app);
 
 
 /* ui.c */
 /* ui.c */
+int get_current_subview(ProtoViewApp *app);
 void show_available_subviews(Canvas *canvas, ProtoViewApp *app, int last_subview);
 void show_available_subviews(Canvas *canvas, ProtoViewApp *app, int last_subview);
 bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview);
 bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview);
 void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);
 void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);

+ 16 - 5
signal.c

@@ -4,7 +4,6 @@
 #include "app.h"
 #include "app.h"
 
 
 bool decode_signal(RawSamplesBuffer *s, uint64_t len, ProtoViewMsgInfo *info);
 bool decode_signal(RawSamplesBuffer *s, uint64_t len, ProtoViewMsgInfo *info);
-void initialize_msg_info(ProtoViewMsgInfo *i, ProtoViewApp *app);
 
 
 /* =============================================================================
 /* =============================================================================
  * Raw signal detection
  * Raw signal detection
@@ -23,6 +22,8 @@ void reset_current_signal(ProtoViewApp *app) {
     app->signal_decoded = false;
     app->signal_decoded = false;
     raw_samples_reset(DetectedSamples);
     raw_samples_reset(DetectedSamples);
     raw_samples_reset(RawSamples);
     raw_samples_reset(RawSamples);
+    free_msg_info(app->msg_info);
+    app->msg_info = NULL;
 }
 }
 
 
 /* This function starts scanning samples at offset idx looking for the
 /* This function starts scanning samples at offset idx looking for the
@@ -143,7 +144,7 @@ void scan_for_signal(ProtoViewApp *app) {
 
 
         /* For messages that are long enough, attempt decoding. */
         /* For messages that are long enough, attempt decoding. */
         if (thislen > minlen) {
         if (thislen > minlen) {
-            initialize_msg_info(info,app);
+            init_msg_info(info,app);
             uint32_t saved_idx = copy->idx; /* Save index, see later. */
             uint32_t saved_idx = copy->idx; /* Save index, see later. */
             /* decode_signal() expects the detected signal to start
             /* decode_signal() expects the detected signal to start
              * from index .*/
              * from index .*/
@@ -158,7 +159,8 @@ void scan_for_signal(ProtoViewApp *app) {
             if ((thislen > app->signal_bestlen && app->signal_decoded == false)
             if ((thislen > app->signal_bestlen && app->signal_decoded == false)
                 || (app->signal_decoded == false && decoded))
                 || (app->signal_decoded == false && decoded))
             {
             {
-                app->signal_info = *info;
+                free_msg_info(app->msg_info);
+                app->msg_info = info;
                 app->signal_bestlen = thislen;
                 app->signal_bestlen = thislen;
                 app->signal_decoded = decoded;
                 app->signal_decoded = decoded;
                 raw_samples_copy(DetectedSamples,copy);
                 raw_samples_copy(DetectedSamples,copy);
@@ -172,12 +174,13 @@ void scan_for_signal(ProtoViewApp *app) {
                     app->us_scale = 10;
                     app->us_scale = 10;
                 else if (DetectedSamples->short_pulse_dur < 145)
                 else if (DetectedSamples->short_pulse_dur < 145)
                     app->us_scale = 30;
                     app->us_scale = 30;
+            } else {
+                free_msg_info(info);
             }
             }
         }
         }
         i += thislen ? thislen : 1;
         i += thislen ? thislen : 1;
     }
     }
     raw_samples_free(copy);
     raw_samples_free(copy);
-    free(info);
 }
 }
 
 
 /* =============================================================================
 /* =============================================================================
@@ -502,12 +505,20 @@ ProtoViewDecoder *Decoders[] = {
     NULL
     NULL
 };
 };
 
 
+/* Free the message info and allocated data. */
+void free_msg_info(ProtoViewMsgInfo *i) {
+    if (i == NULL) return;
+    free(i->bits);
+    free(i);
+}
+
 /* Reset the message info structure before passing it to the decoding
 /* Reset the message info structure before passing it to the decoding
  * functions. */
  * functions. */
-void initialize_msg_info(ProtoViewMsgInfo *i, ProtoViewApp *app) {
+void init_msg_info(ProtoViewMsgInfo *i, ProtoViewApp *app) {
     UNUSED(app);
     UNUSED(app);
     memset(i,0,sizeof(ProtoViewMsgInfo));
     memset(i,0,sizeof(ProtoViewMsgInfo));
     i->short_pulse_dur = DetectedSamples->short_pulse_dur;
     i->short_pulse_dur = DetectedSamples->short_pulse_dur;
+    i->bits = NULL;
 }
 }
 
 
 /* This function is called when a new signal is detected. It converts it
 /* This function is called when a new signal is detected. It converts it

+ 8 - 2
ui.c

@@ -3,13 +3,19 @@
 
 
 #include "app.h"
 #include "app.h"
 
 
+/* Return the ID of the currently selected subview, of the current
+ * view. */
+int get_current_subview(ProtoViewApp *app) {
+    return app->current_subview[app->current_view];
+}
+
 /* Called by view rendering callback that has subviews, to show small triangles
 /* Called by view rendering callback that has subviews, to show small triangles
  * facing down/up if there are other subviews the user can access with up
  * facing down/up if there are other subviews the user can access with up
  * and down. */
  * and down. */
 void show_available_subviews(Canvas *canvas, ProtoViewApp *app,
 void show_available_subviews(Canvas *canvas, ProtoViewApp *app,
                              int last_subview)
                              int last_subview)
 {
 {
-    int subview = app->current_subview[app->current_view];
+    int subview = get_current_subview(app);
     if (subview != 0)
     if (subview != 0)
         canvas_draw_triangle(canvas,120,5,8,5,CanvasDirectionBottomToTop);
         canvas_draw_triangle(canvas,120,5,8,5,CanvasDirectionBottomToTop);
     if (subview != last_subview-1)
     if (subview != last_subview-1)
@@ -20,7 +26,7 @@ void show_available_subviews(Canvas *canvas, ProtoViewApp *app,
  * such keypress, it returns true, so that the actual view input callback
  * such keypress, it returns true, so that the actual view input callback
  * knows it can just return ASAP without doing anything. */
  * knows it can just return ASAP without doing anything. */
 bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview) {
 bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview) {
-    int subview = app->current_subview[app->current_view];
+    int subview = get_current_subview(app);
     if (input.type == InputTypePress) {
     if (input.type == InputTypePress) {
         if (input.key == InputKeyUp) {
         if (input.key == InputKeyUp) {
             if (subview != 0)
             if (subview != 0)

+ 23 - 9
view_info.c

@@ -14,27 +14,41 @@ static void render_subview_main(Canvas *const canvas, ProtoViewApp *app) {
     /* Protocol name as title. */
     /* Protocol name as title. */
     canvas_set_font(canvas, FontPrimary);
     canvas_set_font(canvas, FontPrimary);
     uint8_t y = 8, lineheight = 10;
     uint8_t y = 8, lineheight = 10;
-    canvas_draw_str(canvas, 0, y, app->signal_info.name);
+    canvas_draw_str(canvas, 0, y, app->msg_info->name);
     y += lineheight;
     y += lineheight;
 
 
     /* Info fields. */
     /* Info fields. */
     char buf[128];
     char buf[128];
     canvas_set_font(canvas, FontSecondary);
     canvas_set_font(canvas, FontSecondary);
-    if (app->signal_info.raw[0]) {
-        snprintf(buf,sizeof(buf),"Raw: %s", app->signal_info.raw);
+    if (app->msg_info->raw[0]) {
+        snprintf(buf,sizeof(buf),"Raw: %s", app->msg_info->raw);
         canvas_draw_str(canvas, 0, y, buf);
         canvas_draw_str(canvas, 0, y, buf);
         y += lineheight;
         y += lineheight;
     }
     }
-    canvas_draw_str(canvas, 0, y, app->signal_info.info1); y += lineheight;
-    canvas_draw_str(canvas, 0, y, app->signal_info.info2); y += lineheight;
-    canvas_draw_str(canvas, 0, y, app->signal_info.info3); y += lineheight;
-    canvas_draw_str(canvas, 0, y, app->signal_info.info4); y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->msg_info->info1); y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->msg_info->info2); y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->msg_info->info3); y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->msg_info->info4); y += lineheight;
 }
 }
 
 
 /* Render view with save option. */
 /* Render view with save option. */
 static void render_subview_save(Canvas *const canvas, ProtoViewApp *app) {
 static void render_subview_save(Canvas *const canvas, ProtoViewApp *app) {
-    UNUSED(canvas);
-    UNUSED(app);
+    uint8_t rows = 6;
+    uint8_t rowheight = 8;
+    uint8_t bitwidth = 4;
+    uint8_t bitheight = 5;
+    uint32_t idx = 0;
+    bool prevbit = false;
+    for (uint8_t y = bitheight; y < rows*rowheight; y += rowheight) {
+        for (uint8_t x = 5; x < 128; x += 4) {
+            bool bit = bitmap_get(app->msg_info->bits,
+                                  app->msg_info->bits_bytes,idx++);
+            uint8_t prevy = y + prevbit*bitheight - 1;
+            uint8_t thisy = y + bit*bitheight - 1;
+            canvas_draw_line(canvas,x,prevy,x,thisy);
+            canvas_draw_line(canvas,x,thisy,x+bitwidth-1,thisy);
+        }
+    }
 }
 }
 
 
 /* Render the selected subview of this view. */
 /* Render the selected subview of this view. */

+ 1 - 1
view_raw_signal.c

@@ -65,7 +65,7 @@ void render_view_raw_pulses(Canvas *const canvas, ProtoViewApp *app) {
     canvas_draw_str_with_border(canvas, 97, 63, buf, ColorWhite, ColorBlack);
     canvas_draw_str_with_border(canvas, 97, 63, buf, ColorWhite, ColorBlack);
     if (app->signal_decoded) {
     if (app->signal_decoded) {
         canvas_set_font(canvas, FontPrimary);
         canvas_set_font(canvas, FontPrimary);
-        canvas_draw_str_with_border(canvas, 1, 61, app->signal_info.name, ColorWhite, ColorBlack);
+        canvas_draw_str_with_border(canvas, 1, 61, app->msg_info->name, ColorWhite, ColorBlack);
     }
     }
 }
 }