Skip to content

Commit ae4e328

Browse files
committed
Cached channel digital threshold value.
1 parent a833c4a commit ae4e328

8 files changed

+83
-13
lines changed

scopehal/LeCroyOscilloscope.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ void LeCroyOscilloscope::FlushConfigCache()
10541054

10551055
m_channelVoltageRanges.clear();
10561056
m_channelOffsets.clear();
1057+
m_channelDigitalThresholds.clear();
10571058
m_channelsEnabled.clear();
10581059
m_channelDeskew.clear();
10591060
m_probeIsActive.clear();
@@ -4054,13 +4055,24 @@ float LeCroyOscilloscope::GetDigitalThreshold(size_t channel)
40544055
if( (channel < m_digitalChannelBase) || (m_digitalChannelCount == 0) )
40554056
return 0;
40564057

4058+
{
4059+
lock_guard<recursive_mutex> lock(m_cacheMutex);
4060+
4061+
if(m_channelDigitalThresholds.find(channel) != m_channelDigitalThresholds.end())
4062+
return m_channelDigitalThresholds[channel];
4063+
}
4064+
40574065
string reply;
40584066
if(channel <= m_digitalChannels[7]->GetIndex() )
40594067
reply = m_transport->SendCommandQueuedWithReply("VBS? 'return = app.LogicAnalyzer.MSxxThreshold0'");
40604068
else
40614069
reply = m_transport->SendCommandQueuedWithReply("VBS? 'return = app.LogicAnalyzer.MSxxThreshold1'");
40624070

4063-
return atof(reply.c_str());
4071+
float result = atof(reply.c_str());
4072+
4073+
lock_guard<recursive_mutex> lock(m_cacheMutex);
4074+
m_channelDigitalThresholds[channel] = result;
4075+
return result;
40644076
}
40654077

40664078
void LeCroyOscilloscope::SetDigitalHysteresis(size_t channel, float level)

scopehal/LeCroyOscilloscope.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ class LeCroyOscilloscope
352352
//Cached configuration
353353
std::map<size_t, float> m_channelVoltageRanges;
354354
std::map<size_t, float> m_channelOffsets;
355+
std::map<size_t, float> m_channelDigitalThresholds;
355356
std::map<size_t, size_t> m_channelNavg;
356357
std::map<int, bool> m_channelsEnabled;
357358
bool m_sampleRateValid;

scopehal/RSRTO6Oscilloscope.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ void RSRTO6Oscilloscope::FlushConfigCache()
243243
m_channelOffsets.clear();
244244
m_channelVoltageRanges.clear();
245245
m_channelsEnabled.clear();
246+
m_channelDigitalThresholds.clear();
246247
m_channelCouplings.clear();
247248
m_channelAttenuations.clear();
248249

@@ -656,8 +657,21 @@ bool RSRTO6Oscilloscope::IsDigitalThresholdConfigurable()
656657

657658
float RSRTO6Oscilloscope::GetDigitalThreshold(size_t channel)
658659
{
659-
// Cache?
660-
return stof(m_transport->SendCommandQueuedWithReply("DIG" + to_string(HWDigitalNumber(channel)) + ":THR?"));
660+
if( (channel < m_digitalChannelBase) || (m_digitalChannelCount == 0) )
661+
return 0;
662+
663+
{
664+
lock_guard<recursive_mutex> lock(m_cacheMutex);
665+
666+
if(m_channelDigitalThresholds.find(channel) != m_channelDigitalThresholds.end())
667+
return m_channelDigitalThresholds[channel];
668+
}
669+
670+
float result = stof(m_transport->SendCommandQueuedWithReply("DIG" + to_string(HWDigitalNumber(channel)) + ":THR?"));
671+
672+
lock_guard<recursive_mutex> lock(m_cacheMutex);
673+
m_channelDigitalThresholds[channel] = result;
674+
return result;
661675
}
662676

