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

Commits on Jun 12, 2020

  1. Copy the full SHA
    569547a View commit details
Showing with 52 additions and 0 deletions.
  1. +1 −0 scopehal/OscilloscopeChannel.cpp
  2. +50 −0 scopehal/Unit.cpp
  3. +1 −0 scopehal/Unit.h
1 change: 1 addition & 0 deletions scopehal/OscilloscopeChannel.cpp
Original file line number Diff line number Diff line change
@@ -187,6 +187,7 @@ int64_t OscilloscopeChannel::GetDeskew()
{
if(m_scope)
return m_scope->GetDeskewForChannel(m_index);
return 0;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 changes: 50 additions & 0 deletions scopehal/Unit.cpp
Original file line number Diff line number Diff line change
@@ -186,3 +186,53 @@ string Unit::PrettyPrint(double value)
}
return string(tmp);
}

/**
@brief Parses a string based on the supplied unit
*/
double Unit::ParseString(string str)
{
//Find the first non-numeric character in the strnig
double scale = 1;
for(size_t i=0; i<str.size(); i++)
{
char c = str[i];
if(isspace(c) || isdigit(c) || (c == '.') || (c == '-') )
continue;

if(c == 'G')
scale = 1000000000.0;
else if(c == 'M')
scale = 1000000.0;
else if(c == 'K')
scale = 1000.0;
else if(c == 'm')
scale = 0.001;
else if(c == 'u') //TODO: handle μ
scale = 1e-6;
else if(c == 'n')
scale = 1e-9;
else if(c == 'p')
scale = 1e-12;

break;
}

//Parse the base value
double ret;
sscanf(str.c_str(), "%20lf", &ret);
ret *= scale;

//Apply a unit-specific scaling factor
switch(m_type)
{
case Unit::UNIT_PS:
ret *= 1e12;
break;

default:
break;
}

return ret;
}
1 change: 1 addition & 0 deletions scopehal/Unit.h
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ class Unit
{}

std::string PrettyPrint(double value);
double ParseString(std::string str);

UnitType GetType()
{ return m_type; }