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: 63b6d5ff37a1
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: de1bc0230367
Choose a head ref
  • 6 commits
  • 3 files changed
  • 3 contributors

Commits on Jul 19, 2020

  1. Copy the full SHA
    20110f6 View commit details
  2. caching

    x44203 committed Jul 19, 2020
    Copy the full SHA
    89f0718 View commit details
  3. fix syntactic errors

    x44203 committed Jul 19, 2020
    Copy the full SHA
    2767c4a View commit details
  4. fixed bw limit

    x44203 committed Jul 19, 2020
    Copy the full SHA
    ad7a99c View commit details

Commits on Jul 20, 2020

  1. fixed mutex on coupling

    x44203 committed Jul 20, 2020
    Copy the full SHA
    ffced7b View commit details
  2. Merge pull request #181 from x44203/rigol_caching

    Rigol caching
    azonenberg authored Jul 20, 2020
    Copy the full SHA
    de1bc02 View commit details
Showing with 226 additions and 16 deletions.
  1. +122 −0 scopehal/.clang-format
  2. +101 −16 scopehal/RigolOscilloscope.cpp
  3. +3 −0 scopehal/RigolOscilloscope.h
122 changes: 122 additions & 0 deletions scopehal/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^[^ ]'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Always
117 changes: 101 additions & 16 deletions scopehal/RigolOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -138,9 +138,13 @@ void RigolOscilloscope::FlushConfigCache()
{
lock_guard<recursive_mutex> lock(m_cacheMutex);

m_channelAttenuations.clear();
m_channelCouplings.clear();
m_channelOffsets.clear();
m_channelVoltageRanges.clear();
m_channelsEnabled.clear();
m_channelBandwidthLimits.clear();

m_triggerChannelValid = false;
m_triggerLevelValid = false;
m_triggerTypeValid = false;
@@ -194,22 +198,31 @@ void RigolOscilloscope::DisableChannel(size_t i)

OscilloscopeChannel::CouplingType RigolOscilloscope::GetChannelCoupling(size_t i)
{
lock_guard<recursive_mutex> lock(m_mutex);
{
lock_guard<recursive_mutex> lock(m_cacheMutex);
if(m_channelCouplings.find(i) != m_channelCouplings.end())
return m_channelCouplings[i];
}

lock_guard<recursive_mutex> lock2(m_mutex);

m_transport->SendCommand(m_channels[i]->GetHwname() + ":COUP?");
string reply = m_transport->ReadReply();

lock_guard<recursive_mutex> lock(m_cacheMutex);
if(reply == "AC")
return OscilloscopeChannel::COUPLE_AC_1M;
m_channelCouplings[i] = OscilloscopeChannel::COUPLE_AC_1M;
else if(reply == "DC")
return OscilloscopeChannel::COUPLE_DC_1M;
m_channelCouplings[i] = OscilloscopeChannel::COUPLE_DC_1M;
else /* if(reply == "GND") */
return OscilloscopeChannel::COUPLE_GND;
m_channelCouplings[i] = OscilloscopeChannel::COUPLE_GND;
return m_channelCouplings[i];
}

void RigolOscilloscope::SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type)
{
lock_guard<recursive_mutex> lock(m_mutex);
bool valid = true;
switch(type)
{
case OscilloscopeChannel::COUPLE_AC_1M:
@@ -226,24 +239,41 @@ void RigolOscilloscope::SetChannelCoupling(size_t i, OscilloscopeChannel::Coupli

default:
LogError("Invalid coupling for channel\n");
valid = false;
}

if(valid)
{
lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelCouplings[i] = type;
}
}

double RigolOscilloscope::GetChannelAttenuation(size_t i)
{
lock_guard<recursive_mutex> lock(m_mutex);
{
lock_guard<recursive_mutex> lock(m_cacheMutex);
if(m_channelAttenuations.find(i) != m_channelAttenuations.end())
return m_channelAttenuations[i];
}

lock_guard<recursive_mutex> lock2(m_mutex);

m_transport->SendCommand(m_channels[i]->GetHwname() + ":PROB?");

string reply = m_transport->ReadReply();
double atten;
sscanf(reply.c_str(), "%lf", &atten);

lock_guard<recursive_mutex> lock(m_cacheMutex);
m_channelAttenuations[i] = atten;
return atten;
}

void RigolOscilloscope::SetChannelAttenuation(size_t i, double atten)
{
lock_guard<recursive_mutex> lock(m_mutex);
bool valid = true;
switch((
int)(atten * 10000 +
0.1)) //+ 0.1 in case atten is for example 0.049999 or so, to round it to 0.05 which turns to an int of 500
@@ -331,61 +361,104 @@ void RigolOscilloscope::SetChannelAttenuation(size_t i, double atten)
break;
default:
LogError("Invalid attenuation for channel\n");
valid = false;
}

if(valid)
{
lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelAttenuations[i] = (int)(atten * 10000 + 0.1) * 0.0001;
}
}

int RigolOscilloscope::GetChannelBandwidthLimit(size_t i)
{
{
lock_guard<recursive_mutex> lock(m_cacheMutex);
if(m_channelBandwidthLimits.find(i) != m_channelBandwidthLimits.end())
return m_channelBandwidthLimits[i];
}

lock_guard<recursive_mutex> lock(m_mutex);

m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL?");
string reply = m_transport->ReadReply();

lock_guard<recursive_mutex> lock2(m_cacheMutex);
if(reply == "20M")
return 20;
m_channelBandwidthLimits[i] = 20;
if(reply == "100M")
m_channelBandwidthLimits[i] = 100;
if(reply == "200M")
m_channelBandwidthLimits[i] = 200;
else
return 0;
m_channelBandwidthLimits[i] = m_bandwidth;
return m_channelBandwidthLimits[i];
}

