Skip to content

Commit f87261f

Browse files
authored
Merge pull request #144 from open-ephys-plugins/issue-135
Automatically save Probe Interface files when recording starts
2 parents 3ddbd9a + e1481f0 commit f87261f

28 files changed

+702
-196
lines changed

Source/Devices/AnalogIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ AnalogIO::AnalogIO (std::string name, std::string hubName, const oni_dev_idx_t d
2828
: OnixDevice (name, hubName, AnalogIO::getDeviceType(), deviceIdx_, oni_ctx)
2929
{
3030
StreamInfo analogInputStream = StreamInfo (
31-
OnixDevice::createStreamName ({ getHubName(), name, "AnalogInput" }),
31+
createStreamName ("AnalogInput", false),
3232
"Analog Input data",
3333
getStreamIdentifier(),
3434
numChannels,

Source/Devices/Bno055.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Bno055::Bno055 (std::string name, std::string hubName, const oni_dev_idx_t devic
3131

3232
std::string port = getPortName (deviceIdx);
3333
StreamInfo eulerAngleStream = StreamInfo (
34-
OnixDevice::createStreamName ({ port, getHubName(), getName(), "Euler" }),
34+
createStreamName ("Euler"),
3535
"Bosch Bno055 9-axis inertial measurement unit (IMU) Euler angle",
3636
streamIdentifier,
3737
3,
@@ -46,7 +46,7 @@ Bno055::Bno055 (std::string name, std::string hubName, const oni_dev_idx_t devic
4646
streamInfos.add (eulerAngleStream);
4747

4848
StreamInfo quaternionStream = StreamInfo (
49-
OnixDevice::createStreamName ({ port, getHubName(), getName(), "Quaternion" }),
49+
createStreamName ("Quaternion"),
5050
"Bosch Bno055 9-axis inertial measurement unit (IMU) Quaternion",
5151
streamIdentifier,
5252
4,
@@ -61,7 +61,7 @@ Bno055::Bno055 (std::string name, std::string hubName, const oni_dev_idx_t devic
6161
streamInfos.add (quaternionStream);
6262

6363
StreamInfo accelerationStream = StreamInfo (
64-
OnixDevice::createStreamName ({ port, getHubName(), getName(), "Acceleration" }),
64+
createStreamName ("Acceleration"),
6565
"Bosch Bno055 9-axis inertial measurement unit (IMU) Acceleration",
6666
streamIdentifier,
6767
3,
@@ -76,7 +76,7 @@ Bno055::Bno055 (std::string name, std::string hubName, const oni_dev_idx_t devic
7676
streamInfos.add (accelerationStream);
7777

7878
StreamInfo gravityStream = StreamInfo (
79-
OnixDevice::createStreamName ({ port, getHubName(), getName(), "Gravity" }),
79+
createStreamName ("Gravity"),
8080
"Bosch Bno055 9-axis inertial measurement unit (IMU) Gravity",
8181
streamIdentifier,
8282
3,
@@ -91,7 +91,7 @@ Bno055::Bno055 (std::string name, std::string hubName, const oni_dev_idx_t devic
9191
streamInfos.add (gravityStream);
9292

9393
StreamInfo temperatureStream = StreamInfo (
94-
OnixDevice::createStreamName ({ port, getHubName(), getName(), "Temperature" }),
94+
createStreamName ("Temperature"),
9595
"Bosch Bno055 9-axis inertial measurement unit (IMU) Temperature",
9696
streamIdentifier,
9797
1,
@@ -105,7 +105,7 @@ Bno055::Bno055 (std::string name, std::string hubName, const oni_dev_idx_t devic
105105
streamInfos.add (temperatureStream);
106106

107107
StreamInfo calibrationStatusStream = StreamInfo (
108-
OnixDevice::createStreamName ({ port, getHubName(), getName(), "Calibration" }),
108+
createStreamName ("Calibration"),
109109
"Bosch Bno055 9-axis inertial measurement unit (IMU) Calibration status",
110110
streamIdentifier,
111111
4,

Source/Devices/DigitalIO.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ DigitalIO::DigitalIO (std::string name, std::string hubName, const oni_dev_idx_t
2929
: OnixDevice (name, hubName, DigitalIO::getDeviceType(), deviceIdx_, oni_ctx)
3030
{
3131
StreamInfo digitalInputStream = StreamInfo (
32-
OnixDevice::createStreamName ({ getHubName(), name, "DigitalInputs" }),
32+
createStreamName ({ getHubName(), name, "DigitalInputs" }),
3333
"Digital Inputs data",
3434
getStreamIdentifier(),
3535
NumDigitalInputs,
@@ -43,7 +43,7 @@ DigitalIO::DigitalIO (std::string name, std::string hubName, const oni_dev_idx_t
4343
streamInfos.add (digitalInputStream);
4444

4545
StreamInfo digitalButtonStream = StreamInfo (
46-
OnixDevice::createStreamName ({ getHubName(), name, "DigitalButtons" }),
46+
createStreamName ({ getHubName(), name, "DigitalButtons" }),
4747
"Digital Buttons data",
4848
getStreamIdentifier(),
4949
NumButtons,
@@ -111,7 +111,7 @@ EventChannel::Settings DigitalIO::getEventChannelSettings (DataStream* stream)
111111
{
112112
EventChannel::Settings settings {
113113
EventChannel::Type::TTL,
114-
OnixDevice::createStreamName ({ getHubName(), getName(), "Events" }),
114+
createStreamName ("Events", false),
115115
"Digital inputs and breakout button states coming from a DigitalIO device",
116116
getStreamIdentifier() + ".event.digital",
117117
stream,

Source/Devices/HarpSyncInput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ HarpSyncInput::HarpSyncInput (std::string name, std::string hubName, const oni_d
3030
setEnabled (false);
3131

3232
StreamInfo harpTimeStream = StreamInfo (
33-
OnixDevice::createStreamName ({ getHubName(), getName(), "HarpTime" }),
33+
createStreamName ("HarpTime", false),
3434
"Harp clock time corresponding to the local acquisition ONIX clock count",
3535
getStreamIdentifier(),
3636
1,

Source/Devices/MemoryMonitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ MemoryMonitor::MemoryMonitor (std::string name, std::string hubName, const oni_d
7878
: OnixDevice (name, hubName, MemoryMonitor::getDeviceType(), deviceIdx_, oni_ctx)
7979
{
8080
StreamInfo percentUsedStream = StreamInfo (
81-
OnixDevice::createStreamName ({ getHubName(), getName(), "PercentUsed" }),
81+
createStreamName ("PercentUsed", false),
8282
"Percent of available memory that is currently used",
8383
getStreamIdentifier(),
8484
1,

Source/Devices/Neuropixels1.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,37 @@ void Neuropixels1::defineMetadata (ProbeSettings<numberOfChannels, numberOfElect
302302

303303
uint64_t Neuropixels1::getProbeSerialNumber (int index)
304304
{
305-
return probeNumber;
305+
return probeMetadata.getProbeSerialNumber();
306+
}
307+
308+
std::string Neuropixels1::getProbePartNumber (int index)
309+
{
310+
return probeMetadata.getProbePartNumber();
311+
}
312+
313+
std::string Neuropixels1::getFlexPartNumber (int index)
314+
{
315+
return probeMetadata.getFlexPartNumber();
316+
}
317+
318+
std::string Neuropixels1::getFlexVersion (int index)
319+
{
320+
return probeMetadata.getFlexVersion();
306321
}
307322

308323
bool Neuropixels1::parseGainCalibrationFile()
309324
{
310325
if (gainCalibrationFilePath == "None" || gainCalibrationFilePath == "")
311326
{
312-
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing gain calibration file for probe " + std::to_string (probeNumber));
327+
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing gain calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
313328
return false;
314329
}
315330

316331
File gainFile = File (gainCalibrationFilePath);
317332

318333
if (! gainFile.existsAsFile())
319334
{
320-
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid gain calibration file for probe " + std::to_string (probeNumber));
335+
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid gain calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
321336
return false;
322337
}
323338

@@ -328,9 +343,9 @@ bool Neuropixels1::parseGainCalibrationFile()
328343

329344
LOGD ("Gain calibration file SN = ", gainSN);
330345

331-
if (gainSN != probeNumber)
346+
if (gainSN != probeMetadata.getProbeSerialNumber())
332347
{
333-
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "Gain calibration file serial number (" + std::to_string (gainSN) + ") does not match probe serial number (" + std::to_string (probeNumber) + ").");
348+
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "Gain calibration file serial number (" + std::to_string (gainSN) + ") does not match probe serial number (" + std::to_string (probeMetadata.getProbeSerialNumber()) + ").");
334349
return false;
335350
}
336351

@@ -366,15 +381,15 @@ bool Neuropixels1::parseAdcCalibrationFile()
366381
{
367382
if (adcCalibrationFilePath == "None" || adcCalibrationFilePath == "")
368383
{
369-
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing ADC calibration file for probe " + std::to_string (probeNumber));
384+
Onix1::showWarningMessageBoxAsync ("Missing File", "Missing ADC calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
370385
return false;
371386
}
372387

373388
File adcFile = File (adcCalibrationFilePath);
374389

375390
if (! adcFile.existsAsFile())
376391
{
377-
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid ADC calibration file for probe " + std::to_string (probeNumber));
392+
Onix1::showWarningMessageBoxAsync ("Invalid File", "Invalid ADC calibration file for probe " + std::to_string (probeMetadata.getProbeSerialNumber()));
378393
return false;
379394
}
380395

@@ -385,9 +400,9 @@ bool Neuropixels1::parseAdcCalibrationFile()
385400

386401
LOGD ("ADC calibration file SN = ", adcSN);
387402

388-
if (adcSN != probeNumber)
403+
if (adcSN != probeMetadata.getProbeSerialNumber())
389404
{
390-
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "ADC calibration serial number (" + std::to_string (adcSN) + ") does not match probe serial number (" + std::to_string (probeNumber) + ").");
405+
Onix1::showWarningMessageBoxAsync ("Serial Number Mismatch", "ADC calibration serial number (" + std::to_string (adcSN) + ") does not match probe serial number (" + std::to_string (probeMetadata.getProbeSerialNumber()) + ").");
391406
return false;
392407
}
393408

Source/Devices/Neuropixels1.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "../I2CRegisterContext.h"
2626
#include "../NeuropixelsComponents.h"
27-
#include "../OnixDevice.h"
27+
#include "NeuropixelsProbeMetadata.h"
2828

2929
namespace OnixSourcePlugin
3030
{
@@ -52,10 +52,13 @@ class Neuropixels1 : public INeuropixel<NeuropixelsV1Values::numberOfChannels, N
5252
/** Select a preset electrode configuration, based on the index of the given enum */
5353
std::vector<int> selectElectrodeConfiguration (int electrodeConfigurationIndex) override;
5454

55-
uint64_t getProbeSerialNumber (int index = 0) override;
56-
5755
void setSettings (ProbeSettings<numberOfChannels, numberOfElectrodes>* settings_, int index = 0) override;
5856

57+
uint64_t getProbeSerialNumber (int index = 0) override;
58+
std::string getProbePartNumber (int index = 0) override;
59+
std::string getFlexPartNumber (int index = 0) override;
60+
std::string getFlexVersion (int index = 0) override;
61+
5962
bool parseGainCalibrationFile();
6063
bool parseAdcCalibrationFile();
6164

@@ -73,7 +76,7 @@ class Neuropixels1 : public INeuropixel<NeuropixelsV1Values::numberOfChannels, N
7376

7477
const uint32_t ENABLE = 0x8000;
7578

76-
static constexpr int ProbeI2CAddress = 0x70;
79+
NeuropixelsProbeMetadata probeMetadata;
7780

7881
static constexpr int superFramesPerUltraFrame = 12;
7982
static constexpr int framesPerSuperFrame = 13;
@@ -84,6 +87,9 @@ class Neuropixels1 : public INeuropixel<NeuropixelsV1Values::numberOfChannels, N
8487
static constexpr uint16_t NumberOfAdcBins = 1024;
8588
static constexpr float DataMidpoint = NumberOfAdcBins / 2;
8689

90+
static constexpr int ProbeI2CAddress = 0x70;
91+
static constexpr int FlexEepromI2CAddress = 0x50;
92+
8793
static constexpr int secondsToSettle = 5;
8894
static constexpr int samplesToAverage = 100;
8995

Source/Devices/Neuropixels1e.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Neuropixels1e::Neuropixels1e (std::string name, std::string hubName, const oni_d
8080
{
8181
std::string port = getPortName (getDeviceIdx());
8282
StreamInfo apStream = StreamInfo (
83-
OnixDevice::createStreamName ({ port, getHubName(), getName(), STREAM_NAME_AP }),
83+
createStreamName (STREAM_NAME_AP),
8484
"Neuropixels 1.0 AP band data stream",
8585
getStreamIdentifier(),
8686
numberOfChannels,
@@ -94,7 +94,7 @@ Neuropixels1e::Neuropixels1e (std::string name, std::string hubName, const oni_d
9494
streamInfos.add (apStream);
9595

9696
StreamInfo lfpStream = StreamInfo (
97-
OnixDevice::createStreamName ({ port, getHubName(), getName(), STREAM_NAME_LFP }),
97+
createStreamName (STREAM_NAME_LFP),
9898
"Neuropixels 1.0 LFP band data stream",
9999
getStreamIdentifier(),
100100
numberOfChannels,
@@ -117,8 +117,6 @@ Neuropixels1e::Neuropixels1e (std::string name, std::string hubName, const oni_d
117117
apEventCodes[i] = 0;
118118
lfpEventCodes[i] = 0;
119119
}
120-
121-
probeNumber = 0;
122120
}
123121

124122
int Neuropixels1e::configureDevice()
@@ -132,25 +130,10 @@ int Neuropixels1e::configureDevice()
132130
if (rc != ONI_ESUCCESS)
133131
throw error_str ("Unable to set I2C rate for " + getName());
134132

135-
// Get Probe SN
136-
137-
int errorCode = 0;
138-
139-
for (int i = 0; i < 8; i++)
140-
{
141-
oni_reg_val_t reg_val;
142-
rc = flex->ReadByte (OFFSET_ID + i, &reg_val);
143-
144-
if (rc != ONI_ESUCCESS)
145-
throw error_str ("Unable to read the probe serial number for device at address " + getDeviceIdx());
146-
147-
if (reg_val <= 0xFF)
148-
{
149-
probeNumber |= (((uint64_t) reg_val) << (i * 8));
150-
}
151-
}
133+
// Get Probe Metadata
134+
probeMetadata = NeuropixelsProbeMetadata (flex.get(), OnixDeviceType::NEUROPIXELSV1E);
152135

153-
LOGD ("Probe SN: ", probeNumber);
136+
LOGD ("Probe SN: ", probeMetadata.getProbeSerialNumber());
154137

155138
return ONI_ESUCCESS;
156139
}

Source/Devices/Neuropixels1e.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,15 @@ class Neuropixels1e : public Neuropixels1
5353

5454
static constexpr int FlexEepromI2CAddress = 0x50;
5555

56-
static constexpr uint32_t OFFSET_ID = 0;
57-
static constexpr uint32_t OFFSET_VERSION = 10;
58-
static constexpr uint32_t OFFSET_REVISION = 11;
59-
static constexpr uint32_t OFFSET_FLEXPN = 20;
60-
static constexpr uint32_t OFFSET_PROBEPN = 40;
56+
std::unique_ptr<I2CRegisterContext> deserializer;
57+
std::unique_ptr<I2CRegisterContext> serializer;
58+
std::unique_ptr<I2CRegisterContext> flex;
6159

6260
static constexpr uint8_t DefaultGPO10Config = 0b00010001; // GPIO0 Low, NP in MUX reset
6361
static constexpr uint8_t DefaultGPO32Config = 0b10010001; // LED off, GPIO1 Low
6462
static constexpr uint32_t Gpo10ResetMask = 1 << 3; // Used to issue mux reset command to probe
6563
static constexpr uint32_t Gpo32LedMask = 1 << 7; // Used to turn on and off LED
6664

67-
std::unique_ptr<I2CRegisterContext> deserializer;
68-
std::unique_ptr<I2CRegisterContext> serializer;
69-
std::unique_ptr<I2CRegisterContext> flex;
70-
7165
void resetProbe();
7266
void writeShiftRegisters();
7367

Source/Devices/Neuropixels1f.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Neuropixels1f::Neuropixels1f (std::string name, std::string hubName, const oni_d
6868
{
6969
std::string port = getPortName (deviceIdx);
7070
StreamInfo apStream = StreamInfo (
71-
OnixDevice::createStreamName ({ port, getHubName(), getName(), STREAM_NAME_AP }),
71+
createStreamName (STREAM_NAME_AP),
7272
"Neuropixels 1.0 AP band data stream",
7373
getStreamIdentifier(),
7474
numberOfChannels,
@@ -82,7 +82,7 @@ Neuropixels1f::Neuropixels1f (std::string name, std::string hubName, const oni_d
8282
streamInfos.add (apStream);
8383

8484
StreamInfo lfpStream = StreamInfo (
85-
OnixDevice::createStreamName ({ port, getHubName(), getName(), STREAM_NAME_LFP }),
85+
createStreamName (STREAM_NAME_LFP),
8686
"Neuropixels 1.0 LFP band data stream",
8787
getStreamIdentifier(),
8888
numberOfChannels,
@@ -105,8 +105,6 @@ Neuropixels1f::Neuropixels1f (std::string name, std::string hubName, const oni_d
105105
apEventCodes[i] = 0;
106106
lfpEventCodes[i] = 0;
107107
}
108-
109-
probeNumber = 0;
110108
}
111109

112110
int Neuropixels1f::configureDevice()
@@ -123,32 +121,11 @@ int Neuropixels1f::configureDevice()
123121
return ONI_ESUCCESS;
124122
}
125123

126-
// Get Probe SN
127-
uint32_t eepromOffset = 0;
128-
uint32_t i2cAddr = 0x50;
129-
int errorCode = 0;
130-
131-
for (int i = 0; i < 8; i++)
132-
{
133-
oni_reg_addr_t reg_addr = ((eepromOffset + i) << 7) | i2cAddr;
134-
135-
oni_reg_val_t reg_val;
136-
rc = deviceContext->readRegister (deviceIdx, reg_addr, &reg_val);
137-
138-
if (rc != ONI_ESUCCESS)
139-
{
140-
LOGE (oni_error_str (rc));
141-
throw error_str ("Could not communicate with " + getName() + " on " + getHubName()
142-
+ ". Ensure that the flex connection is properly seated, or disable the device if it is not connected.");
143-
}
144-
145-
if (reg_val <= 0xFF)
146-
{
147-
probeNumber |= (((uint64_t) reg_val) << (i * 8));
148-
}
149-
}
124+
// Get Probe Metadata
125+
auto flex = std::make_unique<I2CRegisterContext> (FlexEepromI2CAddress, deviceIdx, deviceContext);
126+
probeMetadata = NeuropixelsProbeMetadata (flex.get(), OnixDeviceType::NEUROPIXELSV1F);
150127

151-
LOGD ("Probe SN: ", probeNumber);
128+
LOGD ("Probe SN: ", probeMetadata.getProbeSerialNumber());
152129

153130
// Enable device streaming
154131
rc = deviceContext->writeRegister (deviceIdx, 0x8000, 1);

0 commit comments

Comments
 (0)