Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c6a6a44e483f
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ca48577db730
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Mar 13, 2020

  1. Continued work on file load. Can now create new instruments from save…

    … file but not configure them or set up any UI. See #3.
    azonenberg committed Mar 13, 2020
    Copy the full SHA
    ca48577 View commit details
Showing with 120 additions and 23 deletions.
  1. +116 −20 glscopeclient/OscilloscopeWindow.cpp
  2. +3 −2 glscopeclient/OscilloscopeWindow.h
  3. +1 −1 glscopeclient/glscopeclient.h
136 changes: 116 additions & 20 deletions glscopeclient/OscilloscopeWindow.cpp
Original file line number Diff line number Diff line change
@@ -51,27 +51,8 @@ using namespace std;
*/
OscilloscopeWindow::OscilloscopeWindow(vector<Oscilloscope*> scopes)
: m_scopes(scopes)
// m_iconTheme(Gtk::IconTheme::get_default())
{
//Set title
string title = "Oscilloscope: ";
for(size_t i=0; i<scopes.size(); i++)
{
auto scope = scopes[i];

char tt[256];
snprintf(tt, sizeof(tt), "%s (%s %s, serial %s)",
scope->m_nickname.c_str(),
scope->GetVendor().c_str(),
scope->GetName().c_str(),
scope->GetSerial().c_str()
);

if(i > 0)
title += ", ";
title += tt;
}
set_title(title);
SetTitle();

//Initial setup
set_reallocate_redraws(true);
@@ -95,6 +76,29 @@ OscilloscopeWindow::OscilloscopeWindow(vector<Oscilloscope*> scopes)
m_tEvent = 0;
}

void OscilloscopeWindow::SetTitle()
{
//Set title
string title = "Oscilloscope: ";
for(size_t i=0; i<m_scopes.size(); i++)
{
auto scope = m_scopes[i];

char tt[256];
snprintf(tt, sizeof(tt), "%s (%s %s, serial %s)",
scope->m_nickname.c_str(),
scope->GetVendor().c_str(),
scope->GetName().c_str(),
scope->GetSerial().c_str()
);

if(i > 0)
title += ", ";
title += tt;
}
set_title(title);
}

/**
@brief Application cleanup
*/
@@ -446,7 +450,99 @@ void OscilloscopeWindow::OnFileOpen()
CloseSession();

//Open the top level
bool loadLayout = dlg.get_choice("layout") == "true";
bool loadWaveform = dlg.get_choice("waveform") == "true";
bool reconnect = dlg.get_choice("reconnect") == "true";
auto docs = YAML::LoadAllFromFile(m_currentFileName);
DoFileOpen(docs, loadLayout, loadWaveform, reconnect);
}

/**
@brief Loads configuration from a file
*/
void OscilloscopeWindow::DoFileOpen(
std::vector<YAML::Node>& docs,
bool loadLayout,
bool loadWaveform,
bool reconnect)
{
//Create the ID map for resolving all of our pointers etc
std::map<void*, int> idmap;

//Only open the first doc, our file format doesn't ever generate multiple docs in a file.
//Ignore any trailing stuff at the end
auto node = docs[0];

//Load the instruments
LoadInstruments(node["instruments"], reconnect, idmap);

//Re-title the window for the new scope
SetTitle();
}

/**
@brief Reconnect to existing instruments and reconfigure them
*/
void OscilloscopeWindow::LoadInstruments(const YAML::Node& node, bool reconnect, std::map<void*, int>& idmap)
{
if(!node)
{
LogError("Save file missing instruments node\n");
return;
}

if(!reconnect)
{
LogError("Mock scopes for no-reconnect file load not yet implemented\n");
return;
}

//Load each instrument
for(auto it : node)
{
auto inst = it.second;

//Create the scope
auto transport = SCPITransport::CreateTransport(inst["transport"].as<string>(), inst["args"].as<string>());
auto scope = Oscilloscope::CreateOscilloscope(inst["driver"].as<string>(), transport);

//Sanity check make/model/serial. If mismatch, stop
string message;
bool fail;
if(inst["name"].as<string>() != scope->GetName())
{
message = string("Unable to connect to oscilloscope: instrument has model name \"") +
scope->GetName() + "\", save file has model name \"" + inst["name"].as<string>() + "\"";
fail = true;
}
else if(inst["vendor"].as<string>() != scope->GetVendor())
{
message = string("Unable to connect to oscilloscope: instrument has vendor \"") +
scope->GetVendor() + "\", save file has vendor \"" + inst["vendor"].as<string>() + "\"";
fail = true;
}
else if(inst["serial"].as<string>() != scope->GetSerial())
{
message = string("Unable to connect to oscilloscope: instrument has serial \"") +
scope->GetSerial() + "\", save file has serial \"" + inst["serial"].as<string>() + "\"";
fail = true;
}
if(fail)
{
Gtk::MessageDialog dlg(*this, message, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
dlg.run();
delete scope;
continue;
}

//All good. Add to our list of scopes etc
g_app->m_scopes.push_back(scope);
m_scopes.push_back(scope);
idmap[scope] = inst["id"].as<int>();

//Configure the scope
scope->LoadConfiguration(inst, idmap);
}
}

/**
5 changes: 3 additions & 2 deletions glscopeclient/OscilloscopeWindow.h
Original file line number Diff line number Diff line change
@@ -42,8 +42,6 @@
#include "ProtocolAnalyzerWindow.h"
#include "HistoryWindow.h"

#include <yaml-cpp/yaml.h>

/**
@brief Main application window class for an oscilloscope
*/
@@ -113,6 +111,7 @@ class OscilloscopeWindow : public Gtk::Window
{ return m_alphaslider.get_value(); }

protected:
void SetTitle();
void ArmTrigger(bool oneshot);

void SplitGroup(Gtk::Widget* frame, WaveformGroup* group, bool horizontal);
@@ -189,6 +188,8 @@ class OscilloscopeWindow : public Gtk::Window
//Menu event handlers
void OnFileSave(bool saveToCurrentFile, bool saveLayout, bool saveWaveforms);
void OnFileOpen();
void DoFileOpen(std::vector<YAML::Node>& docs, bool loadLayout, bool loadWaveform, bool reconnect);
void LoadInstruments(const YAML::Node& node, bool reconnect, std::map<void*, int>& idmap);
void CloseSession();
void OnEyeColorChanged(EyeColor color, Gtk::RadioMenuItem* item);
void OnTriggerProperties(Oscilloscope* scope);
2 changes: 1 addition & 1 deletion glscopeclient/glscopeclient.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2018 Andrew D. Zonenberg *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *