]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Factor out packet sending
authorJoel Holdsworth <redacted>
Sun, 24 Apr 2016 21:06:28 +0000 (23:06 +0200)
committerUwe Hermann <redacted>
Wed, 27 Apr 2016 20:29:56 +0000 (22:29 +0200)
This will make it possible to use different senders based on
driver mode. This is needed for USBee AX support.

src/hardware/fx2lafw/api.c
src/hardware/fx2lafw/protocol.c
src/hardware/fx2lafw/protocol.h

index 024680364209804725fa5fd45e8aba2b4a7903aa..d7f602820f75fd49645a0359186a4bd1b0c6e5a3 100644 (file)
@@ -710,6 +710,8 @@ static int start_transfers(const struct sr_dev_inst *sdi)
                devc->submitted_transfers++;
        }
 
+       devc->send_data_proc = la_send_data_proc;
+
        /* Send header packet to the session bus. */
        std_session_send_df_header(sdi, LOG_PREFIX);
 
index 8fe7b6c1fea5713a21b6066a6be5e424f43e045a..8a11514ed824d6b0227f61f0879cd0fccccf4712 100644 (file)
@@ -382,13 +382,28 @@ static void resubmit_transfer(struct libusb_transfer *transfer)
 
 }
 
+SR_PRIV void la_send_data_proc(void *cb_data,
+       uint8_t *data, size_t length, size_t sample_width)
+{
+       const struct sr_datafeed_logic logic = {
+               .length = length,
+               .unitsize = sample_width,
+               .data = data
+       };
+
+       const struct sr_datafeed_packet packet = {
+               .type = SR_DF_LOGIC,
+               .payload = &logic
+       };
+
+       sr_session_send(cb_data, &packet);
+}
+
 SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transfer)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        gboolean packet_has_error = FALSE;
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_logic logic;
        unsigned int num_samples;
        int trigger_offset, cur_sample_count, unitsize;
        int pre_trigger_samples;
@@ -446,16 +461,15 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf
        if (devc->trigger_fired) {
                if (!devc->limit_samples || devc->sent_samples < devc->limit_samples) {
                        /* Send the incoming transfer to the session bus. */
-                       packet.type = SR_DF_LOGIC;
-                       packet.payload = &logic;
                        if (devc->limit_samples && devc->sent_samples + cur_sample_count > devc->limit_samples)
                                num_samples = devc->limit_samples - devc->sent_samples;
                        else
                                num_samples = cur_sample_count;
-                       logic.length = num_samples * unitsize;
-                       logic.unitsize = unitsize;
-                       logic.data = transfer->buffer;
-                       sr_session_send(devc->cb_data, &packet);
+
+                       devc->send_data_proc(devc->cb_data,
+                                               (uint8_t*)transfer->buffer,
+                                               num_samples * unitsize,
+                                               unitsize);
                        devc->sent_samples += num_samples;
                }
        } else {
@@ -463,16 +477,15 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf
                        transfer->buffer, transfer->actual_length, &pre_trigger_samples);
                if (trigger_offset > -1) {
                        devc->sent_samples += pre_trigger_samples;
-                       packet.type = SR_DF_LOGIC;
-                       packet.payload = &logic;
                        num_samples = cur_sample_count - trigger_offset;
                        if (devc->limit_samples &&
                                        num_samples > devc->limit_samples - devc->sent_samples)
                                num_samples = devc->limit_samples - devc->sent_samples;
-                       logic.length = num_samples * unitsize;
-                       logic.unitsize = unitsize;
-                       logic.data = transfer->buffer + trigger_offset * unitsize;
-                       sr_session_send(devc->cb_data, &packet);
+
+                       devc->send_data_proc(devc->cb_data,
+                                               (uint8_t*)transfer->buffer + trigger_offset * unitsize,
+                                               num_samples * unitsize,
+                                               unitsize);
                        devc->sent_samples += num_samples;
 
                        devc->trigger_fired = TRUE;
index 50e0ea4bf75e3994f35ae7a7d675da9d06611f67..0220ae24c6baeadadb11efebd12baab4496156ea 100644 (file)
@@ -122,6 +122,8 @@ struct dev_context {
        unsigned int num_transfers;
        struct libusb_transfer **transfers;
        struct sr_context *ctx;
+       void (*send_data_proc)(void *cb_data,
+               uint8_t *data, size_t length, size_t sample_width);
 
        /* Is this a DSLogic? */
        gboolean dslogic;
@@ -140,5 +142,7 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf
 SR_PRIV size_t fx2lafw_get_buffer_size(struct dev_context *devc);
 SR_PRIV unsigned int fx2lafw_get_number_of_transfers(struct dev_context *devc);
 SR_PRIV unsigned int fx2lafw_get_timeout(struct dev_context *devc);
+SR_PRIV void la_send_data_proc(void *cb_data, uint8_t *data, size_t length,
+               size_t sample_width);
 
 #endif