From fd27873c216bc9b8fbd9a3ee84228323886a6698 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Wed, 23 Mar 2022 16:45:21 +0800 Subject: [PATCH] fix: if numberic string have split letter, it can not format right --- DSView/pv/config/appconfig.h | 2 +- DSView/pv/data/decode/annotationrestable.cpp | 125 ++++++++++++++++++- DSView/pv/data/decode/annotationrestable.h | 5 + DSView/pv/data/decode/decoder.h | 4 + DSView/pv/data/decoderstack.cpp | 11 +- DSView/pv/view/decodetrace.cpp | 40 +++--- DSView/pv/view/decodetrace.h | 7 +- libsigrokdecode4DSL/decoders/1-spi/pd.py | 4 +- libsigrokdecode4DSL/instance.c | 5 +- libsigrokdecode4DSL/libsigrokdecode.h | 2 + 10 files changed, 164 insertions(+), 41 deletions(-) diff --git a/DSView/pv/config/appconfig.h b/DSView/pv/config/appconfig.h index 43b7cbe7..95e9f834 100644 --- a/DSView/pv/config/appconfig.h +++ b/DSView/pv/config/appconfig.h @@ -29,7 +29,7 @@ #define LAN_CN 25 #define LAN_EN 31 -#define DARK_STYLE "dark" +//#define DARK_STYLE "dark" //--------------------api--- diff --git a/DSView/pv/data/decode/annotationrestable.cpp b/DSView/pv/data/decode/annotationrestable.cpp index 3f777cd5..b2295bfb 100644 --- a/DSView/pv/data/decode/annotationrestable.cpp +++ b/DSView/pv/data/decode/annotationrestable.cpp @@ -21,6 +21,7 @@ #include "annotationrestable.h" #include +#include #include "../../dsvdef.h" const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111"; @@ -127,10 +128,8 @@ AnnotationSourceItem* AnnotationResTable::GetItem(int index){ return m_resourceTable[index]; } -const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt) -{ - assert(hex_str); - +const char* AnnotationResTable::format_to_string(const char *hex_str, int fmt) +{ //flow, convert to oct\dec\bin format const char *data = hex_str; if (data[0] == 0 || fmt == DecoderDataFormat::hex){ @@ -208,6 +207,124 @@ const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt) return data; } +const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt) +{ + assert(hex_str); + + if (hex_str[0] == 0 || fmt == DecoderDataFormat::hex){ + return hex_str; + } + + //check if have split letter + const char *rd = hex_str; + bool bMutil = false; + char c = 0; + + while (*rd) + { + c = *rd; + rd++; + + if (c >= '0' && c <= '9') + { + continue; + } + if (c >= 'A' && c <= 'F') + { + continue; + } + bMutil = true; + break; + } + + if (!bMutil){ + return format_to_string(hex_str, fmt); + } + + //convert each sub string + char sub_buf[DECODER_MAX_DATA_BLOCK_LEN + 1]; + char *sub_wr = sub_buf; + char *sub_end = sub_wr + DECODER_MAX_DATA_BLOCK_LEN; + char *all_buf = g_all_buf; + char *all_wr = all_buf; + + rd = hex_str; + + while (*rd) + { + c = *rd; + rd++; + + if (c >= '0' && c <= '9'){ + if (sub_wr == sub_end){ + printf("conver error,sub string length is too long!\n"); + return hex_str; + } + + *sub_wr = c; //make sub string + sub_wr++; + continue; + } + + if (c >= 'A' && c <= 'F'){ + if (sub_wr == sub_end){ + printf("convert error,sub string length is too long!\n"); + return hex_str; + } + + *sub_wr = c; + sub_wr++; + continue; + } + + //convert sub string + if (sub_wr != sub_buf){ + *sub_wr = 0; + const char *sub_str = format_to_string(sub_buf, fmt); + int sublen = strlen(sub_str); + + if ((all_wr - all_buf) + sublen > CONVERT_STR_MAX_LEN){ + printf("convert error,write buffer is full!\n"); + return hex_str; + } + + strncpy(all_wr, sub_str, sublen); + all_wr += sublen; + sub_wr = sub_buf; //reset write buffer + } + + //the split letter + if ((all_wr - all_buf) + 1 > CONVERT_STR_MAX_LEN){ + printf("convert error,write buffer is full!\n"); + return hex_str; + } + + *all_wr = c; + all_wr++; + } + + //convert the last sub string + if (sub_wr != sub_buf) + { + *sub_wr = 0; + const char *sub_str = format_to_string(sub_buf, fmt); + int sublen = strlen(sub_str); + + if ((all_wr - all_buf) + sublen > CONVERT_STR_MAX_LEN) + { + printf("convert error,write buffer is full!\n"); + return hex_str; + } + + strncpy(all_wr, sub_str, sublen); + all_wr += sublen; + } + + *all_wr = 0; + + return all_buf; +} + void AnnotationResTable::reset() { //release all resource diff --git a/DSView/pv/data/decode/annotationrestable.h b/DSView/pv/data/decode/annotationrestable.h index 2a30f9d8..6fbe95ac 100644 --- a/DSView/pv/data/decode/annotationrestable.h +++ b/DSView/pv/data/decode/annotationrestable.h @@ -27,6 +27,7 @@ #include #define DECODER_MAX_DATA_BLOCK_LEN 35 +#define CONVERT_STR_MAX_LEN 150 struct AnnotationSourceItem { @@ -55,10 +56,14 @@ class AnnotationResTable void reset(); + private: + const char* format_to_string(const char *hex_str, int fmt); + private: std::map m_indexs; std::vector m_resourceTable; char g_bin_format_tmp_buffer[DECODER_MAX_DATA_BLOCK_LEN * 4 + 2]; char g_oct_format_tmp_buffer[DECODER_MAX_DATA_BLOCK_LEN * 3 + 2]; char g_number_tmp_64[30]; + char g_all_buf[CONVERT_STR_MAX_LEN + 1]; }; diff --git a/DSView/pv/data/decode/decoder.h b/DSView/pv/data/decode/decoder.h index cb5a34d1..2b9a3e39 100755 --- a/DSView/pv/data/decode/decoder.h +++ b/DSView/pv/data/decode/decoder.h @@ -83,6 +83,10 @@ public: return _decode_start; } + inline void reset_start(){ + _decode_start = _decode_start_back; + } + inline uint64_t decode_end(){ return _decode_end; } diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 7be39a0d..8d6db49e 100755 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -80,7 +80,7 @@ DecoderStack::~DecoderStack() //release source for (auto &kv : _rows) { - kv.second->clear(); + kv.second->clear(); //destory all annotations delete kv.second; } _rows.clear(); @@ -127,7 +127,8 @@ void DecoderStack::build_row() { //release source for (auto &kv : _rows) - { + { + kv.second->clear(); //destory all annotations delete kv.second; } _rows.clear(); @@ -139,6 +140,8 @@ void DecoderStack::build_row() const srd_decoder *const decc = dec->decoder(); assert(dec->decoder()); + dec->reset_start(); + // Add a row for the decoder if it doesn't have a row list if (!decc->annotation_rows) { const Row row(decc); @@ -378,6 +381,7 @@ void DecoderStack::begin_decode_work() { assert(_decode_state == Stopped); + _error_message = ""; _decode_state = Running; do_decode_work(); _decode_state = Stopped; @@ -571,8 +575,9 @@ void DecoderStack::execute_decode_stack() // Get the intial sample count _sample_count = _snapshot->get_sample_count(); - + qDebug()<<"decoder sample count:"<<_sample_count; + // Create the decoders for(auto &dec : _stack) { diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index 5508f657..e83d82d9 100755 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -374,6 +374,7 @@ bool DecodeTrace::create_popup() } _decoder_container = NULL; + _decoder_panels.clear(); return ret; } @@ -502,7 +503,7 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form) connect(_start_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_region_set(int))); connect(_end_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_region_set(int))); - connect(decoder_menu, SIGNAL(decoder_selected(srd_decoder *)), this, SLOT(on_stack_decoder(srd_decoder *))); + connect(decoder_menu, SIGNAL(decoder_selected(srd_decoder *)), this, SLOT(on_add_stack(srd_decoder *))); connect(button_box, SIGNAL(accepted()), parent, SLOT(accept())); connect(button_box, SIGNAL(rejected()), parent, SLOT(reject())); } @@ -899,7 +900,7 @@ void DecodeTrace::on_probe_selected(int) commit_probes(); } -void DecodeTrace::on_stack_decoder(srd_decoder *decoder) +void DecodeTrace::on_add_stack(srd_decoder *decoder) { assert(decoder); assert(_decoder_stack); @@ -925,6 +926,8 @@ void DecodeTrace::on_stack_decoder(srd_decoder *decoder) } load_all_decoder_property(items); + + on_region_set(_start_index); } void DecodeTrace::on_del_stack(data::decode::Decoder *dec) @@ -942,29 +945,28 @@ void DecodeTrace::on_del_stack(data::decode::Decoder *dec) dels.push_back((*it)); auto del_it = it; + //rebuild the panel it++; while (it != _decoder_panels.end()) { dels.push_back((*it)); adds.push_back((pv::data::decode::Decoder*)(*it).decoder_handle); it++; - } - _decoder_panels.erase(del_it); + } + _decoder_panels.erase(del_it); break; } } - while (true) - { - if (dels.empty()) - break; - + while (dels.size() > 0) + { auto it = dels.end(); it--; auto inf = (*it); assert(inf.panel); inf.panel->deleteLater(); + inf.panel = NULL; dels.erase(it); for (auto fd = _decoder_panels.begin(); fd != _decoder_panels.end(); ++fd){ @@ -977,25 +979,11 @@ void DecodeTrace::on_del_stack(data::decode::Decoder *dec) if (adds.size() > 0){ load_all_decoder_property(adds); - } - -// QTimer::singleShot(200, this, SLOT(on_resize_decoder_panel())); -} - -void DecodeTrace::on_resize_decoder_panel() -{ - /* - int dex = 0; - - for (auto &panel : _decoder_panels){ - assert(panel.panel); - dex++; - if (dex > 1){ - panel.panel->setMaximumHeight(panel.panel_height); - } } - */ + + on_region_set(_start_index); } + int DecodeTrace::rows_size() { diff --git a/DSView/pv/view/decodetrace.h b/DSView/pv/view/decodetrace.h index e9a39543..833b515f 100755 --- a/DSView/pv/view/decodetrace.h +++ b/DSView/pv/view/decodetrace.h @@ -203,15 +203,14 @@ signals: private slots: void on_new_decode_data(); void on_probe_selected(int); - void on_stack_decoder(srd_decoder *decoder); + void on_add_stack(srd_decoder *decoder); void on_del_stack(data::decode::Decoder *dec); void on_decode_done(); - void on_region_set(int index); - void on_resize_decoder_panel(); + void on_region_set(int index); public: - volatile bool _delete_flag; //detroy it when deocde task end + volatile bool _delete_flag; //destroy it when deocde task end private: pv::SigSession *_session; diff --git a/libsigrokdecode4DSL/decoders/1-spi/pd.py b/libsigrokdecode4DSL/decoders/1-spi/pd.py index 355ecc75..d094dcf4 100755 --- a/libsigrokdecode4DSL/decoders/1-spi/pd.py +++ b/libsigrokdecode4DSL/decoders/1-spi/pd.py @@ -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/instance.c b/libsigrokdecode4DSL/instance.c index 1b3d5df7..1066b245 100755 --- a/libsigrokdecode4DSL/instance.c +++ b/libsigrokdecode4DSL/instance.c @@ -1046,11 +1046,13 @@ static gpointer di_thread(gpointer data) struct srd_decoder_inst *di; int wanted_term; PyGILState_STATE gstate; + char ** error_buffer = NULL; if (!data) return NULL; di = data; + error_buffer = di->error_buffer; srd_dbg("%s: Starting thread routine for decoder.", di->inst_id); @@ -1093,7 +1095,7 @@ static gpointer di_thread(gpointer data) * Silently ignore errors upon return from decode() calls * when termination was requested. Terminate the thread * which executed this instance's decode() logic. - */ + */ srd_dbg("%s: Thread done (!res, want_term).", di->inst_id); PyErr_Clear(); PyGILState_Release(gstate); @@ -1221,6 +1223,7 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di, if (!di->thread_handle) { srd_dbg("No worker thread for this decoder stack " "exists yet, creating one: %s.", di->inst_id); + di->error_buffer = error; di->thread_handle = g_thread_new(di->inst_id, di_thread, di); } diff --git a/libsigrokdecode4DSL/libsigrokdecode.h b/libsigrokdecode4DSL/libsigrokdecode.h index 90117735..488d1140 100755 --- a/libsigrokdecode4DSL/libsigrokdecode.h +++ b/libsigrokdecode4DSL/libsigrokdecode.h @@ -327,6 +327,8 @@ struct srd_decoder_inst { GCond got_new_samples_cond; GCond handled_all_samples_cond; GMutex data_mutex; + + char **error_buffer; }; struct srd_pd_output {