Skip to content

Commit 8cba3fe

Browse files
committed
Check some settings are what we expect, and minor reorg
1 parent 8ea0641 commit 8cba3fe

File tree

2 files changed

+72
-60
lines changed

2 files changed

+72
-60
lines changed

src/hardware/tektronix-tds2000b/api.c

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,36 @@
2525
#include "protocol.h"
2626
#include "scpi.h"
2727

28-
static struct sr_dev_driver tektronix_ocp2k5_driver_info;
29-
3028
/**
3129
* Documentation for the SCPI commands can be found in
3230
* https://download.tek.com/manual/TBS1000-B-EDU-TDS2000-B-C-TDS1000-B-C-EDU-TDS200-TPS2000-B-Programmer-077044403_RevB.pdf
3331
* and is referred to as "doc page $PDF_PAGE/$PRINTED_PAGE"
3432
*/
3533

36-
static const uint32_t scanopts[] = {SR_CONF_CONN, SR_CONF_SERIALCOMM};
3734

38-
static const uint32_t drvopts[] = {SR_CONF_OSCILLOSCOPE};
3935
/**
40-
* TODOS
41-
*
42-
* General cleanup
43-
* current options?
36+
* Missing semi-important features:
37+
* bandwidth limiting ch<x>:bandwidth
38+
* chanel invert ch<x>:invert
39+
* volt/amp configuration ch:<x>:yunit
40+
* pulse triggering
41+
* ext trigger coupling
42+
* peak-detect mode (data retreival)
43+
*
44+
* Missing less important features:
45+
* capture/savefiles
46+
* screenshots
47+
* fine adjust of vdivs
48+
* video triggering
4449
*/
4550

