Skip to content

Commit

Permalink
Merge pull request #362 from open-ephys/issue-351
Browse files Browse the repository at this point in the history
Simplify PortStatusFrame
  • Loading branch information
jonnew authored Nov 12, 2024
2 parents 61483a1 + 99120e6 commit 427c752
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
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;
}
}

0 comments on commit 427c752

Please sign in to comment.