From: Gerhard Sittig Date: Sat, 22 Jan 2022 10:47:56 +0000 (+0100) Subject: kingst-la2016: address endianess issue in data feed submission X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fe953391bd7782813256c02350afa1996c773659;p=libsigrok.git kingst-la2016: address endianess issue in data feed submission 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. --- diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index 7888ed3e..5ae79caa 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -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);