X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fmic-985xx%2Fapi.c;h=4c093148750de14b6598e61466c1de2d21ce33d8;hb=3a277f3b2b01da3d7d1e26ddbb30471db68fc11c;hp=b8983a6dab69aa336baf78edad383d04cfa89af3;hpb=0cd8e23140612703406a57316bb0a507fb8f1994;p=libsigrok.git diff --git a/hardware/mic-985xx/api.c b/hardware/mic-985xx/api.c index b8983a6d..4c093148 100644 --- a/hardware/mic-985xx/api.c +++ b/hardware/mic-985xx/api.c @@ -20,26 +20,31 @@ #include "protocol.h" -static const int hwopts[] = { +static const int32_t hwopts[] = { SR_CONF_CONN, SR_CONF_SERIALCOMM, - 0, }; -static const int hwcaps[] = { +static const int32_t hwcaps[] = { SR_CONF_THERMOMETER, SR_CONF_HYGROMETER, SR_CONF_LIMIT_SAMPLES, SR_CONF_LIMIT_MSEC, SR_CONF_CONTINUOUS, - 0, }; +SR_PRIV struct sr_dev_driver mic_98581_driver_info; SR_PRIV struct sr_dev_driver mic_98583_driver_info; SR_PRIV const struct mic_dev_info mic_devs[] = { { - "MIC", "98583", "38400/8n2", 32000, TRUE, TRUE, + "MIC", "98581", "38400/8n2", 32000, TRUE, FALSE, 6, + packet_valid_temp, + &mic_98581_driver_info, receive_data_MIC_98581, + }, + { + "MIC", "98583", "38400/8n2", 32000, TRUE, TRUE, 10, + packet_valid_temp_hum, &mic_98583_driver_info, receive_data_MIC_98583, }, }; @@ -49,6 +54,7 @@ static int clear_instances(int idx) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; + struct sr_serial_dev_inst *serial; GSList *l; struct sr_dev_driver *di; @@ -62,7 +68,8 @@ static int clear_instances(int idx) continue; if (!(devc = sdi->priv)) continue; - sr_serial_dev_inst_free(devc->serial); + serial = sdi->conn; + sr_serial_dev_inst_free(serial); sr_dev_inst_free(sdi); } @@ -113,7 +120,8 @@ static GSList *scan(const char *conn, const char *serialcomm, int idx) goto scan_cleanup; } - devc->serial = serial; + sdi->inst_type = SR_INST_SERIAL; + sdi->conn = serial; sdi->priv = devc; sdi->driver = mic_devs[idx].di; @@ -122,9 +130,11 @@ static GSList *scan(const char *conn, const char *serialcomm, int idx) goto scan_cleanup; sdi->probes = g_slist_append(sdi->probes, probe); - if (!(probe = sr_probe_new(1, SR_PROBE_ANALOG, TRUE, "Humidity"))) - goto scan_cleanup; - sdi->probes = g_slist_append(sdi->probes, probe); + if (mic_devs[idx].has_humidity) { + if (!(probe = sr_probe_new(1, SR_PROBE_ANALOG, TRUE, "Humidity"))) + goto scan_cleanup; + sdi->probes = g_slist_append(sdi->probes, probe); + } drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); @@ -146,10 +156,10 @@ static GSList *hw_scan(GSList *options, int idx) src = l->data; switch (src->key) { case SR_CONF_CONN: - conn = src->value; + conn = g_variant_get_string(src->data, NULL); break; case SR_CONF_SERIALCOMM: - serialcomm = src->value; + serialcomm = g_variant_get_string(src->data, NULL); break; } } @@ -169,20 +179,15 @@ static GSList *hw_scan(GSList *options, int idx) static GSList *hw_dev_list(int idx) { - struct drv_context *drvc; - - drvc = mic_devs[idx].di->priv; - - return drvc->instances; + return ((struct drv_context *)(mic_devs[idx].di->priv))->instances; } static int hw_dev_open(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - devc = sdi->priv; + struct sr_serial_dev_inst *serial; - if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + serial = sdi->conn; + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return SR_ERR; sdi->status = SR_ST_ACTIVE; @@ -192,12 +197,11 @@ static int hw_dev_open(struct sr_dev_inst *sdi) static int hw_dev_close(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - devc = sdi->priv; + struct sr_serial_dev_inst *serial; - if (devc->serial && devc->serial->fd != -1) { - serial_close(devc->serial); + serial = sdi->conn; + if (serial && serial->fd != -1) { + serial_close(serial); sdi->status = SR_ST_INACTIVE; } @@ -211,47 +215,48 @@ static int hw_cleanup(int idx) return SR_OK; } -static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) { struct dev_context *devc; if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; + return SR_ERR_DEV_CLOSED; devc = sdi->priv; switch (id) { case SR_CONF_LIMIT_SAMPLES: - devc->limit_samples = *(const uint64_t *)value; + devc->limit_samples = g_variant_get_uint64(data); sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: - devc->limit_msec = *(const uint64_t *)value; + devc->limit_msec = g_variant_get_uint64(data); sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec); break; default: - sr_err("Unknown config: %d.", id); - return SR_ERR_ARG; + return SR_ERR_NA; } return SR_OK; } -static int config_list(int key, const void **data, const struct sr_dev_inst *sdi) +static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) { (void)sdi; switch (key) { case SR_CONF_SCAN_OPTIONS: - *data = hwopts; + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); break; case SR_CONF_DEVICE_OPTIONS: - *data = hwcaps; + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); break; default: - return SR_ERR_ARG; + return SR_ERR_NA; } return SR_OK; @@ -260,29 +265,23 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data, int idx) { - struct sr_datafeed_packet packet; - struct sr_datafeed_header header; struct dev_context *devc; + struct sr_serial_dev_inst *serial; - devc = sdi->priv; + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; + devc = sdi->priv; devc->cb_data = cb_data; - - sr_dbg("Starting acquisition."); - devc->num_samples = 0; devc->starttime = g_get_monotonic_time(); /* Send header packet to the session bus. */ - sr_dbg("Sending SR_DF_HEADER."); - packet.type = SR_DF_HEADER; - packet.payload = (uint8_t *)&header; - header.feed_version = 1; - gettimeofday(&header.starttime, NULL); - sr_session_send(devc->cb_data, &packet); + std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); /* Poll every 100ms, or whenever some data comes in. */ - sr_source_add(devc->serial->fd, G_IO_IN, 100, + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 100, mic_devs[idx].receive_data, (void *)sdi); return SR_OK; @@ -290,27 +289,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { - struct sr_datafeed_packet packet; - struct dev_context *devc; - - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device inactive, can't stop acquisition."); - return SR_ERR; - } - - devc = sdi->priv; - - sr_dbg("Stopping acquisition."); - - sr_source_remove(devc->serial->fd); - hw_dev_close((struct sr_dev_inst *)sdi); - - /* Send end packet to the session bus. */ - sr_dbg("Sending SR_DF_END."); - packet.type = SR_DF_END; - sr_session_send(cb_data, &packet); - - return SR_OK; + return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close, + sdi->conn, DRIVER_LOG_DOMAIN); } /* Driver-specific API function wrappers */ @@ -355,4 +335,5 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \ .priv = NULL, \ }; +DRV(mic_98581, MIC_98581, "mic-98581", "MIC 98581") DRV(mic_98583, MIC_98583, "mic-98583", "MIC 98583")