struct dev_context *devc;
struct sr_dev_inst *sdi;
size_t i;
+ const struct rdtech_tc_channel_desc *pch;
+ struct sr_channel *ch;
+ struct feed_queue_analog *feed;
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
+ devc->feeds = g_malloc0(devc->channel_count * sizeof(devc->feeds[0]));
for (i = 0; devc->channels[i].name; i++) {
- sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
- devc->channels[i].name);
+ pch = &devc->channels[i];
+ ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, pch->name);
+ feed = feed_queue_analog_alloc(sdi, 1, pch->digits, ch);
+ feed_queue_analog_mq_unit(feed, pch->mq, 0, pch->unit);
+ feed_queue_analog_scale_offset(feed, &pch->scale, NULL);
+ devc->feeds[i] = feed;
}
devices = g_slist_append(NULL, sdi);
return NULL;
}
+static void clear_helper(struct dev_context *devc)
+{
+ size_t idx;
+
+ if (!devc)
+ return;
+
+ if (devc->feeds) {
+ for (idx = 0; idx < devc->channel_count; idx++)
+ feed_queue_analog_free(devc->feeds[idx]);
+ g_free(devc->feeds);
+ }
+}
+
+static int dev_clear(const struct sr_dev_driver *driver)
+{
+ return std_dev_clear_with_callback(driver, (std_dev_clear_callback)clear_helper);
+}
+
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
const char *conn;
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
- .dev_clear = std_dev_clear,
+ .dev_clear = dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,
0xa7, 0xf1, 0x06, 0x61, 0x9a, 0xb8, 0x72, 0x88,
};
-static const struct binary_analog_channel rdtech_tc_channels[] = {
- { "V", { 0 + 48, BVT_LE_UINT32, 1e-4, }, 4, SR_MQ_VOLTAGE, SR_UNIT_VOLT },
- { "I", { 0 + 52, BVT_LE_UINT32, 1e-5, }, 5, SR_MQ_CURRENT, SR_UNIT_AMPERE },
- { "D+", { 64 + 32, BVT_LE_UINT32, 1e-2, }, 2, SR_MQ_VOLTAGE, SR_UNIT_VOLT },
- { "D-", { 64 + 36, BVT_LE_UINT32, 1e-2, }, 2, SR_MQ_VOLTAGE, SR_UNIT_VOLT },
- { "E0", { 64 + 12, BVT_LE_UINT32, 1e-3, }, 3, SR_MQ_ENERGY, SR_UNIT_WATT_HOUR },
- { "E1", { 64 + 20, BVT_LE_UINT32, 1e-3, }, 3, SR_MQ_ENERGY, SR_UNIT_WATT_HOUR },
- ALL_ZERO,
+static const struct rdtech_tc_channel_desc rdtech_tc_channels[] = {
+ { "V", { 0 + 48, BVT_LE_UINT32, 1, }, { 100, 1e6, }, 4, SR_MQ_VOLTAGE, SR_UNIT_VOLT },
+ { "I", { 0 + 52, BVT_LE_UINT32, 1, }, { 10, 1e6, }, 5, SR_MQ_CURRENT, SR_UNIT_AMPERE },
+ { "D+", { 64 + 32, BVT_LE_UINT32, 1, }, { 10, 1e3, }, 2, SR_MQ_VOLTAGE, SR_UNIT_VOLT },
+ { "D-", { 64 + 36, BVT_LE_UINT32, 1, }, { 10, 1e3, }, 2, SR_MQ_VOLTAGE, SR_UNIT_VOLT },
+ { "E0", { 64 + 12, BVT_LE_UINT32, 1, }, { 1, 1e3, }, 3, SR_MQ_ENERGY, SR_UNIT_WATT_HOUR },
+ { "E1", { 64 + 20, BVT_LE_UINT32, 1, }, { 1, 1e3, }, 3, SR_MQ_ENERGY, SR_UNIT_WATT_HOUR },
};
static gboolean check_pac_crc(uint8_t *data)
}
devc->channels = rdtech_tc_channels;
+ devc->channel_count = ARRAY_SIZE(rdtech_tc_channels);
devc->dev_info.model_name = g_strndup((const char *)&poll_pkt[OFF_MODEL], LEN_MODEL);
devc->dev_info.fw_ver = g_strndup((const char *)&poll_pkt[OFF_FW_VER], LEN_FW_VER);
devc->dev_info.serial_num = read_u32le(&poll_pkt[OFF_SERIAL]);
{
struct dev_context *devc;
uint8_t poll_pkt[TC_POLL_LEN];
- size_t i;
- GSList *ch;
+ size_t ch_idx;
+ const struct rdtech_tc_channel_desc *pch;
int ret;
+ float v;
devc = sdi->priv;
sr_spew("Received poll packet (len: %zu).", devc->buflen);
return SR_ERR_DATA;
}
- i = 0;
- for (ch = sdi->channels; ch; ch = g_slist_next(ch)) {
- ret = bv_send_analog_channel(sdi, ch->data,
- &devc->channels[i], poll_pkt, TC_POLL_LEN);
- i++;
+ for (ch_idx = 0; ch_idx < devc->channel_count; ch_idx++) {
+ pch = &devc->channels[ch_idx];
+ ret = bv_get_value(&v, &pch->spec, poll_pkt, TC_POLL_LEN);
+ if (ret != SR_OK)
+ return ret;
+ ret = feed_queue_analog_submit(devc->feeds[ch_idx], v, 1);
if (ret != SR_OK)
return ret;
}