void RigolOscilloscope::SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz)
{
//FIXME
lock_guard<recursive_mutex> lock(m_mutex);

bool valid = true;

if(m_protocol == MSO5)
{
switch(m_bandwidth)
{
case 70:
case 100:
if(limit_mhz <= 20)
if((limit_mhz <= 20) & (limit_mhz != 0))
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL 20M");
else
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL OFF");
break;
case 200:
if(limit_mhz <= 20)
if((limit_mhz <= 20) & (limit_mhz != 0))
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL 20M");
else if(limit_mhz <= 100)
else if((limit_mhz <= 100) & (limit_mhz != 0))
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL 100M");
else
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL OFF");
break;
case 350:
if(limit_mhz <= 20)
if((limit_mhz <= 20) & (limit_mhz != 0))
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL 20M");
else if(limit_mhz <= 100)
else if((limit_mhz <= 100) & (limit_mhz != 0))
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL 100M");
else if(limit_mhz <= 200)
else if((limit_mhz <= 200) & (limit_mhz != 0))
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL 200M");
else
m_transport->SendCommand(m_channels[i]->GetHwname() + ":BWL OFF");
break;
default:
LogError("Invalid model number\n");
valid = false;
}
}
else
{
LogError("m_bandwidth Limit not implemented for this model\n");
valid = false;
}

if(valid)
{
lock_guard<recursive_mutex> lock2(m_cacheMutex);
if(limit_mhz == 0)
m_channelBandwidthLimits[i] = m_bandwidth; // max
if(limit_mhz <= 20)
m_channelBandwidthLimits[i] = 20;
else if(m_bandwidth == 70)
m_channelBandwidthLimits[i] = 70;
else if((limit_mhz <= 100) | (m_bandwidth == 100))
m_channelBandwidthLimits[i] = 100;
else if((limit_mhz <= 200) | (m_bandwidth == 200))
m_channelBandwidthLimits[i] = 200;
else
m_channelBandwidthLimits[i] = m_bandwidth; // 350 MHz
}
}

double RigolOscilloscope::GetChannelVoltageRange(size_t i)
@@ -410,19 +483,25 @@ double RigolOscilloscope::GetChannelVoltageRange(size_t i)
if(m_protocol == MSO5)
range = 8 * range;
m_channelVoltageRanges[i] = range;

return range;
}

void RigolOscilloscope::SetChannelVoltageRange(size_t i, double range)
{
{
lock_guard<recursive_mutex> lock2(m_cacheMutex);
m_channelVoltageRanges[i] = range;
}

lock_guard<recursive_mutex> lock(m_mutex);
char buf[128];

if(m_protocol == DS)
snprintf(buf, sizeof(buf), "%s:RANGE %f", m_channels[i]->GetHwname().c_str(), range);
else if(m_protocol == MSO5)
snprintf(buf, sizeof(buf), "%s:SCALE %f", m_channels[i]->GetHwname().c_str(), range / 8);
m_transport->SendCommand(buf);
m_channelVoltageRanges[i] = range;

//FIXME
}
@@ -449,6 +528,7 @@ double RigolOscilloscope::GetChannelOffset(size_t i)
string reply = m_transport->ReadReply();
double offset;
sscanf(reply.c_str(), "%lf", &offset);

lock_guard<recursive_mutex> lock(m_cacheMutex);
m_channelOffsets[i] = offset;
return offset;
@@ -577,15 +657,18 @@ bool RigolOscilloscope::AcquireData(bool toQueue)
size_t end = npoint + maxpoints;
if(end > npoints)
end = npoints;
snprintf(tmp, sizeof(tmp), "WAV:STOP %zu", end); //Here it is zero based, so it gets from 1-1000
snprintf(tmp, sizeof(tmp), "WAV:STOP %zu", end); //Here it is zero based, so it gets from 1-1000
m_transport->SendCommand(tmp);

//Ask for the data block
m_transport->SendCommand("WAV:DATA?");

//Read block header
unsigned char header[12] = {0};

double start = GetTime();
m_transport->ReadRawData(11, header);
LogWarning("Time %f\n", (GetTime() - start));

//Look up the block size
//size_t blocksize = end - npoints;
@@ -650,6 +733,7 @@ bool RigolOscilloscope::AcquireData(bool toQueue)
}

//LogDebug("Acquisition done\n");

return true;
}

@@ -687,6 +771,8 @@ size_t RigolOscilloscope::GetTriggerChannelIndex()
{
//Check cache
//No locking, worst case we return a result a few seconds old

lock_guard<recursive_mutex> lock2(m_cacheMutex);
if(m_triggerChannelValid)
return m_triggerChannel;

@@ -969,7 +1055,6 @@ void RigolOscilloscope::SetTriggerOffset(int64_t offset)
m_transport->SendCommand(buf);
}


int64_t RigolOscilloscope::GetTriggerOffset()
{
if(m_triggerOffsetValid)
3 changes: 3 additions & 0 deletions scopehal/RigolOscilloscope.h
Original file line number Diff line number Diff line change
@@ -103,8 +103,11 @@ class RigolOscilloscope : public SCPIOscilloscope
unsigned int m_analogChannelCount;

//config cache
std::map<size_t, double> m_channelAttenuations;
std::map<size_t, OscilloscopeChannel::CouplingType> m_channelCouplings;
std::map<size_t, double> m_channelOffsets;
std::map<size_t, double> m_channelVoltageRanges;
std::map<size_t, unsigned int> m_channelBandwidthLimits;
std::map<int, bool> m_channelsEnabled;
bool m_triggerChannelValid;
size_t m_triggerChannel;