Skip to content

Commit 729597b

Browse files
committed
Address review comments
- Rmove "Breakout" prefix from class names (this information is included through the BreakoutBoard MultiDeviceFactory when used in that context) - Lots of typo fixes - Fixed the agruements to OutpuClockParameters such that floating point arthmetic is used so we dont loose precision
1 parent 1f4e21b commit 729597b

File tree

3 files changed

+44
-46
lines changed

3 files changed

+44
-46
lines changed

OpenEphys.Onix1/ConfigureBreakoutBoard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class ConfigureBreakoutBoard : MultiDeviceFactory
5252
[TypeConverter(typeof(SingleDeviceFactoryConverter))]
5353
[Description("Specifies the configuration for the clock output in the ONIX breakout board.")]
5454
[Category(DevicesCategory)]
55-
public ConfigureBreakoutOutputClock ClockOutput { get; set; } = new();
55+
public ConfigureOutputClock ClockOutput { get; set; } = new();
5656

5757
/// <summary>
5858
/// Gets or sets the hardware memory monitor configuration.

OpenEphys.Onix1/ConfigureBreakoutOutputClock.cs renamed to OpenEphys.Onix1/ConfigureOutputClock.cs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ namespace OpenEphys.Onix1
1111
/// Configures the ONIX breakout board's output clock.
1212
/// </summary>
1313
/// <remarks>
14-
/// The output clock provides physical, 3.3V logic level, 50 Ohm output impedance, frequency divided copy
14+
/// The output clock provides a 3.3V logic level, 50 Ohm output impedance, frequency divided copy
1515
/// of the <see cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see> that is used to generate
16-
/// <see cref="DataFrame.Clock"/> values for all data streams within an ONIX system. This clock runs a
16+
/// <see cref="DataFrame.Clock"/> values for all data streams within an ONIX system. This clock runs at a
1717
/// user defined rate, duty cycle, and start delay. It can be used to drive external hardware or can be
1818
/// logged by external recording systems for post-hoc synchronization with ONIX data.
1919
/// </remarks>
2020
[Description("Configures the ONIX breakout board's output clock.")]
21-
public class ConfigureBreakoutOutputClock : SingleDeviceFactory
21+
public class ConfigureOutputClock : SingleDeviceFactory
2222
{
2323
readonly BehaviorSubject<bool> gate = new(false);
2424
double frequencyHz = 1e6;
2525
double dutyCycle = 50;
2626

2727
/// <summary>
28-
/// Initializes a new instance of the <see cref="ConfigureBreakoutOutputClock"/> class.
28+
/// Initializes a new instance of the <see cref="ConfigureOutputClock"/> class.
2929
/// </summary>
30-
public ConfigureBreakoutOutputClock()
31-
: base(typeof(BreakoutOutputClock))
30+
public ConfigureOutputClock()
31+
: base(typeof(OutputClock))
3232
{
3333
DeviceAddress = 5;
3434
}
@@ -37,7 +37,7 @@ public ConfigureBreakoutOutputClock()
3737
/// Gets or sets a value specifying if the output clock is active.
3838
/// </summary>
3939
/// <remarks>
40-
/// If set to true, the clock output will connected to the clock output line. If set to false, the
40+
/// If set to true, the clock output will be connected to the clock output line. If set to false, the
4141
/// clock output line will be held low. This value can be toggled in real time to gate acquisition of
4242
/// external hardware.
4343
/// </remarks>
@@ -57,7 +57,7 @@ public bool ClockGate
5757
/// integer multiple of the <see cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see>
5858
/// frequency. Therefore, the true clock frequency will be set to a value that is as close as possible
5959
/// to the requested setting while respecting this constraint. The value as actualized in hardware is
60-
/// reported by <see cref="BreakoutOutputClockData"/>.
60+
/// reported by <see cref="OutputClockData"/>.
6161
/// </remarks>
6262
[Range(0.1, 10e6)]
6363
[Category(ConfigurationCategory)]
@@ -79,7 +79,7 @@ public double Frequency
7979
/// multiple of the <see cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see> frequency.
8080
/// Therefore, the true duty cycle will be set to a value that is as close as possible to the
8181
/// requested setting while respecting this constraint. The value as actualized in hardware is
82-
/// reported by <see cref="BreakoutOutputClockData"/>.
82+
/// reported by <see cref="OutputClockData"/>.
8383
/// </remarks>
8484
[Range(10, 90)]
8585
[Editor(DesignTypes.SliderEditor, typeof(UITypeEditor))]
@@ -103,14 +103,14 @@ public double DutyCycle
103103
/// <para>
104104
/// Valid values are between 0 and and 3600 seconds. Setting to a value greater than 0 can be useful
105105
/// for ensuring data sources that are driven by the output clock start significantly after ONIX has
106-
/// begun aquisition for the purposes of ordering acquisition start times.
106+
/// begun acquisition for the purposes of ordering acquisition start times.
107107
/// </para>
108108
/// <para>
109-
/// The delay must each be an integer multiple of the <see
109+
/// The delay must be an integer multiple of the <see
110110
/// cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see> frequency. Therefore, the true delay
111111
/// cycle will be set to a value that is as close as possible to the requested setting while
112112
/// respecting this constraint. The value as actualized in hardware is reported by <see
113-
/// cref="BreakoutOutputClockData"/>.
113+
/// cref="OutputClockData"/>.
114114
/// </para>
115115
/// </remarks>
116116
[Category(ConfigurationCategory)]
@@ -137,53 +137,52 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
137137
var deviceName = DeviceName;
138138
var deviceAddress = DeviceAddress;
139139

140-
// TODO: Dispose action that turns clock off
141140
return source.ConfigureDevice((context, observer) =>
142141
{
143142
var device = context.GetDeviceContext(deviceAddress, DeviceType);
144143

145-
var baseFreqHz = device.ReadRegister(BreakoutOutputClock.BASE_FREQ_HZ);
144+
var baseFreqHz = device.ReadRegister(OutputClock.BASE_FREQ_HZ);
146145
var periodTicks = (uint)(baseFreqHz / clkFreqHz);
147146
var h = (uint)(periodTicks * (dutyCycle / 100));
148147
var l = periodTicks - h;
149148
var delayTicks = (uint)(delaySeconds * baseFreqHz);
150-
device.WriteRegister(BreakoutOutputClock.HIGH_CYCLES, h);
151-
device.WriteRegister(BreakoutOutputClock.LOW_CYCLES, l);
152-
device.WriteRegister(BreakoutOutputClock.DELAY_CYCLES, delayTicks);
149+
device.WriteRegister(OutputClock.HIGH_CYCLES, h);
150+
device.WriteRegister(OutputClock.LOW_CYCLES, l);
151+
device.WriteRegister(OutputClock.DELAY_CYCLES, delayTicks);
153152

154-
var deviceInfo = new BreakoutOutputClockDeviceInfo(device, DeviceType,
155-
new(baseFreqHz / (h + l), 100 * h / periodTicks, delaySeconds, h + l, h, l, delayTicks));
153+
var deviceInfo = new OutputClockDeviceInfo(device, DeviceType,
154+
new((double)baseFreqHz / periodTicks, 100.0 * h / periodTicks, delaySeconds, h + l, h, l, delayTicks));
156155

157156
var shutdown = Disposable.Create(() =>
158157
{
159-
device.WriteRegister(BreakoutOutputClock.CLOCK_GATE, 0u);
158+
device.WriteRegister(OutputClock.CLOCK_GATE, 0u);
160159
});
161160

162161
return new CompositeDisposable(
163162
DeviceManager.RegisterDevice(deviceName, deviceInfo),
164-
gate.SubscribeSafe(observer, value => device.WriteRegister(BreakoutOutputClock.CLOCK_GATE, value ? 1u : 0u)),
163+
gate.SubscribeSafe(observer, value => device.WriteRegister(OutputClock.CLOCK_GATE, value ? 1u : 0u)),
165164
shutdown
166165
);
167166
});
168167
}
169168
}
170169

