X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhameg-hmo%2Fprotocol.c;h=f355e2c272dc882293857a651aaaf73b0361eb84;hb=HEAD;hp=d15d7a8924346ed5cf0d46d85daeaace078c0963;hpb=4c5f70063ad6ae311809ee7818ddc9070fbe05cf;p=libsigrok.git diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index d15d7a89..f355e2c2 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -117,7 +117,7 @@ static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = { static const uint32_t devopts[] = { SR_CONF_OSCILLOSCOPE, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, - SR_CONF_LIMIT_FRAMES | SR_CONF_SET, + SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET, SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_NUM_HDIV | SR_CONF_GET, @@ -161,6 +161,11 @@ static const char *coupling_options_rtm300x[] = { "GND", }; +static const char *coupling_options_rth100x[] = { + "ACL", // AC with 1 MOhm termination + "DCL", // DC with 1 MOhm termination +}; + static const char *scope_trigger_slopes[] = { "POS", "NEG", @@ -209,6 +214,18 @@ static const char *an2_dig16_sbus_trigger_sources[] = { "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15", }; +/* RTH1002 */ +static const char *an2_dig8_isol_trigger_sources[] = { + "CH1", "CH2", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", +}; + +/* RTH1004 */ +static const char *an4_dig8_isol_trigger_sources[] = { + "CH1", "CH2", "CH3", "CH4", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", +}; + /* HMO Compact4 */ static const char *an4_dig8_trigger_sources[] = { "CH1", "CH2", "CH3", "CH4", @@ -330,7 +347,17 @@ static const uint64_t vdivs[][2] = { { 2, 1 }, { 5, 1 }, { 10, 1 }, + { 20, 1 }, + { 50, 1 }, }; +/* + * It feels a little hacky to use a single table yet use different item + * count values here. But it simplifies maintenance, reduces redundancy + * by avoiding several vdivs[] table versions of mostly identical content, + * still references which declare models' capabilities remain readable. + */ +#define VDIVS_COUNT_UPTO_10V (ARRAY_SIZE(vdivs) - 2) +#define VDIVS_COUNT_UPTO_50V (ARRAY_SIZE(vdivs)) static const char *scope_analog_channel_names[] = { "CH1", "CH2", "CH3", "CH4", @@ -377,7 +404,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases_hmo_compact), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_10V, .num_ydivs = 8, @@ -418,7 +445,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_10V, .num_ydivs = 8, @@ -459,7 +486,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_10V, .num_ydivs = 8, @@ -500,7 +527,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases_hmo_compact), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_10V, .num_ydivs = 8, @@ -540,7 +567,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_10V, .num_ydivs = 8, @@ -580,7 +607,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_50V, .num_ydivs = 8, @@ -620,7 +647,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_50V, .num_ydivs = 8, @@ -660,7 +687,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_10V, .num_ydivs = 8, @@ -700,7 +727,7 @@ static struct scope_config scope_models[] = { .num_timebases = ARRAY_SIZE(timebases), .vdivs = &vdivs, - .num_vdivs = ARRAY_SIZE(vdivs), + .num_vdivs = VDIVS_COUNT_UPTO_10V, .num_ydivs = 8, @@ -739,6 +766,86 @@ static struct scope_config scope_models[] = { .timebases = &timebases, .num_timebases = ARRAY_SIZE(timebases), + .vdivs = &vdivs, + .num_vdivs = VDIVS_COUNT_UPTO_10V, + + .num_ydivs = 8, + + .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect, + }, + { + .name = {"RTH1002", NULL}, + .analog_channels = 2, + .digital_channels = 8, + + .analog_names = &scope_analog_channel_names, + .digital_names = &scope_digital_channel_names, + + .devopts = &devopts, + .num_devopts = ARRAY_SIZE(devopts), + + .devopts_cg_analog = &devopts_cg_analog, + .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), + + .devopts_cg_digital = &devopts_cg_digital, + .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital), + + .coupling_options = &coupling_options_rth100x, + .num_coupling_options = ARRAY_SIZE(coupling_options_rth100x), + + .logic_threshold = &logic_threshold, + .num_logic_threshold = ARRAY_SIZE(logic_threshold), + .logic_threshold_for_pod = TRUE, + + .trigger_sources = &an2_dig8_isol_trigger_sources, + .num_trigger_sources = ARRAY_SIZE(an2_dig8_isol_trigger_sources), + + .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), + + .timebases = &timebases, + .num_timebases = ARRAY_SIZE(timebases), + + .vdivs = &vdivs, + .num_vdivs = ARRAY_SIZE(vdivs), + + .num_ydivs = 8, + + .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect, + }, + { + .name = {"RTH1004", NULL}, + .analog_channels = 4, + .digital_channels = 8, + + .analog_names = &scope_analog_channel_names, + .digital_names = &scope_digital_channel_names, + + .devopts = &devopts, + .num_devopts = ARRAY_SIZE(devopts), + + .devopts_cg_analog = &devopts_cg_analog, + .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), + + .devopts_cg_digital = &devopts_cg_digital, + .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital), + + .coupling_options = &coupling_options_rth100x, + .num_coupling_options = ARRAY_SIZE(coupling_options_rth100x), + + .logic_threshold = &logic_threshold, + .num_logic_threshold = ARRAY_SIZE(logic_threshold), + .logic_threshold_for_pod = TRUE, + + .trigger_sources = &an4_dig8_isol_trigger_sources, + .num_trigger_sources = ARRAY_SIZE(an4_dig8_isol_trigger_sources), + + .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), + + .timebases = &timebases, + .num_timebases = ARRAY_SIZE(timebases), + .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), @@ -896,7 +1003,7 @@ static int analog_channel_state_get(struct sr_dev_inst *sdi, if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK) return SR_ERR; - if (array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j) != SR_OK) { + if (array_float_get(tmp_str, *(config->vdivs), config->num_vdivs, &j) != SR_OK) { g_free(tmp_str); sr_err("Could not determine array index for vertical div scale."); return SR_ERR; @@ -1192,6 +1299,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) unsigned int i, j, group; struct sr_channel *ch; struct dev_context *devc; + const char *cg_name; int ret; devc = sdi->priv; @@ -1232,27 +1340,20 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, (*scope_models[model_index].analog_names)[i]); - devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->analog_groups[i]->name = g_strdup( - (char *)(*scope_models[model_index].analog_names)[i]); + cg_name = (*scope_models[model_index].analog_names)[i]; + devc->analog_groups[i] = sr_channel_group_new(sdi, cg_name, NULL); devc->analog_groups[i]->channels = g_slist_append(NULL, ch); - - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->analog_groups[i]); } /* Add digital channel groups. */ ret = SR_OK; for (i = 0; i < scope_models[model_index].digital_pods; i++) { - devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); + devc->digital_groups[i] = sr_channel_group_new(sdi, NULL, NULL); if (!devc->digital_groups[i]) { ret = SR_ERR_MALLOC; break; } devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->digital_groups[i]); } if (ret != SR_OK) return ret; @@ -1380,8 +1481,6 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) (void)fd; (void)revents; - data = NULL; - if (!(sdi = cb_data)) return TRUE; @@ -1410,6 +1509,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) */ switch (ch->type) { case SR_CHANNEL_ANALOG: + data = NULL; if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) { if (data) g_byte_array_free(data, TRUE); @@ -1423,25 +1523,9 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) /* Truncate acquisition if a smaller number of samples has been requested. */ if (devc->samples_limit > 0 && analog.num_samples > devc->samples_limit) analog.num_samples = devc->samples_limit; - analog.encoding = &encoding; - analog.meaning = &meaning; - analog.spec = &spec; - - encoding.unitsize = sizeof(float); - encoding.is_signed = TRUE; - encoding.is_float = TRUE; -#ifdef WORDS_BIGENDIAN - encoding.is_bigendian = TRUE; -#else - encoding.is_bigendian = FALSE; -#endif /* TODO: Use proper 'digits' value for this device (and its modes). */ - encoding.digits = 2; - encoding.is_digits_decimal = FALSE; - encoding.scale.p = 1; - encoding.scale.q = 1; - encoding.offset.p = 0; - encoding.offset.q = 1; + sr_analog_init(&analog, &encoding, &meaning, &spec, 2); + encoding.is_signed = TRUE; if (state->analog_channels[ch->index].probe_unit == 'V') { meaning.mq = SR_MQ_VOLTAGE; meaning.unit = SR_UNIT_VOLT; @@ -1449,10 +1533,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) meaning.mq = SR_MQ_CURRENT; meaning.unit = SR_UNIT_AMPERE; } - meaning.mqflags = 0; meaning.channels = g_slist_append(NULL, ch); - /* TODO: Use proper 'digits' value for this device (and its modes). */ - spec.spec_digits = 2; packet.payload = &analog; sr_session_send(sdi, &packet); devc->num_samples = data->len / sizeof(float); @@ -1461,6 +1542,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) data = NULL; break; case SR_CHANNEL_LOGIC: + data = NULL; if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) { if (data) g_byte_array_free(data, TRUE);