Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Devices/Bno055.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Bno055::Bno055(std::string name, std::string hubName, const oni_dev_idx_t device
{
auto streamIdentifier = getStreamIdentifier();

std::string port = getPortNameFromIndex(deviceIdx);
std::string port = getPortName(deviceIdx);
StreamInfo eulerAngleStream = StreamInfo(
OnixDevice::createStreamName({ port, getHubName(), getName(), "Euler" }),
"Bosch Bno055 9-axis inertial measurement unit (IMU) Euler angle",
Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/Neuropixels1e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void NeuropixelsV1eBackgroundUpdater::run()
Neuropixels1e::Neuropixels1e(std::string name, std::string hubName, const oni_dev_idx_t deviceIdx_, std::shared_ptr<Onix1> ctx_) :
Neuropixels1(name, hubName, OnixDeviceType::NEUROPIXELSV1E, deviceIdx_, ctx_)
{
std::string port = getPortNameFromIndex(getDeviceIdx());
std::string port = getPortName(getDeviceIdx());
StreamInfo apStream = StreamInfo(
OnixDevice::createStreamName({ port, getHubName(), getName(), STREAM_NAME_AP }),
"Neuropixels 1.0 AP band data stream",
Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/Neuropixels1f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void NeuropixelsV1fBackgroundUpdater::run()
Neuropixels1f::Neuropixels1f(std::string name, std::string hubName, const oni_dev_idx_t deviceIdx_, std::shared_ptr<Onix1> ctx_) :
Neuropixels1(name, hubName, OnixDeviceType::NEUROPIXELSV1F, deviceIdx_, ctx_)
{
std::string port = getPortNameFromIndex(deviceIdx);
std::string port = getPortName(deviceIdx);
StreamInfo apStream = StreamInfo(
OnixDevice::createStreamName({ port, getHubName(), getName(), STREAM_NAME_AP }),
"Neuropixels 1.0 AP band data stream",
Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/Neuropixels2e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Neuropixels2e::Neuropixels2e(std::string name, std::string hubName, const oni_de
void Neuropixels2e::createDataStream(int n)
{
StreamInfo apStream = StreamInfo(
OnixDevice::createStreamName({ getPortNameFromIndex(getDeviceIdx()), getHubName(), "Probe" + std::to_string(n) }),
OnixDevice::createStreamName({ getPortName(getDeviceIdx()), getHubName(), "Probe" + std::to_string(n) }),
"Neuropixels 2.0 data stream",
getStreamIdentifier(),
numberOfChannels,
Expand Down
2 changes: 1 addition & 1 deletion Source/Devices/PolledBno055.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PolledBno055::PolledBno055(std::string name, std::string hubName, const oni_dev_
{
auto streamIdentifier = getStreamIdentifier();

std::string port = getPortNameFromIndex(deviceIdx);
std::string port = getPortName(deviceIdx);
StreamInfo eulerAngleStream = StreamInfo(
OnixDevice::createStreamName({ port, getHubName(), getName(), "Euler" }),
"Bosch Bno055 9-axis inertial measurement unit (IMU) Euler angle",
Expand Down
4 changes: 2 additions & 2 deletions Source/Onix1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ std::map<int, int> Onix1::getHubIds(device_map_t deviceTable) const

auto deviceIndices = getDeviceIndices(deviceTable);

auto offsets = OnixDevice::getUniqueOffsetsFromIndices(deviceIndices, false);
auto offsets = OnixDevice::getUniqueOffsets(deviceIndices, false);

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

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

Expand Down
24 changes: 18 additions & 6 deletions Source/OnixDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,28 @@ std::string OnixDevice::getPortName(PortName port)
return getPortName(getPortOffset(port));
}

std::string OnixDevice::getPortNameFromIndex(oni_dev_idx_t index)
std::string OnixDevice::getPortName(oni_dev_idx_t index)
{
return getPortName(getOffsetFromIndex(index));
return getPortName(getOffset(index));
}

PortName OnixDevice::getPortFromIndex(oni_dev_idx_t index)
{
return index & (1 << 8) ? PortName::PortA : PortName::PortB;
}

int OnixDevice::getOffsetFromIndex(oni_dev_idx_t index)
int OnixDevice::getOffset(oni_dev_idx_t index)
{
return index & 0x0000FF00;
}

std::vector<int> OnixDevice::getUniqueOffsetsFromIndices(std::vector<int> indices, bool ignoreBreakoutBoard)
std::vector<int> OnixDevice::getUniqueOffsets(std::vector<int> indices, bool ignoreBreakoutBoard)
{
std::set<int> offsets;

for (auto index : indices)
{
auto offset = getOffsetFromIndex(index);
auto offset = getOffset(index);

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

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

Array<PortName> OnixDevice::getUniquePortsFromIndices(std::vector<int> indices)
std::vector<int> OnixDevice::getUniqueOffsets(OnixDeviceMap devices, bool ignoreBreakoutBoard)
{
std::vector<int> indices;

for (const auto& [key, _] : devices)
{
indices.emplace_back(key);
}

return getUniqueOffsets(indices, ignoreBreakoutBoard);
}

Array<PortName> OnixDevice::getUniquePorts(std::vector<int> indices)
{
Array<PortName> ports;

Expand Down
24 changes: 8 additions & 16 deletions Source/OnixDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ namespace OnixSourcePlugin
std::vector<std::string> m_channelIdentifierSubTypes = { "subtypes" };
};

using OnixDeviceMap = std::map<uint32_t, OnixDeviceType>;

/**

Streams data from an ONIX device
Expand All @@ -153,32 +155,21 @@ namespace OnixSourcePlugin
/** Constructor */
OnixDevice(std::string name_, std::string hubName, OnixDeviceType type_, const oni_dev_idx_t, std::shared_ptr<Onix1> oni_ctx, bool passthrough = false);

/** Destructor */
~OnixDevice() { }

virtual void addFrame(oni_frame_t*) {};

virtual void processFrames() {};

const std::string getName() { return name; }

bool isEnabled() const { return enabled; }

void setEnabled(bool newState) { enabled = newState; }
oni_dev_idx_t getDeviceIdx(bool getPassthroughIndex = false);

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

virtual bool updateSettings() { return false; };

virtual void startAcquisition() {};

virtual void stopAcquisition() {};

/** Given the sourceBuffers from OnixSource, add all streams for the current device to the array */
virtual void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) {};

oni_dev_idx_t getDeviceIdx(bool getPassthroughIndex = false);

/** 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 */
static std::string createStreamName(std::vector<std::string> names);

Expand All @@ -196,11 +187,12 @@ namespace OnixSourcePlugin
static int getPortOffset(PortName port);
static std::string getPortName(int offset);
static std::string getPortName(PortName port);
static std::string getPortNameFromIndex(oni_dev_idx_t index);
static std::string getPortName(oni_dev_idx_t index);
static PortName getPortFromIndex(oni_dev_idx_t index);
static int getOffsetFromIndex(oni_dev_idx_t index);
static std::vector<int> getUniqueOffsetsFromIndices(std::vector<int> indices, bool ignoreBreakoutBoard = true);
static Array<PortName> getUniquePortsFromIndices(std::vector<int> indices);
static int getOffset(oni_dev_idx_t index);
static std::vector<int> getUniqueOffsets(std::vector<int> indices, bool ignoreBreakoutBoard = true);
static std::vector<int> getUniqueOffsets(OnixDeviceMap devices, bool ignoreBreakoutBoard = true);
static Array<PortName> getUniquePorts(std::vector<int> indices);

OnixDeviceType getDeviceType() const;

Expand Down
Loading