Skip to content

Commit 13ace4b

Browse files
Fix decode issue when skip zero
1 parent 7782e49 commit 13ace4b

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

libsigrokdecode4DSL/instance.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di, char **error)
699699
/* none matched */
700700
di->abs_cur_matched = FALSE;
701701

702+
/* skip zero flag */
703+
di->skip_zero = FALSE;
704+
702705
/* Set self.samplenum to 0. */
703706
PyObject_SetAttrString(di->py_inst, "samplenum", PyLong_FromLong(0));
704707

@@ -859,7 +862,7 @@ static void update_old_pins_array_initial_pins(struct srd_decoder_inst *di)
859862
}
860863
}
861864

862-
static gboolean term_matches(const struct srd_decoder_inst *di,
865+
static gboolean term_matches(struct srd_decoder_inst *di,
863866
struct srd_term *term, gboolean *skip_allow)
864867
{
865868
uint8_t old_sample, sample;
@@ -869,8 +872,11 @@ static gboolean term_matches(const struct srd_decoder_inst *di,
869872
/* Caller ensures di, di->dec_channelmap, term, sample_pos != NULL. */
870873

871874
*skip_allow = FALSE;
872-
if (term->type == SRD_TERM_SKIP)
875+
if (term->type == SRD_TERM_SKIP) {
876+
if (di->abs_cur_matched && term->num_samples_to_skip == 0)
877+
di->skip_zero = TRUE;
873878
return sample_matches(0, 0, term);
879+
}
874880

875881
ch = term->channel;
876882
if (*(di->inbuf + ch) == NULL) {
@@ -886,7 +892,7 @@ static gboolean term_matches(const struct srd_decoder_inst *di,
886892
return sample_matches(old_sample, sample, term);
887893
}
888894

889-
static gboolean all_terms_match(const struct srd_decoder_inst *di,
895+
static gboolean all_terms_match(struct srd_decoder_inst *di,
890896
const GSList *cond, gboolean *skip_allow)
891897
{
892898
const GSList *l;
@@ -900,6 +906,10 @@ static gboolean all_terms_match(const struct srd_decoder_inst *di,
900906
return FALSE;
901907
}
902908

909+
if (di->skip_zero) {
910+
di->abs_cur_samplenum--;
911+
di->skip_zero = FALSE;
912+
}
903913
return TRUE;
904914
}
905915

libsigrokdecode4DSL/libsigrokdecode.h

+3
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ struct srd_decoder_inst {
309309
/** First entry of wait(). */
310310
gboolean first_pos;
311311

312+
/** skip zero flag. */
313+
gboolean skip_zero;
314+
312315
/** Indicates the current state of the decoder stack. */
313316
int decoder_state;
314317

libsigrokdecode4DSL/type_decoder.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static int create_term_list(PyObject *py_dict, GSList **term_list, gboolean cur_
685685
term = g_malloc(sizeof(struct srd_term));
686686
term->type = SRD_TERM_SKIP;
687687
term->num_samples_to_skip = num_samples_to_skip;
688-
term->num_samples_already_skipped = cur_matched ? 1 : 0;
688+
term->num_samples_already_skipped = cur_matched ? (term->num_samples_to_skip != 0) : 0;
689689
} else {
690690
srd_err("Term key is neither a string nor a number.");
691691
goto err;
@@ -841,7 +841,7 @@ static int set_skip_condition(struct srd_decoder_inst *di, uint64_t count)
841841
term = g_malloc(sizeof(*term));
842842
term->type = SRD_TERM_SKIP;
843843
term->num_samples_to_skip = count;
844-
term->num_samples_already_skipped = di->abs_cur_matched ? 1 : 0;
844+
term->num_samples_already_skipped = di->abs_cur_matched ? (term->num_samples_to_skip != 0) : 0;
845845
term_list = g_slist_append(NULL, term);
846846
di->condition_list = g_slist_append(di->condition_list, term_list);
847847

0 commit comments

Comments
 (0)