ngscopeclient 0.1-dev+51fbda87c
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Session Class Reference

A Session stores all of the instrument configuration and other state the user has open. More...

#include <Session.h>

Collaboration diagram for Session:
Collaboration graph
[legend]

Public Member Functions

 Session (MainWindow *wnd)
 
bool OnMemoryPressure (MemoryPressureLevel level, MemoryPressureType type, size_t requestedSize)
 Handler for low memory conditions.
 
void ArmTrigger (TriggerGroup::TriggerType type, bool all=false)
 Arms the trigger for all trigger groups. More...
 
void StopTrigger (bool all=false)
 Stop the trigger for the session. More...
 
bool HasOnlineScopes ()
 Returns true if we have at least one scope that isn't offline.
 
void DownloadWaveforms ()
 Pull the waveform data out of the queue and make it current.
 
bool CheckForWaveforms (vk::raii::CommandBuffer &cmdbuf)
 Check if new waveform data has arrived. More...
 
void RefreshAllFilters ()
 
void RefreshAllFiltersNonblocking ()
 Queues a request to refresh all filters the next time we poll stuff.
 
void RefreshDirtyFiltersNonblocking ()
 Queues a request to refresh dirty filters the next time we poll stuff. More...
 
bool RefreshDirtyFilters ()
 Refresh dirty filters (and anything in their downstream influence cone) More...
 
void FlushConfigCache ()
 
void MarkChannelDirty (InstrumentChannel *chan)
 Flags a single channel as dirty (updated outside of a global trigger event)
 
void RenderWaveformTextures (vk::raii::CommandBuffer &cmdbuf, std::vector< std::shared_ptr< DisplayedChannel > > &channels)
 
void Clear ()
 Clears all session state and returns the object to an empty state. More...
 
void ClearBackgroundThreads ()
 Terminate all background threads for instruments. More...
 
bool PreLoadFromYaml (const YAML::Node &node, const std::string &dataDir, bool online)
 Perform partial loading and check for potentially dangerous configurations. More...
 
bool LoadFromYaml (const YAML::Node &node, const std::string &dataDir, bool online)
 Deserialize a YAML::Node (and associated data directory) to the current session. More...
 
YAML::Node SerializeInstrumentConfiguration ()
 Serialize the configuration for all oscilloscopes.
 
YAML::Node SerializeMetadata ()
 Serializes metadata about the session / software stack. More...
 
YAML::Node SerializeTriggerGroups ()
 
bool LoadTriggerGroups (const YAML::Node &node)
 
YAML::Node SerializeFilterConfiguration ()
 Serialize the configuration for all protocol decoders.
 
YAML::Node SerializeMarkers ()
 
bool SerializeWaveforms (const std::string &dataDir)
 
bool SerializeSparseWaveform (SparseWaveformBase *wfm, const std::string &path)
 Saves waveform sample data in the "sparsev1" file format. More...
 
bool SerializeUniformWaveform (UniformWaveformBase *wfm, const std::string &path)
 Saves waveform sample data in the "densev1" file format. More...
 
void AddMultimeterDialog (std::shared_ptr< SCPIMultimeter > meter)
 Adds a multimeter dialog to the session. More...
 
std::shared_ptr< PacketManagerAddPacketFilter (PacketDecoder *filter)
 Called when a new packet filter is created.
 
void AddInstrument (std::shared_ptr< Instrument > inst, bool createDialogs=true)
 Adds a new instrument to the session. More...
 
void RemoveInstrument (std::shared_ptr< Instrument > inst)
 Removes an instrument from the session.
 
std::shared_ptr< InstrumentConnectionStateGetInstrumentConnectionState (std::shared_ptr< Instrument > inst)
 
bool IsMultiScope ()
 
MainWindowGetMainWindow ()
 
std::shared_ptr< BERTStateGetBERTState (std::shared_ptr< BERT > bert)
 Returns a pointer to the state for a BERT.
 
std::shared_ptr< PowerSupplyStateGetPSUState (std::shared_ptr< SCPIPowerSupply > psu)
 Returns a pointer to the state for a power supply.
 
std::shared_ptr< FunctionGeneratorStateGetFunctionGeneratorState (std::shared_ptr< FunctionGenerator > awg)
 Returns a pointer to the state for a function generator.
 
std::shared_ptr< PacketManagerGetPacketManager (PacketDecoder *filter)
 Returns a pointer to the existing packet manager for a protocol decode filter.
 
void ApplyPreferences (std::shared_ptr< Oscilloscope > scope)
 
