@@ -68,7 +68,7 @@ void allocateDoubleArray3D(std::vector<std::vector<std::vector<double> > >& arra
6868
6969DataThread* RHD2000Thread::createDataThread (SourceNode *sn)
7070{
71- return new RHD2000Thread (sn);
71+ return new RHD2000Thread (sn);
7272}
7373
7474RHD2000Thread::RHD2000Thread (SourceNode* sn) : DataThread(sn),
@@ -77,8 +77,8 @@ RHD2000Thread::RHD2000Thread(SourceNode* sn) : DataThread(sn),
7777 deviceFound(false ),
7878 isTransmitting(false ),
7979 dacOutputShouldChange(false ),
80+ acquireAuxChannels(false ),
8081 acquireAdcChannels(false ),
81- acquireAuxChannels(true ),
8282 fastSettleEnabled(false ),
8383 fastTTLSettleEnabled(false ),
8484 fastSettleTTLChannel(-1 ),
@@ -818,6 +818,7 @@ void RHD2000Thread::setDefaultChannelNames()
818818 stream_prefix.add (" D1" );
819819 stream_prefix.add (" D2" );
820820
821+ // headstage channels
821822 for (int i = 0 ; i < MAX_NUM_HEADSTAGES; i++)
822823 {
823824 if (headstagesArray[i]->isPlugged ())
@@ -839,32 +840,33 @@ void RHD2000Thread::setDefaultChannelNames()
839840 }
840841 }
841842 }
842- // Aux channels
843- for ( int i = 0 ; i < MAX_NUM_HEADSTAGES; i++ )
843+ // AUX channels
844+ if (acquireAuxChannels )
844845 {
845- if (headstagesArray[i]-> isPlugged () )
846+ for ( int i = 0 ; i < MAX_NUM_HEADSTAGES; i++ )
846847 {
847- for ( int k = 0 ; k < 3 ; k++ )
848+ if (headstagesArray[i]-> isPlugged () )
848849 {
849- int chn = channelNumber - 1 ;
850-
851- if (newScan || !channelInfo[chn].modified )
850+ for (int k = 0 ; k < 3 ; k++)
852851 {
853- ChannelCustomInfo in;
854- if (numberingScheme == 1 )
855- in.name = " AUX" + String (aux_counter);
856- else
857- in.name = " AUX_" + stream_prefix[i] + " _" + String (1 + k);
858- in.gain = getBitVolts (sn->getDataChannel (chn));
859- channelInfo.set (chn, in);
860-
852+ int chn = channelNumber - 1 ;
853+ if (newScan || !channelInfo[chn].modified )
854+ {
855+ ChannelCustomInfo in;
856+ if (numberingScheme == 1 )
857+ in.name = " AUX" + String (aux_counter);
858+ else
859+ in.name = " AUX_" + stream_prefix[i] + " _" + String (1 + k);
860+ in.gain = getBitVolts (sn->getDataChannel (chn));
861+ channelInfo.set (chn, in);
862+ }
863+ channelNumber++;
864+ aux_counter++;
861865 }
862- channelNumber++;
863- aux_counter++;
864866 }
865867 }
866868 }
867- // ADC channels
869+ // ADC channels
868870 if (acquireAdcChannels)
869871 {
870872 for (int k = 0 ; k < 8 ; k++)
@@ -1168,12 +1170,23 @@ int RHD2000Thread::getChannelsInHeadstage (int hsNum) const
11681170
11691171}*/
11701172
1173+ void RHD2000Thread::enableAuxs (bool t)
1174+ {
1175+ acquireAuxChannels = t;
1176+ sourceBuffers[0 ]->resize (getNumChannels (), 10000 );
1177+ updateRegisters ();
1178+ }
1179+
11711180void RHD2000Thread::enableAdcs (bool t)
11721181{
11731182 acquireAdcChannels = t;
11741183 sourceBuffers[0 ]->resize (getNumChannels (), 10000 );
11751184}
11761185
1186+ bool RHD2000Thread::isAuxEnabled ()
1187+ {
1188+ return acquireAuxChannels;
1189+ }
11771190
11781191void RHD2000Thread::setSampleRate (int sampleRateIndex, bool isTemporary)
11791192{
@@ -1344,10 +1357,10 @@ void RHD2000Thread::updateRegisters()
13441357 chipRegisters.enableDsp (dspEnabled);
13451358 // std::cout << "DSP Offset Status " << dspEnabled << std::endl;
13461359
1347- // turn on aux inputs
1348- chipRegisters.enableAux1 (true );
1349- chipRegisters.enableAux2 (true );
1350- chipRegisters.enableAux3 (true );
1360+ // enable/disable aux inputs:
1361+ chipRegisters.enableAux1 (acquireAuxChannels );
1362+ chipRegisters.enableAux2 (acquireAuxChannels );
1363+ chipRegisters.enableAux3 (acquireAuxChannels );
13511364
13521365 chipRegisters.createCommandListRegisterConfig (commandList, true );
13531366 // Upload version with ADC calibration to AuxCmd3 RAM Bank 0.
@@ -1513,11 +1526,13 @@ bool RHD2000Thread::updateBuffer()
15131526 bool return_code;
15141527
15151528 return_code = evalBoard->readRawDataBlock (&bufferPtr);
1529+ // see Rhd2000DataBlock::fillFromUsbBuffer() for an idea of data order in bufferPtr
15161530
15171531 int index = 0 ;
15181532 int auxIndex, chanIndex;
15191533 int numStreams = enabledStreams.size ();
15201534 int nSamps = Rhd2000DataBlock::getSamplesPerDataBlock (evalBoard->isUSB3 ());
1535+
15211536 // evalBoard->printFIFOmetrics();
15221537 for (int samp = 0 ; samp < nSamps; samp++)
15231538 {
@@ -1529,71 +1544,74 @@ bool RHD2000Thread::updateBuffer()
15291544 break ;
15301545 }
15311546
1532- index += 8 ;
1533- timestamps.set (0 ,Rhd2000DataBlock::convertUsbTimeStamp (bufferPtr,index));
1534- index += 4 ;
1535- auxIndex = index;
1536- // skip the aux channels
1537- index += numStreams * 6 ;
1538- // do the neural data channels first
1539- for (int dataStream = 0 ; dataStream < numStreams; dataStream++)
1540- {
1541- int nChans = numChannelsPerDataStream[dataStream];
1542- chanIndex = index + 2 *dataStream;
1543- if ((chipId[dataStream] == CHIP_ID_RHD2132) && (nChans == 16 )) // RHD2132 16ch. headstage
1544- {
1545- chanIndex += 2 * RHD2132_16CH_OFFSET*numStreams;
1546- }
1547- for (int chan = 0 ; chan < nChans; chan++)
1548- {
1549- channel++;
1550- thisSample[channel] = float (*(uint16*)(bufferPtr + chanIndex) - 32768 )*0 .195f ;
1551- chanIndex += 2 *numStreams;
1552- }
1553- }
1554- index += 64 * numStreams;
1555- // now we can do the aux channels
1556- auxIndex += 2 *numStreams;
1557- for (int dataStream = 0 ; dataStream < numStreams; dataStream++)
1558- {
1559- if (chipId[dataStream] != CHIP_ID_RHD2164_B)
1560- {
1561- int auxNum = (samp+3 ) % 4 ;
1562- if (auxNum < 3 )
1563- {
1564- auxSamples[dataStream][auxNum] = float (*(uint16*)(bufferPtr + auxIndex) - 32768 )*0.0000374 ;
1565- }
1566- for (int chan = 0 ; chan < 3 ; chan++)
1567- {
1568- channel++;
1569- if (auxNum == 3 )
1570- {
1571- auxBuffer[channel] = auxSamples[dataStream][chan];
1572- }
1573- thisSample[channel] = auxBuffer[channel];
1574- }
1575- }
1576- auxIndex += 2 ;
1577-
1578- }
1579- index += 2 * numStreams;
1580- if (acquireAdcChannels)
1581- {
1582- for (int adcChan = 0 ; adcChan < 8 ; ++adcChan)
1583- {
1584-
1585- index += 2 ;
1586- index += 16 ;
1547+ index += 8 ; // magic number header width (bytes)
1548+ timestamps.set (0 , Rhd2000DataBlock::convertUsbTimeStamp (bufferPtr, index));
1549+ index += 4 ; // timestamp width
1550+ auxIndex = index; // aux chans start at this offset
1551+ // skip aux channels for now
1552+ index += 6 * numStreams; // width of the 3 aux chans
1553+ // copy 64 neural data channels
1554+ for (int dataStream = 0 ; dataStream < numStreams; dataStream++)
1555+ {
1556+ int nChans = numChannelsPerDataStream[dataStream];
1557+ chanIndex = index + 2 *dataStream;
1558+ if ((chipId[dataStream] == CHIP_ID_RHD2132) && (nChans == 16 )) // RHD2132 16ch. headstage
1559+ {
1560+ chanIndex += 2 * RHD2132_16CH_OFFSET*numStreams;
1561+ }
1562+ for (int chan = 0 ; chan < nChans; chan++)
1563+ {
1564+ channel++;
1565+ thisSample[channel] = float (*(uint16*)(bufferPtr + chanIndex) - 32768 )*0 .195f ;
1566+ chanIndex += 2 *numStreams; // single chan width (2 bytes)
1567+ }
1568+ }
1569+ index += 64 * numStreams; // neural data width
1570+ auxIndex += 2 * numStreams; // mspacek: not clear why this is here
1571+ // copy the 3 aux channels
1572+ if (acquireAuxChannels)
1573+ {
1574+ for (int dataStream = 0 ; dataStream < numStreams; dataStream++)
1575+ {
1576+ if (chipId[dataStream] != CHIP_ID_RHD2164_B)
1577+ {
1578+ int auxNum = (samp+3 ) % 4 ;
1579+ if (auxNum < 3 )
1580+ {
1581+ auxSamples[dataStream][auxNum] = float (*(uint16*)(bufferPtr + auxIndex) - 32768 )*0.0000374 ;
1582+ }
1583+ for (int chan = 0 ; chan < 3 ; chan++)
1584+ {
1585+ channel++;
1586+ if (auxNum == 3 )
1587+ {
1588+ auxBuffer[channel] = auxSamples[dataStream][chan];
1589+ }
1590+ thisSample[channel] = auxBuffer[channel];
1591+ }
1592+ }
1593+ auxIndex += 2 ; // single chan width (2 bytes)
1594+ }
1595+ }
1596+ index += 2 * numStreams; // skip over filler word at the end of each data stream
1597+ // copy the 8 ADC channels
1598+ if (acquireAdcChannels)
1599+ {
1600+ for (int adcChan = 0 ; adcChan < 8 ; ++adcChan)
1601+ {
1602+
15871603 channel++;
15881604 // ADC waveform units = volts
15891605 thisSample[channel] = adcRangeSettings[adcChan] == 0 ?
15901606 // 0.000050354 * float(dataBlock->boardAdcData[adcChan][samp]);
15911607 0.00015258789 * float (*(uint16*)(bufferPtr + index)) - 5 - 0.4096 : // account for +/-5V input range and DC offset
15921608 0.00030517578 * float (*(uint16*)(bufferPtr + index));
1609+ index += 2 ; // single chan width (2 bytes)
15931610 }
15941611 }
15951612 else
15961613 {
1614+ index += 16 ; // skip ADC chans (8 * 2 bytes)
15971615 }
15981616 ttlEventWords.set (0 , *(uint16*)(bufferPtr + index));
15991617 index += 4 ;
0 commit comments