Skip to content

Commit 0317c11

Browse files
authored
Merge pull request #93 from open-ephys-plugins/issue-76
Handle invalid headstage selections gracefully
2 parents 0842725 + 0d737ec commit 0317c11

14 files changed

+120
-245
lines changed

Source/Devices/Bno055.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Bno055::Bno055(std::string name, std::string hubName, const oni_dev_idx_t device
2929
{
3030
auto streamIdentifier = getStreamIdentifier();
3131

32-
std::string port = getPortNameFromIndex(deviceIdx);
32+
std::string port = getPortName(deviceIdx);
3333
StreamInfo eulerAngleStream = StreamInfo(
3434
OnixDevice::createStreamName({ port, getHubName(), getName(), "Euler" }),
3535
"Bosch Bno055 9-axis inertial measurement unit (IMU) Euler angle",

Source/Devices/Neuropixels1e.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void NeuropixelsV1eBackgroundUpdater::run()
7979
Neuropixels1e::Neuropixels1e(std::string name, std::string hubName, const oni_dev_idx_t deviceIdx_, std::shared_ptr<Onix1> ctx_) :
8080
Neuropixels1(name, hubName, OnixDeviceType::NEUROPIXELSV1E, deviceIdx_, ctx_)
8181
{
82-
std::string port = getPortNameFromIndex(getDeviceIdx());
82+
std::string port = getPortName(getDeviceIdx());
8383
StreamInfo apStream = StreamInfo(
8484
OnixDevice::createStreamName({ port, getHubName(), getName(), STREAM_NAME_AP }),
8585
"Neuropixels 1.0 AP band data stream",

Source/Devices/Neuropixels1f.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void NeuropixelsV1fBackgroundUpdater::run()
6666
Neuropixels1f::Neuropixels1f(std::string name, std::string hubName, const oni_dev_idx_t deviceIdx_, std::shared_ptr<Onix1> ctx_) :
6767
Neuropixels1(name, hubName, OnixDeviceType::NEUROPIXELSV1F, deviceIdx_, ctx_)
6868
{
69-
std::string port = getPortNameFromIndex(deviceIdx);
69+
std::string port = getPortName(deviceIdx);
7070
StreamInfo apStream = StreamInfo(
7171
OnixDevice::createStreamName({ port, getHubName(), getName(), STREAM_NAME_AP }),
7272
"Neuropixels 1.0 AP band data stream",

Source/Devices/Neuropixels2e.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Neuropixels2e::Neuropixels2e(std::string name, std::string hubName, const oni_de
4343
void Neuropixels2e::createDataStream(int n)
4444
{
4545
StreamInfo apStream = StreamInfo(
46-
OnixDevice::createStreamName({ getPortNameFromIndex(getDeviceIdx()), getHubName(), "Probe" + std::to_string(n) }),
46+
OnixDevice::createStreamName({ getPortName(getDeviceIdx()), getHubName(), "Probe" + std::to_string(n) }),
4747
"Neuropixels 2.0 data stream",
4848
getStreamIdentifier(),
4949
numberOfChannels,

Source/Devices/PolledBno055.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
3131
{
3232
auto streamIdentifier = getStreamIdentifier();
3333

34-
std::string port = getPortNameFromIndex(deviceIdx);
34+
std::string port = getPortName(deviceIdx);
3535
StreamInfo eulerAngleStream = StreamInfo(
3636
OnixDevice::createStreamName({ port, getHubName(), getName(), "Euler" }),
3737
"Bosch Bno055 9-axis inertial measurement unit (IMU) Euler angle",

Source/Onix1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ std::map<int, int> Onix1::getHubIds(device_map_t deviceTable) const
8787

8888
auto deviceIndices = getDeviceIndices(deviceTable);
8989

90-
auto offsets = OnixDevice::getUniqueOffsetsFromIndices(deviceIndices, false);
90+
auto offsets = OnixDevice::getUniqueOffsets(deviceIndices, false);
9191

9292
for (int i = 0; i < offsets.size(); i++)
9393
{
@@ -111,7 +111,7 @@ std::vector<int> Onix1::getDeviceIndices(device_map_t deviceMap, int hubIndex)
111111

112112
for (const auto& [idx, dev] : deviceMap)
113113
{
114-
if (dev.id != ONIX_NULL && (hubIndex == -1 || OnixDevice::getOffsetFromIndex(dev.idx) == hubIndex))
114+
if (dev.id != ONIX_NULL && (hubIndex == -1 || OnixDevice::getOffset(dev.idx) == hubIndex))
115115
deviceIndices.emplace_back(idx);
116116
}
117117

Source/OnixDevice.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,28 +173,28 @@ std::string OnixDevice::getPortName(PortName port)
173173
return getPortName(getPortOffset(port));
174174
}
175175

176-
std::string OnixDevice::getPortNameFromIndex(oni_dev_idx_t index)
176+
std::string OnixDevice::getPortName(oni_dev_idx_t index)
177177
{
178-
return getPortName(getOffsetFromIndex(index));
178+
return getPortName(getOffset(index));
179179
}
180180

181181
PortName OnixDevice::getPortFromIndex(oni_dev_idx_t index)
182182
{
183183
return index & (1 << 8) ? PortName::PortA : PortName::PortB;
184184
}
185185

186-
int OnixDevice::getOffsetFromIndex(oni_dev_idx_t index)
186+
int OnixDevice::getOffset(oni_dev_idx_t index)
187187
{
188188
return index & 0x0000FF00;
189189
}
190190

191-
std::vector<int> OnixDevice::getUniqueOffsetsFromIndices(std::vector<int> indices, bool ignoreBreakoutBoard)
191+
std::vector<int> OnixDevice::getUniqueOffsets(std::vector<int> indices, bool ignoreBreakoutBoard)
192192
{
193193
std::set<int> offsets;
194194

195195
for (auto index : indices)
196196
{
197-
auto offset = getOffsetFromIndex(index);
197+
auto offset = getOffset(index);
198198

199199
if (offset == HubAddressBreakoutBoard && ignoreBreakoutBoard) continue;
200200

@@ -204,7 +204,19 @@ std::vector<int> OnixDevice::getUniqueOffsetsFromIndices(std::vector<int> indice
204204
return std::vector<int>(offsets.begin(), offsets.end());
205205
}
206206

207-
Array<PortName> OnixDevice::getUniquePortsFromIndices(std::vector<int> indices)
207+
std::vector<int> OnixDevice::getUniqueOffsets(OnixDeviceMap devices, bool ignoreBreakoutBoard)
208+
{
209+
std::vector<int> indices;
210+
211+
for (const auto& [key, _] : devices)
212+
{
213+
indices.emplace_back(key);
214+
}
215+
216+
return getUniqueOffsets(indices, ignoreBreakoutBoard);
217+
}
218+
219+
Array<PortName> OnixDevice::getUniquePorts(std::vector<int> indices)
208220
{
209221
Array<PortName> ports;
210222

Source/OnixDevice.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ namespace OnixSourcePlugin
141141
std::vector<std::string> m_channelIdentifierSubTypes = { "subtypes" };
142142
};
143143

144+
using OnixDeviceMap = std::map<uint32_t, OnixDeviceType>;
145+
144146
/**
145147
146148
Streams data from an ONIX device
@@ -153,32 +155,21 @@ namespace OnixSourcePlugin
153155
/** Constructor */
154156
OnixDevice(std::string name_, std::string hubName, OnixDeviceType type_, const oni_dev_idx_t, std::shared_ptr<Onix1> oni_ctx, bool passthrough = false);
155157

156-
/** Destructor */
157-
~OnixDevice() { }
158-
159158
virtual void addFrame(oni_frame_t*) {};
160-
161159
virtual void processFrames() {};
162160

163161
const std::string getName() { return name; }
164-
165162
bool isEnabled() const { return enabled; }
166-
167163
void setEnabled(bool newState) { enabled = newState; }
164+
oni_dev_idx_t getDeviceIdx(bool getPassthroughIndex = false);
168165

169166
virtual int configureDevice() { return -1; };
170-
171167
virtual bool updateSettings() { return false; };
172-
173168
virtual void startAcquisition() {};
174-
175169
virtual void stopAcquisition() {};
176-
177170
/** Given the sourceBuffers from OnixSource, add all streams for the current device to the array */
178171
virtual void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) {};
179172

180-
oni_dev_idx_t getDeviceIdx(bool getPassthroughIndex = false);
181-
182173
/** Creates a stream name using the provided inputs, returning a string following the pattern: name[0]-name[1]-name[2]-etc., with all spaces removed */
183174
static std::string createStreamName(std::vector<std::string> names);
184175

@@ -196,11 +187,12 @@ namespace OnixSourcePlugin
196187
static int getPortOffset(PortName port);
197188
static std::string getPortName(int offset);
198189
static std::string getPortName(PortName port);
199-
static std::string getPortNameFromIndex(oni_dev_idx_t index);
190+
static std::string getPortName(oni_dev_idx_t index);
200191
static PortName getPortFromIndex(oni_dev_idx_t index);
201-
static int getOffsetFromIndex(oni_dev_idx_t index);
202-
static std::vector<int> getUniqueOffsetsFromIndices(std::vector<int> indices, bool ignoreBreakoutBoard = true);
203-
static Array<PortName> getUniquePortsFromIndices(std::vector<int> indices);
192+
static int getOffset(oni_dev_idx_t index);
193+
static std::vector<int> getUniqueOffsets(std::vector<int> indices, bool ignoreBreakoutBoard = true);
194+
static std::vector<int> getUniqueOffsets(OnixDeviceMap devices, bool ignoreBreakoutBoard = true);
195+
static Array<PortName> getUniquePorts(std::vector<int> indices);
204196

205197
OnixDeviceType getDeviceType() const;
206198

0 commit comments

Comments
 (0)