]> sigrok.org Git - libsigrok.git/commitdiff
kingst-la2016: address endianess issue in data feed submission
authorGerhard Sittig <redacted>
Sat, 22 Jan 2022 10:47:56 +0000 (11:47 +0100)
committerGerhard Sittig <redacted>
Sun, 6 Feb 2022 17:53:53 +0000 (18:53 +0100)
Capture data was taken from the device in an endianess aware manner, but
submission to the session feed assumed a little endian host (and casted
an u8 pointer to u16 items, which is bad). Use an endianess aware writer
before sending accumulated sample data to the sigrok session. Address
remaining open coded byte counts in several send_chunk() places.

The conversion from LE (the device) to the host and to LE (the session)
may appear redundant, but is worth keeping in place when other models
with 32 channels should get added in a future implementation.

src/hardware/kingst-la2016/protocol.c

index 7888ed3ec7ebd0c45bf8764b52ce5281b5858473..5ae79caaf13c13a5cd81823ec5a9beb5e725bcb8 100644 (file)
@@ -914,22 +914,23 @@ static void send_chunk(struct sr_dev_inst *sdi,
        unsigned int max_samples, n_samples, total_samples, free_n_samples;
        unsigned int i, j, k;
        int do_signal_trigger;
-       uint16_t *wp;
+       uint8_t *wp;
        const uint8_t *rp;
        uint16_t state;
        uint8_t repetitions;
+       uint8_t sample_buff[sizeof(state)];
 
        devc = sdi->priv;
 
-       logic.unitsize = 2;
+       logic.unitsize = sizeof(sample_buff);
        logic.data = devc->convbuffer;
 
        sr_packet.type = SR_DF_LOGIC;
        sr_packet.payload = &logic;
 
-       max_samples = devc->convbuffer_size / 2;
+       max_samples = devc->convbuffer_size / sizeof(sample_buff);
        n_samples = 0;
-       wp = (uint16_t *)devc->convbuffer;
+       wp = devc->convbuffer;
        total_samples = 0;
        do_signal_trigger = 0;
 
@@ -946,7 +947,7 @@ static void send_chunk(struct sr_dev_inst *sdi,
                                logic.length = n_samples * 2;
                                sr_session_send(sdi, &sr_packet);
                                n_samples = 0;
-                               wp = (uint16_t *)devc->convbuffer;
+                               wp = devc->convbuffer;
                                if (do_signal_trigger) {
                                        std_session_send_df_trigger(sdi);
                                        do_signal_trigger = 0;
@@ -955,8 +956,11 @@ static void send_chunk(struct sr_dev_inst *sdi,
 
                        state = read_u16le_inc(&rp);
                        repetitions = read_u8_inc(&rp);
-                       for (j = 0; j < repetitions; j++)
-                               *wp++ = state;
+                       write_u16le((void *)&sample_buff, state);
+                       for (j = 0; j < repetitions; j++) {
+                               memcpy(wp, sample_buff, logic.unitsize);
+                               wp += logic.unitsize;
+                       }
 
                        n_samples += repetitions;
                        total_samples += repetitions;
@@ -975,7 +979,7 @@ static void send_chunk(struct sr_dev_inst *sdi,
                (void)read_u8_inc(&rp); /* Skip sequence number. */
        }
        if (n_samples) {
-               logic.length = n_samples * 2;
+               logic.length = n_samples * logic.unitsize;
                sr_session_send(sdi, &sr_packet);
                if (do_signal_trigger) {
                        std_session_send_df_trigger(sdi);