size_t GetFilterCount ()
 
bool IsChannelBeingDragged ()
 
int64_t GetToneMapTime ()
 Gets the last execution time of the tone mapping shaders.
 
int64_t GetFilterGraphExecTime ()
 Gets the last execution time of the filter graph.
 
int64_t GetLastWaveformRenderTime ()
 Gets the last run time of the waveform rendering shaders.
 
double GetWaveformDownloadRate ()
 Gets the average rate at which we are pulling waveforms off the scope, in Hz.
 
const std::vector< std::shared_ptr< Oscilloscope > > GetScopes ()
 Get the set of scopes we're currently connected to.
 
const std::vector< std::shared_ptr< BERT > > GetBERTs ()
 Get the set of BERTs we're currently connected to.
 
std::set< std::shared_ptr< SCPIInstrument > > GetSCPIInstruments ()
 Gets the set of all SCPI instruments we're connect to (regardless of type) More...
 
std::set< std::shared_ptr< Instrument > > GetInstruments ()
 Gets the set of all instruments we're connect to (regardless of type) More...
 
size_t GetInstrumentCount ()
 Get the number of instruments we're connected to (regardless of type)
 
bool CheckForPendingWaveforms ()
 Check if we have data available from all of our scopes.
 
std::shared_mutex & GetWaveformDataMutex ()
 Get the mutex controlling access to waveform data.
 
HistoryManagerGetHistory ()
 Get our history manager.
 
void AddMarker (Marker m)
 Adds a marker.
 
void StartWaveformThreadIfNeeded ()
 Starts the WaveformThread if we don't already have one.
 
void ClearSweeps ()
 Clear state on all of our filters.
 
std::mutex & GetRasterizedWaveformMutex ()
 Get the mutex controlling access to rasterized waveforms.
 
std::vector< std::shared_ptr< TriggerGroup > > GetTriggerGroups ()
 
void GarbageCollectTriggerGroups ()
 Remove trigger groups with no instruments in them. More...
 
void MakeNewTriggerGroup (std::shared_ptr< Oscilloscope > scope)
 
void MakeNewTriggerGroup (PausableFilter *filter)
 
int64_t GetDeskew (std::shared_ptr< Oscilloscope > scope)
 
void SetDeskew (std::shared_ptr< Oscilloscope > scope, int64_t skew)
 
bool IsPrimaryOfMultiScopeGroup (std::shared_ptr< Oscilloscope > scope)
 Check if a scope is the primary of a group containing at least one other scope.
 
bool IsSecondaryOfMultiScopeGroup (std::shared_ptr< Oscilloscope > scope)
 Check if a scope is a secondary within a multiscope group.
 
std::shared_ptr< TriggerGroupGetTriggerGroupForScope (std::shared_ptr< Oscilloscope > scope)
 Gets the trigger group that contains a specified scope.
 
std::shared_ptr< TriggerGroupGetTriggerGroupForFilter (PausableFilter *filter)
 Gets the trigger group that contains a specified filter.
 
const ConfigWarningListGetWarnings ()
 
std::shared_ptr< LoadStateGetLoadState (std::shared_ptr< Load > load)
 Get the state for a load.
 
std::shared_ptr< TriggerGroupGetTrendFilterGroup ()
 
void OnMarkerChanged ()
 Called when a marker is added, removed, or modified. More...
 
std::map< FlowGraphNode *, int64_t > GetFilterGraphRuntime ()
 Return the last filter graph runtime stats.
 
std::string GetNextMarkerName ()
 Generate an automatic name for a newly created marker.
 
std::vector< Marker > & GetMarkers (TimePoint t)
 Get the markers for a given waveform timestamp.
 
std::vector< TimePointGetMarkerTimes ()
 Get a list of timestamps for markers.
 
void RemoveMarkers (TimePoint t)
 Deletes markers for a waveform timestamp.
 
void RemovePackets (TimePoint t)
 Deletes packets from our packet managers for a waveform timestamp.
 
std::set< FlowGraphNode * > GetAllGraphNodes ()
 Gets all of our graph nodes (filters plus instrument channels)
 
std::optional< TimePointGetHoveredPacketTimestamp ()
 Returns the timestamp of the protocol analyzer event that the mouse is over, if any.
 
void SetHoveredPacketTimestamp (std::optional< TimePoint > t)
 
PreferenceManagerGetPreferences ()
 
FilterGetReferenceFilter (const std::string &name)
 Gets the reference instance of a given filter.
 
