2
0
forked from Ivasoft/DSView

add support for path with chinese characters

This commit is contained in:
DreamSourceLab
2015-06-24 22:07:09 +08:00
parent 4348c2a895
commit 8ffa3c9119
29 changed files with 280 additions and 139 deletions

View File

@@ -357,10 +357,14 @@ install(FILES res/DSLogicPro.fw DESTINATION bin/res/)
install(FILES res/DSLogicPro.bin DESTINATION bin/res/)
install(FILES res/DSCope.fw DESTINATION bin/res/)
install(FILES res/DSCope.bin DESTINATION bin/res/)
install(FILES res/DSLogic_ini.dsc DESTINATION bin/res/)
install(FILES res/DSLogic_ini.dsc.bak DESTINATION bin/res/)
install(FILES res/DSCope_ini.dsc DESTINATION bin/res/)
install(FILES res/DSCope_ini.dsc.bak DESTINATION bin/res/)
install(FILES res/DSLogic0.dsc DESTINATION bin/res/)
install(FILES res/DSLogic0.def.dsc DESTINATION bin/res/)
install(FILES res/DSLogic1.dsc DESTINATION bin/res/)
install(FILES res/DSLogic1.def.dsc DESTINATION bin/res/)
install(FILES res/DSLogic2.dsc DESTINATION bin/res/)
install(FILES res/DSLogic2.def.dsc DESTINATION bin/res/)
install(FILES res/DSCope1.dsc DESTINATION bin/res/)
install(FILES res/DSCope1.def.dsc DESTINATION bin/res/)
#===============================================================================
#= Packaging (handled by CPack)

View File

@@ -64,7 +64,7 @@ void Device::release()
sr_dev_close(_sdi);
}
std::string Device::format_device_title() const
QString Device::format_device_title() const
{
ostringstream s;
@@ -86,7 +86,7 @@ std::string Device::format_device_title() const
if (_sdi->version && _sdi->version[0])
s << _sdi->version;
return s.str();
return QString::fromStdString(s.str());
}
bool Device::is_trigger_enabled() const

View File

@@ -38,7 +38,7 @@ public:
void release();
std::string format_device_title() const;
QString format_device_title() const;
bool is_trigger_enabled() const;

View File

@@ -59,7 +59,7 @@ public:
SigSession* owner() const;
virtual std::string format_device_title() const = 0;
virtual QString format_device_title() const = 0;
GVariant* get_config(const sr_channel *ch, const sr_channel_group *group, int key);

View File

