ols: Refactor, deduplicate logic packet code
authorv1ne <v1ne2go@gmail.com>
Tue, 31 Mar 2020 17:02:29 +0000 (19:02 +0200)
committerGerhard Sittig <gerhard.sittig@gmx.net>
Mon, 24 Aug 2020 05:57:06 +0000 (07:57 +0200)
Reviewed-By: Wolfram Sang <wsa@kernel.org>
src/hardware/openbench-logic-sniffer/protocol.c

index 9a36c8c89513231fc33cb2bb69e993c0b011f86e..0e7ebd7939d966e0e57a9c23583ac3ba430fef6e 100644 (file)
@@ -509,25 +509,19 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
 
                        /* Send the trigger. */
                        std_session_send_df_trigger(sdi);
-
-                       /* Send post-trigger samples. */
-                       packet.type = SR_DF_LOGIC;
-                       packet.payload = &logic;
-                       logic.length = (devc->num_samples * 4) - (devc->trigger_at_smpl * 4);
-                       logic.unitsize = 4;
-                       logic.data = devc->raw_sample_buf + devc->trigger_at_smpl * 4 +
-                               (devc->limit_samples - devc->num_samples) * 4;
-                       sr_session_send(sdi, &packet);
-               } else {
-                       /* no trigger was used */
-                       packet.type = SR_DF_LOGIC;
-                       packet.payload = &logic;
-                       logic.length = devc->num_samples * 4;
-                       logic.unitsize = 4;
-                       logic.data = devc->raw_sample_buf +
-                               (devc->limit_samples - devc->num_samples) * 4;
-                       sr_session_send(sdi, &packet);
                }
+
+               /* Send post-trigger / all captured samples. */
+               int num_pre_trigger_samples = devc->trigger_at_smpl == OLS_NO_TRIGGER
+                       ? 0 : devc->trigger_at_smpl;
+               packet.type = SR_DF_LOGIC;
+               packet.payload = &logic;
+               logic.length = (devc->num_samples - num_pre_trigger_samples) * 4;
+               logic.unitsize = 4;
+               logic.data = devc->raw_sample_buf + (num_pre_trigger_samples +
+                       devc->limit_samples - devc->num_samples) * 4;
+               sr_session_send(sdi, &packet);
+
                g_free(devc->raw_sample_buf);
 
                serial_flush(serial);