static int run_one(cmd_args_t *args, uint32_t id, uint32_t T, uint32_t N, uint64_t C, uint64_t S, uint64_t O, uint64_t B) { zpios_cmd_t *cmd; int rc, rc2, cmd_size; dev_clear(); cmd_size = sizeof (zpios_cmd_t) + ((T + N + 1) * sizeof (zpios_stats_t)); cmd = (zpios_cmd_t *)malloc(cmd_size); if (cmd == NULL) return (ENOMEM); memset(cmd, 0, cmd_size); cmd->cmd_magic = ZPIOS_CMD_MAGIC; strncpy(cmd->cmd_pool, args->pool, ZPIOS_NAME_SIZE - 1); strncpy(cmd->cmd_pre, args->pre, ZPIOS_PATH_SIZE - 1); strncpy(cmd->cmd_post, args->post, ZPIOS_PATH_SIZE - 1); strncpy(cmd->cmd_log, args->log, ZPIOS_PATH_SIZE - 1); cmd->cmd_id = id; cmd->cmd_chunk_size = C; cmd->cmd_thread_count = T; cmd->cmd_region_count = N; cmd->cmd_region_size = S; cmd->cmd_offset = O; cmd->cmd_block_size = B; cmd->cmd_region_noise = args->regionnoise; cmd->cmd_chunk_noise = args->chunknoise; cmd->cmd_thread_delay = args->thread_delay; cmd->cmd_flags = args->flags; cmd->cmd_data_size = (T + N + 1) * sizeof (zpios_stats_t); rc = ioctl(zpiosctl_fd, ZPIOS_CMD, cmd); if (rc) args->rc = errno; print_stats(args, cmd); if (args->verbose) { rc2 = read(zpiosctl_fd, zpios_buffer, zpios_buffer_size - 1); if (rc2 < 0) { fprintf(stdout, "Error reading results: %d\n", rc2); } else if ((rc2 > 0) && (strlen(zpios_buffer) > 0)) { fprintf(stdout, "\n%s\n", zpios_buffer); fflush(stdout); } } free(cmd); return (rc); }
static int cleanup(const struct sr_dev_driver *di) { struct drv_context *drvc = di->context; int ret; ret = dev_clear(di); g_free(drvc); return ret; }
static int test_run(cmd_args_t *args, test_t *test) { subsystem_t *sub = test->test_sub; splat_cmd_t *cmd; int rc, cmd_size; dev_clear(); cmd_size = sizeof(*cmd); cmd = (splat_cmd_t *)malloc(cmd_size); if (cmd == NULL) return -ENOMEM; memset(cmd, 0, cmd_size); cmd->cmd_magic = SPLAT_CMD_MAGIC; cmd->cmd_subsystem = sub->sub_desc.id; cmd->cmd_test = test->test_desc.id; cmd->cmd_data_size = 0; /* Unused feature */ fprintf(stdout, "%*s:%-*s ", SPLAT_NAME_SIZE, sub->sub_desc.name, SPLAT_NAME_SIZE, test->test_desc.name); fflush(stdout); rc = ioctl(splatctl_fd, SPLAT_CMD, cmd); if (args->args_do_color) { fprintf(stdout, "%s %s\n", rc ? COLOR_RED "Fail" COLOR_RESET : COLOR_GREEN "Pass" COLOR_RESET, rc ? strerror(errno) : ""); } else { fprintf(stdout, "%s %s\n", rc ? "Fail" : "Pass", rc ? strerror(errno) : ""); } fflush(stdout); free(cmd); if ((args->args_verbose == 1 && rc) || (args->args_verbose >= 2)) { if ((rc = read(splatctl_fd, splat_buffer, splat_buffer_size - 1)) < 0) { fprintf(stdout, "Error reading results: %d\n", rc); } else { fprintf(stdout, "\n%s\n", splat_buffer); fflush(stdout); } } return rc; }
static int dev_init(void) { int rc; zpiosctl_fd = open(ZPIOS_DEV, O_RDONLY); if (zpiosctl_fd == -1) { fprintf(stderr, "Unable to open %s: %d\n" "Is the zpios module loaded?\n", ZPIOS_DEV, errno); rc = errno; goto error; } if ((rc = dev_clear())) goto error; if ((rc = dev_size(0)) < 0) goto error; zpios_buffer_size = rc; zpios_buffer = (char *)malloc(zpios_buffer_size); if (zpios_buffer == NULL) { rc = ENOMEM; goto error; } memset(zpios_buffer, 0, zpios_buffer_size); return (0); error: if (zpiosctl_fd != -1) { if (close(zpiosctl_fd) == -1) { fprintf(stderr, "Unable to close %s: %d\n", ZPIOS_DEV, errno); } } return (rc); }
/** * Main function. Initializes the USB-device, parses commandline-parameters and * calls the functions that communicate with the device. * \param argc Number of arguments. * \param argv Arguments. * \return Error code. */ int main(int argc, char **argv) { usb_dev_handle *handle = NULL; if (argc < 2) { usage(argv[0]); exit(1); } usb_init(); if (usbOpenDevice (&handle, USBDEV_SHARED_VENDOR, "www.schatenseite.de", USBDEV_SHARED_PRODUCT, "USB-LED-Fader") != 0) { fprintf(stderr, "Could not find USB device \"USB-LED-Fader\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT); exit(1); } /* We have searched all devices on all busses for our USB device above. Now * try to open it and perform the vendor specific control operations for the * function requested by the user. */ if (strcmp(argv[1], "test") == 0) { dev_test(handle, argc, argv); } else if (strcmp(argv[1], "set") == 0) { dev_set(handle, argc, argv); } else if (strcmp(argv[1], "clear") == 0) { dev_clear(handle, argc, argv); } else if (strcmp(argv[1], "status") == 0) { dev_status(handle, argc, argv); } else if (strcmp(argv[1], "reset") == 0) { dev_reset(handle, argc, argv); } else if (strcmp(argv[1], "show") == 0) { dev_show(handle, argc, argv); } else { usage(argv[0]); exit(1); } usb_close(handle); return 0; }
static int cleanup(const struct sr_dev_driver *di) { return dev_clear(di); }
static int cleanup(void) { return dev_clear(); }
static int cleanup(const struct sr_dev_driver *di) { dev_clear(di); return SR_OK; }
static int cleanup(int dmm) { return dev_clear(dmm); }
static int cleanup(int idx) { return dev_clear(idx); }
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"), }; struct sr_config default_modbusaddr = { .key = SR_CONF_MODBUSADDR, .data = g_variant_new_uint64(1), }; GSList *opts = options, *devices; if (!g_slist_find_custom(options, &default_serialcomm, config_compare)) opts = g_slist_prepend(opts, &default_serialcomm); if (!g_slist_find_custom(options, &default_modbusaddr, config_compare)) opts = g_slist_prepend(opts, &default_modbusaddr); devices = sr_modbus_scan(di->context, opts, probe_device); while (opts != options) opts = g_slist_delete_link(opts, opts); g_variant_unref(default_serialcomm.data); g_variant_unref(default_modbusaddr.data); return devices; } static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->context))->instances; } static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, g_free); } static int dev_open(struct sr_dev_inst *sdi) { struct sr_modbus_dev_inst *modbus = sdi->conn; if (sr_modbus_open(modbus) < 0) return SR_ERR; sdi->status = SR_ST_ACTIVE; maynuo_m97_set_bit(modbus, PC1, 1); return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_modbus_dev_inst *modbus; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; modbus = sdi->conn; if (modbus) { devc = sdi->priv; if (devc->expecting_registers) { /* 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); } maynuo_m97_set_bit(modbus, PC1, 0); if (sr_modbus_close(modbus) < 0) return SR_ERR; sdi->status = SR_ST_INACTIVE; } return SR_OK; } static int cleanup(const struct sr_dev_driver *di) { return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; struct sr_modbus_dev_inst *modbus; enum maynuo_m97_mode mode; int ret, ivalue; float fvalue; (void)cg; modbus = sdi->conn; devc = sdi->priv; ret = SR_OK; switch (key) { case SR_CONF_LIMIT_SAMPLES: *data = g_variant_new_uint64(devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: *data = g_variant_new_uint64(devc->limit_msec); break; case SR_CONF_ENABLED: if ((ret = maynuo_m97_get_bit(modbus, ISTATE, &ivalue)) == SR_OK) *data = g_variant_new_boolean(ivalue); break; case SR_CONF_REGULATION: if ((ret = maynuo_m97_get_bit(modbus, UNREG, &ivalue)) != SR_OK) break; if (ivalue) *data = g_variant_new_string("UR"); else if ((ret = maynuo_m97_get_mode(modbus, &mode)) == SR_OK) *data = g_variant_new_string(maynuo_m97_mode_to_str(mode)); break; case SR_CONF_VOLTAGE: if ((ret = maynuo_m97_get_float(modbus, U, &fvalue)) == SR_OK) *data = g_variant_new_double(fvalue); break; case SR_CONF_VOLTAGE_TARGET: if ((ret = maynuo_m97_get_float(modbus, UFIX, &fvalue)) == SR_OK) *data = g_variant_new_double(fvalue); break; case SR_CONF_CURRENT: if ((ret = maynuo_m97_get_float(modbus, I, &fvalue)) == SR_OK) *data = g_variant_new_double(fvalue); break; case SR_CONF_CURRENT_LIMIT: if ((ret = maynuo_m97_get_float(modbus, IFIX, &fvalue)) == SR_OK) *data = g_variant_new_double(fvalue); break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: *data = g_variant_new_boolean(TRUE); break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE: if ((ret = maynuo_m97_get_bit(modbus, UOVER, &ivalue)) == SR_OK) *data = g_variant_new_boolean(ivalue); break; case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: if ((ret = maynuo_m97_get_float(modbus, UMAX, &fvalue)) == SR_OK) *data = g_variant_new_double(fvalue); break; case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: *data = g_variant_new_boolean(TRUE); break; case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE: if ((ret = maynuo_m97_get_bit(modbus, IOVER, &ivalue)) == SR_OK) *data = g_variant_new_boolean(ivalue); break; case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: if ((ret = maynuo_m97_get_float(modbus, IMAX, &fvalue)) == SR_OK) *data = g_variant_new_double(fvalue); break; case SR_CONF_OVER_TEMPERATURE_PROTECTION: *data = g_variant_new_boolean(TRUE); break; case SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE: if ((ret = maynuo_m97_get_bit(modbus, HEAT, &ivalue)) == SR_OK) *data = g_variant_new_boolean(ivalue); break; default: return SR_ERR_NA; } return ret; } static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; struct sr_modbus_dev_inst *modbus; int ret; (void)data; (void)cg; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; modbus = sdi->conn; devc = sdi->priv; ret = SR_OK; switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); break; case SR_CONF_ENABLED: ret = maynuo_m97_set_input(modbus, g_variant_get_boolean(data)); break; case SR_CONF_VOLTAGE_TARGET: ret = maynuo_m97_set_float(modbus, UFIX, g_variant_get_double(data)); break; case SR_CONF_CURRENT_LIMIT: ret = maynuo_m97_set_float(modbus, IFIX, g_variant_get_double(data)); break; case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: ret = maynuo_m97_set_float(modbus, UMAX, g_variant_get_double(data)); break; case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: ret = maynuo_m97_set_float(modbus, IMAX, g_variant_get_double(data)); break; default: ret = SR_ERR_NA; } return ret; } static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; GVariantBuilder gvb; int ret; /* Always available, even without sdi. */ if (key == SR_CONF_SCAN_OPTIONS) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); return SR_OK; } else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); return SR_OK; } if (!sdi) return SR_ERR_ARG; devc = sdi->priv; ret = SR_OK; if (!cg) { /* No channel group: global options. */ switch (key) { case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); break; default: return SR_ERR_NA; } } else { switch (key) { case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); break; case SR_CONF_VOLTAGE_TARGET: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, write resolution. */ g_variant_builder_add_value(&gvb, g_variant_new_double(0.0)); g_variant_builder_add_value(&gvb, g_variant_new_double(devc->model->max_voltage)); g_variant_builder_add_value(&gvb, g_variant_new_double(0.001)); *data = g_variant_builder_end(&gvb); break; case SR_CONF_CURRENT_LIMIT: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, step. */ g_variant_builder_add_value(&gvb, g_variant_new_double(0.0)); g_variant_builder_add_value(&gvb, g_variant_new_double(devc->model->max_current)); g_variant_builder_add_value(&gvb, g_variant_new_double(0.0001)); *data = g_variant_builder_end(&gvb); break; default: return SR_ERR_NA; } } return ret; } static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct sr_modbus_dev_inst *modbus; int ret; (void)cb_data; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; modbus = sdi->conn; devc = sdi->priv; if ((ret = sr_modbus_source_add(sdi->session, modbus, G_IO_IN, 10, maynuo_m97_receive_data, (void *)sdi)) != SR_OK) return ret; /* Send header packet to the session bus. */ std_session_send_df_header(sdi, LOG_PREFIX); devc->num_samples = 0; devc->starttime = g_get_monotonic_time(); return maynuo_m97_capture_start(sdi); } static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_modbus_dev_inst *modbus; struct sr_datafeed_packet packet; (void)cb_data; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; /* End of last frame. */ packet.type = SR_DF_END; sr_session_send(sdi, &packet); modbus = sdi->conn; sr_modbus_source_remove(sdi->session, modbus); return SR_OK; } SR_PRIV struct sr_dev_driver maynuo_m97_driver_info = { .name = "maynuo-m97", .longname = "maynuo M97/M98 series", .api_version = 1, .init = init, .cleanup = cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list, .dev_open = dev_open, .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, .context = NULL, };
static int dev_init(void) { ListIterator i; subsystem_t *sub; int rc; splatctl_fd = open(SPLAT_DEV, O_RDONLY); if (splatctl_fd == -1) { fprintf(stderr, "Unable to open %s: %d\n" "Is the splat module loaded?\n", SPLAT_DEV, errno); rc = errno; goto error; } /* Determine kernel module version string */ memset(splat_version, 0, VERSION_SIZE); if ((rc = read(splatctl_fd, splat_version, VERSION_SIZE - 1)) == -1) goto error; if ((rc = dev_clear())) goto error; if ((rc = dev_size(0)) < 0) goto error; splat_buffer_size = rc; splat_buffer = (char *)malloc(splat_buffer_size); if (splat_buffer == NULL) { rc = -ENOMEM; goto error; } memset(splat_buffer, 0, splat_buffer_size); /* Determine available subsystems */ if ((rc = subsystem_setup()) != 0) goto error; /* Determine available tests for all subsystems */ i = list_iterator_create(subsystems); while ((sub = list_next(i))) { if ((rc = test_setup(sub)) != 0) { list_iterator_destroy(i); goto error; } } list_iterator_destroy(i); return 0; error: if (splatctl_fd != -1) { if (close(splatctl_fd) == -1) { fprintf(stderr, "Unable to close %s: %d\n", SPLAT_DEV, errno); } } return rc; }
static int usr_input(void) /* get user input and process it */ { VIEW vparams; char cmd[256]; register char *args; register int i; if (fgets(cmd, sizeof(cmd), sstdin) == NULL) { fclose(sstdin); sstdin = NULL; return(-1); } if (*cmd == '\n') return(DC_RESUME); for (args = cmd; *args && !isspace(*args); args++) ; while (isspace(*args)) *args++ = '\0'; if (*args && args[i=strlen(args)-1] == '\n') args[i] = '\0'; for (i = 0; i < DC_NCMDS; i++) if (!strcmp(cmd, cmdlist[i])) break; if (i >= DC_NCMDS) { dev_auxcom(cmd, args); return(-1); } switch (i) { case DC_SETVIEW: /* set the view */ vparams = odev.v; if (!sscanview(&vparams, args)) error(COMMAND, "missing view options"); else new_view(&vparams); break; case DC_GETVIEW: /* print the current view */ printview(); break; case DC_LASTVIEW: /* restore previous view */ new_view(NULL); break; case DC_FOCUS: /* set focus frame */ set_focus(args); break; case DC_PAUSE: /* pause the current calculation */ case DC_RESUME: /* resume the calculation */ /* handled in main() */ break; case DC_REDRAW: /* redraw from server */ imm_mode = beam_sync(1) > 0; dev_clear(); break; case DC_KILL: /* kill rtrace process(es) */ serv_request(DR_KILL, 0, NULL); break; case DC_CLOBBER: /* clobber holodeck */ serv_request(DR_CLOBBER, 0, NULL); break; case DC_RESTART: /* restart rtrace */ serv_request(DR_RESTART, 0, NULL); break; case DC_QUIT: /* quit request */ serv_request(DR_SHUTDOWN, 0, NULL); break; default: error(CONSISTENCY, "bad command id in usr_input"); } return(i); }