fix: if numberic string have split letter, it can not format right

This commit is contained in:
dreamsourcelabTAI 2022-03-23 16:45:21 +08:00
parent a1cc19588a
commit fd27873c21
10 changed files with 164 additions and 41 deletions

View File

@ -29,7 +29,7 @@
#define LAN_CN 25 #define LAN_CN 25
#define LAN_EN 31 #define LAN_EN 31
#define DARK_STYLE "dark" //#define DARK_STYLE "dark"
//--------------------api--- //--------------------api---

View File

@ -21,6 +21,7 @@
#include "annotationrestable.h" #include "annotationrestable.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include "../../dsvdef.h" #include "../../dsvdef.h"
const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111"; const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111";
@ -127,10 +128,8 @@ AnnotationSourceItem* AnnotationResTable::GetItem(int index){
return m_resourceTable[index]; return m_resourceTable[index];
} }
const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt) const char* AnnotationResTable::format_to_string(const char *hex_str, int fmt)
{ {
assert(hex_str);
//flow, convert to oct\dec\bin format //flow, convert to oct\dec\bin format
const char *data = hex_str; const char *data = hex_str;
if (data[0] == 0 || fmt == DecoderDataFormat::hex){ if (data[0] == 0 || fmt == DecoderDataFormat::hex){
@ -208,6 +207,124 @@ const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt)
return data; 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() void AnnotationResTable::reset()
{ {
//release all resource //release all resource

View File

@ -27,6 +27,7 @@
#include <QString> #include <QString>
#define DECODER_MAX_DATA_BLOCK_LEN 35 #define DECODER_MAX_DATA_BLOCK_LEN 35
#define CONVERT_STR_MAX_LEN 150
struct AnnotationSourceItem struct AnnotationSourceItem
{ {
@ -55,10 +56,14 @@ class AnnotationResTable
void reset(); void reset();
private:
const char* format_to_string(const char *hex_str, int fmt);
private: private:
std::map<std::string, int> m_indexs; std::map<std::string, int> m_indexs;
std::vector<AnnotationSourceItem*> m_resourceTable; std::vector<AnnotationSourceItem*> m_resourceTable;
char g_bin_format_tmp_buffer[DECODER_MAX_DATA_BLOCK_LEN * 4 + 2]; 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_oct_format_tmp_buffer[DECODER_MAX_DATA_BLOCK_LEN * 3 + 2];
char g_number_tmp_64[30]; char g_number_tmp_64[30];
char g_all_buf[CONVERT_STR_MAX_LEN + 1];
}; };

View File

@ -83,6 +83,10 @@ public:
return _decode_start; return _decode_start;
} }
inline void reset_start(){
_decode_start = _decode_start_back;
}
inline uint64_t decode_end(){ inline uint64_t decode_end(){
return _decode_end; return _decode_end;
} }

View File

@ -80,7 +80,7 @@ DecoderStack::~DecoderStack()
//release source //release source
for (auto &kv : _rows) for (auto &kv : _rows)
{ {
kv.second->clear(); kv.second->clear(); //destory all annotations
delete kv.second; delete kv.second;
} }
_rows.clear(); _rows.clear();
@ -128,6 +128,7 @@ void DecoderStack::build_row()
//release source //release source
for (auto &kv : _rows) for (auto &kv : _rows)
{ {
kv.second->clear(); //destory all annotations
delete kv.second; delete kv.second;
} }
_rows.clear(); _rows.clear();
@ -139,6 +140,8 @@ void DecoderStack::build_row()
const srd_decoder *const decc = dec->decoder(); const srd_decoder *const decc = dec->decoder();
assert(dec->decoder()); assert(dec->decoder());
dec->reset_start();
// Add a row for the decoder if it doesn't have a row list // Add a row for the decoder if it doesn't have a row list
if (!decc->annotation_rows) { if (!decc->annotation_rows) {
const Row row(decc); const Row row(decc);
@ -378,6 +381,7 @@ void DecoderStack::begin_decode_work()
{ {
assert(_decode_state == Stopped); assert(_decode_state == Stopped);
_error_message = "";
_decode_state = Running; _decode_state = Running;
do_decode_work(); do_decode_work();
_decode_state = Stopped; _decode_state = Stopped;
@ -572,6 +576,7 @@ void DecoderStack::execute_decode_stack()
// Get the intial sample count // Get the intial sample count
_sample_count = _snapshot->get_sample_count(); _sample_count = _snapshot->get_sample_count();
qDebug()<<"decoder sample count:"<<_sample_count;
// Create the decoders // Create the decoders
for(auto &dec : _stack) for(auto &dec : _stack)

View File

@ -374,6 +374,7 @@ bool DecodeTrace::create_popup()
} }
_decoder_container = NULL; _decoder_container = NULL;
_decoder_panels.clear();
return ret; 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(_start_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_region_set(int)));
connect(_end_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(accepted()), parent, SLOT(accept()));
connect(button_box, SIGNAL(rejected()), parent, SLOT(reject())); connect(button_box, SIGNAL(rejected()), parent, SLOT(reject()));
} }
@ -899,7 +900,7 @@ void DecodeTrace::on_probe_selected(int)
commit_probes(); commit_probes();
} }
void DecodeTrace::on_stack_decoder(srd_decoder *decoder) void DecodeTrace::on_add_stack(srd_decoder *decoder)
{ {
assert(decoder); assert(decoder);
assert(_decoder_stack); assert(_decoder_stack);
@ -925,6 +926,8 @@ void DecodeTrace::on_stack_decoder(srd_decoder *decoder)
} }
load_all_decoder_property(items); load_all_decoder_property(items);
on_region_set(_start_index);
} }
void DecodeTrace::on_del_stack(data::decode::Decoder *dec) void DecodeTrace::on_del_stack(data::decode::Decoder *dec)
@ -942,6 +945,7 @@ void DecodeTrace::on_del_stack(data::decode::Decoder *dec)
dels.push_back((*it)); dels.push_back((*it));
auto del_it = it; auto del_it = it;
//rebuild the panel
it++; it++;
while (it != _decoder_panels.end()) while (it != _decoder_panels.end())
{ {
@ -954,17 +958,15 @@ void DecodeTrace::on_del_stack(data::decode::Decoder *dec)
} }
} }
while (true) while (dels.size() > 0)
{ {
if (dels.empty())
break;
auto it = dels.end(); auto it = dels.end();
it--; it--;
auto inf = (*it); auto inf = (*it);
assert(inf.panel); assert(inf.panel);
inf.panel->deleteLater(); inf.panel->deleteLater();
inf.panel = NULL;
dels.erase(it); dels.erase(it);
for (auto fd = _decoder_panels.begin(); fd != _decoder_panels.end(); ++fd){ for (auto fd = _decoder_panels.begin(); fd != _decoder_panels.end(); ++fd){
@ -979,23 +981,9 @@ void DecodeTrace::on_del_stack(data::decode::Decoder *dec)
load_all_decoder_property(adds); load_all_decoder_property(adds);
} }
// QTimer::singleShot(200, this, SLOT(on_resize_decoder_panel())); on_region_set(_start_index);
} }
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);
}
}
*/
}
int DecodeTrace::rows_size() int DecodeTrace::rows_size()
{ {

View File

@ -203,15 +203,14 @@ signals:
private slots: private slots:
void on_new_decode_data(); void on_new_decode_data();
void on_probe_selected(int); 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_del_stack(data::decode::Decoder *dec);
void on_decode_done(); void on_decode_done();
void on_region_set(int index); void on_region_set(int index);
void on_resize_decoder_panel();
public: public:
volatile bool _delete_flag; //detroy it when deocde task end volatile bool _delete_flag; //destroy it when deocde task end
private: private:
pv::SigSession *_session; pv::SigSession *_session;

View File

@ -289,10 +289,10 @@ class Decoder(srd.Decoder):
elif self.ss_transfer != -1: elif self.ss_transfer != -1:
if self.have_miso: if self.have_miso:
self.put(self.ss_transfer, self.samplenum, self.out_ann, 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: if self.have_mosi:
self.put(self.ss_transfer, self.samplenum, self.out_ann, 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, self.put(self.ss_transfer, self.samplenum, self.out_python,
['TRANSFER', self.mosibytes, self.misobytes]) ['TRANSFER', self.mosibytes, self.misobytes])

View File

@ -1046,11 +1046,13 @@ static gpointer di_thread(gpointer data)
struct srd_decoder_inst *di; struct srd_decoder_inst *di;
int wanted_term; int wanted_term;
PyGILState_STATE gstate; PyGILState_STATE gstate;
char ** error_buffer = NULL;
if (!data) if (!data)
return NULL; return NULL;
di = data; di = data;
error_buffer = di->error_buffer;
srd_dbg("%s: Starting thread routine for decoder.", di->inst_id); srd_dbg("%s: Starting thread routine for decoder.", di->inst_id);
@ -1221,6 +1223,7 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di,
if (!di->thread_handle) { if (!di->thread_handle) {
srd_dbg("No worker thread for this decoder stack " srd_dbg("No worker thread for this decoder stack "
"exists yet, creating one: %s.", di->inst_id); "exists yet, creating one: %s.", di->inst_id);
di->error_buffer = error;
di->thread_handle = g_thread_new(di->inst_id, di->thread_handle = g_thread_new(di->inst_id,
di_thread, di); di_thread, di);
} }

View File

@ -327,6 +327,8 @@ struct srd_decoder_inst {
GCond got_new_samples_cond; GCond got_new_samples_cond;
GCond handled_all_samples_cond; GCond handled_all_samples_cond;
GMutex data_mutex; GMutex data_mutex;
char **error_buffer;
}; };
struct srd_pd_output { struct srd_pd_output {