X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fteleinfo%2Fapi.c;h=5e1dfba1acd4b8692d6edac5730906f86a8d9dd4;hb=91219afc75c9aa1d0c5e2da5c03343c1e43eb6df;hp=02de164c8dae5e58bf5bec6e05cc357361a870fb;hpb=a0e0bb4149081eda06714f1158639f2dadcfa9d8;p=libsigrok.git diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 02de164c..5e1dfba1 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -30,9 +30,9 @@ static const uint32_t scanopts[] = { 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);