24 #include <QFileDialog> 27 #include <QMessageBox> 29 #include <QVBoxLayout> 31 #include <libsigrokdecode/libsigrokdecode.h> 46 using std::shared_ptr;
50 namespace decoder_binary {
55 "Hex Dump, with offset",
61 ViewBase(session, is_main_view, parent),
65 decoder_selector_(new QComboBox()),
66 format_selector_(new QComboBox()),
67 class_selector_(new QComboBox()),
68 stacked_widget_(new QStackedWidget()),
71 save_action_(new QAction(
this)),
74 QVBoxLayout *root_layout =
new QVBoxLayout(
this);
75 root_layout->setContentsMargins(0, 0, 0, 0);
79 toolbar->setContextMenuPolicy(Qt::PreventContextMenu);
80 parent->addToolBar(toolbar);
83 toolbar->addWidget(
new QLabel(tr(
"Decoder:")));
86 toolbar->addSeparator();
87 toolbar->addWidget(
new QLabel(tr(
"Show data as")));
89 toolbar->addSeparator();
111 save_action_->setIcon(QIcon::fromTheme(
"document-save-as",
112 QIcon(
":/icons/document-save-as.png")));
113 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 114 save_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
116 save_action_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
121 QMenu *save_menu =
new QMenu();
122 connect(save_menu, SIGNAL(triggered(QAction*)),
126 QAction *
const action = save_menu->addAction(tr(SaveTypeNames[i]));
127 action->setData(QVariant::fromValue(i));
132 save_button_->setPopupMode(QToolButton::MenuButtonPopup);
149 return ViewTypeDecoderBinary;
166 ViewBase::clear_decode_signals();
174 ViewBase::add_decode_signal(signal);
176 connect(signal.get(), SIGNAL(name_changed(
const QString&)),
178 connect(signal.get(), SIGNAL(decoder_stacked(
void*)),
180 connect(signal.get(), SIGNAL(decoder_removed(
void*)),
184 auto stack = signal->decoder_stack();
185 if (stack.size() > 1) {
186 for (
const shared_ptr<Decoder>& dec : stack)
188 if (dec->get_binary_class_count() > 0) {
189 QString title = QString(
"%1 (%2)").arg(signal->name(), dec->name());
193 if (!stack.empty()) {
194 shared_ptr<Decoder>& dec = stack.at(0);
195 if (dec->get_binary_class_count() > 0)
196 decoder_selector_->addItem(signal->name(), QVariant::fromValue((
void*)dec.get()));
203 for (
const shared_ptr<Decoder>& dec : signal->decoder_stack()) {
210 ViewBase::remove_decode_signal(signal);
267 const QString dir = settings.value(
"MainWindow/SaveDirectory").toString();
269 const QString file_name = QFileDialog::getSaveFileName(
270 parent_, tr(
"Save Binary Data"), dir, tr(
"Binary Data Files (*.bin);;All Files (*)"));
272 if (file_name.isEmpty())
275 QFile
file(file_name);
276 if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
279 vector<uint8_t>
data;
280 data.resize(selection.second - selection.first + 1);
285 int64_t bytes_written = file.write((
const char*)data.data(), data.size());
287 if ((bytes_written == -1) || ((uint64_t)bytes_written != data.size())) {
289 msg.setText(tr(
"Error") +
"\n\n" + tr(
"File %1 could not be written to.").arg(file_name));
290 msg.setStandardButtons(QMessageBox::Ok);
291 msg.setIcon(QMessageBox::Warning);
307 const QString dir = settings.value(
"MainWindow/SaveDirectory").toString();
309 const QString file_name = QFileDialog::getSaveFileName(
310 parent_, tr(
"Save Binary Data"), dir, tr(
"Hex Dumps (*.txt);;All Files (*)"));
312 if (file_name.isEmpty())
315 QFile
file(file_name);
316 if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
319 vector<uint8_t>
data;
320 data.resize(selection.second - selection.first + 1);
325 QTextStream out_stream(&file);
327 uint64_t offset = selection.first;
331 while (offset < selection.second) {
332 size_t end =
std::min((uint64_t)(selection.second), offset + n);
334 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) 335 out_stream << s << Qt::endl;
337 out_stream << s << endl;
341 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) 342 out_stream << Qt::endl;
347 if (out_stream.status() != QTextStream::Ok) {
349 msg.setText(tr(
"Error") +
"\n\n" + tr(
"File %1 could not be written to.").arg(file_name));
350 msg.setStandardButtons(QMessageBox::Ok);
351 msg.setIcon(QMessageBox::Warning);
361 disconnect(
signal_, SIGNAL(new_binary_data(
unsigned int,
void*,
unsigned int)));
368 for (
const shared_ptr<DecodeSignal>& ds : decode_signals_)
369 for (
const shared_ptr<Decoder>& dec : ds->decoder_stack())
378 for (uint32_t i = 0; i < bin_classes; i++) {
383 connect(
signal_, SIGNAL(new_binary_data(
unsigned int,
void*,
unsigned int)),
413 if (stack.size() > 1) {
414 for (
const shared_ptr<Decoder>& dec : stack) {
415 QString title = QString(
"%1 (%2)").arg(signal->
name(), dec->name());
422 if (!stack.empty()) {
423 shared_ptr<Decoder>& dec = stack.at(0);
451 for (
const shared_ptr<DecodeSignal>& ds : decode_signals_)
452 for (
const shared_ptr<Decoder>& dec : ds->decoder_stack())
459 QString title = QString(
"%1 (%2)").arg(signal->
name(), d->
name());
478 save_type = action->data().toInt();
const char * SaveTypeNames[SaveTypeCount]
QStackedWidget * stacked_widget_
const vector< shared_ptr< Decoder > > & decoder_stack() const
void on_decoder_stacked(void *decoder)
QTimer delayed_view_updater_
virtual void on_metadata_object_changed(MetadataObject *obj, MetadataValueType value_type)
const DecodeBinaryClassInfo * get_binary_class(uint32_t id) const
void set_highlighted_data_sample(uint64_t sample)
void set_data(const DecodeBinaryClass *data)
virtual void save_settings(QSettings &settings) const
virtual ViewType get_type() const
virtual void perform_delayed_view_update()
virtual void restore_settings(QSettings &settings)
pair< size_t, size_t > get_selection() const
uint32_t current_segment_
The ID of the currently displayed segment.
const char * name() const
void on_selected_class_changed(int index)
QComboBox * decoder_selector_
virtual void remove_decode_signal(shared_ptr< data::DecodeSignal > signal)
const DecodeBinaryClass * get_binary_data_class(uint32_t segment_id, const Decoder *dec, uint32_t bin_class_id) const
QToolButton * save_button_
QComboBox * class_selector_
MetadataObjManager * metadata_obj_manager()
void set_visible_sample_range(uint64_t start, uint64_t end)
libsigrok allows users to import and export data from files in various formats some of them as generic as others very specific For a list and make sure to check not so common and outright exotic ways to represent data and sigrok tries to suit as many needs as it can To see which formats your version of PulseView just click on the small arrow next to the _Open_ PulseView will ask for the file name to open Once you picked the file
void save_data_as_hex_dump(bool with_offset=false, bool with_ascii=false) const
void on_decoder_removed(void *decoder)
virtual void clear_decode_signals()
T min(const T v0, const T v1)
size_t create_hex_line(size_t start, size_t end, QString *dest, bool with_offset=false, bool with_ascii=false)
virtual QSizePolicy sizePolicy() const
virtual void reset_view_state()
void on_signal_name_changed(const QString &name)
View(Session &session, bool is_main_view=false, QMainWindow *parent=nullptr)
unsigned int get_bytes_per_line() const
void on_new_binary_data(unsigned int segment_id, void *decoder, unsigned int bin_class_id)
virtual void reset_view_state()
virtual void restore_settings(QSettings &settings)
it will come up with a session that has the demo device selected That you can get to know the program even when you don t have any hardware to use it you see a list of devices PulseView has recognized If the device you want to use is you can just select it here image::device_selector_dropdown png[] If it s not you ll need to scan for it first Since most serial port and Ethernet devices can t be auto this is usually required for those To do either choose the Connect to Device option from the list or click on the button itself You will see the following you ll need to pick a driver that you want to use In order to do this
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
const data::decode::Decoder * decoder_
void on_selected_decoder_changed(int index)
uint32_t get_binary_data_chunk_count(uint32_t segment_id, const Decoder *dec, uint32_t bin_class_id) const
void get_merged_binary_data_chunks_by_offset(uint32_t segment_id, const Decoder *dec, uint32_t bin_class_id, uint64_t start, uint64_t end, vector< uint8_t > *dest) const
virtual void save_settings(QSettings &settings) const
virtual void add_decode_signal(shared_ptr< data::DecodeSignal > signal)
uint32_t get_binary_class_count() const
QComboBox * format_selector_
data::DecodeSignal * signal_
void on_actionSave_triggered(QAction *action=nullptr)