Merge branch 'master' of https://github.com/dreamsource-tai/DSView into dreamsource-tai-master

This commit is contained in:
DreamSourceLab 2022-01-27 05:43:07 -08:00
commit 07d3d04173
579 changed files with 21740 additions and 6132 deletions

1
.gitignore vendored
View File

@ -49,3 +49,4 @@ moc_*.cpp_parameters
DSView-prj
build*
share
.vscode

BIN
DSView.icns Normal file

Binary file not shown.

View File

@ -1,10 +0,0 @@
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=DSView
Comment=GUI Program for DreamSourceLab USB-based Instruments
TryExec=DSView
Exec=DSView
Icon=dsview
Terminal=false
Categories=Development;Electronics;Qt;

36
DSView/config.h Executable file
View File

@ -0,0 +1,36 @@
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _DSVIEW_CONFIG_H
#define _DSVIEW_CONFIG_H
/* Application details */
#define DS_TITLE "DSView"
#define DS_DESCRIPTION "A GUI for instruments of DreamSourceLab"
#define DS_BIN_NAME "DSView"
/* DSView version information */
#define DS_VERSION_MAJOR 1
#define DS_VERSION_MINOR 2
#define DS_VERSION_MICRO 0
#define DS_VERSION_STRING "1.2.0"
#define DS_DEBUG_TRACE
#endif

View File

@ -19,12 +19,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <libsigrok4DSL/libsigrok.h>
#ifdef ENABLE_DECODE
#include <libsigrokdecode4DSL/libsigrokdecode.h>
#endif
#include <stdint.h>
#include <getopt.h>
@ -33,22 +28,25 @@
#include <QFile>
#include <QDir>
#include <QTranslator>
#include <QSettings>
#include <QDesktopServices>
#include <QStyle>
#include "dsapplication.h"
#include "mystyle.h"
#include "pv/devicemanager.h"
#include "mystyle.h"
#include "pv/mainframe.h"
#include "pv/config/appconfig.h"
#include "config.h"
#include "pv/appcontrol.h"
char DS_RES_PATH[256];
#ifdef _WIN32
#include <windows.h>
#endif
//#include <libsigrok4DSL/libsigrok.h>
void usage()
{
fprintf(stdout,
printf(
"Usage:\n"
" %s [OPTION…] [FILE] — %s\n"
"\n"
@ -57,15 +55,18 @@ void usage()
" -V, --version Show release version\n"
" -h, -?, --help Show help option\n"
"\n", DS_BIN_NAME, DS_DESCRIPTION);
}
}
int main(int argc, char *argv[])
{
int ret = 0;
struct sr_context *sr_ctx = NULL;
{
// sr_test_usb_api();return 0;
int ret = 0;
const char *open_file = NULL;
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
//On Windows, need to compile with the QT5 version of the library, which makes the interface slightly larger.
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif // QT_VERSION
@ -110,6 +111,13 @@ int main(int argc, char *argv[])
QApplication::setOrganizationName("DreamSourceLab");
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");
#endif
AppControl *control = AppControl::Instance();
// Parse arguments
while (1) {
static const struct option long_options[] = {
@ -128,18 +136,13 @@ int main(int argc, char *argv[])
case 'l':
{
const int loglevel = atoi(optarg);
sr_log_loglevel_set(loglevel);
#ifdef ENABLE_DECODE
srd_log_loglevel_set(loglevel);
#endif
control->SetLogLevel(loglevel);
break;
}
case 'V':
// Print version info
fprintf(stdout, "%s %s\n", DS_TITLE, DS_VERSION_STRING);
printf("%s %s\n", DS_TITLE, DS_VERSION_STRING);
return 0;
case 'h':
@ -150,69 +153,55 @@ int main(int argc, char *argv[])
}
if (argcFinal - optind > 1) {
fprintf(stderr, "Only one file can be openened.\n");
printf("Only one file can be openened.\n");
return 1;
} else if (argcFinal - optind == 1)
} else if (argcFinal - optind == 1){
open_file = argvFinal[argcFinal - 1];
control->_open_file_name = open_file;
}
// Initialise DS_RES_PATH
QDir dir(QCoreApplication::applicationDirPath());
if (dir.cd("..") &&
dir.cd("share") &&
dir.cd(QApplication::applicationName()) &&
dir.cd("res")) {
QString res_dir = dir.absolutePath() + "/";
strcpy(DS_RES_PATH, res_dir.toUtf8().data());
} else {
qDebug() << "ERROR: config files don't exist.";
return 1;
}
//#ifdef Q_OS_DARWIN
//#endif
// Initialise libsigrok
if (sr_init(&sr_ctx) != SR_OK) {
qDebug() << "ERROR: libsigrok init failed.";
//load app config
AppConfig::Instance().LoadAll();
//init core
if (!control->Init()){
printf("init error!");
qDebug() << control->GetLastError();
return 1;
}
do {
#ifdef ENABLE_DECODE
// Initialise libsigrokdecode
if (srd_init(NULL) != SRD_OK) {
qDebug() << "ERROR: libsigrokdecode init failed.";
break;
}
try
{
control->Start();
// Initialise the main frame
pv::MainFrame w;
w.show();
w.readSettings();
//to show the dailog for open help document
w.show_doc();
// Load the protocol decoders
srd_decoder_load_all();
#endif
//Run the application
ret = a.exec();
try {
// Create the device manager, initialise the drivers
pv::DeviceManager device_manager(sr_ctx);
control->Stop();
}
catch (const std::exception &e)
{
printf("main() catch a except!");
const char *exstr = e.what();
qDebug() << exstr;
}
// Initialise the main frame
pv::MainFrame w(device_manager, open_file);
w.show();
w.readSettings();
w.show_doc();
// Run the application
ret = a.exec();
} catch(const std::exception &e) {
qDebug() << e.what();
}
#ifdef ENABLE_DECODE
// Destroy libsigrokdecode
srd_exit();
#endif
} while (0);
// Destroy libsigrok
if (sr_ctx)
sr_exit(sr_ctx);
//uninit
control->UnInit();
control->Destroy();
return ret;
}

View File

@ -7,7 +7,7 @@ class MyStyle : public QProxyStyle
{
Q_OBJECT
public:
int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const {
int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) {
int s = QProxyStyle::pixelMetric(metric, option, widget);
if (metric == QStyle::PM_SmallIconSize) {
s = 24;

273
DSView/pv/ZipMaker.cpp Normal file
View File

@ -0,0 +1,273 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 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 "ZipMaker.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "minizip/zip.h"
#include "minizip/unzip.h"
ZipMaker::ZipMaker() :
m_zDoc(NULL)
{
m_error[0] = 0;
m_opt_compress_level = Z_BEST_SPEED;
m_zi = NULL;
}
ZipMaker::~ZipMaker()
{
Release();
}
bool ZipMaker::CreateNew(const char *fileName, bool bAppend)
{
assert(fileName);
Release();
m_zDoc = zipOpen64(fileName, bAppend);
if (m_zDoc == NULL) {
strcpy(m_error, "zipOpen64 error");
}
//make zip inner file time
m_zi = new zip_fileinfo();
time_t rawtime;
time (&rawtime);
struct tm *tinf= localtime(&rawtime);
struct tm &ti = *tinf;
zip_fileinfo &zi= *(zip_fileinfo*)m_zi;
zi.tmz_date.tm_year = ti.tm_year;
zi.tmz_date.tm_mon = ti.tm_mon;
zi.tmz_date.tm_mday = ti.tm_mday;
zi.tmz_date.tm_hour = ti.tm_hour;
zi.tmz_date.tm_min = ti.tm_min;
zi.tmz_date.tm_sec = ti.tm_sec;
zi.dosDate = 0;
return m_zDoc != NULL;
}
void ZipMaker::Release()
{
if (m_zDoc){
zipClose((zipFile)m_zDoc, NULL);
m_zDoc = NULL;
}
if (m_zi){
delete ((zip_fileinfo*)m_zi);
m_zi = NULL;
}
}
bool ZipMaker::Close(){
if (m_zDoc){
zipClose((zipFile)m_zDoc, NULL);
m_zDoc = NULL;
return true;
}
return false;
}
bool ZipMaker::AddFromBuffer(const char *innerFile, const char *buffer, unsigned int buferSize)
{
assert(buffer);
assert(innerFile);
assert(m_zDoc);
int level = m_opt_compress_level;
if (level < Z_DEFAULT_COMPRESSION || level > Z_BEST_COMPRESSION){
level = Z_DEFAULT_COMPRESSION;
}
zipOpenNewFileInZip((zipFile)m_zDoc,innerFile,(zip_fileinfo*)m_zi,
NULL,0,NULL,0,NULL ,
Z_DEFLATED,
level);
zipWriteInFileInZip((zipFile)m_zDoc, buffer, (unsigned int)buferSize);
zipCloseFileInZip((zipFile)m_zDoc);
return true;
}
bool ZipMaker::AddFromFile(const char *localFile, const char *innerFile)
{
assert(localFile);
struct stat st;
FILE *fp;
char *data = NULL;
long long size = 0;
if ((fp = fopen(localFile, "rb")) == NULL) {
strcpy(m_error, "fopen error");
return false;
}
if (fstat(fileno(fp), &st) < 0) {
strcpy(m_error, "fstat error");
fclose(fp);
return -1;
}
if ((data = (char*)malloc((size_t)st.st_size)) == NULL) {
strcpy(m_error, "can't malloc buffer");
fclose(fp);
return false;
}
if (fread(data, 1, (size_t)st.st_size, fp) < (size_t)st.st_size) {
strcpy(m_error, "fread error");
free(data);
fclose(fp);
return false;
}
fclose(fp);
size = (size_t)st.st_size;
bool ret = AddFromBuffer(innerFile, data, size);
return ret;
}
const char *ZipMaker::GetError()
{
if (m_error[0])
return m_error;
return NULL;
}
//------------------------ZipDecompress
ZipDecompress::ZipDecompress()
{
m_uzDoc = NULL;
m_curIndex = 0;
m_fileCount = 0;
m_bufferSize = 0;
m_buffer = NULL;
}
ZipDecompress::~ZipDecompress()
{
Close();
}
bool ZipDecompress::Open(const char *fileName)
{
assert(fileName);
m_uzDoc = unzOpen64(fileName);
if (m_uzDoc){
m_uzi = new unz_file_info64();
unz_global_info64 inf;
unzGetGlobalInfo64((unzFile)m_uzDoc, &inf);
m_fileCount = (int)inf.number_entry;
}
return m_uzDoc != NULL;
}
void ZipDecompress::Close()
{
if (m_uzDoc)
{
unzClose((unzFile)m_uzDoc);
m_uzDoc = NULL;
}
if (m_uzi){
delete ((unz_file_info64*)m_uzi);
m_uzi = NULL;
}
if (m_buffer){
free(m_buffer);
m_buffer = NULL;
}
}
bool ZipDecompress::ReadNextFileData(UnZipFileInfo &inf)
{
assert(m_uzDoc);
if (m_curIndex >= m_fileCount){
strcpy(m_error, "read index is last");
return false;
}
m_curIndex++;
int ret = unzGetCurrentFileInfo64((unzFile)m_uzDoc, (unz_file_info64*)m_uzi, inf.inFileName, 256, NULL, 0, NULL, 0);
if (ret != UNZ_OK){
strcpy(m_error, "unzGetCurrentFileInfo64 error");
return false;
}
unz_file_info64 &uzinf = *(unz_file_info64*)m_uzi;
inf.dataLen = uzinf.uncompressed_size;
inf.inFileNameLen = uzinf.size_filename;
// need malloc memory buffer
if (m_buffer == NULL || inf.dataLen > m_bufferSize){
if (m_buffer) free(m_buffer);
m_buffer = NULL;
m_buffer = malloc(inf.dataLen + 10);
if (m_buffer == NULL){
strcpy(m_error, "malloc get null");
return false;
}
}
inf.pData = m_buffer;
unzOpenCurrentFile((unzFile)m_uzDoc);
//read file data to buffer
char *buf = (char*)inf.pData;
long long buflen = inf.dataLen;
long long rdlen = 0;
while (rdlen < inf.dataLen)
{
int dlen = unzReadCurrentFile((unzFile)m_uzDoc, buf, buflen);
if (dlen == 0){
break;
}
rdlen += dlen;
buf += dlen; //move pointer
buflen = inf.dataLen - rdlen;
}
unzCloseCurrentFile((unzFile)m_uzDoc);
unzGoToNextFile((unzFile)m_uzDoc);
return true;
}

91
DSView/pv/ZipMaker.h Normal file
View File

@ -0,0 +1,91 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 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
*/
//test git 2
#pragma once
typedef struct
{
char inFileName[256];
int inFileNameLen;
void *pData;
long long dataLen;
} UnZipFileInfo;
class ZipMaker
{
public:
ZipMaker();
~ZipMaker();
//create new zip archive in the memory
bool CreateNew(const char *fileName, bool bAppend);
//free the source
void Release();
//save data to file
bool Close();
//add a inner file from buffer
bool AddFromBuffer(const char *innerFile, const char *buffer, unsigned int buferSize);
//add a inner file from local file
bool AddFromFile(const char *localFile, const char *innerFile);
//get the last error
const char *GetError();
public:
int m_opt_compress_level;
private:
void *m_zDoc; //zip file handle
void *m_zi; //life must as m_zDoc;
char m_error[500];
};
class ZipDecompress
{
public:
ZipDecompress();
~ZipDecompress();
bool Open(const char *fileName);
void Close();
bool ReadNextFileData(UnZipFileInfo &inf);
private:
void *m_uzDoc;
void *m_uzi;
int m_fileCount;
int m_curIndex;
char m_error[500];
void *m_buffer; // file read buffer
long long m_bufferSize;
};

149
DSView/pv/appcontrol.cpp Normal file
View File

@ -0,0 +1,149 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 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 "appcontrol.h"
#include <libsigrok4DSL/libsigrok.h>
#include <libsigrokdecode4DSL/libsigrokdecode.h>
#include <QDir>
#include <QCoreApplication>
#include <QDebug>
#include "devicemanager.h"
#include "sigsession.h"
#include "dsvdef.h"
#include "config/appconfig.h"
AppControl::AppControl()
{
sr_ctx = NULL;
_device_manager = new pv::DeviceManager();
_session = new pv::SigSession(_device_manager);
}
AppControl::AppControl(AppControl &o)
{
(void)o;
}
AppControl::~AppControl()
{
DESTROY_OBJECT(_device_manager);
DESTROY_OBJECT(_session);
}
AppControl* AppControl::Instance()
{
static AppControl *ins = NULL;
if (ins == NULL){
ins = new AppControl();
}
return ins;
}
void AppControl::Destroy(){
delete this;
}
bool AppControl::Init()
{
// Initialise libsigrok
if (sr_init(&sr_ctx) != SR_OK)
{
m_error = "DSView run ERROR: libsigrok init failed.";
return false;
}
QString resdir = GetResourceDir();
sr_set_firmware_resource_dir(resdir.toUtf8().data());
#ifdef _WIN32
//able run debug with qtcreator
QString pythonHome = "c:/python";
QDir pydir;
if (pydir.exists(pythonHome)){
const wchar_t *pyhome = reinterpret_cast<const wchar_t*>(pythonHome.utf16());
srd_set_python_home(pyhome);
}
#endif
char path[256] = {0};
QString dir = GetAppDataDir() + "/decoders";
strcpy(path, dir.toUtf8().data());
// Initialise libsigrokdecode
if (srd_init(path) != SRD_OK)
{
m_error = "ERROR: libsigrokdecode init failed.";
return false;
}
// Load the protocol decoders
if (srd_decoder_load_all() != SRD_OK)
{
m_error = "ERROR: load the protocol decoders failed.";
return false;
}
return true;
}
bool AppControl::Start()
{
_session->Open();
_device_manager->initAll(sr_ctx);
return true;
}
void AppControl::Stop()
{
_session->Close();
_device_manager->UnInitAll();
}
void AppControl::UnInit()
{
// Destroy libsigrokdecode
srd_exit();
if (sr_ctx)
{
sr_exit(sr_ctx);
sr_ctx = NULL;
}
}
const char *AppControl::GetLastError()
{
return m_error.c_str();
}
void AppControl::SetLogLevel(int level)
{
sr_log_loglevel_set(level);
srd_log_loglevel_set(level);
}

73
DSView/pv/appcontrol.h Normal file
View File

@ -0,0 +1,73 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 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
*/
#pragma once
#include <string>
struct sr_context;
namespace pv{
class DeviceManager;
class SigSession;
}
class AppControl
{
private:
explicit AppControl();
~AppControl();
AppControl(AppControl &o);
public:
static AppControl* Instance();
void Destroy();
bool Init();
bool Start();
void Stop();
void UnInit();
const char* GetLastError();
void SetLogLevel(int level);
inline pv::SigSession* GetSession()
{ return _session;}
inline pv::DeviceManager& GetDeviceManager()
{ return *_device_manager;}
public:
std::string _open_file_name;
private:
std::string m_error;
struct sr_context *sr_ctx;
pv::DeviceManager *_device_manager;
pv::SigSession *_session;
};

View File

@ -0,0 +1,354 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 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 "appconfig.h"
#include <QApplication>
#include <QSettings>
#include <QLocale>
#include <QDir>
#include <QDebug>
#include <assert.h>
#include <QStandardPaths>
#define MAX_PROTOCOL_FORMAT_LIST 15
StringPair::StringPair(const std::string &key, const std::string &value)
{
m_key = key;
m_value = value;
}
//------------function
QString FormatArrayToString(std::vector<StringPair> &protocolFormats){
QString str;
for (StringPair &o : protocolFormats){
if (!str.isEmpty()){
str += ";";
}
str += o.m_key.c_str();
str += "=";
str += o.m_value.c_str();
}
return str;
}
void StringToFormatArray(const QString &str, std::vector<StringPair> &protocolFormats){
QStringList arr = str.split(";");
for (int i=0; i<arr.size(); i++){
QString line = arr[i];
if (!line.isEmpty()){
QStringList vs = line.split("=");
if (vs.size() == 2){
protocolFormats.push_back(StringPair(vs[0].toStdString(), vs[1].toStdString()));
}
}
}
}
//read write field
void getFiled(const char *key, QSettings &st, QString &f, const char *dv){
f = st.value(key, dv).toString();
}
void getFiled(const char *key, QSettings &st, int &f, int dv){
f = st.value(key, dv).toInt();
}
void getFiled(const char *key, QSettings &st, bool &f, bool dv){
f = st.value(key, dv).toBool();
}
void setFiled(const char *key, QSettings &st, QString f){
st.setValue(key, f);
}
void setFiled(const char *key, QSettings &st, int f){
st.setValue(key, f);
}
void setFiled(const char *key, QSettings &st, bool f){
st.setValue(key, f);
}
///------ app
void _loadApp(AppOptions &o, QSettings &st){
st.beginGroup("Application");
getFiled("quickScroll", st, o.quickScroll, true);
getFiled("warnofMultiTrig", st, o.warnofMultiTrig, true);
getFiled("originalData", st, o.originalData, false);
QString fmt;
getFiled("protocalFormats", st, fmt, "");
if (fmt != ""){
StringToFormatArray(fmt, o.m_protocolFormats);
}
st.endGroup();
}
void _saveApp(AppOptions &o, QSettings &st){
st.beginGroup("Application");
setFiled("quickScroll", st, o.quickScroll);
setFiled("warnofMultiTrig", st, o.warnofMultiTrig);
setFiled("originalData", st, o.originalData);
QString fmt = FormatArrayToString(o.m_protocolFormats);
setFiled("protocalFormats", st, fmt);
st.endGroup();
}
//-----frame
void _loadDockOptions(DockOptions &o, QSettings &st, const char *group){
st.beginGroup(group);
getFiled("decodeDoc", st, o.decodeDoc, false);
getFiled("triggerDoc", st, o.triggerDoc, false);
getFiled("measureDoc", st, o.measureDoc, false);
getFiled("searchDoc", st, o.searchDoc, false);
st.endGroup();
}
void _saveDockOptions(DockOptions &o, QSettings &st, const char *group){
st.beginGroup(group);
setFiled("decodeDoc", st, o.decodeDoc);
setFiled("triggerDoc", st, o.triggerDoc);
setFiled("measureDoc", st, o.measureDoc);
setFiled("searchDoc", st, o.searchDoc);
st.endGroup();
}
void _loadFrame(FrameOptions &o, QSettings &st){
st.beginGroup("MainFrame");
getFiled("style", st, o.style, "dark");
getFiled("language", st, o.language, -1);
getFiled("isMax", st, o.isMax, false);
getFiled("left", st, o.left, 0);
getFiled("top", st, o.top, 0);
getFiled("right", st, o.right, 0);
getFiled("bottom", st, o.bottom, 0);
_loadDockOptions(o._logicDock, st, "LOGIC_DOCK");
_loadDockOptions(o._analogDock, st, "ANALOG_DOCK");
_loadDockOptions(o._dsoDock, st, "DSO_DOCK");
o.windowState = st.value("windowState", QByteArray()).toByteArray();
st.endGroup();
if (o.language == -1 || (o.language != LAN_CN && o.language != LAN_EN)){
//get local language
QLocale locale;
if (QLocale::languageToString(locale.language()) == "Chinese")
o.language = LAN_CN;
else
o.language = LAN_EN;
}
}
void _saveFrame(FrameOptions &o, QSettings &st){
st.beginGroup("MainFrame");
setFiled("style", st, o.style);
setFiled("language", st, o.language);
setFiled("isMax", st, o.isMax);
setFiled("left", st, o.left);
setFiled("top", st, o.top);
setFiled("right", st, o.right);
setFiled("bottom", st, o.bottom);
st.setValue("windowState", o.windowState);
_saveDockOptions(o._logicDock, st, "LOGIC_DOCK");
_saveDockOptions(o._analogDock, st, "ANALOG_DOCK");
_saveDockOptions(o._dsoDock, st, "DSO_DOCK");
st.endGroup();
}
//------history
void _loadHistory(UserHistory &o, QSettings &st){
st.beginGroup("UserHistory");
getFiled("exportDir", st, o.exportDir, "");
getFiled("saveDir", st, o.saveDir, "");
getFiled("showDocuments", st, o.showDocuments, true);
getFiled("screenShotPath", st, o.screenShotPath, "");
getFiled("sessionDir", st, o.sessionDir, "");
getFiled("openDir", st, o.openDir, "");
getFiled("protocolExportPath", st, o.protocolExportPath, "");
getFiled("exportFormat", st, o.exportFormat, "");
st.endGroup();
}
void _saveHistory(UserHistory &o, QSettings &st){
st.beginGroup("UserHistory");
setFiled("exportDir", st, o.exportDir);
setFiled("saveDir", st, o.saveDir);
setFiled("showDocuments", st, o.showDocuments);
setFiled("screenShotPath", st, o.screenShotPath);
setFiled("sessionDir", st, o.sessionDir);
setFiled("openDir", st, o.openDir);
setFiled("protocolExportPath", st, o.protocolExportPath);
setFiled("exportFormat", st, o.exportFormat);
st.endGroup();
}
//------------AppConfig
AppConfig::AppConfig()
{
}
AppConfig::AppConfig(AppConfig &o)
{
(void)o;
}
AppConfig::~AppConfig()
{
}
AppConfig& AppConfig::Instance()
{
static AppConfig *ins = NULL;
if (ins == NULL){
ins = new AppConfig();
}
return *ins;
}
void AppConfig::LoadAll()
{
QSettings st(QApplication::organizationName(), QApplication::applicationName());
_loadApp(_appOptions, st);
_loadHistory(_userHistory, st);
_loadFrame(_frameOptions, st);
}
void AppConfig::SaveApp()
{
QSettings st(QApplication::organizationName(), QApplication::applicationName());
_saveApp(_appOptions, st);
}
void AppConfig::SaveHistory()
{
QSettings st(QApplication::organizationName(), QApplication::applicationName());
_saveHistory(_userHistory, st);
}
void AppConfig::SaveFrame()
{
QSettings st(QApplication::organizationName(), QApplication::applicationName());
_saveFrame(_frameOptions, st);
}
void AppConfig::SetProtocolFormat(const std::string &protocolName, const std::string &value)
{
bool bChange = false;
for (StringPair &o : _appOptions.m_protocolFormats){
if (o.m_key == protocolName){
o.m_value = value;
bChange = true;
break;
}
}
if (!bChange)
{
if (_appOptions.m_protocolFormats.size() > MAX_PROTOCOL_FORMAT_LIST)
{
while (_appOptions.m_protocolFormats.size() < MAX_PROTOCOL_FORMAT_LIST)
{
_appOptions.m_protocolFormats.erase(_appOptions.m_protocolFormats.begin());
}
}
_appOptions.m_protocolFormats.push_back(StringPair(protocolName, value));
bChange = true;
}
if (bChange){
SaveApp();
}
}
std::string AppConfig::GetProtocolFormat(const std::string &protocolName)
{
for (StringPair &o : _appOptions.m_protocolFormats){
if (o.m_key == protocolName){
return o.m_value;
}
}
return "";
}
//-------------api
QString GetDirectoryName(QString path)
{
int lstdex = path.lastIndexOf('/');
if (lstdex != -1)
{
return path.left(lstdex);
}
return path;
}
QString GetIconPath()
{
QString style = AppConfig::Instance()._frameOptions.style;
if (style == ""){
style = "dark";
}
return ":/icons/" + style;
}
QString GetAppDataDir()
{
//applicationDirPath not end with '/'
#ifdef Q_OS_LINUX
QDir dir(QCoreApplication::applicationDirPath());
if (dir.cd("..") && dir.cd("share") &&dir.cd("DSView"))
{
return dir.absolutePath();
}
qDebug() << "dir is not exists:" << QCoreApplication::applicationDirPath() + "/../share/DSView";
assert(false);
#else
return QCoreApplication::applicationDirPath();
#endif
}
QString GetResourceDir(){
QDir dir = GetAppDataDir() + "/res";
if (dir.exists()){
return dir.absolutePath();
}
qDebug() << "dir is not exists:" << dir.absolutePath();
assert(false);
}
QString GetUserDataDir()
{
#if QT_VERSION >= 0x050400
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
#else
return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#endif
}

View File

@ -0,0 +1,118 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 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
*/
#pragma once
#include <string>
#include <vector>
#include <QString>
#include <QByteArray>
#define LAN_CN 25
#define LAN_EN 31
//--------------------api---
QString GetDirectoryName(QString path);
QString GetIconPath();
QString GetAppDataDir();
QString GetResourceDir();
QString GetUserDataDir();
//------------------class
class StringPair
{
public:
StringPair(const std::string &key, const std::string &value);
std::string m_key;
std::string m_value;
};
struct AppOptions
{
bool quickScroll;
bool warnofMultiTrig;
bool originalData;
std::vector<StringPair> m_protocolFormats;
};
struct DockOptions{
bool decodeDoc;
bool triggerDoc;
bool measureDoc;
bool searchDoc;
};
struct FrameOptions
{
QString style;
int language;
int left; //frame region
int top;
int right;
int bottom;
bool isMax;
QByteArray windowState;
DockOptions _logicDock;
DockOptions _analogDock;
DockOptions _dsoDock;
};
struct UserHistory
{
QString exportDir;
QString saveDir;
bool showDocuments;
QString screenShotPath;
QString sessionDir;
QString openDir;
QString protocolExportPath;
QString exportFormat;
};
class AppConfig
{
private:
AppConfig();
~AppConfig();
AppConfig(AppConfig &o);
public:
static AppConfig &Instance();
void LoadAll();
void SaveApp();
void SaveHistory();
void SaveFrame();
void SetProtocolFormat(const std::string &protocolName, const std::string &value);
std::string GetProtocolFormat(const std::string &protocolName);
public:
AppOptions _appOptions;
UserHistory _userHistory;
FrameOptions _frameOptions;
};

View File

@ -22,26 +22,27 @@
#include "analog.h"
#include "analogsnapshot.h"
#include <assert.h>
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
namespace pv {
namespace data {
Analog::Analog() :
Analog::Analog(AnalogSnapshot *snapshot) :
SignalData()
{
assert(snapshot);
_snapshots.push_front(snapshot);
}
void Analog::push_snapshot(boost::shared_ptr<AnalogSnapshot> &snapshot)
void Analog::push_snapshot(AnalogSnapshot *snapshot)
{
_snapshots.push_front(snapshot);
}
deque< boost::shared_ptr<AnalogSnapshot> >& Analog::get_snapshots()
std::deque<AnalogSnapshot*>& Analog::get_snapshots()
{
return _snapshots;
}
@ -49,15 +50,20 @@ deque< boost::shared_ptr<AnalogSnapshot> >& Analog::get_snapshots()
void Analog::clear()
{
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<AnalogSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->clear();
}
void Analog::init()
{
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<AnalogSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->init();
}
AnalogSnapshot* Analog::snapshot()
{
return _snapshots[0];
}
} // namespace data
} // namespace pv

View File

@ -26,7 +26,7 @@
#include "signaldata.h"
#include <boost/shared_ptr.hpp>
#include <deque>
namespace pv {
@ -37,19 +37,17 @@ class AnalogSnapshot;
class Analog : public SignalData
{
public:
Analog();
void push_snapshot(
boost::shared_ptr<AnalogSnapshot> &snapshot);
std::deque< boost::shared_ptr<AnalogSnapshot> >&
get_snapshots();
Analog(AnalogSnapshot *snapshot);
void push_snapshot(AnalogSnapshot *snapshot);
std::deque<AnalogSnapshot*>& get_snapshots();
void clear();
void init();
AnalogSnapshot* snapshot();
private:
std::deque< boost::shared_ptr<AnalogSnapshot> > _snapshots;
std::deque<AnalogSnapshot*> _snapshots;
};
} // namespace data

View File

@ -20,20 +20,15 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <extdef.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <boost/foreach.hpp>
#include "analogsnapshot.h"
#include "../extdef.h"
using namespace boost;
using namespace std;
namespace pv {
@ -60,7 +55,7 @@ AnalogSnapshot::~AnalogSnapshot()
void AnalogSnapshot::free_envelop()
{
for (unsigned int i = 0; i < _channel_num; i++) {
BOOST_FOREACH(Envelope &e, _envelope_levels[i]) {
for(auto &e : _envelope_levels[i]) {
if (e.samples)
free(e.samples);
}
@ -70,7 +65,12 @@ void AnalogSnapshot::free_envelop()
void AnalogSnapshot::init()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
init_all();
}
void AnalogSnapshot::init_all()
{
_sample_count = 0;
_ring_sample_count = 0;
_memory_failed = false;
@ -88,10 +88,10 @@ void AnalogSnapshot::init()
void AnalogSnapshot::clear()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
free_data();
free_envelop();
init();
init_all();
}
void AnalogSnapshot::first_payload(const sr_datafeed_analog &analog, uint64_t total_sample_count, GSList *channels)
@ -167,7 +167,7 @@ void AnalogSnapshot::first_payload(const sr_datafeed_analog &analog, uint64_t to
void AnalogSnapshot::append_payload(
const sr_datafeed_analog &analog)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
append_data(analog.data, analog.num_samples, analog.unit_pitch);
// Generate the first mip-map from the data
@ -212,7 +212,7 @@ void AnalogSnapshot::append_data(void *data, uint64_t samples, uint16_t pitch)
}
}
const uint8_t* AnalogSnapshot::get_samples(int64_t start_sample) const
const uint8_t* AnalogSnapshot::get_samples(int64_t start_sample)
{
assert(start_sample >= 0);
assert(start_sample < (int64_t)get_sample_count());
@ -225,7 +225,7 @@ const uint8_t* AnalogSnapshot::get_samples(int64_t start_sample) const
}
void AnalogSnapshot::get_envelope_section(EnvelopeSection &s,
uint64_t start, int64_t count, float min_length, int probe_index) const
uint64_t start, int64_t count, float min_length, int probe_index)
{
assert(count >= 0);
assert(min_length > 0);
@ -369,7 +369,7 @@ int AnalogSnapshot::get_ch_order(int sig_index)
return order;
}
int AnalogSnapshot::get_scale_factor() const
int AnalogSnapshot::get_scale_factor()
{
return EnvelopeScaleFactor;
}

View File

@ -79,6 +79,9 @@ private:
static const uint64_t LeafBlockSamples = 1 << LeafBlockPower;
static const uint64_t LeafMask = ~(~0ULL << LeafBlockPower);
private:
void init_all();
public:
AnalogSnapshot();
@ -92,14 +95,14 @@ public:
void append_payload(const sr_datafeed_analog &analog);
const uint8_t *get_samples(int64_t start_sample) const;
const uint8_t *get_samples(int64_t start_sample);
void get_envelope_section(EnvelopeSection &s,
uint64_t start, int64_t count, float min_length, int probe_index) const;
uint64_t start, int64_t count, float min_length, int probe_index);
int get_ch_order(int sig_index);
int get_scale_factor() const;
int get_scale_factor();
bool has_data(int index);
int get_block_num();

View File

@ -0,0 +1,206 @@
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2014 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 "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;
*wr = 0; //end flag
char *rd = (char*)bin + len - 1; //move to last byte
char tmp[3];
while (rd >= bin && wr > buf)
{
wr--;
int num = 0;
while (rd >= bin && num < 3)
{
tmp[2-num] = *rd;
rd--;
num++;
}
//fill
while (num < 3)
{
tmp[2-num] = '0';
++num;
}
if (strncmp(tmp, "000", 3) == 0)
*wr = '0';
else if (strncmp(tmp, "001", 3) == 0)
*wr = '1';
else if (strncmp(tmp, "010", 3) == 0)
*wr = '2';
else if (strncmp(tmp, "011", 3) == 0)
*wr = '3';
else if (strncmp(tmp, "100", 3) == 0)
*wr = '4';
else if (strncmp(tmp, "101", 3) == 0)
*wr = '5';
else if (strncmp(tmp, "110", 3) == 0)
*wr = '6';
else if (strncmp(tmp, "111", 3) == 0)
*wr = '7';
}
return wr;
}
long long bin2long_string(const char *bin, int len)
{
char *rd = (char *)bin + len - 1; //move to last byte
int dex = 0;
long long value = 0;
long long bv = 0;
while (rd >= bin)
{
if (*rd == '1')
{
bv = 1 << dex;
value += bv;
}
rd--;
++dex;
}
return value;
}
int AnnotationResTable::MakeIndex(const std::string &key, AnnotationSourceItem* &newItem)
{
auto fd = m_indexs.find(key);
if (fd != m_indexs.end()){
return (*fd).second;
}
AnnotationSourceItem *item = new AnnotationSourceItem();
m_resourceTable.push_back(item);
item->cur_display_format = -1;
item->is_numeric = false;
newItem = item;
int dex = m_indexs.size();
m_indexs[key] = dex;
return dex;
}
AnnotationSourceItem* AnnotationResTable::GetItem(int index){
assert(index >= 0 && index < m_resourceTable.size());
return m_resourceTable[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){
return data;
}
//convert to bin format
char *buf = g_bin_format_tmp_buffer + sizeof(g_bin_format_tmp_buffer) - 2;
buf[1] = 0; //set the end flag
buf[0] = 0;
int len = strlen(data);
//buffer is not enough
if (len > DECODER_MAX_DATA_BLOCK_LEN){
return data;
}
char *rd = (char*)data + len - 1; //move to last byte
char c = 0;
int dex = 0;
while (rd >= data)
{
c = *rd;
dex = (int)(c <= '9' ? (c - '0') : (c - 'A' + 10));
char *ptable = (char*)g_bin_cvt_table + dex * 4;
buf -= 4; //move to left for 4 bytes
buf[0] = ptable[0];
buf[1] = ptable[1];
buf[2] = ptable[2];
buf[3] = ptable[3];
rd--;
}
//get bin format
if (fmt == DecoderDataFormat::bin){
return buf;
}
//get oct format
if (fmt == DecoderDataFormat::oct){
char *oct_buf = bin2oct_string(g_oct_format_tmp_buffer,
sizeof(g_oct_format_tmp_buffer), buf, len * 4);
return oct_buf;
}
//64 bit integer
if (fmt == DecoderDataFormat::dec && len * 4 <= 64){
long long lv = bin2long_string(buf, len * 4);
g_number_tmp_64[0] = 0;
sprintf(g_number_tmp_64, "%lld", lv);
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;
}

View File

@ -0,0 +1,53 @@
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2014 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
*/
#pragma once
#include <map>
#include <string>
#include <vector>
#include <QString>
struct AnnotationSourceItem
{
bool is_numeric;
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> cvt_lines; //the converted to bin/hex/oct format string lines
int cur_display_format; //current format as bin/ex/oct..., init with -1
};
class AnnotationResTable
{
public:
int MakeIndex(const std::string &key, AnnotationSourceItem* &newItem);
AnnotationSourceItem* GetItem(int index);
inline int GetCount(){
return m_resourceTable.size();}
static const char* format_numberic(const char *hex_str, int fmt);
private:
std::map<std::string, int> m_indexs;
std::vector<AnnotationSourceItem*> m_resourceTable;
};

View File

@ -25,27 +25,91 @@
#include <assert.h>
#include "annotation.h"
#include "AnnotationResTable.h"
#include <cstring>
#include <assert.h>
#include <string.h>
#include "../../config/appconfig.h"
#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;
int len = 0;
while (c)
{
++len;
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')){
c = *str;
str++;
continue;
}
return false;
}
return len % 2 == 0 && len > 0;
}
namespace pv {
namespace data {
namespace decode {
Annotation::Annotation(const srd_proto_data *const pdata) :
_start_sample(pdata->start_sample),
_end_sample(pdata->end_sample)
Annotation::Annotation(const srd_proto_data *const pdata, DecoderStatus *status)
{
assert(pdata);
const srd_proto_data_annotation *const pda =
(const srd_proto_data_annotation*)pdata->data;
assert(pda);
_format = pda->ann_class;
_type = pda->ann_type;
_start_sample = pdata->start_sample;
_end_sample = pdata->end_sample;
_format = pda->ann_class;
_type = pda->ann_type;
_resIndex = 0;
_status = status;
//make resource find key
std::string key;
const char *const *annotations = (char**)pda->ann_text;
while(*annotations) {
_annotations.push_back(QString::fromUtf8(*annotations));
annotations++;
char **annotations = pda->ann_text;
while(annotations && *annotations) {
key.append(*annotations, strlen(*annotations));
annotations++;
}
if (pda->str_number_hex[0]){
//append numeric string
key.append(pda->str_number_hex, strlen(pda->str_number_hex));
}
AnnotationSourceItem *resItem = NULL;
_resIndex = annTable.MakeIndex(key, resItem);
//is a new item
if (resItem != NULL){
char **annotations = pda->ann_text;
while(annotations && *annotations) {
resItem->src_lines.push_back(QString::fromUtf8(*annotations));
annotations++;
}
//get numeric data
if (pda->str_number_hex[0]){
strcpy(resItem->str_number_hex, pda->str_number_hex);
resItem->is_numeric = true;
}
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;
}
}
@ -57,33 +121,60 @@ Annotation::Annotation()
Annotation::~Annotation()
{
_annotations.clear();
}
uint64_t Annotation::start_sample() const
{
return _start_sample;
}
uint64_t Annotation::end_sample() const
{
return _end_sample;
}
int Annotation::format() const
{
return _format;
}
int Annotation::type() const
{
return _type;
}
const std::vector<QString>& Annotation::annotations() const
{
return _annotations;
}
assert(_status);
AnnotationSourceItem &resItem = *annTable.GetItem(_resIndex);
//get origin data, is not a numberic value
if (!resItem.is_numeric){
return resItem.src_lines;
}
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)
{
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));
}
}
}
else{
const char *num_str = AnnotationResTable::format_numberic(resItem.str_number_hex, resItem.cur_display_format);
resItem.cvt_lines.push_back(QString(num_str));
}
}
return resItem.cvt_lines;
}
bool Annotation::is_numberic()
{
AnnotationSourceItem *resItem = annTable.GetItem(_resIndex);
return resItem->is_numeric;
}
} // namespace decode
} // namespace data

