From: Soeren Apel Date: Sun, 1 Mar 2020 15:50:46 +0000 (+0100) Subject: Remove samplerate from srd_decoder_logic_output_channel X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=460e6cfa5d45c8d2ba0f5be1235ab31d4ec9508b;p=libsigrokdecode.git Remove samplerate from srd_decoder_logic_output_channel This means that the samplerate for logic output channels is implicitly determined by the input channel samplerate. The motivation for this is that hard-coding a samplerate isn't possible - but at the same time, it's also not possible to determine the samplerate at the time the logic output channels are initialized, as the samplerate can be set at runtime. From my point of view, we would need one of two mechanisms to make this work: 1) Allow creation of logic outputs at runtime via some registration callback or 2) Allow changing a logic output's samplerate after it has been created, again requiring some kind of callback To me, both currently are overkill because making the assumption that samplerate_in = samplerate_out not only makes this problem go away as it can easily be handled on the client side where samplerate_in is already known, it also makes handling of the logic data in the PDs easier. --- diff --git a/decoder.c b/decoder.c index 3bbc7f9..0d266d4 100644 --- a/decoder.c +++ b/decoder.c @@ -621,7 +621,7 @@ err_out: /* Convert logic_output_channels to GSList of 'struct srd_decoder_logic_output_channel'. */ static int get_logic_output_channels(struct srd_decoder *dec) { - PyObject *py_logic_out_chs, *py_logic_out_ch, *py_samplerate, *py_item; + PyObject *py_logic_out_chs, *py_logic_out_ch, *py_item; GSList *logic_out_chs; struct srd_decoder_logic_output_channel *logic_out_ch; ssize_t i; @@ -651,9 +651,9 @@ static int get_logic_output_channels(struct srd_decoder *dec) if (!py_logic_out_ch) goto except_out; - if (!PyTuple_Check(py_logic_out_ch) || PyTuple_Size(py_logic_out_ch) != 3) { + if (!PyTuple_Check(py_logic_out_ch) || PyTuple_Size(py_logic_out_ch) != 2) { srd_err("Protocol decoder %s logic_output_channels " - "must contain only tuples of 3 elements.", + "must contain only tuples of 2 elements.", dec->name); goto err_out; } @@ -672,19 +672,6 @@ static int get_logic_output_channels(struct srd_decoder *dec) goto except_out; if (py_str_as_str(py_item, &logic_out_ch->desc) != SRD_OK) goto err_out; - - py_samplerate = PyTuple_GetItem(py_logic_out_ch, 2); - if (!py_samplerate) - goto except_out; - - if (!PyLong_Check(py_samplerate)) { - srd_err("Protocol decoder %s logic_output_channels tuples " - "must have a number as 3rd element.", - dec->name); - goto err_out; - } - - logic_out_ch->samplerate = PyLong_AsUnsignedLongLong(py_samplerate); } dec->logic_output_channels = logic_out_chs; Py_DECREF(py_logic_out_chs); diff --git a/decoders/pca9571/pd.py b/decoders/pca9571/pd.py index 6000952..8531081 100644 --- a/decoders/pca9571/pd.py +++ b/decoders/pca9571/pd.py @@ -23,10 +23,10 @@ NUM_OUTPUT_CHANNELS = 8 # TODO: Other I²C functions: general call / reset address, device ID address. -def logic_channels(num_channels): +def logic_channels(num_channels, samplerate): l = [] for i in range(num_channels): - l.append(tuple(['p%d' % i, 'P%d' % i, 100000])) + l.append(tuple(['p%d' % i, 'P%d' % i])) return tuple(l) class Decoder(srd.Decoder): diff --git a/decoders/tca6408a/pd.py b/decoders/tca6408a/pd.py index 3b0556f..fdfebed 100644 --- a/decoders/tca6408a/pd.py +++ b/decoders/tca6408a/pd.py @@ -26,7 +26,7 @@ NUM_OUTPUT_CHANNELS = 8 def logic_channels(num_channels): l = [] for i in range(num_channels): - l.append(tuple(['p%d' % i, 'P-port input/output %d' % i, 100000])) + l.append(tuple(['p%d' % i, 'P-port input/output %d' % i])) return tuple(l) class Decoder(srd.Decoder): diff --git a/libsigrokdecode.h b/libsigrokdecode.h index 4440267..30282f5 100644 --- a/libsigrokdecode.h +++ b/libsigrokdecode.h @@ -190,7 +190,7 @@ struct srd_decoder { GSList *binary; /** - * List of logic output channels (item: id, description, samplerate). + * List of logic output channels (item: id, description). */ GSList *logic_output_channels; @@ -241,7 +241,6 @@ struct srd_decoder_annotation_row { struct srd_decoder_logic_output_channel { char *id; char *desc; - uint64_t samplerate; }; struct srd_decoder_inst {