663677
void RSRTO6Oscilloscope::SetDigitalThreshold(size_t channel, float level)

scopehal/RSRTO6Oscilloscope.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class RSRTO6Oscilloscope
161161
std::map<size_t, float> m_channelOffsets;
162162
std::map<size_t, float> m_channelVoltageRanges;
163163
std::map<int, bool> m_channelsEnabled;
164+
std::map<size_t, float> m_channelDigitalThresholds;
164165
std::map<size_t, OscilloscopeChannel::CouplingType> m_channelCouplings;
165166
std::map<size_t, int> m_channelBandwidthLimits;
166167
std::map<size_t, double> m_channelAttenuations;

scopehal/SiglentSCPIOscilloscope.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ void SiglentSCPIOscilloscope::FlushConfigCache()
650650
m_channelOffsets.clear();
651651
m_channelsEnabled.clear();
652652
m_channelDeskew.clear();
653+
m_channelDigitalThresholds.clear();
653654
m_probeIsActive.clear();
654655
m_sampleRateValid = false;
655656
m_memoryDepthValid = false;
@@ -3726,7 +3727,18 @@ float SiglentSCPIOscilloscope::GetDigitalHysteresis(size_t /*channel*/)
37263727

37273728
float SiglentSCPIOscilloscope::GetDigitalThreshold(size_t channel)
37283729
{
3730+
if( (channel < m_digitalChannelBase) || (m_digitalChannelCount == 0) )
3731+
return 0;
3732+
37293733
channel -= m_analogChannelCount;
3734+
{
3735+
lock_guard<recursive_mutex> lock(m_cacheMutex);
3736+
3737+
if(m_channelDigitalThresholds.find(channel) != m_channelDigitalThresholds.end())
3738+
return m_channelDigitalThresholds[channel];
3739+
}
3740+
3741+
float result = 0.0f;
37303742

37313743
string r = converse(":DIGITAL:THRESHOLD%d?", (channel / 8) + 1).c_str();
37323744

@@ -3737,14 +3749,21 @@ float SiglentSCPIOscilloscope::GetDigitalThreshold(size_t channel)
37373749
i++;
37383750

37393751
if(c_sds2000xp_threshold_table[i].name)
3740-
return c_sds2000xp_threshold_table[i].val;
3741-
3742-
// Didn't match a standard, check for custom
3743-
if(!strncmp(r.c_str(), c_custom_thresh, strlen(c_custom_thresh)))
3744-
return strtof(&(r.c_str()[strlen(c_custom_thresh)]), NULL);
3752+
{
3753+
result = c_sds2000xp_threshold_table[i].val;
3754+
}
3755+
else if(!strncmp(r.c_str(), c_custom_thresh, strlen(c_custom_thresh)))
3756+
{ // Didn't match a standard, check for custom
3757+
result = strtof(&(r.c_str()[strlen(c_custom_thresh)]), NULL);
3758+
}
3759+
else
3760+
{
3761+
LogWarning("GetDigitalThreshold unrecognised value [%s]\n", r.c_str());
3762+
}
37453763

3746-
LogWarning("GetDigitalThreshold unrecognised value [%s]\n", r.c_str());
3747-
return 0.0f;
3764+
lock_guard<recursive_mutex> lock(m_cacheMutex);
3765+
m_channelDigitalThresholds[channel] = result;
3766+
return result;
37483767
}
37493768

37503769
void SiglentSCPIOscilloscope::SetDigitalHysteresis(size_t /*channel*/, float /*level*/)

scopehal/SiglentSCPIOscilloscope.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ class SiglentSCPIOscilloscope : public virtual SCPIOscilloscope
347347
//Cached configuration
348348
std::map<size_t, float> m_channelVoltageRanges;
349349
std::map<size_t, float> m_channelOffsets;
350+
std::map<size_t, float> m_channelDigitalThresholds;
350351
std::map<int, bool> m_channelsEnabled;
351352
bool m_sampleRateValid;
352353
int64_t m_sampleRate;