@@ -32,19 +32,19 @@ using std::string;
namespace pv {
namespace device {
File::File(const std::string path) :
File::File(QString path) :
_path(path)
{
}
std::string File::format_device_title() const
QString File::format_device_title() const
{
return boost::filesystem::path(_path).filename().string();
return _path;
}
File* File::create(const string &name)
File* File::create(QString name)
{
if (sr_session_load(name.c_str()) == SR_OK) {
if (sr_session_load(name.toLocal8Bit().data()) == SR_OK) {
GSList *devlist = NULL;
sr_session_dev_list(&devlist);
sr_session_destroy();

View File

@@ -32,16 +32,16 @@ namespace device {
class File : public DevInst
{
protected:
File(const std::string path);
File(QString path);
public:
static File* create(const std::string &name);
static File* create(QString name);
public:
std::string format_device_title() const;
QString format_device_title() const;
protected:
const std::string _path;
const QString _path;
};
} // device

View File

@@ -34,7 +34,7 @@ using std::string;
namespace pv {
namespace device {
InputFile::InputFile(const std::string &path) :
InputFile::InputFile(QString path) :
File(path),
_input(NULL)
{
@@ -71,8 +71,7 @@ void InputFile::release()
_input = NULL;
}
sr_input_format* InputFile::determine_input_file_format(
const string &filename)
sr_input_format* InputFile::determine_input_file_format(const QString filename)
{
int i;
@@ -85,7 +84,7 @@ sr_input_format* InputFile::determine_input_file_format(
/* Otherwise, try to find an input module that can handle this file. */
for (i = 0; inputs[i]; i++) {
if (inputs[i]->format_match(filename.c_str()))
if (inputs[i]->format_match(filename.toLocal8Bit().data()))
break;
}
@@ -98,19 +97,19 @@ sr_input_format* InputFile::determine_input_file_format(
return inputs[i];
}
sr_input* InputFile::load_input_file_format(const string &filename,
sr_input* InputFile::load_input_file_format(const QString filename,
sr_input_format *format)
{
struct stat st;
sr_input *in;
if (!format && !(format =
determine_input_file_format(filename.c_str()))) {
determine_input_file_format(filename))) {
/* The exact cause was already logged. */
throw tr("Failed to load file");
}
if (stat(filename.c_str(), &st) == -1)
if (stat(filename.toLocal8Bit().data(), &st) == -1)
throw tr("Failed to load file");
/* Initialize the input module. */
@@ -121,7 +120,7 @@ sr_input* InputFile::load_input_file_format(const string &filename,
in->format = format;
in->param = NULL;
if (in->format->init &&
in->format->init(in, filename.c_str()) != SR_OK) {
in->format->init(in, filename.toLocal8Bit().data()) != SR_OK) {
throw tr("Failed to load file");
}
@@ -137,7 +136,7 @@ void InputFile::run()
assert(_input);
assert(_input->format);
assert(_input->format->loadfile);
_input->format->loadfile(_input, _path.c_str());
_input->format->loadfile(_input, _path.toLocal8Bit().data());
}
} // device

View File

@@ -35,7 +35,7 @@ namespace device {
class InputFile : public File
{
public:
InputFile(const std::string &path);
InputFile(QString path);
sr_dev_inst* dev_inst() const;
@@ -55,9 +55,9 @@ private:
* or NULL if no input format was selected or auto-detected.
*/
static sr_input_format* determine_input_file_format(
const std::string &filename);
const QString filename);
static sr_input* load_input_file_format(const std::string &filename,
static sr_input* load_input_file_format(const QString filename,
sr_input_format *format);
private:
sr_input *_input;

View File

@@ -26,7 +26,7 @@
namespace pv {
namespace device {
SessionFile::SessionFile(const std::string &path) :
SessionFile::SessionFile(QString path) :
File(path),
_sdi(NULL)
{
@@ -41,7 +41,7 @@ void SessionFile::use(SigSession *owner) throw(QString)
{
assert(!_sdi);
if (sr_session_load(_path.c_str()) != SR_OK)
if (sr_session_load(_path.toLocal8Bit().data()) != SR_OK)
throw tr("Failed to open file.\n");
GSList *devlist = NULL;

View File

@@ -30,7 +30,7 @@ namespace device {
class SessionFile : public File
{
public:
SessionFile(const std::string &path);
SessionFile(QString path);
sr_dev_inst* dev_inst() const;

View File

@@ -106,8 +106,9 @@ std::list<boost::shared_ptr<device::DevInst> > DeviceManager::driver_scan(
QDir dir(QCoreApplication::applicationDirPath());
if (!dir.cd("res"))
return driver_devices;
std::string str = dir.absolutePath().toStdString() + "/";
strcpy(config_path, str.c_str());
QString str = dir.absolutePath() + "/";
QString str_utf8 = QString::fromLocal8Bit(str.toLocal8Bit());
strcpy(config_path, str_utf8.toUtf8().data());
}
// Do the scan

View File

@@ -318,7 +318,7 @@ void MainWindow::update_device_list()
if (strcmp(selected_device->dev_inst()->driver->name, "demo") != 0) {
_logo_bar->dsl_connected(true);
QString ses_name = config_path +
QString::fromLocal8Bit(selected_device->dev_inst()->driver->name) +
QString::fromUtf8(selected_device->dev_inst()->driver->name) +
QString::number(selected_device->dev_inst()->mode) +
".dsc";
load_session(ses_name);
@@ -336,7 +336,8 @@ void MainWindow::reload()
void MainWindow::load_file(QString file_name)
{
try {
_session.set_file(file_name.toStdString());
//_session.set_file(file_name.toStdString());
_session.set_file(file_name);
} catch(QString e) {
show_session_error(tr("Failed to load ") + file_name, e);
_session.set_default_device(boost::bind(&MainWindow::session_error, this,
@@ -571,7 +572,7 @@ void MainWindow::on_save()
bool MainWindow::load_session(QString name)
{
QFile sessionFile(name.toStdString().c_str());
QFile sessionFile(name);
if (!sessionFile.open(QIODevice::ReadOnly)) {
QMessageBox msg(this);
msg.setText(tr("File Error"));
@@ -582,8 +583,8 @@ bool MainWindow::load_session(QString name)
return false;
}
QByteArray sessionData = sessionFile.readAll();
QJsonDocument sessionDoc = QJsonDocument::fromJson(sessionData);
QString sessionData = QString::fromUtf8(sessionFile.readAll());
QJsonDocument sessionDoc = QJsonDocument::fromJson(sessionData.toUtf8());
QJsonObject sessionObj = sessionDoc.object();
// check device and mode
@@ -617,7 +618,7 @@ bool MainWindow::load_session(QString name)
else if (info->datatype == SR_T_FLOAT)
_session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_double(sessionObj[info->name].toDouble()));
else if (info->datatype == SR_T_CHAR)
_session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toLocal8Bit()));
_session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toUtf8()));
}
}
_sampling_bar->update_record_length();
@@ -680,8 +681,8 @@ bool MainWindow::load_session(QString name)
bool MainWindow::store_session(QString name)
{
QFile sessionFile(name.toStdString().c_str());
if (!sessionFile.open(QIODevice::WriteOnly)) {
QFile sessionFile(name);
if (!sessionFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox msg(this);
msg.setText(tr("File Error"));
msg.setInformativeText(tr("Couldn't open session file to write!"));
@@ -690,6 +691,9 @@ bool MainWindow::store_session(QString name)
msg.exec();
return false;
}
QTextStream outStream(&sessionFile);
outStream.setCodec("UTF-8");
outStream.setGenerateByteOrderMark(true);
GVariant *gvar_opts;
GVariant *gvar;
@@ -748,8 +752,11 @@ bool MainWindow::store_session(QString name)
sessionVar["trigger"] = _trigger_widget->get_session();
}
QJsonDocument sessionDoc(sessionVar);
sessionFile.write(sessionDoc.toJson());
//sessionFile.write(QString::fromUtf8(sessionDoc.toJson()));
outStream << QString::fromUtf8(sessionDoc.toJson());
sessionFile.close();
return true;
}

View File

@@ -66,7 +66,7 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) :
if(sr_config_list(_sdi->driver, _sdi, NULL, key, &gvar_list) != SR_OK)
gvar_list = NULL;
const QString name(info->name);
const QString name(info->label);
switch(key)
{
@@ -194,11 +194,11 @@ QString DeviceOptions::print_gvariant(GVariant *const gvar)
QString s;
if (g_variant_is_of_type(gvar, G_VARIANT_TYPE("s")))
s = QString(g_variant_get_string(gvar, NULL));
s = QString::fromUtf8(g_variant_get_string(gvar, NULL));
else
{
gchar *const text = g_variant_print(gvar, FALSE);
s = QString(text);
s = QString::fromUtf8(text);
g_free(text);
}

View File

@@ -47,7 +47,7 @@ QWidget* String::get_widget(QWidget *parent, bool auto_commit)
_line_edit = new QLineEdit(parent);
_line_edit->setText(QString::fromUtf8(
g_variant_get_string(value, NULL)));
g_variant_get_string(value, NULL)));
g_variant_unref(value);
if (auto_commit)
@@ -65,7 +65,7 @@ void String::commit()
return;
QByteArray ba = _line_edit->text().toLocal8Bit();
_setter(g_variant_new_string(ba.data()));
_setter(g_variant_new_string(ba.data()));
}
void String::on_text_edited(const QString&)

View File

@@ -158,7 +158,8 @@ void SigSession::set_device(boost::shared_ptr<device::DevInst> dev_inst) throw(Q
}
}
void SigSession::set_file(const string &name) throw(QString)
void SigSession::set_file(QString name) throw(QString)
{
// Deslect the old device, because file type detection in File::create
// destorys the old session inside libsigrok.
@@ -176,7 +177,7 @@ void SigSession::set_file(const string &name) throw(QString)
}
}
void SigSession::save_file(const std::string &name){
void SigSession::save_file(const QString name){
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
_logic_data->get_snapshots();
if (snapshots.empty())
@@ -185,7 +186,7 @@ void SigSession::save_file(const std::string &name){
const boost::shared_ptr<pv::data::LogicSnapshot> &snapshot =
snapshots.front();
sr_session_save(name.c_str(), _dev_inst->dev_inst(),
sr_session_save(name.toLocal8Bit().data(), _dev_inst->dev_inst(),
(unsigned char*)snapshot->get_data(),
snapshot->unit_size(),
snapshot->get_sample_count());
@@ -213,7 +214,7 @@ void SigSession::cancelSaveFile(){
saveFileThreadRunning = false;
}
void SigSession::export_file(const std::string &name, QWidget* parent, const std::string &ext){
void SigSession::export_file(const QString name, QWidget* parent, const QString ext){
boost::shared_ptr<pv::data::Snapshot> snapshot;
int channel_type;
@@ -240,7 +241,7 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
while(*supportedModules){
if(*supportedModules == NULL)
break;
if(!strcmp((*supportedModules)->id, ext.c_str())){
if(!strcmp((*supportedModules)->id, ext.toLocal8Bit().data())){
outModule = *supportedModules;
break;
}
@@ -251,7 +252,7 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
GHashTable *params = g_hash_table_new(g_str_hash, g_str_equal);
GVariant* filenameGVariant = g_variant_new_string(name.c_str());
GVariant* filenameGVariant = g_variant_new_bytestring(name.toLocal8Bit().data());
g_hash_table_insert(params, (char*)"filename", filenameGVariant);
GVariant* typeGVariant = g_variant_new_int16(channel_type);
g_hash_table_insert(params, (char*)"type", typeGVariant);
@@ -270,9 +271,11 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
output.param = NULL;
if(outModule->init)
outModule->init(&output, params);
QFile file(name.c_str());
QFile file(name);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out.setCodec("UTF-8");
out.setGenerateByteOrderMark(true);
QFuture<void> future;
if (_dev_inst->dev_inst()->mode == LOGIC) {
future = QtConcurrent::run([&]{
@@ -294,7 +297,7 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
p.payload = &lp;
outModule->receive(&output, &p, &data_out);
if(data_out){
out << (char*) data_out->str;
out << QString::fromUtf8((char*) data_out->str);
g_string_free(data_out,TRUE);
}
emit progressSaveFileValueChanged(i*100/numsamples);
@@ -333,8 +336,8 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
QFutureWatcher<void> watcher;
Qt::WindowFlags flags = Qt::CustomizeWindowHint;
QProgressDialog dlg(QString::fromUtf8("Exporting data... It can take a while."),
QString::fromUtf8("Cancel"),0,100,parent,flags);
QProgressDialog dlg(tr("Exporting data... It can take a while."),
tr("Cancel"),0,100,parent,flags);
dlg.setWindowModality(Qt::WindowModal);
watcher.setFuture(future);
connect(&watcher,SIGNAL(finished()),&dlg,SLOT(cancel()));
@@ -832,9 +835,9 @@ void SigSession::refresh(int holdtime)
_analog_data->clear();
_cur_analog_snapshot.reset();
}
data_updated();
_data_lock = true;
_refresh_timer.start(holdtime);
data_updated();
}
void SigSession::data_unlock()

View File

@@ -114,13 +114,13 @@ public:
void set_device(boost::shared_ptr<device::DevInst> dev_inst)
throw(QString);
void set_file(const std::string &name)
void set_file(QString name)
throw(QString);
void save_file(const std::string &name);
void save_file(const QString name);
void set_default_device(boost::function<void (const QString)> error_handler);
void export_file(const std::string &name, QWidget* parent, const std::string &ext);
void export_file(const QString name, QWidget* parent, const QString ext);
void set_default_device();

View File

@@ -182,7 +182,7 @@ void FileBar::on_actionExport_triggered(){
QString ext = list.first();
if(f.suffix().compare(ext))
file_name+=tr(".")+ext;
_session.export_file(file_name.toStdString(), this, ext.toStdString());
_session.export_file(file_name, this, ext);
}
}
}
@@ -215,7 +215,7 @@ void FileBar::on_actionSave_triggered()
QFileInfo f(file_name);
if(f.suffix().compare("dsl"))
file_name.append(tr(".dsl"));
_session.save_file(file_name.toStdString());
_session.save_file(file_name);
}
}
}

View File

@@ -173,7 +173,7 @@ void SamplingBar::set_device_list(
BOOST_FOREACH (shared_ptr<pv::device::DevInst> dev_inst, devices) {
assert(dev_inst);
const string title = dev_inst->format_device_title();
const QString title = dev_inst->format_device_title();
const void *id = dev_inst->get_id();
assert(id);
@@ -181,7 +181,7 @@ void SamplingBar::set_device_list(
selected_index = _device_selector.count();
_device_selector_map[id] = dev_inst;
_device_selector.addItem(title.c_str(),
_device_selector.addItem(title,
qVariantFromValue((void*)id));
}

View File

@@ -1,18 +1,18 @@
{
{
"Device": "DSCope",
"DeviceMode": 1,
"Horizontal trigger position": "0",
"Operation Mode": "Normal",
"Sample count": "1048576",
"Sample rate": "50000",
"Time base": "2000000000",
"Sample rate": "100000000",
"Time base": "10000",
"Trigger hold off": "0",
"Trigger slope": "0",
"Trigger source": "0",
"channel": [
{
"colour": "#eeb211",
"coupling": 1,
"coupling": 0,
"enabled": true,
"index": 0,
"name": "0",

View File

@@ -1,4 +1,4 @@
{
{
"Device": "DSLogic",
"DeviceMode": 0,
"Filter Targets": "None",
@@ -6,13 +6,53 @@
"Operation Mode": "Normal",
"Sample count": "16777216",
"Sample rate": "100000000",
"Threshold Level": "1.8/2.5/3.3V Level",
"Threshold Level": 1,
"Trigger hold off": "0",
"Trigger slope": "0",
"Trigger source": "0",
"Using Clock Negedge": 0,
"Using External Clock": 0,
"channel": [
{
"colour": "#16191a",
"enabled": true,
"index": 0,
"name": "0",
"strigger": 0,
"type": 10000
},
{
"colour": "#8f5202",
"enabled": true,
"index": 1,
"name": "1",
"strigger": 0,
"type": 10000
},
{
"colour": "#cc0000",
"enabled": true,
"index": 2,
"name": "2",
"strigger": 0,
"type": 10000
},
{
"colour": "#f57900",
"enabled": true,
"index": 3,
"name": "3",
"strigger": 0,
"type": 10000
},
{
"colour": "#edd400",
"enabled": true,
"index": 4,
"name": "4",
"strigger": 0,
"type": 10000
},
{
"colour": "#73d216",
"enabled": true,
@@ -21,6 +61,62 @@
"strigger": 0,
"type": 10000
},
{
"colour": "#3465a4",
"enabled": true,
"index": 6,
"name": "6",
"strigger": 0,
"type": 10000
},
{
"colour": "#75507b",
"enabled": true,
"index": 7,
"name": "7",
"strigger": 0,
"type": 10000
},
{
"colour": "#16191a",
"enabled": true,
"index": 8,
"name": "8",
"strigger": 0,
"type": 10000
},
{
"colour": "#8f5202",
"enabled": true,
"index": 9,
"name": "9",
"strigger": 0,
"type": 10000
},
{
"colour": "#cc0000",
"enabled": true,
"index": 10,
"name": "10",
"strigger": 0,
"type": 10000
},
{
"colour": "#f57900",
"enabled": true,
"index": 11,
"name": "11",
"strigger": 0,
"type": 10000
},
{
"colour": "#edd400",
"enabled": true,
"index": 12,
"name": "12",
"strigger": 0,
"type": 10000
},
{
"colour": "#73d216",
"enabled": true,
@@ -28,6 +124,22 @@
"name": "13",
"strigger": 0,
"type": 10000
},
{
"colour": "#3465a4",
"enabled": true,
"index": 14,
"name": "14",
"strigger": 0,
"type": 10000
},
{
"colour": "#75507b",
"enabled": true,
"index": 15,
"name": "15",
"strigger": 0,
"type": 10000
}
],
"trigger": {

View File

@@ -348,7 +348,7 @@ static int fpga_config(struct libusb_device_handle *hdl, const char *filename)
struct stat f_stat;
sr_info("Configure FPGA using %s", filename);
if ((fw = fopen(filename, "rb")) == NULL) {
if ((fw = g_fopen(filename, "rb")) == NULL) {
sr_err("Unable to open FPGA bit file %s for reading: %s",
filename, strerror(errno));
return SR_ERR;
@@ -671,7 +671,7 @@ static GSList *scan(GSList *options)
src = l->data;
switch (src->key) {
case SR_CONF_CONN:
conn = g_variant_get_string(src->data, NULL);
conn = g_variant_get_string(src->data, NULL);
break;
}
}
@@ -741,9 +741,11 @@ static GSList *scan(GSList *options)
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
} else {
char filename[256];
sprintf(filename,"%s%s",config_path,prof->firmware);
const char *firmware = filename;
char *firmware = malloc(strlen(config_path)+strlen(prof->firmware)+1);
if (firmware == NULL)
return NULL;
strcpy(firmware, config_path);
strcat(firmware, prof->firmware);
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
firmware) == SR_OK)
/* Store when this device's FW was updated. */
@@ -987,10 +989,11 @@ static int dev_open(struct sr_dev_inst *sdi)
} else {
/* Takes >= 10ms for the FX2 to be ready for FPGA configure. */
g_usleep(10 * 1000);
char filename[256];
sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit33);
const char *fpga_bit = filename;
char *fpga_bit = malloc(strlen(config_path)+strlen(devc->profile->fpga_bit33)+1);
if (fpga_bit == NULL)
return SR_ERR_MALLOC;
strcpy(fpga_bit, config_path);
strcat(fpga_bit, devc->profile->fpga_bit33);
ret = fpga_config(usb->devhdl, fpga_bit);
if (ret != SR_OK) {
sr_err("Configure FPGA failed!");
@@ -1142,7 +1145,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
* upload, so we don't know its (future) address. */
return SR_ERR;
snprintf(str, 128, "%d.%d", usb->bus, usb->address);
*data = g_variant_new_string(str);
*data = g_variant_new_string(str);
break;
case SR_CONF_LIMIT_SAMPLES:
if (!sdi)
@@ -1404,9 +1407,14 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
} else {
/* Takes >= 10ms for the FX2 to be ready for FPGA configure. */
g_usleep(10 * 1000);
char filename[256];
sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit33);
const char *fpga_bit = filename;
//char filename[256];
//sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit33);
//const char *fpga_bit = filename;
char *fpga_bit = malloc(strlen(config_path)+strlen(devc->profile->fpga_bit33)+1);
if (fpga_bit == NULL)
return SR_ERR_MALLOC;
strcpy(fpga_bit, config_path);
strcat(fpga_bit, devc->profile->fpga_bit33);
ret = fpga_config(usb->devhdl, fpga_bit);
if (ret != SR_OK) {
sr_err("Configure FPGA failed!");
@@ -1630,7 +1638,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_TRIGGER_TYPE:
*data = g_variant_new_string(TRIGGER_TYPE);
*data = g_variant_new_string(TRIGGER_TYPE);
break;
case SR_CONF_OPERATION_MODE:
*data = g_variant_new_strv(opmodes, ARRAY_SIZE(opmodes));

View File

@@ -415,7 +415,7 @@ static int fpga_config(struct libusb_device_handle *hdl, const char *filename)
struct stat f_stat;
sr_info("Configure FPGA using %s", filename);
if ((fw = fopen(filename, "rb")) == NULL) {
if ((fw = g_fopen(filename, "rb")) == NULL) {
sr_err("Unable to open FPGA bit file %s for reading: %s",
filename, strerror(errno));
return SR_ERR;
@@ -740,7 +740,7 @@ static GSList *scan(GSList *options)
src = l->data;
switch (src->key) {
case SR_CONF_CONN:
conn = g_variant_get_string(src->data, NULL);
conn = g_variant_get_string(src->data, NULL);
break;
}
}
@@ -811,9 +811,11 @@ static GSList *scan(GSList *options)
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
} else {
char filename[256];
sprintf(filename,"%s%s",config_path,prof->firmware);
const char *firmware = filename;
char *firmware = malloc(strlen(config_path)+strlen(prof->firmware)+1);
if (firmware == NULL)
return NULL;
strcpy(firmware, config_path);
strcat(firmware, prof->firmware);
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
firmware) == SR_OK)
/* Store when this device's FW was updated. */
@@ -1057,18 +1059,20 @@ static int dev_open(struct sr_dev_inst *sdi)
} else {
/* Takes >= 10ms for the FX2 to be ready for FPGA configure. */
g_usleep(10 * 1000);
char filename[256];
char *fpga_bit = malloc(strlen(config_path)+strlen(devc->profile->fpga_bit33)+1);
if (fpga_bit == NULL)
return SR_ERR_MALLOC;
strcpy(fpga_bit, config_path);
switch(devc->th_level) {
case SR_TH_3V3:
sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit33);
strcat(fpga_bit, devc->profile->fpga_bit33);;
break;
case SR_TH_5V0:
sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit50);
strcat(fpga_bit, devc->profile->fpga_bit50);;
break;
default:
return SR_ERR;
}
const char *fpga_bit = filename;
ret = fpga_config(usb->devhdl, fpga_bit);
if (ret != SR_OK) {
sr_err("Configure FPGA failed!");
@@ -1141,7 +1145,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
* upload, so we don't know its (future) address. */
return SR_ERR;
snprintf(str, 128, "%d.%d", usb->bus, usb->address);
*data = g_variant_new_string(str);
*data = g_variant_new_string(str);
break;
case SR_CONF_LIMIT_SAMPLES:
if (!sdi)
@@ -1517,18 +1521,20 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
} else {
/* Takes >= 10ms for the FX2 to be ready for FPGA configure. */
g_usleep(10 * 1000);
char filename[256];
char *fpga_bit = malloc(strlen(config_path)+strlen(devc->profile->fpga_bit33)+1);
if (fpga_bit == NULL)
return SR_ERR_MALLOC;
strcpy(fpga_bit, config_path);
switch(devc->th_level) {
case SR_TH_3V3:
sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit33);
strcat(fpga_bit, devc->profile->fpga_bit33);;
break;
case SR_TH_5V0:
sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit50);
strcat(fpga_bit, devc->profile->fpga_bit50);;
break;
default:
return SR_ERR;
}
const char *fpga_bit = filename;
ret = fpga_config(usb->devhdl, fpga_bit);
if (ret != SR_OK) {
sr_err("Configure FPGA failed!");
@@ -1545,7 +1551,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
else
sr_dbg("%s: setting threshold voltage to %d failed",
__func__, devc->vth);
} else if (id == SR_CONF_FILTER) {
} else if (id == SR_CONF_FILTER) {
stropt = g_variant_get_string(data, NULL);
ret = SR_OK;
if (!strcmp(stropt, filters[SR_FILTER_NONE])) {
@@ -1589,8 +1595,10 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
__func__, ch->index, ch->vdiv);
} else if (id == SR_CONF_FACTOR) {
ch->vfactor = g_variant_get_uint64(data);
ret = SR_OK;
} else if (id == SR_CONF_TIMEBASE) {
devc->timebase = g_variant_get_uint64(data);
ret = SR_OK;
} else if (id == SR_CONF_COUPLING) {
ch->coupling = g_variant_get_byte(data);
if (ch->coupling == SR_GND_COUPLING)
@@ -1672,6 +1680,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
__func__, devc->trigger_holdoff);
} else if (id == SR_CONF_ZERO) {
devc->zero = g_variant_get_boolean(data);
ret = SR_OK;
} else if (id == SR_CONF_ZERO_SET) {
GSList *l;
for(l = sdi->channels; l; l = l->next) {
@@ -1759,7 +1768,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_TRIGGER_TYPE:
*data = g_variant_new_string(TRIGGER_TYPE);
*data = g_variant_new_string(TRIGGER_TYPE);
break;
case SR_CONF_OPERATION_MODE:
*data = g_variant_new_strv(opmodes, ARRAY_SIZE(opmodes));
@@ -2536,9 +2545,6 @@ static int dev_status_get(struct sr_dev_inst *sdi, struct sr_status *status, int
ret = command_get_status(usb->devhdl, (unsigned char*)status, begin, end);
}
if (ret != SR_OK)
sr_err("Device don't exist!");
return ret;
} else {
return SR_ERR;

View File

@@ -52,54 +52,54 @@
static struct sr_config_info sr_config_info_data[] = {
{SR_CONF_CONN, SR_T_CHAR, "conn",
"Connection", NULL},
"Connection", "Connection", NULL},
{SR_CONF_SERIALCOMM, SR_T_CHAR, "serialcomm",
"Serial communication", NULL},
"Serial communication", "Serial communication", NULL},
{SR_CONF_SAMPLERATE, SR_T_UINT64, "samplerate",
"Sample rate", NULL},
"Sample rate", "Sample rate", NULL},
{SR_CONF_LIMIT_SAMPLES, SR_T_UINT64, "samplecount",
"Sample count", NULL},
"Sample count", "Sample count", NULL},
{SR_CONF_CLOCK_TYPE, SR_T_BOOL, "clocktype",
"Using External Clock", NULL},
"Using External Clock", "Using External Clock", NULL},
{SR_CONF_CLOCK_EDGE, SR_T_BOOL, "clockedge",
"Using Clock Negedge", NULL},
"Using Clock Negedge", "Using Clock Negedge", NULL},
{SR_CONF_CAPTURE_RATIO, SR_T_UINT64, "captureratio",
"Pre-trigger capture ratio", NULL},
"Pre-trigger capture ratio", "Pre-trigger capture ratio", NULL},
{SR_CONF_PATTERN_MODE, SR_T_CHAR, "pattern",
"Pattern mode", NULL},
"Pattern mode", "Pattern mode", NULL},
{SR_CONF_TRIGGER_TYPE, SR_T_CHAR, "triggertype",
"Trigger types", NULL},
"Trigger types", "Trigger types", NULL},
{SR_CONF_RLE, SR_T_BOOL, "rle",
"Run Length Encoding", NULL},
"Run Length Encoding", "Run Length Encoding", NULL},
{SR_CONF_TRIGGER_SLOPE, SR_T_UINT8, "triggerslope",
"Trigger slope", NULL},
"Trigger slope", "Trigger slope", NULL},
{SR_CONF_TRIGGER_SOURCE, SR_T_UINT8, "triggersource",
"Trigger source", NULL},
"Trigger source", "Trigger source", NULL},
{SR_CONF_HORIZ_TRIGGERPOS, SR_T_UINT8, "horiz_triggerpos",
"Horizontal trigger position", NULL},
"Horizontal trigger position", "Horizontal trigger position", NULL},
{SR_CONF_TRIGGER_HOLDOFF, SR_T_UINT64, "triggerholdoff",
"Trigger hold off", NULL},
"Trigger hold off", "Trigger hold off", NULL},
{SR_CONF_BUFFERSIZE, SR_T_UINT64, "buffersize",
"Buffer size", NULL},
"Buffer size", "Buffer size", NULL},
{SR_CONF_TIMEBASE, SR_T_UINT64, "timebase",
"Time base", NULL},
"Time base", "Time base", NULL},
{SR_CONF_FILTER, SR_T_CHAR, "filter",
"Filter Targets", NULL},
"Filter Targets", "Filter Targets", NULL},
{SR_CONF_VDIV, SR_T_RATIONAL_VOLT, "vdiv",
"Volts/div", NULL},
"Volts/div", "Volts/div", NULL},
{SR_CONF_VDIV, SR_T_RATIONAL_VOLT, "factor",
"Probe Factor", NULL},
"Probe Factor", "Probe Factor", NULL},
{SR_CONF_COUPLING, SR_T_CHAR, "coupling",
"Coupling", NULL},
"Coupling", "Coupling", NULL},
{SR_CONF_DATALOG, SR_T_BOOL, "datalog",
"Datalog", NULL},
"Datalog", "Datalog", NULL},
{SR_CONF_OPERATION_MODE, SR_T_CHAR, "operation",
"Operation Mode", NULL},
"Operation Mode", "Operation Mode", NULL},
{SR_CONF_THRESHOLD, SR_T_CHAR, "threshold",
"Threshold Level", NULL},
"Threshold Level", "Threshold Level", NULL},
{SR_CONF_VTH, SR_T_FLOAT, "threshold",
"Threshold Level", NULL},
{0, 0, NULL, NULL, NULL},
"Threshold Level", "Threshold Level", NULL},
{0, 0, NULL, NULL, NULL, NULL},
};
/** @cond PRIVATE */

