mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-23 13:42:55 +08:00
Add ascii display format for numberic value from the decode result
This commit is contained in:
parent
be2514f009
commit
1cd25f29a6
@ -24,11 +24,10 @@
|
|||||||
#include "../../dsvdef.h"
|
#include "../../dsvdef.h"
|
||||||
|
|
||||||
#define DECODER_MAX_DATA_BLOCK_LEN 25
|
#define DECODER_MAX_DATA_BLOCK_LEN 25
|
||||||
#define FORMAT_TMP_BUFFER_SIZE 100
|
|
||||||
|
|
||||||
const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111";
|
const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111";
|
||||||
char g_bin_format_tmp_buffer[FORMAT_TMP_BUFFER_SIZE + 3];
|
char g_bin_format_tmp_buffer[DECODER_MAX_DATA_BLOCK_LEN * 4 + 2];
|
||||||
char g_oct_format_tmp_buffer[FORMAT_TMP_BUFFER_SIZE + 6];
|
char g_oct_format_tmp_buffer[DECODER_MAX_DATA_BLOCK_LEN * 3 + 2];
|
||||||
char g_number_tmp_64[30];
|
char g_number_tmp_64[30];
|
||||||
|
|
||||||
char* bin2oct_string(char *buf, int size, const char *bin, int len){
|
char* bin2oct_string(char *buf, int size, const char *bin, int len){
|
||||||
@ -111,7 +110,7 @@ int AnnotationResTable::MakeIndex(const std::string &key, AnnotationSourceItem*
|
|||||||
m_resourceTable.push_back(item);
|
m_resourceTable.push_back(item);
|
||||||
|
|
||||||
item->cur_display_format = -1;
|
item->cur_display_format = -1;
|
||||||
item->is_numerical = false;
|
item->is_numeric = false;
|
||||||
newItem = item;
|
newItem = item;
|
||||||
|
|
||||||
int dex = m_indexs.size();
|
int dex = m_indexs.size();
|
||||||
@ -135,9 +134,9 @@ const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//convert to bin format
|
//convert to bin format
|
||||||
char *buf = g_bin_format_tmp_buffer + FORMAT_TMP_BUFFER_SIZE;
|
char *buf = g_bin_format_tmp_buffer + sizeof(g_bin_format_tmp_buffer) - 2;
|
||||||
*(buf + 1) = 0; //set the end flag
|
buf[1] = 0; //set the end flag
|
||||||
*buf = 0;
|
buf[0] = 0;
|
||||||
|
|
||||||
int len = strlen(data);
|
int len = strlen(data);
|
||||||
//buffer is not enough
|
//buffer is not enough
|
||||||
@ -178,11 +177,29 @@ const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt)
|
|||||||
|
|
||||||
//64 bit integer
|
//64 bit integer
|
||||||
if (fmt == DecoderDataFormat::dec && len * 4 <= 64){
|
if (fmt == DecoderDataFormat::dec && len * 4 <= 64){
|
||||||
long long lv = bin2long_string(buf, len *4);
|
long long lv = bin2long_string(buf, len * 4);
|
||||||
g_number_tmp_64[0] = 0;
|
g_number_tmp_64[0] = 0;
|
||||||
sprintf(g_number_tmp_64, "%lld", lv);
|
sprintf(g_number_tmp_64, "%lld", lv);
|
||||||
return g_number_tmp_64;
|
return g_number_tmp_64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ascii
|
||||||
|
if (fmt == DecoderDataFormat::ascii && len < 30 - 3){
|
||||||
|
if (len == 2){
|
||||||
|
int lv = (int)bin2long_string(buf, len * 4);
|
||||||
|
//can display chars
|
||||||
|
if (lv >= 33 && lv <= 126){
|
||||||
|
sprintf(g_number_tmp_64, "%c", (char)lv);
|
||||||
|
return g_number_tmp_64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char * const wr_buf = g_number_tmp_64;
|
||||||
|
g_number_tmp_64[0] = '[';
|
||||||
|
strcpy(g_number_tmp_64 + 1, data);
|
||||||
|
g_number_tmp_64[len+1] = ']';
|
||||||
|
g_number_tmp_64[len+2] = 0;
|
||||||
|
return g_number_tmp_64;
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,9 @@
|
|||||||
|
|
||||||
struct AnnotationSourceItem
|
struct AnnotationSourceItem
|
||||||
{
|
{
|
||||||
bool is_numerical;
|
bool is_numeric;
|
||||||
char str_number_hex[18]; //numerical value hex format string
|
char str_number_hex[18]; //numerical value hex format string
|
||||||
|
long long numberic_value;
|
||||||
std::vector<QString> src_lines; //the origin source string lines
|
std::vector<QString> src_lines; //the origin source string lines
|
||||||
std::vector<QString> cvt_lines; //the converted to bin/hex/oct format string lines
|
std::vector<QString> cvt_lines; //the converted to bin/hex/oct format string lines
|
||||||
int cur_display_format; //current format as bin/ex/oct..., init with -1
|
int cur_display_format; //current format as bin/ex/oct..., init with -1
|
||||||
|
@ -40,9 +40,11 @@ char sz_format_tmp_buf[50];
|
|||||||
bool is_hex_number_str(const char *str)
|
bool is_hex_number_str(const char *str)
|
||||||
{
|
{
|
||||||
char c = *str;
|
char c = *str;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
while (c)
|
while (c)
|
||||||
{
|
{
|
||||||
|
++len;
|
||||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')){
|
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')){
|
||||||
c = *str;
|
c = *str;
|
||||||
str++;
|
str++;
|
||||||
@ -50,8 +52,7 @@ bool is_hex_number_str(const char *str)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return len % 2 == 0 && len > 0;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pv {
|
namespace pv {
|
||||||
@ -96,19 +97,19 @@ Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status)
|
|||||||
resItem->src_lines.push_back(QString::fromUtf8(*annotations));
|
resItem->src_lines.push_back(QString::fromUtf8(*annotations));
|
||||||
annotations++;
|
annotations++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get numerical data
|
//get numeric data
|
||||||
if (pda->str_number_hex[0]){
|
if (pda->str_number_hex[0]){
|
||||||
strcpy(resItem->str_number_hex, pda->str_number_hex);
|
strcpy(resItem->str_number_hex, pda->str_number_hex);
|
||||||
resItem->is_numerical = true;
|
resItem->is_numeric = true;
|
||||||
}
|
}
|
||||||
else if (resItem->src_lines.size() == 1 && _type >= 100 && _type < 200){
|
else if (resItem->src_lines.size() == 1 && _type >= 100 && _type < 200){
|
||||||
if (is_hex_number_str(resItem->src_lines[0].toLatin1().data())){
|
if (is_hex_number_str(resItem->src_lines[0].toLatin1().data())){
|
||||||
resItem->is_numerical = true;
|
resItem->is_numeric = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_status->m_bNumerical |= resItem->is_numerical;
|
_status->m_bNumeric |= resItem->is_numeric;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +127,11 @@ Annotation::~Annotation()
|
|||||||
const std::vector<QString>& Annotation::annotations() const
|
const std::vector<QString>& Annotation::annotations() const
|
||||||
{
|
{
|
||||||
assert(_status);
|
assert(_status);
|
||||||
|
|
||||||
AnnotationSourceItem &resItem = *annTable.GetItem(_resIndex);
|
AnnotationSourceItem &resItem = *annTable.GetItem(_resIndex);
|
||||||
|
|
||||||
//get origin data, is not a numberical value
|
//get origin data, is not a numberic value
|
||||||
if (!resItem.is_numerical){
|
if (!resItem.is_numeric){
|
||||||
return resItem.src_lines;
|
return resItem.src_lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,8 +168,13 @@ const std::vector<QString>& Annotation::annotations() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
return resItem.cvt_lines;
|
return resItem.cvt_lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Annotation::is_numberic()
|
||||||
|
{
|
||||||
|
AnnotationSourceItem *resItem = annTable.GetItem(_resIndex);
|
||||||
|
return resItem->is_numeric;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace decode
|
} // namespace decode
|
||||||
} // namespace data
|
} // namespace data
|
||||||
|
@ -62,6 +62,8 @@ public:
|
|||||||
return _type;
|
return _type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_numberic();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const std::vector<QString>& annotations() const;
|
const std::vector<QString>& annotations() const;
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ class DecoderStatus
|
|||||||
public:
|
public:
|
||||||
DecoderStatus()
|
DecoderStatus()
|
||||||
{
|
{
|
||||||
m_bNumerical = false;
|
m_bNumeric = false;
|
||||||
m_format = 0;
|
m_format = 0;
|
||||||
sdr_decoder_handle = NULL;
|
sdr_decoder_handle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool m_bNumerical; //when decoder get any numerical data,it will be set
|
bool m_bNumeric; //when decoder get any numerical data,it will be set
|
||||||
int m_format; //protocol format code
|
int m_format; //protocol format code
|
||||||
void *sdr_decoder_handle;
|
void *sdr_decoder_handle;
|
||||||
};
|
};
|
||||||
|
@ -618,10 +618,12 @@ void ProtocolDock::search_pre()
|
|||||||
bool ann_valid;
|
bool ann_valid;
|
||||||
while(i < _str_list.size()) {
|
while(i < _str_list.size()) {
|
||||||
QString nxt = _str_list.at(i);
|
QString nxt = _str_list.at(i);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ann_valid = decoder_stack->list_annotation(ann, col, row);
|
ann_valid = decoder_stack->list_annotation(ann, col, row);
|
||||||
row++;
|
row++;
|
||||||
}while(ann_valid && (ann.type() < 100 || ann.type() > 999));
|
}while(ann_valid && !ann.is_numberic());
|
||||||
|
|
||||||
QString source = ann.annotations().at(0);
|
QString source = ann.annotations().at(0);
|
||||||
if (ann_valid && source.contains(nxt))
|
if (ann_valid && source.contains(nxt))
|
||||||
i++;
|
i++;
|
||||||
@ -686,10 +688,11 @@ void ProtocolDock::search_nxt()
|
|||||||
|
|
||||||
while(i < _str_list.size()) {
|
while(i < _str_list.size()) {
|
||||||
QString nxt = _str_list.at(i);
|
QString nxt = _str_list.at(i);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ann_valid = decoder_stack->list_annotation(ann, col, row);
|
ann_valid = decoder_stack->list_annotation(ann, col, row);
|
||||||
row++;
|
row++;
|
||||||
}while(ann_valid && (ann.type() < 100 || ann.type() > 999));
|
}while(ann_valid && !ann.is_numberic());
|
||||||
|
|
||||||
auto strlist = ann.annotations();
|
auto strlist = ann.annotations();
|
||||||
QString source = ann.annotations().at(0);
|
QString source = ann.annotations().at(0);
|
||||||
|
@ -122,10 +122,13 @@ void ProtocolItemLayer::LoadFormatSelect(bool bSingle)
|
|||||||
m_bSetting = true;
|
m_bSetting = true;
|
||||||
_format_combox->clear();
|
_format_combox->clear();
|
||||||
|
|
||||||
_format_combox->addItem("hex");
|
if (!bSingle){
|
||||||
_format_combox->addItem("dec");
|
_format_combox->addItem("hex");
|
||||||
_format_combox->addItem("oct");
|
_format_combox->addItem("dec");
|
||||||
_format_combox->addItem("bin");
|
_format_combox->addItem("oct");
|
||||||
|
_format_combox->addItem("bin");
|
||||||
|
}
|
||||||
|
_format_combox->addItem("ascii");
|
||||||
|
|
||||||
_format_combox->setCurrentIndex(0);
|
_format_combox->setCurrentIndex(0);
|
||||||
m_bSetting = false;
|
m_bSetting = false;
|
||||||
|
@ -44,15 +44,18 @@ namespace DecoderDataFormat
|
|||||||
if (strcmp(name, "dec") == 0){
|
if (strcmp(name, "dec") == 0){
|
||||||
return (int)dec;
|
return (int)dec;
|
||||||
}
|
}
|
||||||
if (strcmp(name, "hex") == 0){
|
if (strcmp(name, "hex") == 0){
|
||||||
return (int)hex;
|
return (int)hex;
|
||||||
}
|
}
|
||||||
if (strcmp(name, "oct") == 0){
|
if (strcmp(name, "oct") == 0){
|
||||||
return (int)oct;
|
return (int)oct;
|
||||||
}
|
}
|
||||||
if (strcmp(name, "bin") == 0){
|
if (strcmp(name, "bin") == 0){
|
||||||
return (int)bin;
|
return (int)bin;
|
||||||
}
|
}
|
||||||
|
if (strcmp(name, "ascii") == 0){
|
||||||
|
return (int)ascii;
|
||||||
|
}
|
||||||
return (int)hex;
|
return (int)hex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,10 +49,11 @@ namespace DecoderDataFormat
|
|||||||
{
|
{
|
||||||
enum _data_format
|
enum _data_format
|
||||||
{
|
{
|
||||||
hex,
|
hex=0,
|
||||||
dec,
|
dec=1,
|
||||||
oct,
|
oct=2,
|
||||||
bin
|
bin=3,
|
||||||
|
ascii=4
|
||||||
};
|
};
|
||||||
|
|
||||||
int Parse(const char *name);
|
int Parse(const char *name);
|
||||||
|
@ -188,8 +188,7 @@ class Decoder(srd.Decoder):
|
|||||||
self.putx([proto[cmd][0], w])
|
self.putx([proto[cmd][0], w])
|
||||||
self.ss, self.es = self.ss_byte, self.samplenum
|
self.ss, self.es = self.ss_byte, self.samplenum
|
||||||
|
|
||||||
self.putx([proto[cmd][0], ['%s: %02X' % (proto[cmd][1], d),
|
self.putx([proto[cmd][0], ['%s: {$}' % proto[cmd][1], '%s: {$}' % proto[cmd][2], '{$}', d]])
|
||||||
'%s: %02X' % (proto[cmd][2], d), '%02X' % d]])
|
|
||||||
|
|
||||||
# Done with this packet.
|
# Done with this packet.
|
||||||
self.bitcount = self.databyte = 0
|
self.bitcount = self.databyte = 0
|
||||||
|
@ -151,9 +151,9 @@ class Decoder(srd.Decoder):
|
|||||||
|
|
||||||
# Dataword annotations.
|
# Dataword annotations.
|
||||||
if self.have_miso:
|
if self.have_miso:
|
||||||
self.put(ss, es, self.out_ann, [0, ['%02X' % self.misodata]])
|
self.put(ss, es, self.out_ann, [0, [self.misodata]])
|
||||||
if self.have_mosi:
|
if self.have_mosi:
|
||||||
self.put(ss, es, self.out_ann, [1, ['%02X' % self.mosidata]])
|
self.put(ss, es, self.out_ann, [1, [self.mosidata]])
|
||||||
|
|
||||||
def reset_decoder_state(self):
|
def reset_decoder_state(self):
|
||||||
self.misodata = 0 if self.have_miso else None
|
self.misodata = 0 if self.have_miso else None
|
||||||
|
@ -218,11 +218,11 @@ class Decoder(srd.Decoder):
|
|||||||
if self.options['bit_order'] == 'msb-first':
|
if self.options['bit_order'] == 'msb-first':
|
||||||
bits.reverse()
|
bits.reverse()
|
||||||
self.datavalue = bitpack(bits)
|
self.datavalue = bitpack(bits)
|
||||||
|
self.putx([0, [self.datavalue]])
|
||||||
b = self.datavalue
|
#b = self.datavalue
|
||||||
formatted = self.format_value(b)
|
#formatted = self.format_value(b)
|
||||||
if formatted is not None:
|
#if formatted is not None:
|
||||||
self.putx([0, [formatted]])
|
# self.putx([0, [formatted]])
|
||||||
|
|
||||||
self.databits = []
|
self.databits = []
|
||||||
|
|
||||||
|
@ -213,11 +213,10 @@ class Decoder(srd.Decoder):
|
|||||||
if cmd.startswith('ADDRESS'):
|
if cmd.startswith('ADDRESS'):
|
||||||
self.ss, self.es = self.samplenum, self.samplenum + self.bitwidth
|
self.ss, self.es = self.samplenum, self.samplenum + self.bitwidth
|
||||||
w = ['Write', 'Wr', 'W'] if self.wr else ['Read', 'Rd', 'R']
|
w = ['Write', 'Wr', 'W'] if self.wr else ['Read', 'Rd', 'R']
|
||||||
self.putx([proto[cmd][0], w])
|
self.putx([0, w])
|
||||||
self.ss, self.es = self.ss_byte, self.samplenum
|
self.ss, self.es = self.ss_byte, self.samplenum
|
||||||
|
|
||||||
self.putx([proto[cmd][0], ['%s: %02X' % (proto[cmd][1], d),
|
self.putx([proto[cmd][0], ['%s: {$}' % proto[cmd][1], '%s: {$}' % proto[cmd][2], '{$}', d]])
|
||||||
'%s: %02X' % (proto[cmd][2], d), '%02X' % d]])
|
|
||||||
|
|
||||||
# Done with this packet.
|
# Done with this packet.
|
||||||
self.bitcount = self.databyte = 0
|
self.bitcount = self.databyte = 0
|
||||||
|
@ -253,10 +253,12 @@ class Decoder(srd.Decoder):
|
|||||||
self.datavalue = bitpack(bits)
|
self.datavalue = bitpack(bits)
|
||||||
self.putpx(['DATA', 0, (self.datavalue, self.databits)])
|
self.putpx(['DATA', 0, (self.datavalue, self.databits)])
|
||||||
|
|
||||||
|
self.putx([0, [self.datavalue]])
|
||||||
|
|
||||||
b = self.datavalue
|
b = self.datavalue
|
||||||
formatted = self.format_value(b)
|
#formatted = self.format_value(b)
|
||||||
if formatted is not None:
|
#if formatted is not None:
|
||||||
self.putx([0, [formatted]])
|
# self.putx([0, [formatted]])
|
||||||
|
|
||||||
bdata = b.to_bytes(self.bw, byteorder='big')
|
bdata = b.to_bytes(self.bw, byteorder='big')
|
||||||
self.putbin([0, bdata])
|
self.putbin([0, bdata])
|
||||||
|
@ -348,6 +348,7 @@ struct srd_proto_data_annotation {
|
|||||||
int ann_class;
|
int ann_class;
|
||||||
int ann_type;
|
int ann_type;
|
||||||
char str_number_hex[18]; //numerical value hex format string
|
char str_number_hex[18]; //numerical value hex format string
|
||||||
|
long long numberic_value;
|
||||||
char **ann_text; //text string lines
|
char **ann_text; //text string lines
|
||||||
};
|
};
|
||||||
struct srd_proto_data_binary {
|
struct srd_proto_data_binary {
|
||||||
|
@ -53,7 +53,7 @@ static void release_annotation(struct srd_proto_data_annotation *pda)
|
|||||||
g_strfreev(pda->ann_text);
|
g_strfreev(pda->ann_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size, char *hex_str_buf)
|
static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size, char *hex_str_buf, long long *numberic_value)
|
||||||
{
|
{
|
||||||
PyObject *py_item, *py_bytes;
|
PyObject *py_item, *py_bytes;
|
||||||
char **strv, *str;
|
char **strv, *str;
|
||||||
@ -93,7 +93,8 @@ static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size
|
|||||||
|
|
||||||
if (py_numobj != NULL){
|
if (py_numobj != NULL){
|
||||||
lv = PyLong_AsLongLong(py_numobj);
|
lv = PyLong_AsLongLong(py_numobj);
|
||||||
sprintf(hex_str_buf, "%02llX", lv);
|
sprintf(hex_str_buf, "%02llX", lv);
|
||||||
|
*numberic_value = lv;
|
||||||
}
|
}
|
||||||
|
|
||||||
//have no text, only one numberical
|
//have no text, only one numberical
|
||||||
@ -209,7 +210,9 @@ static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj,
|
|||||||
|
|
||||||
pda->str_number_hex[0] = 0;
|
pda->str_number_hex[0] = 0;
|
||||||
ann_text = NULL;
|
ann_text = NULL;
|
||||||
if (py_parse_ann_data(py_tmp, &ann_text, ann_size, pda->str_number_hex) != SRD_OK) {
|
pda->numberic_value = 0;
|
||||||
|
|
||||||
|
if (py_parse_ann_data(py_tmp, &ann_text, ann_size, pda->str_number_hex, &pda->numberic_value) != SRD_OK) {
|
||||||
srd_err("Protocol decoder %s submitted annotation list, but "
|
srd_err("Protocol decoder %s submitted annotation list, but "
|
||||||
"second element was malformed.", di->decoder->name);
|
"second element was malformed.", di->decoder->name);
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.11.0, 2022-01-10T16:21:21. -->
|
<!-- Written by QtCreator 4.11.0, 2022-01-10T18:22:56. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user