const std::map< std::string, Filter * > & GetReferenceFilters ()
 
const std::vector< std::string > & GetDriverNamesForType (const std::string &type)
 Get all of the drivers of a given type.
 
void CreateAndAddInstrument (const std::string &driver, SCPITransport *transport, const std::string &nickname)
 Creates a new instrument and adds it to the session.
 

Public Attributes

IDTable m_idtable
 ID mapping used for serialization.
 
std::string m_generalNotes
 Session notes.
 
std::string m_setupNotes
 Session notes about the experimental setup.
 

Protected Member Functions

void UpdatePacketManagers (const std::set< FlowGraphNode * > &nodes)
 Update all of the packet managers when new data arrives.
 
std::string GetRegisteredTypeOfDriver (const std::string &drivername)
 Performs an exhaustive search of the driver list to see which type this instrument is. More...
 
bool LoadInstruments (int version, const YAML::Node &node, bool online)
 
bool PreLoadInstruments (int version, const YAML::Node &node, bool online)
 
SCPITransportCreateTransportForNode (const YAML::Node &node)
 
bool VerifyInstrument (const YAML::Node &node, std::shared_ptr< Instrument > inst)
 
bool PreLoadVNA (int version, const YAML::Node &node, bool online)
 
bool PreLoadOscilloscope (int version, const YAML::Node &node, bool online)
 
bool PreLoadPowerSupply (int version, const YAML::Node &node, bool online)
 
bool PreLoadRFSignalGenerator (int version, const YAML::Node &node, bool online)
 
bool PreLoadFunctionGenerator (int version, const YAML::Node &node, bool online)
 
bool PreLoadMultimeter (int version, const YAML::Node &node, bool online)
 
bool PreLoadSpectrometer (int version, const YAML::Node &node, bool online)
 
bool PreLoadSDR (int version, const YAML::Node &node, bool online)
 
bool PreLoadBERT (int version, const YAML::Node &node, bool online)
 
bool PreLoadLoad (int version, const YAML::Node &node, bool online)
 
bool PreLoadMisc (int version, const YAML::Node &node, bool online)
 
bool LoadFilters (int version, const YAML::Node &node)
 
bool LoadInstrumentInputs (int version, const YAML::Node &node)
 
bool LoadWaveformData (int version, const std::string &dataDir)
 
bool LoadWaveformDataForScope (int version, const YAML::Node &node, std::shared_ptr< Oscilloscope > scope, const std::string &dataDir)
 Loads waveform data for a single scope.
 
bool LoadWaveformDataForFilters (int version, const YAML::Node &node, const std::string &dataDir)
 Loads waveform data for filters that need to be preserved.
 
void DoLoadWaveformDataForStream (OscilloscopeChannel *chan, int stream, std::string format, std::string fname)
 
void CreateReferenceFilters ()
 Creates one filter of each known type to use as a reference for what inputs are legal to use to a new filter.
 
void DestroyReferenceFilters ()
 Destroys the reference filters. More...
 

Protected Attributes

int m_fileLoadVersion
 Version of the file being loaded.
 
ConfigWarningList m_warnings
 Warnings generated by loading the current file.
 
std::map< std::shared_ptr< Oscilloscope >, int64_t > m_scopeDeskewCal
 Deskew correction coefficients for multi-scope.
 
std::mutex m_scopeMutex
 Mutex for controlling access to scope vectors.
 
std::shared_mutex m_waveformDataMutex
 Mutex for controlling access to waveform data.
 
std::mutex m_filterUpdatingMutex
 Mutex for controlling access to filter graph.
 
MainWindowm_mainWindow
 Top level UI window.
 
std::atomic< bool > m_shuttingDown
 Flag for shutting down all scope threads when we exit.
 
bool m_modifiedSinceLastSave
 True if the session has been modified since last time it was saved.
 
std::vector< std::shared_ptr< Oscilloscope > > m_oscilloscopes
 Oscilloscopes we are currently connected to.
 
std::map< std::shared_ptr< PowerSupply >, std::shared_ptr< PowerSupplyState > > m_psus
 Power supplies we are currently connected to.
 
std::map< std::shared_ptr< Multimeter >, std::shared_ptr< MultimeterState > > m_meters
 Multimeters we are currently connected to.
 
std::map< std::shared_ptr< Load >, std::shared_ptr< LoadState > > m_loads
 Loads we are currently connected to.
 
std::map< std::shared_ptr< BERT >, std::shared_ptr< BERTState > > m_berts
 BERTs we are currently connected to.
 
