X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmaynuo-m97%2Fapi.c;h=aae0d094a4a23a15e123c4011b9f0bf381752b42;hb=c3cd66a00cdb4afbd43108563d979eebfbafaf69;hp=b99f8eeb2a565193f516e1f7437ed40c88c1f97a;hpb=45b75c368fece1faa39c96d662de8fc7075db25f;p=libsigrok.git diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index b99f8eeb..aae0d094 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -53,9 +53,11 @@ static const uint32_t devopts_cg[] = { SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE | SR_CONF_GET, }; -/* The IDs in this list are only guessed and needs to be verified - against some real hardware. If at least a few of them matches, - it will probably be safe to enable the others. */ +/* + * The IDs in this list are only guessed and needs to be verified + * against some real hardware. If at least a few of them matches, + * it will probably be safe to enable the others. + */ static const struct maynuo_m97_model supported_models[] = { // { 53, "M9711" , 30, 150, 150 }, // { 54, "M9712" , 30, 150, 300 }, @@ -109,12 +111,7 @@ static const struct maynuo_m97_model supported_models[] = { // { 102, "M9812B" , 15, 500, 300 }, }; -SR_PRIV struct sr_dev_driver maynuo_m97_driver_info; - -static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, di, LOG_PREFIX); -} +static struct sr_dev_driver maynuo_m97_driver_info; static struct sr_dev_inst *probe_device(struct sr_modbus_dev_inst *modbus) { @@ -140,7 +137,7 @@ static struct sr_dev_inst *probe_device(struct sr_modbus_dev_inst *modbus) } sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_ACTIVE; + sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup("Maynuo"); sdi->model = g_strdup(model->name); sdi->version = g_strdup_printf("v%d.%d", version/10, version%10); @@ -175,12 +172,12 @@ static int config_compare(gconstpointer a, gconstpointer b) static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_config default_serialcomm = { - .key = SR_CONF_SERIALCOMM, - .data = g_variant_new_string("9600/8n1"), + .key = SR_CONF_SERIALCOMM, + .data = g_variant_new_string("9600/8n1"), }; struct sr_config default_modbusaddr = { - .key = SR_CONF_MODBUSADDR, - .data = g_variant_new_uint64(1), + .key = SR_CONF_MODBUSADDR, + .data = g_variant_new_uint64(1), }; GSList *opts = options, *devices; @@ -229,8 +226,7 @@ static int dev_close(struct sr_dev_inst *sdi) /* Wait for the last data that was requested from the device. */ uint16_t registers[devc->expecting_registers]; sr_modbus_read_holding_registers(modbus, -1, - devc->expecting_registers, - registers); + devc->expecting_registers, registers); } maynuo_m97_set_bit(modbus, PC1, 0); @@ -336,9 +332,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - modbus = sdi->conn; devc = sdi->priv; @@ -439,9 +432,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_modbus_dev_inst *modbus; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - modbus = sdi->conn; devc = sdi->priv; @@ -450,7 +440,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return ret; sr_sw_limits_acquisition_start(&devc->limits); - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); return maynuo_m97_capture_start(sdi); } @@ -459,10 +449,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct sr_modbus_dev_inst *modbus; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - std_session_send_df_end(sdi, LOG_PREFIX); + std_session_send_df_end(sdi); modbus = sdi->conn; sr_modbus_source_remove(sdi->session, modbus); @@ -470,11 +457,11 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) return SR_OK; } -SR_PRIV struct sr_dev_driver maynuo_m97_driver_info = { +static struct sr_dev_driver maynuo_m97_driver_info = { .name = "maynuo-m97", .longname = "maynuo M97/M98 series", .api_version = 1, - .init = init, + .init = std_init, .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, @@ -487,3 +474,4 @@ SR_PRIV struct sr_dev_driver maynuo_m97_driver_info = { .dev_acquisition_stop = dev_acquisition_stop, .context = NULL, }; +SR_REGISTER_DEV_DRIVER(maynuo_m97_driver_info);