From: Guido Trentalancia Date: Tue, 20 Nov 2018 22:24:07 +0000 (+0100) Subject: hameg-hmo: Get SCPI_CMD_GET_HORIZONTAL_DIV at runtime. X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=29a9b1a0bd0af79e0eb2adee594f42895452344c hameg-hmo: Get SCPI_CMD_GET_HORIZONTAL_DIV at runtime. Get the number of horizontal divisions from the device (at runtime) instead of hardcoding its value in the driver. --- diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 9135601c..167c1a4f 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -34,6 +34,7 @@ static const char *hameg_scpi_dialect[] = { [SCPI_CMD_GET_DIG_DATA] = ":FORM UINT,8;:POD%d:DATA?", [SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?", [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s", + [SCPI_CMD_GET_HORIZONTAL_DIV] = ":TIM:DIV?", [SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?", [SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s", [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?", @@ -71,6 +72,7 @@ static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = { [SCPI_CMD_GET_DIG_DATA] = ":FORM UINT,8;:LOG%d:DATA?", [SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?", [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s", + [SCPI_CMD_GET_HORIZONTAL_DIV] = ":TIM:DIV?", [SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?", [SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s", [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?", @@ -364,7 +366,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &hameg_scpi_dialect, @@ -406,7 +407,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &hameg_scpi_dialect, @@ -448,7 +448,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &hameg_scpi_dialect, @@ -490,7 +489,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &hameg_scpi_dialect, @@ -531,7 +529,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &hameg_scpi_dialect, @@ -572,7 +569,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect, @@ -613,7 +609,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect, @@ -654,7 +649,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect, @@ -695,7 +689,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect, @@ -736,7 +729,6 @@ static struct scope_config scope_models[] = { .vdivs = &vdivs, .num_vdivs = ARRAY_SIZE(vdivs), - .num_xdivs = 12, .num_ydivs = 8, .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect, @@ -1091,6 +1083,12 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi) state->timebase = i; + /* Determine the number of horizontal (x) divisions. */ + if (sr_scpi_get_int(sdi->conn, + (*config->scpi_dialect)[SCPI_CMD_GET_HORIZONTAL_DIV], + (int *)&config->num_xdivs) != SR_OK) + return SR_ERR; + if (sr_scpi_get_float(sdi->conn, (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS], &tmp_float) != SR_OK) @@ -1182,6 +1180,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) sr_dbg("Unsupported device."); return SR_ERR_NA; } + /* Configure the number of PODs given the number of digital channels. */ scope_models[model_index].digital_pods = scope_models[model_index].digital_channels / DIGITAL_CHANNELS_PER_POD; diff --git a/src/hardware/hameg-hmo/protocol.h b/src/hardware/hameg-hmo/protocol.h index df4a4e4c..975ea7e3 100644 --- a/src/hardware/hameg-hmo/protocol.h +++ b/src/hardware/hameg-hmo/protocol.h @@ -73,8 +73,8 @@ struct scope_config { const uint64_t (*vdivs)[][2]; const uint8_t num_vdivs; - const uint8_t num_xdivs; - const uint8_t num_ydivs; + unsigned int num_xdivs; + const unsigned int num_ydivs; const char *(*scpi_dialect)[]; }; diff --git a/src/scpi.h b/src/scpi.h index b66dd554..7d9a39bb 100644 --- a/src/scpi.h +++ b/src/scpi.h @@ -35,6 +35,7 @@ enum { SCPI_CMD_GET_TIMEBASE = 1, SCPI_CMD_SET_TIMEBASE, + SCPI_CMD_GET_HORIZONTAL_DIV, SCPI_CMD_GET_VERTICAL_SCALE, SCPI_CMD_SET_VERTICAL_SCALE, SCPI_CMD_GET_TRIGGER_SLOPE,