std::map< std::shared_ptr< FunctionGenerator >, std::shared_ptr< FunctionGeneratorState > > m_awgs
 Function generator we are currently connected to.
 
std::vector< std::shared_ptr< TriggerGroup > > m_triggerGroups
 Trigger groups for syncing oscilloscopes.
 
std::shared_ptr< TriggerGroupm_trendTriggerGroup
 Trigger group dedicated to trend filters.
 
std::recursive_mutex m_triggerGroupMutex
 Mutex controlling access to m_triggerGroups.
 
std::map< std::shared_ptr< Instrument >, std::shared_ptr< InstrumentConnectionState > > m_instrumentStates
 Worker threads and other bookkeeping metadata for instruments.
 
std::unique_ptr< std::thread > m_waveformThread
 Processing thread for waveform data.
 
std::set< std::shared_ptr< Oscilloscope > > m_recentlyTriggeredScopes
 Scopes whose data is currently being processed for history.
 
std::set< std::shared_ptr< TriggerGroup > > m_recentlyTriggeredGroups
 Groups whose data is currently being processed.
 
std::mutex m_recentlyTriggeredScopeMutex
 Mutex to synchronize access to m_recentlyTriggeredScopes.
 
double m_tArm
 Time we last armed the global trigger.
 
double m_tPrimaryTrigger
 Time that the primary scope triggered (in multi-scope setups)
 
bool m_triggerArmed
 Indicates trigger is armed (incoming waveforms are ignored if not armed)
 
bool m_triggerOneShot
 If true, trigger is currently armed in single-shot mode.
 
FilterGraphExecutor m_graphExecutor
 Context for filter graph evaluation.
 
std::atomic< int64_t > m_lastFilterGraphExecTime
 Time spent on the last filter graph execution.
 
std::mutex m_lastFilterGraphRuntimeMutex
 Mutex for controlling access to m_lastFilterGraphRuntimeStats.
 
std::map< FlowGraphNode *, int64_t > m_lastFilterGraphRuntimeStats
 Performance stats from last graph execution.
 
std::mutex m_perfClockMutex
 Mutex for controlling access to performance counters.
 
HzClock m_waveformDownloadRate
 Frequency at which we are pulling waveforms off of scopes.
 
HistoryManager m_history
 Historical waveform data.
 
std::mutex m_packetMgrMutex
 Mutex for controlling access to m_packetmgrs.
 
std::map< PacketDecoder *, std::shared_ptr< PacketManager > > m_packetmgrs
 Historical packet data from filters.
 
std::mutex m_rasterizedWaveformMutex
 Mutex for controlling access to rasterized waveforms.
 
bool m_multiScope
 True if we have >1 oscilloscope.
 
std::map< TimePoint, std::vector< Marker > > m_markers
 Map of waveform timestamps to markers.
 
int m_nextMarkerNum
 Number for next autogenerated waveform name.
 
std::set< FlowGraphNode * > m_dirtyChannels
 Set of dirty channels.
 
std::mutex m_dirtyChannelsMutex
 Mutex controlling access to m_dirtyChannels.
 
std::optional< TimePointm_hoverTime
 
PreferenceManager m_preferences
 
std::map< std::string, Filter * > m_referenceFilters
 
std::map< std::string, std::vector< std::string > > m_driverNamesByType
 Map of "type" to drivername[].
 

Detailed Description

A Session stores all of the instrument configuration and other state the user has open.

Generally only accessed from the GUI thread. TODO: interlocking if needed?

Member Function Documentation

◆ AddInstrument()

void Session::AddInstrument ( std::shared_ptr< Instrument inst,
bool  createDialogs = true 
)

Adds a new instrument to the session.

Parameters
instThe instment to add
createDialogsTrue if we should add waveform areas for each enabled channel and/or dialogs if applicable

◆ AddMultimeterDialog()

void Session::AddMultimeterDialog ( std::shared_ptr< SCPIMultimeter meter)

Adds a multimeter dialog to the session.

Low level helper, intended to be only used by file loading

◆ ArmTrigger()

void Session::ArmTrigger ( TriggerGroup::TriggerType  type,
bool  all = false 
)

Arms the trigger for all trigger groups.

Parameters
typeType of trigger to start
allIf true, arm all groups in the sesison. If false, only stop groups with the "default" flag set

◆ CheckForWaveforms()

bool Session::CheckForWaveforms ( vk::raii::CommandBuffer &  cmdbuf)

Check if new waveform data has arrived.

This runs in the main GUI thread.

TODO: this might be best to move to MainWindow?