View File

@@ -299,7 +299,7 @@ static int format_match(const char *filename)
gchar *name = NULL, *contents = NULL;
gboolean status;
file = fopen(filename, "r");
file = g_fopen(filename, "r");
if (file == NULL)
return FALSE;
@@ -564,7 +564,7 @@ static int loadfile(struct sr_input *in, const char *filename)
ctx = in->internal;
if ((file = fopen(filename, "r")) == NULL)
if ((file = g_fopen(filename, "r")) == NULL)
return SR_ERR;
if (!parse_header(file, ctx))

View File

@@ -590,6 +590,7 @@ struct sr_config_info {
int datatype;
char *id;
char *name;
char *label;
char *description;
};

View File

@@ -41,7 +41,7 @@ static int init(struct sr_output *o, GHashTable *options)
outc = g_malloc0(sizeof(struct out_context));
o->priv = outc;
outc->filename = g_strdup(g_variant_get_string(g_hash_table_lookup(options, "filename"), NULL));
outc->filename = g_strdup(g_variant_get_bytestring(g_hash_table_lookup(options, "filename")));
if (strlen(outc->filename) == 0)
return SR_ERR_ARG;
@@ -303,7 +303,7 @@ static struct sr_option options[] = {
static const struct sr_option *get_options(void)
{
if (!options[0].def)
options[0].def = g_variant_ref_sink(g_variant_new_string(""));
options[0].def = g_variant_ref_sink(g_variant_new_string(""));
return options;
}

View File

@@ -203,11 +203,11 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
sr_info("Setting samplerate to %" PRIu64 ".", vdev->samplerate);
break;
case SR_CONF_SESSIONFILE:
vdev->sessionfile = g_strdup(g_variant_get_string(data, NULL));
vdev->sessionfile = g_strdup(g_variant_get_bytestring(data));
sr_info("Setting sessionfile to '%s'.", vdev->sessionfile);
break;
case SR_CONF_CAPTUREFILE:
vdev->capturefile = g_strdup(g_variant_get_string(data, NULL));
vdev->capturefile = g_strdup(g_variant_get_bytestring(data));
sr_info("Setting capturefile to '%s'.", vdev->capturefile);
break;
case SR_CONF_CAPTURE_UNITSIZE:

View File

@@ -182,9 +182,9 @@ SR_API int sr_session_load(const char *filename)
sr_dev_open(sdi);
sr_session_dev_add(sdi);
sdi->driver->config_set(SR_CONF_SESSIONFILE,
g_variant_new_string(filename), sdi, NULL, NULL);
g_variant_new_bytestring(filename), sdi, NULL, NULL);
sdi->driver->config_set(SR_CONF_CAPTUREFILE,
g_variant_new_string(val), sdi, NULL, NULL);
g_variant_new_bytestring(val), sdi, NULL, NULL);
g_ptr_array_add(capturefiles, val);
} else if (!strcmp(keys[j], "samplerate")) {
sr_parse_sizestring(val, &tmp_u64);

View File

@@ -338,7 +338,7 @@ SR_API char **sr_parse_triggerstring(const struct sr_dev_inst *sdi,
sr_err("%s: Device doesn't support any triggers.", __func__);
return NULL;
}
trigger_types = g_variant_get_string(gvar, NULL);
trigger_types = g_variant_get_string(gvar, NULL);
tokens = g_strsplit(triggerstring, ",", max_probes);
for (i = 0; tokens[i]; i++) {