[DS1000] = {VENDOR(RIGOL), "DS1000", PROTOCOL_V2, FORMAT_IEEE488_2, {50, 1}, {2, 1000}, 12, 600, 1048576}, [DS2000] = {VENDOR(RIGOL), "DS2000", PROTOCOL_V3, FORMAT_IEEE488_2, {500, 1}, {500, 1000000}, 14, 1400, 14000}, [DS2000A] = {VENDOR(RIGOL), "DS2000A", PROTOCOL_V3, FORMAT_IEEE488_2, {1000, 1}, {500, 1000000}, 14, 1400, 14000}, [DSO1000] = {VENDOR(AGILENT), "DSO1000", PROTOCOL_V3, FORMAT_IEEE488_2, {50, 1}, {2, 1000}, 12, 600, 20480}, [DS1000Z] = {VENDOR(RIGOL), "DS1000Z", PROTOCOL_V4, FORMAT_IEEE488_2, {50, 1}, {1, 1000}, 12, 1200, 12000000}, }; #define SERIES(x) &supported_series[x] /* series, model, min timebase, analog channels, digital */ static const struct rigol_ds_model supported_models[] = { {SERIES(VS5000), "VS5022", {20, 1000000000}, 2, false}, {SERIES(VS5000), "VS5042", {10, 1000000000}, 2, false}, {SERIES(VS5000), "VS5062", {5, 1000000000}, 2, false}, {SERIES(VS5000), "VS5102", {2, 1000000000}, 2, false}, {SERIES(VS5000), "VS5202", {2, 1000000000}, 2, false}, {SERIES(VS5000), "VS5022D", {20, 1000000000}, 2, true}, {SERIES(VS5000), "VS5042D", {10, 1000000000}, 2, true}, {SERIES(VS5000), "VS5062D", {5, 1000000000}, 2, true}, {SERIES(VS5000), "VS5102D", {2, 1000000000}, 2, true}, {SERIES(VS5000), "VS5202D", {2, 1000000000}, 2, true}, {SERIES(DS1000), "DS1052E", {5, 1000000000}, 2, false}, {SERIES(DS1000), "DS1102E", {2, 1000000000}, 2, false}, {SERIES(DS1000), "DS1152E", {2, 1000000000}, 2, false}, {SERIES(DS1000), "DS1052D", {5, 1000000000}, 2, true}, {SERIES(DS1000), "DS1102D", {2, 1000000000}, 2, true}, {SERIES(DS1000), "DS1152D", {2, 1000000000}, 2, true},
static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) { struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_scpi_hw_info *hw_info; struct sr_channel *ch; long n[3]; unsigned int i; const struct rigol_ds_model *model = NULL; gchar *channel_name, **version; if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { sr_info("Couldn't get IDN response, retrying."); sr_scpi_close(scpi); sr_scpi_open(scpi); if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { sr_info("Couldn't get IDN response."); return NULL; } } for (i = 0; i < ARRAY_SIZE(supported_models); i++) { if (!g_ascii_strcasecmp(hw_info->manufacturer, supported_models[i].series->vendor->full_name) && !strcmp(hw_info->model, supported_models[i].name)) { model = &supported_models[i]; break; } } if (!model) { sr_scpi_hw_info_free(hw_info); return NULL; } sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->vendor = g_strdup(model->series->vendor->name); sdi->model = g_strdup(model->name); sdi->version = g_strdup(hw_info->firmware_version); sdi->conn = scpi; sdi->driver = &rigol_ds_driver_info; sdi->inst_type = SR_INST_SCPI; sdi->serial_num = g_strdup(hw_info->serial_number); devc = g_malloc0(sizeof(struct dev_context)); devc->limit_frames = 0; devc->model = model; devc->format = model->series->format; /* DS1000 models with firmware before 0.2.4 used the old data format. */ if (model->series == SERIES(DS1000)) { version = g_strsplit(hw_info->firmware_version, ".", 0); do { if (!version[0] || !version[1] || !version[2]) break; if (version[0][0] == 0 || version[1][0] == 0 || version[2][0] == 0) break; for (i = 0; i < 3; i++) { if (sr_atol(version[i], &n[i]) != SR_OK) break; } if (i != 3) break; scpi->firmware_version = n[0] * 100 + n[1] * 10 + n[2]; if (scpi->firmware_version < 24) { sr_dbg("Found DS1000 firmware < 0.2.4, using raw data format."); devc->format = FORMAT_RAW; } break; } while (0); g_strfreev(version); } sr_scpi_hw_info_free(hw_info); devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) * model->analog_channels); for (i = 0; i < model->analog_channels; i++) { channel_name = g_strdup_printf("CH%d", i + 1); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name); devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); devc->analog_groups[i]->name = channel_name; devc->analog_groups[i]->channels = g_slist_append(NULL, ch); sdi->channel_groups = g_slist_append(sdi->channel_groups, devc->analog_groups[i]); } if (devc->model->has_digital) { devc->digital_group = g_malloc0(sizeof(struct sr_channel_group)); for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) { channel_name = g_strdup_printf("D%d", i); ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); g_free(channel_name); devc->digital_group->channels = g_slist_append( devc->digital_group->channels, ch); } devc->digital_group->name = g_strdup("LA"); sdi->channel_groups = g_slist_append(sdi->channel_groups, devc->digital_group); } for (i = 0; i < NUM_TIMEBASE; i++) { if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2]))) devc->timebases = &timebases[i]; if (!memcmp(&devc->model->series->max_timebase, &timebases[i], sizeof(uint64_t[2]))) devc->num_timebases = &timebases[i] - devc->timebases + 1; } for (i = 0; i < NUM_VDIV; i++) { if (!memcmp(&devc->model->series->min_vdiv, &vdivs[i], sizeof(uint64_t[2]))) { devc->vdivs = &vdivs[i]; devc->num_vdivs = NUM_VDIV - i; } } devc->buffer = g_malloc(ACQ_BUFFER_SIZE); devc->data = g_malloc(ACQ_BUFFER_SIZE * sizeof(float)); devc->data_source = DATA_SOURCE_LIVE; sdi->priv = devc; return sdi; }
static INT ranbinom(long n, double pp) { static double psave = -1.0, xnp, xnpq, qn, p, q, r, g; static double p1, p2, p3, p4, c; static double xm, xr, xl, xlr, xll, fm; static INT nsave = -1, m; double f; double u, v, x; double amaxp, ynorm, alv; INT i, ix, k; WHERE("ranbinom"); /* determine appropriate algorithm and whether setup is necessary */ if (pp != psave || n != nsave) { /* *****setup, perform only when parameters change */ nsave = n; psave = pp; p = (psave <= 0.5) ? psave : 1.0 - psave; q = 1.0 - p; xnp = n*p; if (xnp < 30.0) { /* inverse cdf logic for mean less than 30 */ qn = pow(q, (double) n); r = p/q; g = r*(n + 1); } /*if (xnp < 30.0) */ else { double ffm = xnp + p; double al; m = (INT) ffm; fm = (double) m; /* floor(ffm) */ xnpq = xnp*q; p1 = (INT) (2.195*sqrt(xnpq) - 4.6*q) + 0.5; xm = fm + 0.5; xl = xm - p1; xr = xm + p1; c = 0.134 + 20.5/(15.3 + fm); al = (ffm - xl)/(ffm - xl*p); xll = al*(1.0 + .5*al); al = (xr - ffm)/(xr*q); xlr = al*(1.0 + .5*al); p2 = p1*(1.0 + c + c); p3 = p2 + c/xll; p4 = p3 + c/xlr; } /*if (xnp < 30.0){}else{}*/ } /*if (pp != psave || n != nsave)*/ if (xnp < 30.0) { int done = 0; while (!done) { ix = 0; f = qn; u = rand(iseed); while (1) { if (u < f) { done = 1; break; } if (ix > 110) { break; } u -= f; ix++; f *= g/ix - r; } /*while (1)*/ } /*while (!done)*/ } /*if (xnp < 30.0)*/ else { while (1) { /* *****generate variate */ u = rand(iseed)*p4; /*2*/ v = rand(iseed); if (u <= p1) { /* triangular region */ ix = (INT) (xm - p1*v + u); break; } if (u <= p2) /*3*/ { /* parallelogram region */ x = xl + (u - p1)/c; v = v*c + 1.0 - fabs(xm - x)/p1; if (v > 1.0 || v <= 0.0) { continue; } ix = (INT) x; } /*if (u <= p2) */ else { if (u > p3) /*4*/ { /*5*/ /* right tail */ ix = xr - log(v)/xlr; if (ix > n) { continue; } v *= (u - p3)*xlr; } /*if (u > p3)*/ else { /* left tail */ ix = xl + log(v)/xll; if (ix < 0) { continue; } v *= (u - p2)*xll; } } /*if (u <= p2) {}else{}*/ /* *****determine appropriate way to perform accept/reject test */ k = labs(ix - m); /*6*/ if (k <= 20 || k >= xnpq/2 - 1) { /* explicit evaluation */ f = 1.0; r = p/q; g = (n + 1)*r; if (m < ix) { for (i = m + 1;i <= ix ;i++) { f *= g/i - r; } } else if (m != ix) { for (i = ix+1;i <= m ;i++) { f /= g/i - r; } } if (v <= f) { goto normalExit; } } /*if (k <= 20 || k >= xnpq/2 - 1) */ else { /*12*/ /* squeezing using upper and lower bounds on alog(f(x)) */ amaxp = (k/xnpq)*((k*(k/3.0 + .625) + .1666666666666)/xnpq + .5); ynorm = -k*k/(2.0*xnpq); alv = log(v); if (alv < ynorm - amaxp) { goto normalExit; } if (alv <= ynorm + amaxp) { double x1, f1, z, w; double t_; /*temporary used by macro SERIES*/ /* Stirling's formula to machine accuracy for */ /* the final acceptance/rejection test */ x1 = ix + 1; f1 = fm + 1.0; z = n + 1 - fm; w = n - ix + 1; if (alv <= xm*log(f1/x1) + (n - m + .5)*log(z/w) + (ix - m)*log(w*p/x1*q) + SERIES(f1) + SERIES(z) + SERIES(x1) + SERIES(w)) { goto normalExit; } } /*if (alv <= ynorm + amaxp) */ } /*if (k <= 20 || k >= xnpq/2 - 1) {}else{}*/ } /*while (1)*/ } /*if (xnp < 30.0){}else{}*/ normalExit: /*16*/ return ( (psave > 0.5) ? n - ix : ix); } /*ranbinom()*/