Returns
True if a new waveform came in, false if not

◆ Clear()

void Session::Clear ( )

Clears all session state and returns the object to an empty state.

HACK: for now, export filters keep an open reference to themselves to avoid memory leaks

Free them now. Need to use a 2-pass flow to avoid attempting to iterate over something that got freed when we freed a previous filter. This will be so much easier when we transition to shared_ptr's!

◆ ClearBackgroundThreads()

void Session::ClearBackgroundThreads ( )

Terminate all background threads for instruments.

You must call Clear() after calling this function, however it's OK to do other cleanup in between.

The reason for the split is that canceling the background threads is needed to prevent rendering or waveform processing from happening while we're in the middle of destroying stuff. But we can't clear the scopes etc until we've deleted all of the views and waveform groups as they hold onto references to them.

◆ DestroyReferenceFilters()

void Session::DestroyReferenceFilters ( )
protected

Destroys the reference filters.

This only needs to be done at application shutdown, not in Clear(), because the reference filters have no persistent state. The only thing they're ever used for is calling ValidateChannel() on them.

◆ GarbageCollectTriggerGroups()

void Session::GarbageCollectTriggerGroups ( )

Remove trigger groups with no instruments in them.

Removes a maximum of one group per invocation.

◆ GetInstruments()

set< shared_ptr< Instrument > > Session::GetInstruments ( )

Gets the set of all instruments we're connect to (regardless of type)

Returns a list of all connected instruments, of any type.

Multi-type instruments are only counted once.

◆ GetRegisteredTypeOfDriver()

string Session::GetRegisteredTypeOfDriver ( const std::string &  drivername)
protected

Performs an exhaustive search of the driver list to see which type this instrument is.

TODO: we should really just unify the dynamic creation tables...

◆ GetSCPIInstruments()

set< shared_ptr< SCPIInstrument > > Session::GetSCPIInstruments ( )

Gets the set of all SCPI instruments we're connect to (regardless of type)

Returns a list of all connected SCPI instruments, of any type.

Multi-type instruments are only counted once.

◆ LoadFromYaml()

bool Session::LoadFromYaml ( const YAML::Node &  node,
const std::string &  dataDir,
bool  online 
)

Deserialize a YAML::Node (and associated data directory) to the current session.

Parameters
nodeRoot YAML node of the file
dataDirPath to the _data directory associated with the session
onlineTrue if we should reconnect to instruments
Returns
True if successful, false on error

◆ OnMarkerChanged()

void Session::OnMarkerChanged ( )

Called when a marker is added, removed, or modified.

TODO: hint as to what marker and what was changed?

◆ PreLoadFromYaml()

bool Session::PreLoadFromYaml ( const YAML::Node &  node,
const std::string &  dataDir,
bool  online 
)

Perform partial loading and check for potentially dangerous configurations.

Parameters
nodeRoot YAML node of the file
dataDirPath to the _data directory associated with the session
onlineTrue if we should reconnect to instruments
Returns
True if successful, false on error

◆ RefreshDirtyFilters()

bool Session::RefreshDirtyFilters ( )

Refresh dirty filters (and anything in their downstream influence cone)

Returns
True if at least one filter was refreshed, false if nothing was dirty

◆ RefreshDirtyFiltersNonblocking()

void Session::RefreshDirtyFiltersNonblocking ( )

Queues a request to refresh dirty filters the next time we poll stuff.

Avoid waking up the waveform thread if we have no dirty filters, though.

◆ SerializeMetadata()

YAML::Node Session::SerializeMetadata ( )

Serializes metadata about the session / software stack.

Not currently used for anything, but might be helpful for troubleshooting etc in the future

◆ SerializeSparseWaveform()

bool Session::SerializeSparseWaveform ( SparseWaveformBase wfm,
const std::string &  path 
)

Saves waveform sample data in the "sparsev1" file format.

Interleaved (slow): int64 offset int64 len for analog float voltage for digital bool voltage

◆ SerializeUniformWaveform()

bool Session::SerializeUniformWaveform ( UniformWaveformBase wfm,
const std::string &  path 
)

Saves waveform sample data in the "densev1" file format.

for analog float[] voltage for digital bool[] voltage

Durations are implied {1....1} and offsets are implied {0...n-1}.

◆ StopTrigger()

void Session::StopTrigger ( bool  all = false)

Stop the trigger for the session.

Parameters
allIf true, stop all groups in the sesison. If false, only stop groups with the "default" flag set

The documentation for this class was generated from the following files: