X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fteleinfo%2Fapi.c;h=5e1dfba1acd4b8692d6edac5730906f86a8d9dd4;hb=91219afc75c9aa1d0c5e2da5c03343c1e43eb6df;hp=9b487f19341159932ddd98c2de80d639cf7f2989;hpb=f254bc4bba68d2cade0c8f7993d8fa8d3d9b556a;p=libsigrok.git diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 9b487f19..5e1dfba1 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -23,16 +23,16 @@ #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; @@ -74,9 +74,9 @@ static GSList *scan(GSList *options) 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); @@ -92,70 +92,52 @@ static GSList *scan(GSList *options) 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); @@ -217,7 +199,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * 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,