Skip to content

Commit

Permalink
Util: Add GetUsedHWDACFromLNB helper function to retrieve hardware ty…
Browse files Browse the repository at this point in the history
…pe from LNB

- to simplify the task to determine the hardware type at the point when a sweep was
  measured and the associated LNB entries were created, the helper function
  GetUsedHWDACFromLNB was created.

- Unify method in other locations that retrieve the hardware type from the LNB
  • Loading branch information
MichaelHuth committed Jul 21, 2023
1 parent ca807f0 commit 7c8c65e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
34 changes: 24 additions & 10 deletions Packages/MIES/MIES_MiesUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2694,19 +2694,16 @@ Function CreateTiledChannelGraph(string graph, WAVE config, variable sweepNo, WA
numADCs = DimSize(ADCs, ROWS)
numTTLs = DimSize(TTLs, ROWS)

// introduced in db531d20 (DC_PlaceDataIn ITCDataWave: Document the digitizer hardware type, 2018-07-30)
// before that we only had ITC hardware
hardwareType = GetLastSettingIndep(numericalValues, sweepNo, "Digitizer Hardware Type", DATA_ACQUISITION_MODE, defValue = HARDWARE_ITC_DAC)
hardwareType = GetUsedHWDACFromLNB(numericalValues, sweepNo)
WAVE/Z ttlRackZeroBits = GetLastSetting(numericalValues, sweepNo, "TTL rack zero bits", DATA_ACQUISITION_MODE)
WAVE/Z ttlRackOneBits = GetLastSetting(numericalValues, sweepNo, "TTL rack one bits", DATA_ACQUISITION_MODE)
WAVE/Z/T ttlChannels = GetLastSetting(textualValues, sweepNo, "TTL channels", DATA_ACQUISITION_MODE)

if(tgs.splitTTLBits && numTTLs > 0)
if(!WaveExists(ttlRackZeroBits) && !WaveExists(ttlRackOneBits) && hardwareType == HARDWARE_ITC_DAC)
print "Turning off tgs.splitTTLBits as some labnotebook entries could not be found"
ControlWindowToFront()
tgs.splitTTLBits = 0
elseif(WaveExists(ttlChannels))
elseif(hardwareType == HARDWARE_NI_DAC)
// NI hardware does use one channel per bit so we don't need that here
tgs.splitTTLBits = 0
endif
Expand Down Expand Up @@ -4734,6 +4731,18 @@ threadsafe Function GetTTLBits(numericalValues, sweep, channel)
return ttlBits[index]
End

/// @brief Returns the used hardware DAC type from the LNB
///
/// @param numericalValues Numerical labnotebook values
/// @param sweep Sweep number
/// @returns used hardware dac type @sa HardwareDACTypeConstants
threadsafe Function GetUsedHWDACFromLNB(WAVE numericalValues, variable sweep)

// introduced in db531d20 (DC_PlaceDataIn ITCDataWave: Document the digitizer hardware type, 2018-07-30)
// before that we only had ITC hardware
return GetLastSettingIndep(numericalValues, sweep, "Digitizer Hardware Type", UNKNOWN_MODE, defValue = HARDWARE_ITC_DAC)
End

/// @brief Return a wave with the requested TTL channel information defined by TTLmode
///
/// @param numericalValues Numerical labnotebook values
Expand All @@ -4742,14 +4751,19 @@ End
/// @param TTLmode One of @ref ActiveChannelsTTLMode.
threadsafe static Function/WAVE GetActiveChannelsTTL(WAVE numericalValues, WAVE textualValues, variable sweep, variable TTLmode)

variable i, index, first, last, haveRackZero, haveRackOne, numHWTTLChannels, bits, hwChannel
variable i, index, first, last, haveRackZero, haveRackOne, numHWTTLChannels, bits, hwChannel, hwDACType

index = GetIndexForHeadstageIndepData(numericalValues)

// present since 2f56481a (DC_MakeNITTLWave: Document TTL settings and rework it completely, 2018-09-06)
WAVE/T/Z ttlChannels = GetLastSetting(textualValues, sweep, "TTL channels", DATA_ACQUISITION_MODE)
if(WaveExists(ttlChannels))
// NI hardware
hwDACType = GetUsedHWDACFromLNB(numericalValues, sweep)
ASSERT_TS(hwDACType == HARDWARE_ITC_DAC || hwDACType == HARDWARE_NI_DAC, "Unsupported hardware dac type")

if(hwDACType == HARDWARE_NI_DAC)
// present since 2f56481a (DC_MakeNITTLWave: Document TTL settings and rework it completely, 2018-09-06)
WAVE/T/Z ttlChannels = GetLastSetting(textualValues, sweep, "TTL channels", DATA_ACQUISITION_MODE)
if(!WaveExists(ttlChannels))
return $""
endif
switch(TTLmode)
case TTL_HARDWARE_CHANNEL: // intended drop-through
case TTL_DAEPHYS_CHANNEL:
Expand Down
23 changes: 6 additions & 17 deletions Packages/MIES/MIES_NeuroDataWithoutBorders.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,12 @@ threadsafe static Function/S NWB_GenerateDeviceDescription(string device, WAVE n
// digitizer info is fixed per "device" device
sweepNo = 0

hardwareType = GetLastSettingIndep(numericalValues, sweepNo, "Digitizer Hardware Type", UNKNOWN_MODE)
hardwareType = GetUsedHWDACFromLNB(numericalValues, sweepNo)

if(IsNaN(hardwareType))
// if we don't have a hardware type this must be ITC hardware
hardwareType = HARDWARE_ITC_DAC

ASSERT_TS(ParseDeviceString(device, deviceType, deviceNumber), "Could not parse device")
hardwareName = deviceType
else
// present since e2302f5d (DC_PlaceDataInHardwareDataWave: Add hardware name and serial numbers to the labnotebook, 2019-02-22)
hardwareName = GetLastSettingTextIndep(textualValues, sweepNo, "Digitizer Hardware Name", UNKNOWN_MODE)

if(IsEmpty(hardwareName))
hardwareName = device
endif
// present since e2302f5d (DC_PlaceDataInHardwareDataWave: Add hardware name and serial numbers to the labnotebook, 2019-02-22)
hardwareName = GetLastSettingTextIndep(textualValues, sweepNo, "Digitizer Hardware Name", UNKNOWN_MODE)
if(IsEmpty(hardwareName))
hardwareName = device
endif

switch(hardwareType)
Expand Down Expand Up @@ -1133,9 +1124,7 @@ threadsafe static Function NWB_AppendSweepLowLevel(STRUCT NWBAsyncParameters &s)

NWB_ClearWriteChannelParams(params)

// introduced in db531d20 (DC_PlaceDataInITCDataWave: Document the digitizer hardware type, 2018-07-30)
// before that we only had ITC hardware
hardwareType = GetLastSettingIndep(s.numericalValues, s.sweep, "Digitizer Hardware Type", DATA_ACQUISITION_MODE, defValue = HARDWARE_ITC_DAC)
hardwareType = GetUsedHWDACFromLNB(s.numericalValues, s.sweep)
WAVE/Z/T ttlStimsets = GetTTLLabnotebookEntry(s.textualValues, LABNOTEBOOK_TTL_STIMSETS, s.sweep)

// i has the following meaning:
Expand Down

0 comments on commit 7c8c65e

Please sign in to comment.