51+
52+
static struct sr_dev_driver tektronix_ocp2k5_driver_info;
53+
54+
static const uint32_t scanopts[] = {SR_CONF_CONN, SR_CONF_SERIALCOMM};
55+
56+
static const uint32_t drvopts[] = {SR_CONF_OSCILLOSCOPE};
57+
4658
static const uint32_t devopts[] = {
4759
SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
4860
SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
@@ -58,37 +70,20 @@ static const uint32_t devopts[] = {
5870
SR_CONF_BUFFERSIZE | SR_CONF_GET,
5971
SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
6072
SR_CONF_PEAK_DETECTION | SR_CONF_GET | SR_CONF_SET,
61-
62-
// capturefile or session file?
63-
64-
// SR_CONF_LIMIT_SAMPLES? (could be here or per-channel, but
65-
// realistically, 2.5k samples isn't going to overwhelm anyone)
66-
67-
// TODO: voltage threshold?
6873
};
6974

70-
/**
71-
* Missing semi-important features:
72-
* bandwidth limiting ch<x>:bandwidth
73-
* chanel invert ch<x>:invert
74-
* volt/amp configuration ch:<x>:yunit
75-
*/
76-
7775
static const uint32_t devopts_cg_analog[] = {
7876
SR_CONF_NUM_VDIV | SR_CONF_GET,
7977
SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
8078
SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
8179
SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
8280
SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
83-
84-
// Is SR_CONF_CHANNEL_CONFIG how "advanced" features are supported?
8581
};
8682

87-
// TODO: Compensation adjusts the vdivs, and I implemented a semi-proper
88-
// configuration of that, but it wasn't ideal, so for now
89-
// all possible compensation vdivs are present
83+
// TODO: Compensation adjusts the vdivs, but PulseView doesn't pick up
84+
// any such dynamic changes, nor does it seem to support fine-adjust,
85+
// so for now all possible compensation vdivs are present
9086

91-
// TODO: allow fine adjust
9287
// validated in doc page 75/2-57
9388
static const uint64_t vdivs[][2] = {
9489
/* millivolts */
@@ -118,7 +113,7 @@ static const uint64_t vdivs[][2] = {
118113
{5000, 1},
119114
};
120115

121-
// everyone uses the same voltrange
116+
// everyone uses the same voltrange, only modified by compensation ranges (also the same)
122117
#define VOLTRANGE_2m_5V 0, 0
123118

124119
static const uint64_t timebases[][2] = {
@@ -165,7 +160,6 @@ static const uint64_t timebases[][2] = {
165160
#define TIMEBASE_10n_50s 2, 0
166161
#define TIMEBASE_5ns_5s 1, 3
167162

168-
// TODO: edge trigger has other options
169163
// validated in doc page 71/2-53
170164
static const char *coupling[] = {
171165
"AC",
@@ -175,25 +169,9 @@ static const char *coupling[] = {
175169

176170
// validated in doc page 74/2-53
177171
static const uint64_t probe_factor_new[] = {1, 10, 20, 50, 100, 500, 1000};
178-
// tds200, tds2000, tds1000
172+
// Only for tds200, tds2000, tds1000
179173
static const uint64_t probe_factor_old[] = {1, 10, 100, 1000};
180174

181-
182-
// TODO: current probe factor FIXME: 0.2x current probes are supported but this
183-
// is an int setting
184-
185-
// {5,1,.5,.2,.1,.02,.01,.001} tbs1000B/EDU,
186-
// {5,1,.5,.2,.1,.02,.01,.001} tbs1000,
187-
// {5,1,.5,.2,.1,.02,.01,.001} tds2000c,
188-
// {5,1,.5,.2,.1,.02,.01,.001} tds1000C-edu,
189-
// {5,1,.5,.2,.1,.02,.01,.001} tds2000b,
190-
// {5,1,.5,.2,.1,.02,.01,.001} tds1000B,
191-
192-
// {5,1,.2,.1,.05.02,.01,.001} tps2000/B
193-
// N/A tds200
194-
// tds2000
195-
// tds1000 ?
196-
197175
static const char *trigger_slopes[] = {
198176
"r",
199177
"f",
@@ -247,18 +225,19 @@ static const char *trigger_sources_models_TPS_2k[] = {
247225
4 + channels \
248226
}
249227

250-
/* The doc is for:
228+
/* This table was generated from the documentation:
251229
*
252-
* [x] TBS1000B/EDU: https://download.tek.com/manual/TBS1000B-User-Manual-077088602-RevA.pdf
253-
* [x] TBS1000: https://download.tek.com/manual/TBS1000-Oscilloscope-User-Manual_077076001.pdf
254-
* [x] TDS2000C/TDS1000C-EDU: https://download.tek.com/manual/TDS2000C-and-TDS1000C-EDU-Oscilloscope-User-Manual-EN_077082600.pdf
255-
* [x] TDS2000B/TDS1000B: https://download.tek.com/manual/071181702web.pdf
256-
* [x] TDS2000/TDS1000: https://download.tek.com/manual/TDS2000_TDS1000_User_071106400_Revision_A.pdf
257-
* [x] TDS200: https://download.tek.com/manual/071039803.pdf
258-
* [x] TPS2000B:https://download.tek.com/manual/TPS2000B-Digital-Oscilloscope-User-Manual-077137901.pdf
259-
* [x] TPS2000: https://download.tek.com/manual/071144105web.pdf
230+
* TBS1000B/EDU: https://download.tek.com/manual/TBS1000B-User-Manual-077088602-RevA.pdf
231+
* TBS1000: https://download.tek.com/manual/TBS1000-Oscilloscope-User-Manual_077076001.pdf
232+
* TDS2000C/TDS1000C-EDU: https://download.tek.com/manual/TDS2000C-and-TDS1000C-EDU-Oscilloscope-User-Manual-EN_077082600.pdf
233+
* TDS2000B/TDS1000B: https://download.tek.com/manual/071181702web.pdf
234+
* TDS2000/TDS1000: https://download.tek.com/manual/TDS2000_TDS1000_User_071106400_Revision_A.pdf
235+
* TDS200: https://download.tek.com/manual/071039803.pdf
236+
* TPS2000B:https://download.tek.com/manual/TPS2000B-Digital-Oscilloscope-User-Manual-077137901.pdf
237+
* TPS2000: https://download.tek.com/manual/071144105web.pdf
260238
*
261239
* All specs can be found in Appendix A's of the linked pdfs
240+
* EDU series are badge-only, and respond as if they are non-EDU products
262241
*/
263242
static const struct device_spec device_models[] = {
264243

@@ -690,7 +669,7 @@ static int config_set(uint32_t key, GVariant *data,
690669
tmp_str = "EXT10";
691670
else
692671
tmp_str = (char *)devc->trigger_source;
693-
// TODO: pulse and video
672+
// Note: pulse and video triggering isn't set here
694673
return tektronix_ocp2k5_config_set(
695674
sdi, "TRIG:mai:edge:sou %s", tmp_str);
696675
case SR_CONF_VDIV:

src/hardware/tektronix-tds2000b/protocol.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,27 @@ static int parse_scpi_blockstart(const char *data, int *out_err)
425425
return -1;
426426
}
427427

428+
429+
static void check_expected_value(
430+
const char* name, int actual, int expected, int* out_err,
431+
const struct tek_enum_parser *parser_table)
432+
{
433+
if (actual != expected) {
434+
*out_err = SR_ERR_DATA;
435+
if (parser_table == NULL)
436+
sr_err(
437+
"Error validating data header. Field '%s' expected %d, but found %d",
438+
name, expected, actual);
439+
else {
440+
sr_err(
441+
"Error validating data header. Field '%s' expected %s, but found %s",
442+
name,
443+
render_scpi_enum(expected, parser_table, out_err),
444+
render_scpi_enum(actual, parser_table, out_err));
445+
}
446+
}
447+
}
448+
428449
static int tektronix_ocp2k5_parse_header(struct sr_dev_inst *sdi, char *end_buf)
429450
{
430451
struct sr_scpi_dev_inst *scpi = sdi->conn;
@@ -481,7 +502,6 @@ static int tektronix_ocp2k5_parse_header(struct sr_dev_inst *sdi, char *end_buf)
481502
*/
482503

483504
i = 0;
484-
// TODO: assert a few of these values
485505
byte_width = parse_scpi_int(fields[i++], &ret, 1);
486506
bit_width = parse_scpi_int(fields[i++], &ret, 8);
487507
encoding = parse_scpi_enum(
@@ -495,8 +515,7 @@ static int tektronix_ocp2k5_parse_header(struct sr_dev_inst *sdi, char *end_buf)
495515
pt_format = parse_scpi_enum(
496516
fields[i++], parse_table_point_format, &ret, PT_FMT_Y);
497517
devc->wavepre.x_incr = parse_scpi_float(fields[i++], &ret, 1);
498-
pt_off = parse_scpi_int(fields[i++], &ret, 0); // always zero, parsed
499-
// only for completeness
518+
pt_off = parse_scpi_int(fields[i++], &ret, 0);
500519
devc->wavepre.x_zero = parse_scpi_float(fields[i++], &ret, 0);
501520
devc->wavepre.x_unit = parse_scpi_enum(sr_scpi_unquote_string(fields[i++]),
502521
parse_table_xunits, &ret, XU_SECOND);
@@ -528,6 +547,19 @@ static int tektronix_ocp2k5_parse_header(struct sr_dev_inst *sdi, char *end_buf)
528547
render_scpi_enum(devc->wavepre.y_unit,
529548
parse_table_yunits, &ret),
530549
blocklength);
550+
551+
// check that settings weren't tampered with
552+
check_expected_value("byte width", byte_width, 1, &ret, NULL);
553+
check_expected_value("bit size", bit_width, 8, &ret, NULL);
554+
check_expected_value("data encoding", encoding, ENC_BINARY, &ret, parse_table_data_encoding);
555+
check_expected_value("data format", format, FMT_RI, &ret, parse_table_data_format);
556+
check_expected_value("data encoding", ordering, ORDER_MSB, &ret, parse_table_data_ordering);
557+
check_expected_value("number of points", devc->wavepre.num_pts, TEK_BUFFER_SIZE, &ret, NULL);
558+
// this value is ENV when in peak detect mode
559+
check_expected_value("point format", pt_format, PT_FMT_Y, &ret, parse_table_point_format);
560+
561+
check_expected_value("point offset", pt_off, 0, &ret, NULL);
562+
check_expected_value("block length", blocklength, TEK_BUFFER_SIZE, &ret, NULL);
531563
return ret;
532564
}
533565

@@ -782,6 +814,7 @@ SR_PRIV int tektronix_ocp2k5_get_dev_cfg_horizontal(const struct sr_dev_inst *sd
782814
devc->model->sample_rate);
783815
else
784816
sr_dbg("Current samplerate: %ld Sa/s.", (long)fvalue);
817+
785818
// TODO: peak detect mode is half of this
786819
sr_dbg("Current memory depth: %d.", TEK_BUFFER_SIZE);
787820
return SR_OK;

0 commit comments

Comments
 (0)