diff --git a/DSView/pv/data/decode/annotation.cpp b/DSView/pv/data/decode/annotation.cpp index a362f0e6..ee7e2cc7 100755 --- a/DSView/pv/data/decode/annotation.cpp +++ b/DSView/pv/data/decode/annotation.cpp @@ -76,7 +76,9 @@ Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status) char **annotations = pda->ann_text; while(annotations && *annotations) { - key.append(*annotations, strlen(*annotations)); + if ((*annotations)[0] != '\n'){ + key.append(*annotations, strlen(*annotations)); + } annotations++; } @@ -92,7 +94,9 @@ Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status) if (resItem != NULL){ char **annotations = pda->ann_text; while(annotations && *annotations) { - resItem->src_lines.push_back(QString::fromUtf8(*annotations)); + if ((*annotations)[0] != '\n'){ + resItem->src_lines.push_back(QString::fromUtf8(*annotations)); + } annotations++; } @@ -101,14 +105,6 @@ Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status) strcpy(resItem->str_number_hex, pda->str_number_hex); resItem->is_numeric = true; } - /* - //disable auto convert to numberic format - else if (resItem->src_lines.size() == 1 && _type >= 100 && _type < 200){ - if (is_hex_number_str(resItem->src_lines[0].toLatin1().data())){ - resItem->is_numeric = true; - } - } - */ _status->m_bNumeric |= resItem->is_numeric; } diff --git a/DSView/pv/data/decode/annotationrestable.h b/DSView/pv/data/decode/annotationrestable.h index 222e0147..61994c7e 100644 --- a/DSView/pv/data/decode/annotationrestable.h +++ b/DSView/pv/data/decode/annotationrestable.h @@ -26,12 +26,12 @@ #include #include -#define DECODER_MAX_DATA_BLOCK_LEN 25 +#define DECODER_MAX_DATA_BLOCK_LEN 35 struct AnnotationSourceItem { bool is_numeric; - char str_number_hex[18]; //numerical value hex format string + char str_number_hex[DECODER_MAX_DATA_BLOCK_LEN]; //numerical value hex format string long long numberic_value; std::vector src_lines; //the origin source string lines std::vector cvt_lines; //the converted to bin/hex/oct format string lines diff --git a/libsigrokdecode4DSL/decoders/0-spi/pd.py b/libsigrokdecode4DSL/decoders/0-spi/pd.py old mode 100644 new mode 100755 index 2d397f02..939926b1 --- a/libsigrokdecode4DSL/decoders/0-spi/pd.py +++ b/libsigrokdecode4DSL/decoders/0-spi/pd.py @@ -151,9 +151,9 @@ class Decoder(srd.Decoder): # Dataword annotations. if self.have_miso: - self.put(ss, es, self.out_ann, [0, [self.misodata]]) + self.put(ss, es, self.out_ann, [0, ['@%02X' % self.misodata]]) if self.have_mosi: - self.put(ss, es, self.out_ann, [1, [self.mosidata]]) + self.put(ss, es, self.out_ann, [1, ['@%02X' % self.mosidata]]) def reset_decoder_state(self): self.misodata = 0 if self.have_miso else None diff --git a/libsigrokdecode4DSL/decoders/0-uart/pd.py b/libsigrokdecode4DSL/decoders/0-uart/pd.py old mode 100644 new mode 100755 index 9edf2254..eaf4b8f9 --- a/libsigrokdecode4DSL/decoders/0-uart/pd.py +++ b/libsigrokdecode4DSL/decoders/0-uart/pd.py @@ -218,12 +218,8 @@ class Decoder(srd.Decoder): if self.options['bit_order'] == 'msb-first': bits.reverse() self.datavalue = bitpack(bits) - self.putx([0, [self.datavalue]]) - #b = self.datavalue - #formatted = self.format_value(b) - #if formatted is not None: - # self.putx([0, [formatted]]) - + self.putx([0, ['@%02X' % self.datavalue]]) + self.databits = [] # Advance to either reception of the parity bit, or reception of @@ -231,49 +227,7 @@ class Decoder(srd.Decoder): self.state = 'GET PARITY BIT' if self.options['parity_type'] == 'none': self.state = 'GET STOP BITS' - - def format_value(self, v): - # Format value 'v' according to configured options. - # Reflects the user selected kind of representation, as well as - # the number of data bits in the UART frames. - - fmt, bits = self.options['format'], self.options['num_data_bits'] - - # Assume "is printable" for values from 32 to including 126, - # below 32 is "control" and thus not printable, above 127 is - # "not ASCII" in its strict sense, 127 (DEL) is not printable, - # fall back to hex representation for non-printables. - if fmt == 'ascii': - if v in range(32, 126 + 1): - return chr(v) - hexfmt = "[{:02X}]" if bits <= 8 else "[{:03X}]" - return hexfmt.format(v) - - # Mere number to text conversion without prefix and padding - # for the "decimal" output format. - if fmt == 'dec': - return "{:d}".format(v) - - # Padding with leading zeroes for hex/oct/bin formats, but - # without a prefix for density -- since the format is user - # specified, there is no ambiguity. - if fmt == 'hex': - digits = (bits + 4 - 1) // 4 - fmtchar = "X" - elif fmt == 'oct': - digits = (bits + 3 - 1) // 3 - fmtchar = "o" - elif fmt == 'bin': - digits = bits - fmtchar = "b" - else: - fmtchar = None - if fmtchar is not None: - fmt = "{{:0{:d}{:s}}}".format(digits, fmtchar) - return fmt.format(v) - - return None - + def get_parity_bit(self, signal): self.paritybit = signal diff --git a/libsigrokdecode4DSL/decoders/1-spi/pd.py b/libsigrokdecode4DSL/decoders/1-spi/pd.py old mode 100644 new mode 100755 index e17e6adb..355ecc75 --- a/libsigrokdecode4DSL/decoders/1-spi/pd.py +++ b/libsigrokdecode4DSL/decoders/1-spi/pd.py @@ -195,11 +195,11 @@ class Decoder(srd.Decoder): for bit in self.mosibits: self.put(bit[1], bit[2], self.out_ann, [3, ['%d' % bit[0]]]) - # Dataword annotations. + # Dataword annotations. if self.have_miso: - self.put(ss, es, self.out_ann, [0, ['%02X' % self.misodata]]) + self.put(ss, es, self.out_ann, [0, ['@%02X' % self.misodata]]) if self.have_mosi: - self.put(ss, es, self.out_ann, [1, ['%02X' % self.mosidata]]) + self.put(ss, es, self.out_ann, [1, ['@%02X' % self.mosidata]]) def reset_decoder_state(self): self.misodata = 0 if self.have_miso else None @@ -289,10 +289,10 @@ class Decoder(srd.Decoder): elif self.ss_transfer != -1: if self.have_miso: self.put(self.ss_transfer, self.samplenum, self.out_ann, - [5, [' '.join(format(x.val, '02X') for x in self.misobytes)]]) + [5, [' '.join('@' + format(x.val, '02X') for x in self.misobytes)]]) if self.have_mosi: self.put(self.ss_transfer, self.samplenum, self.out_ann, - [6, [' '.join(format(x.val, '02X') for x in self.mosibytes)]]) + [6, [' '.join('@' + format(x.val, '02X') for x in self.mosibytes)]]) self.put(self.ss_transfer, self.samplenum, self.out_python, ['TRANSFER', self.mosibytes, self.misobytes]) diff --git a/libsigrokdecode4DSL/decoders/1-uart/pd.py b/libsigrokdecode4DSL/decoders/1-uart/pd.py old mode 100644 new mode 100755 index f3d6181c..b8b26201 --- a/libsigrokdecode4DSL/decoders/1-uart/pd.py +++ b/libsigrokdecode4DSL/decoders/1-uart/pd.py @@ -253,13 +253,10 @@ class Decoder(srd.Decoder): self.datavalue = bitpack(bits) self.putpx(['DATA', 0, (self.datavalue, self.databits)]) - self.putx([0, [self.datavalue]]) + self.putx([0, ['@%02X' % self.datavalue]]) b = self.datavalue - #formatted = self.format_value(b) - #if formatted is not None: - # self.putx([0, [formatted]]) - + bdata = b.to_bytes(self.bw, byteorder='big') self.putbin([0, bdata]) self.putbin([1, bdata]) @@ -271,48 +268,7 @@ class Decoder(srd.Decoder): self.state = 'GET PARITY BIT' if self.options['parity_type'] == 'none': self.state = 'GET STOP BITS' - - def format_value(self, v): - # Format value 'v' according to configured options. - # Reflects the user selected kind of representation, as well as - # the number of data bits in the UART frames. - - fmt, bits = self.options['format'], self.options['num_data_bits'] - - # Assume "is printable" for values from 32 to including 126, - # below 32 is "control" and thus not printable, above 127 is - # "not ASCII" in its strict sense, 127 (DEL) is not printable, - # fall back to hex representation for non-printables. - if fmt == 'ascii': - if v in range(32, 126 + 1): - return chr(v) - hexfmt = "[{:02X}]" if bits <= 8 else "[{:03X}]" - return hexfmt.format(v) - - # Mere number to text conversion without prefix and padding - # for the "decimal" output format. - if fmt == 'dec': - return "{:d}".format(v) - - # Padding with leading zeroes for hex/oct/bin formats, but - # without a prefix for density -- since the format is user - # specified, there is no ambiguity. - if fmt == 'hex': - digits = (bits + 4 - 1) // 4 - fmtchar = "X" - elif fmt == 'oct': - digits = (bits + 3 - 1) // 3 - fmtchar = "o" - elif fmt == 'bin': - digits = bits - fmtchar = "b" - else: - fmtchar = None - if fmtchar is not None: - fmt = "{{:0{:d}{:s}}}".format(digits, fmtchar) - return fmt.format(v) - - return None + def get_parity_bit(self, signal): self.paritybit = signal diff --git a/libsigrokdecode4DSL/libsigrokdecode.h b/libsigrokdecode4DSL/libsigrokdecode.h index a399de18..90117735 100755 --- a/libsigrokdecode4DSL/libsigrokdecode.h +++ b/libsigrokdecode4DSL/libsigrokdecode.h @@ -25,6 +25,8 @@ #include #include +#define DECODE_NUM_HEX_MAX_LEN 35 + #ifdef __cplusplus extern "C" { #endif @@ -347,7 +349,7 @@ struct srd_proto_data { struct srd_proto_data_annotation { int ann_class; int ann_type; - char str_number_hex[18]; //numerical value hex format string + char str_number_hex[DECODE_NUM_HEX_MAX_LEN]; //numerical value hex format string long long numberic_value; char **ann_text; //text string lines }; diff --git a/libsigrokdecode4DSL/type_decoder.c b/libsigrokdecode4DSL/type_decoder.c index 2362eda1..cf43de74 100755 --- a/libsigrokdecode4DSL/type_decoder.c +++ b/libsigrokdecode4DSL/type_decoder.c @@ -22,6 +22,7 @@ #include "libsigrokdecode-internal.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */ #include "libsigrokdecode.h" #include +#include /** @cond PRIVATE */ extern SRD_PRIV GSList *sessions; @@ -66,6 +67,7 @@ static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size PyObject *py_numobj = NULL; int i; long long lv; + int nstr; gstate = PyGILState_Ensure(); @@ -91,7 +93,7 @@ static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size goto err; } - //vet numberic value + //get numberic value if (py_numobj != NULL){ lv = PyLong_AsLongLong(py_numobj); sprintf(hex_str_buf, "%02llX", lv); @@ -122,6 +124,16 @@ static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size if (!str) goto err; + //check numberic field value + if (str[0]== '@'){ + nstr = strlen(str) - 1; + if (nstr > 0 && nstr < DECODE_NUM_HEX_MAX_LEN){ + strcpy(hex_str_buf, str + 1); + str[0] = '\n'; //set ignore flag + str[1] = 0; + } + } + strv[i] = str; }