Skip to content
Permalink
Browse files

add basic Vector ASC export

  • Loading branch information...
HubertD committed Jul 12, 2016
1 parent 660fbb2 commit 71f5d5edeaa98a296e97b45a5862b00e06d81962
@@ -163,11 +163,6 @@ void Backend::setSetup(MeasurementSetup &new_setup)
_setup.cloneFrom(new_setup);
}

void Backend::saveCanDump(QString filename)
{
_trace->saveCanDump(filename);
}

double Backend::currentTimeStamp() const
{
return ((double)QDateTime::currentMSecsSinceEpoch()) / 1000;
@@ -65,7 +65,6 @@ class Backend : public QObject
void loadDefaultSetup(MeasurementSetup &setup);
void setDefaultSetup();
void setSetup(MeasurementSetup &new_setup);
void saveCanDump(QString filename);

double currentTimeStamp() const;

@@ -284,6 +284,11 @@ double CanMessage::getFloatTimestamp() const
return (double)_timestamp.tv_sec + ((double)_timestamp.tv_usec/1000000);
}

QDateTime CanMessage::getDateTime() const
{
return QDateTime::fromMSecsSinceEpoch((qint64)(1000*getFloatTimestamp()));
}

QString CanMessage::getIdString() const
{
if (isExtended()) {
@@ -25,6 +25,7 @@
#include <sys/time.h>

#include <QString>
#include <QDateTime>
#include <driver/CanDriver.h>

class CanMessage {
@@ -75,6 +76,7 @@ class CanMessage {
void setTimestamp(const uint64_t seconds, const uint32_t micro_seconds);

double getFloatTimestamp() const;
QDateTime getDateTime() const;

QString getIdString() const;
QString getDataHexString() const;
@@ -130,29 +130,78 @@ void CanTrace::startTimer()
}
}

void CanTrace::saveCanDump(QString filename)
void CanTrace::saveCanDump(QFile &file)
{
QFile file(filename);
if (file.open(QIODevice::ReadWrite)) {
QMutexLocker locker(&_mutex);
QTextStream stream(&file);
for (unsigned int i=0; i<size(); i++) {
CanMessage *msg = &_data[i];
QString line;
line.append(QString().sprintf("(%.6f) ", msg->getFloatTimestamp()));
line.append(_backend.getInterfaceName(msg->getInterfaceId()));
if (msg->isExtended()) {
line.append(QString().sprintf(" %08X#", msg->getId()));
} else {
line.append(QString().sprintf(" %03X#", msg->getId()));
}
for (int i=0; i<msg->getLength(); i++) {
line.append(QString().sprintf("%02X", msg->getByte(i)));
}
stream << line << endl;
QMutexLocker locker(&_mutex);
QTextStream stream(&file);
for (unsigned int i=0; i<size(); i++) {
CanMessage *msg = &_data[i];
QString line;
line.append(QString().sprintf("(%.6f) ", msg->getFloatTimestamp()));
line.append(_backend.getInterfaceName(msg->getInterfaceId()));
if (msg->isExtended()) {
line.append(QString().sprintf(" %08X#", msg->getId()));
} else {
line.append(QString().sprintf(" %03X#", msg->getId()));
}
for (int i=0; i<msg->getLength(); i++) {
line.append(QString().sprintf("%02X", msg->getByte(i)));
}
stream << line << endl;
}
}

void CanTrace::saveVectorAsc(QFile &file)
{
QMutexLocker locker(&_mutex);
QTextStream stream(&file);

if (_data.length()<1) {
return;
}


auto firstMessage = _data.first();
double t_start = firstMessage.getFloatTimestamp();

QLocale locale_c(QLocale::C);
QString dt_start = locale_c.toString(firstMessage.getDateTime(), "ddd MMM dd hh:mm:ss.zzz ap yyyy");

stream << "date " << dt_start << endl;
stream << "base hex timestamps absolute" << endl;
stream << "internal events logged" << endl;
stream << "// version 8.5.0" << endl;
stream << "Begin Triggerblock " << dt_start << endl;
stream << " 0.000000 Start of measurement" << endl;

for (unsigned int i=0; i<size(); i++) {
CanMessage &msg = _data[i];

double t_current = msg.getFloatTimestamp();
QString id_hex_str = QString().sprintf("%x", msg.getId());
QString id_dec_str = QString().sprintf("%d", msg.getId());
if (msg.isExtended()) {
id_hex_str.append("x");
id_dec_str.append("x");
}
file.close();

// TODO how to handle RTR flag?
QString line = QString().sprintf(
"%11.6lf 1 %-15s %s d %d %s Length = %d BitCount = %d ID = %s",
t_current-t_start,
id_hex_str.toStdString().c_str(),
"Rx", // TODO handle Rx/Tx
msg.getLength(),
msg.getDataHexString().toStdString().c_str(),
0, // TODO Length (transfer time in ns)
0, // TODO BitCount (overall frame length, including stuff bits)
id_dec_str.toStdString().c_str()
);

stream << line << endl;
}

stream << "End TriggerBlock" << endl;
}

bool CanTrace::getMuxedSignalFromCache(const CanDbSignal *signal, uint32_t *raw_value)
@@ -26,6 +26,7 @@
#include <QTimer>
#include <QVector>
#include <QMap>
#include <QFile>

#include "CanMessage.h"

@@ -47,7 +48,8 @@ class CanTrace : public QObject
const CanMessage *getMessage(int idx);
void enqueueMessage(const CanMessage &msg, bool more_to_follow=false);

void saveCanDump(QString filename);
void saveCanDump(QFile &file);
void saveVectorAsc(QFile &file);

bool getMuxedSignalFromCache(const CanDbSignal *signal, uint32_t *raw_value);

@@ -29,6 +29,7 @@
#include <QDomDocument>

#include <core/MeasurementSetup.h>
#include <core/CanTrace.h>
#include <window/TraceWindow/TraceWindow.h>
#include <window/SetupDialog/SetupDialog.h>
#include <window/LogWindow/LogWindow.h>
@@ -427,10 +428,33 @@ void MainWindow::stopMeasurement()

void MainWindow::saveTraceToFile()
{
QString filename = QFileDialog::getSaveFileName(this, "Save Trace to file", "", "Candump Files (*.candump)");
if (!filename.isNull()) {
backend().saveCanDump(filename);
QString filters("Vector ASC (*.asc);;Linux candump (*.candump))");
QString defaultFilter("Vector ASC (*.asc)");

QFileDialog fileDialog(0, "Save Trace to file", QDir::currentPath(), filters);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setConfirmOverwrite(true);
fileDialog.selectNameFilter(defaultFilter);
fileDialog.setDefaultSuffix("asc");
if (fileDialog.exec()) {
QString filename = fileDialog.selectedFiles()[0];
QFile file(filename);
if (file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {

if (filename.endsWith(".candump", Qt::CaseInsensitive)) {
backend().getTrace()->saveCanDump(file);
} else {
backend().getTrace()->saveVectorAsc(file);
}

file.close();
} else {
// TODO error message
}


}

}


@@ -106,10 +106,10 @@ void BaseTraceViewModel::setTimestampMode(timestamp_mode_t timestampMode)

QVariant BaseTraceViewModel::formatTimestamp(timestamp_mode_t mode, const CanMessage &currentMsg, const CanMessage &lastMsg) const
{
double t_current = currentMsg.getFloatTimestamp();

if (mode==timestamp_mode_delta) {

double t_current = currentMsg.getFloatTimestamp();
double t_last = lastMsg.getFloatTimestamp();
if (t_last==0) {
return QVariant();
@@ -119,11 +119,11 @@ QVariant BaseTraceViewModel::formatTimestamp(timestamp_mode_t mode, const CanMes

} else if (mode==timestamp_mode_absolute) {

QDateTime dt = QDateTime::fromMSecsSinceEpoch((qint64)(1000*t_current));
return dt.toString("hh:mm:ss.zzz");
return currentMsg.getDateTime().toString("hh:mm:ss.zzz");

} else if (mode==timestamp_mode_relative) {

double t_current = currentMsg.getFloatTimestamp();
return QString().sprintf("%.04lf", t_current - backend()->getTimestampAtMeasurementStart());

}

0 comments on commit 71f5d5e

Please sign in to comment.
You can’t perform that action at this time.