Skip to content

Commit

Permalink
Initial power supply serialization support
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Oct 21, 2023
1 parent 6b1a81c commit 6ef82f1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib
15 changes: 15 additions & 0 deletions src/ngscopeclient/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "MetricsDialog.h"
#include "MultimeterDialog.h"
#include "PersistenceSettingsDialog.h"
#include "PowerSupplyDialog.h"
#include "PreferenceDialog.h"
#include "ProtocolAnalyzerDialog.h"
#include "RFGeneratorDialog.h"
Expand Down Expand Up @@ -202,6 +203,7 @@ void MainWindow::CloseSession()
m_fileBrowser = nullptr;
m_measurementsDialog = nullptr;
m_meterDialogs.clear();
m_psuDialogs.clear();
m_channelPropertiesDialogs.clear();
m_generatorDialogs.clear();
m_rfgeneratorDialogs.clear();
Expand Down Expand Up @@ -880,6 +882,10 @@ void MainWindow::OnDialogClosed(const std::shared_ptr<Dialog>& dlg)
if(meterDlg)
m_meterDialogs.erase(meterDlg->GetMeter());

auto psuDlg = dynamic_pointer_cast<PowerSupplyDialog>(dlg);
if(psuDlg)
m_psuDialogs.erase(psuDlg->GetPSU());

auto genDlg = dynamic_pointer_cast<FunctionGeneratorDialog>(dlg);
if(genDlg)
m_generatorDialogs.erase(genDlg->GetGenerator());
Expand Down Expand Up @@ -1940,6 +1946,14 @@ bool MainWindow::LoadSessionFromYaml(const YAML::Node& node, const string& dataD
return false;
}

//Update all of our instrument dialogs as needed
for(auto it : m_psuDialogs)
{
auto dlg = dynamic_pointer_cast<PowerSupplyDialog>(it.second);
if(dlg)
dlg->RefreshFromHardware();
}

//Load ImGui configuration
LogTrace("Loading ImGui configuration\n");
string ipath = dataDir + "/imgui.ini";
Expand Down Expand Up @@ -2482,6 +2496,7 @@ YAML::Node MainWindow::SerializeDialogs()
node["meters"] = mnode;
}

//TODO: psu dialogs
//TODO: generator dialogs
//TODO: rf generator dialogs
//TODO: SCPI console
Expand Down
3 changes: 3 additions & 0 deletions src/ngscopeclient/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class MainWindow : public VulkanWindow
///@brief Map of multimeters to meter control dialogs
std::map<SCPIMultimeter*, std::shared_ptr<Dialog> > m_meterDialogs;

///@brief Map of PSUs to power supply control dialogs
std::map<SCPIPowerSupply*, std::shared_ptr<Dialog> > m_psuDialogs;

///@brief Map of generators to generator control dialogs
std::map<SCPIFunctionGenerator*, std::shared_ptr<Dialog> > m_generatorDialogs;

Expand Down
5 changes: 5 additions & 0 deletions src/ngscopeclient/MainWindow_Menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "MetricsDialog.h"
#include "MultimeterDialog.h"
#include "PersistenceSettingsDialog.h"
#include "PowerSupplyDialog.h"
#include "PreferenceDialog.h"
#include "ProtocolAnalyzerDialog.h"
#include "RFGeneratorDialog.h"
Expand All @@ -75,6 +76,10 @@ void MainWindow::AddDialog(shared_ptr<Dialog> dlg)
if(mdlg != nullptr)
m_meterDialogs[mdlg->GetMeter()] = dlg;

auto pdlg = dynamic_cast<PowerSupplyDialog*>(dlg.get());
if(pdlg != nullptr)
m_psuDialogs[pdlg->GetPSU()] = dlg;

auto fdlg = dynamic_cast<FunctionGeneratorDialog*>(dlg.get());
if(fdlg != nullptr)
m_generatorDialogs[fdlg->GetGenerator()] = dlg;
Expand Down
34 changes: 24 additions & 10 deletions src/ngscopeclient/PowerSupplyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,32 @@ PowerSupplyDialog::PowerSupplyDialog(SCPIPowerSupply* psu, shared_ptr<PowerSuppl
, m_psu(psu)
, m_state(state)
{
//Set up initial empty state
AsyncLoadState();
}

PowerSupplyDialog::~PowerSupplyDialog()
{
m_session->RemovePowerSupply(m_psu);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Rendering

void PowerSupplyDialog::RefreshFromHardware()
{
//pull settings again
AsyncLoadState();
}

void PowerSupplyDialog::AsyncLoadState()
{
//Clear existing state (if any) and allocate space for new state
m_channelUIState.clear();
m_channelUIState.resize(m_psu->GetChannelCount());

//Asynchronously load rest of the state
//Do the async load
m_futureUIState.clear();
SCPIPowerSupply* psu = m_psu;
for(size_t i=0; i<m_psu->GetChannelCount(); i++)
{
//Add placeholders for non-power channels
Expand All @@ -70,14 +92,6 @@ PowerSupplyDialog::PowerSupplyDialog(SCPIPowerSupply* psu, shared_ptr<PowerSuppl
}
}

PowerSupplyDialog::~PowerSupplyDialog()
{
m_session->RemovePowerSupply(m_psu);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Rendering

bool PowerSupplyDialog::DoRender()
{
//Device information
Expand Down
6 changes: 6 additions & 0 deletions src/ngscopeclient/PowerSupplyDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ class PowerSupplyDialog : public Dialog

virtual bool DoRender();

void RefreshFromHardware();

SCPIPowerSupply* GetPSU()
{ return m_psu; }

protected:
void ChannelSettings(int i, float v, float a, float etime);
void AsyncLoadState();

///@brief Session handle so we can remove the PSU when closed
Session* m_session;
Expand Down
7 changes: 5 additions & 2 deletions src/ngscopeclient/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,11 @@ bool Session::LoadInstruments(int version, const YAML::Node& node, bool /*online
auto nick = inst["nick"].as<string>();
LogTrace("Loading instrument \"%s\"\n", nick.c_str());

reinterpret_cast<Instrument*>(m_idtable[inst["id"].as<uintptr_t>()])->LoadConfiguration(
version, inst, m_idtable);
auto pinst = reinterpret_cast<Instrument*>(m_idtable[inst["id"].as<uintptr_t>()]);
if(!pinst)
continue;

pinst->LoadConfiguration(version, inst, m_idtable);
}

return true;
Expand Down

0 comments on commit 6ef82f1

Please sign in to comment.