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_EN 31
#define DARK_STYLE "dark"
//#define DARK_STYLE "dark"
//--------------------api---

View File

@ -21,6 +21,7 @@
#include "annotationrestable.h"
#include <assert.h>
#include <stdlib.h>
#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

View File

@ -27,6 +27,7 @@
#include <QString>
#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<std::string, int> m_indexs;
std::vector<AnnotationSourceItem*> 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];
};

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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()
{

View File

@ -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;

View File

@ -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])

View File

@ -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);
}

View File

@ -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 {