Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify PortStatusFrame #362

Merged
merged 3 commits into from
Nov 12, 2024
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
38 changes: 26 additions & 12 deletions OpenEphys.Onix1/ConfigurePortController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
context.HubState = (PassthroughState)(((int)context.HubState & ~(1 << portShift)) | passthroughState);

// leave in standard mode when finished
return Disposable.Create(() => context.HubState = (PassthroughState)((int)context.HubState & ~(1 << portShift)));
return Disposable.Create(() => context.HubState = (PassthroughState)((int)context.HubState & ~(1 << portShift)));
})
.ConfigureLink(context =>
{
Expand All @@ -76,7 +76,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
}
return Disposable.Create(dispose);
})
.ConfigureDevice(context =>
.ConfigureDevice(context =>
{
var deviceInfo = new DeviceInfo(context, DeviceType, deviceAddress);
return DeviceManager.RegisterDevice(deviceName, deviceInfo);
Expand Down Expand Up @@ -117,36 +117,50 @@ internal enum HubConfiguration
/// Specifies the headstage port status codes.
/// </summary>
[Flags]
public enum PortStatusCode : byte
public enum PortStatusCode : ushort
{
/// <summary>
/// Specifies that the status code should be disregarded.
/// Specifies the SERDES forward channel lock status.
/// </summary>
Invalid = 0x0,
SerdesLock = 0x0001,

/// <summary>
/// Specifies a cyclic redundancy check failure.
/// Specifies the SERDES on-chip parity check status.
/// </summary>
CrcError = 0x1,
SerdesParityPass = 0x0002,

/// <summary>
/// Specifies a cyclic redundancy check failure during data transmission.
/// </summary>
CrcError = 0x0100,

/// <summary>
/// Specifies that too many devices were indicated in the hub device table.
/// </summary>
TooManyDevices = 0x2,
TooManyDevices = 0x0200,

/// <summary>
/// Specifies a hub initialization error.
/// </summary>
InitializationError = 0x4,
InitializationError = 0x0400,

/// <summary>
/// Specifies the receipt of a badly formatted data packet.
/// </summary>
BadPacketFormat = 0x8,
BadPacketFormat = 0x0800,

/// <summary>
/// Specifies the a cyclic redundancy check failure during hub initialization.
/// </summary>
InitializationCrcError = 0x1000,
}

/// <summary>
/// Specifies the physical port that a headstage is plugged into.
/// </summary>
/// <remarks>
/// ONIX uses a common protocol to communicate with a variety of devices using the same physical connection. For this reason
/// lots of different headstage types can be plugged into a headstage port.
/// ONIX uses a common protocol to communicate with a variety of devices using the same physical
/// connection. For this reason lots of different headstage types can be plugged into a headstage port.
/// </remarks>
public enum PortName
{
Expand Down
16 changes: 1 addition & 15 deletions OpenEphys.Onix1/PortStatusFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,19 @@ public unsafe PortStatusFrame(oni.Frame frame)
{
var payload = (PortStatusPayload*)frame.Data.ToPointer();
HubClock = payload->HubClock;
var statusCodeValid = (payload->SerdesStatus & 0x0004) == 4;
StatusCode = statusCodeValid ? payload->Code : PortStatusCode.Invalid;
SerdesLocked = (payload->SerdesStatus & 0x0001) == 1;
SerdesPass = (payload->SerdesStatus & 0x0002) == 2;
StatusCode = payload->Code;
}

/// <summary>
/// Gets the port status code.
/// </summary>
public PortStatusCode StatusCode { get; }

/// <summary>
/// Gets the SERDES forward channel lock status.
/// </summary>
public bool SerdesLocked { get; }

/// <summary>
/// Gets the SERDES on-chip parity check status.
/// </summary>
public bool SerdesPass { get; }
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct PortStatusPayload
{
public ulong HubClock;
public PortStatusCode Code;
public byte SerdesStatus;
}
}