com.shinolab.autd3-sdk 0.5.0 → 0.6.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 +35 -21
- package/Commands.cs +5 -0
- package/Datagram.cs +85 -37
- package/Legacy.cs +77 -32
- package/Native.cs +60 -22
- 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/Stm.cs +5 -0
- package/THIRD-PARTY-LICENSES.md +35 -5
- package/package.json +4 -4
package/Client.cs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Threading;
|
|
2
3
|
using System.Collections.Generic;
|
|
3
4
|
using System.Runtime.CompilerServices;
|
|
4
5
|
using System.Runtime.InteropServices;
|
|
@@ -136,19 +137,20 @@ namespace AUTD3
|
|
|
136
137
|
|
|
137
138
|
public void Dispose()
|
|
138
139
|
{
|
|
139
|
-
|
|
140
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
141
|
+
if (handle != IntPtr.Zero)
|
|
140
142
|
{
|
|
141
|
-
NativeClient.autd3_checker_free(
|
|
142
|
-
_handle = IntPtr.Zero;
|
|
143
|
+
NativeClient.autd3_checker_free(handle);
|
|
143
144
|
}
|
|
144
145
|
GC.SuppressFinalize(this);
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
~Checker()
|
|
148
149
|
{
|
|
149
|
-
|
|
150
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
151
|
+
if (handle != IntPtr.Zero)
|
|
150
152
|
{
|
|
151
|
-
NativeClient.autd3_checker_free(
|
|
153
|
+
NativeClient.autd3_checker_free(handle);
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
}
|
|
@@ -166,7 +168,7 @@ namespace AUTD3
|
|
|
166
168
|
|
|
167
169
|
public void Check()
|
|
168
170
|
{
|
|
169
|
-
var err = new byte[
|
|
171
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
170
172
|
if (!NativeClient.autd3_response_check(_data, (UIntPtr)_data.Length, err, (UIntPtr)err.Length))
|
|
171
173
|
{
|
|
172
174
|
throw new Autd3Exception(NativeUtil.Utf8(err));
|
|
@@ -185,8 +187,7 @@ namespace AUTD3
|
|
|
185
187
|
|
|
186
188
|
public async Task<Response> AwaitAsync()
|
|
187
189
|
{
|
|
188
|
-
var handle = _handle;
|
|
189
|
-
_handle = IntPtr.Zero;
|
|
190
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
190
191
|
if (handle == IntPtr.Zero)
|
|
191
192
|
{
|
|
192
193
|
throw new Autd3Exception("ResponseToken has already been awaited");
|
|
@@ -201,19 +202,20 @@ namespace AUTD3
|
|
|
201
202
|
|
|
202
203
|
public void Dispose()
|
|
203
204
|
{
|
|
204
|
-
|
|
205
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
206
|
+
if (handle != IntPtr.Zero)
|
|
205
207
|
{
|
|
206
|
-
NativeClient.autd3_response_token_free(
|
|
207
|
-
_handle = IntPtr.Zero;
|
|
208
|
+
NativeClient.autd3_response_token_free(handle);
|
|
208
209
|
}
|
|
209
210
|
GC.SuppressFinalize(this);
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
~ResponseToken()
|
|
213
214
|
{
|
|
214
|
-
|
|
215
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
216
|
+
if (handle != IntPtr.Zero)
|
|
215
217
|
{
|
|
216
|
-
NativeClient.autd3_response_token_free(
|
|
218
|
+
NativeClient.autd3_response_token_free(handle);
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
}
|
|
@@ -222,13 +224,15 @@ namespace AUTD3
|
|
|
222
224
|
{
|
|
223
225
|
public const int MaxInflight = 127;
|
|
224
226
|
|
|
225
|
-
|
|
227
|
+
private IntPtr _handle;
|
|
228
|
+
|
|
229
|
+
internal IntPtr Handle => _handle;
|
|
226
230
|
|
|
227
231
|
private readonly Geometry _geometry;
|
|
228
232
|
|
|
229
233
|
private Client(IntPtr handle, Geometry geometry)
|
|
230
234
|
{
|
|
231
|
-
|
|
235
|
+
_handle = handle;
|
|
232
236
|
_geometry = geometry;
|
|
233
237
|
}
|
|
234
238
|
|
|
@@ -236,8 +240,17 @@ namespace AUTD3
|
|
|
236
240
|
{
|
|
237
241
|
var opener = link.TakeOpener();
|
|
238
242
|
|
|
243
|
+
IntPtr configHandle;
|
|
244
|
+
try
|
|
245
|
+
{
|
|
246
|
+
configHandle = config.CreateHandle();
|
|
247
|
+
}
|
|
248
|
+
catch
|
|
249
|
+
{
|
|
250
|
+
NativeClient.autd3_client_opener_free(opener);
|
|
251
|
+
throw;
|
|
252
|
+
}
|
|
239
253
|
|
|
240
|
-
var configHandle = config.CreateHandle();
|
|
241
254
|
Task<IntPtr> task;
|
|
242
255
|
try
|
|
243
256
|
{
|
|
@@ -347,19 +360,20 @@ namespace AUTD3
|
|
|
347
360
|
|
|
348
361
|
public void Dispose()
|
|
349
362
|
{
|
|
350
|
-
|
|
363
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
364
|
+
if (handle != IntPtr.Zero)
|
|
351
365
|
{
|
|
352
|
-
NativeClient.autd3_client_free(
|
|
353
|
-
Handle = IntPtr.Zero;
|
|
366
|
+
NativeClient.autd3_client_free(handle);
|
|
354
367
|
}
|
|
355
368
|
GC.SuppressFinalize(this);
|
|
356
369
|
}
|
|
357
370
|
|
|
358
371
|
~Client()
|
|
359
372
|
{
|
|
360
|
-
|
|
373
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
374
|
+
if (handle != IntPtr.Zero)
|
|
361
375
|
{
|
|
362
|
-
NativeClient.autd3_client_free(
|
|
376
|
+
NativeClient.autd3_client_free(handle);
|
|
363
377
|
}
|
|
364
378
|
}
|
|
365
379
|
}
|
package/Commands.cs
CHANGED
|
@@ -14,6 +14,11 @@ namespace AUTD3
|
|
|
14
14
|
{
|
|
15
15
|
private const string Lib = "autd3capi";
|
|
16
16
|
|
|
17
|
+
static NativeCommand() => NativeAbi.Verify(Lib, autd3_abi_version());
|
|
18
|
+
|
|
19
|
+
[DllImport(Lib)]
|
|
20
|
+
private static extern uint autd3_abi_version();
|
|
21
|
+
|
|
17
22
|
[DllImport(Lib)]
|
|
18
23
|
internal static extern IntPtr autd3_op_clear();
|
|
19
24
|
|
package/Datagram.cs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Threading;
|
|
2
3
|
using System.Collections;
|
|
3
4
|
using System.Collections.Generic;
|
|
4
5
|
|
|
@@ -6,6 +7,13 @@ namespace AUTD3
|
|
|
6
7
|
{
|
|
7
8
|
|
|
8
9
|
|
|
10
|
+
public enum RtSchedulePolicy : byte
|
|
11
|
+
{
|
|
12
|
+
Normal = 0,
|
|
13
|
+
Fifo = 1,
|
|
14
|
+
RoundRobin = 2,
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
public readonly struct ClientConfig
|
|
10
18
|
{
|
|
11
19
|
public bool LowLatency { get; }
|
|
@@ -15,12 +23,10 @@ namespace AUTD3
|
|
|
15
23
|
public uint ResetResendCycles { get; }
|
|
16
24
|
public byte? RtPriority { get; }
|
|
17
25
|
public bool DisableRtPriority { get; }
|
|
26
|
+
public RtSchedulePolicy RtPolicy { get; }
|
|
18
27
|
public ulong? RtAffinity { get; }
|
|
19
28
|
public bool ValidateState { get; }
|
|
20
|
-
|
|
21
|
-
private const byte RtPriorityModeDefault = 0;
|
|
22
|
-
private const byte RtPriorityModeDisabled = 1;
|
|
23
|
-
private const byte RtPriorityModeExplicit = 2;
|
|
29
|
+
public bool RequireSupportedFirmware { get; }
|
|
24
30
|
|
|
25
31
|
public ClientConfig() : this(lowLatency: false)
|
|
26
32
|
{
|
|
@@ -34,8 +40,10 @@ namespace AUTD3
|
|
|
34
40
|
uint resetResendCycles = 2,
|
|
35
41
|
byte? rtPriority = null,
|
|
36
42
|
bool disableRtPriority = false,
|
|
43
|
+
RtSchedulePolicy rtPolicy = RtSchedulePolicy.Fifo,
|
|
37
44
|
ulong? rtAffinity = null,
|
|
38
|
-
bool validateState = true
|
|
45
|
+
bool validateState = true,
|
|
46
|
+
bool requireSupportedFirmware = false)
|
|
39
47
|
{
|
|
40
48
|
if (rtPriority.HasValue && disableRtPriority)
|
|
41
49
|
{
|
|
@@ -48,42 +56,72 @@ namespace AUTD3
|
|
|
48
56
|
ResetResendCycles = resetResendCycles;
|
|
49
57
|
RtPriority = rtPriority;
|
|
50
58
|
DisableRtPriority = disableRtPriority;
|
|
59
|
+
RtPolicy = rtPolicy;
|
|
51
60
|
RtAffinity = rtAffinity;
|
|
52
61
|
ValidateState = validateState;
|
|
62
|
+
RequireSupportedFirmware = requireSupportedFirmware;
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
internal IntPtr CreateHandle()
|
|
56
66
|
{
|
|
57
|
-
var handle = NativeClient.autd3_client_config_new(
|
|
58
|
-
LowLatency,
|
|
59
|
-
TimeoutCycles,
|
|
60
|
-
(UIntPtr)MaxInflight,
|
|
61
|
-
MaxResyncRounds,
|
|
62
|
-
ResetResendCycles,
|
|
63
|
-
RtPriority.HasValue
|
|
64
|
-
? RtPriorityModeExplicit
|
|
65
|
-
: DisableRtPriority
|
|
66
|
-
? RtPriorityModeDisabled
|
|
67
|
-
: RtPriorityModeDefault,
|
|
68
|
-
RtPriority ?? 0,
|
|
69
|
-
RtAffinity.HasValue,
|
|
70
|
-
(UIntPtr)(RtAffinity ?? 0),
|
|
71
|
-
ValidateState);
|
|
67
|
+
var handle = NativeClient.autd3_client_config_new();
|
|
72
68
|
if (handle == IntPtr.Zero)
|
|
73
69
|
{
|
|
74
70
|
throw new Autd3Exception("failed to create client config");
|
|
75
71
|
}
|
|
72
|
+
try
|
|
73
|
+
{
|
|
74
|
+
NativeConfig.Apply("lowLatency", NativeClient.autd3_client_config_set_low_latency(handle, LowLatency));
|
|
75
|
+
NativeConfig.Apply("timeoutCycles", NativeClient.autd3_client_config_set_timeout_cycles(handle, TimeoutCycles));
|
|
76
|
+
NativeConfig.Apply("maxInflight", NativeClient.autd3_client_config_set_max_inflight(handle, (UIntPtr)MaxInflight));
|
|
77
|
+
NativeConfig.Apply("maxResyncRounds", NativeClient.autd3_client_config_set_max_resync_rounds(handle, MaxResyncRounds));
|
|
78
|
+
NativeConfig.Apply("resetResendCycles", NativeClient.autd3_client_config_set_reset_resend_cycles(handle, ResetResendCycles));
|
|
79
|
+
NativeConfig.Apply("rtPriority", NativeClient.autd3_client_config_set_rt_priority(handle, NativeConfig.RtPriorityMode(RtPriority, DisableRtPriority), RtPriority ?? 0));
|
|
80
|
+
NativeConfig.Apply("rtPolicy", NativeClient.autd3_client_config_set_rt_policy(handle, (byte)RtPolicy));
|
|
81
|
+
NativeConfig.Apply("rtAffinity", NativeClient.autd3_client_config_set_rt_affinity(handle, RtAffinity.HasValue, (UIntPtr)(RtAffinity ?? 0)));
|
|
82
|
+
NativeConfig.Apply("validateState", NativeClient.autd3_client_config_set_validate_state(handle, ValidateState));
|
|
83
|
+
NativeConfig.Apply("requireSupportedFirmware", NativeClient.autd3_client_config_set_require_supported_firmware(handle, RequireSupportedFirmware));
|
|
84
|
+
}
|
|
85
|
+
catch
|
|
86
|
+
{
|
|
87
|
+
NativeClient.autd3_client_config_free(handle);
|
|
88
|
+
throw;
|
|
89
|
+
}
|
|
76
90
|
return handle;
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
93
|
|
|
94
|
+
internal static class NativeConfig
|
|
95
|
+
{
|
|
96
|
+
internal const byte RtPriorityModeDefault = 0;
|
|
97
|
+
internal const byte RtPriorityModeDisabled = 1;
|
|
98
|
+
internal const byte RtPriorityModeExplicit = 2;
|
|
99
|
+
|
|
100
|
+
internal static byte RtPriorityMode(byte? rtPriority, bool disabled) =>
|
|
101
|
+
rtPriority.HasValue
|
|
102
|
+
? RtPriorityModeExplicit
|
|
103
|
+
: disabled
|
|
104
|
+
? RtPriorityModeDisabled
|
|
105
|
+
: RtPriorityModeDefault;
|
|
106
|
+
|
|
107
|
+
internal static void Apply(string field, int code)
|
|
108
|
+
{
|
|
109
|
+
if (code != 0)
|
|
110
|
+
{
|
|
111
|
+
throw new Autd3Exception($"`{field}` is out of the range the native library accepts");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
80
116
|
public sealed class DatagramBuilder : IDisposable
|
|
81
117
|
{
|
|
82
118
|
private readonly Geometry _geometry;
|
|
83
119
|
private readonly int _numDevices;
|
|
84
120
|
private readonly IntPtr _client;
|
|
85
121
|
|
|
86
|
-
|
|
122
|
+
private IntPtr _handle;
|
|
123
|
+
|
|
124
|
+
internal IntPtr Handle => _handle;
|
|
87
125
|
|
|
88
126
|
public DatagramBuilder(Geometry geometry) : this(geometry, IntPtr.Zero)
|
|
89
127
|
{
|
|
@@ -94,7 +132,7 @@ namespace AUTD3
|
|
|
94
132
|
_geometry = geometry;
|
|
95
133
|
_numDevices = geometry.NumDevices;
|
|
96
134
|
_client = client;
|
|
97
|
-
|
|
135
|
+
_handle = NativeClient.autd3_datagram_builder_new(geometry.Handle);
|
|
98
136
|
if (Handle == IntPtr.Zero)
|
|
99
137
|
{
|
|
100
138
|
throw new Autd3Exception("failed to create datagram builder");
|
|
@@ -104,7 +142,10 @@ namespace AUTD3
|
|
|
104
142
|
public DatagramBuilder Push(ICommand command)
|
|
105
143
|
{
|
|
106
144
|
var op = command.CreateOp();
|
|
107
|
-
NativeClient.autd3_datagram_builder_push(Handle, op)
|
|
145
|
+
if (NativeClient.autd3_datagram_builder_push(Handle, op) != 0)
|
|
146
|
+
{
|
|
147
|
+
throw new Autd3Exception("failed to push the command onto the datagram builder");
|
|
148
|
+
}
|
|
108
149
|
return this;
|
|
109
150
|
}
|
|
110
151
|
|
|
@@ -130,13 +171,16 @@ namespace AUTD3
|
|
|
130
171
|
}
|
|
131
172
|
throw;
|
|
132
173
|
}
|
|
133
|
-
NativeClient.autd3_datagram_builder_push_each(Handle, ops, (UIntPtr)_numDevices)
|
|
174
|
+
if (NativeClient.autd3_datagram_builder_push_each(Handle, ops, (UIntPtr)_numDevices) != 0)
|
|
175
|
+
{
|
|
176
|
+
throw new Autd3Exception("failed to push the per-device commands onto the datagram builder");
|
|
177
|
+
}
|
|
134
178
|
return this;
|
|
135
179
|
}
|
|
136
180
|
|
|
137
181
|
public Frames Build()
|
|
138
182
|
{
|
|
139
|
-
var err = new byte[
|
|
183
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
140
184
|
var handle = NativeClient.autd3_datagram_builder_build(Handle, _client, err, (UIntPtr)err.Length);
|
|
141
185
|
if (handle == IntPtr.Zero)
|
|
142
186
|
{
|
|
@@ -147,19 +191,20 @@ namespace AUTD3
|
|
|
147
191
|
|
|
148
192
|
public void Dispose()
|
|
149
193
|
{
|
|
150
|
-
|
|
194
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
195
|
+
if (handle != IntPtr.Zero)
|
|
151
196
|
{
|
|
152
|
-
NativeClient.autd3_datagram_builder_free(
|
|
153
|
-
Handle = IntPtr.Zero;
|
|
197
|
+
NativeClient.autd3_datagram_builder_free(handle);
|
|
154
198
|
}
|
|
155
199
|
GC.SuppressFinalize(this);
|
|
156
200
|
}
|
|
157
201
|
|
|
158
202
|
~DatagramBuilder()
|
|
159
203
|
{
|
|
160
|
-
|
|
204
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
205
|
+
if (handle != IntPtr.Zero)
|
|
161
206
|
{
|
|
162
|
-
NativeClient.autd3_datagram_builder_free(
|
|
207
|
+
NativeClient.autd3_datagram_builder_free(handle);
|
|
163
208
|
}
|
|
164
209
|
}
|
|
165
210
|
}
|
|
@@ -179,11 +224,13 @@ namespace AUTD3
|
|
|
179
224
|
|
|
180
225
|
public sealed class Frames : IDisposable, IEnumerable<Frame>
|
|
181
226
|
{
|
|
182
|
-
|
|
227
|
+
private IntPtr _handle;
|
|
228
|
+
|
|
229
|
+
internal IntPtr Handle => _handle;
|
|
183
230
|
|
|
184
231
|
internal Frames(IntPtr handle)
|
|
185
232
|
{
|
|
186
|
-
|
|
233
|
+
_handle = handle;
|
|
187
234
|
}
|
|
188
235
|
|
|
189
236
|
public int Length => (int)NativeClient.autd3_datagrams_num_frames(Handle);
|
|
@@ -213,19 +260,20 @@ namespace AUTD3
|
|
|
213
260
|
|
|
214
261
|
public void Dispose()
|
|
215
262
|
{
|
|
216
|
-
|
|
263
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
264
|
+
if (handle != IntPtr.Zero)
|
|
217
265
|
{
|
|
218
|
-
NativeClient.autd3_datagrams_free(
|
|
219
|
-
Handle = IntPtr.Zero;
|
|
266
|
+
NativeClient.autd3_datagrams_free(handle);
|
|
220
267
|
}
|
|
221
268
|
GC.SuppressFinalize(this);
|
|
222
269
|
}
|
|
223
270
|
|
|
224
271
|
~Frames()
|
|
225
272
|
{
|
|
226
|
-
|
|
273
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
274
|
+
if (handle != IntPtr.Zero)
|
|
227
275
|
{
|
|
228
|
-
NativeClient.autd3_datagrams_free(
|
|
276
|
+
NativeClient.autd3_datagrams_free(handle);
|
|
229
277
|
}
|
|
230
278
|
}
|
|
231
279
|
}
|
package/Legacy.cs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Threading;
|
|
2
3
|
using System.Collections;
|
|
3
4
|
using System.Collections.Generic;
|
|
4
5
|
using System.Threading.Tasks;
|
|
@@ -11,6 +12,8 @@ namespace AUTD3.Legacy
|
|
|
11
12
|
{
|
|
12
13
|
public uint TimeoutCycles { get; }
|
|
13
14
|
public byte? RtPriority { get; }
|
|
15
|
+
public bool DisableRtPriority { get; }
|
|
16
|
+
public RtSchedulePolicy RtPolicy { get; }
|
|
14
17
|
public ulong? RtAffinity { get; }
|
|
15
18
|
|
|
16
19
|
public LegacyClientConfig() : this(timeoutCycles: 2000)
|
|
@@ -20,25 +23,40 @@ namespace AUTD3.Legacy
|
|
|
20
23
|
public LegacyClientConfig(
|
|
21
24
|
uint timeoutCycles = 2000,
|
|
22
25
|
byte? rtPriority = null,
|
|
26
|
+
bool disableRtPriority = false,
|
|
27
|
+
RtSchedulePolicy rtPolicy = RtSchedulePolicy.Fifo,
|
|
23
28
|
ulong? rtAffinity = null)
|
|
24
29
|
{
|
|
30
|
+
if (rtPriority.HasValue && disableRtPriority)
|
|
31
|
+
{
|
|
32
|
+
throw new ArgumentException("rtPriority and disableRtPriority are mutually exclusive");
|
|
33
|
+
}
|
|
25
34
|
TimeoutCycles = timeoutCycles;
|
|
26
35
|
RtPriority = rtPriority;
|
|
36
|
+
DisableRtPriority = disableRtPriority;
|
|
37
|
+
RtPolicy = rtPolicy;
|
|
27
38
|
RtAffinity = rtAffinity;
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
internal IntPtr CreateHandle()
|
|
31
42
|
{
|
|
32
|
-
var handle = NativeLegacyClient.autd3_legacy_client_config_new(
|
|
33
|
-
TimeoutCycles,
|
|
34
|
-
RtPriority.HasValue,
|
|
35
|
-
RtPriority ?? 0,
|
|
36
|
-
RtAffinity.HasValue,
|
|
37
|
-
(UIntPtr)(RtAffinity ?? 0));
|
|
43
|
+
var handle = NativeLegacyClient.autd3_legacy_client_config_new();
|
|
38
44
|
if (handle == IntPtr.Zero)
|
|
39
45
|
{
|
|
40
46
|
throw new Autd3Exception("failed to create legacy client config");
|
|
41
47
|
}
|
|
48
|
+
try
|
|
49
|
+
{
|
|
50
|
+
NativeConfig.Apply("timeoutCycles", NativeLegacyClient.autd3_legacy_client_config_set_timeout_cycles(handle, TimeoutCycles));
|
|
51
|
+
NativeConfig.Apply("rtPriority", NativeLegacyClient.autd3_legacy_client_config_set_rt_priority(handle, NativeConfig.RtPriorityMode(RtPriority, DisableRtPriority), RtPriority ?? 0));
|
|
52
|
+
NativeConfig.Apply("rtPolicy", NativeLegacyClient.autd3_legacy_client_config_set_rt_policy(handle, (byte)RtPolicy));
|
|
53
|
+
NativeConfig.Apply("rtAffinity", NativeLegacyClient.autd3_legacy_client_config_set_rt_affinity(handle, RtAffinity.HasValue, (UIntPtr)(RtAffinity ?? 0)));
|
|
54
|
+
}
|
|
55
|
+
catch
|
|
56
|
+
{
|
|
57
|
+
NativeLegacyClient.autd3_legacy_client_config_free(handle);
|
|
58
|
+
throw;
|
|
59
|
+
}
|
|
42
60
|
return handle;
|
|
43
61
|
}
|
|
44
62
|
}
|
|
@@ -80,7 +98,9 @@ namespace AUTD3.Legacy
|
|
|
80
98
|
private readonly int _numDevices;
|
|
81
99
|
private readonly IntPtr _client;
|
|
82
100
|
|
|
83
|
-
|
|
101
|
+
private IntPtr _handle;
|
|
102
|
+
|
|
103
|
+
internal IntPtr Handle => _handle;
|
|
84
104
|
|
|
85
105
|
public LegacyDatagramBuilder(Geometry geometry) : this(geometry, IntPtr.Zero)
|
|
86
106
|
{
|
|
@@ -91,7 +111,7 @@ namespace AUTD3.Legacy
|
|
|
91
111
|
_geometry = geometry;
|
|
92
112
|
_numDevices = geometry.NumDevices;
|
|
93
113
|
_client = client;
|
|
94
|
-
|
|
114
|
+
_handle = NativeLegacyClient.autd3_legacy_datagram_builder_new(geometry.Handle);
|
|
95
115
|
if (Handle == IntPtr.Zero)
|
|
96
116
|
{
|
|
97
117
|
throw new Autd3Exception("failed to create legacy datagram builder");
|
|
@@ -101,14 +121,20 @@ namespace AUTD3.Legacy
|
|
|
101
121
|
public LegacyDatagramBuilder Push(ICommand command)
|
|
102
122
|
{
|
|
103
123
|
var op = command.CreateOp();
|
|
104
|
-
NativeLegacyClient.autd3_legacy_datagram_builder_push(Handle, op)
|
|
124
|
+
if (NativeLegacyClient.autd3_legacy_datagram_builder_push(Handle, op) != 0)
|
|
125
|
+
{
|
|
126
|
+
throw new Autd3Exception("failed to push the command onto the legacy datagram builder");
|
|
127
|
+
}
|
|
105
128
|
return this;
|
|
106
129
|
}
|
|
107
130
|
|
|
108
131
|
public LegacyDatagramBuilder Push(ILegacyCommand command)
|
|
109
132
|
{
|
|
110
133
|
var op = command.CreateOp();
|
|
111
|
-
NativeLegacyClient.autd3_legacy_datagram_builder_push_legacy(Handle, op)
|
|
134
|
+
if (NativeLegacyClient.autd3_legacy_datagram_builder_push_legacy(Handle, op) != 0)
|
|
135
|
+
{
|
|
136
|
+
throw new Autd3Exception("failed to push the command onto the legacy datagram builder");
|
|
137
|
+
}
|
|
112
138
|
return this;
|
|
113
139
|
}
|
|
114
140
|
|
|
@@ -134,13 +160,16 @@ namespace AUTD3.Legacy
|
|
|
134
160
|
}
|
|
135
161
|
throw;
|
|
136
162
|
}
|
|
137
|
-
NativeLegacyClient.autd3_legacy_datagram_builder_push_each(Handle, ops, (UIntPtr)_numDevices)
|
|
163
|
+
if (NativeLegacyClient.autd3_legacy_datagram_builder_push_each(Handle, ops, (UIntPtr)_numDevices) != 0)
|
|
164
|
+
{
|
|
165
|
+
throw new Autd3Exception("failed to push the per-device commands onto the legacy datagram builder");
|
|
166
|
+
}
|
|
138
167
|
return this;
|
|
139
168
|
}
|
|
140
169
|
|
|
141
170
|
public LegacyFrames Build()
|
|
142
171
|
{
|
|
143
|
-
var err = new byte[
|
|
172
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
144
173
|
var handle = NativeLegacyClient.autd3_legacy_datagram_builder_build(Handle, _client, err, (UIntPtr)err.Length);
|
|
145
174
|
if (handle == IntPtr.Zero)
|
|
146
175
|
{
|
|
@@ -151,19 +180,20 @@ namespace AUTD3.Legacy
|
|
|
151
180
|
|
|
152
181
|
public void Dispose()
|
|
153
182
|
{
|
|
154
|
-
|
|
183
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
184
|
+
if (handle != IntPtr.Zero)
|
|
155
185
|
{
|
|
156
|
-
NativeLegacyClient.autd3_legacy_datagram_builder_free(
|
|
157
|
-
Handle = IntPtr.Zero;
|
|
186
|
+
NativeLegacyClient.autd3_legacy_datagram_builder_free(handle);
|
|
158
187
|
}
|
|
159
188
|
GC.SuppressFinalize(this);
|
|
160
189
|
}
|
|
161
190
|
|
|
162
191
|
~LegacyDatagramBuilder()
|
|
163
192
|
{
|
|
164
|
-
|
|
193
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
194
|
+
if (handle != IntPtr.Zero)
|
|
165
195
|
{
|
|
166
|
-
NativeLegacyClient.autd3_legacy_datagram_builder_free(
|
|
196
|
+
NativeLegacyClient.autd3_legacy_datagram_builder_free(handle);
|
|
167
197
|
}
|
|
168
198
|
}
|
|
169
199
|
}
|
|
@@ -182,11 +212,13 @@ namespace AUTD3.Legacy
|
|
|
182
212
|
|
|
183
213
|
public sealed class LegacyFrames : IDisposable, IEnumerable<LegacyFrame>
|
|
184
214
|
{
|
|
185
|
-
|
|
215
|
+
private IntPtr _handle;
|
|
216
|
+
|
|
217
|
+
internal IntPtr Handle => _handle;
|
|
186
218
|
|
|
187
219
|
internal LegacyFrames(IntPtr handle)
|
|
188
220
|
{
|
|
189
|
-
|
|
221
|
+
_handle = handle;
|
|
190
222
|
}
|
|
191
223
|
|
|
192
224
|
public int Length => (int)NativeLegacyClient.autd3_legacy_frames_num_frames(Handle);
|
|
@@ -216,32 +248,35 @@ namespace AUTD3.Legacy
|
|
|
216
248
|
|
|
217
249
|
public void Dispose()
|
|
218
250
|
{
|
|
219
|
-
|
|
251
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
252
|
+
if (handle != IntPtr.Zero)
|
|
220
253
|
{
|
|
221
|
-
NativeLegacyClient.autd3_legacy_frames_free(
|
|
222
|
-
Handle = IntPtr.Zero;
|
|
254
|
+
NativeLegacyClient.autd3_legacy_frames_free(handle);
|
|
223
255
|
}
|
|
224
256
|
GC.SuppressFinalize(this);
|
|
225
257
|
}
|
|
226
258
|
|
|
227
259
|
~LegacyFrames()
|
|
228
260
|
{
|
|
229
|
-
|
|
261
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
262
|
+
if (handle != IntPtr.Zero)
|
|
230
263
|
{
|
|
231
|
-
NativeLegacyClient.autd3_legacy_frames_free(
|
|
264
|
+
NativeLegacyClient.autd3_legacy_frames_free(handle);
|
|
232
265
|
}
|
|
233
266
|
}
|
|
234
267
|
}
|
|
235
268
|
|
|
236
269
|
public sealed class LegacyClient : IDisposable
|
|
237
270
|
{
|
|
238
|
-
|
|
271
|
+
private IntPtr _handle;
|
|
272
|
+
|
|
273
|
+
internal IntPtr Handle => _handle;
|
|
239
274
|
|
|
240
275
|
private readonly Geometry _geometry;
|
|
241
276
|
|
|
242
277
|
private LegacyClient(IntPtr handle, Geometry geometry)
|
|
243
278
|
{
|
|
244
|
-
|
|
279
|
+
_handle = handle;
|
|
245
280
|
_geometry = geometry;
|
|
246
281
|
}
|
|
247
282
|
|
|
@@ -249,8 +284,17 @@ namespace AUTD3.Legacy
|
|
|
249
284
|
{
|
|
250
285
|
var opener = link.TakeLegacyOpener();
|
|
251
286
|
|
|
287
|
+
IntPtr configHandle;
|
|
288
|
+
try
|
|
289
|
+
{
|
|
290
|
+
configHandle = config.CreateHandle();
|
|
291
|
+
}
|
|
292
|
+
catch
|
|
293
|
+
{
|
|
294
|
+
NativeLegacyClient.autd3_legacy_client_opener_free(opener);
|
|
295
|
+
throw;
|
|
296
|
+
}
|
|
252
297
|
|
|
253
|
-
var configHandle = config.CreateHandle();
|
|
254
298
|
Task<IntPtr> task;
|
|
255
299
|
try
|
|
256
300
|
{
|
|
@@ -329,19 +373,20 @@ namespace AUTD3.Legacy
|
|
|
329
373
|
|
|
330
374
|
public void Dispose()
|
|
331
375
|
{
|
|
332
|
-
|
|
376
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
377
|
+
if (handle != IntPtr.Zero)
|
|
333
378
|
{
|
|
334
|
-
NativeLegacyClient.autd3_legacy_client_free(
|
|
335
|
-
Handle = IntPtr.Zero;
|
|
379
|
+
NativeLegacyClient.autd3_legacy_client_free(handle);
|
|
336
380
|
}
|
|
337
381
|
GC.SuppressFinalize(this);
|
|
338
382
|
}
|
|
339
383
|
|
|
340
384
|
~LegacyClient()
|
|
341
385
|
{
|
|
342
|
-
|
|
386
|
+
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
387
|
+
if (handle != IntPtr.Zero)
|
|
343
388
|
{
|
|
344
|
-
NativeLegacyClient.autd3_legacy_client_free(
|
|
389
|
+
NativeLegacyClient.autd3_legacy_client_free(handle);
|
|
345
390
|
}
|
|
346
391
|
}
|
|
347
392
|
}
|
package/Native.cs
CHANGED
|
@@ -12,30 +12,58 @@ namespace AUTD3
|
|
|
12
12
|
{
|
|
13
13
|
private const string Lib = "autd3capi";
|
|
14
14
|
|
|
15
|
+
static NativeClient() => NativeAbi.Verify(Lib, autd3_abi_version());
|
|
16
|
+
|
|
17
|
+
[DllImport(Lib)]
|
|
18
|
+
private static extern uint autd3_abi_version();
|
|
19
|
+
|
|
20
|
+
[DllImport(Lib)]
|
|
21
|
+
internal static extern IntPtr autd3_client_config_new();
|
|
22
|
+
|
|
23
|
+
[DllImport(Lib)]
|
|
24
|
+
internal static extern int autd3_client_config_set_low_latency(IntPtr config, [MarshalAs(UnmanagedType.I1)] bool value);
|
|
25
|
+
|
|
26
|
+
[DllImport(Lib)]
|
|
27
|
+
internal static extern int autd3_client_config_set_validate_state(IntPtr config, [MarshalAs(UnmanagedType.I1)] bool value);
|
|
28
|
+
|
|
15
29
|
[DllImport(Lib)]
|
|
16
|
-
internal static extern IntPtr
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
internal static extern int autd3_client_config_set_require_supported_firmware(IntPtr config, [MarshalAs(UnmanagedType.I1)] bool value);
|
|
31
|
+
|
|
32
|
+
[DllImport(Lib)]
|
|
33
|
+
internal static extern int autd3_client_config_set_timeout_cycles(IntPtr config, uint value);
|
|
34
|
+
|
|
35
|
+
[DllImport(Lib)]
|
|
36
|
+
internal static extern int autd3_client_config_set_max_inflight(IntPtr config, UIntPtr value);
|
|
37
|
+
|
|
38
|
+
[DllImport(Lib)]
|
|
39
|
+
internal static extern int autd3_client_config_set_max_resync_rounds(IntPtr config, uint value);
|
|
40
|
+
|
|
41
|
+
[DllImport(Lib)]
|
|
42
|
+
internal static extern int autd3_client_config_set_reset_resend_cycles(IntPtr config, uint value);
|
|
43
|
+
|
|
44
|
+
[DllImport(Lib)]
|
|
45
|
+
internal static extern int autd3_client_config_set_rt_priority(IntPtr config, byte mode, byte value);
|
|
46
|
+
|
|
47
|
+
[DllImport(Lib)]
|
|
48
|
+
internal static extern int autd3_client_config_set_rt_policy(IntPtr config, byte value);
|
|
49
|
+
|
|
50
|
+
[DllImport(Lib)]
|
|
51
|
+
internal static extern int autd3_client_config_set_rt_affinity(IntPtr config, [MarshalAs(UnmanagedType.I1)] bool hasAffinity, UIntPtr coreId);
|
|
27
52
|
|
|
28
53
|
[DllImport(Lib)]
|
|
29
54
|
internal static extern void autd3_client_config_free(IntPtr config);
|
|
30
55
|
|
|
56
|
+
[DllImport(Lib)]
|
|
57
|
+
internal static extern void autd3_client_opener_free(IntPtr opener);
|
|
58
|
+
|
|
31
59
|
[DllImport(Lib)]
|
|
32
60
|
internal static extern IntPtr autd3_datagram_builder_new(IntPtr geometry);
|
|
33
61
|
|
|
34
62
|
[DllImport(Lib)]
|
|
35
|
-
internal static extern
|
|
63
|
+
internal static extern int autd3_datagram_builder_push(IntPtr builder, IntPtr op);
|
|
36
64
|
|
|
37
65
|
[DllImport(Lib)]
|
|
38
|
-
internal static extern
|
|
66
|
+
internal static extern int autd3_datagram_builder_push_each(IntPtr builder, IntPtr[] ops, UIntPtr numDevices);
|
|
39
67
|
|
|
40
68
|
[DllImport(Lib)]
|
|
41
69
|
internal static extern void autd3_op_free(IntPtr op);
|
|
@@ -141,21 +169,31 @@ namespace AUTD3
|
|
|
141
169
|
private const string Lib = "autd3capi";
|
|
142
170
|
|
|
143
171
|
[DllImport(Lib)]
|
|
144
|
-
internal static extern IntPtr autd3_legacy_client_config_new(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
172
|
+
internal static extern IntPtr autd3_legacy_client_config_new();
|
|
173
|
+
|
|
174
|
+
[DllImport(Lib)]
|
|
175
|
+
internal static extern int autd3_legacy_client_config_set_timeout_cycles(IntPtr config, uint value);
|
|
176
|
+
|
|
177
|
+
[DllImport(Lib)]
|
|
178
|
+
internal static extern int autd3_legacy_client_config_set_rt_priority(IntPtr config, byte mode, byte value);
|
|
179
|
+
|
|
180
|
+
[DllImport(Lib)]
|
|
181
|
+
internal static extern int autd3_legacy_client_config_set_rt_policy(IntPtr config, byte value);
|
|
182
|
+
|
|
183
|
+
[DllImport(Lib)]
|
|
184
|
+
internal static extern int autd3_legacy_client_config_set_rt_affinity(IntPtr config, [MarshalAs(UnmanagedType.I1)] bool hasAffinity, UIntPtr coreId);
|
|
150
185
|
|
|
151
186
|
[DllImport(Lib)]
|
|
152
187
|
internal static extern void autd3_legacy_client_config_free(IntPtr config);
|
|
153
188
|
|
|
189
|
+
[DllImport(Lib)]
|
|
190
|
+
internal static extern void autd3_legacy_client_opener_free(IntPtr opener);
|
|
191
|
+
|
|
154
192
|
[DllImport(Lib)]
|
|
155
193
|
internal static extern IntPtr autd3_legacy_datagram_builder_new(IntPtr geometry);
|
|
156
194
|
|
|
157
195
|
[DllImport(Lib)]
|
|
158
|
-
internal static extern
|
|
196
|
+
internal static extern int autd3_legacy_datagram_builder_push(IntPtr builder, IntPtr op);
|
|
159
197
|
|
|
160
198
|
[DllImport(Lib)]
|
|
161
199
|
internal static extern IntPtr autd3_legacy_op_change_segment(byte kind, byte bank, byte transitionMode, ulong transitionValue);
|
|
@@ -164,10 +202,10 @@ namespace AUTD3
|
|
|
164
202
|
internal static extern void autd3_legacy_op_free(IntPtr op);
|
|
165
203
|
|
|
166
204
|
[DllImport(Lib)]
|
|
167
|
-
internal static extern
|
|
205
|
+
internal static extern int autd3_legacy_datagram_builder_push_legacy(IntPtr builder, IntPtr op);
|
|
168
206
|
|
|
169
207
|
[DllImport(Lib)]
|
|
170
|
-
internal static extern
|
|
208
|
+
internal static extern int autd3_legacy_datagram_builder_push_each(IntPtr builder, IntPtr[] ops, UIntPtr numDevices);
|
|
171
209
|
|
|
172
210
|
[DllImport(Lib)]
|
|
173
211
|
internal static extern void autd3_legacy_datagram_builder_free(IntPtr builder);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/Stm.cs
CHANGED
|
@@ -25,6 +25,11 @@ namespace AUTD3
|
|
|
25
25
|
{
|
|
26
26
|
private const string Lib = "autd3capi";
|
|
27
27
|
|
|
28
|
+
static NativeStm() => NativeAbi.Verify(Lib, autd3_abi_version());
|
|
29
|
+
|
|
30
|
+
[DllImport(Lib)]
|
|
31
|
+
private static extern uint autd3_abi_version();
|
|
32
|
+
|
|
28
33
|
[DllImport(Lib)]
|
|
29
34
|
internal static extern IntPtr autd3_stm_config_freq(float hz);
|
|
30
35
|
|
package/THIRD-PARTY-LICENSES.md
CHANGED
|
@@ -886,11 +886,41 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
886
886
|
|
|
887
887
|
Used by:
|
|
888
888
|
|
|
889
|
-
- autd3-
|
|
890
|
-
- autd3-
|
|
891
|
-
- autd3-
|
|
892
|
-
|
|
893
|
-
|
|
889
|
+
- autd3-rs 0.6.0 — https://github.com/shinolab/autd3-sdk
|
|
890
|
+
- autd3-rs-core 0.6.0 — https://github.com/shinolab/autd3-sdk
|
|
891
|
+
- autd3-cpu-wire 0.6.0 — https://github.com/shinolab/autd3-sdk
|
|
892
|
+
|
|
893
|
+
```
|
|
894
|
+
MIT License
|
|
895
|
+
|
|
896
|
+
Copyright (c) 2026 Shun Suzuki
|
|
897
|
+
|
|
898
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
899
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
900
|
+
in the Software without restriction, including without limitation the rights
|
|
901
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
902
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
903
|
+
furnished to do so, subject to the following conditions:
|
|
904
|
+
|
|
905
|
+
The above copyright notice and this permission notice shall be included in all
|
|
906
|
+
copies or substantial portions of the Software.
|
|
907
|
+
|
|
908
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
909
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
910
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
911
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
912
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
913
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
914
|
+
SOFTWARE.
|
|
915
|
+
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
## MIT License
|
|
919
|
+
|
|
920
|
+
Used by:
|
|
921
|
+
|
|
922
|
+
- autd3-ffi 0.6.0 — https://github.com/shinolab/autd3-sdk
|
|
923
|
+
- autd3-ffi-abi 0.6.0 — https://github.com/shinolab/autd3-sdk
|
|
894
924
|
- chrono 0.4.45 — https://github.com/chronotope/chrono
|
|
895
925
|
- wide 1.5.0 — https://github.com/Lokathor/wide
|
|
896
926
|
- winapi-i686-pc-windows-gnu 0.4.0 — https://github.com/retep998/winapi-rs
|
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.6.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.6.0",
|
|
19
|
+
"com.shinolab.autd3-sdk.pattern": "0.6.0",
|
|
20
|
+
"com.shinolab.autd3-sdk.modulation": "0.6.0"
|
|
21
21
|
},
|
|
22
22
|
"samples": [
|
|
23
23
|
{
|