Skip to content

Commit 2b04466

Browse files
aacuevasjonnew
authored andcommitted
Include attribute to create devices with equivalent data frames
1 parent 2327e9a commit 2b04466

File tree

5 files changed

+13
-43
lines changed

5 files changed

+13
-43
lines changed

OpenEphys.Onix1/ConfigurePersistentHeartbeat.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
7474
}
7575
}
7676

77+
[EquivalentDataSource(typeof(Heartbeat))]
7778
static class PersistentHeartbeat
7879
{
7980
public const int ID = 34;

OpenEphys.Onix1/ContextHelper.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Reflection;
34
using oni;
45

@@ -68,5 +69,14 @@ static void ThrowInvalidDeviceException(Type expectedType, uint address)
6869
{
6970
throw new InvalidOperationException($"Invalid device ID. The device found at address {address} is not a '{expectedType.Name}' device.");
7071
}
72+
73+
internal static bool CheckDeviceType(Type deviceType, Type targetType)
74+
{
75+
if (deviceType == targetType) return true;
76+
77+
var equivalentTypes = deviceType.GetCustomAttributes(typeof(EquivalentDataSource), false).Cast<EquivalentDataSource>();
78+
79+
return equivalentTypes.Any(t => t.BaseType == targetType);
80+
}
7181
}
7282
}

OpenEphys.Onix1/DeviceInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public DeviceInfo(ContextTask context, Type deviceType, uint deviceAddress)
2424

2525
public void AssertType(Type expectedType)
2626
{
27-
if (DeviceType != expectedType)
27+
if (!ContextHelper.CheckDeviceType(DeviceType, expectedType))
2828
{
2929
throw new InvalidOperationException(
3030
$"Expected device of type {expectedType.Name}. Actual type is {DeviceType.Name}."

OpenEphys.Onix1/DeviceNameConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ from element in SelectContextElements(level)
112112
let factory = ExpressionBuilder.GetWorkflowElement(element) as DeviceFactory
113113
where factory != null
114114
from device in factory.GetDevices()
115-
where device.DeviceType == targetType
115+
where ContextHelper.CheckDeviceType(device.DeviceType,targetType)
116116
select device.DeviceName)
117117
.Distinct()
118118
.ToList();

OpenEphys.Onix1/PersistentHeartbeatData.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)