+/* Queue data of one channel group, for later submission. */
+SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
+ size_t group, GByteArray *pod_data)
+{
+ size_t size;
+ GByteArray *store;
+ uint8_t *logic_data;
+ size_t idx, logic_step;
+
+ /*
+ * Upon first invocation, allocate the array which can hold the
+ * combined logic data for all channels. Assume that each channel
+ * will yield an identical number of samples per receive call.
+ *
+ * As a poor man's safety measure: (Silently) skip processing
+ * for unexpected sample counts, and ignore samples for
+ * unexpected channel groups. Don't bother with complicated
+ * resize logic, considering that many models only support one
+ * pod, and the most capable supported models have two pods of
+ * identical size. We haven't yet seen any "odd" configuration.
+ */
+ if (!devc->logic_data) {
+ size = pod_data->len * devc->pod_count;
+ store = g_byte_array_sized_new(size);
+ memset(store->data, 0, size);
+ store = g_byte_array_set_size(store, size);
+ devc->logic_data = store;
+ } else {
+ store = devc->logic_data;
+ size = store->len / devc->pod_count;
+ if (size != pod_data->len)
+ return;
+ if (group >= devc->pod_count)
+ return;
+ }
+
+ /*
+ * Fold the data of the most recently received channel group into
+ * the storage, where data resides for all channels combined.
+ */
+ logic_data = store->data;
+ logic_data += group;
+ logic_step = devc->pod_count;
+ for (idx = 0; idx < pod_data->len; idx++) {
+ *logic_data = pod_data->data[idx];
+ logic_data += logic_step;
+ }
+}
+
+/* Submit data for all channels, after the individual groups got collected. */
+SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
+ struct dev_context *devc)
+{
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_logic logic;
+
+ if (!devc->logic_data)
+ return;
+
+ logic.data = devc->logic_data->data;
+ logic.length = devc->logic_data->len;
+ logic.unitsize = devc->pod_count;
+
+ packet.type = SR_DF_LOGIC;
+ packet.payload = &logic;
+
+ sr_session_send(sdi, &packet);
+}
+
+/* Undo previous resource allocation. */
+SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc)
+{
+
+ if (devc->logic_data) {
+ g_byte_array_free(devc->logic_data, TRUE);
+ devc->logic_data = NULL;
+ }
+ /*
+ * Keep 'pod_count'! It's required when more frames will be
+ * received, and does not harm when kept after acquisition.
+ */
+}
+