Skip to content

Commit 241b191

Browse files
committed
Consolidate port name retrieval methods
1 parent 5907dee commit 241b191

File tree

9 files changed

+36
-24
lines changed

9 files changed

+36
-24
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
@@ -30,7 +30,7 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
3030
{
3131
auto streamIdentifier = getStreamIdentifier();
3232

33-
std::string port = getPortNameFromIndex(deviceIdx);
33+
std::string port = getPortName(deviceIdx);
3434
StreamInfo eulerAngleStream = StreamInfo(
3535
OnixDevice::createStreamName({ port, getHubName(), getName(), "Euler" }),
3636
"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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ namespace OnixSourcePlugin
168168
bool isEnabled() const { return enabled; }
169169

170170
void setEnabled(bool newState) { enabled = newState; }
171+
oni_dev_idx_t getDeviceIdx(bool getPassthroughIndex = false);
171172

172173
virtual int configureDevice() { return -1; };
173174

@@ -180,8 +181,6 @@ namespace OnixSourcePlugin
180181
/** Given the sourceBuffers from OnixSource, add all streams for the current device to the array */
181182
virtual void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) {};
182183

183-
oni_dev_idx_t getDeviceIdx(bool getPassthroughIndex = false);
184-
185184
/** 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 */
186185
static std::string createStreamName(std::vector<std::string> names);
187186

@@ -199,11 +198,12 @@ namespace OnixSourcePlugin
199198
static int getPortOffset(PortName port);
200199
static std::string getPortName(int offset);
201200
static std::string getPortName(PortName port);
202-
static std::string getPortNameFromIndex(oni_dev_idx_t index);
201+
static std::string getPortName(oni_dev_idx_t index);
203202
static PortName getPortFromIndex(oni_dev_idx_t index);
204-
static int getOffsetFromIndex(oni_dev_idx_t index);
205-
static std::vector<int> getUniqueOffsetsFromIndices(std::vector<int> indices, bool ignoreBreakoutBoard = true);
206-
static Array<PortName> getUniquePortsFromIndices(std::vector<int> indices);
203+
static int getOffset(oni_dev_idx_t index);
204+
static std::vector<int> getUniqueOffsets(std::vector<int> indices, bool ignoreBreakoutBoard = true);
205+
static std::vector<int> getUniqueOffsets(OnixDeviceMap devices, bool ignoreBreakoutBoard = true);
206+
static Array<PortName> getUniquePorts(std::vector<int> indices);
207207

208208
OnixDeviceType getDeviceType() const;
209209

Source/OnixSource.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ bool OnixSource::initializeDevices(device_map_t deviceTable, bool updateStreamIn
404404
polledBno->setBnoAxisMap(PolledBno055::Bno055AxisMap::YZX);
405405
polledBno->setBnoAxisSign((uint32_t)(PolledBno055::Bno055AxisSign::MirrorX) | (uint32_t)(PolledBno055::Bno055AxisSign::MirrorY));
406406

407-
hubNames.insert({ PortController::getOffsetFromIndex(polledBno->getDeviceIdx()), NEUROPIXELSV2E_HEADSTAGE_NAME });
407+
hubNames.insert({ PortController::getOffset(polledBno->getDeviceIdx()), NEUROPIXELSV2E_HEADSTAGE_NAME });
408408
}
409409
else if (hsid == 0xFFFFFFFF || hsid == ONIX_HUB_HSNP1ET || hsid == ONIX_HUB_HSNP1EH)
410410
{
@@ -437,7 +437,7 @@ bool OnixSource::initializeDevices(device_map_t deviceTable, bool updateStreamIn
437437
polledBno->setBnoAxisMap(PolledBno055::Bno055AxisMap::YZX);
438438
polledBno->setBnoAxisSign((uint32_t)(PolledBno055::Bno055AxisSign::MirrorX) | (uint32_t)(PolledBno055::Bno055AxisSign::MirrorZ));
439439

440-
hubNames.insert({ PortController::getOffsetFromIndex(polledBno->getDeviceIdx()), NEUROPIXELSV1E_HEADSTAGE_NAME });
440+
hubNames.insert({ PortController::getOffset(polledBno->getDeviceIdx()), NEUROPIXELSV1E_HEADSTAGE_NAME });
441441
}
442442
}
443443
}
@@ -555,11 +555,11 @@ OnixDeviceVector OnixSource::getEnabledDataSources()
555555
OnixDeviceVector OnixSource::getDataSourcesFromOffset(int offset)
556556
{
557557
OnixDeviceVector devices{};
558-
offset = PortController::getOffsetFromIndex(offset);
558+
offset = PortController::getOffset(offset);
559559

560560
for (const auto& source : sources)
561561
{
562-
if (PortController::getOffsetFromIndex(source->getDeviceIdx()) == offset)
562+
if (PortController::getOffset(source->getDeviceIdx()) == offset)
563563
devices.emplace_back(source);
564564
}
565565

@@ -770,7 +770,7 @@ void OnixSource::updateSettings(OwnedArray<ContinuousChannel>* continuousChannel
770770
deviceInfos->add(new DeviceInfo(deviceSettings));
771771

772772
DataStream::Settings dataStreamSettings{
773-
OnixDevice::createStreamName({OnixDevice::getPortNameFromIndex(source->getDeviceIdx()), source->getHubName(), source->getName()}),
773+
OnixDevice::createStreamName({OnixDevice::getPortName(source->getDeviceIdx()), source->getHubName(), source->getName()}),
774774
"Continuous data from a Bno055 9-axis IMU",
775775
source->getStreamIdentifier(),
776776
source->streamInfos[0].getSampleRate()

0 commit comments

Comments
 (0)