com.shinolab.autd3-sdk 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Client.cs +6 -6
- package/Commands.cs +28 -22
- package/Datagram.cs +31 -13
- package/Legacy.cs +348 -0
- package/Legacy.cs.meta +11 -0
- package/Link.cs +6 -0
- package/Native.cs +79 -7
- package/Plugins/linux-x64/libautd3capi.so +0 -0
- package/Plugins/osx-arm64/libautd3capi.dylib +0 -0
- package/Plugins/win-x64/autd3capi.dll +0 -0
- package/README.md +1 -35
- package/THIRD-PARTY-LICENSES.md +7 -6
- package/package.json +4 -4
package/Client.cs
CHANGED
|
@@ -224,9 +224,12 @@ namespace AUTD3
|
|
|
224
224
|
|
|
225
225
|
internal IntPtr Handle { get; private set; }
|
|
226
226
|
|
|
227
|
-
private
|
|
227
|
+
private readonly Geometry _geometry;
|
|
228
|
+
|
|
229
|
+
private Client(IntPtr handle, Geometry geometry)
|
|
228
230
|
{
|
|
229
231
|
Handle = handle;
|
|
232
|
+
_geometry = geometry;
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
public static async Task<Client> OpenAsync(Geometry geometry, ILink link, ClientConfig config)
|
|
@@ -246,7 +249,7 @@ namespace AUTD3
|
|
|
246
249
|
NativeClient.autd3_client_config_free(configHandle);
|
|
247
250
|
}
|
|
248
251
|
var value = await task.ConfigureAwait(false);
|
|
249
|
-
return new Client(value);
|
|
252
|
+
return new Client(value, geometry);
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
public static async Task<(Client Client, Checker Checker)> OpenWithCheckerAsync(Geometry geometry, ILink link, ClientConfig config)
|
|
@@ -264,7 +267,7 @@ namespace AUTD3
|
|
|
264
267
|
public int NumDevices => (int)NativeClient.autd3_client_num_devices(Handle);
|
|
265
268
|
|
|
266
269
|
|
|
267
|
-
public DatagramBuilder DatagramBuilder() => new DatagramBuilder(
|
|
270
|
+
public DatagramBuilder DatagramBuilder() => new DatagramBuilder(_geometry, Handle);
|
|
268
271
|
|
|
269
272
|
|
|
270
273
|
|
|
@@ -317,9 +320,6 @@ namespace AUTD3
|
|
|
317
320
|
public Task<byte[]> ReadTelemetryAsync(Telemetry counter) =>
|
|
318
321
|
ReadByteArrayAsync((cb, ud) => NativeClient.autd3_client_read_telemetry(Handle, (byte)counter, cb, ud));
|
|
319
322
|
|
|
320
|
-
public Task<byte[]> ReadFpgaFunctionsAsync() =>
|
|
321
|
-
ReadByteArrayAsync((cb, ud) => NativeClient.autd3_client_read_fpga_functions(Handle, cb, ud));
|
|
322
|
-
|
|
323
323
|
internal static async Task<byte[]> ReadByteArrayAsync(Action<CompletionCallback, IntPtr> invoke)
|
|
324
324
|
{
|
|
325
325
|
var array = await AsyncOps.InvokeAsync(invoke).ConfigureAwait(false);
|
package/Commands.cs
CHANGED
|
@@ -42,10 +42,10 @@ namespace AUTD3
|
|
|
42
42
|
internal static extern IntPtr autd3_op_emulate_gpio_in(byte[] values);
|
|
43
43
|
|
|
44
44
|
[DllImport(Lib)]
|
|
45
|
-
internal static extern IntPtr autd3_op_set_output_mask(byte[] masks, UIntPtr numDevices);
|
|
45
|
+
internal static extern IntPtr autd3_op_set_output_mask(byte[] masks, UIntPtr[] lens, UIntPtr numDevices);
|
|
46
46
|
|
|
47
47
|
[DllImport(Lib)]
|
|
48
|
-
internal static extern IntPtr autd3_op_set_phase_correction(byte[] phases, UIntPtr numDevices);
|
|
48
|
+
internal static extern IntPtr autd3_op_set_phase_correction(byte[] phases, UIntPtr[] lens, UIntPtr numDevices);
|
|
49
49
|
|
|
50
50
|
[DllImport(Lib)]
|
|
51
51
|
internal static extern IntPtr autd3_op_set_pulse_width_table(ushort[] table);
|
|
@@ -239,8 +239,6 @@ namespace AUTD3
|
|
|
239
239
|
|
|
240
240
|
public sealed class SetOutputMask : ICommand
|
|
241
241
|
{
|
|
242
|
-
private const int NumTransducers = 249;
|
|
243
|
-
|
|
244
242
|
private readonly bool[][] _masks;
|
|
245
243
|
|
|
246
244
|
public SetOutputMask(bool[][] masks)
|
|
@@ -250,19 +248,24 @@ namespace AUTD3
|
|
|
250
248
|
|
|
251
249
|
IntPtr ICommand.CreateOp()
|
|
252
250
|
{
|
|
253
|
-
var
|
|
251
|
+
var lens = new UIntPtr[_masks.Length];
|
|
252
|
+
var total = 0;
|
|
254
253
|
for (var d = 0; d < _masks.Length; d++)
|
|
255
254
|
{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
255
|
+
lens[d] = (UIntPtr)_masks[d].Length;
|
|
256
|
+
total += _masks[d].Length;
|
|
257
|
+
}
|
|
258
|
+
var flat = new byte[total];
|
|
259
|
+
var offset = 0;
|
|
260
|
+
for (var d = 0; d < _masks.Length; d++)
|
|
261
|
+
{
|
|
262
|
+
for (var t = 0; t < _masks[d].Length; t++)
|
|
261
263
|
{
|
|
262
|
-
flat[
|
|
264
|
+
flat[offset + t] = (byte)(_masks[d][t] ? 1 : 0);
|
|
263
265
|
}
|
|
266
|
+
offset += _masks[d].Length;
|
|
264
267
|
}
|
|
265
|
-
return NativeCommand.autd3_op_set_output_mask(flat, (UIntPtr)_masks.Length);
|
|
268
|
+
return NativeCommand.autd3_op_set_output_mask(flat, lens, (UIntPtr)_masks.Length);
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
|
|
@@ -339,8 +342,6 @@ namespace AUTD3
|
|
|
339
342
|
|
|
340
343
|
public sealed class SetPhaseCorrection : ICommand
|
|
341
344
|
{
|
|
342
|
-
private const int NumTransducers = 249;
|
|
343
|
-
|
|
344
345
|
private readonly Phase[][] _phases;
|
|
345
346
|
|
|
346
347
|
public SetPhaseCorrection(Phase[][] phases)
|
|
@@ -350,19 +351,24 @@ namespace AUTD3
|
|
|
350
351
|
|
|
351
352
|
IntPtr ICommand.CreateOp()
|
|
352
353
|
{
|
|
353
|
-
var
|
|
354
|
+
var lens = new UIntPtr[_phases.Length];
|
|
355
|
+
var total = 0;
|
|
354
356
|
for (var d = 0; d < _phases.Length; d++)
|
|
355
357
|
{
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
358
|
+
lens[d] = (UIntPtr)_phases[d].Length;
|
|
359
|
+
total += _phases[d].Length;
|
|
360
|
+
}
|
|
361
|
+
var flat = new byte[total];
|
|
362
|
+
var offset = 0;
|
|
363
|
+
for (var d = 0; d < _phases.Length; d++)
|
|
364
|
+
{
|
|
365
|
+
for (var t = 0; t < _phases[d].Length; t++)
|
|
361
366
|
{
|
|
362
|
-
flat[
|
|
367
|
+
flat[offset + t] = _phases[d][t].Value;
|
|
363
368
|
}
|
|
369
|
+
offset += _phases[d].Length;
|
|
364
370
|
}
|
|
365
|
-
return NativeCommand.autd3_op_set_phase_correction(flat, (UIntPtr)_phases.Length);
|
|
371
|
+
return NativeCommand.autd3_op_set_phase_correction(flat, lens, (UIntPtr)_phases.Length);
|
|
366
372
|
}
|
|
367
373
|
}
|
|
368
374
|
}
|
package/Datagram.cs
CHANGED
|
@@ -11,13 +11,17 @@ namespace AUTD3
|
|
|
11
11
|
public bool LowLatency { get; }
|
|
12
12
|
public uint TimeoutCycles { get; }
|
|
13
13
|
public uint MaxInflight { get; }
|
|
14
|
-
public uint SendIntervalCycles { get; }
|
|
15
14
|
public uint MaxResyncRounds { get; }
|
|
16
15
|
public uint ResetResendCycles { get; }
|
|
17
16
|
public byte? RtPriority { get; }
|
|
17
|
+
public bool DisableRtPriority { get; }
|
|
18
18
|
public ulong? RtAffinity { get; }
|
|
19
19
|
public bool ValidateState { get; }
|
|
20
20
|
|
|
21
|
+
private const byte RtPriorityModeDefault = 0;
|
|
22
|
+
private const byte RtPriorityModeDisabled = 1;
|
|
23
|
+
private const byte RtPriorityModeExplicit = 2;
|
|
24
|
+
|
|
21
25
|
public ClientConfig() : this(lowLatency: false)
|
|
22
26
|
{
|
|
23
27
|
}
|
|
@@ -26,20 +30,24 @@ namespace AUTD3
|
|
|
26
30
|
bool lowLatency = false,
|
|
27
31
|
uint timeoutCycles = 10,
|
|
28
32
|
uint maxInflight = 127,
|
|
29
|
-
uint sendIntervalCycles = 1,
|
|
30
33
|
uint maxResyncRounds = 8,
|
|
31
34
|
uint resetResendCycles = 2,
|
|
32
35
|
byte? rtPriority = null,
|
|
36
|
+
bool disableRtPriority = false,
|
|
33
37
|
ulong? rtAffinity = null,
|
|
34
38
|
bool validateState = true)
|
|
35
39
|
{
|
|
40
|
+
if (rtPriority.HasValue && disableRtPriority)
|
|
41
|
+
{
|
|
42
|
+
throw new ArgumentException("rtPriority and disableRtPriority are mutually exclusive");
|
|
43
|
+
}
|
|
36
44
|
LowLatency = lowLatency;
|
|
37
45
|
TimeoutCycles = timeoutCycles;
|
|
38
46
|
MaxInflight = maxInflight;
|
|
39
|
-
SendIntervalCycles = sendIntervalCycles;
|
|
40
47
|
MaxResyncRounds = maxResyncRounds;
|
|
41
48
|
ResetResendCycles = resetResendCycles;
|
|
42
49
|
RtPriority = rtPriority;
|
|
50
|
+
DisableRtPriority = disableRtPriority;
|
|
43
51
|
RtAffinity = rtAffinity;
|
|
44
52
|
ValidateState = validateState;
|
|
45
53
|
}
|
|
@@ -50,10 +58,13 @@ namespace AUTD3
|
|
|
50
58
|
LowLatency,
|
|
51
59
|
TimeoutCycles,
|
|
52
60
|
(UIntPtr)MaxInflight,
|
|
53
|
-
SendIntervalCycles,
|
|
54
61
|
MaxResyncRounds,
|
|
55
62
|
ResetResendCycles,
|
|
56
|
-
RtPriority.HasValue
|
|
63
|
+
RtPriority.HasValue
|
|
64
|
+
? RtPriorityModeExplicit
|
|
65
|
+
: DisableRtPriority
|
|
66
|
+
? RtPriorityModeDisabled
|
|
67
|
+
: RtPriorityModeDefault,
|
|
57
68
|
RtPriority ?? 0,
|
|
58
69
|
RtAffinity.HasValue,
|
|
59
70
|
(UIntPtr)(RtAffinity ?? 0),
|
|
@@ -68,19 +79,26 @@ namespace AUTD3
|
|
|
68
79
|
|
|
69
80
|
public sealed class DatagramBuilder : IDisposable
|
|
70
81
|
{
|
|
82
|
+
private readonly Geometry _geometry;
|
|
71
83
|
private readonly int _numDevices;
|
|
84
|
+
private readonly IntPtr _client;
|
|
72
85
|
|
|
73
86
|
internal IntPtr Handle { get; private set; }
|
|
74
87
|
|
|
75
|
-
|
|
88
|
+
public DatagramBuilder(Geometry geometry) : this(geometry, IntPtr.Zero)
|
|
76
89
|
{
|
|
77
|
-
_numDevices = numDevices;
|
|
78
|
-
Handle = NativeClient.autd3_datagram_builder_new((UIntPtr)numDevices);
|
|
79
90
|
}
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
public DatagramBuilder(Geometry geometry) : this(geometry.NumDevices)
|
|
92
|
+
internal DatagramBuilder(Geometry geometry, IntPtr client)
|
|
83
93
|
{
|
|
94
|
+
_geometry = geometry;
|
|
95
|
+
_numDevices = geometry.NumDevices;
|
|
96
|
+
_client = client;
|
|
97
|
+
Handle = NativeClient.autd3_datagram_builder_new(geometry.Handle);
|
|
98
|
+
if (Handle == IntPtr.Zero)
|
|
99
|
+
{
|
|
100
|
+
throw new Autd3Exception("failed to create datagram builder");
|
|
101
|
+
}
|
|
84
102
|
}
|
|
85
103
|
|
|
86
104
|
public DatagramBuilder Push(ICommand command)
|
|
@@ -90,14 +108,14 @@ namespace AUTD3
|
|
|
90
108
|
return this;
|
|
91
109
|
}
|
|
92
110
|
|
|
93
|
-
public DatagramBuilder PushEach(Func<
|
|
111
|
+
public DatagramBuilder PushEach(Func<Device, ICommand?> factory)
|
|
94
112
|
{
|
|
95
113
|
var ops = new IntPtr[_numDevices];
|
|
96
114
|
try
|
|
97
115
|
{
|
|
98
116
|
for (var i = 0; i < _numDevices; i++)
|
|
99
117
|
{
|
|
100
|
-
var command = factory(i);
|
|
118
|
+
var command = factory(_geometry[i]);
|
|
101
119
|
ops[i] = command == null ? IntPtr.Zero : command.CreateOp();
|
|
102
120
|
}
|
|
103
121
|
}
|
|
@@ -119,7 +137,7 @@ namespace AUTD3
|
|
|
119
137
|
public Frames Build()
|
|
120
138
|
{
|
|
121
139
|
var err = new byte[256];
|
|
122
|
-
var handle = NativeClient.autd3_datagram_builder_build(Handle, err, (UIntPtr)err.Length);
|
|
140
|
+
var handle = NativeClient.autd3_datagram_builder_build(Handle, _client, err, (UIntPtr)err.Length);
|
|
123
141
|
if (handle == IntPtr.Zero)
|
|
124
142
|
{
|
|
125
143
|
throw new Autd3Exception(NativeUtil.Utf8(err));
|
package/Legacy.cs
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.Threading.Tasks;
|
|
5
|
+
|
|
6
|
+
namespace AUTD3.Legacy
|
|
7
|
+
{
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
public readonly struct LegacyClientConfig
|
|
11
|
+
{
|
|
12
|
+
public uint TimeoutCycles { get; }
|
|
13
|
+
public byte? RtPriority { get; }
|
|
14
|
+
public ulong? RtAffinity { get; }
|
|
15
|
+
|
|
16
|
+
public LegacyClientConfig() : this(timeoutCycles: 2000)
|
|
17
|
+
{
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public LegacyClientConfig(
|
|
21
|
+
uint timeoutCycles = 2000,
|
|
22
|
+
byte? rtPriority = null,
|
|
23
|
+
ulong? rtAffinity = null)
|
|
24
|
+
{
|
|
25
|
+
TimeoutCycles = timeoutCycles;
|
|
26
|
+
RtPriority = rtPriority;
|
|
27
|
+
RtAffinity = rtAffinity;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
internal IntPtr CreateHandle()
|
|
31
|
+
{
|
|
32
|
+
var handle = NativeLegacyClient.autd3_legacy_client_config_new(
|
|
33
|
+
TimeoutCycles,
|
|
34
|
+
RtPriority.HasValue,
|
|
35
|
+
RtPriority ?? 0,
|
|
36
|
+
RtAffinity.HasValue,
|
|
37
|
+
(UIntPtr)(RtAffinity ?? 0));
|
|
38
|
+
if (handle == IntPtr.Zero)
|
|
39
|
+
{
|
|
40
|
+
throw new Autd3Exception("failed to create legacy client config");
|
|
41
|
+
}
|
|
42
|
+
return handle;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public interface ILegacyCommand
|
|
47
|
+
{
|
|
48
|
+
internal IntPtr CreateOp();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public sealed class LegacyChangePatternBank : ILegacyCommand
|
|
52
|
+
{
|
|
53
|
+
private readonly byte _kind;
|
|
54
|
+
private readonly PatternBank _bank;
|
|
55
|
+
private readonly TransitionMode _transitionMode;
|
|
56
|
+
|
|
57
|
+
private LegacyChangePatternBank(byte kind, PatternBank bank, TransitionMode transitionMode)
|
|
58
|
+
{
|
|
59
|
+
_kind = kind;
|
|
60
|
+
_bank = bank;
|
|
61
|
+
_transitionMode = transitionMode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static LegacyChangePatternBank Pattern(PatternBank bank) =>
|
|
65
|
+
new LegacyChangePatternBank(0, bank, TransitionMode.Immediate);
|
|
66
|
+
|
|
67
|
+
public static LegacyChangePatternBank FociStm(PatternBank bank, TransitionMode? transitionMode = null) =>
|
|
68
|
+
new LegacyChangePatternBank(1, bank, transitionMode ?? TransitionMode.Immediate);
|
|
69
|
+
|
|
70
|
+
public static LegacyChangePatternBank PatternStm(PatternBank bank, TransitionMode? transitionMode = null) =>
|
|
71
|
+
new LegacyChangePatternBank(2, bank, transitionMode ?? TransitionMode.Immediate);
|
|
72
|
+
|
|
73
|
+
IntPtr ILegacyCommand.CreateOp() =>
|
|
74
|
+
NativeLegacyClient.autd3_legacy_op_change_segment(_kind, (byte)_bank, _transitionMode.Mode, _transitionMode.Value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public sealed class LegacyDatagramBuilder : IDisposable
|
|
78
|
+
{
|
|
79
|
+
private readonly Geometry _geometry;
|
|
80
|
+
private readonly int _numDevices;
|
|
81
|
+
private readonly IntPtr _client;
|
|
82
|
+
|
|
83
|
+
internal IntPtr Handle { get; private set; }
|
|
84
|
+
|
|
85
|
+
public LegacyDatagramBuilder(Geometry geometry) : this(geometry, IntPtr.Zero)
|
|
86
|
+
{
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
internal LegacyDatagramBuilder(Geometry geometry, IntPtr client)
|
|
90
|
+
{
|
|
91
|
+
_geometry = geometry;
|
|
92
|
+
_numDevices = geometry.NumDevices;
|
|
93
|
+
_client = client;
|
|
94
|
+
Handle = NativeLegacyClient.autd3_legacy_datagram_builder_new(geometry.Handle);
|
|
95
|
+
if (Handle == IntPtr.Zero)
|
|
96
|
+
{
|
|
97
|
+
throw new Autd3Exception("failed to create legacy datagram builder");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public LegacyDatagramBuilder Push(ICommand command)
|
|
102
|
+
{
|
|
103
|
+
var op = command.CreateOp();
|
|
104
|
+
NativeLegacyClient.autd3_legacy_datagram_builder_push(Handle, op);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public LegacyDatagramBuilder Push(ILegacyCommand command)
|
|
109
|
+
{
|
|
110
|
+
var op = command.CreateOp();
|
|
111
|
+
NativeLegacyClient.autd3_legacy_datagram_builder_push_legacy(Handle, op);
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public LegacyDatagramBuilder PushEach(Func<Device, ICommand?> factory)
|
|
116
|
+
{
|
|
117
|
+
var ops = new IntPtr[_numDevices];
|
|
118
|
+
try
|
|
119
|
+
{
|
|
120
|
+
for (var i = 0; i < _numDevices; i++)
|
|
121
|
+
{
|
|
122
|
+
var command = factory(_geometry[i]);
|
|
123
|
+
ops[i] = command == null ? IntPtr.Zero : command.CreateOp();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch
|
|
127
|
+
{
|
|
128
|
+
foreach (var op in ops)
|
|
129
|
+
{
|
|
130
|
+
if (op != IntPtr.Zero)
|
|
131
|
+
{
|
|
132
|
+
NativeClient.autd3_op_free(op);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
throw;
|
|
136
|
+
}
|
|
137
|
+
NativeLegacyClient.autd3_legacy_datagram_builder_push_each(Handle, ops, (UIntPtr)_numDevices);
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public LegacyFrames Build()
|
|
142
|
+
{
|
|
143
|
+
var err = new byte[256];
|
|
144
|
+
var handle = NativeLegacyClient.autd3_legacy_datagram_builder_build(Handle, _client, err, (UIntPtr)err.Length);
|
|
145
|
+
if (handle == IntPtr.Zero)
|
|
146
|
+
{
|
|
147
|
+
throw new Autd3Exception(NativeUtil.Utf8(err));
|
|
148
|
+
}
|
|
149
|
+
return new LegacyFrames(handle);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public void Dispose()
|
|
153
|
+
{
|
|
154
|
+
if (Handle != IntPtr.Zero)
|
|
155
|
+
{
|
|
156
|
+
NativeLegacyClient.autd3_legacy_datagram_builder_free(Handle);
|
|
157
|
+
Handle = IntPtr.Zero;
|
|
158
|
+
}
|
|
159
|
+
GC.SuppressFinalize(this);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
~LegacyDatagramBuilder()
|
|
163
|
+
{
|
|
164
|
+
if (Handle != IntPtr.Zero)
|
|
165
|
+
{
|
|
166
|
+
NativeLegacyClient.autd3_legacy_datagram_builder_free(Handle);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public readonly struct LegacyFrame
|
|
172
|
+
{
|
|
173
|
+
internal LegacyFrames Frames { get; }
|
|
174
|
+
internal long Index { get; }
|
|
175
|
+
|
|
176
|
+
internal LegacyFrame(LegacyFrames frames, long index)
|
|
177
|
+
{
|
|
178
|
+
Frames = frames;
|
|
179
|
+
Index = index;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public sealed class LegacyFrames : IDisposable, IEnumerable<LegacyFrame>
|
|
184
|
+
{
|
|
185
|
+
internal IntPtr Handle { get; private set; }
|
|
186
|
+
|
|
187
|
+
internal LegacyFrames(IntPtr handle)
|
|
188
|
+
{
|
|
189
|
+
Handle = handle;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public int Length => (int)NativeLegacyClient.autd3_legacy_frames_num_frames(Handle);
|
|
193
|
+
|
|
194
|
+
public LegacyFrame this[int index]
|
|
195
|
+
{
|
|
196
|
+
get
|
|
197
|
+
{
|
|
198
|
+
if (index < 0 || index >= Length)
|
|
199
|
+
{
|
|
200
|
+
throw new ArgumentOutOfRangeException(nameof(index));
|
|
201
|
+
}
|
|
202
|
+
return new LegacyFrame(this, index);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public IEnumerator<LegacyFrame> GetEnumerator()
|
|
207
|
+
{
|
|
208
|
+
var count = Length;
|
|
209
|
+
for (long i = 0; i < count; i++)
|
|
210
|
+
{
|
|
211
|
+
yield return new LegacyFrame(this, i);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
216
|
+
|
|
217
|
+
public void Dispose()
|
|
218
|
+
{
|
|
219
|
+
if (Handle != IntPtr.Zero)
|
|
220
|
+
{
|
|
221
|
+
NativeLegacyClient.autd3_legacy_frames_free(Handle);
|
|
222
|
+
Handle = IntPtr.Zero;
|
|
223
|
+
}
|
|
224
|
+
GC.SuppressFinalize(this);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
~LegacyFrames()
|
|
228
|
+
{
|
|
229
|
+
if (Handle != IntPtr.Zero)
|
|
230
|
+
{
|
|
231
|
+
NativeLegacyClient.autd3_legacy_frames_free(Handle);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public sealed class LegacyClient : IDisposable
|
|
237
|
+
{
|
|
238
|
+
internal IntPtr Handle { get; private set; }
|
|
239
|
+
|
|
240
|
+
private readonly Geometry _geometry;
|
|
241
|
+
|
|
242
|
+
private LegacyClient(IntPtr handle, Geometry geometry)
|
|
243
|
+
{
|
|
244
|
+
Handle = handle;
|
|
245
|
+
_geometry = geometry;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public static async Task<LegacyClient> OpenAsync(Geometry geometry, ILegacyLink link, LegacyClientConfig config)
|
|
249
|
+
{
|
|
250
|
+
var opener = link.TakeLegacyOpener();
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
var configHandle = config.CreateHandle();
|
|
254
|
+
Task<IntPtr> task;
|
|
255
|
+
try
|
|
256
|
+
{
|
|
257
|
+
task = AsyncOps.InvokeAsync((cb, ud) =>
|
|
258
|
+
NativeLegacyClient.autd3_legacy_client_open(geometry.Handle, opener, configHandle, cb, ud));
|
|
259
|
+
}
|
|
260
|
+
finally
|
|
261
|
+
{
|
|
262
|
+
NativeLegacyClient.autd3_legacy_client_config_free(configHandle);
|
|
263
|
+
}
|
|
264
|
+
var value = await task.ConfigureAwait(false);
|
|
265
|
+
return new LegacyClient(value, geometry);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public static async Task<(LegacyClient Client, Checker Checker)> OpenWithCheckerAsync(Geometry geometry, ILegacyLink link, LegacyClientConfig config)
|
|
269
|
+
{
|
|
270
|
+
var client = await OpenAsync(geometry, link, config).ConfigureAwait(false);
|
|
271
|
+
var checker = NativeLegacyClient.autd3_legacy_client_checker(client.Handle);
|
|
272
|
+
if (checker == IntPtr.Zero)
|
|
273
|
+
{
|
|
274
|
+
client.Dispose();
|
|
275
|
+
throw new Autd3Exception("failed to create checker");
|
|
276
|
+
}
|
|
277
|
+
return (client, new Checker(checker));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public int NumDevices => (int)NativeLegacyClient.autd3_legacy_client_num_devices(Handle);
|
|
281
|
+
|
|
282
|
+
public LegacyDatagramBuilder DatagramBuilder() => new LegacyDatagramBuilder(_geometry, Handle);
|
|
283
|
+
|
|
284
|
+
public Task SendCheckedAsync(LegacyFrame frame) =>
|
|
285
|
+
AsyncOps.InvokeAsync((cb, ud) =>
|
|
286
|
+
NativeLegacyClient.autd3_legacy_client_send_checked(Handle, frame.Frames.Handle, frame.Index, cb, ud));
|
|
287
|
+
|
|
288
|
+
public Task<byte[]> SendAsync(LegacyFrame frame) =>
|
|
289
|
+
Client.ReadByteArrayAsync((cb, ud) =>
|
|
290
|
+
NativeLegacyClient.autd3_legacy_client_send(Handle, frame.Frames.Handle, frame.Index, cb, ud));
|
|
291
|
+
|
|
292
|
+
public async Task<IReadOnlyList<string>> ReadFirmwareVersionAsync()
|
|
293
|
+
{
|
|
294
|
+
var array = await AsyncOps.InvokeAsync((cb, ud) =>
|
|
295
|
+
NativeLegacyClient.autd3_legacy_client_read_firmware_version(Handle, cb, ud)).ConfigureAwait(false);
|
|
296
|
+
try
|
|
297
|
+
{
|
|
298
|
+
var count = (int)NativeClient.autd3_string_array_len(array);
|
|
299
|
+
var versions = new List<string>(count);
|
|
300
|
+
for (var i = 0; i < count; i++)
|
|
301
|
+
{
|
|
302
|
+
versions.Add(NativeUtil.PtrToString(NativeClient.autd3_string_array_get(array, (UIntPtr)i)));
|
|
303
|
+
}
|
|
304
|
+
return versions;
|
|
305
|
+
}
|
|
306
|
+
finally
|
|
307
|
+
{
|
|
308
|
+
NativeClient.autd3_string_array_free(array);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public async Task<IReadOnlyList<FpgaState>> ReadFpgaStateAsync()
|
|
313
|
+
{
|
|
314
|
+
var bytes = await Client.ReadByteArrayAsync((cb, ud) =>
|
|
315
|
+
NativeLegacyClient.autd3_legacy_client_read_fpga_state(Handle, cb, ud)).ConfigureAwait(false);
|
|
316
|
+
var states = new FpgaState[bytes.Length];
|
|
317
|
+
for (var i = 0; i < bytes.Length; i++)
|
|
318
|
+
{
|
|
319
|
+
states[i] = new FpgaState(bytes[i]);
|
|
320
|
+
}
|
|
321
|
+
return states;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public Task StopAsync() =>
|
|
325
|
+
AsyncOps.InvokeAsync((cb, ud) => NativeLegacyClient.autd3_legacy_client_stop(Handle, cb, ud));
|
|
326
|
+
|
|
327
|
+
public Task CloseAsync() =>
|
|
328
|
+
AsyncOps.InvokeAsync((cb, ud) => NativeLegacyClient.autd3_legacy_client_close(Handle, cb, ud));
|
|
329
|
+
|
|
330
|
+
public void Dispose()
|
|
331
|
+
{
|
|
332
|
+
if (Handle != IntPtr.Zero)
|
|
333
|
+
{
|
|
334
|
+
NativeLegacyClient.autd3_legacy_client_free(Handle);
|
|
335
|
+
Handle = IntPtr.Zero;
|
|
336
|
+
}
|
|
337
|
+
GC.SuppressFinalize(this);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
~LegacyClient()
|
|
341
|
+
{
|
|
342
|
+
if (Handle != IntPtr.Zero)
|
|
343
|
+
{
|
|
344
|
+
NativeLegacyClient.autd3_legacy_client_free(Handle);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
package/Legacy.cs.meta
ADDED
package/Link.cs
CHANGED
package/Native.cs
CHANGED
|
@@ -17,10 +17,9 @@ namespace AUTD3
|
|
|
17
17
|
[MarshalAs(UnmanagedType.I1)] bool lowLatency,
|
|
18
18
|
uint timeoutCycles,
|
|
19
19
|
UIntPtr maxInflight,
|
|
20
|
-
uint sendIntervalCycles,
|
|
21
20
|
uint maxResyncRounds,
|
|
22
21
|
uint resetResendCycles,
|
|
23
|
-
|
|
22
|
+
byte rtPriorityMode,
|
|
24
23
|
byte rtPriority,
|
|
25
24
|
[MarshalAs(UnmanagedType.I1)] bool hasRtAffinity,
|
|
26
25
|
UIntPtr rtAffinity,
|
|
@@ -30,7 +29,7 @@ namespace AUTD3
|
|
|
30
29
|
internal static extern void autd3_client_config_free(IntPtr config);
|
|
31
30
|
|
|
32
31
|
[DllImport(Lib)]
|
|
33
|
-
internal static extern IntPtr autd3_datagram_builder_new(
|
|
32
|
+
internal static extern IntPtr autd3_datagram_builder_new(IntPtr geometry);
|
|
34
33
|
|
|
35
34
|
[DllImport(Lib)]
|
|
36
35
|
internal static extern void autd3_datagram_builder_push(IntPtr builder, IntPtr op);
|
|
@@ -45,7 +44,7 @@ namespace AUTD3
|
|
|
45
44
|
internal static extern void autd3_datagram_builder_free(IntPtr builder);
|
|
46
45
|
|
|
47
46
|
[DllImport(Lib)]
|
|
48
|
-
internal static extern IntPtr autd3_datagram_builder_build(IntPtr builder, byte[] outErr, UIntPtr outErrLen);
|
|
47
|
+
internal static extern IntPtr autd3_datagram_builder_build(IntPtr builder, IntPtr client, byte[] outErr, UIntPtr outErrLen);
|
|
49
48
|
|
|
50
49
|
[DllImport(Lib)]
|
|
51
50
|
internal static extern UIntPtr autd3_datagrams_num_frames(IntPtr datagrams);
|
|
@@ -96,9 +95,6 @@ namespace AUTD3
|
|
|
96
95
|
[DllImport(Lib)]
|
|
97
96
|
internal static extern void autd3_client_read_telemetry(IntPtr client, byte counter, CompletionCallback cb, IntPtr userData);
|
|
98
97
|
|
|
99
|
-
[DllImport(Lib)]
|
|
100
|
-
internal static extern void autd3_client_read_fpga_functions(IntPtr client, CompletionCallback cb, IntPtr userData);
|
|
101
|
-
|
|
102
98
|
[DllImport(Lib)]
|
|
103
99
|
internal static extern UIntPtr autd3_byte_array_len(IntPtr array);
|
|
104
100
|
|
|
@@ -139,4 +135,80 @@ namespace AUTD3
|
|
|
139
135
|
[DllImport(Lib)]
|
|
140
136
|
internal static extern void autd3_link_status_free(IntPtr status);
|
|
141
137
|
}
|
|
138
|
+
|
|
139
|
+
internal static class NativeLegacyClient
|
|
140
|
+
{
|
|
141
|
+
private const string Lib = "autd3capi";
|
|
142
|
+
|
|
143
|
+
[DllImport(Lib)]
|
|
144
|
+
internal static extern IntPtr autd3_legacy_client_config_new(
|
|
145
|
+
uint timeoutCycles,
|
|
146
|
+
[MarshalAs(UnmanagedType.I1)] bool hasRtPriority,
|
|
147
|
+
byte rtPriority,
|
|
148
|
+
[MarshalAs(UnmanagedType.I1)] bool hasRtAffinity,
|
|
149
|
+
UIntPtr rtAffinity);
|
|
150
|
+
|
|
151
|
+
[DllImport(Lib)]
|
|
152
|
+
internal static extern void autd3_legacy_client_config_free(IntPtr config);
|
|
153
|
+
|
|
154
|
+
[DllImport(Lib)]
|
|
155
|
+
internal static extern IntPtr autd3_legacy_datagram_builder_new(IntPtr geometry);
|
|
156
|
+
|
|
157
|
+
[DllImport(Lib)]
|
|
158
|
+
internal static extern void autd3_legacy_datagram_builder_push(IntPtr builder, IntPtr op);
|
|
159
|
+
|
|
160
|
+
[DllImport(Lib)]
|
|
161
|
+
internal static extern IntPtr autd3_legacy_op_change_segment(byte kind, byte bank, byte transitionMode, ulong transitionValue);
|
|
162
|
+
|
|
163
|
+
[DllImport(Lib)]
|
|
164
|
+
internal static extern void autd3_legacy_op_free(IntPtr op);
|
|
165
|
+
|
|
166
|
+
[DllImport(Lib)]
|
|
167
|
+
internal static extern void autd3_legacy_datagram_builder_push_legacy(IntPtr builder, IntPtr op);
|
|
168
|
+
|
|
169
|
+
[DllImport(Lib)]
|
|
170
|
+
internal static extern void autd3_legacy_datagram_builder_push_each(IntPtr builder, IntPtr[] ops, UIntPtr numDevices);
|
|
171
|
+
|
|
172
|
+
[DllImport(Lib)]
|
|
173
|
+
internal static extern void autd3_legacy_datagram_builder_free(IntPtr builder);
|
|
174
|
+
|
|
175
|
+
[DllImport(Lib)]
|
|
176
|
+
internal static extern IntPtr autd3_legacy_datagram_builder_build(IntPtr builder, IntPtr client, byte[] outErr, UIntPtr outErrLen);
|
|
177
|
+
|
|
178
|
+
[DllImport(Lib)]
|
|
179
|
+
internal static extern UIntPtr autd3_legacy_frames_num_frames(IntPtr frames);
|
|
180
|
+
|
|
181
|
+
[DllImport(Lib)]
|
|
182
|
+
internal static extern void autd3_legacy_frames_free(IntPtr frames);
|
|
183
|
+
|
|
184
|
+
[DllImport(Lib)]
|
|
185
|
+
internal static extern void autd3_legacy_client_open(IntPtr geometry, IntPtr link, IntPtr config, CompletionCallback cb, IntPtr userData);
|
|
186
|
+
|
|
187
|
+
[DllImport(Lib)]
|
|
188
|
+
internal static extern UIntPtr autd3_legacy_client_num_devices(IntPtr client);
|
|
189
|
+
|
|
190
|
+
[DllImport(Lib)]
|
|
191
|
+
internal static extern void autd3_legacy_client_send(IntPtr client, IntPtr frames, long frame, CompletionCallback cb, IntPtr userData);
|
|
192
|
+
|
|
193
|
+
[DllImport(Lib)]
|
|
194
|
+
internal static extern void autd3_legacy_client_send_checked(IntPtr client, IntPtr frames, long frame, CompletionCallback cb, IntPtr userData);
|
|
195
|
+
|
|
196
|
+
[DllImport(Lib)]
|
|
197
|
+
internal static extern void autd3_legacy_client_read_firmware_version(IntPtr client, CompletionCallback cb, IntPtr userData);
|
|
198
|
+
|
|
199
|
+
[DllImport(Lib)]
|
|
200
|
+
internal static extern void autd3_legacy_client_read_fpga_state(IntPtr client, CompletionCallback cb, IntPtr userData);
|
|
201
|
+
|
|
202
|
+
[DllImport(Lib)]
|
|
203
|
+
internal static extern IntPtr autd3_legacy_client_checker(IntPtr client);
|
|
204
|
+
|
|
205
|
+
[DllImport(Lib)]
|
|
206
|
+
internal static extern void autd3_legacy_client_stop(IntPtr client, CompletionCallback cb, IntPtr userData);
|
|
207
|
+
|
|
208
|
+
[DllImport(Lib)]
|
|
209
|
+
internal static extern void autd3_legacy_client_close(IntPtr client, CompletionCallback cb, IntPtr userData);
|
|
210
|
+
|
|
211
|
+
[DllImport(Lib)]
|
|
212
|
+
internal static extern void autd3_legacy_client_free(IntPtr client);
|
|
213
|
+
}
|
|
142
214
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/README.md
CHANGED
|
@@ -2,41 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The AUTD3 client: opening a link, sending datagrams and driving STM.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Add the scoped registry and the package to `Packages/manifest.json`; sibling
|
|
8
|
-
AUTD3 packages are resolved from the registry automatically.
|
|
9
|
-
|
|
10
|
-
```json
|
|
11
|
-
{
|
|
12
|
-
"scopedRegistries": [
|
|
13
|
-
{ "name": "npmjs", "url": "https://registry.npmjs.org", "scopes": ["com.shinolab"] }
|
|
14
|
-
],
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"com.shinolab.autd3-sdk": "0.1.0"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Packages served from `registry.npmjs.org` do **not** appear in the Package Manager's
|
|
22
|
-
*My Registries* tab, because npmjs does not implement the legacy `/-/all` route that
|
|
23
|
-
Unity's package listing relies on. Resolution is unaffected: edit the manifest as above,
|
|
24
|
-
or use **+ → Add package by name**.
|
|
25
|
-
|
|
26
|
-
The bundled `Focus Sine` sample additionally needs `com.shinolab.autd3-sdk.link.nop`.
|
|
27
|
-
|
|
28
|
-
## Platforms
|
|
29
|
-
|
|
30
|
-
Editor and Standalone builds on Windows (`win-x64`), Linux (`linux-x64`) and Apple
|
|
31
|
-
Silicon macOS (`osx-arm64`). Intel macOS is not shipped.
|
|
32
|
-
|
|
33
|
-
## Notes
|
|
34
|
-
|
|
35
|
-
Minimum Unity version is 6 (6000.x). The API speaks Unity's left-handed, metre frame;
|
|
36
|
-
conversion to the AUTD3 canonical frame happens at the binding boundary.
|
|
37
|
-
|
|
38
|
-
See the [Unity binding README](https://github.com/shinolab/autd3-sdk/blob/main/bindings/unity/README.md) for the
|
|
39
|
-
coordinate system, the full package list and local development with `file:` references.
|
|
5
|
+
See the [Unity binding README](https://github.com/shinolab/autd3-sdk/blob/main/bindings/unity/README.md) for more details.
|
|
40
6
|
|
|
41
7
|
## License
|
|
42
8
|
|
package/THIRD-PARTY-LICENSES.md
CHANGED
|
@@ -5,7 +5,7 @@ The following is a list of those components and the full text of their licenses.
|
|
|
5
5
|
|
|
6
6
|
## Overview
|
|
7
7
|
|
|
8
|
-
- MIT License (
|
|
8
|
+
- MIT License (53)
|
|
9
9
|
- Apache License 2.0 (3)
|
|
10
10
|
- Unicode License v3 (1)
|
|
11
11
|
|
|
@@ -886,10 +886,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
886
886
|
|
|
887
887
|
Used by:
|
|
888
888
|
|
|
889
|
-
- autd3-ffi 0.
|
|
890
|
-
- autd3-ffi-abi 0.
|
|
891
|
-
- autd3-rs 0.
|
|
892
|
-
- autd3-rs-core 0.
|
|
889
|
+
- autd3-ffi 0.5.0 — https://github.com/shinolab/autd3-sdk
|
|
890
|
+
- autd3-ffi-abi 0.5.0 — https://github.com/shinolab/autd3-sdk
|
|
891
|
+
- autd3-rs 0.5.0 — https://github.com/shinolab/autd3-sdk
|
|
892
|
+
- autd3-rs-core 0.5.0 — https://github.com/shinolab/autd3-sdk
|
|
893
|
+
- autd3-cpu-wire 0.4.0 — https://github.com/shinolab/autd3-sdk
|
|
893
894
|
- chrono 0.4.45 — https://github.com/chronotope/chrono
|
|
894
895
|
- wide 1.5.0 — https://github.com/Lokathor/wide
|
|
895
896
|
- winapi-i686-pc-windows-gnu 0.4.0 — https://github.com/retep998/winapi-rs
|
|
@@ -933,7 +934,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
933
934
|
|
|
934
935
|
Used by:
|
|
935
936
|
|
|
936
|
-
- tokio 1.
|
|
937
|
+
- tokio 1.53.0 — https://github.com/tokio-rs/tokio
|
|
937
938
|
|
|
938
939
|
```
|
|
939
940
|
MIT License
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "git+https://github.com/shinolab/autd3-sdk.git",
|
|
6
6
|
"directory": "bindings/unity/com.shinolab.autd3-sdk"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.5.0",
|
|
9
9
|
"displayName": "AUTD3",
|
|
10
10
|
"description": "AUTD3 client, datagrams and STM (Unity binding).",
|
|
11
11
|
"unity": "6000.0",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"url": "https://github.com/shinolab"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"com.shinolab.autd3-sdk.core": "0.
|
|
19
|
-
"com.shinolab.autd3-sdk.pattern": "0.
|
|
20
|
-
"com.shinolab.autd3-sdk.modulation": "0.
|
|
18
|
+
"com.shinolab.autd3-sdk.core": "0.5.0",
|
|
19
|
+
"com.shinolab.autd3-sdk.pattern": "0.5.0",
|
|
20
|
+
"com.shinolab.autd3-sdk.modulation": "0.5.0"
|
|
21
21
|
},
|
|
22
22
|
"samples": [
|
|
23
23
|
{
|