View File

@ -25,6 +25,10 @@
#include <stdint.h>
#include <QString>
#include <vector>
class AnnotationResTable;
class DecoderStatus;
struct srd_proto_data;
@ -32,25 +36,44 @@ namespace pv {
namespace data {
namespace decode {
//create at DecoderStack.annotation_callback
class Annotation
{
public:
Annotation(const srd_proto_data *const pdata);
Annotation(const srd_proto_data *const pdata, DecoderStatus *status);
Annotation();
public:
~Annotation();
uint64_t start_sample() const;
uint64_t end_sample() const;
int format() const;
int type() const;
inline uint64_t start_sample() const{
return _start_sample;
}
inline uint64_t end_sample() const{
return _end_sample;
}
inline int format() const{
return _format;
}
inline int type() const{
return _type;
}
bool is_numberic();
public:
const std::vector<QString>& annotations() const;
private:
uint64_t _start_sample;
uint64_t _end_sample;
int _format;
int _type;
std::vector<QString> _annotations;
uint64_t _start_sample;
uint64_t _end_sample;
short _format;
short _type;
short _resIndex;
DecoderStatus *_status; /*a global variable*/
};
} // namespace decode

View File

@ -22,63 +22,38 @@
#include <libsigrokdecode4DSL/libsigrokdecode.h>
#include "decoder.h"
#include <assert.h>
using boost::shared_ptr;
using std::set;
using std::map;
using std::string;
namespace pv {
namespace data {
namespace decode {
Decoder::Decoder(const srd_decoder *const dec) :
_decoder(dec),
_shown(true),
_setted(true)
Decoder::Decoder(const srd_decoder *const dec):
_decoder(dec)
{
_shown = true;
_setted = true;
_decode_start = 0;
_decode_end = 0;
_decode_start_back = 0;
_decode_end_back = 0;
}
Decoder::~Decoder()
{
for (map<string, GVariant*>::const_iterator i = _options_back.begin();
for (auto i = _options_back.begin();
i != _options_back.end(); i++)
if ((*i).second)
g_variant_unref((*i).second);
}
const srd_decoder* Decoder::decoder() const
{
return _decoder;
}
bool Decoder::shown() const
{
return _shown;
}
void Decoder::show(bool show)
{
_shown = show;
}
const map<const srd_channel*, int>&
Decoder::channels() const
{
return _probes;
}
void Decoder::set_probes(std::map<const srd_channel *, int> probes)
void Decoder::set_probes(std::map<const srd_channel*, int> probes)
{
_probes_back = probes;
_setted = true;
}
const std::map<std::string, GVariant*>& Decoder::options() const
{
return _options;
}
void Decoder::set_option(const char *id, GVariant *value)
{
assert(value);
@ -94,21 +69,13 @@ void Decoder::set_decode_region(uint64_t start, uint64_t end)
{
_decode_start_back = start;
_decode_end_back = end;
if (_decode_start != start ||
_decode_end != end)
_setted = true;
if (_decode_start != start || _decode_end != end){
_setted = true;
}
}
uint64_t Decoder::decode_start() const
{
return _decode_start;
}
uint64_t Decoder::decode_end() const
{
return _decode_end;
}
//apply setting
bool Decoder::commit()
{
if (_setted) {
@ -123,7 +90,7 @@ bool Decoder::commit()
}
}
bool Decoder::have_required_probes() const
bool Decoder::have_required_probes()
{
for (GSList *l = _decoder->channels; l; l = l->next) {
const srd_channel *const pdch = (const srd_channel*)l->data;
@ -135,12 +102,12 @@ bool Decoder::have_required_probes() const
return true;
}
srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const
srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session)
{
GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash,
g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
for (map<string, GVariant*>::const_iterator i = _options.begin();
for (auto i = _options.begin();
i != _options.end(); i++)
{
GVariant *const value = (*i).second;
@ -160,9 +127,7 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const
GHashTable *const probes = g_hash_table_new_full(g_str_hash,
g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
for(map<const srd_channel*, int>::
const_iterator i = _probes.begin();
i != _probes.end(); i++)
for(auto i = _probes.begin(); i != _probes.end(); i++)
{
GVariant *const gvar = g_variant_new_int32((*i).second);
g_variant_ref_sink(gvar);
@ -173,11 +138,7 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const
return decoder_inst;
}
int Decoder::get_channel_type(const srd_channel *ch)
{
return ch->type;
}
} // decode
} // data

View File

@ -27,9 +27,7 @@
#include <string>
#include <sstream>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <glib.h>
struct srd_decoder;
@ -46,47 +44,69 @@ class Decoder
public:
Decoder(const srd_decoder *const decoder);
public:
virtual ~Decoder();
const srd_decoder* decoder() const;
inline const srd_decoder* decoder(){
return _decoder;
}
bool shown() const;
void show(bool show = true);
inline bool shown(){
return _shown;
}
inline void show(bool show = true){
_shown = show;
}
inline std::map<const srd_channel*, int>& channels(){
return _probes;
}
const std::map<const srd_channel*, int>& channels() const;
void set_probes(std::map<const srd_channel*, int> probes);
const std::map<std::string, GVariant*>& options() const;
inline std::map<std::string, GVariant*>& options(){
return _options;
}
void set_option(const char *id, GVariant *value);
bool have_required_probes() const;
bool have_required_probes();
srd_decoder_inst* create_decoder_inst(srd_session *session) const;
srd_decoder_inst* create_decoder_inst(srd_session *session);
void set_decode_region(uint64_t start, uint64_t end);
uint64_t decode_start() const;
uint64_t decode_end() const;
inline uint64_t decode_start(){
return _decode_start;
}
inline uint64_t decode_end(){
return _decode_end;
}
bool commit();
int get_channel_type(const srd_channel* ch);
inline int get_channel_type(const srd_channel* ch){
return ch->type;
}
private:
const srd_decoder *const _decoder;
std::map<const srd_channel*, int> _probes;
std::map<std::string, GVariant*> _options;
std::map<const srd_channel*, int> _probes_back;
std::map<std::string, GVariant*> _options_back;
bool _shown;
uint64_t _decode_start;
uint64_t _decode_end;
uint64_t _decode_start_back;
uint64_t _decode_end_back;
std::map<const srd_channel*, int> _probes;
std::map<std::string, GVariant*> _options;
std::map<const srd_channel*, int> _probes_back;
std::map<std::string, GVariant*> _options_back;
uint64_t _decode_start, _decode_end;
uint64_t _decode_start_back, _decode_end_back;
bool _setted;
bool _setted;
bool _shown;
};
} // namespace decode

View File

@ -0,0 +1,38 @@
/*
* This file is part of the PulseView project.
*
* Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2014 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
*/
#pragma once
class DecoderStatus
{
public:
DecoderStatus()
{
m_bNumeric = false;
m_format = 0;
sdr_decoder_handle = NULL;
}
public:
bool m_bNumeric; //when decoder get any numerical data,it will be set
int m_format; //protocol format code
void *sdr_decoder_handle;
};

View File

@ -38,24 +38,16 @@ Row::Row(const srd_decoder *decoder, const srd_decoder_annotation_row *row, cons
_row(row),
_order(order)
{
}
}
Row::~Row()
Row::Row(const Row &o)
{
_decoder = o._decoder;
_row = o._row;
_order = o._order;
}
const srd_decoder* Row::decoder() const
{
return _decoder;
}
const srd_decoder_annotation_row* Row::row() const
{
return _row;
}
const QString Row::title() const
QString Row::title() const
{
if (_decoder && _decoder->name && _row && _row->desc)
return QString("%1: %2")

View File

@ -32,27 +32,36 @@ namespace pv {
namespace data {
namespace decode {
//map find key data
class Row
{
public:
Row();
~Row();
Row(const srd_decoder *decoder,
const srd_decoder_annotation_row *row = NULL,
const int order = -1);
const srd_decoder* decoder() const;
const srd_decoder_annotation_row* row() const;
Row(const Row &o);
const QString title() const;
public:
bool operator<(const Row &other) const;
inline const srd_decoder* decoder() const{
return _decoder;
}
inline const srd_decoder_annotation_row* row() const{
return _row;
}
QString title() const;
bool operator<(const Row &other)const;
private:
const srd_decoder *_decoder;
const srd_decoder_annotation_row *_row;
int _order;
int _order;
};
} // decode

View File

@ -31,35 +31,47 @@ namespace pv {
namespace data {
namespace decode {
std::mutex RowData::_global_visitor_mutex;
RowData::RowData() :
_max_annotation(0),
_min_annotation(UINT64_MAX)
{
_item_count = 0;
}
RowData::~RowData()
{
clear();
//stack object can not destory the sources
}
void RowData::clear()
{
std::lock_guard<std::mutex> lock(_global_visitor_mutex);
//destroy objercts
for (Annotation *p : _annotations){
delete p;
}
_annotations.clear();
_item_count = 0;
}
uint64_t RowData::get_max_sample() const
uint64_t RowData::get_max_sample()
{
std::lock_guard<std::mutex> lock(_global_visitor_mutex);
if (_annotations.empty())
return 0;
return _annotations.back().end_sample();
return _annotations.back()->end_sample();
}
uint64_t RowData::get_max_annotation() const
uint64_t RowData::get_max_annotation()
{
return _max_annotation;
}
uint64_t RowData::get_min_annotation() const
uint64_t RowData::get_min_annotation()
{
if (_min_annotation == UINT64_MAX)
return 10;
@ -67,52 +79,62 @@ uint64_t RowData::get_min_annotation() const
return _min_annotation;
}
void RowData::get_annotation_subset(
vector<pv::data::decode::Annotation> &dest,
uint64_t start_sample, uint64_t end_sample) const
{
for (vector<Annotation>::const_iterator i = _annotations.begin();
i != _annotations.end(); i++)
if ((*i).end_sample() > start_sample &&
(*i).start_sample() <= end_sample)
dest.push_back(*i);
void RowData::get_annotation_subset(std::vector<pv::data::decode::Annotation> &dest,
uint64_t start_sample, uint64_t end_sample)
{
std::lock_guard<std::mutex> lock(_global_visitor_mutex);
for (Annotation *p : _annotations){
if (p->end_sample() > start_sample &&
p->start_sample() <= end_sample){
Annotation a = *p;
dest.push_back(a);
}
}
}
uint64_t RowData::get_annotation_index(uint64_t start_sample) const
uint64_t RowData::get_annotation_index(uint64_t start_sample)
{
std::lock_guard<std::mutex> lock(_global_visitor_mutex);
uint64_t index = 0;
for (vector<Annotation>::const_iterator i = _annotations.begin();
i != _annotations.end(); i++) {
if ((*i).start_sample() > start_sample)
break;
index++;
}
for (Annotation *p : _annotations){
if (p->start_sample() > start_sample)
break;
index++;
}
return index;
}
bool RowData::push_annotation(const Annotation &a)
{
bool RowData::push_annotation(Annotation *a)
{
assert(a);
std::lock_guard<std::mutex> lock(_global_visitor_mutex);
try {
_annotations.push_back(a);
_max_annotation = max(_max_annotation, a.end_sample() - a.start_sample());
if (a.end_sample() != a.start_sample())
_min_annotation = min(_min_annotation, a.end_sample() - a.start_sample());
_item_count = _annotations.size();
_max_annotation = max(_max_annotation, a->end_sample() - a->start_sample());
if (a->end_sample() != a->start_sample())
_min_annotation = min(_min_annotation, a->end_sample() - a->start_sample());
return true;
} catch (const std::bad_alloc&) {
return false;
}
}
uint64_t RowData::get_annotation_size() const
bool RowData::get_annotation(Annotation &ann, uint64_t index)
{
return _annotations.size();
}
std::lock_guard<std::mutex> lock(_global_visitor_mutex);
bool RowData::get_annotation(Annotation &ann,
uint64_t index) const
{
if (index < _annotations.size()) {
ann = _annotations[index];
ann = *_annotations[index];
return true;
} else {
return false;

View File

@ -22,7 +22,8 @@
#ifndef DSVIEW_PV_DATA_DECODE_ROWDATA_H
#define DSVIEW_PV_DATA_DECODE_ROWDATA_H
#include <vector>
#include <vector>
#include <mutex>
#include "annotation.h"
@ -35,33 +36,37 @@ class RowData
public:
RowData();
~RowData();
public:
uint64_t get_max_sample() const;
uint64_t get_max_annotation() const;
uint64_t get_min_annotation() const;
/**
public:
uint64_t get_max_sample();
uint64_t get_max_annotation();
uint64_t get_min_annotation();
uint64_t get_annotation_index(uint64_t start_sample);
bool push_annotation(Annotation *a);
inline uint64_t get_annotation_size(){
return _item_count;
}
bool get_annotation(pv::data::decode::Annotation &ann, uint64_t index);
/**
* Extracts sorted annotations between two period into a vector.
*/
void get_annotation_subset(
std::vector<pv::data::decode::Annotation> &dest,
uint64_t start_sample, uint64_t end_sample) const;
uint64_t get_annotation_index(uint64_t start_sample) const;
bool push_annotation(const Annotation &a);
uint64_t get_annotation_size() const;
bool get_annotation(pv::data::decode::Annotation &ann,
uint64_t index) const;
void get_annotation_subset(std::vector<pv::data::decode::Annotation> &dest,
uint64_t start_sample, uint64_t end_sample);
void clear();
private:
uint64_t _max_annotation;
uint64_t _min_annotation;
std::vector<Annotation> _annotations;
uint64_t _max_annotation;
uint64_t _min_annotation;
uint64_t _item_count;
std::vector<Annotation*> _annotations;
static std::mutex _global_visitor_mutex;
};
}

View File

@ -19,13 +19,9 @@
*/
#include <libsigrokdecode4DSL/libsigrokdecode.h>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <pv/data/decode/annotation.h>
#include <pv/data/decode/rowdata.h>
#include "decode/annotation.h"
#include "decode/rowdata.h"
#include "decoderstack.h"
#include "decodermodel.h"
@ -41,18 +37,13 @@ DecoderModel::DecoderModel(QObject *parent)
{
}
void DecoderModel::setDecoderStack(boost::shared_ptr<pv::data::DecoderStack> decoder_stack)
void DecoderModel::setDecoderStack(DecoderStack *decoder_stack)
{
beginResetModel();
_decoder_stack = decoder_stack;
endResetModel();
}
const boost::shared_ptr<pv::data::DecoderStack>& DecoderModel::getDecoderStack() const
{
return _decoder_stack;
}
int DecoderModel::rowCount(const QModelIndex & /* parent */) const
{
if (_decoder_stack)

View File

@ -22,10 +22,8 @@
#define DSVIEW_PV_DATA_DECODERMODEL_H
#include <QAbstractTableModel>
#include <boost/shared_ptr.hpp>
#include <pv/data/decode/rowdata.h>
#include "decode/rowdata.h"
namespace pv {
namespace data {
@ -46,14 +44,16 @@ public:
int rowCount(const QModelIndex & /*parent*/) const;
int columnCount(const QModelIndex & /*parent*/) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role) const;
QVariant headerData(int section, Qt::Orientation orientation,int role) const;
void setDecoderStack(boost::shared_ptr<pv::data::DecoderStack> decoder_stack);
const boost::shared_ptr<pv::data::DecoderStack>& getDecoderStack() const;
void setDecoderStack(DecoderStack *decoder_stack);
inline DecoderStack* getDecoderStack(){
return _decoder_stack;
}
private:
boost::shared_ptr<pv::data::DecoderStack> _decoder_stack;
DecoderStack *_decoder_stack;
};
} // namespace data

View File

@ -18,9 +18,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <stdexcept>
#include <algorithm>
@ -29,74 +27,72 @@
#include "decoderstack.h"
#include <pv/data/logic.h>
#include <pv/data/logicsnapshot.h>
#include <pv/data/decode/decoder.h>
#include <pv/data/decode/annotation.h>
#include <pv/sigsession.h>
#include <pv/view/logicsignal.h>
using namespace boost;
using namespace std;
#include "logic.h"
#include "logicsnapshot.h"
#include "decode/decoder.h"
#include "decode/annotation.h"
#include "decode/rowdata.h"
#include "../sigsession.h"
#include "../view/logicsignal.h"
#include "../dsvdef.h"
#include <assert.h>
using namespace pv::data::decode;
using namespace std;
using namespace boost;
namespace pv {
namespace data {
const double DecoderStack::DecodeMargin = 1.0;
const double DecoderStack::DecodeThreshold = 0.2;
const int64_t DecoderStack::DecodeChunkLength = 4 * 1024;
//const int64_t DecoderStack::DecodeChunkLength = 1024 * 1024;
const int64_t DecoderStack::DecodeChunkLength = 4 * 1024;
const unsigned int DecoderStack::DecodeNotifyPeriod = 1024;
boost::mutex DecoderStack::_global_decode_mutex;
DecoderStack::DecoderStack(pv::SigSession &session,
const srd_decoder *const dec) :
_session(session),
_sample_count(0),
_frame_complete(false),
_samples_decoded(0),
_decode_state(Stopped),
_options_changed(false),
_no_memory(false),
_mark_index(-1)
DecoderStack::DecoderStack(pv::SigSession *session,
const srd_decoder *const dec, DecoderStatus *decoder_status) :
_session(session)
{
connect(&_session, SIGNAL(frame_began()),
this, SLOT(on_new_frame()));
connect(&_session, SIGNAL(data_received()),
this, SLOT(on_data_received()));
connect(&_session, SIGNAL(frame_ended()),
this, SLOT(on_frame_ended()));
_stack.push_back(boost::shared_ptr<decode::Decoder>(
new decode::Decoder(dec)));
assert(session);
assert(dec);
assert(decoder_status);
_samples_decoded = 0;
_sample_count = 0;
_decode_state = Stopped;
_options_changed = false;
_no_memory = false;
_mark_index = -1;
_decoder_status = decoder_status;
_stask_stauts = NULL;
_stack.push_back(new decode::Decoder(dec));
build_row();
}
DecoderStack::~DecoderStack()
{
// if (_decode_thread.joinable()) {
// _decode_thread.interrupt();
// _decode_thread.join();
// }
stop_decode();
_stack.clear();
{
//release source
for (auto &kv : _rows)
{
kv.second->clear();
delete kv.second;
}
_rows.clear();
//Decoder
for (auto *p : _stack){
delete p;
}
_stack.clear();
_rows_gshow.clear();
_rows_lshow.clear();
_class_rows.clear();
}
const std::list< boost::shared_ptr<decode::Decoder> >&
DecoderStack::stack() const
{
return _stack;
}
void DecoderStack::push(boost::shared_ptr<decode::Decoder> decoder)
void DecoderStack::push(decode::Decoder *decoder)
{
assert(decoder);
_stack.push_back(decoder);
@ -104,17 +100,20 @@ void DecoderStack::push(boost::shared_ptr<decode::Decoder> decoder)
_options_changed = true;
}
void DecoderStack::remove(boost::shared_ptr<Decoder> &decoder)
void DecoderStack::remove(Decoder *decoder)
{
// Find the decoder in the stack
list< boost::shared_ptr<Decoder> >::iterator iter = _stack.begin();
auto iter = _stack.begin();
for(unsigned int i = 0; i < _stack.size(); i++, iter++)
if ((*iter) == decoder)
break;
// Delete the element
if (iter != _stack.end())
{
_stack.erase(iter);
delete decoder;
}
build_row();
_options_changed = true;
@ -122,9 +121,15 @@ void DecoderStack::remove(boost::shared_ptr<Decoder> &decoder)
void DecoderStack::build_row()
{
//release source
for (auto &kv : _rows)
{
delete kv.second;
}
_rows.clear();
// Add classes
BOOST_FOREACH (const boost::shared_ptr<decode::Decoder> &dec, _stack)
for (auto &dec : _stack)
{
assert(dec);
const srd_decoder *const decc = dec->decoder();
@ -133,7 +138,7 @@ void DecoderStack::build_row()
// Add a row for the decoder if it doesn't have a row list
if (!decc->annotation_rows) {
const Row row(decc);
_rows[row] = decode::RowData();
_rows[row] = new decode::RowData();
std::map<const decode::Row, bool>::const_iterator iter = _rows_gshow.find(row);
if (iter == _rows_gshow.end()) {
_rows_gshow[row] = true;
@ -157,7 +162,7 @@ void DecoderStack::build_row()
const Row row(decc, ann_row, order);
// Add a new empty row data object
_rows[row] = decode::RowData();
_rows[row] = new decode::RowData();
std::map<const decode::Row, bool>::const_iterator iter = _rows_gshow.find(row);
if (iter == _rows_gshow.end()) {
_rows_gshow[row] = true;
@ -180,61 +185,49 @@ void DecoderStack::build_row()
}
}
int64_t DecoderStack::samples_decoded() const
int64_t DecoderStack::samples_decoded()
{
boost::lock_guard<boost::recursive_mutex> decode_lock(_output_mutex);
std::lock_guard<std::mutex> decode_lock(_output_mutex);
return _samples_decoded;
}
void DecoderStack::get_annotation_subset(
std::vector<pv::data::decode::Annotation> &dest,
const Row &row, uint64_t start_sample,
uint64_t end_sample) const
{
//lock_guard<mutex> lock(_output_mutex);
std::map<const Row, decode::RowData>::const_iterator iter =
_rows.find(row);
uint64_t end_sample)
{
auto iter = _rows.find(row);
if (iter != _rows.end())
(*iter).second.get_annotation_subset(dest,
(*iter).second->get_annotation_subset(dest,
start_sample, end_sample);
}
uint64_t DecoderStack::get_annotation_index(
const Row &row, uint64_t start_sample) const
{
//lock_guard<mutex> lock(_output_mutex);
const Row &row, uint64_t start_sample)
{
uint64_t index = 0;
std::map<const Row, decode::RowData>::const_iterator iter =
_rows.find(row);
auto iter = _rows.find(row);
if (iter != _rows.end())
index = (*iter).second.get_annotation_index(start_sample);
index = (*iter).second->get_annotation_index(start_sample);
return index;
}
uint64_t DecoderStack::get_max_annotation(const Row &row)
{
//lock_guard<mutex> lock(_output_mutex);
std::map<const Row, decode::RowData>::const_iterator iter =
_rows.find(row);
{
auto iter = _rows.find(row);
if (iter != _rows.end())
return (*iter).second.get_max_annotation();
return (*iter).second->get_max_annotation();
return 0;
}
uint64_t DecoderStack::get_min_annotation(const Row &row)
{
//lock_guard<mutex> lock(_output_mutex);
std::map<const Row, decode::RowData>::const_iterator iter =
_rows.find(row);
{
auto iter = _rows.find(row);
if (iter != _rows.end())
return (*iter).second.get_min_annotation();
return (*iter).second->get_min_annotation();
return 0;
}
@ -275,14 +268,12 @@ void DecoderStack::set_rows_lshow(const decode::Row row, bool show)
}
}
bool DecoderStack::has_annotations(const Row &row) const
{
//lock_guard<mutex> lock(_output_mutex);
std::map<const Row, decode::RowData>::const_iterator iter =
bool DecoderStack::has_annotations(const Row &row)
{
auto iter =
_rows.find(row);
if (iter != _rows.end())
if(0 == (*iter).second.get_max_sample())
if(0 == (*iter).second->get_max_sample())
return false;
else
return true;
@ -290,46 +281,43 @@ bool DecoderStack::has_annotations(const Row &row) const
return false;
}
uint64_t DecoderStack::list_annotation_size() const
uint64_t DecoderStack::list_annotation_size()
{
boost::lock_guard<boost::recursive_mutex> lock(_output_mutex);
std::lock_guard<std::mutex> lock(_output_mutex);
uint64_t max_annotation_size = 0;
for (map<const Row, RowData>::const_iterator i = _rows.begin();
for (auto i = _rows.begin();
i != _rows.end(); i++) {
map<const Row, bool>::const_iterator iter = _rows_lshow.find((*i).first);
auto iter = _rows_lshow.find((*i).first);
if (iter != _rows_lshow.end() && (*iter).second)
max_annotation_size = max(max_annotation_size,
(*i).second.get_annotation_size());
(*i).second->get_annotation_size());
}
return max_annotation_size;
}
uint64_t DecoderStack::list_annotation_size(uint16_t row_index) const
{
//lock_guard<boost::recursive_mutex> lock(_output_mutex);
//int row = 0;
for (map<const Row, RowData>::const_iterator i = _rows.begin();
uint64_t DecoderStack::list_annotation_size(uint16_t row_index)
{
for (auto i = _rows.begin();
i != _rows.end(); i++) {
map<const Row, bool>::const_iterator iter = _rows_lshow.find((*i).first);
auto iter = _rows_lshow.find((*i).first);
if (iter != _rows_lshow.end() && (*iter).second)
if (row_index-- == 0) {
return (*i).second.get_annotation_size();
return (*i).second->get_annotation_size();
}
}
return 0;
}
bool DecoderStack::list_annotation(pv::data::decode::Annotation &ann,
uint16_t row_index, uint64_t col_index) const
{
//lock_guard<mutex> lock(_output_mutex);
for (map<const Row, RowData>::const_iterator i = _rows.begin();
uint16_t row_index, uint64_t col_index)
{
for (auto i = _rows.begin();
i != _rows.end(); i++) {
map<const Row, bool>::const_iterator iter = _rows_lshow.find((*i).first);
auto iter = _rows_lshow.find((*i).first);
if (iter != _rows_lshow.end() && (*iter).second) {
if (row_index-- == 0) {
return (*i).second.get_annotation(ann, col_index);
return (*i).second->get_annotation(ann, col_index);
}
}
}
@ -338,12 +326,11 @@ bool DecoderStack::list_annotation(pv::data::decode::Annotation &ann,
}
bool DecoderStack::list_row_title(int row, QString &title) const
{
//lock_guard<mutex> lock(_output_mutex);
for (map<const Row, RowData>::const_iterator i = _rows.begin();
bool DecoderStack::list_row_title(int row, QString &title)
{
for (auto i = _rows.begin();
i != _rows.end(); i++) {
map<const Row, bool>::const_iterator iter = _rows_lshow.find((*i).first);
auto iter = _rows_lshow.find((*i).first);
if (iter != _rows_lshow.end() && (*iter).second) {
if (row-- == 0) {
title = (*i).first.title();
@ -355,8 +342,7 @@ bool DecoderStack::list_row_title(int row, QString &title) const
}
QString DecoderStack::error_message()
{
//lock_guard<mutex> lock(_output_mutex);
{
return _error_message;
}
@ -367,45 +353,59 @@ void DecoderStack::clear()
void DecoderStack::init()
{
_sample_count = 0;
_frame_complete = false;
_sample_count = 0;
_samples_decoded = 0;
_error_message = QString();
_no_memory = false;
for (map<const Row, RowData>::iterator i = _rows.begin();
i != _rows.end(); i++) {
//_rows[(*i).first] = decode::RowData();
(*i).second.clear();
for (auto i = _rows.begin();
i != _rows.end(); i++) {
(*i).second->clear();
}
set_mark_index(-1);
}
void DecoderStack::stop_decode()
{
//_snapshot.reset();
if(_decode_state != Stopped) {
if (_decode_thread.get()) {
_decode_thread->interrupt();
_decode_thread->join();
_decode_state = Stopped;
}
_decode_thread.reset();
}
void DecoderStack::stop_decode_work()
{
//set the flag to exit from task thread
if (_stask_stauts){
_stask_stauts->m_bStop = true;
}
_decode_state = Stopped;
}
void DecoderStack::begin_decode()
void DecoderStack::begin_decode_work()
{
boost::shared_ptr<pv::view::LogicSignal> logic_signal;
boost::shared_ptr<pv::data::Logic> data;
assert(_decode_state == Stopped);
_decode_state = Running;
do_decode_work();
_decode_state = Stopped;
}
void DecoderStack::do_decode_work()
{
//set the flag to exit from task thread
if (_stask_stauts){
_stask_stauts->m_bStop = true;
}
_stask_stauts = new decode_task_status();
_stask_stauts->m_bStop = false;
pv::view::LogicSignal *logic_signal = NULL;
pv::data::Logic *data = NULL;
if (!_options_changed)
{
return;
}
_options_changed = false;
stop_decode();
init();
// Check that all decoders have the required channels
BOOST_FOREACH(const boost::shared_ptr<decode::Decoder> &dec, _stack)
for(auto &dec : _stack)
if (!dec->have_required_probes()) {
_error_message = tr("One or more required channels "
"have not been specified");
@ -415,11 +415,11 @@ void DecoderStack::begin_decode()
// We get the logic data of the first channel in the list.
// This works because we are currently assuming all
// LogicSignals have the same data/snapshot
BOOST_FOREACH (const boost::shared_ptr<decode::Decoder> &dec, _stack) {
for (auto &dec : _stack) {
if (dec && !dec->channels().empty()) {
BOOST_FOREACH(boost::shared_ptr<view::Signal> sig, _session.get_signals()) {
for(auto &sig : _session->get_signals()) {
if((sig->get_index() == (*dec->channels().begin()).second) &&
(logic_signal = dynamic_pointer_cast<view::LogicSignal>(sig)) &&
(logic_signal = dynamic_cast<view::LogicSignal*>(sig)) &&
(data = logic_signal->logic_data()))
break;
}
@ -432,10 +432,10 @@ void DecoderStack::begin_decode()
return;
// Check we have a snapshot of data
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
data->get_snapshots();
const auto &snapshots = data->get_snapshots();
if (snapshots.empty())
return;
_snapshot = snapshots.front();
if (_snapshot->empty())
return;
@ -444,27 +444,27 @@ void DecoderStack::begin_decode()
_samplerate = data->samplerate();
if (_samplerate == 0.0)
return;
//_decode_thread = boost::thread(&DecoderStack::decode_proc, this);
_decode_thread.reset(new boost::thread(&DecoderStack::decode_proc, this));
decode_proc();
}
uint64_t DecoderStack::get_max_sample_count() const
uint64_t DecoderStack::get_max_sample_count()
{
uint64_t max_sample_count = 0;
for (map<const Row, RowData>::const_iterator i = _rows.begin();
i != _rows.end(); i++)
max_sample_count = max(max_sample_count,
(*i).second.get_max_sample());
for (auto i = _rows.begin(); i != _rows.end(); i++){
max_sample_count = max(max_sample_count, (*i).second->get_max_sample());
}
return max_sample_count;
}
void DecoderStack::decode_data(
const uint64_t decode_start, const uint64_t decode_end,
srd_session *const session)
void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decode_end, srd_session *const session)
{
decode_task_status *status = _stask_stauts;
// qDebug()<<"decode start:"<<decode_start<<", decode end:"<<decode_end;
//uint8_t *chunk = NULL;
uint64_t last_cnt = 0;
uint64_t notify_cnt = (decode_end - decode_start + 1)/100;
@ -482,14 +482,22 @@ void DecoderStack::decode_data(
uint64_t entry_cnt = 0;
uint64_t i = decode_start;
char *error = NULL;
while(!boost::this_thread::interruption_requested() &&
i < decode_end && !_no_memory)
{
//lock_guard<mutex> decode_lock(_global_decode_mutex);
char *error = NULL;
if( i >= decode_end){
qDebug()<<"decode data index have been end:"<<i;
}
while(i < decode_end && !_no_memory)
{
if (status->m_bStop){
break;
}
std::vector<const uint8_t *> chunk;
std::vector<uint8_t> chunk_const;
uint64_t chunk_end = decode_end;
for (int j =0 ; j < logic_di->dec_num_channels; j++) {
int sig_index = logic_di->dec_channelmap[j];
if (sig_index == -1) {
@ -510,15 +518,23 @@ void DecoderStack::decode_data(
if (chunk_end - i > MaxChunkSize)
chunk_end = i + MaxChunkSize;
if (srd_session_send(session, i, chunk_end,
chunk.data(), chunk_const.data(), chunk_end - i, &error) != SRD_OK) {
if (srd_session_send(
session,
i,
chunk_end,
chunk.data(),
chunk_const.data(),
chunk_end - i,
&error) != SRD_OK){
_error_message = QString::fromLocal8Bit(error);
break;
}
i = chunk_end;
//use mutex
{
boost::lock_guard<boost::recursive_mutex> lock(_output_mutex);
std::lock_guard<std::mutex> lock(_output_mutex);
_samples_decoded = i - decode_start + 1;
}
@ -527,17 +543,19 @@ void DecoderStack::decode_data(
new_decode_data();
}
entry_cnt++;
}
}
qDebug()<<"send to decoder times:"<<entry_cnt;
if (error)
g_free(error);
decode_done();
if (!_session->is_closed())
decode_done();
}
void DecoderStack::decode_proc()
{
boost::lock_guard<boost::mutex> decode_lock(_global_decode_mutex);
optional<uint64_t> sample_count;
{
srd_session *session;
srd_decoder_inst *prev_di = NULL;
uint64_t decode_start = 0;
@ -547,18 +565,15 @@ void DecoderStack::decode_proc()
// Create the session
srd_session_new(&session);
assert(session);
_decode_state = Running;
// Get the intial sample count
{
//unique_lock<mutex> input_lock(_input_mutex);
sample_count = _sample_count = _snapshot->get_sample_count();
}
_sample_count = _snapshot->get_sample_count();
// Create the decoders
BOOST_FOREACH(const boost::shared_ptr<decode::Decoder> &dec, _stack)
for(auto &dec : _stack)
{
srd_decoder_inst *const di = dec->create_decoder_inst(session);
@ -586,6 +601,7 @@ void DecoderStack::decode_proc()
char *error = NULL;
if (srd_session_start(session, &error) == SRD_OK)
//need a lot time
decode_data(decode_start, decode_end, session);
else
_error_message = QString::fromLocal8Bit(error);
@ -594,12 +610,10 @@ void DecoderStack::decode_proc()
if (error) {
g_free(error);
}
srd_session_destroy(session);
_decode_state = Stopped;
srd_session_destroy(session);
}
uint64_t DecoderStack::sample_count() const
uint64_t DecoderStack::sample_count()
{
if (_snapshot)
return _snapshot->get_sample_count();
@ -607,11 +621,12 @@ uint64_t DecoderStack::sample_count() const
return 0;
}
uint64_t DecoderStack::sample_rate() const
uint64_t DecoderStack::sample_rate()
{
return _samplerate;
}
//the decode callback, annotation object will be create
void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
{
assert(pdata);
@ -619,14 +634,16 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
DecoderStack *const d = (DecoderStack*)decoder;
assert(d);
//lock_guard<mutex> lock(d->_output_mutex);
if (d->_no_memory) {
return;
}
const Annotation a(pdata);
Annotation *a = new Annotation(pdata, d->_decoder_status);
if (a == NULL){
d->_no_memory = true;
return;
}
// Find the row
assert(pdata->pdo);
@ -634,11 +651,11 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
const srd_decoder *const decc = pdata->pdo->di->decoder;
assert(decc);
map<const Row, decode::RowData>::iterator row_iter = d->_rows.end();
auto row_iter = d->_rows.end();
// Try looking up the sub-row of this class
const map<pair<const srd_decoder*, int>, Row>::const_iterator r =
d->_class_rows.find(make_pair(decc, a.format()));
d->_class_rows.find(make_pair(decc, a->format()));
if (r != d->_class_rows.end())
row_iter = d->_rows.find((*r).second);
else
@ -650,58 +667,33 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
assert(row_iter != d->_rows.end());
if (row_iter == d->_rows.end()) {
qDebug() << "Unexpected annotation: decoder = " << decc <<
", format = " << a.format();
", format = " << a->format();
assert(0);
return;
}
// Add the annotation
boost::lock_guard<boost::recursive_mutex> lock(d->_output_mutex);
if (!(*row_iter).second.push_annotation(a))
d->_no_memory = true;
// Add the annotation
if (!(*row_iter).second->push_annotation(a))
d->_no_memory = true;
}
void DecoderStack::on_new_frame()
{
//begin_decode();
}
void DecoderStack::on_data_received()
{
// {
// unique_lock<mutex> lock(_input_mutex);
// if (_snapshot)
// _sample_count = _snapshot->get_sample_count();
// }
// _input_cond.notify_one();
}
void DecoderStack::on_frame_ended()
{
// {
// unique_lock<mutex> lock(_input_mutex);
// if (_snapshot)
// _frame_complete = true;
// }
// _input_cond.notify_one();
_options_changed = true;
begin_decode();
void DecoderStack::frame_ended()
{
_options_changed = true;
}
int DecoderStack::list_rows_size()
{
//lock_guard<mutex> lock(_output_mutex);
{
int rows_size = 0;
for (map<const Row, RowData>::const_iterator i = _rows.begin();
i != _rows.end(); i++) {
map<const Row, bool>::const_iterator iter = _rows_lshow.find((*i).first);
for (auto i = _rows.begin(); i != _rows.end(); i++) {
auto iter = _rows_lshow.find((*i).first);
if (iter != _rows_lshow.end() && (*iter).second)
rows_size++;
}
return rows_size;
}
bool DecoderStack::options_changed() const
bool DecoderStack::options_changed()
{
return _options_changed;
}
@ -711,7 +703,7 @@ void DecoderStack::set_options_changed(bool changed)
_options_changed = changed;
}
bool DecoderStack::out_of_memory() const
bool DecoderStack::out_of_memory()
{
return _no_memory;
}
@ -721,7 +713,7 @@ void DecoderStack::set_mark_index(int64_t index)
_mark_index = index;
}
int64_t DecoderStack::get_mark_index() const
int64_t DecoderStack::get_mark_index()
{
return _mark_index;
}

View File

@ -21,25 +21,28 @@
#ifndef DSVIEW_PV_DATA_DECODERSTACK_H
#define DSVIEW_PV_DATA_DECODERSTACK_H
#include <libsigrokdecode4DSL/libsigrokdecode.h>
#include <list>
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <QObject>
#include <QString>
#include <mutex>
#include "../data/decode/row.h"
#include "../data/decode/rowdata.h"
#include "decode/row.h"
#include "../data/signaldata.h"
class DecoderStatus;
struct decode_task_status
{
volatile bool m_bStop;
};
namespace DecoderStackTest {
class TwoDecoderStack;
}
namespace pv {
class SigSession;
@ -55,10 +58,12 @@ class LogicSnapshot;
namespace decode {
class Annotation;
class Decoder;
class RowData;
}
class Logic;
//a torotocol have a DecoderStack, destroy by DecodeTrace
class DecoderStack : public QObject, public SignalData
{
Q_OBJECT
@ -77,17 +82,22 @@ public:
};
public:
DecoderStack(pv::SigSession &_session,
const srd_decoder *const decoder);
DecoderStack(pv::SigSession *_session,
const srd_decoder *const decoder, DecoderStatus *decoder_status);
public:
virtual ~DecoderStack();
const std::list< boost::shared_ptr<decode::Decoder> >& stack() const;
void push(boost::shared_ptr<decode::Decoder> decoder);
void remove(boost::shared_ptr<decode::Decoder>& decoder);
inline std::list<decode::Decoder*>& stack(){
return _stack;
}
void push(decode::Decoder *decoder);
void remove(decode::Decoder *decoder);
void build_row();
int64_t samples_decoded() const;
int64_t samples_decoded();
/**
* Extracts sorted annotations between two period into a vector.
@ -95,11 +105,10 @@ public:
void get_annotation_subset(
std::vector<pv::data::decode::Annotation> &dest,
const decode::Row &row, uint64_t start_sample,
uint64_t end_sample) const;
uint64_t end_sample);
uint64_t get_annotation_index(
const decode::Row &row, uint64_t start_sample) const;
const decode::Row &row, uint64_t start_sample);
uint64_t get_max_annotation(const decode::Row &row);
uint64_t get_min_annotation(const decode::Row &row); // except instant(end=start) annotation
@ -107,100 +116,71 @@ public:
std::map<const decode::Row, bool> get_rows_lshow();
void set_rows_gshow(const decode::Row row, bool show);
void set_rows_lshow(const decode::Row row, bool show);
bool has_annotations(const decode::Row &row) const;
uint64_t list_annotation_size() const;
uint64_t list_annotation_size(uint16_t row_index) const;
bool has_annotations(const decode::Row &row);
uint64_t list_annotation_size();
uint64_t list_annotation_size(uint16_t row_index);
bool list_annotation(decode::Annotation &ann,
uint16_t row_index, uint64_t col_index) const;
uint16_t row_index, uint64_t col_index);
bool list_row_title(int row, QString &title) const;
bool list_row_title(int row, QString &title);
QString error_message();
void clear();
void init();
uint64_t get_max_sample_count();
uint64_t get_max_sample_count() const;
void begin_decode();
void stop_decode();
inline bool IsRunning(){
return _decode_state == Running;
}
void begin_decode_work();
void do_decode_work();
void stop_decode_work();
int list_rows_size();
bool options_changed() const;
bool options_changed();
void set_options_changed(bool changed);
uint64_t sample_count() const;
uint64_t sample_rate() const;
bool out_of_memory() const;
uint64_t sample_count();
uint64_t sample_rate();
bool out_of_memory();
void set_mark_index(int64_t index);
int64_t get_mark_index() const;
int64_t get_mark_index();
void frame_ended();
private:
void decode_data(const uint64_t decode_start, const uint64_t decode_end, srd_session *const session);
void decode_proc();
static void annotation_callback(srd_proto_data *pdata, void *decoder);
static void annotation_callback(srd_proto_data *pdata,
void *decoder);
private slots:
void on_new_frame();
void on_data_received();
void on_frame_ended();
signals:
void new_decode_data();
void decode_done();
private:
pv::SigSession &_session;
/**
* This mutex prevents more than one decode operation occuring
* concurrently.
* @todo A proper solution should be implemented to allow multiple
* decode operations.
*/
static boost::mutex _global_decode_mutex;
std::list< boost::shared_ptr<decode::Decoder> > _stack;
boost::shared_ptr<pv::data::LogicSnapshot> _snapshot;
//mutable boost::mutex _input_mutex;
//mutable boost::condition_variable _input_cond;
uint64_t _sample_count;
bool _frame_complete;
mutable boost::recursive_mutex _output_mutex;
//mutable boost::mutex _output_mutex;
int64_t _samples_decoded;
std::map<const decode::Row, decode::RowData> _rows;
std::map<const decode::Row, bool> _rows_gshow;
std::map<const decode::Row, bool> _rows_lshow;
private:
std::list<decode::Decoder*> _stack;
pv::data::LogicSnapshot *_snapshot;
std::map<const decode::Row, decode::RowData*> _rows;
std::map<const decode::Row, bool> _rows_gshow;
std::map<const decode::Row, bool> _rows_lshow;
std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
SigSession *_session;
decode_state _decode_state;
volatile bool _options_changed;
volatile bool _no_memory;
int64_t _mark_index;
QString _error_message;
std::unique_ptr<boost::thread> _decode_thread;
decode_state _decode_state;
bool _options_changed;
bool _no_memory;
int64_t _mark_index;
DecoderStatus *_decoder_status;
QString _error_message;
int64_t _samples_decoded;
uint64_t _sample_count;
decode_task_status *_stask_stauts;
mutable std::mutex _output_mutex;
friend class DecoderStackTest::TwoDecoderStack;
};

View File

@ -21,26 +21,27 @@
#include "dso.h"
#include "dsosnapshot.h"
#include <assert.h>
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
namespace pv {
namespace data {
Dso::Dso() :
Dso::Dso(DsoSnapshot *snapshot) :
SignalData()
{
assert(snapshot);
_snapshots.push_front(snapshot);
}
void Dso::push_snapshot(boost::shared_ptr<DsoSnapshot> &snapshot)
void Dso::push_snapshot(DsoSnapshot *snapshot)
{
_snapshots.push_front(snapshot);
}
deque< boost::shared_ptr<DsoSnapshot> >& Dso::get_snapshots()
std::deque<DsoSnapshot*>& Dso::get_snapshots()
{
return _snapshots;
}
@ -48,16 +49,21 @@ deque< boost::shared_ptr<DsoSnapshot> >& Dso::get_snapshots()
void Dso::clear()
{
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<DsoSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->clear();
}
void Dso::init()
{
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<DsoSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->init();
}
DsoSnapshot* Dso::snapshot()
{
return _snapshots[0];
}
} // namespace data
} // namespace pv

View File

@ -24,8 +24,7 @@
#define DSVIEW_PV_DATA_DSO_H
#include "signaldata.h"
#include <boost/shared_ptr.hpp>
#include <deque>
namespace pv {
@ -36,19 +35,19 @@ class DsoSnapshot;
class Dso : public SignalData
{
public:
Dso();
Dso(DsoSnapshot *snapshot);
void push_snapshot(
boost::shared_ptr<DsoSnapshot> &snapshot);
void push_snapshot(DsoSnapshot *snapshot);
std::deque< boost::shared_ptr<DsoSnapshot> >&
get_snapshots();
std::deque<DsoSnapshot*>& get_snapshots();
void clear();
void init();
DsoSnapshot* snapshot();
private:
std::deque< boost::shared_ptr<DsoSnapshot> > _snapshots;
std::deque<DsoSnapshot*> _snapshots;
};
} // namespace data

View File

@ -19,20 +19,15 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <extdef.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <boost/foreach.hpp>
#include "dsosnapshot.h"
#include "../extdef.h"
using namespace boost;
using namespace std;
namespace pv {
@ -63,7 +58,7 @@ DsoSnapshot::~DsoSnapshot()
void DsoSnapshot::free_envelop()
{
for (unsigned int i = 0; i < _channel_num; i++) {
BOOST_FOREACH(Envelope &e, _envelope_levels[i]) {
for(auto &e : _envelope_levels[i]) {
if (e.samples)
free(e.samples);
}
@ -73,13 +68,19 @@ void DsoSnapshot::free_envelop()
void DsoSnapshot::init()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
init_all();
}
void DsoSnapshot::init_all()
{
_sample_count = 0;
_ring_sample_count = 0;
_memory_failed = false;
_last_ended = true;
_envelope_done = false;
_ch_enable.clear();
for (unsigned int i = 0; i < _channel_num; i++) {
for (unsigned int level = 0; level < ScaleStepCount; level++) {
_envelope_levels[i][level].length = 0;
@ -90,10 +91,10 @@ void DsoSnapshot::init()
void DsoSnapshot::clear()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
free_data();
free_envelop();
init();
init_all();
}
void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sample_count,
@ -157,7 +158,7 @@ void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sampl
void DsoSnapshot::append_payload(const sr_datafeed_dso &dso)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
if (_channel_num > 0 && dso.num_samples != 0) {
append_data(dso.data, dso.num_samples, _instant);
@ -184,33 +185,30 @@ void DsoSnapshot::append_data(void *data, uint64_t samples, bool instant)
void DsoSnapshot::enable_envelope(bool enable)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
if (!_envelope_done && enable)
append_payload_to_envelope_levels(true);
_envelope_en = enable;
}
const uint8_t *DsoSnapshot::get_samples(
int64_t start_sample, int64_t end_sample, uint16_t index) const
int64_t start_sample, int64_t end_sample, uint16_t index)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
(void)end_sample;
assert(start_sample >= 0);
assert(start_sample < (int64_t)get_sample_count());
assert(start_sample < (int64_t)sample_count());
assert(end_sample >= 0);
assert(end_sample < (int64_t)get_sample_count());
assert(end_sample < (int64_t)sample_count());
assert(start_sample <= end_sample);
// uint16_t *const data = new uint16_t[end_sample - start_sample];
// memcpy(data, (uint16_t*)_data + start_sample, sizeof(uint16_t) *
// (end_sample - start_sample));
// return data;
return (uint8_t*)_data + start_sample * _channel_num + index * (_channel_num != 1);
}
void DsoSnapshot::get_envelope_section(EnvelopeSection &s,
uint64_t start, uint64_t end, float min_length, int probe_index) const
uint64_t start, uint64_t end, float min_length, int probe_index)
{
assert(end <= get_sample_count());
assert(start <= end);
@ -348,7 +346,7 @@ void DsoSnapshot::append_payload_to_envelope_levels(bool header)
_envelope_done = true;
}
double DsoSnapshot::cal_vrms(double zero_off, int index) const
double DsoSnapshot::cal_vrms(double zero_off, int index)
{
assert(index >= 0);
//assert(index < _channel_num);
@ -378,12 +376,12 @@ double DsoSnapshot::cal_vrms(double zero_off, int index) const
vrms = vrms_pre + vrms / get_sample_count();
vrms_pre = vrms;
}
vrms = std::pow(vrms, 0.5);
vrms = pow(vrms, 0.5);
return vrms;
}
double DsoSnapshot::cal_vmean(int index) const
double DsoSnapshot::cal_vmean(int index)
{
assert(index >= 0);
//assert(index < _channel_num);

View File

@ -25,6 +25,7 @@
#include <utility>
#include <vector>
#include <map>
#include <libsigrok4DSL/libsigrok.h>
#include "snapshot.h"
@ -74,6 +75,9 @@ private:
static const int VrmsScaleFactor;
private:
void init_all();
public:
DsoSnapshot();
@ -88,15 +92,15 @@ public:
void append_payload(const sr_datafeed_dso &dso);
const uint8_t* get_samples(int64_t start_sample,
int64_t end_sample, uint16_t index) const;
int64_t end_sample, uint16_t index);
void get_envelope_section(EnvelopeSection &s,
uint64_t start, uint64_t end, float min_length, int probe_index) const;
uint64_t start, uint64_t end, float min_length, int probe_index);
void enable_envelope(bool enable);
double cal_vrms(double zero_off, int index) const;
double cal_vmean(int index) const;
double cal_vrms(double zero_off, int index);
double cal_vmean(int index);
bool has_data(int index);
int get_block_num();

View File

@ -21,10 +21,8 @@
#include "group.h"
#include "groupsnapshot.h"
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
namespace pv {
@ -35,25 +33,25 @@ Group::Group() :
{
}
void Group::push_snapshot(boost::shared_ptr<GroupSnapshot> &snapshot)
void Group::push_snapshot(GroupSnapshot *snapshot)
{
_snapshots.push_back(snapshot);
}
deque< boost::shared_ptr<GroupSnapshot> >& Group::get_snapshots()
std::deque<GroupSnapshot*>& Group::get_snapshots()
{
return _snapshots;
}
void Group::clear()
{
BOOST_FOREACH(const boost::shared_ptr<GroupSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->clear();
}
void Group::init()
{
BOOST_FOREACH(const boost::shared_ptr<GroupSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->init();
}

View File

@ -24,8 +24,7 @@
#define DSVIEW_PV_DATA_GROUP_H
#include "signaldata.h"
#include <boost/shared_ptr.hpp>
#include <deque>
namespace pv {
@ -38,17 +37,15 @@ class Group : public SignalData
public:
Group();
void push_snapshot(
boost::shared_ptr<GroupSnapshot> &snapshot);
void push_snapshot(GroupSnapshot *snapshot);
std::deque< boost::shared_ptr<GroupSnapshot> >&
get_snapshots();
std::deque<GroupSnapshot*>& get_snapshots();
void clear();
void init();
private:
std::deque< boost::shared_ptr<GroupSnapshot> > _snapshots;
std::deque<GroupSnapshot*> _snapshots;
};
} // namespace data

View File

@ -18,9 +18,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <extdef.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
@ -28,12 +26,10 @@
#include <algorithm>
#include <boost/foreach.hpp>
#include "logicsnapshot.h"
#include "groupsnapshot.h"
#include "../extdef.h"
using namespace boost;
using namespace std;
namespace pv {
@ -49,15 +45,17 @@ const uint16_t GroupSnapshot::value_mask[16] = {0x1, 0x2, 0x4, 0x8,
0x100, 0x200, 0x400, 0x800,
0x1000, 0x2000, 0x4000, 0x8000};
GroupSnapshot::GroupSnapshot(const boost::shared_ptr<LogicSnapshot> &_logic_snapshot, std::list<int> index_list)
GroupSnapshot::GroupSnapshot(const LogicSnapshot *_logic_snapshot, std::list<int> index_list)
{
assert(_logic_snapshot);
//boost::lock_guard<boost::recursive_mutex> lock(_mutex);
LogicSnapshot *logic_snapshot = const_cast<LogicSnapshot*>(_logic_snapshot);
memset(_envelope_levels, 0, sizeof(_envelope_levels));
_data = _logic_snapshot->get_data();
_sample_count = _logic_snapshot->get_sample_count();
_unit_size = _logic_snapshot->unit_size();
_data = logic_snapshot->get_data();
_sample_count = logic_snapshot->get_sample_count();
_unit_size = logic_snapshot->unit_size();
_index_list = index_list;
_mask = 0;
@ -94,9 +92,8 @@ GroupSnapshot::GroupSnapshot(const boost::shared_ptr<LogicSnapshot> &_logic_snap
}
GroupSnapshot::~GroupSnapshot()
{
//boost::lock_guard<boost::recursive_mutex> lock(_mutex);
BOOST_FOREACH(Envelope &e, _envelope_levels)
{
for(auto &e : _envelope_levels)
free(e.samples);
}
@ -110,17 +107,14 @@ void GroupSnapshot::clear()
}
uint64_t GroupSnapshot::get_sample_count() const
{
//boost::lock_guard<boost::recursive_mutex> lock(_mutex);
uint64_t GroupSnapshot::get_sample_count()
{
return _sample_count;
}
void GroupSnapshot::append_payload()
{
//boost::lock_guard<boost::recursive_mutex> lock(_mutex);
// Generate the first mip-map from the data
append_payload_to_envelope_levels();
}
@ -134,13 +128,10 @@ const uint16_t* GroupSnapshot::get_samples(
assert(start_sample <= end_sample);
int64_t i;
uint16_t tmpl, tmpr;
//boost::lock_guard<boost::recursive_mutex> lock(_mutex);
uint16_t tmpl, tmpr;
uint16_t *const data = new uint16_t[end_sample - start_sample];
// memcpy(data, (uint16_t*)_data + start_sample, sizeof(uint16_t) *
// (end_sample - start_sample));
// memset(data, 0, sizeof(uint16_t) * (end_sample - start_sample));
for(i = start_sample; i < end_sample; i++) {
if (_unit_size == 2)
tmpl = *((uint16_t*)_data + i) & _mask;
@ -158,13 +149,12 @@ const uint16_t* GroupSnapshot::get_samples(
}
void GroupSnapshot::get_envelope_section(EnvelopeSection &s,
uint64_t start, uint64_t end, float min_length) const
uint64_t start, uint64_t end, float min_length)
{
assert(end <= _sample_count);
assert(start <= end);
assert(min_length > 0);
//boost::lock_guard<boost::recursive_mutex> lock(_mutex);
const unsigned int min_level = max((int)floorf(logf(min_length) /
LogEnvelopeScaleFactor) - 1, 0);

View File

@ -22,10 +22,7 @@
#ifndef DSVIEW_PV_DATA_GROUPSNAPSHOT_H
#define DSVIEW_PV_DATA_GROUPSNAPSHOT_H
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include "../view/signal.h"
#include <utility>
@ -75,7 +72,7 @@ private:
static const uint16_t value_mask[16];
public:
GroupSnapshot(const boost::shared_ptr<LogicSnapshot> &_logic_snapshot, std::list<int> index_list);
GroupSnapshot(const LogicSnapshot *_logic_snapshot, std::list<int> index_list);
virtual ~GroupSnapshot();
@ -84,13 +81,13 @@ public:
void append_payload();
uint64_t get_sample_count() const;
uint64_t get_sample_count();
const uint16_t* get_samples(int64_t start_sample,
int64_t end_sample);
void get_envelope_section(EnvelopeSection &s,
uint64_t start, uint64_t end, float min_length) const;
uint64_t start, uint64_t end, float min_length);
private:
void reallocate_envelope(Envelope &l);
@ -99,11 +96,11 @@ private:
private:
struct Envelope _envelope_levels[ScaleStepCount];
//mutable boost::recursive_mutex _mutex;
const void *_data;
uint64_t _sample_count;
int _unit_size;
boost::shared_ptr<view::Signal> _signal;
view::Signal *_signal;
std::list<int> _index_list;
uint16_t _mask;
int _bubble_start[32];

View File

@ -22,27 +22,26 @@
#include "logic.h"
#include "logicsnapshot.h"
#include <assert.h>
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
namespace pv {
namespace data {
Logic::Logic() :
Logic::Logic(LogicSnapshot *snapshot) :
SignalData()
{
assert(snapshot);
_snapshots.push_front(snapshot);
}
void Logic::push_snapshot(
boost::shared_ptr<LogicSnapshot> &snapshot)
void Logic::push_snapshot(LogicSnapshot *snapshot)
{
_snapshots.push_front(snapshot);
}
deque< boost::shared_ptr<LogicSnapshot> >& Logic::get_snapshots()
std::deque<LogicSnapshot*>& Logic::get_snapshots()
{
return _snapshots;
}
@ -50,16 +49,21 @@ deque< boost::shared_ptr<LogicSnapshot> >& Logic::get_snapshots()
void Logic::clear()
{
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<LogicSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->clear();
}
void Logic::init()
{
//_snapshots.clear();
BOOST_FOREACH(const boost::shared_ptr<LogicSnapshot> s, _snapshots)
for(auto &s : _snapshots)
s->init();
}
LogicSnapshot* Logic::snapshot()
{
return _snapshots[0];
}
} // namespace data
} // namespace pv

View File

@ -25,8 +25,7 @@
#define DSVIEW_PV_DATA_LOGIC_H
#include "signaldata.h"
#include <boost/shared_ptr.hpp>
#include <deque>
namespace pv {
@ -37,20 +36,20 @@ class LogicSnapshot;
class Logic : public SignalData
{
public:
Logic();
Logic(LogicSnapshot *snapshot);
void push_snapshot(
boost::shared_ptr<LogicSnapshot> &snapshot);
void push_snapshot(LogicSnapshot *snapshot);
std::deque< boost::shared_ptr<LogicSnapshot> >&
get_snapshots();
std::deque<LogicSnapshot*>& get_snapshots();
void clear();
void init();
LogicSnapshot* snapshot();
private:
std::deque< boost::shared_ptr<LogicSnapshot> > _snapshots;
std::deque<LogicSnapshot*> _snapshots;
};
} // namespace data

View File

@ -19,21 +19,17 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <extdef.h>
#include <QDebug>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <boost/foreach.hpp>
#include "logicsnapshot.h"
#include "../extdef.h"
using namespace boost;
using namespace std;
namespace pv {
@ -80,8 +76,13 @@ void LogicSnapshot::free_data()
void LogicSnapshot::init()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
_sample_count = 0;
std::lock_guard<std::mutex> lock(_mutex);
init_all();
}
void LogicSnapshot::init_all()
{
_sample_count = 0;
_ring_sample_count = 0;
_block_num = 0;
_byte_fraction = 0;
@ -95,9 +96,9 @@ void LogicSnapshot::init()
void LogicSnapshot::clear()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
free_data();
init();
init_all();
}
void LogicSnapshot::capture_ended()
@ -203,7 +204,7 @@ void LogicSnapshot::first_payload(const sr_datafeed_logic &logic, uint64_t total
void LogicSnapshot::append_payload(
const sr_datafeed_logic &logic)
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
if (logic.format == LA_CROSS_DATA)
append_cross_payload(logic);
@ -473,8 +474,9 @@ const uint8_t *LogicSnapshot::get_samples(uint64_t start_sample, uint64_t &end_s
int sig_index)
{
//assert(data);
assert(start_sample < get_sample_count());
assert(end_sample <= get_sample_count());
uint64_t sample_count = get_sample_count();
assert(start_sample < sample_count);
assert(end_sample <= sample_count);
assert(start_sample <= end_sample);
int order = get_ch_order(sig_index);

View File

@ -32,6 +32,7 @@
#include <utility>
#include <vector>
#include <map>
namespace LogicSnapshotTest {
class Pow2;
@ -76,13 +77,19 @@ private:
public:
typedef std::pair<uint64_t, bool> EdgePair;
private:
void init_all();
public:
LogicSnapshot();
virtual ~LogicSnapshot();
void free_data();
void clear();
void init();
void init();
void first_payload(const sr_datafeed_logic &logic, uint64_t total_sample_count, GSList *channels);

View File

@ -19,14 +19,12 @@
*/
#include "mathstack.h"
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <pv/data/dso.h>
#include <pv/data/dsosnapshot.h>
#include <pv/sigsession.h>
#include <pv/view/dsosignal.h>
#include "dso.h"
#include "dsosnapshot.h"
#include "../sigsession.h"
#include "../view/dsosignal.h"
#include <math.h>
#define PI 3.1415
@ -75,9 +73,9 @@ const QString MathStack::vDialDivUnit[MathStack::vDialUnitCount] = {
"V/V",
};
MathStack::MathStack(pv::SigSession &session,
boost::shared_ptr<view::DsoSignal> dsoSig1,
boost::shared_ptr<view::DsoSignal> dsoSig2,
MathStack::MathStack(pv::SigSession *session,
view::DsoSignal* dsoSig1,
view::DsoSignal* dsoSig2,
MathType type) :
_session(session),
_dsoSig1(dsoSig1),
@ -100,7 +98,7 @@ MathStack::~MathStack()
void MathStack::free_envelop()
{
BOOST_FOREACH(Envelope &e, _envelope_level) {
for(auto &e : _envelope_level) {
if (e.samples)
free(e.samples);
}
@ -109,23 +107,23 @@ void MathStack::free_envelop()
void MathStack::clear()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
}
void MathStack::init()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
_sample_num = 0;
_envelope_done = false;
}
MathStack::MathType MathStack::get_type() const
MathStack::MathType MathStack::get_type()
{
return _type;
}
uint64_t MathStack::get_sample_num() const
uint64_t MathStack::get_sample_num()
{
return _sample_num;
}
@ -279,13 +277,13 @@ double MathStack::get_math_scale()
return scale;
}
const double* MathStack::get_math(uint64_t start) const
const double* MathStack::get_math(uint64_t start)
{
return _math.data() + start;
}
void MathStack::get_math_envelope_section(EnvelopeSection &s,
uint64_t start, uint64_t end, float min_length) const
uint64_t start, uint64_t end, float min_length)
{
assert(end <= get_sample_num());
assert(start <= end);
@ -315,18 +313,16 @@ void MathStack::get_math_envelope_section(EnvelopeSection &s,
void MathStack::calc_math()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
_math_state = Running;
const boost::shared_ptr<pv::data::Dso> data = _dsoSig1->dso_data();
const deque< boost::shared_ptr<pv::data::DsoSnapshot> > &snapshots =
data->get_snapshots();
const auto data = _dsoSig1->dso_data();
const auto &snapshots = data->get_snapshots();
if (snapshots.empty())
return;
const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot =
snapshots.front();
const auto snapshot = snapshots.front();
if (snapshot->empty())
return;

View File

@ -25,9 +25,8 @@
#include <list>
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/optional.hpp>
#include <QObject>
#include <QString>
@ -102,17 +101,17 @@ private:
static const QString vDialDivUnit[vDialUnitCount];
public:
MathStack(pv::SigSession &_session,
boost::shared_ptr<view::DsoSignal> dsoSig1,
boost::shared_ptr<view::DsoSignal> dsoSig2, MathType type);
MathStack(pv::SigSession *_session,
view::DsoSignal *dsoSig1,
view::DsoSignal *dsoSig2, MathType type);
virtual ~MathStack();
void clear();
void init();
void free_envelop();
void realloc(uint64_t num);
MathType get_type() const;
uint64_t get_sample_num() const;
MathType get_type();
uint64_t get_sample_num();
void enable_envelope(bool enable);
@ -121,9 +120,9 @@ public:
QString get_unit(int level);
double get_math_scale();
const double *get_math(uint64_t start) const;
const double *get_math(uint64_t start);
void get_math_envelope_section(EnvelopeSection &s,
uint64_t start, uint64_t end, float min_length) const;
uint64_t start, uint64_t end, float min_length);
void calc_math();
void reallocate_envelope(Envelope &e);
@ -132,9 +131,9 @@ public:
signals:
private:
pv::SigSession &_session;
boost::shared_ptr<view::DsoSignal> _dsoSig1;
boost::shared_ptr<view::DsoSignal> _dsoSig2;
pv::SigSession *_session;
view::DsoSignal *_dsoSig1;
view::DsoSignal *_dsoSig2;
MathType _type;
uint64_t _sample_num;

View File

@ -33,11 +33,7 @@ SignalData::SignalData() :
}
SignalData::~SignalData() {}
double SignalData::samplerate() const
{
return _samplerate;
}
void SignalData::set_samplerate(double samplerate)
{

View File

@ -25,7 +25,7 @@
#define DSVIEW_PV_DATA_SIGNALDATA_H
#include <stdint.h>
#include <boost/thread.hpp>
#include <mutex>
namespace pv {
namespace data {
@ -35,17 +35,17 @@ class SignalData
public:
SignalData();
virtual ~SignalData() = 0;
public:
double samplerate() const;
inline double samplerate()const
{return _samplerate; }
void set_samplerate(double samplerate);
virtual void clear() = 0;
virtual void init() = 0;
protected:
mutable boost::recursive_mutex _mutex;
mutable std::mutex _mutex;
double _samplerate;
};

View File

@ -28,9 +28,7 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
using namespace boost;
namespace pv {
namespace data {
@ -66,12 +64,7 @@ void Snapshot::free_data()
_ch_index.clear();
}
bool Snapshot::memory_failed() const
{
return _memory_failed;
}
bool Snapshot::empty() const
bool Snapshot::empty()
{
if (get_sample_count() == 0)
return true;
@ -79,34 +72,34 @@ bool Snapshot::empty() const
return false;
}
bool Snapshot::last_ended() const
uint64_t Snapshot::get_sample_count()
{
return _last_ended;
}
void Snapshot::set_last_ended(bool ended)
{
_last_ended = ended;
}
uint64_t Snapshot::get_sample_count() const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
return _sample_count;
}
uint64_t Snapshot::get_ring_start() const
uint64_t Snapshot::get_ring_start()
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
return ring_start();
}
uint64_t Snapshot::get_ring_end()
{
std::lock_guard<std::mutex> lock(_mutex);
return ring_end();
}
uint64_t Snapshot::ring_start()
{
if (_sample_count < _total_sample_count)
return 0;
else
return _ring_sample_count;
}
uint64_t Snapshot::get_ring_end() const
{
boost::lock_guard<boost::recursive_mutex> lock(_mutex);
uint64_t Snapshot::ring_end()
{
if (_sample_count == 0)
return 0;
else if (_ring_sample_count == 0)
@ -115,26 +108,6 @@ uint64_t Snapshot::get_ring_end() const
return _ring_sample_count - 1;
}
const void* Snapshot::get_data() const
{
return _data;
}
int Snapshot::unit_size() const
{
return _unit_size;
}
uint8_t Snapshot::get_unit_bytes() const
{
return _unit_bytes;
}
unsigned int Snapshot::get_channel_num() const
{
return _channel_num;
}
void Snapshot::capture_ended()
{
set_last_ended(true);

View File

@ -23,7 +23,8 @@
#ifndef DSVIEW_PV_DATA_SNAPSHOT_H
#define DSVIEW_PV_DATA_SNAPSHOT_H
#include <boost/thread.hpp>
#include <mutex>
#include <vector>
namespace pv {
namespace data {
@ -38,22 +39,39 @@ public:
virtual void clear() = 0;
virtual void init() = 0;
uint64_t get_sample_count() const;
uint64_t get_ring_start() const;
uint64_t get_ring_end() const;
uint64_t get_sample_count();
uint64_t get_ring_start();
uint64_t get_ring_end();
const void * get_data() const;
inline const void* get_data(){
return _data;
}
int unit_size() const;
uint8_t get_unit_bytes() const;
inline int unit_size(){
return _unit_size;
}
bool memory_failed() const;
bool empty() const;
inline uint8_t get_unit_bytes(){
return _unit_bytes;
}
bool last_ended() const;
void set_last_ended(bool ended);
inline bool memory_failed(){
return _memory_failed;
}
unsigned int get_channel_num() const;
bool empty();
inline bool last_ended(){
return _last_ended;
}
inline void set_last_ended(bool ended){
_last_ended = ended;
}
inline unsigned int get_channel_num(){
return _channel_num;
}
virtual void capture_ended();
virtual bool has_data(int index) = 0;
@ -63,12 +81,19 @@ public:
protected:
virtual void free_data();
protected:
mutable boost::recursive_mutex _mutex;
inline uint64_t sample_count(){
return _sample_count;
}
//std::vector<uint8_t> _data;
uint64_t ring_start();
uint64_t ring_end();
protected:
mutable std::mutex _mutex;
void* _data;
std::vector<uint16_t> _ch_index;
mutable std::vector<uint16_t> _ch_index;
uint64_t _capacity;
unsigned int _channel_num;

View File

@ -19,14 +19,12 @@
*/
#include "spectrumstack.h"
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <pv/data/dso.h>
#include <pv/data/dsosnapshot.h>
#include <pv/sigsession.h>
#include <pv/view/dsosignal.h>
#include "dso.h"
#include "dsosnapshot.h"
#include "../sigsession.h"
#include "../view/dsosignal.h"
#include <math.h>
#define PI 3.1415
@ -52,7 +50,7 @@ const uint64_t SpectrumStack::length_support[5] = {
16384,
};
SpectrumStack::SpectrumStack(pv::SigSession &session, int index) :
SpectrumStack::SpectrumStack(pv::SigSession *session, int index) :
_session(session),
_index(index),
_dc_ignore(true),
@ -79,12 +77,12 @@ void SpectrumStack::init()
{
}
int SpectrumStack::get_index() const
int SpectrumStack::get_index()
{
return _index;
}
uint64_t SpectrumStack::get_sample_num() const
uint64_t SpectrumStack::get_sample_num()
{
return _sample_num;
}
@ -99,7 +97,7 @@ void SpectrumStack::set_sample_num(uint64_t num)
FFTW_R2HC, FFTW_ESTIMATE);
}
int SpectrumStack::get_windows_index() const
int SpectrumStack::get_windows_index()
{
return _windows_index;
}
@ -109,7 +107,7 @@ void SpectrumStack::set_windows_index(int index)
_windows_index = index;
}
bool SpectrumStack::dc_ignored() const
bool SpectrumStack::dc_ignored()
{
return _dc_ignore;
}
@ -119,7 +117,7 @@ void SpectrumStack::set_dc_ignore(bool ignore)
_dc_ignore = ignore;
}
int SpectrumStack::get_sample_interval() const
int SpectrumStack::get_sample_interval()
{
return _sample_interval;
}
@ -129,7 +127,7 @@ void SpectrumStack::set_sample_interval(int interval)
_sample_interval = interval;
}
const std::vector<QString> SpectrumStack::get_windows_support() const
const std::vector<QString> SpectrumStack::get_windows_support()
{
std::vector<QString> windows;
for (size_t i = 0; i < sizeof(windows_support)/sizeof(windows_support[0]); i++)
@ -139,7 +137,7 @@ const std::vector<QString> SpectrumStack::get_windows_support() const
return windows;
}
const std::vector<uint64_t> SpectrumStack::get_length_support() const
const std::vector<uint64_t> SpectrumStack::get_length_support()
{
std::vector<uint64_t> length;
for (size_t i = 0; i < sizeof(length_support)/sizeof(length_support[0]); i++)
@ -149,7 +147,7 @@ const std::vector<uint64_t> SpectrumStack::get_length_support() const
return length;
}
const std::vector<double> SpectrumStack::get_fft_spectrum() const
const std::vector<double> SpectrumStack::get_fft_spectrum()
{
std::vector<double> empty;
if (_spectrum_state == Stopped)
@ -171,10 +169,11 @@ void SpectrumStack::calc_fft()
{
_spectrum_state = Running;
// Get the dso data
boost::shared_ptr<pv::data::Dso> data;
boost::shared_ptr<pv::view::DsoSignal> dsoSig;
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
pv::data::Dso *data = NULL;
pv::view::DsoSignal *dsoSig = NULL;
for(auto &s : _session->get_signals()) {
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
if (dsoSig->get_index() == _index && dsoSig->enabled()) {
data = dsoSig->dso_data();
break;
@ -186,10 +185,10 @@ void SpectrumStack::calc_fft()
return;
// Check we have a snapshot of data
const deque< boost::shared_ptr<pv::data::DsoSnapshot> > &snapshots =
data->get_snapshots();
const auto &snapshots = data->get_snapshots();
if (snapshots.empty())
return;
_snapshot = snapshots.front();
if (_snapshot->get_sample_count() < _sample_num*_sample_interval)

View File

@ -25,10 +25,8 @@
#include <list>
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/optional.hpp>
#include <fftw3.h>
#include <QObject>
@ -63,29 +61,29 @@ public:
};
public:
SpectrumStack(pv::SigSession &_session, int index);
SpectrumStack(pv::SigSession *_session, int index);
virtual ~SpectrumStack();
void clear();
void init();
int get_index() const;
int get_index();
uint64_t get_sample_num() const;
uint64_t get_sample_num();
void set_sample_num(uint64_t num);
int get_windows_index() const;
int get_windows_index();
void set_windows_index(int index);
const std::vector<QString> get_windows_support() const;
const std::vector<uint64_t> get_length_support() const;
const std::vector<QString> get_windows_support();
const std::vector<uint64_t> get_length_support();
bool dc_ignored() const;
bool dc_ignored();
void set_dc_ignore(bool ignore);
int get_sample_interval() const;
int get_sample_interval();
void set_sample_interval(int interval);
const std::vector<double> get_fft_spectrum() const;
const std::vector<double> get_fft_spectrum();
double get_fft_spectrum(uint64_t index);
void calc_fft();
@ -95,7 +93,7 @@ public:
signals:
private:
pv::SigSession &_session;
pv::SigSession *_session;
int _index;
uint64_t _sample_num;
@ -103,7 +101,7 @@ private:
bool _dc_ignore;
int _sample_interval;
boost::shared_ptr<pv::data::DsoSnapshot> _snapshot;
pv::data::DsoSnapshot *_snapshot;
spectrum_state _spectrum_state;
fftw_plan _fft_plan;

View File

@ -35,7 +35,12 @@ Device::Device(sr_dev_inst *sdi) :
assert(_sdi);
}
sr_dev_inst* Device::dev_inst() const
Device::~Device()
{
}
sr_dev_inst* Device::dev_inst()
{
return _sdi;
}
@ -45,9 +50,8 @@ void Device::use(SigSession *owner)
DevInst::use(owner);
sr_session_new();
assert(_sdi);
sr_dev_open(_sdi);
_usable = (_sdi->status == SR_ST_ACTIVE);
if (sr_session_dev_add(_sdi) != SR_OK)
throw QString(tr("Failed to use device."));
@ -63,19 +67,10 @@ void Device::release()
sr_dev_close(_sdi);
}
QString Device::format_device_title() const
QString Device::format_device_title()
{
ostringstream s;
assert(_sdi);
// if (_sdi->vendor && _sdi->vendor[0]) {
// s << _sdi->vendor;
// if ((_sdi->model && _sdi->model[0]) ||
// (_sdi->version && _sdi->version[0]))
// s << ' ';
// }
if (_sdi->model && _sdi->model[0]) {
s << _sdi->model;
if (_sdi->version && _sdi->version[0])
@ -88,9 +83,8 @@ QString Device::format_device_title() const
return QString::fromStdString(s.str());
}
bool Device::is_trigger_enabled() const
bool Device::is_trigger_enabled()
{
assert(_sdi);
for (const GSList *l = _sdi->channels; l; l = l->next) {
const sr_channel *const p = (const sr_channel *)l->data;
assert(p);

View File

@ -28,19 +28,21 @@ namespace pv {
namespace device {
class Device : public DevInst
{
{
public:
Device(sr_dev_inst *dev_inst);
sr_dev_inst* dev_inst() const;
~Device();
sr_dev_inst* dev_inst();
void use(SigSession *owner);
void release();
QString format_device_title() const;
QString format_device_title();
bool is_trigger_enabled() const;
bool is_trigger_enabled();
private:
sr_dev_inst *const _sdi;

View File

@ -25,7 +25,7 @@
#include "devinst.h"
#include <pv/sigsession.h>
#include "../sigsession.h"
namespace pv {
namespace device {
@ -43,7 +43,7 @@ DevInst::~DevInst()
free(_id);
}
void* DevInst::get_id() const
void* DevInst::get_id()
{
assert(_id);
@ -53,7 +53,6 @@ void* DevInst::get_id() const
void DevInst::use(SigSession *owner)
{
assert(owner);
assert(!_owner);
_owner = owner;
}
@ -61,11 +60,10 @@ void DevInst::release()
{
if (_owner) {
_owner->release_device(this);
_owner = NULL;
}
}
SigSession* DevInst::owner() const
SigSession* DevInst::owner()
{
return _owner;
}
@ -189,7 +187,7 @@ QString DevInst::name()
return QString::fromLocal8Bit(sdi->driver->name);
}
bool DevInst::is_trigger_enabled() const
bool DevInst::is_trigger_enabled()
{
return false;
}
@ -197,18 +195,34 @@ bool DevInst::is_trigger_enabled() const
void DevInst::start()
{
if (sr_session_start() != SR_OK)
throw tr("Failed to start session.");
throw tr("Failed to start session.");
//assert(false);
}
void DevInst::run()
{
sr_session_run();
qDebug()<<"session run loop start";
int ret = sr_session_run();
if (ret != SR_OK){
qDebug()<<"start session error!";
}
qDebug()<<"session run loop end";
}
bool DevInst::is_usable() const
void DevInst::stop()
{
sr_session_stop();
}
bool DevInst::is_usable()
{
return _usable;
}
void DevInst::destroy(){
release();
//delete this; //do not to destroy
}
} // device
} // pv

View File

@ -22,8 +22,6 @@
#ifndef DSVIEW_PV_DEVICE_DEVINST_H
#define DSVIEW_PV_DEVICE_DEVINST_H
#include <boost/shared_ptr.hpp>
#include <QObject>
#include <string>
@ -48,19 +46,12 @@ class DevInst : public QObject
protected:
DevInst();
~DevInst();
public:
virtual sr_dev_inst* dev_inst() const = 0;
virtual void use(SigSession *owner);
virtual void release();
SigSession* owner() const;
virtual QString format_device_title() const = 0;
virtual ~DevInst();
public:
SigSession* owner();
GVariant* get_config(const sr_channel *ch, const sr_channel_group *group, int key);
bool set_config(sr_channel *ch, sr_channel_group *group, int key, GVariant *data);
@ -115,17 +106,30 @@ public:
* @return device name
*/
QString name();
virtual bool is_trigger_enabled() const;
bool is_usable();
bool is_usable() const;
void destroy();
public:
virtual void start();
virtual void run();
virtual void* get_id() const;
virtual void stop();
virtual void* get_id();
virtual sr_dev_inst* dev_inst() = 0;
virtual void use(SigSession *owner);
virtual void release();
virtual bool is_trigger_enabled();
virtual QString format_device_title() = 0;
signals:
void device_updated();

View File

@ -39,7 +39,11 @@ File::File(QString path) :
{
}
QString File::format_device_title() const
File::~File(){
}
QString File::format_device_title()
{
QFileInfo fi(_path);
return fi.fileName();
@ -92,7 +96,7 @@ QJsonArray File::get_decoders()
}
}
zip_close(archive);
zip_close(archive);
}
return dec_array;

View File

@ -35,10 +35,13 @@ namespace device {
class File : public DevInst
{
protected:
File(QString path);
public:
~File();
static File* create(QString name);
QJsonArray get_decoders();
@ -46,7 +49,7 @@ public:
QJsonDocument get_session();
public:
QString format_device_title() const;
QString format_device_title();
protected:
const QString _path;

View File

@ -37,7 +37,7 @@ InputFile::InputFile(QString path) :
{
}
sr_dev_inst* InputFile::dev_inst() const
sr_dev_inst* InputFile::dev_inst()
{
assert(_input);
return _input->sdi;
@ -51,15 +51,7 @@ void InputFile::use(SigSession *owner)
// only *.dsl file is valid
// don't allow other types of file input
throw tr("Not a valid DSView data file.");
return;
// _input = load_input_file_format(_path, NULL);
// File::use(owner);
// sr_session_new();
// if (sr_session_dev_add(_input->sdi) != SR_OK)
// throw tr("Failed to add session device.");
return;
}
void InputFile::release()

View File

@ -37,7 +37,7 @@ class InputFile : public File
public:
InputFile(QString path);
sr_dev_inst* dev_inst() const;
sr_dev_inst* dev_inst();
virtual void use(SigSession *owner);

View File

@ -25,12 +25,12 @@ namespace pv {
namespace device {
SessionFile::SessionFile(QString path) :
File(path),
_sdi(NULL)
File(path)
{
_sdi = NULL;
}
sr_dev_inst* SessionFile::dev_inst() const
sr_dev_inst* SessionFile::dev_inst()
{
return _sdi;
}
@ -38,6 +38,9 @@ sr_dev_inst* SessionFile::dev_inst() const
void SessionFile::use(SigSession *owner)
{
assert(!_sdi);
if (_sdi){
//return;
}
if (sr_session_load(_path.toUtf8().data()) != SR_OK)
throw tr("Failed to open file.\n");
@ -58,16 +61,15 @@ void SessionFile::use(SigSession *owner)
}
void SessionFile::release()
{
if (!_owner)
return;
assert(_sdi);
File::release();
sr_dev_close(_sdi);
sr_dev_clear(_sdi->driver);
sr_session_destroy();
_sdi = NULL;
{
if (_owner != NULL && _sdi != NULL)
{
File::release();
sr_dev_close(_sdi);
sr_dev_clear(_sdi->driver);
sr_session_destroy();
_sdi = NULL;
}
}
} // device

View File

@ -32,7 +32,7 @@ class SessionFile : public File
public:
SessionFile(QString path);
sr_dev_inst* dev_inst() const;
sr_dev_inst* dev_inst();
virtual void use(SigSession *owner);

View File

@ -29,15 +29,12 @@
#include <sstream>
#include <stdexcept>
#include <string>
#include <QApplication>
#include <QObject>
#include <QDebug>
#include <QDir>
#include "config/appconfig.h"
#include <boost/foreach.hpp>
using boost::shared_ptr;
using std::list;
using std::map;
using std::ostringstream;
@ -46,66 +43,72 @@ using std::string;
namespace pv {
DeviceManager::DeviceManager(struct sr_context *sr_ctx) :
_sr_ctx(sr_ctx)
DeviceManager::DeviceManager()
{
init_drivers();
scan_all_drivers();
_sr_ctx = NULL;
}
DeviceManager::DeviceManager(DeviceManager &o)
{
(void)o;
}
DeviceManager::~DeviceManager()
{
release_devices();
}
const std::list<boost::shared_ptr<device::DevInst> > &DeviceManager::devices() const
void DeviceManager::initAll(struct sr_context *sr_ctx)
{
_sr_ctx = sr_ctx;
init_drivers();
scan_all_drivers();
}
void DeviceManager::UnInitAll()
{
release_devices();
}
void DeviceManager::add_device(DevInst *device)
{
return _devices;
assert(device);
auto it = std::find(_devices.begin(), _devices.end(), device);
if (it ==_devices.end()){
_devices.push_front(device);
}
}
void DeviceManager::add_device(boost::shared_ptr<pv::device::DevInst> device)
void DeviceManager::del_device(DevInst *device)
{
assert(device);
if (std::find(_devices.begin(), _devices.end(), device) ==
_devices.end())
_devices.push_front(device);
}
void DeviceManager::del_device(boost::shared_ptr<pv::device::DevInst> device)
{
assert(device);
BOOST_FOREACH(shared_ptr<device::DevInst> dev, _devices) {
assert(dev);
if(dev == device) {
dev->release();
break;
}
auto it = std::find(_devices.begin(), _devices.end(), device);
if (it !=_devices.end()){
_devices.erase(it); //remove from list
device->destroy();
}
if (std::find(_devices.begin(), _devices.end(), device) !=
_devices.end())
_devices.remove(device);
}
std::list<boost::shared_ptr<device::DevInst> > DeviceManager::driver_scan(
struct sr_dev_driver *const driver, GSList *const drvopts)
{
list< shared_ptr<device::DevInst> > driver_devices;
void DeviceManager::driver_scan(
std::list<DevInst*> &driver_devices,
struct sr_dev_driver *const driver,
GSList *const drvopts)
{
assert(driver);
// Remove any device instances from this driver from the device
// list. They will not be valid after the scan.
list< shared_ptr<device::DevInst> >::iterator i = _devices.begin();
auto i = _devices.begin();
while (i != _devices.end()) {
if ((*i)->dev_inst() &&
(*i)->dev_inst()->driver == driver) {
if ((*i)->dev_inst() && (*i)->dev_inst()->driver == driver) {
(*i)->release();
i = _devices.erase(i);
} else {
i++;
}
}
}
// Clear all the old device instances from this driver
sr_dev_clear(driver);
@ -113,25 +116,23 @@ std::list<boost::shared_ptr<device::DevInst> > DeviceManager::driver_scan(
// Check If DSL hardware driver
if (strncmp(driver->name, "virtual", 7)) {
QDir dir(DS_RES_PATH);
QDir dir(GetResourceDir());
if (!dir.exists())
return driver_devices;
return;
}
// Do the scan
GSList *const devices = sr_driver_scan(driver, drvopts);
for (GSList *l = devices; l; l = l->next)
driver_devices.push_front(shared_ptr<device::DevInst>(
new device::Device((sr_dev_inst*)l->data)));
for (GSList *l = devices; l; l = l->next){
Device *dev = new device::Device((sr_dev_inst*)l->data); //create new device
driver_devices.push_front(dev);
}
g_slist_free(devices);
//driver_devices.sort(compare_devices);
// Add the scanned devices to the main list
_devices.insert(_devices.end(), driver_devices.begin(),
driver_devices.end());
//_devices.sort(compare_devices);
return driver_devices;
// append the scanned devices to the main list
_devices.insert(_devices.end(), driver_devices.begin(), driver_devices.end());
}
void DeviceManager::init_drivers()
@ -150,8 +151,7 @@ void DeviceManager::init_drivers()
void DeviceManager::release_devices()
{
// Release all the used devices
BOOST_FOREACH(shared_ptr<device::DevInst> dev, _devices) {
assert(dev);
for (DevInst *dev : _devices) {
dev->release();
}
@ -165,14 +165,15 @@ void DeviceManager::scan_all_drivers()
{
// Scan all drivers for all devices.
struct sr_dev_driver **const drivers = sr_driver_list();
for (struct sr_dev_driver **driver = drivers; *driver; driver++)
driver_scan(*driver);
for (struct sr_dev_driver **driver = drivers; *driver; driver++){
std::list<DevInst*> driver_devices;
driver_scan(driver_devices, *driver);
}
}
void DeviceManager::release_driver(struct sr_dev_driver *const driver)
{
BOOST_FOREACH(shared_ptr<device::DevInst> dev, _devices) {
assert(dev);
for (DevInst *dev : _devices) {
if(dev->dev_inst()->driver == driver)
dev->release();
}
@ -181,8 +182,7 @@ void DeviceManager::release_driver(struct sr_dev_driver *const driver)
sr_dev_clear(driver);
}
bool DeviceManager::compare_devices(boost::shared_ptr<device::DevInst> a,
boost::shared_ptr<device::DevInst> b)
bool DeviceManager::compare_devices(DevInst *a, DevInst *b)
{
assert(a);
assert(b);

View File

@ -29,20 +29,13 @@
#include <list>
#include <map>
#include <string>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <QObject>
#include <QString>
struct sr_context;
struct sr_dev_driver;
struct sr_dev_inst;
struct libusbhp_t;
struct libusbhp_device_t;
namespace pv {
class SigSession;
@ -51,21 +44,33 @@ namespace device {
class DevInst;
}
using namespace pv::device;
class DeviceManager
{
private:
DeviceManager(DeviceManager &o);
public:
DeviceManager(struct sr_context *sr_ctx);
DeviceManager();
~DeviceManager();
const std::list< boost::shared_ptr<pv::device::DevInst> >& devices() const;
inline const std::list<DevInst*>& devices(){
return _devices;
}
void add_device(boost::shared_ptr<pv::device::DevInst> device);
void del_device(boost::shared_ptr<pv::device::DevInst> device);
void add_device(DevInst *device);
void del_device(DevInst *device);
std::list< boost::shared_ptr<pv::device::DevInst> > driver_scan(
struct sr_dev_driver *const driver,
GSList *const drvopts = NULL);
void driver_scan(
std::list<DevInst*> &driver_devices,
struct sr_dev_driver *const driver=NULL,
GSList *const drvopts=NULL);
void initAll(struct sr_context *sr_ctx);
void UnInitAll();
private:
void init_drivers();
@ -76,12 +81,11 @@ private:
void release_driver(struct sr_dev_driver *const driver);
static bool compare_devices(boost::shared_ptr<device::DevInst> a,
boost::shared_ptr<device::DevInst> b);
static bool compare_devices(DevInst *a, DevInst *b);
private:
struct sr_context *const _sr_ctx;
std::list< boost::shared_ptr<pv::device::DevInst> > _devices;
struct sr_context* _sr_ctx;
std::list<DevInst*> _devices;
};
} // namespace pv

View File

@ -21,6 +21,8 @@
*/
#include "about.h"
#include <QPixmap>
#include <QApplication>
#include <QTextBrowser>
@ -28,9 +30,9 @@
#include <QDir>
#include <QTextStream>
#include <QScrollBar>
#include <QTextCodec>
#include "about.h"
#include "../config/appconfig.h"
#include "../dsvdef.h"
namespace pv {
namespace dialogs {
@ -74,18 +76,18 @@ About::About(QWidget *parent) :
.arg("http://sigrok.org/");
QString changlogs = tr("<font size=16>Changelogs</font><br />");
#ifndef Q_OS_LINUX
QDir dir(QCoreApplication::applicationDirPath());
#else
QDir dir(DS_RES_PATH);
dir.cdUp();
#endif
QString filename = dir.absolutePath() + "/NEWS" + QString::number(qApp->property("Language").toInt());
QDir dir(GetAppDataDir());
AppConfig &app = AppConfig::Instance();
int lan = app._frameOptions.language;
QString filename = dir.absolutePath() + "/NEWS" + QString::number(lan);
QFile news(filename);
if (news.open(QIODevice::ReadOnly)) {
QTextCodec *code=QTextCodec::codecForName("UTF-8");
QTextStream stream(&news);
stream.setCodec(code);
app::set_utf8(stream);
QString line;
while (!stream.atEnd()){
line = stream.readLine();

View File

@ -27,8 +27,7 @@
#include <QLabel>
#include "dsdialog.h"
#include <libsigrok4DSL/libsigrok.h>
namespace pv {
namespace dialogs {

View File

@ -0,0 +1,75 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2015 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 "applicationpardlg.h"
#include "dsdialog.h"
#include <QFormLayout>
#include <QCheckBox>
#include <QString>
#include "../config/appconfig.h"
namespace pv
{
namespace dialogs
{
ApplicationParamDlg::ApplicationParamDlg()
{
}
ApplicationParamDlg::~ApplicationParamDlg()
{
}
bool ApplicationParamDlg::ShowDlg(QWidget *parent)
{
DSDialog dlg(parent, true, true);
dlg.setTitle("Application options");
dlg.setMinimumSize(300, 200);
QFormLayout &lay = *(new QFormLayout());
lay.setContentsMargins(0,20,0,30);
//show config
AppConfig &app = AppConfig::Instance();
QCheckBox *ck_quickScroll = new QCheckBox();
ck_quickScroll->setChecked(app._appOptions.quickScroll);
lay.addRow("Quick scroll", ck_quickScroll);
dlg.layout()->addLayout(&lay);
dlg.exec();
bool ret = dlg.IsClickYes();
//save config
if (ret){
app._appOptions.quickScroll = ck_quickScroll->isChecked();
app.SaveApp();
}
return ret;
}
} //
}//

View File

@ -0,0 +1,50 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2015 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
*/
#pragma once
#include <QObject>
#include <QWidget>
namespace pv
{
namespace dialogs
{
class ApplicationParamDlg
{
// Q_OBJECT
public:
ApplicationParamDlg();
~ApplicationParamDlg();
bool ShowDlg(QWidget *parent);
//IDlgCallback
private:
void OnDlgResult(bool bYes);
};
}//
}//

View File

@ -20,9 +20,7 @@
*/
#include "calibration.h"
#include <boost/foreach.hpp>
#include <QGridLayout>
#include <QFuture>
#include <QProgressDialog>
@ -31,8 +29,9 @@
#include "../view/trace.h"
#include "../dialogs/dsmessagebox.h"
#include "../dsvdef.h"
using namespace boost;
using namespace std;
namespace pv {
@ -44,7 +43,13 @@ const QString Calibration::VCOMB = QT_TR_NOOP(" VCOMB");
Calibration::Calibration(QWidget *parent) :
DSDialog(parent)
{
{
_save_btn = NULL;
_abort_btn = NULL;
_reset_btn = NULL;
_exit_btn = NULL;
_flayout = NULL;
#ifdef Q_OS_DARWIN
Qt::WindowFlags flags = windowFlags();
this->setWindowFlags(flags | Qt::Tool);
@ -89,6 +94,14 @@ Calibration::Calibration(QWidget *parent) :
retranslateUi();
}
Calibration::~Calibration(){
DESTROY_QT_OBJECT(_save_btn);
DESTROY_QT_OBJECT(_abort_btn);
DESTROY_QT_OBJECT(_reset_btn);
DESTROY_QT_OBJECT(_exit_btn);
DESTROY_QT_OBJECT(_flayout);
}
void Calibration::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
@ -106,7 +119,7 @@ void Calibration::retranslateUi()
setTitle(tr("Manual Calibration"));
}
void Calibration::set_device(boost::shared_ptr<device::DevInst> dev_inst)
void Calibration::set_device(DevInst *dev_inst)
{
assert(dev_inst);
_dev_inst = dev_inst;

View File

@ -29,13 +29,14 @@
#include <QFormLayout>
#include <QSlider>
#include <list>
#include <boost/shared_ptr.hpp>
#include <list>
#include <pv/device/devinst.h>
#include "../device/devinst.h"
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
using namespace pv::device;
namespace pv {
namespace dialogs {
@ -50,8 +51,9 @@ private:
public:
Calibration(QWidget *parent);
~Calibration();
void set_device(boost::shared_ptr<pv::device::DevInst> dev_inst);
void set_device(DevInst *dev_inst);
protected:
void accept();
void reject();
@ -68,9 +70,8 @@ private slots:
void reload_value();
private:
boost::shared_ptr<pv::device::DevInst> _dev_inst;
toolbars::TitleBar *_titlebar;
DevInst *_dev_inst;
QPushButton *_save_btn;
QPushButton *_abort_btn;
QPushButton *_reset_btn;

View File

@ -21,29 +21,32 @@
*/
#include "deviceoptions.h"
#include <boost/foreach.hpp>
#include <QListWidget>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include "dsmessagebox.h"
#include <pv/prop/property.h>
#include "../prop/property.h"
#include "../dsvdef.h"
using namespace boost;
using namespace std;
namespace pv {
namespace dialogs {
DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptr<pv::device::DevInst> dev_inst) :
DeviceOptions::DeviceOptions(QWidget *parent, DevInst *dev_inst) :
DSDialog(parent),
_dev_inst(dev_inst),
_button_box(QDialogButtonBox::Ok,
Qt::Horizontal, this),
_button_box(QDialogButtonBox::Ok, Qt::Horizontal, this),
_device_options_binding(_dev_inst->dev_inst())
{
_dynamic_box = NULL;
_props_box = NULL;
_config_button = NULL;
_cali_button = NULL;
_props_box = new QGroupBox(tr("Mode"), this);
_props_box->setLayout(get_property_form(_props_box));
_layout.addWidget(_props_box);
@ -52,7 +55,7 @@ DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptr<pv::device::DevI
this);
_dynamic_box->setLayout(&_dynamic_layout);
_layout.addWidget(_dynamic_box);
_dynamic_box->setVisible(_dynamic_box->title() != NULL);
_dynamic_box->setVisible(_dynamic_box->title() != "");
_layout.addStretch(1);
_layout.addWidget(&_button_box);
@ -62,7 +65,7 @@ DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptr<pv::device::DevI
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
//connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(_dev_inst.get(), SIGNAL(device_updated()), this, SLOT(reject()));
connect(_dev_inst, SIGNAL(device_updated()), this, SLOT(reject()));
GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_OPERATION_MODE);
if (gvar != NULL) {
@ -74,15 +77,21 @@ DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptr<pv::device::DevI
_mode_check.start();
}
DeviceOptions::~DeviceOptions(){
DESTROY_QT_OBJECT(_dynamic_box);
DESTROY_QT_OBJECT(_props_box);
DESTROY_QT_OBJECT(_config_button);
DESTROY_QT_OBJECT(_cali_button);
}
void DeviceOptions::accept()
{
using namespace Qt;
bool hasEnabled = false;
// Commit the properties
const vector< boost::shared_ptr<pv::prop::Property> > &dev_props =
_device_options_binding.properties();
BOOST_FOREACH(boost::shared_ptr<pv::prop::Property> p, dev_props) {
const auto &dev_props = _device_options_binding.properties();
for(auto &p : dev_props) {
assert(p);
p->commit();
}
@ -106,9 +115,9 @@ void DeviceOptions::accept()
if (hasEnabled) {
QVector<pv::prop::binding::ProbeOptions *>::iterator i = _probe_options_binding_list.begin();
while(i != _probe_options_binding_list.end()) {
const vector< boost::shared_ptr<pv::prop::Property> > &probe_props =
(*i)->properties();
BOOST_FOREACH(boost::shared_ptr<pv::prop::Property> p, probe_props) {
const auto &probe_props = (*i)->properties();
for(auto &p :probe_props) {
assert(p);
p->commit();
}
@ -138,10 +147,10 @@ QGridLayout * DeviceOptions::get_property_form(QWidget * parent)
QGridLayout *const layout = new QGridLayout(parent);
layout->setVerticalSpacing(5);
const vector< boost::shared_ptr<pv::prop::Property> > &properties =
_device_options_binding.properties();
const auto &properties =_device_options_binding.properties();
int i = 0;
BOOST_FOREACH(boost::shared_ptr<pv::prop::Property> p, properties)
for(auto &p : properties)
{
assert(p);
const QString label = p->labeled_widget() ? QString() : p->label();
@ -337,7 +346,7 @@ void DeviceOptions::mode_check()
if (mode != _mode) {
dynamic_widget(_dynamic_layout);
_dynamic_box->setVisible(_dynamic_box->title() != NULL);
_dynamic_box->setVisible(_dynamic_box->title() != "");
_mode = mode;
}
}
@ -366,7 +375,7 @@ void DeviceOptions::channel_check()
if(sc != NULL)
_dev_inst->set_config(NULL, NULL, SR_CONF_CHANNEL_MODE, g_variant_new_string(text.toUtf8().data()));
dynamic_widget(_dynamic_layout);
_dynamic_box->setVisible(_dynamic_box->title() != NULL);
_dynamic_box->setVisible(_dynamic_box->title() != "");
}
void DeviceOptions::analog_channel_check()
@ -382,7 +391,7 @@ void DeviceOptions::analog_channel_check()
}
}
dynamic_widget(_dynamic_layout);
_dynamic_box->setVisible(_dynamic_box->title() != NULL);
_dynamic_box->setVisible(_dynamic_box->title() != "");
}
void DeviceOptions::channel_enable()
@ -512,10 +521,10 @@ void DeviceOptions::analog_probes(QGridLayout &layout)
pv::prop::binding::ProbeOptions *probe_options_binding =
new pv::prop::binding::ProbeOptions(_dev_inst->dev_inst(), probe);
const vector< boost::shared_ptr<pv::prop::Property> > &properties =
probe_options_binding->properties();
const auto &properties = probe_options_binding->properties();
int i = 1;
BOOST_FOREACH(boost::shared_ptr<pv::prop::Property> p, properties)
for(auto &p : properties)
{
assert(p);
const QString label = p->labeled_widget() ? QString() : p->label();

View File

@ -34,11 +34,8 @@
#include <QVector>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>
#include <QRadioButton>
#include <QTimer>
#include <boost/shared_ptr.hpp>
#include <QTimer>
#include <libsigrok4DSL/libsigrok.h>
#include "../device/devinst.h"
@ -46,6 +43,9 @@
#include "../prop/binding/probeoptions.h"
#include "../toolbars/titlebar.h"
#include "../dialogs/dsdialog.h"
#include "../ui/dscombobox.h"
using namespace pv::device;
namespace pv {
namespace dialogs {
@ -55,7 +55,9 @@ class DeviceOptions : public DSDialog
Q_OBJECT
public:
DeviceOptions(QWidget *parent, boost::shared_ptr<pv::device::DevInst> dev_inst);
DeviceOptions(QWidget *parent, DevInst *dev_inst);
~DeviceOptions();
protected:
void accept();
@ -83,9 +85,8 @@ private slots:
void channel_enable();
private:
boost::shared_ptr<pv::device::DevInst> _dev_inst;
QVBoxLayout _layout;
toolbars::TitleBar *_titlebar;
DevInst *_dev_inst;
QVBoxLayout _layout;
QGroupBox *_dynamic_box;
QGridLayout _dynamic_layout;

View File

@ -28,118 +28,131 @@
#include <QMouseEvent>
#include <QVBoxLayout>
#include <QAbstractButton>
#include "../dsvdef.h"
namespace pv {
namespace dialogs {
DSDialog::DSDialog(QWidget *parent, bool hasClose) :
QDialog(parent),
_moving(false)
DSDialog::DSDialog() : DSDialog(NULL, false, false)
{
}
DSDialog::DSDialog(QWidget *parent): DSDialog(parent, false, false)
{
}
DSDialog::DSDialog(QWidget *parent, bool hasClose): DSDialog(parent, hasClose, false)
{
}
DSDialog::DSDialog(QWidget *parent, bool hasClose, bool bBaseButton) :
QDialog(NULL), //must be null, otherwise window can not able to move
m_bBaseButton(bBaseButton)
{
(void)parent;
_base_layout = NULL;
_main_layout = NULL;
_main_widget = NULL;
_titlebar = NULL;
_shadow = NULL;
_base_button = NULL;
m_callback = NULL;
_clickYes = false;
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
setAttribute(Qt::WA_TranslucentBackground);
build_main(hasClose);
build_base(hasClose);
}
_layout = new QVBoxLayout(this);
_layout->addWidget(_main);
setLayout(_layout);
DSDialog::~DSDialog()
{
DESTROY_QT_OBJECT(_base_layout);
DESTROY_QT_OBJECT(_main_layout);
DESTROY_QT_OBJECT(_main_widget);
DESTROY_QT_OBJECT(_titlebar);
DESTROY_QT_OBJECT(_shadow);
DESTROY_QT_OBJECT(_base_button);
}
void DSDialog::accept()
{
using namespace Qt;
{
_clickYes = true;
if (m_callback){
m_callback->OnDlgResult(true);
}
QDialog::accept();
}
void DSDialog::reject()
{
using namespace Qt;
{
_clickYes = false;
if (m_callback){
m_callback->OnDlgResult(false);
}
QDialog::reject();
}
bool DSDialog::eventFilter(QObject *object, QEvent *event)
{
(void)object;
const QEvent::Type type = event->type();
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if (type == QEvent::MouseMove) {
if (_moving && mouse_event->buttons().testFlag(Qt::LeftButton)) {
move(mouse_event->globalPos() - _startPos);
}
return true;
} else if (type == QEvent::MouseButtonPress) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = true;
#ifndef _WIN32
_startPos = mouse_event->pos() +
QPoint(_layout->margin(), _layout->margin()) +
QPoint(_layout->spacing(), _layout->spacing()) +
QPoint(_mlayout->margin(), _mlayout->margin()) +
QPoint(_mlayout->spacing(), _mlayout->spacing());
#else
_startPos = mouse_event->pos() +
QPoint(_layout->margin(), _layout->margin()) +
QPoint(_layout->spacing(), _layout->spacing());
#endif
}
} else if (type == QEvent::MouseButtonRelease) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = false;
}
}
return false;
}
QVBoxLayout* DSDialog::layout()
{
return _mlayout;
}
QWidget* DSDialog::mainWidget()
{
return _main;
}
void DSDialog::setTitle(QString title)
{
_titlebar->setTitle(title);
if (_titlebar){
_titlebar->setTitle(title);
}
}
void DSDialog::reload(bool hasClose)
void DSDialog::reload()
{
QString title;
if (_titlebar)
title = _titlebar->title();
if (_main)
delete _main;
build_main(hasClose);
_titlebar->setTitle(title);
_layout->addWidget(_main);
show();
}
void DSDialog::build_main(bool hasClose)
{
_main = new QWidget(this);
_mlayout = new QVBoxLayout(_main);
_main->setLayout(_mlayout);
//_mlayout->setMargin(5);
//_mlayout->setSpacing(5);
int DSDialog::exec()
{
//ok,cancel
if (m_bBaseButton){
_base_button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal, this);
_main_layout->addWidget(_base_button);//, 5, 1, 1, 1, Qt::AlignHCenter | Qt::AlignBottom);
//_main_layout->addWidget(_base_button,0, Qt::AlignHCenter | Qt::AlignBottom);
connect(_base_button, SIGNAL(rejected()), this, SLOT(reject()));
connect(_base_button, SIGNAL(accepted()), this, SLOT(accept()));
}
return QDialog::exec();
}
Shadow *bodyShadow = new Shadow(_main);
bodyShadow->setBlurRadius(10.0);
bodyShadow->setDistance(3.0);
bodyShadow->setColor(QColor(0, 0, 0, 80));
_main->setAutoFillBackground(true);
_main->setGraphicsEffect(bodyShadow);
void DSDialog::build_base(bool hasClose)
{
_main_widget = new QWidget(this);
_main_layout = new QVBoxLayout(_main_widget);
_main_widget->setLayout(_main_layout);
_shadow = new Shadow(this);
_shadow->setBlurRadius(10.0);
_shadow->setDistance(3.0);
_shadow->setColor(QColor(0, 0, 0, 80));
_main_widget->setAutoFillBackground(true);
this->setGraphicsEffect(_shadow);
_titlebar = new toolbars::TitleBar(false, this, hasClose);
_titlebar->installEventFilter(this);
_mlayout->addWidget(_titlebar);
}
_main_layout->addWidget(_titlebar);
QWidget *space = new QWidget(this);
space->setFixedHeight(15);
_main_layout->addWidget(space);
_base_layout = new QVBoxLayout(this);
_base_layout->addWidget(_main_widget);
setLayout(_base_layout);
_main_layout->setAlignment(Qt::AlignCenter | Qt::AlignTop);
_main_layout->setContentsMargins(10,5,10,10);
}
} // namespace dialogs
} // namespace pv

View File

@ -26,40 +26,58 @@
#include <QDialog>
#include <QWidget>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include "../toolbars/titlebar.h"
#include "../interface/uicallback.h"
class QDialogButtonBox;
namespace pv {
namespace dialogs {
class Shadow;
//DSView any dialog base class
class DSDialog : public QDialog
{
Q_OBJECT
public:
DSDialog(QWidget *parent = 0, bool hasClose = false);
QVBoxLayout *layout();
QWidget *mainWidget();
DSDialog();
DSDialog(QWidget *parent);
DSDialog(QWidget *parent, bool hasClose);
DSDialog(QWidget *parent, bool hasClose, bool bBaseButton);
~DSDialog();
inline void SetCallback(IDlgCallback *callback){m_callback = callback;}
inline QVBoxLayout *layout(){return _main_layout;}
void setTitle(QString title);
void reload(bool hasClose);
void reload();
int exec();
inline bool IsClickYes(){return _clickYes;}
protected:
void accept();
void reject();
//void mousePressEvent(QMouseEvent *event);
//void mouseReleaseEvent(QMouseEvent *event);
bool eventFilter(QObject *object, QEvent *event);
private:
void build_main(bool hasClose);
private:
QVBoxLayout *_layout;
QVBoxLayout *_mlayout;
QWidget *_main;
toolbars::TitleBar *_titlebar;
bool _moving;
QPoint _startPos;
void build_base(bool hasClose);
private:
QVBoxLayout *_base_layout;
QWidget *_main_widget;
QVBoxLayout *_main_layout;
toolbars::TitleBar *_titlebar;
Shadow *_shadow;
QDialogButtonBox *_base_button;
QPoint _startPos;
bool m_bBaseButton;
bool _clickYes;
IDlgCallback *m_callback;
};
} // namespace dialogs

View File

@ -28,45 +28,72 @@
#include <QMouseEvent>
#include <QVBoxLayout>
#include <QAbstractButton>
#include "../dsvdef.h"
namespace pv {
namespace dialogs {
DSMessageBox::DSMessageBox(QWidget *parent) :
QDialog(parent),
_moving(false)
DSMessageBox::DSMessageBox(QWidget *parent,const char *title) :
QDialog(NULL) //must be null, otherwise window can not able to move
{
(void)parent;
_layout = NULL;
_main_widget = NULL;
_msg = NULL;
_titlebar = NULL;
_shadow = NULL;
_main_layout = NULL;
_bClickYes = false;
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
setAttribute(Qt::WA_TranslucentBackground);
_main = new QWidget(this);
QVBoxLayout *mlayout = new QVBoxLayout(_main);
_main->setLayout(mlayout);
Shadow *bodyShadow = new Shadow();
bodyShadow->setBlurRadius(10.0);
bodyShadow->setDistance(3.0);
bodyShadow->setColor(QColor(0, 0, 0, 80));
_main->setAutoFillBackground(true);
_main->setGraphicsEffect(bodyShadow);
_main_widget = new QWidget(this);
_main_layout = new QVBoxLayout(_main_widget);
_main_widget->setLayout(_main_layout);
_shadow = new Shadow(this);
_msg = new QMessageBox(this);
_msg->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
_titlebar = new toolbars::TitleBar(false, this);
_titlebar->setTitle(tr("Message"));
_titlebar->installEventFilter(this);
mlayout->addWidget(_titlebar);
mlayout->addWidget(_msg);
_layout = new QVBoxLayout(this);
_layout->addWidget(_main);
setLayout(_layout);
_shadow->setBlurRadius(10.0);
_shadow->setDistance(3.0);
_shadow->setColor(QColor(0, 0, 0, 80));
_main_widget->setAutoFillBackground(true);
this->setGraphicsEffect(_shadow);
_msg->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
if (title){
_titlebar->setTitle(QString(title));
}
else{
_titlebar->setTitle(tr("Message"));
}
_main_layout->addWidget(_titlebar);
_main_layout->addWidget(_msg);
_layout->addWidget(_main_widget);
setLayout(_layout);
//connect(_msg, SIGNAL(finished(int)), this, SLOT(accept()));
connect(_msg, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(on_button(QAbstractButton*)));
}
DSMessageBox::~DSMessageBox()
{
DESTROY_QT_OBJECT(_layout);
DESTROY_QT_OBJECT(_main_widget);
DESTROY_QT_OBJECT(_msg);
DESTROY_QT_OBJECT(_titlebar);
DESTROY_QT_OBJECT(_shadow);
DESTROY_QT_OBJECT(_main_layout);
}
void DSMessageBox::accept()
{
using namespace Qt;
@ -80,48 +107,20 @@ void DSMessageBox::reject()
QDialog::reject();
}
bool DSMessageBox::eventFilter(QObject *object, QEvent *event)
{
(void)object;
const QEvent::Type type = event->type();
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if (type == QEvent::MouseMove) {
if (_moving && mouse_event->buttons().testFlag(Qt::LeftButton)) {
move(mouse_event->globalPos() - _startPos);
}
return true;
} else if (type == QEvent::MouseButtonPress) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = true;
_startPos = mouse_event->pos() +
QPoint(_layout->margin(), _layout->margin()) +
QPoint(_layout->spacing(), _layout->spacing());
}
} else if (type == QEvent::MouseButtonRelease) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = false;
}
}
return false;
}
QMessageBox* DSMessageBox::mBox()
{
return _msg;
}
int DSMessageBox::exec()
{
//_msg->show();
return QDialog::exec();
}
void DSMessageBox::on_button(QAbstractButton *btn)
{
QMessageBox::ButtonRole role = _msg->buttonRole(btn);
if (role == QMessageBox::AcceptRole)
accept();
if (role == QMessageBox::AcceptRole || role == QMessageBox::YesRole){
_bClickYes = true;
accept();
}
else
reject();
}

View File

@ -33,33 +33,38 @@
namespace pv {
namespace dialogs {
class Shadow;
class DSMessageBox : public QDialog
{
Q_OBJECT
public:
DSMessageBox(QWidget *parent);
QMessageBox *mBox();
DSMessageBox(QWidget *parent, const char *title=0);
int exec();
~DSMessageBox();
QMessageBox *mBox();
inline int IsYes(){return _bClickYes;}
protected:
void accept();
void reject();
//void mousePressEvent(QMouseEvent *event);
//void mouseReleaseEvent(QMouseEvent *event);
bool eventFilter(QObject *object, QEvent *event);
void reject();
private slots:
void on_button(QAbstractButton* btn);
private:
QVBoxLayout *_layout;
QWidget *_main;
QMessageBox *_msg;
toolbars::TitleBar *_titlebar;
bool _moving;
QPoint _startPos;
QVBoxLayout *_layout;
QVBoxLayout *_main_layout;
QWidget *_main_widget;
QMessageBox *_msg;
toolbars::TitleBar *_titlebar;
Shadow *_shadow;
QPoint _startPos;
bool _bClickYes;
};
} // namespace dialogs

View File

@ -29,8 +29,8 @@
#include <QLabel>
#include <QTabBar>
#include <QBitmap>
#include <boost/foreach.hpp>
#include "../dsvdef.h"
using namespace boost;
using namespace std;
@ -39,7 +39,7 @@ using namespace pv::view;
namespace pv {
namespace dialogs {
DsoMeasure::DsoMeasure(SigSession &session, View &parent,
DsoMeasure::DsoMeasure(SigSession *session, View &parent,
unsigned int position, int last_sig_index) :
DSDialog((QWidget *)&parent),
_session(session),
@ -48,15 +48,17 @@ DsoMeasure::DsoMeasure(SigSession &session, View &parent,
_button_box(QDialogButtonBox::Reset | QDialogButtonBox::Cancel,
Qt::Horizontal, this)
{
_measure_tab = NULL;
setMinimumSize(500, 400);
_measure_tab = new QTabWidget(this);
_measure_tab->setTabPosition(QTabWidget::West);
_measure_tab->setUsesScrollButtons(false);
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)) && dsoSig->enabled()) {
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s)) && dsoSig->enabled()) {
QWidget *measure_widget = new QWidget(this);
this->add_measure(measure_widget, dsoSig);
_measure_tab->addTab(measure_widget, QString::number(dsoSig->get_index()));
@ -76,23 +78,29 @@ DsoMeasure::DsoMeasure(SigSession &session, View &parent,
connect(_button_box.button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
connect(_button_box.button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(reset()));
connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject()));
connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject()));
}
void DsoMeasure::add_measure(QWidget *widget, const boost::shared_ptr<view::DsoSignal> dsoSig)
DsoMeasure::~DsoMeasure(){
DESTROY_QT_OBJECT(_measure_tab);
}
void DsoMeasure::add_measure(QWidget *widget, const view::DsoSignal *dsoSig)
{
const int Column = 5;
const int IconSizeForText = 5;
QGridLayout *layout = new QGridLayout(widget);
layout->setMargin(0);
layout->setSpacing(0);
pv::view::DsoSignal *psig = const_cast<pv::view::DsoSignal*>(dsoSig);
for (int i=DSO_MS_BEGIN+1; i<DSO_MS_END; i++) {
QToolButton *button = new QToolButton(this);
button->setProperty("id", QVariant(i));
button->setIconSize(QSize(48, 48));
QPixmap msPix(get_ms_icon(i));
QBitmap msMask = msPix.createMaskFromColor(QColor("black"), Qt::MaskOutColor);
msPix.fill(dsoSig->get_colour());
msPix.fill(psig->get_colour());
msPix.setMask(msMask);
button->setIcon(QIcon(msPix));
layout->addWidget(button,
@ -150,9 +158,10 @@ void DsoMeasure::accept()
if(sc != NULL) {
QVariant id = sc->property("id");
enum DSO_MEASURE_TYPE ms_type = DSO_MEASURE_TYPE(id.toInt());
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig = NULL;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
if (_measure_tab->currentWidget()->property("index").toInt() == dsoSig->get_index()) {
_view.get_viewstatus()->set_measure(_position, false, dsoSig->get_index(), ms_type);
break;

View File

@ -27,8 +27,7 @@
#include <QToolButton>
#include <QDialogButtonBox>
#include <QTabWidget>
#include <boost/shared_ptr.hpp>
#include "../view/dsosignal.h"
#include "../toolbars/titlebar.h"
@ -49,14 +48,15 @@ class DsoMeasure : public DSDialog
Q_OBJECT
public:
DsoMeasure(SigSession &session, view::View &parent,
unsigned int position, int last_sig_index);
DsoMeasure(SigSession *session, view::View &parent, unsigned int position, int last_sig_index);
~DsoMeasure();
static QString get_ms_icon(int ms_type);
static QString get_ms_text(int ms_type);
private:
void add_measure(QWidget *widget, const boost::shared_ptr<view::DsoSignal> dsoSig);
void add_measure(QWidget *widget, const view::DsoSignal *dsoSig);
private slots:
void set_measure(bool en);
@ -67,15 +67,13 @@ protected:
void reject();
private:
SigSession &_session;
SigSession *_session;
view::View &_view;
unsigned int _position;
toolbars::TitleBar *_titlebar;
QDialogButtonBox _button_box;
QTabWidget *_measure_tab;
QVBoxLayout _layout;
std::vector<QToolButton *> _mbtn_vec;
QVBoxLayout _layout;
};
} // namespace dialogs

View File

@ -21,50 +21,64 @@
#include "fftoptions.h"
#include <boost/foreach.hpp>
#include <QFormLayout>
#include <QListWidget>
#include <QDebug>
#include "../sigsession.h"
#include "../data/spectrumstack.h"
#include "../view/trace.h"
#include "../view/dsosignal.h"
#include "../view/spectrumtrace.h"
#include "../dsvdef.h"
using namespace boost;
using namespace std;
namespace pv {
namespace dialogs {
FftOptions::FftOptions(QWidget *parent, SigSession &session) :
FftOptions::FftOptions(QWidget *parent, SigSession *session) :
DSDialog(parent),
_session(session),
_button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, this)
{
_len_combobox = NULL;
_interval_combobox = NULL;
_en_checkbox = NULL;
_ch_combobox = NULL;
_window_combobox = NULL;
_dc_checkbox = NULL;
_view_combobox = NULL;
_dbv_combobox = NULL;
_hint_label = NULL;
_glayout = NULL;
_layout = NULL;
_en_checkbox = new QCheckBox(this);
_len_combobox = new QComboBox(this);
_interval_combobox = new QComboBox(this);
_ch_combobox = new QComboBox(this);
_window_combobox = new QComboBox(this);
_len_combobox = new DsComboBox(this);
_interval_combobox = new DsComboBox(this);
_ch_combobox = new DsComboBox(this);
_window_combobox = new DsComboBox(this);
_dc_checkbox = new QCheckBox(this);
_dc_checkbox->setChecked(true);
_view_combobox = new QComboBox(this);
_dbv_combobox = new QComboBox(this);
_view_combobox = new DsComboBox(this);
_dbv_combobox = new DsComboBox(this);
// setup _ch_combobox
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig = NULL;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
_ch_combobox->addItem(dsoSig->get_name(), QVariant::fromValue(dsoSig->get_index()));
}
}
// setup _window_combobox _len_combobox
_sample_limit = 0;
GVariant* gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLELIMITS);
GVariant* gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLELIMITS);
if (gvar != NULL) {
_sample_limit = g_variant_get_uint64(gvar) * 0.5;
g_variant_unref(gvar);
@ -75,9 +89,10 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) :
std::vector<uint64_t> length;
std::vector<QString> view_modes;
std::vector<int> dbv_ranges;
BOOST_FOREACH(const boost::shared_ptr<view::Trace> t, _session.get_spectrum_traces()) {
boost::shared_ptr<view::SpectrumTrace> spectrumTraces;
if ((spectrumTraces = dynamic_pointer_cast<view::SpectrumTrace>(t))) {
for(auto &t : _session->get_spectrum_traces()) {
view::SpectrumTrace *spectrumTraces = NULL;
if ((spectrumTraces = dynamic_cast<view::SpectrumTrace*>(t))) {
windows = spectrumTraces->get_spectrum_stack()->get_windows_support();
length = spectrumTraces->get_spectrum_stack()->get_length_support();
view_modes = spectrumTraces->get_view_modes_support();
@ -125,9 +140,9 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) :
}
// load current settings
BOOST_FOREACH(const boost::shared_ptr<view::Trace> t, _session.get_spectrum_traces()) {
boost::shared_ptr<view::SpectrumTrace> spectrumTraces;
if ((spectrumTraces = dynamic_pointer_cast<view::SpectrumTrace>(t))) {
for(auto &t : _session->get_spectrum_traces()) {
view::SpectrumTrace *spectrumTraces = NULL;
if ((spectrumTraces = dynamic_cast<view::SpectrumTrace*>(t))) {
if (spectrumTraces->enabled()) {
_en_checkbox->setChecked(true);
for (int i = 0; i < _ch_combobox->count(); i++) {
@ -173,7 +188,7 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) :
QPixmap pixmap(hint_pic);
_hint_label->setPixmap(pixmap);
_glayout = new QGridLayout();
_glayout = new QGridLayout(); //QGridLayout
_glayout->setVerticalSpacing(5);
_glayout->addWidget(new QLabel(tr("FFT Enable: "), this), 0, 0);
_glayout->addWidget(_en_checkbox, 0, 1);
@ -203,9 +218,13 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) :
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(_window_combobox, SIGNAL(currentIndexChanged(QString)), this, SLOT(window_changed(QString)));
connect(_window_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(window_changed(int)));
connect(_len_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(len_changed(int)));
connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject()));
connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject()));
}
FftOptions::~FftOptions(){
}
void FftOptions::accept()
@ -214,9 +233,9 @@ void FftOptions::accept()
QDialog::accept();
BOOST_FOREACH(const boost::shared_ptr<view::Trace> t, _session.get_spectrum_traces()) {
boost::shared_ptr<view::SpectrumTrace> spectrumTraces;
if ((spectrumTraces = dynamic_pointer_cast<view::SpectrumTrace>(t))) {
for(auto &t : _session->get_spectrum_traces()) {
view::SpectrumTrace *spectrumTraces = NULL;
if ((spectrumTraces = dynamic_cast<view::SpectrumTrace*>(t))) {
spectrumTraces->set_enable(false);
if (spectrumTraces->get_index() == _ch_combobox->currentData().toInt()) {
spectrumTraces->get_spectrum_stack()->set_dc_ignore(_dc_checkbox->isChecked());
@ -227,13 +246,13 @@ void FftOptions::accept()
//spectrumTraces->init_zoom();
spectrumTraces->set_dbv_range(_dbv_combobox->currentData().toInt());
spectrumTraces->set_enable(_en_checkbox->isChecked());
if (_session.get_capture_state() == SigSession::Stopped &&
if (_session->get_capture_state() == SigSession::Stopped &&
spectrumTraces->enabled())
spectrumTraces->get_spectrum_stack()->calc_fft();
}
}
}
_session.spectrum_rebuild();
_session->spectrum_rebuild();
}
void FftOptions::reject()
@ -243,8 +262,9 @@ void FftOptions::reject()
QDialog::reject();
}
void FftOptions::window_changed(QString str)
void FftOptions::window_changed(int index)
{
QString str = _window_combobox->itemText(index);
QString hint_pic= ":/icons/" + str +".png";
QPixmap pixmap(hint_pic);
_hint_label->setPixmap(pixmap);

View File

@ -27,14 +27,13 @@
#include <QFormLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>
#include <boost/shared_ptr.hpp>
#include <QCheckBox>
#include "../device/devinst.h"
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../ui/dscombobox.h"
namespace pv {
@ -50,29 +49,30 @@ private:
public:
FftOptions(QWidget *parent, SigSession &session);
FftOptions(QWidget *parent, SigSession *session);
~FftOptions();
protected:
void accept();
void reject();
private slots:
void window_changed(QString str);
void window_changed(int index);
void len_changed(int index);
private:
SigSession &_session;
SigSession *_session;
uint64_t _sample_limit;
toolbars::TitleBar *_titlebar;
QComboBox *_len_combobox;
QComboBox *_interval_combobox;
DsComboBox *_len_combobox;
DsComboBox *_interval_combobox;
QCheckBox *_en_checkbox;
QComboBox *_ch_combobox;
QComboBox *_window_combobox;
DsComboBox *_ch_combobox;
DsComboBox *_window_combobox;
QCheckBox *_dc_checkbox;
QComboBox *_view_combobox;
QComboBox *_dbv_combobox;
DsComboBox *_view_combobox;
DsComboBox *_dbv_combobox;
QLabel *_hint_label;
QGridLayout *_glayout;

View File

@ -26,12 +26,17 @@
namespace pv {
namespace dialogs {
Interval::Interval(SigSession &session, QWidget *parent) :
Interval::Interval(SigSession *session, QWidget *parent) :
DSDialog(parent),
_session(session),
_button_box(QDialogButtonBox::Ok,
Qt::Horizontal, this)
{
_interval_label = NULL;
_interval_spinBox = NULL;
_interval_slider = NULL;
setMinimumWidth(300);
_interval_label = new QLabel(tr("Interval(s): "), this);
_interval_spinBox = new QSpinBox(this);
@ -42,7 +47,7 @@ Interval::Interval(SigSession &session, QWidget *parent) :
connect(_interval_slider, SIGNAL(valueChanged(int)), _interval_spinBox, SLOT(setValue(int)));
connect(_interval_spinBox, SIGNAL(valueChanged(int)), _interval_slider, SLOT(setValue(int)));
_interval_slider->setValue(_session.get_repeat_intvl());
_interval_slider->setValue(_session->get_repeat_intvl());
QGridLayout *glayout = new QGridLayout(this);
glayout->addWidget(_interval_label, 0, 0);
@ -59,7 +64,7 @@ Interval::Interval(SigSession &session, QWidget *parent) :
void Interval::accept()
{
using namespace Qt;
_session.set_repeat_intvl(_interval_slider->value());
_session->set_repeat_intvl(_interval_slider->value());
QDialog::accept();
}

View File

@ -40,14 +40,14 @@ class Interval : public DSDialog
Q_OBJECT
public:
Interval(SigSession &session, QWidget *parent);
Interval(SigSession *session, QWidget *parent);
protected:
void accept();
void reject();
private:
SigSession &_session;
SigSession *_session;
QLabel *_interval_label;
QSpinBox *_interval_spinBox;

View File

@ -30,9 +30,9 @@
#include <QLabel>
#include <QTabBar>
#include <QBitmap>
#include <math.h>
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
using namespace pv::view;
@ -40,12 +40,18 @@ using namespace pv::view;
namespace pv {
namespace dialogs {
LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) :
LissajousOptions::LissajousOptions(SigSession *session, QWidget *parent) :
DSDialog(parent),
_session(session),
_button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, this)
{
_enable = NULL;
_x_group = NULL;
_y_group = NULL;
_percent = NULL;
_layout = NULL;
setMinimumSize(300, 300);
_enable = new QCheckBox(this);
@ -56,8 +62,8 @@ LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) :
_percent = new QSlider(Qt::Horizontal, this);
_percent->setRange(100, 100);
_percent->setEnabled(false);
if (_session.cur_samplelimits() > WellLen) {
int min = ceil(WellLen*100.0/_session.cur_samplelimits());
if (_session->cur_samplelimits() > WellLen) {
int min = ceil(WellLen*100.0/_session->cur_samplelimits());
_percent->setEnabled(true);
_percent->setRange(min, 100);
_percent->setValue(min);
@ -67,9 +73,10 @@ LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) :
_y_group = new QGroupBox(this);
QHBoxLayout *xlayout = new QHBoxLayout();
QHBoxLayout *ylayout = new QHBoxLayout();
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig = NULL;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
QString index_str = QString::number(dsoSig->get_index());
QRadioButton *xradio = new QRadioButton(index_str, _x_group);
xradio->setProperty("index", dsoSig->get_index());
@ -85,7 +92,7 @@ LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) :
_y_group->setLayout(ylayout);
boost::shared_ptr<LissajousTrace> lissajous = _session.get_lissajous_trace();
auto lissajous = _session->get_lissajous_trace();
if (lissajous) {
_enable->setChecked(lissajous->enabled());
_percent->setValue(lissajous->percent());
@ -118,7 +125,6 @@ LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) :
}
_layout = new QGridLayout();
_layout->setMargin(0);
_layout->setSpacing(0);
_layout->addWidget(lisa_label, 0, 0, 1, 2, Qt::AlignCenter);
_layout->addWidget(_enable, 1, 0, 1, 1);
@ -173,15 +179,15 @@ void LissajousOptions::accept()
}
}
bool enable = (xindex != -1 && yindex != -1 && _enable->isChecked());
_session.lissajous_rebuild(enable, xindex, yindex, _percent->value());
_session->lissajous_rebuild(enable, xindex, yindex, _percent->value());
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig = NULL;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
dsoSig->set_show(!enable);
}
}
boost::shared_ptr<view::MathTrace> mathTrace = _session.get_math_trace();
auto mathTrace = _session->get_math_trace();
if (mathTrace && mathTrace->enabled()) {
mathTrace->set_show(!enable);
}

View File

@ -31,8 +31,7 @@
#include <QCheckBox>
#include <QRadioButton>
#include <QSlider>
#include <boost/shared_ptr.hpp>
#include "../view/dsosignal.h"
#include "../toolbars/titlebar.h"
@ -56,7 +55,7 @@ private:
static const int WellLen = SR_Kn(16);
public:
LissajousOptions(SigSession &session, QWidget *parent);
LissajousOptions(SigSession *session, QWidget *parent);
private:
void changeEvent(QEvent *event);
@ -67,16 +66,17 @@ protected:
void reject();
private:
SigSession &_session;
SigSession *_session;
QCheckBox *_enable;
QGroupBox *_x_group;
QGroupBox *_y_group;
QSlider *_percent;
QGridLayout *_layout;
QVector<QRadioButton *> _x_radio;
QVector<QRadioButton *> _y_radio;
QDialogButtonBox _button_box;
QGridLayout *_layout;
QDialogButtonBox _button_box;
};
} // namespace dialogs

View File

@ -31,8 +31,7 @@
#include <QLabel>
#include <QTabBar>
#include <QBitmap>
#include <boost/foreach.hpp>
using namespace boost;
using namespace std;
@ -41,7 +40,7 @@ using namespace pv::view;
namespace pv {
namespace dialogs {
MathOptions::MathOptions(SigSession &session, QWidget *parent) :
MathOptions::MathOptions(SigSession *session, QWidget *parent) :
DSDialog(parent),
_session(session),
_button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
@ -78,9 +77,10 @@ MathOptions::MathOptions(SigSession &session, QWidget *parent) :
_src2_group = new QGroupBox(this);
QHBoxLayout *src1_layout = new QHBoxLayout();
QHBoxLayout *src2_layout = new QHBoxLayout();
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig = NULL;;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
QString index_str = QString::number(dsoSig->get_index());
QRadioButton *xradio = new QRadioButton(index_str, _src1_group);
xradio->setProperty("index", dsoSig->get_index());
@ -96,7 +96,7 @@ MathOptions::MathOptions(SigSession &session, QWidget *parent) :
_src2_group->setLayout(src2_layout);
boost::shared_ptr<MathTrace> math = _session.get_math_trace();
auto math = _session->get_math_trace();
if (math) {
_enable->setChecked(math->enabled());
for (QVector<QRadioButton *>::const_iterator i = _src1_radio.begin();
@ -139,8 +139,7 @@ MathOptions::MathOptions(SigSession &session, QWidget *parent) :
}
}
_layout = new QGridLayout();
_layout->setMargin(0);
_layout = new QGridLayout();
_layout->setSpacing(0);
_layout->addWidget(lisa_label, 0, 0, 1, 2, Qt::AlignCenter);
_layout->addWidget(_enable, 1, 0, 1, 1);
@ -204,18 +203,19 @@ void MathOptions::accept()
}
}
bool enable = (src1 != -1 && src2 != -1 && _enable->isChecked());
boost::shared_ptr<view::DsoSignal> dsoSig1;
boost::shared_ptr<view::DsoSignal> dsoSig2;
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
view::DsoSignal *dsoSig1 = NULL;
view::DsoSignal *dsoSig2 = NULL;
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig = NULL;;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
if (dsoSig->get_index() == src1)
dsoSig1 = dsoSig;
if (dsoSig->get_index() == src2)
dsoSig2 = dsoSig;
}
}
_session.math_rebuild(enable, dsoSig1, dsoSig2, type);
_session->math_rebuild(enable, dsoSig1, dsoSig2, type);
}
void MathOptions::reject()

View File

@ -31,8 +31,7 @@
#include <QCheckBox>
#include <QRadioButton>
#include <QSlider>
#include <boost/shared_ptr.hpp>
#include "../view/dsosignal.h"
#include "../toolbars/titlebar.h"
@ -56,7 +55,7 @@ private:
static const int WellLen = SR_Kn(16);
public:
MathOptions(SigSession &session, QWidget *parent);
MathOptions(SigSession *session, QWidget *parent);
private:
void changeEvent(QEvent *event);
@ -67,7 +66,7 @@ protected:
void reject();
private:
SigSession &_session;
SigSession *_session;
QCheckBox *_enable;
QGroupBox *_src1_group;

View File

@ -20,10 +20,7 @@
*/
#include "protocolexp.h"
#include <boost/foreach.hpp>
#include <QApplication>
#include <QFormLayout>
#include <QListWidget>
#include <QFile>
@ -39,6 +36,8 @@
#include "../data/decode/annotation.h"
#include "../view/decodetrace.h"
#include "../data/decodermodel.h"
#include "../config/appconfig.h"
#include "../dsvdef.h"
using namespace boost;
using namespace std;
@ -46,14 +45,14 @@ using namespace std;
namespace pv {
namespace dialogs {
ProtocolExp::ProtocolExp(QWidget *parent, SigSession &session) :
ProtocolExp::ProtocolExp(QWidget *parent, SigSession *session) :
DSDialog(parent),
_session(session),
_button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, this),
_export_cancel(false)
{
_format_combobox = new QComboBox(this);
_format_combobox = new DsComboBox(this);
_format_combobox->addItem(tr("Comma-Separated Values (*.csv)"));
_format_combobox->addItem(tr("Text files (*.txt)"));
@ -64,13 +63,14 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession &session) :
_flayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
_flayout->addRow(new QLabel(tr("Export Format: "), this), _format_combobox);
pv::data::DecoderModel* decoder_model = _session.get_decoder_model();
const boost::shared_ptr<pv::data::DecoderStack>& decoder_stack = decoder_model->getDecoderStack();
pv::data::DecoderModel* decoder_model = _session->get_decoder_model();
const auto decoder_stack = decoder_model->getDecoderStack();
if (decoder_stack) {
int row_index = 0;
const std::map<const pv::data::decode::Row, bool> rows = decoder_stack->get_rows_lshow();
for (std::map<const pv::data::decode::Row, bool>::const_iterator i = rows.begin();
i != rows.end(); i++) {
auto rows = decoder_stack->get_rows_lshow();
for (auto i = rows.begin();i != rows.end(); i++) {
if ((*i).second) {
QLabel *row_label = new QLabel((*i).first.title(), this);
QRadioButton *row_sel = new QRadioButton(this);
@ -96,7 +96,7 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession &session) :
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject()));
connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject()));
}
@ -118,15 +118,20 @@ void ProtocolExp::accept()
if(i < supportedFormats.count() - 1)
filter.append(";;");
}
const QString DIR_KEY("ProtocolExportPath");
QSettings settings(QApplication::organizationName(), QApplication::applicationName());
AppConfig &app = AppConfig::Instance();
QString default_filter = _format_combobox->currentText();
QString default_name = settings.value(DIR_KEY).toString() + "/" + "decoder-";
default_name += _session.get_session_time().toString("-yyMMdd-hhmmss");
QString default_name = app._userHistory.protocolExportPath + "/" + "decoder-";
default_name += _session->get_session_time().toString("-yyMMdd-hhmmss");
QString file_name = QFileDialog::getSaveFileName(
this, tr("Export Data"), default_name,filter,&default_filter);
this,
tr("Export Data"),
default_name,filter,
&default_filter);
if (!file_name.isEmpty()) {
QFileInfo f(file_name);
QStringList list = default_filter.split('.').last().split(')');
@ -134,13 +139,17 @@ void ProtocolExp::accept()
if(f.suffix().compare(ext))
file_name+=tr(".")+ext;
QDir CurrentDir;
settings.setValue(DIR_KEY, CurrentDir.filePath(file_name));
QString fname = GetDirectoryName(file_name);
if (fname != app._userHistory.openDir)
{
app._userHistory.protocolExportPath = fname;
app.SaveHistory();
}
QFile file(file_name);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out.setCodec("UTF-8");
app::set_utf8(out);
//out.setGenerateByteOrderMark(true); // UTF-8 without BOM
QFuture<void> future;
@ -161,8 +170,8 @@ void ProtocolExp::accept()
.arg("Time[ns]")
.arg(title);
pv::data::DecoderModel* decoder_model = _session.get_decoder_model();
const boost::shared_ptr<pv::data::DecoderStack>& decoder_stack = decoder_model->getDecoderStack();
pv::data::DecoderModel* decoder_model = _session->get_decoder_model();
const auto decoder_stack = decoder_model->getDecoderStack();
int row_index = 0;
Row row;
const std::map<const Row, bool> rows_lshow = decoder_stack->get_rows_lshow();
@ -179,11 +188,11 @@ void ProtocolExp::accept()
uint64_t exported = 0;
double ns_per_sample = SR_SEC(1) * 1.0 / decoder_stack->samplerate();
vector<Annotation> annotations;
std::vector<Annotation> annotations;
decoder_stack->get_annotation_subset(annotations, row,
0, decoder_stack->sample_count()-1);
if (!annotations.empty()) {
BOOST_FOREACH(const Annotation &a, annotations) {
for(auto &a : annotations) {
out << QString("%1,%2,%3\n")
.arg(QString::number(exported))
.arg(QString::number(a.start_sample()*ns_per_sample, 'f', 20))

View File

@ -28,14 +28,12 @@
#include <QVBoxLayout>
#include <QLabel>
#include <QRadioButton>
#include <QComboBox>
#include <boost/shared_ptr.hpp>
#include "../device/devinst.h"
#include "../prop/binding/deviceoptions.h"
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../ui/dscombobox.h"
namespace pv {
@ -54,7 +52,7 @@ class ProtocolExp : public DSDialog
Q_OBJECT
public:
ProtocolExp(QWidget *parent, SigSession &session);
ProtocolExp(QWidget *parent, SigSession *session);
protected:
void accept();
@ -67,10 +65,10 @@ private slots:
void cancel_export();
private:
SigSession &_session;
SigSession *_session;
toolbars::TitleBar *_titlebar;
QComboBox *_format_combobox;
DsComboBox *_format_combobox;
std::list<QRadioButton *> _row_sel_list;
std::list<QLabel *> _row_label_list;
QFormLayout *_flayout;

View File

@ -20,8 +20,7 @@
*/
#include "protocollist.h"
#include <boost/foreach.hpp>
#include <QFormLayout>
#include <QListWidget>
@ -38,29 +37,31 @@ using namespace std;
namespace pv {
namespace dialogs {
ProtocolList::ProtocolList(QWidget *parent, SigSession &session) :
ProtocolList::ProtocolList(QWidget *parent, SigSession *session) :
DSDialog(parent),
_session(session),
_button_box(QDialogButtonBox::Ok,
Qt::Horizontal, this)
{
pv::data::DecoderModel* decoder_model = _session.get_decoder_model();
pv::data::DecoderModel* decoder_model = _session->get_decoder_model();
_map_zoom_combobox = new QComboBox(this);
_map_zoom_combobox = new DsComboBox(this);
_map_zoom_combobox->addItem(tr("Fit to Window"));
_map_zoom_combobox->addItem(tr("Fixed"));
int cur_map_zoom = _session.get_map_zoom();
int cur_map_zoom = _session->get_map_zoom();
if (cur_map_zoom >= _map_zoom_combobox->count())
_map_zoom_combobox->setCurrentIndex(0);
else
_map_zoom_combobox->setCurrentIndex(cur_map_zoom);
connect(_map_zoom_combobox, SIGNAL(currentIndexChanged(int)), &_session, SLOT(set_map_zoom(int)));
_protocol_combobox = new QComboBox(this);
const std::vector< boost::shared_ptr<pv::view::DecodeTrace> > decode_sigs(
_session.get_decode_signals());
connect(_map_zoom_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_set_map_zoom(int)));
_protocol_combobox = new DsComboBox(this);
auto &decode_sigs = _session->get_decode_signals();
int index = 0;
BOOST_FOREACH(boost::shared_ptr<pv::view::DecodeTrace> d, decode_sigs) {
for(auto &d : decode_sigs) {
_protocol_combobox->addItem(d->get_name());
if (decoder_model->getDecoderStack() == d->decoder())
_protocol_combobox->setCurrentIndex(index);
@ -89,7 +90,7 @@ ProtocolList::ProtocolList(QWidget *parent, SigSession &session) :
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
connect(_protocol_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(set_protocol(int)));
set_protocol(_protocol_combobox->currentIndex());
connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject()));
connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject()));
}
@ -126,11 +127,11 @@ void ProtocolList::set_protocol(int index)
}
_show_label_list.clear();
boost::shared_ptr<pv::data::DecoderStack> decoder_stack;
const std::vector< boost::shared_ptr<pv::view::DecodeTrace> > decode_sigs(
_session.get_decode_signals());
pv::data::DecoderStack *decoder_stack = NULL;
const auto &decode_sigs = _session->get_decode_signals();
int cur_index = 0;
BOOST_FOREACH(boost::shared_ptr<pv::view::DecodeTrace> d, decode_sigs) {
for(auto &d : decode_sigs) {
if (index == cur_index) {
decoder_stack = d->decoder();
break;
@ -139,15 +140,15 @@ void ProtocolList::set_protocol(int index)
}
if (!decoder_stack){
_session.get_decoder_model()->setDecoderStack(NULL);
_session->get_decoder_model()->setDecoderStack(NULL);
return;
}
_session.get_decoder_model()->setDecoderStack(decoder_stack);
_session->get_decoder_model()->setDecoderStack(decoder_stack);
int row_index = 0;
const std::map<const pv::data::decode::Row, bool> rows = decoder_stack->get_rows_lshow();
for (std::map<const pv::data::decode::Row, bool>::const_iterator i = rows.begin();
i != rows.end(); i++) {
const auto rows = decoder_stack->get_rows_lshow();
for (auto i = rows.begin();i != rows.end(); i++) {
QLabel *row_label = new QLabel((*i).first.title(), this);
QCheckBox *row_checkbox = new QCheckBox(this);
//row_checkbox->setChecked(false);
@ -168,11 +169,11 @@ void ProtocolList::on_row_check(bool show)
QVariant id = sc->property("index");
int index = id.toInt();
boost::shared_ptr<pv::data::DecoderStack> decoder_stack;
const std::vector< boost::shared_ptr<pv::view::DecodeTrace> > decode_sigs(
_session.get_decode_signals());
pv::data::DecoderStack *decoder_stack = NULL;
const auto &decode_sigs = _session->get_decode_signals();
int cur_index = 0;
BOOST_FOREACH(boost::shared_ptr<pv::view::DecodeTrace> d, decode_sigs) {
for(auto &d : decode_sigs) {
if (cur_index == _protocol_combobox->currentIndex()) {
decoder_stack = d->decoder();
break;
@ -192,7 +193,13 @@ void ProtocolList::on_row_check(bool show)
}
}
_session.get_decoder_model()->setDecoderStack(decoder_stack);
_session->get_decoder_model()->setDecoderStack(decoder_stack);
}
void ProtocolList::on_set_map_zoom(int index)
{
_session->set_map_zoom(index);
}
} // namespace dialogs
} // namespace pv

View File

@ -27,15 +27,13 @@
#include <QFormLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>
#include <boost/shared_ptr.hpp>
#include <QCheckBox>
#include "../device/devinst.h"
#include "../prop/binding/deviceoptions.h"
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../ui/dscombobox.h"
namespace pv {
@ -48,7 +46,7 @@ class ProtocolList : public DSDialog
Q_OBJECT
public:
ProtocolList(QWidget *parent, SigSession &session);
ProtocolList(QWidget *parent, SigSession *session);
protected:
void accept();
@ -57,13 +55,14 @@ protected:
private slots:
void set_protocol(int index);
void on_row_check(bool show);
void on_set_map_zoom(int index);
private:
SigSession &_session;
SigSession *_session;
toolbars::TitleBar *_titlebar;
QComboBox *_map_zoom_combobox;
QComboBox *_protocol_combobox;
DsComboBox *_map_zoom_combobox;
DsComboBox *_protocol_combobox;
std::list<QCheckBox *> _show_checkbox_list;
std::list<QLabel *> _show_label_list;
QFormLayout *_flayout;

View File

@ -20,9 +20,7 @@
*/
#include "regionoptions.h"
#include <boost/foreach.hpp>
#include "../sigsession.h"
#include "../view/cursor.h"
#include "../view/view.h"
@ -37,7 +35,7 @@ namespace dialogs {
const QString RegionOptions::RegionStart = QT_TR_NOOP("Start");
const QString RegionOptions::RegionEnd = QT_TR_NOOP("End");
RegionOptions::RegionOptions(view::View *view, SigSession &session, QWidget *parent) :
RegionOptions::RegionOptions(view::View *view, SigSession *session, QWidget *parent) :
DSDialog(parent),
_session(session),
_view(view),
@ -45,10 +43,10 @@ RegionOptions::RegionOptions(view::View *view, SigSession &session, QWidget *par
Qt::Horizontal, this)
{
QHBoxLayout *hlayout = new QHBoxLayout();
hlayout->setMargin(0);
hlayout->setContentsMargins(0,0,0,0);
hlayout->setSpacing(0);
_start_comboBox = new QComboBox(this);
_end_comboBox = new QComboBox(this);
_start_comboBox = new DsComboBox(this);
_end_comboBox = new DsComboBox(this);
_start_comboBox->addItem(RegionStart);
_end_comboBox->addItem(RegionEnd);
if (_view) {
@ -75,19 +73,19 @@ RegionOptions::RegionOptions(view::View *view, SigSession &session, QWidget *par
setTitle(tr("Region"));
connect(&_button_box, SIGNAL(accepted()), this, SLOT(set_region()));
connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject()));
connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject()));
}
void RegionOptions::set_region()
{
const uint64_t last_samples = _session.cur_samplelimits() - 1;
const uint64_t last_samples = _session->cur_samplelimits() - 1;
const int index1 = _start_comboBox->currentIndex();
const int index2 = _end_comboBox->currentIndex();
uint64_t start, end;
_session.set_save_start(0);
_session.set_save_end(last_samples);
_session->set_save_start(0);
_session->set_save_end(last_samples);
if (index1 == 0) {
start = 0;
@ -105,8 +103,8 @@ void RegionOptions::set_region()
if (end > last_samples)
end = last_samples;
_session.set_save_start(min(start, end));
_session.set_save_end(max(start, end));
_session->set_save_start(min(start, end));
_session->set_save_end(max(start, end));
QDialog::accept();
}

View File

@ -27,12 +27,10 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QComboBox>
#include <boost/shared_ptr.hpp>
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../ui/dscombobox.h"
namespace pv {
@ -52,17 +50,17 @@ private:
static const QString RegionEnd;
public:
RegionOptions(view::View *view, SigSession &session, QWidget *parent = 0);
RegionOptions(view::View *view, SigSession *session, QWidget *parent = 0);
private slots:
void set_region();
private:
SigSession &_session;
SigSession *_session;
view::View *_view;
QComboBox *_start_comboBox;
QComboBox *_end_comboBox;
DsComboBox *_start_comboBox;
DsComboBox *_end_comboBox;
QDialogButtonBox _button_box;

View File

@ -23,14 +23,13 @@
#include "../view/logicsignal.h"
#include <assert.h>
#include <QRegExpValidator>
#include <boost/foreach.hpp>
#include <QRegularExpressionValidator>
namespace pv {
namespace dialogs {
Search::Search(QWidget *parent, SigSession &session, std::map<uint16_t, QString> pattern) :
Search::Search(QWidget *parent, SigSession *session, std::map<uint16_t, QString> pattern) :
DSDialog(parent),
_session(session)
{
@ -40,8 +39,8 @@ Search::Search(QWidget *parent, SigSession &session, std::map<uint16_t, QString>
font.setFixedPitch(true);
//this->setMinimumWidth(350);
QRegExp value_rx("[10XRFCxrfc]+");
QValidator *value_validator = new QRegExpValidator(value_rx, this);
QRegularExpression value_rx("[10XRFCxrfc]+");
QValidator *value_validator = new QRegularExpressionValidator(value_rx, this);
search_buttonBox.addButton(QDialogButtonBox::Ok);
search_buttonBox.addButton(QDialogButtonBox::Cancel);
@ -50,11 +49,11 @@ Search::Search(QWidget *parent, SigSession &session, std::map<uint16_t, QString>
search_layout->setVerticalSpacing(0);
int index = 0;
BOOST_FOREACH(const boost::shared_ptr<view::Signal> sig,
_session.get_signals()) {
for(auto &sig : _session->get_signals()) {
assert(sig);
boost::shared_ptr<view::LogicSignal> logic_sig;
if ((logic_sig = boost::dynamic_pointer_cast<view::LogicSignal>(sig))) {
view::LogicSignal *logic_sig = NULL;
if ((logic_sig = dynamic_cast<view::LogicSignal*>(sig))) {
QLineEdit *search_lineEdit = new QLineEdit(this);
if (pattern.find(logic_sig->get_index()) != pattern.end())
search_lineEdit->setText(pattern[logic_sig->get_index()]);
@ -86,7 +85,7 @@ Search::Search(QWidget *parent, SigSession &session, std::map<uint16_t, QString>
connect(&search_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(&search_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject()));
connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject()));
}
Search::~Search()
@ -111,11 +110,10 @@ std::map<uint16_t, QString> Search::get_pattern()
std::map<uint16_t, QString> pattern;
int index = 0;
BOOST_FOREACH(const boost::shared_ptr<view::Signal> sig,
_session.get_signals()) {
for(auto &sig :_session->get_signals()) {
assert(sig);
boost::shared_ptr<view::LogicSignal> logic_sig;
if ((logic_sig = boost::dynamic_pointer_cast<view::LogicSignal>(sig))) {
view::LogicSignal *logic_sig = NULL;
if ((logic_sig = dynamic_cast<view::LogicSignal*>(sig))) {
pattern[logic_sig->get_index()] = _search_lineEdit_vec[index]->text();
index++;
}

View File

@ -33,9 +33,7 @@
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../device/devinst.h"
#include <boost/shared_ptr.hpp>
namespace pv {
namespace dialogs {
@ -45,7 +43,7 @@ class Search : public DSDialog
public:
Search(QWidget *parent, SigSession &session, std::map<uint16_t, QString> pattern);
Search(QWidget *parent, SigSession *session, std::map<uint16_t, QString> pattern);
~Search();
std::map<uint16_t, QString> get_pattern();
@ -59,7 +57,7 @@ private slots:
void format();
private:
SigSession &_session;
SigSession *_session;
toolbars::TitleBar *_titlebar;
QVector<QLineEdit *> _search_lineEdit_vec;

View File

@ -19,36 +19,71 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "storeprogress.h"
#include "dsmessagebox.h"
#include "pv/sigsession.h"
#include "storeprogress.h"
#include "../sigsession.h"
#include <QGridLayout>
#include <QDialogButtonBox>
#include <QTimer>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include "QVBoxLayout"
#include "../ui/msgbox.h"
#include "../config/appconfig.h"
namespace pv {
namespace dialogs {
StoreProgress::StoreProgress(SigSession &session, QWidget *parent) :
StoreProgress::StoreProgress(SigSession *session, QWidget *parent) :
DSDialog(parent),
_store_session(session),
_button_box(QDialogButtonBox::Cancel, Qt::Horizontal, this),
_done(false)
_store_session(session)
{
this->setModal(true);
_fileLab = NULL;
_ckOrigin = NULL;
_info.setText("...");
this->setMinimumSize(550, 220);
this->setModal(true);
_progress.setValue(0);
_progress.setMaximum(100);
QVBoxLayout* add_layout = new QVBoxLayout();
add_layout->addWidget(&_info, 0, Qt::AlignCenter);
add_layout->addWidget(&_progress);
add_layout->addWidget(&_button_box);
layout()->addLayout(add_layout);
_isExport = false;
_done = false;
QGridLayout *grid = new QGridLayout();
_grid = grid;
grid->setContentsMargins(10, 20, 10, 10);
grid->setVerticalSpacing(25);
grid->setColumnStretch(0, 2);
grid->setColumnStretch(1, 2);
grid->setColumnStretch(2, 1);
grid->setColumnStretch(3, 1);
_fileLab = new QLineEdit();
_fileLab->setEnabled(false);
_fileLab->setObjectName("PathLine");
QPushButton *openButton = new QPushButton(this);
openButton->setText(tr("change"));
grid->addWidget(&_progress, 0, 0, 1, 4);
grid->addWidget(_fileLab, 1, 0, 1, 3);
grid->addWidget(openButton, 1, 3, 1, 1);
QDialogButtonBox *_button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, this);
grid->addWidget(_button_box, 2, 2, 1, 2, Qt::AlignRight | Qt::AlignBottom);
layout()->addLayout(grid);
connect(_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(_button_box, SIGNAL(accepted()), this, SLOT(accept()));
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(&_store_session, SIGNAL(progress_updated()),
this, SLOT(on_progress_updated()), Qt::QueuedConnection);
connect(openButton, SIGNAL(clicked()),this, SLOT(on_change_file()));
}
StoreProgress::~StoreProgress()
@ -56,57 +91,117 @@ StoreProgress::~StoreProgress()
_store_session.wait();
}
void StoreProgress::on_change_file()
{
if (_isExport){
QString file = _store_session.MakeExportFile(true);
if (file != "")
_fileLab->setText(file);
}
else{
QString file = _store_session.MakeSaveFile(true);
if (file != "")
_fileLab->setText(file);
}
}
void StoreProgress::reject()
{
using namespace Qt;
_store_session.cancel();
save_done();
QDialog::reject();
DSDialog::reject();
}
void StoreProgress::accept()
{
if (_store_session.GetFileName() == ""){
MsgBox::Show(NULL, "you need to select a file name.");
return;
}
if (_isExport && _store_session.IsLogicDataType()){
bool ck = _ckOrigin->isChecked();
AppConfig &app = AppConfig::Instance();
if (app._appOptions.originalData != ck){
app._appOptions.originalData = ck;
app.SaveApp();
}
}
//start done
if (_isExport){
if (_store_session.export_start()){
QTimer::singleShot(100, this, SLOT(timeout()));
}
else{
save_done();
close();
show_error();
}
}
else{
if (_store_session.save_start()){
QTimer::singleShot(100, this, SLOT(timeout()));
}
else{
save_done();
close();
show_error();
}
}
//do not to call base class method, otherwise the window will be closed;
}
void StoreProgress::timeout()
{
if (_done) {
_store_session.session().set_saving(false);
_store_session.session()->set_saving(false);
save_done();
close();
close();
delete this;
} else {
QTimer::singleShot(100, this, SLOT(timeout()));
}
}
void StoreProgress::save_run(QString session_file)
void StoreProgress::save_run(ISessionDataGetter *getter)
{
_info.setText(tr("Saving..."));
if (_store_session.save_start(session_file))
show();
else
show_error();
QTimer::singleShot(100, this, SLOT(timeout()));
_isExport = false;
setTitle(tr("Saving..."));
QString file = _store_session.MakeSaveFile(false);
_fileLab->setText(file);
_store_session._sessionDataGetter = getter;
show();
}
void StoreProgress::export_run()
{
_info.setText(tr("Exporting..."));
if (_store_session.export_start())
show();
else
show_error();
if (_store_session.IsLogicDataType())
{
QGridLayout *lay = new QGridLayout();
lay->setContentsMargins(15, 0, 0, 0);
AppConfig &app = AppConfig::Instance();
_ckOrigin = new QCheckBox();
_ckOrigin->setChecked(app._appOptions.originalData);
_ckOrigin->setText(tr("all original data"));
lay->addWidget(_ckOrigin);
_grid->addLayout(lay, 2, 0, 1, 2);
}
QTimer::singleShot(100, this, SLOT(timeout()));
_isExport = true;
setTitle(tr("Exporting..."));
QString file = _store_session.MakeExportFile(false);
_fileLab->setText(file);
show();
}
void StoreProgress::show_error()
{
_done = true;
if (!_store_session.error().isEmpty()) {
dialogs::DSMessageBox msg(parentWidget());
msg.mBox()->setText(tr("Failed to save data."));
msg.mBox()->setInformativeText(_store_session.error());
msg.mBox()->setStandardButtons(QMessageBox::Ok);
msg.mBox()->setIcon(QMessageBox::Warning);
msg.exec();
if (!_store_session.error().isEmpty()) {
MsgBox::Show(NULL, _store_session.error().toStdString().c_str(), NULL);
}
}

View File

@ -21,19 +21,15 @@
#ifndef DSVIEW_PV_DIALOGS_SAVEPROGRESS_H
#define DSVIEW_PV_DIALOGS_SAVEPROGRESS_H
#include <set>
#include <boost/shared_ptr.hpp>
#include <QLabel>
#include <QProgressBar>
#include <QDialogButtonBox>
#include <QTimer>
#include "../storesession.h"
#include "../dialogs/dsdialog.h"
#include "../toolbars/titlebar.h"
#include "../dialogs/dsdialog.h"
#include "../interface/icallbacks.h"
class QLineEdit;
class QCheckBox;
class QGridLayout;
namespace pv {
@ -46,15 +42,15 @@ class StoreProgress : public DSDialog
Q_OBJECT
public:
StoreProgress(SigSession &session,
StoreProgress(SigSession *session,
QWidget *parent = 0);
virtual ~StoreProgress();
protected:
void reject();
void accept();
private:
void show_error();
@ -64,23 +60,22 @@ signals:
void save_done();
public slots:
void save_run(QString session_file);
void save_run(ISessionDataGetter *getter);
void export_run();
private slots:
void on_progress_updated();
void timeout();
void on_change_file();
private:
pv::StoreSession _store_session;
QLabel _info;
QProgressBar _progress;
QDialogButtonBox _button_box;
toolbars::TitleBar *_titlebar;
bool _done;
pv::StoreSession _store_session;
QProgressBar _progress;
bool _done;
bool _isExport;
QLineEdit *_fileLab;
QCheckBox *_ckOrigin;
QGridLayout *_grid;
};
} // dialogs

View File

@ -20,8 +20,7 @@
*/
#include "waitingdialog.h"
#include <boost/foreach.hpp>
#include <QMovie>
#include <QAbstractButton>
@ -32,6 +31,7 @@
#include "../view/trace.h"
#include "../view/dsosignal.h"
#include "../config/appconfig.h"
using namespace boost;
using namespace std;
@ -42,14 +42,14 @@ namespace dialogs {
const QString WaitingDialog::TIPS_WAIT = "Waiting";
const QString WaitingDialog::TIPS_FINISHED = "Finished!";
WaitingDialog::WaitingDialog(QWidget *parent, SigSession &session, int key) :
WaitingDialog::WaitingDialog(QWidget *parent, SigSession *session, int key) :
DSDialog(parent),
_key(key),
_session(session),
_button_box(QDialogButtonBox::Abort,
Qt::Horizontal, this)
{
_dev_inst = _session.get_device();
_dev_inst = _session->get_device();
this->setFixedSize((GIF_WIDTH+2*TIP_WIDTH)*1.2, (GIF_HEIGHT+2*TIP_HEIGHT)*4);
this->setWindowOpacity(0.7);
@ -62,7 +62,7 @@ WaitingDialog::WaitingDialog(QWidget *parent, SigSession &session, int key) :
warning_tips->setFont(font);
warning_tips->setAlignment(Qt::AlignCenter);
QString iconPath = ":/icons/" + qApp->property("Style").toString();
QString iconPath = GetIconPath();
label = new QLabel(this);
movie = new QMovie(iconPath+"/wait.gif");
label->setMovie(movie);
@ -78,7 +78,7 @@ WaitingDialog::WaitingDialog(QWidget *parent, SigSession &session, int key) :
connect(timer, SIGNAL(timeout()), this, SLOT(changeText()));
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(_dev_inst.get(), SIGNAL(device_updated()), this, SLOT(stop()));
connect(_dev_inst, SIGNAL(device_updated()), this, SLOT(stop()));
QVBoxLayout *mlayout = new QVBoxLayout();
@ -184,13 +184,14 @@ void WaitingDialog::changeText()
zero_fgain = g_variant_get_boolean(gvar);
g_variant_unref(gvar);
if (zero_fgain) {
boost::shared_ptr<view::DsoSignal> dsoSig;
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals())
view::DsoSignal *dsoSig = NULL;
for(auto &s : _session->get_signals())
{
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)))
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s)))
dsoSig->set_enable(dsoSig->get_index() == 0);
}
boost::this_thread::sleep(boost::posix_time::millisec(100));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
_dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_COMB, g_variant_new_boolean(true));
}
}

View File

@ -27,14 +27,14 @@
#include <QTimer>
#include <QLabel>
#include <QMovie>
#include <boost/shared_ptr.hpp>
#include "../sigsession.h"
#include "../device/devinst.h"
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
using namespace pv::device;
namespace pv {
namespace dialogs {
@ -53,7 +53,7 @@ private:
static const QString TIPS_FINISHED;
public:
WaitingDialog(QWidget *parent, SigSession &session, int key);
WaitingDialog(QWidget *parent, SigSession *session, int key);
int start();
protected:
@ -66,8 +66,8 @@ private slots:
private:
int _key;
SigSession &_session;
boost::shared_ptr<pv::device::DevInst> _dev_inst;
SigSession *_session;
DevInst* _dev_inst;
toolbars::TitleBar *_titlebar;
QDialogButtonBox _button_box;

View File

@ -24,9 +24,7 @@
#include "../device/devinst.h"
#include "../dialogs/dsmessagebox.h"
#include "../view/dsosignal.h"
#include <boost/shared_ptr.hpp>
#include <boost/foreach.hpp>
#include <QObject>
#include <QLabel>
@ -37,6 +35,7 @@
#include <QVector>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QEvent>
using namespace boost;
using namespace std;
@ -44,7 +43,7 @@ using namespace std;
namespace pv {
namespace dock {
DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession &session) :
DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession *session) :
QScrollArea(parent),
_session(session)
{
@ -62,7 +61,7 @@ DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession &session) :
connect(_position_slider, SIGNAL(valueChanged(int)), this, SLOT(pos_changed(int)));
_holdoff_label = new QLabel(_widget);
_holdoff_comboBox = new QComboBox(_widget);
_holdoff_comboBox = new DsComboBox(_widget);
_holdoff_comboBox->addItem(tr("uS"), QVariant::fromValue(1000));
_holdoff_comboBox->addItem(tr("mS"), QVariant::fromValue(1000000));
_holdoff_comboBox->addItem(tr("S"), QVariant::fromValue(1000000000));
@ -104,7 +103,7 @@ DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession &session) :
connect(_falling_radioButton, SIGNAL(clicked()), this, SLOT(type_changed()));
_source_group=new QButtonGroup(_widget);
_channel_comboBox = new QComboBox(_widget);
_channel_comboBox = new DsComboBox(_widget);
_type_group=new QButtonGroup(_widget);
_source_group->addButton(_auto_radioButton);
@ -200,7 +199,7 @@ void DsoTriggerDock::retranslateUi()
void DsoTriggerDock::reStyle()
{
//QString iconPath = ":/icons/" + qApp->property("Style").toString();
}
void DsoTriggerDock::paintEvent(QPaintEvent *)
@ -222,7 +221,7 @@ void DsoTriggerDock::auto_trig(int index)
void DsoTriggerDock::pos_changed(int pos)
{
int ret;
ret = _session.get_device()->set_config(NULL, NULL,
ret = _session->get_device()->set_config(NULL, NULL,
SR_CONF_HORIZ_TRIGGERPOS,
g_variant_new_byte((uint8_t)pos));
if (!ret) {
@ -247,7 +246,7 @@ void DsoTriggerDock::hold_changed(int hold)
_holdoff_slider->setRange(0, 999);
}
holdoff = _holdoff_slider->value() * _holdoff_comboBox->currentData().toDouble() / 10;
ret = _session.get_device()->set_config(NULL, NULL,
ret = _session->get_device()->set_config(NULL, NULL,
SR_CONF_TRIGGER_HOLDOFF,
g_variant_new_uint64(holdoff));
@ -264,7 +263,7 @@ void DsoTriggerDock::hold_changed(int hold)
void DsoTriggerDock::margin_changed(int margin)
{
int ret;
ret = _session.get_device()->set_config(NULL, NULL,
ret = _session->get_device()->set_config(NULL, NULL,
SR_CONF_TRIGGER_MARGIN,
g_variant_new_byte(margin));
if (!ret) {
@ -282,7 +281,7 @@ void DsoTriggerDock::source_changed()
int id = _source_group->checkedId();
int ret;
ret = _session.get_device()->set_config(NULL, NULL,
ret = _session->get_device()->set_config(NULL, NULL,
SR_CONF_TRIGGER_SOURCE,
g_variant_new_byte(id));
if (!ret) {
@ -300,7 +299,7 @@ void DsoTriggerDock::channel_changed(int ch)
(void)ch;
int ret;
ret = _session.get_device()->set_config(NULL, NULL,
ret = _session->get_device()->set_config(NULL, NULL,
SR_CONF_TRIGGER_CHANNEL,
g_variant_new_byte(_channel_comboBox->currentData().toInt()));
if (!ret) {
@ -318,7 +317,7 @@ void DsoTriggerDock::type_changed()
int id = _type_group->checkedId();
int ret;
ret = _session.get_device()->set_config(NULL, NULL,
ret = _session->get_device()->set_config(NULL, NULL,
SR_CONF_TRIGGER_SLOPE,
g_variant_new_byte(id));
if (!ret) {
@ -333,7 +332,7 @@ void DsoTriggerDock::type_changed()
void DsoTriggerDock::device_change()
{
if (_session.get_device()->name() != "DSLogic") {
if (_session->get_device()->name() != "DSLogic") {
_position_spinBox->setDisabled(true);
_position_slider->setDisabled(true);
} else {
@ -344,11 +343,13 @@ void DsoTriggerDock::device_change()
void DsoTriggerDock::init()
{
if (_session.get_device()->name().contains("virtual")) {
foreach(QAbstractButton * btn, _source_group->buttons())
if (_session->get_device()->name().contains("virtual")) {
for(QAbstractButton * btn : _source_group->buttons())
btn->setDisabled(true);
foreach(QAbstractButton * btn, _type_group->buttons())
for(QAbstractButton * btn : _type_group->buttons())
btn->setDisabled(true);
_holdoff_slider->setDisabled(true);
_holdoff_spinBox->setDisabled(true);
_holdoff_comboBox->setDisabled(true);
@ -356,10 +357,12 @@ void DsoTriggerDock::init()
_channel_comboBox->setDisabled(true);
return;
} else {
foreach(QAbstractButton * btn, _source_group->buttons())
for(QAbstractButton * btn : _source_group->buttons())
btn->setDisabled(false);
foreach(QAbstractButton * btn, _type_group->buttons())
for(QAbstractButton * btn : _type_group->buttons())
btn->setDisabled(false);
_holdoff_slider->setDisabled(false);
_holdoff_spinBox->setDisabled(false);
_holdoff_comboBox->setDisabled(false);
@ -368,7 +371,7 @@ void DsoTriggerDock::init()
}
// TRIGGERPOS
GVariant* gvar = _session.get_device()->get_config(NULL, NULL,
GVariant* gvar = _session->get_device()->get_config(NULL, NULL,
SR_CONF_HORIZ_TRIGGERPOS);
if (gvar != NULL) {
uint16_t pos = g_variant_get_byte(gvar);
@ -376,7 +379,7 @@ void DsoTriggerDock::init()
_position_slider->setValue(pos);
}
gvar = _session.get_device()->get_config(NULL, NULL,
gvar = _session->get_device()->get_config(NULL, NULL,
SR_CONF_TRIGGER_SOURCE);
if (gvar != NULL) {
uint8_t src = g_variant_get_byte(gvar);
@ -387,13 +390,14 @@ void DsoTriggerDock::init()
// setup _channel_comboBox
disconnect(_channel_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(channel_changed(int)));
_channel_comboBox->clear();
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
for(auto &s : _session->get_signals()) {
view::DsoSignal *dsoSig = NULL;
if ((dsoSig = dynamic_cast<view::DsoSignal*>(s))) {
_channel_comboBox->addItem(dsoSig->get_name(), QVariant::fromValue(dsoSig->get_index()));
}
}
gvar = _session.get_device()->get_config(NULL, NULL,
gvar = _session->get_device()->get_config(NULL, NULL,
SR_CONF_TRIGGER_CHANNEL);
if (gvar != NULL) {
uint8_t src = g_variant_get_byte(gvar);
@ -407,7 +411,7 @@ void DsoTriggerDock::init()
}
connect(_channel_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(channel_changed(int)));
gvar = _session.get_device()->get_config(NULL, NULL,
gvar = _session->get_device()->get_config(NULL, NULL,
SR_CONF_TRIGGER_SLOPE);
if (gvar != NULL) {
uint8_t slope = g_variant_get_byte(gvar);
@ -417,7 +421,7 @@ void DsoTriggerDock::init()
disconnect(_holdoff_slider, SIGNAL(valueChanged(int)), this, SLOT(hold_changed(int)));
disconnect(_holdoff_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(hold_changed(int)));
gvar = _session.get_device()->get_config(NULL, NULL,
gvar = _session->get_device()->get_config(NULL, NULL,
SR_CONF_TRIGGER_HOLDOFF);
if (gvar != NULL) {
uint64_t holdoff = g_variant_get_uint64(gvar);
@ -439,7 +443,7 @@ void DsoTriggerDock::init()
connect(_holdoff_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(hold_changed(int)));
disconnect(_margin_slider, SIGNAL(valueChanged(int)), this, SLOT(margin_changed(int)));
gvar = _session.get_device()->get_config(NULL, NULL,
gvar = _session->get_device()->get_config(NULL, NULL,
SR_CONF_TRIGGER_MARGIN);
if (gvar != NULL) {
uint8_t margin = g_variant_get_byte(gvar);

View File

@ -27,12 +27,13 @@
#include <QSpinBox>
#include <QButtonGroup>
#include <QScrollArea>
#include <QComboBox>
#include <QLabel>
#include <QRadioButton>
#include <vector>
#include "../ui/dscombobox.h"
namespace pv {
class SigSession;
@ -44,7 +45,7 @@ class DsoTriggerDock : public QScrollArea
Q_OBJECT
public:
DsoTriggerDock(QWidget *parent, SigSession &session);
DsoTriggerDock(QWidget *parent, SigSession *session);
~DsoTriggerDock();
void paintEvent(QPaintEvent *);
@ -75,11 +76,11 @@ private slots:
private:
private:
SigSession &_session;
SigSession *_session;
QWidget *_widget;
QComboBox *_holdoff_comboBox;
DsComboBox *_holdoff_comboBox;
QSpinBox *_holdoff_spinBox;
QSlider *_holdoff_slider;
@ -89,7 +90,7 @@ private:
QSlider *_position_slider;
QButtonGroup *_source_group;
QComboBox *_channel_comboBox;
DsComboBox *_channel_comboBox;
QButtonGroup *_type_group;
QLabel *_position_label;

View File

@ -38,9 +38,9 @@
#include "../dialogs/dsmessagebox.h"
#include <QObject>
#include <QPainter>
#include <QRegExpValidator>
#include <QPainter>
#include <QMessageBox>
#include "../config/appconfig.h"
using namespace boost;
@ -49,7 +49,7 @@ namespace dock {
using namespace pv::view;
MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession &session) :
MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) :
QScrollArea(parent),
_session(session),
_view(view)
@ -183,7 +183,7 @@ void MeasureDock::retranslateUi()
void MeasureDock::reStyle()
{
QString iconPath = ":/icons/" + qApp->property("Style").toString();
QString iconPath = GetIconPath();
_dist_add_btn->setIcon(QIcon(iconPath+"/add.svg"));
_edge_add_btn->setIcon(QIcon(iconPath+"/add.svg"));
@ -211,12 +211,12 @@ void MeasureDock::refresh()
void MeasureDock::reload()
{
if (_session.get_device()->dev_inst()->mode == LOGIC)
if (_session->get_device()->dev_inst()->mode == LOGIC)
_edge_groupBox->setDisabled(false);
else
_edge_groupBox->setDisabled(true);
for (QVector <QComboBox *>::const_iterator i = _edge_ch_cmb_vec.begin();
for (QVector <DsComboBox *>::const_iterator i = _edge_ch_cmb_vec.begin();
i != _edge_ch_cmb_vec.end(); i++) {
update_probe_selector(*i);
}
@ -247,7 +247,7 @@ void MeasureDock::cursor_update()
update_edge();
int index = 1;
QString iconPath = ":/icons/" + qApp->property("Style").toString();
QString iconPath = GetIconPath();
for(std::list<Cursor*>::iterator i = _view.get_cursorList().begin();
i != _view.get_cursorList().end(); i++) {
QString curCursor = QString::number(index);
@ -307,6 +307,7 @@ void MeasureDock::reCalc()
update_dist();
update_edge();
}
void MeasureDock::goto_cursor()
{
@ -336,7 +337,7 @@ void MeasureDock::add_dist_measure()
row_widget->setLayout(row_layout);
_dist_row_widget_vec.push_back(row_widget);
QString iconPath = ":/icons/" + qApp->property("Style").toString();
QString iconPath = GetIconPath();
QToolButton *del_btn = new QToolButton(row_widget);
del_btn->setIcon(QIcon(iconPath+"/del.svg"));
del_btn->setCheckable(true);
@ -402,7 +403,7 @@ void MeasureDock::add_edge_measure()
row_widget->setLayout(row_layout);
_edge_row_widget_vec.push_back(row_widget);
QString iconPath = ":/icons/" + qApp->property("Style").toString();
QString iconPath = GetIconPath();
QToolButton *del_btn = new QToolButton(row_widget);
del_btn->setIcon(QIcon(iconPath+"/del.svg"));
del_btn->setCheckable(true);
@ -415,7 +416,7 @@ void MeasureDock::add_edge_measure()
g_label->setContentsMargins(0,0,0,0);
QLabel *a_label = new QLabel(tr("@"), row_widget);
a_label->setContentsMargins(0,0,0,0);
QComboBox *ch_cmb = create_probe_selector(row_widget);
DsComboBox *ch_cmb = create_probe_selector(row_widget);
_edge_del_btn_vec.push_back(del_btn);
_edge_s_btn_vec.push_back(s_btn);
_edge_e_btn_vec.push_back(e_btn);
@ -597,12 +598,15 @@ void MeasureDock::update_edge()
if (start_ret && end_ret) {
uint64_t rising_edges;
uint64_t falling_edges;
const std::vector< boost::shared_ptr<Signal> > sigs(_session.get_signals());
const auto &sigs = _session->get_signals();
for(size_t i = 0; i < sigs.size(); i++) {
const boost::shared_ptr<view::Signal> s(sigs[i]);
boost::shared_ptr<view::LogicSignal> logicSig;
view::Signal *s = sigs[i];
view::LogicSignal *logicSig = NULL;
assert(s);
if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s)) &&
if ((logicSig = dynamic_cast<view::LogicSignal*>(s)) &&
(logicSig->enabled()) &&
(logicSig->get_index() == _edge_ch_cmb_vec[edge_index]->currentText().toInt())){
if (logicSig->edges(_view.get_cursor_samples(end), _view.get_cursor_samples(start), rising_edges, falling_edges)) {
@ -639,22 +643,23 @@ void MeasureDock::set_cursor_btn_color(QPushButton *btn)
btn->setStyleSheet(style);
}
QComboBox* MeasureDock::create_probe_selector(QWidget *parent)
DsComboBox* MeasureDock::create_probe_selector(QWidget *parent)
{
QComboBox *selector = new QComboBox(parent);
DsComboBox *selector = new DsComboBox(parent);
update_probe_selector(selector);
return selector;
}
void MeasureDock::update_probe_selector(QComboBox *selector)
void MeasureDock::update_probe_selector(DsComboBox *selector)
{
selector->clear();
const std::vector< boost::shared_ptr<Signal> > sigs(_session.get_signals());
const auto &sigs = _session->get_signals();
for(size_t i = 0; i < sigs.size(); i++) {
const boost::shared_ptr<view::Signal> s(sigs[i]);
const auto s = sigs[i];
assert(s);
if (dynamic_pointer_cast<LogicSignal>(s) && s->enabled())
if (dynamic_cast<LogicSignal*>(s) && s->enabled())
{
selector->addItem(QString::number(s->get_index()));
}

Some files were not shown because too many files have changed in this diff Show More