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
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 21c04bb06e4c
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 419dc0fa4b06
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Mar 5, 2020

  1. Copy the full SHA
    419dc0f View commit details
Showing with 83 additions and 3 deletions.
  1. +69 −1 scopehal/Measurement.cpp
  2. +14 −2 scopehal/Measurement.h
70 changes: 69 additions & 1 deletion scopehal/Measurement.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 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 *
@@ -561,3 +561,71 @@ string FloatMeasurement::GetValueAsString()

return tmp;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

string Measurement::SerializeConfiguration(std::map<void*, int>& idmap, int& nextID, string nick)
{
//Name ourself. Note that serialization may not be topologically sorted!
//It's possible another measurement may depend on us, and allocate an ID for us in advance
int id;
if(idmap.find(this) == idmap.end())
{
id = nextID ++;
idmap[this] = id;
}
else
id = idmap[this];

//Save basic info
char tmp[1024];
snprintf(tmp, sizeof(tmp), " : %%\n");
string config = tmp;
snprintf(tmp, sizeof(tmp), " id: %d\n", id);
config += tmp;

//Config
snprintf(tmp, sizeof(tmp), " measurement: \"%s\"\n", GetMeasurementDisplayName().c_str());
config += tmp;
snprintf(tmp, sizeof(tmp), " nick: \"%s\"\n", nick.c_str());
config += tmp;

//Inputs
snprintf(tmp, sizeof(tmp), " inputs: %%\n");
config += tmp;
for(size_t i=0; i<m_channels.size(); i++)
{
auto chan = m_channels[i];
if(chan == NULL)
snprintf(tmp, sizeof(tmp), " %s: 0\n", m_signalNames[i].c_str());
else
{
if(idmap.find(chan) == idmap.end())
{
id = nextID ++;
idmap[chan] = id;
}
else
id = idmap[chan];

snprintf(tmp, sizeof(tmp), " %-20s %d\n", (m_signalNames[i] + ":").c_str(), id);
}

config += tmp;
}

/*
//Parameters
snprintf(tmp, sizeof(tmp), " parameters: %%\n");
config += tmp;
for(auto it : m_parameters)
{
snprintf(tmp, sizeof(tmp), " %-20s %s\n", (it.first+":").c_str(), it.second.ToString().c_str());
config += tmp;
}
*/

return config;
}
16 changes: 14 additions & 2 deletions scopehal/Measurement.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 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 *
@@ -65,6 +65,16 @@ class Measurement

virtual MeasurementType GetMeasurementType() =0;

/**
@brief Gets the display name of this protocol (for use in menus, save files, etc). Must be unique.
*/
virtual std::string GetMeasurementDisplayName() =0;

/**
@brief Serialize this measurement's configuration to a string
*/
virtual std::string SerializeConfiguration(std::map<void*, int>& idmap, int& nextID, std::string nick);

protected:

///Names of signals we take as input
@@ -137,6 +147,8 @@ class FloatMeasurement : public Measurement

#define MEASUREMENT_INITPROC(T) \
static Measurement* CreateInstance() \
{ return new T; }
{ return new T; } \
virtual std::string GetMeasurementDisplayName() \
{ return GetMeasurementName(); }

#endif