171-
static class BreakoutOutputClock
170+
static class OutputClock
172171
{
173172
public const int ID = 20;
174173

175174
public const uint NULL = 0; // No command
176-
public const uint CLOCK_GATE = 1; // Output enable. Bit 0 = 0 is disabled, Bit 0 = 1 is enabled.
175+
public const uint CLOCK_GATE = 1; // Output gate. Bit 0 = 0 is disabled, Bit 0 = 1 is enabled.
177176
public const uint HIGH_CYCLES = 2; // Number of input clock cycles output clock should be high. Valid values are 1 or greater.
178177
public const uint LOW_CYCLES = 3; // Number of input clock cycles output clock should be low. Valid values are 1 or greater.
179-
public const uint DELAY_CYCLES = 4; // Number of input clock cycles output clock should be low. Valid values are 1 or greater.
180-
public const uint GATE_RUN = 5; // Number of input clock cycles output clock should be low. Valid values are 1 or greater.
181-
public const uint BASE_FREQ_HZ = 6; // Number of input clock cycles output clock should be low. Valid values are 1 or greater.
178+
public const uint DELAY_CYCLES = 4; // Delay, in input clock cycles, following reset before clock becomes active.
179+
public const uint GATE_RUN = 5; // LSB sets the gate using run status. Bit 0 = 0: Clock runs whenever CLOCK_GATE(0) is 1. Bit 0 = 1: Clock runs only when acquisition is in RUNNING state.
180+
public const uint BASE_FREQ_HZ = 6; // Frequency of the input clock in Hz.
182181

183182
internal class NameConverter : DeviceNameConverter
184183
{
185184
public NameConverter()
186-
: base(typeof(BreakoutOutputClock))
185+
: base(typeof(OutputClock))
187186
{
188187
}
189188
}
@@ -199,26 +198,26 @@ public NameConverter()
199198
/// <param name="Delay">Gets the exact clock delay as actualized by the clock synthesizer in
200199
/// seconds.</param>
201200
/// <param name="PeriodTicks">Gets the exact clock period as actualized by the clock synthesizer in units
202-
/// of ticks of the of the <see cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see>.</param>
201+
/// of ticks of the <see cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see>.</param>
203202
/// <param name="HighTicks">Gets the exact clock high time per period as actualized by the clock
204-
/// synthesizer in units of ticks of the of the <see cref="ContextTask.AcquisitionClockHz">Acquisition
203+
/// synthesizer in units of ticks of the <see cref="ContextTask.AcquisitionClockHz">Acquisition
205204
/// Clock</see>.</param>
206205
/// <param name="LowTicks">Gets the exact clock low time per period as actualized by the clock synthesizer
207-
/// in units of ticks of the of the <see cref="ContextTask.AcquisitionClockHz">Acquisition
206+
/// in units of ticks of the <see cref="ContextTask.AcquisitionClockHz">Acquisition
208207
/// Clock</see>.</param>
209208
/// <param name="DelayTicks">Gets the exact clock delay as actualized by the clock synthesizer in units of
210-
/// ticks of the of the <see cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see>.</param>
211-
public readonly record struct BreakoutOutputClockParameters(double Frequency,
209+
/// ticks of the <see cref="ContextTask.AcquisitionClockHz">Acquisition Clock</see>.</param>
210+
public readonly record struct OutputClockParameters(double Frequency,
212211
double DutyCycle, double Delay, uint PeriodTicks, uint HighTicks, uint LowTicks, uint DelayTicks);
213212

214-
class BreakoutOutputClockDeviceInfo : DeviceInfo
213+
class OutputClockDeviceInfo : DeviceInfo
215214
{
216-
public BreakoutOutputClockDeviceInfo(DeviceContext device, Type deviceType, BreakoutOutputClockParameters parameters)
215+
public OutputClockDeviceInfo(DeviceContext device, Type deviceType, OutputClockParameters parameters)
217216
: base(device, deviceType)
218217
{
219218
Parameters = parameters;
220219
}
221220

222-
public BreakoutOutputClockParameters Parameters { get; }
221+
public OutputClockParameters Parameters { get; }
223222
}
224223
}

OpenEphys.Onix1/BreakoutOutputClockData.cs renamed to OpenEphys.Onix1/OutputClockData.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,32 @@
66

77
namespace OpenEphys.Onix1
88
{
9-
109
/// <summary>
11-
/// Produces a sequence with a single element containing the output clock's exact hardware parameters.
10+
/// Produces a sequence with a single element containing the output clock's exact hardware parameters for each subscription.
1211
/// </summary>
1312
/// <remarks>
1413
/// This data IO operator must be linked to an appropriate configuration, such as a <see
15-
/// cref="ConfigureBreakoutOutputClock"/>, using a shared <c>DeviceName</c>.
14+
/// cref="ConfigureOutputClock"/>, using a shared <c>DeviceName</c>.
1615
/// </remarks>
17-
[Description("Produces a sequence of analog input frames from an ONIX breakout board.")]
18-
public class BreakoutOutputClockData : Source<BreakoutOutputClockParameters>
16+
[Description("Produces a sequence with a single element containing the output clock's hardware parameters for each subscription.")]
17+
public class OutputClockData : Source<OutputClockParameters>
1918
{
2019
/// <inheritdoc cref = "SingleDeviceFactory.DeviceName"/>
21-
[TypeConverter(typeof(BreakoutOutputClock.NameConverter))]
20+
[TypeConverter(typeof(OutputClock.NameConverter))]
2221
[Description(SingleDeviceFactory.DeviceNameDescription)]
2322
[Category(DeviceFactory.ConfigurationCategory)]
2423
public string DeviceName { get; set; }
2524

2625
/// <summary>
27-
/// Generates a sequence containing a single <see cref="BreakoutOutputClockParameters"/>.
26+
/// Generates a sequence containing a single <see cref="OutputClockParameters"/> structure.
2827
/// </summary>
29-
/// <returns>A sequence containing a single <see cref="BreakoutOutputClockParameters"/></returns>
30-
public override IObservable<BreakoutOutputClockParameters> Generate()
28+
/// <returns>A sequence containing a single <see cref="OutputClockParameters"/></returns> structure.
29+
public override IObservable<OutputClockParameters> Generate()
3130
{
3231
return DeviceManager.GetDevice(DeviceName).SelectMany(
3332
deviceInfo =>
3433
{
35-
var clockOutDeviceInfo = (BreakoutOutputClockDeviceInfo)deviceInfo;
34+
var clockOutDeviceInfo = (OutputClockDeviceInfo)deviceInfo;
3635
return Observable.Defer(() => Observable.Return(clockOutDeviceInfo.Parameters));
3736
});
3837
}

0 commit comments

Comments
 (0)