scopehal/TektronixOscilloscope.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ TektronixOscilloscope::TektronixOscilloscope(SCPITransport* transport)
7272
, m_dmmModeValid(false)
7373
, m_dmmMode(Multimeter::DC_VOLTAGE)
7474
, m_digitalChannelBase(0)
75+
, m_digitalChannelCount(0)
7576
, m_triggerArmed(false)
7677
, m_triggerOneShot(false)
7778
, m_maxBandwidth(1000)
@@ -225,6 +226,7 @@ TektronixOscilloscope::TektronixOscilloscope(SCPITransport* transport)
225226
m_flexChannelParents[chan] = i;
226227
m_flexChannelLanes[chan] = j;
227228
m_channels.push_back(chan);
229+
m_digitalChannelCount++;
228230
}
229231
}
230232
break;
@@ -428,6 +430,7 @@ void TektronixOscilloscope::FlushConfigCache()
428430

429431
m_channelOffsets.clear();
430432
m_channelVoltageRanges.clear();
433+
m_channelDigitalThresholds.clear();
431434
m_channelCouplings.clear();
432435
m_channelsEnabled.clear();
433436
m_probeTypes.clear();
@@ -3598,7 +3601,17 @@ float TektronixOscilloscope::GetDigitalHysteresis(size_t /*channel*/)
35983601

35993602
float TektronixOscilloscope::GetDigitalThreshold(size_t channel)
36003603
{
3601-
//TODO: caching?
3604+
if( (channel < m_digitalChannelBase) || (m_digitalChannelCount == 0) )
3605+
return 0;
3606+
3607+
{
3608+
lock_guard<recursive_mutex> lock(m_cacheMutex);
3609+
3610+
if(m_channelDigitalThresholds.find(channel) != m_channelDigitalThresholds.end())
3611+
return m_channelDigitalThresholds[channel];
3612+
}
3613+
3614+
float result = -1;
36023615

36033616
auto chan = GetOscilloscopeChannel(channel);
36043617

@@ -3607,14 +3620,17 @@ float TektronixOscilloscope::GetDigitalThreshold(size_t channel)
36073620
case FAMILY_MSO5:
36083621
case FAMILY_MSO6:
36093622
//note, group IDs are one based but lane IDs are zero based!
3610-
return stof(m_transport->SendCommandQueuedWithReply(
3623+
result = stof(m_transport->SendCommandQueuedWithReply(
36113624
string("DIGGRP") + to_string(m_flexChannelParents[chan]+1) +
36123625
":D" + to_string(m_flexChannelLanes[chan]) + ":THR?"));
36133626

36143627
default:
36153628
break;
36163629
}
3617-
return -1;
3630+
3631+
lock_guard<recursive_mutex> lock(m_cacheMutex);
3632+
m_channelDigitalThresholds[channel] = result;
3633+
return result;
36183634
}
36193635

36203636
void TektronixOscilloscope::SetDigitalHysteresis(size_t /*channel*/, float /*level*/)

scopehal/TektronixOscilloscope.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ class TektronixOscilloscope
300300
///@brief Cached map of <channel ID, full scale range>
301301
std::map<size_t, float> m_channelVoltageRanges;
302302

303+
///@brief Cached map of <channel ID, digital threshold>
304+
std::map<size_t, float> m_channelDigitalThresholds;
305+
303306
///@brief Cached map of <channel ID, coupling>
304307
std::map<size_t, OscilloscopeChannel::CouplingType> m_channelCouplings;
305308

@@ -358,6 +361,9 @@ class TektronixOscilloscope
358361
///@brief Starting index for digital channels
359362
size_t m_digitalChannelBase;
360363

364+
///@brief Nuber of digital channels
365+
size_t m_digitalChannelCount;
366+
361367
///@brief Starting index for spectrum channels
362368
size_t m_spectrumChannelBase;
363369

0 commit comments

Comments
 (0)