#include "libsigrok-internal.h"
#include "protocol.h"
-static const uint32_t hwopts[] = {
+static const uint32_t scanopts[] = {
SR_CONF_CONN,
SR_CONF_SERIALCOMM,
};
static const uint32_t devopts[] = {
SR_CONF_ENERGYMETER,
- SR_CONF_LIMIT_SAMPLES,
- SR_CONF_LIMIT_MSEC,
SR_CONF_CONTINUOUS,
+ SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
+ SR_CONF_LIMIT_MSEC | SR_CONF_SET,
};
SR_PRIV struct sr_dev_driver teleinfo_driver_info;
if (!serialcomm)
serialcomm = "1200/7e1";
- if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
- return NULL;
- if (serial_open(serial, SERIAL_RDONLY | SERIAL_NONBLOCK) != SR_OK)
+ serial = sr_serial_dev_inst_new(conn, serialcomm);
+
+ if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
return NULL;
sr_info("Probing serial port %s.", conn);
sr_info("Found device on port %s.", conn);
- if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "EDF", "Teleinfo", NULL)))
- goto scan_cleanup;
-
- if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
- sr_err("Device context malloc failed.");
- goto scan_cleanup;
- }
-
+ sdi = g_malloc0(sizeof(struct sr_dev_inst));
+ sdi->status = SR_ST_INACTIVE;
+ sdi->vendor = g_strdup("EDF");
+ sdi->model = g_strdup("Teleinfo");
+ devc = g_malloc0(sizeof(struct dev_context));
devc->optarif = teleinfo_get_optarif(buf);
-
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = di;
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P");
sdi->channels = g_slist_append(sdi->channels, ch);
if (devc->optarif == OPTARIF_BASE) {
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "BASE")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "BASE");
sdi->channels = g_slist_append(sdi->channels, ch);
} else if (devc->optarif == OPTARIF_HC) {
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HP")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HP");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HC")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HC");
sdi->channels = g_slist_append(sdi->channels, ch);
} else if (devc->optarif == OPTARIF_EJP) {
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HN")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HN");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPM")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPM");
sdi->channels = g_slist_append(sdi->channels, ch);
} else if (devc->optarif == OPTARIF_BBR) {
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJB")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJB");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJW")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJW");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJR")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJR");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJB")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJB");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJW")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJW");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJR")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJR");
sdi->channels = g_slist_append(sdi->channels, ch);
}
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "IINST")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "IINST");
sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "PAPP")))
- goto scan_cleanup;
+ ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "PAPP");
sdi->channels = g_slist_append(sdi->channels, ch);
drvc->instances = g_slist_append(drvc->instances, sdi);
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- hwopts, ARRAY_SIZE(hwopts), sizeof(uint32_t));
+ scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,