One decoder onwer a resoure table

This commit is contained in:
dreamsourcelabTAI 2022-01-28 20:00:47 +08:00
parent 34de06d0a3
commit cd449045b0
19 changed files with 128 additions and 61 deletions

View File

@ -112,8 +112,14 @@ int main(int argc, char *argv[])
QApplication::setOrganizationDomain("www.DreamSourceLab.com");
#ifdef Q_OS_LINUX
QCoreApplication::addLibraryPath("/usr/lib/x86_64-linux-gnu/qt5/plugins");
printf("qt plugins root:/usr/lib/x86_64-linux-gnu/qt5/plugins\n");
// Use low version qt plugins, for able to debug
QDir qtdir;
qtdir.setPath(GetAppDataDir() + "/qt5.0/plugins");
if (qtdir.exists()){
printf("qt plugins root:%s\n", qtdir.absolutePath().toLatin1().data());
QCoreApplication::addLibraryPath(qtdir.absolutePath());
}
#endif
AppControl *control = AppControl::Instance();

View File

@ -25,7 +25,7 @@
#include <assert.h>
#include "annotation.h"
#include "AnnotationResTable.h"
#include "annotationrestable.h"
#include <cstring>
#include <assert.h>
#include <string.h>
@ -33,10 +33,7 @@
#include "decoderstatus.h"
#include "../../dsvdef.h"
//a find talbe instance
AnnotationResTable annTable;
char sz_format_tmp_buf[50];
bool is_hex_number_str(const char *str)
{
char c = *str;
@ -65,6 +62,7 @@ Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status)
const srd_proto_data_annotation *const pda =
(const srd_proto_data_annotation*)pdata->data;
assert(pda);
assert(status);
_start_sample = pdata->start_sample;
_end_sample = pdata->end_sample;
@ -88,7 +86,7 @@ Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status)
}
AnnotationSourceItem *resItem = NULL;
_resIndex = annTable.MakeIndex(key, resItem);
_resIndex = _status->m_resTable.MakeIndex(key, resItem);
//is a new item
if (resItem != NULL){
@ -103,11 +101,14 @@ 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;
}
@ -125,44 +126,38 @@ Annotation::~Annotation()
}
const std::vector<QString>& Annotation::annotations() const
{
assert(_status);
AnnotationSourceItem &resItem = *annTable.GetItem(_resIndex);
{
AnnotationSourceItem &resItem = *(_status->m_resTable.GetItem(_resIndex));
//get origin data, is not a numberic value
if (!resItem.is_numeric){
return resItem.src_lines;
}
//resItem.str_number_hex must be not null
if (resItem.str_number_hex[0] == 0){
assert(false);
}
if (resItem.cur_display_format != _status->m_format){
resItem.cur_display_format = _status->m_format;
resItem.cvt_lines.clear();
if (resItem.src_lines.size() > 0)
{
//have custom string
for (QString &rd_src : resItem.src_lines)
{
if (resItem.str_number_hex[0] != 0)
{
QString src = rd_src.replace("{$}", "%s");
const char *num_str = AnnotationResTable::format_numberic(resItem.str_number_hex, resItem.cur_display_format);
sprintf(sz_format_tmp_buf, src.toLatin1().data(), num_str);
resItem.cvt_lines.push_back(QString(sz_format_tmp_buf));
}
else
{
const char *src_str = rd_src.toLatin1().data();
const char *num_str = AnnotationResTable::format_numberic(src_str, resItem.cur_display_format);
if (src_str != num_str)
resItem.cvt_lines.push_back(QString(num_str));
else
resItem.cvt_lines.push_back(QString(rd_src));
}
char sz_format_tmp_buf[50] = {0};
QString src = rd_src.replace("{$}", "%s");
const char *num_str = _status->m_resTable.format_numberic(resItem.str_number_hex, resItem.cur_display_format);
sprintf(sz_format_tmp_buf, src.toLatin1().data(), num_str);
resItem.cvt_lines.push_back(QString(sz_format_tmp_buf));
}
}
else{
const char *num_str = AnnotationResTable::format_numberic(resItem.str_number_hex, resItem.cur_display_format);
//have only numberic value
const char *num_str = _status->m_resTable.format_numberic(resItem.str_number_hex, resItem.cur_display_format);
resItem.cvt_lines.push_back(QString(num_str));
}
}
@ -172,7 +167,7 @@ const std::vector<QString>& Annotation::annotations() const
bool Annotation::is_numberic()
{
AnnotationSourceItem *resItem = annTable.GetItem(_resIndex);
AnnotationSourceItem *resItem = _status->m_resTable.GetItem(_resIndex);
return resItem->is_numeric;
}

View File

@ -2,7 +2,7 @@
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2014 DreamSourceLab <support@dreamsourcelab.com>
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,16 +19,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "AnnotationResTable.h"
#include "annotationrestable.h"
#include <assert.h>
#include "../../dsvdef.h"
#define DECODER_MAX_DATA_BLOCK_LEN 25
const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111";
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* bin2oct_string(char *buf, int size, const char *bin, int len){
char *wr = buf + size - 1;
@ -98,6 +93,15 @@ long long bin2long_string(const char *bin, int len)
return value;
}
//-----------------------------------
AnnotationResTable::AnnotationResTable(){
}
AnnotationResTable::~AnnotationResTable(){
reset();
}
int AnnotationResTable::MakeIndex(const std::string &key, AnnotationSourceItem* &newItem)
{
@ -126,7 +130,7 @@ AnnotationSourceItem* AnnotationResTable::GetItem(int index){
const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt)
{
assert(hex_str);
//flow, convert to oct\dec\bin format
const char *data = hex_str;
if (data[0] == 0 || fmt == DecoderDataFormat::hex){
@ -203,4 +207,14 @@ const char* AnnotationResTable::format_numberic(const char *hex_str, int fmt)
return data;
}
void AnnotationResTable::reset()
{
//release all resource
for (auto p : m_resourceTable){
delete p;
}
m_resourceTable.clear();
m_indexs.clear();
}

View File

@ -2,7 +2,7 @@
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2014 DreamSourceLab <support@dreamsourcelab.com>
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,6 +26,8 @@
#include <vector>
#include <QString>
#define DECODER_MAX_DATA_BLOCK_LEN 25
struct AnnotationSourceItem
{
bool is_numeric;
@ -38,6 +40,10 @@ struct AnnotationSourceItem
class AnnotationResTable
{
public:
AnnotationResTable();
~AnnotationResTable();
public:
int MakeIndex(const std::string &key, AnnotationSourceItem* &newItem);
AnnotationSourceItem* GetItem(int index);
@ -45,9 +51,14 @@ class AnnotationResTable
inline int GetCount(){
return m_resourceTable.size();}
static const char* format_numberic(const char *hex_str, int fmt);
const char* format_numberic(const char *hex_str, int fmt);
void reset();
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];
};

View File

@ -0,0 +1,35 @@
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "decoderstatus.h"
DecoderStatus::DecoderStatus()
{
m_bNumeric = false;
m_format = 0;
sdr_decoder_handle = NULL;
}
void DecoderStatus::clear()
{
m_resTable.reset();
}

View File

@ -2,7 +2,7 @@
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2014 DreamSourceLab <support@dreamsourcelab.com>
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,18 +21,18 @@
#pragma once
#include "annotationrestable.h"
class DecoderStatus
{
public:
DecoderStatus()
{
m_bNumeric = false;
m_format = 0;
sdr_decoder_handle = NULL;
}
DecoderStatus();
void clear();
public:
bool m_bNumeric; //when decoder get any numerical data,it will be set
int m_format; //protocol format code
void *sdr_decoder_handle;
bool m_bNumeric; //when decoder get any numerical data,it will be set
int m_format; //protocol format code
void *sdr_decoder_handle;
AnnotationResTable m_resTable;
};

View File

@ -20,6 +20,7 @@
*/
#include <math.h>
#include <assert.h>
#include "rowdata.h"

View File

@ -73,6 +73,9 @@ DecoderStack::DecoderStack(pv::SigSession *session,
DecoderStack::~DecoderStack()
{
//release resource talbe
DESTROY_OBJECT(_decoder_status);
//release source
for (auto &kv : _rows)
{
@ -392,6 +395,7 @@ void DecoderStack::do_decode_work()
}
_stask_stauts = new decode_task_status();
_stask_stauts->m_bStop = false;
_decoder_status->clear(); //clear old items
pv::view::LogicSignal *logic_signal = NULL;
pv::data::Logic *data = NULL;

View File

@ -31,8 +31,8 @@
#include "decode/row.h"
#include "../data/signaldata.h"
class DecoderStatus;
#include "decode/decoderstatus.h"
struct decode_task_status
{

View File

@ -20,6 +20,7 @@
*/
#include <sstream>
#include <assert.h>
#include "device.h"

View File

@ -27,7 +27,6 @@
#include <zip.h>
#include <boost/filesystem.hpp>
using std::string;

View File

@ -20,6 +20,7 @@
*/
#include "sessionfile.h"
#include <assert.h>
namespace pv {
namespace device {

View File

@ -26,6 +26,7 @@
#include <QProgressDialog>
#include <QtConcurrent/QtConcurrent>
#include <QTime>
#include <assert.h>
#include "../view/trace.h"
#include "../dialogs/dsmessagebox.h"

View File

@ -32,7 +32,6 @@
#include "../dsvdef.h"
using namespace boost;
using namespace std;
using namespace pv::view;

View File

@ -33,7 +33,7 @@
#include "../int.h"
#include "../../config/appconfig.h"
using namespace boost;
using namespace std;
namespace pv {

View File

@ -33,7 +33,7 @@
#include "../../config/appconfig.h"
using namespace boost;
using namespace std;
namespace pv {

View File

@ -716,7 +716,7 @@ void StoreSession::export_proc(data::Snapshot *snapshot)
meta.config = g_slist_append(meta.config, src);
GVariant *gvar;
uint8_t bits;
uint8_t bits=0;
gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_UNIT_BITS);
if (gvar != NULL) {
bits = g_variant_get_byte(gvar);

View File

@ -31,7 +31,6 @@
#include "view.h"
#include "../extdef.h"
using namespace boost;
using namespace std;
namespace pv {

View File

@ -91,6 +91,7 @@ static int py_parse_ann_data(PyObject *list_obj, char ***out_strv, int list_size
goto err;
}
//vet numberic value
if (py_numobj != NULL){
lv = PyLong_AsLongLong(py_numobj);
sprintf(hex_str_buf, "%02llX", lv);