com.shinolab.autd3-sdk 0.10.0 → 0.13.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 +145 -292
- package/Commands.cs +241 -362
- package/Datagram.cs +10 -87
- package/Native.cs +31 -181
- 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/SafeHandles.cs +0 -26
- package/Samples~/FocusSine/FocusSineSample.cs +17 -11
- package/Stm.cs +126 -223
- package/THIRD-PARTY-LICENSES.md +56 -121
- package/Udp.cs +51 -248
- package/package.json +4 -4
package/Client.cs
CHANGED
|
@@ -7,6 +7,36 @@ using System.Threading.Tasks;
|
|
|
7
7
|
|
|
8
8
|
namespace AUTD3
|
|
9
9
|
{
|
|
10
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
11
|
+
internal struct ExecAtNative
|
|
12
|
+
{
|
|
13
|
+
public byte Kind;
|
|
14
|
+
public ulong Ns;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public readonly struct ExecAt
|
|
18
|
+
{
|
|
19
|
+
internal byte Kind { get; }
|
|
20
|
+
internal ulong Ns { get; }
|
|
21
|
+
|
|
22
|
+
private ExecAt(byte kind, ulong ns)
|
|
23
|
+
{
|
|
24
|
+
Kind = kind;
|
|
25
|
+
Ns = ns;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static ExecAt Immediate => new ExecAt(0, 0);
|
|
29
|
+
|
|
30
|
+
public static ExecAt Lead(TimeSpan lead) =>
|
|
31
|
+
lead >= TimeSpan.Zero
|
|
32
|
+
? new ExecAt(1, OptionNative.ToNanos(lead))
|
|
33
|
+
: throw new Autd3Exception("ExecAt.Lead must not be negative", Autd3ErrorCode.InvalidArgument);
|
|
34
|
+
|
|
35
|
+
public static ExecAt At(SysTime sysTime) => new ExecAt(2, sysTime.Nanos);
|
|
36
|
+
|
|
37
|
+
internal ExecAtNative ToNative() => new ExecAtNative { Kind = Kind, Ns = Ns };
|
|
38
|
+
}
|
|
39
|
+
|
|
10
40
|
public readonly struct FpgaState
|
|
11
41
|
{
|
|
12
42
|
public byte Raw { get; }
|
|
@@ -20,11 +50,9 @@ namespace AUTD3
|
|
|
20
50
|
public ModulationBank CurrentModBank => (ModulationBank)NativeClient.autd3_fpga_state_current_mod_bank(Raw);
|
|
21
51
|
public PatternBank CurrentPatternBank => (PatternBank)NativeClient.autd3_fpga_state_current_pattern_bank(Raw);
|
|
22
52
|
public bool IsPatternMode => NativeClient.autd3_fpga_state_is_pattern_mode(Raw);
|
|
23
|
-
public bool IsStmMode => !IsPatternMode;
|
|
24
53
|
public bool IsPatternStopped => NativeClient.autd3_fpga_state_is_pattern_stopped(Raw);
|
|
25
54
|
public bool IsModStopped => NativeClient.autd3_fpga_state_is_mod_stopped(Raw);
|
|
26
55
|
public bool IsTransitionPending => NativeClient.autd3_fpga_state_is_transition_pending(Raw);
|
|
27
|
-
public bool IsFailsafeActive => NativeClient.autd3_fpga_state_is_failsafe_active(Raw);
|
|
28
56
|
}
|
|
29
57
|
|
|
30
58
|
public readonly struct Version : IEquatable<Version>
|
|
@@ -97,47 +125,9 @@ namespace AUTD3
|
|
|
97
125
|
public static bool operator !=(FirmwareVersion left, FirmwareVersion right) => !left.Equals(right);
|
|
98
126
|
}
|
|
99
127
|
|
|
100
|
-
public sealed class BusStats : IDisposable
|
|
101
|
-
{
|
|
102
|
-
private readonly BusStatsHandle _handle;
|
|
103
|
-
|
|
104
|
-
internal BusStats(IntPtr handle)
|
|
105
|
-
{
|
|
106
|
-
_handle = new BusStatsHandle(handle);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private BusStatsHandle Handle
|
|
110
|
-
{
|
|
111
|
-
get
|
|
112
|
-
{
|
|
113
|
-
if (_handle.IsClosed)
|
|
114
|
-
{
|
|
115
|
-
throw new ObjectDisposedException(nameof(BusStats));
|
|
116
|
-
}
|
|
117
|
-
return _handle;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public ulong Frames => NativeClient.autd3_bus_stats_frames(Handle);
|
|
122
|
-
public ulong Resets => NativeClient.autd3_bus_stats_resets(Handle);
|
|
123
|
-
public ulong Heartbeats => NativeClient.autd3_bus_stats_heartbeats(Handle);
|
|
124
|
-
public ulong MissedReplies => NativeClient.autd3_bus_stats_missed_replies(Handle);
|
|
125
|
-
public ulong AckedFrames => NativeClient.autd3_bus_stats_acked_frames(Handle);
|
|
126
|
-
public ulong WorstAckLatencyNs => NativeClient.autd3_bus_stats_worst_ack_latency_ns(Handle);
|
|
127
|
-
public ulong MeanAckLatencyNs => NativeClient.autd3_bus_stats_mean_ack_latency_ns(Handle);
|
|
128
|
-
|
|
129
|
-
public void Dispose() => _handle.Dispose();
|
|
130
|
-
|
|
131
|
-
public override string ToString() =>
|
|
132
|
-
$"BusStats {{ Frames = {Frames}, Resets = {Resets}, Heartbeats = {Heartbeats}, MissedReplies = {MissedReplies}, " +
|
|
133
|
-
$"AckedFrames = {AckedFrames}, WorstAckLatencyNs = {WorstAckLatencyNs}, MeanAckLatencyNs = {MeanAckLatencyNs} }}";
|
|
134
|
-
}
|
|
135
|
-
|
|
136
128
|
public readonly struct Telemetry : IEquatable<Telemetry>
|
|
137
129
|
{
|
|
138
130
|
public uint FifoDrop { get; }
|
|
139
|
-
public uint Dedup { get; }
|
|
140
|
-
public uint SeqMismatch { get; }
|
|
141
131
|
public uint DispatchError { get; }
|
|
142
132
|
public uint Processed { get; }
|
|
143
133
|
public uint SendFailure { get; }
|
|
@@ -145,12 +135,12 @@ namespace AUTD3
|
|
|
145
135
|
public ushort PtpUnlockFailsafe { get; }
|
|
146
136
|
public byte SyncResync { get; }
|
|
147
137
|
public byte BootFailure { get; }
|
|
138
|
+
public byte CpuWatchdog { get; }
|
|
139
|
+
public uint ExecLate { get; }
|
|
148
140
|
|
|
149
141
|
internal Telemetry(NativeClient.TelemetryNative native)
|
|
150
142
|
{
|
|
151
143
|
FifoDrop = native.FifoDrop;
|
|
152
|
-
Dedup = native.Dedup;
|
|
153
|
-
SeqMismatch = native.SeqMismatch;
|
|
154
144
|
DispatchError = native.DispatchError;
|
|
155
145
|
Processed = native.Processed;
|
|
156
146
|
SendFailure = native.SendFailure;
|
|
@@ -158,18 +148,21 @@ namespace AUTD3
|
|
|
158
148
|
PtpUnlockFailsafe = native.PtpUnlockFailsafe;
|
|
159
149
|
SyncResync = native.SyncResync;
|
|
160
150
|
BootFailure = native.BootFailure;
|
|
151
|
+
CpuWatchdog = native.CpuWatchdog;
|
|
152
|
+
ExecLate = native.ExecLate;
|
|
161
153
|
}
|
|
162
154
|
|
|
163
155
|
public override string ToString() =>
|
|
164
|
-
$"Telemetry {{ FifoDrop = {FifoDrop},
|
|
156
|
+
$"Telemetry {{ FifoDrop = {FifoDrop}, DispatchError = {DispatchError}, " +
|
|
165
157
|
$"Processed = {Processed}, SendFailure = {SendFailure}, Failsafe = {Failsafe}, PtpUnlockFailsafe = {PtpUnlockFailsafe}, " +
|
|
166
|
-
$"SyncResync = {SyncResync}, BootFailure = {BootFailure} }}";
|
|
158
|
+
$"SyncResync = {SyncResync}, BootFailure = {BootFailure}, CpuWatchdog = {CpuWatchdog}, ExecLate = {ExecLate} }}";
|
|
167
159
|
|
|
168
160
|
public bool Equals(Telemetry other) =>
|
|
169
|
-
FifoDrop == other.FifoDrop &&
|
|
161
|
+
FifoDrop == other.FifoDrop &&
|
|
170
162
|
DispatchError == other.DispatchError && Processed == other.Processed && SendFailure == other.SendFailure &&
|
|
171
163
|
Failsafe == other.Failsafe && PtpUnlockFailsafe == other.PtpUnlockFailsafe &&
|
|
172
|
-
SyncResync == other.SyncResync && BootFailure == other.BootFailure
|
|
164
|
+
SyncResync == other.SyncResync && BootFailure == other.BootFailure && CpuWatchdog == other.CpuWatchdog &&
|
|
165
|
+
ExecLate == other.ExecLate;
|
|
173
166
|
|
|
174
167
|
public override bool Equals(object? obj) => obj is Telemetry other && Equals(other);
|
|
175
168
|
|
|
@@ -177,8 +170,6 @@ namespace AUTD3
|
|
|
177
170
|
{
|
|
178
171
|
var hash = new HashCode();
|
|
179
172
|
hash.Add(FifoDrop);
|
|
180
|
-
hash.Add(Dedup);
|
|
181
|
-
hash.Add(SeqMismatch);
|
|
182
173
|
hash.Add(DispatchError);
|
|
183
174
|
hash.Add(Processed);
|
|
184
175
|
hash.Add(SendFailure);
|
|
@@ -186,6 +177,8 @@ namespace AUTD3
|
|
|
186
177
|
hash.Add(PtpUnlockFailsafe);
|
|
187
178
|
hash.Add(SyncResync);
|
|
188
179
|
hash.Add(BootFailure);
|
|
180
|
+
hash.Add(CpuWatchdog);
|
|
181
|
+
hash.Add(ExecLate);
|
|
189
182
|
return hash.ToHashCode();
|
|
190
183
|
}
|
|
191
184
|
|
|
@@ -194,130 +187,45 @@ namespace AUTD3
|
|
|
194
187
|
public static bool operator !=(Telemetry left, Telemetry right) => !left.Equals(right);
|
|
195
188
|
}
|
|
196
189
|
|
|
197
|
-
public
|
|
190
|
+
public readonly struct DeviceStatus : IEquatable<DeviceStatus>
|
|
198
191
|
{
|
|
199
|
-
public
|
|
192
|
+
public DeviceState State { get; }
|
|
200
193
|
|
|
201
|
-
|
|
202
|
-
{
|
|
203
|
-
Devices = devices;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
public bool AllReady
|
|
207
|
-
{
|
|
208
|
-
get
|
|
209
|
-
{
|
|
210
|
-
foreach (var state in Devices)
|
|
211
|
-
{
|
|
212
|
-
if (state != DeviceState.Ready)
|
|
213
|
-
{
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public bool AnyLost
|
|
222
|
-
{
|
|
223
|
-
get
|
|
224
|
-
{
|
|
225
|
-
foreach (var state in Devices)
|
|
226
|
-
{
|
|
227
|
-
if (state == DeviceState.Lost)
|
|
228
|
-
{
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
194
|
+
public bool PtpLocked { get; }
|
|
235
195
|
|
|
236
|
-
public
|
|
237
|
-
{
|
|
238
|
-
if (obj is not DeviceStatus other)
|
|
239
|
-
{
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
if (Devices.Count != other.Devices.Count)
|
|
243
|
-
{
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
for (var i = 0; i < Devices.Count; i++)
|
|
247
|
-
{
|
|
248
|
-
if (Devices[i] != other.Devices[i])
|
|
249
|
-
{
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
196
|
+
public bool FailsafeActive { get; }
|
|
255
197
|
|
|
256
|
-
|
|
198
|
+
internal DeviceStatus(NativeClient.DeviceStatusNative native)
|
|
257
199
|
{
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
hash.Add(state);
|
|
262
|
-
}
|
|
263
|
-
return hash.ToHashCode();
|
|
200
|
+
State = DeviceState.FromNative(native.State);
|
|
201
|
+
PtpLocked = native.PtpLocked != 0;
|
|
202
|
+
FailsafeActive = native.FailsafeActive != 0;
|
|
264
203
|
}
|
|
265
204
|
|
|
266
|
-
public
|
|
267
|
-
|
|
205
|
+
public override string ToString() =>
|
|
206
|
+
$"DeviceStatus {{ State = {State}, PtpLocked = {PtpLocked}, FailsafeActive = {FailsafeActive} }}";
|
|
268
207
|
|
|
269
|
-
public
|
|
270
|
-
|
|
208
|
+
public bool Equals(DeviceStatus other) =>
|
|
209
|
+
State == other.State && PtpLocked == other.PtpLocked && FailsafeActive == other.FailsafeActive;
|
|
271
210
|
|
|
272
|
-
|
|
273
|
-
{
|
|
274
|
-
private readonly CheckerHandle _handle;
|
|
211
|
+
public override bool Equals(object? obj) => obj is DeviceStatus other && Equals(other);
|
|
275
212
|
|
|
276
|
-
|
|
277
|
-
{
|
|
278
|
-
_handle = new CheckerHandle(handle);
|
|
279
|
-
}
|
|
213
|
+
public override int GetHashCode() => HashCode.Combine(State, PtpLocked, FailsafeActive);
|
|
280
214
|
|
|
281
|
-
public DeviceStatus
|
|
282
|
-
{
|
|
283
|
-
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
284
|
-
var status = NativeClient.autd3_checker_check(_handle, out var code, err, (UIntPtr)err.Length);
|
|
285
|
-
if (status == IntPtr.Zero)
|
|
286
|
-
{
|
|
287
|
-
throw Autd3Exception.FromNative(code, err);
|
|
288
|
-
}
|
|
289
|
-
try
|
|
290
|
-
{
|
|
291
|
-
var count = (int)NativeClient.autd3_device_status_num_devices(status);
|
|
292
|
-
var devices = new List<DeviceState>(count);
|
|
293
|
-
for (var i = 0; i < count; i++)
|
|
294
|
-
{
|
|
295
|
-
if (!NativeClient.autd3_device_status_device_state(status, (UIntPtr)i, out var kind))
|
|
296
|
-
{
|
|
297
|
-
throw new Autd3Exception("failed to read device state");
|
|
298
|
-
}
|
|
299
|
-
devices.Add(DeviceState.FromNative(kind));
|
|
300
|
-
}
|
|
301
|
-
return new DeviceStatus(devices);
|
|
302
|
-
}
|
|
303
|
-
finally
|
|
304
|
-
{
|
|
305
|
-
NativeClient.autd3_device_status_free(status);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
215
|
+
public static bool operator ==(DeviceStatus left, DeviceStatus right) => left.Equals(right);
|
|
308
216
|
|
|
309
|
-
public
|
|
217
|
+
public static bool operator !=(DeviceStatus left, DeviceStatus right) => !left.Equals(right);
|
|
310
218
|
}
|
|
311
219
|
|
|
312
220
|
public sealed class Response
|
|
313
221
|
{
|
|
314
|
-
private readonly byte[]
|
|
315
|
-
private readonly byte[][]
|
|
222
|
+
private readonly byte[] _errorCodes;
|
|
223
|
+
private readonly byte[][] _replyData;
|
|
316
224
|
|
|
317
|
-
internal Response(byte[]
|
|
225
|
+
internal Response(byte[] errorCodes, byte[][] replyData)
|
|
318
226
|
{
|
|
319
|
-
|
|
320
|
-
|
|
227
|
+
_errorCodes = errorCodes;
|
|
228
|
+
_replyData = replyData;
|
|
321
229
|
}
|
|
322
230
|
|
|
323
231
|
internal static Response FromNative(IntPtr handle)
|
|
@@ -325,22 +233,22 @@ namespace AUTD3
|
|
|
325
233
|
try
|
|
326
234
|
{
|
|
327
235
|
var count = (int)NativeClient.autd3_response_num_devices(handle);
|
|
328
|
-
var
|
|
236
|
+
var errorCodes = new byte[count];
|
|
329
237
|
if (count > 0)
|
|
330
238
|
{
|
|
331
|
-
Marshal.Copy(NativeClient.
|
|
239
|
+
Marshal.Copy(NativeClient.autd3_response_error_codes(handle), errorCodes, 0, count);
|
|
332
240
|
}
|
|
333
|
-
var
|
|
241
|
+
var replyData = new byte[count][];
|
|
334
242
|
for (var i = 0; i < count; i++)
|
|
335
243
|
{
|
|
336
|
-
var len = (int)NativeClient.
|
|
337
|
-
|
|
244
|
+
var len = (int)NativeClient.autd3_response_reply_data_of_len(handle, (UIntPtr)i);
|
|
245
|
+
replyData[i] = new byte[len];
|
|
338
246
|
if (len > 0)
|
|
339
247
|
{
|
|
340
|
-
Marshal.Copy(NativeClient.
|
|
248
|
+
Marshal.Copy(NativeClient.autd3_response_reply_data_of(handle, (UIntPtr)i), replyData[i], 0, len);
|
|
341
249
|
}
|
|
342
250
|
}
|
|
343
|
-
return new Response(
|
|
251
|
+
return new Response(errorCodes, replyData);
|
|
344
252
|
}
|
|
345
253
|
finally
|
|
346
254
|
{
|
|
@@ -348,17 +256,17 @@ namespace AUTD3
|
|
|
348
256
|
}
|
|
349
257
|
}
|
|
350
258
|
|
|
351
|
-
public IReadOnlyList<byte>
|
|
259
|
+
public IReadOnlyList<byte> ErrorCodes => _errorCodes;
|
|
352
260
|
|
|
353
|
-
public IReadOnlyList<IReadOnlyList<byte>>
|
|
261
|
+
public IReadOnlyList<IReadOnlyList<byte>> ReplyData => _replyData;
|
|
354
262
|
|
|
355
|
-
public IReadOnlyList<byte>
|
|
356
|
-
device >= 0 && device <
|
|
263
|
+
public IReadOnlyList<byte> ReplyDataOf(int device) =>
|
|
264
|
+
device >= 0 && device < _replyData.Length ? _replyData[device] : Array.Empty<byte>();
|
|
357
265
|
|
|
358
266
|
public void Check()
|
|
359
267
|
{
|
|
360
268
|
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
361
|
-
var code = NativeClient.autd3_response_check(
|
|
269
|
+
var code = NativeClient.autd3_response_check(_errorCodes, (UIntPtr)_errorCodes.Length, err, (UIntPtr)err.Length);
|
|
362
270
|
if (code != 0)
|
|
363
271
|
{
|
|
364
272
|
throw Autd3Exception.FromNative(code, err);
|
|
@@ -408,57 +316,11 @@ namespace AUTD3
|
|
|
408
316
|
~ResponseFuture() => Release();
|
|
409
317
|
}
|
|
410
318
|
|
|
411
|
-
public sealed class
|
|
412
|
-
{
|
|
413
|
-
private IntPtr _handle;
|
|
414
|
-
|
|
415
|
-
internal StreamFuture(IntPtr handle)
|
|
416
|
-
{
|
|
417
|
-
_handle = handle;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
public async Task AwaitAsync()
|
|
421
|
-
{
|
|
422
|
-
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
423
|
-
if (handle == IntPtr.Zero)
|
|
424
|
-
{
|
|
425
|
-
throw new Autd3Exception("StreamFuture has already been awaited");
|
|
426
|
-
}
|
|
427
|
-
GC.SuppressFinalize(this);
|
|
428
|
-
await AsyncOps.InvokeAsync((cb, ud) =>
|
|
429
|
-
NativeClient.autd3_stream_token_await(handle, cb, ud)).ConfigureAwait(false);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
public TaskAwaiter GetAwaiter() => AwaitAsync().GetAwaiter();
|
|
433
|
-
|
|
434
|
-
private void Release()
|
|
435
|
-
{
|
|
436
|
-
var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
|
|
437
|
-
if (handle != IntPtr.Zero)
|
|
438
|
-
{
|
|
439
|
-
NativeClient.autd3_stream_token_free(handle);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
public void Dispose()
|
|
444
|
-
{
|
|
445
|
-
Release();
|
|
446
|
-
GC.SuppressFinalize(this);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
~StreamFuture() => Release();
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
public sealed class Client : IDisposable, IAsyncDisposable
|
|
319
|
+
public sealed class Client : IDisposable
|
|
453
320
|
{
|
|
454
|
-
public static readonly int MaxInflight = Params.MaxInflight;
|
|
455
|
-
|
|
456
|
-
public static readonly int MaxDevices = (int)NativeClient.autd3_params_max_devices();
|
|
457
|
-
|
|
458
|
-
private const long AllFrames = -1;
|
|
459
|
-
|
|
460
321
|
private readonly ClientHandle _handle;
|
|
461
322
|
private readonly Geometry _geometry;
|
|
323
|
+
private volatile bool _closed;
|
|
462
324
|
|
|
463
325
|
internal ClientHandle Handle => _handle;
|
|
464
326
|
|
|
@@ -468,71 +330,45 @@ namespace AUTD3
|
|
|
468
330
|
_geometry = geometry;
|
|
469
331
|
}
|
|
470
332
|
|
|
471
|
-
public static
|
|
333
|
+
public static Client Open(Geometry geometry, TransportOption option)
|
|
472
334
|
{
|
|
335
|
+
var native = option.ToNative();
|
|
473
336
|
var owned = geometry.Clone();
|
|
474
|
-
|
|
337
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
338
|
+
int code;
|
|
339
|
+
IntPtr value;
|
|
475
340
|
try
|
|
476
341
|
{
|
|
477
|
-
|
|
342
|
+
code = NativeClient.autd3_client_open(geometry.Handle, option.IfaceKind, option.IfaceValue, native, out value, err, (UIntPtr)err.Length);
|
|
478
343
|
}
|
|
479
344
|
catch
|
|
480
345
|
{
|
|
481
346
|
owned.Dispose();
|
|
482
347
|
throw;
|
|
483
348
|
}
|
|
484
|
-
|
|
485
|
-
Task<IntPtr> task;
|
|
486
|
-
try
|
|
487
|
-
{
|
|
488
|
-
var configHandle = config.CreateHandle();
|
|
489
|
-
try
|
|
490
|
-
{
|
|
491
|
-
task = AsyncOps.InvokeAsync((cb, ud) =>
|
|
492
|
-
NativeClient.autd3_client_open(geometry.Handle, optionHandle, configHandle, cb, ud));
|
|
493
|
-
}
|
|
494
|
-
finally
|
|
495
|
-
{
|
|
496
|
-
NativeClient.autd3_client_config_free(configHandle);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
catch
|
|
500
|
-
{
|
|
501
|
-
NativeClient.autd3_transport_option_free(optionHandle);
|
|
502
|
-
owned.Dispose();
|
|
503
|
-
throw;
|
|
504
|
-
}
|
|
505
|
-
IntPtr value;
|
|
506
|
-
try
|
|
507
|
-
{
|
|
508
|
-
value = await task.ConfigureAwait(false);
|
|
509
|
-
}
|
|
510
|
-
catch
|
|
349
|
+
if (code != 0)
|
|
511
350
|
{
|
|
512
351
|
owned.Dispose();
|
|
513
|
-
throw;
|
|
352
|
+
throw Autd3Exception.FromNative(code, err);
|
|
514
353
|
}
|
|
515
354
|
return new Client(value, owned);
|
|
516
355
|
}
|
|
517
356
|
|
|
518
|
-
public
|
|
357
|
+
public DeviceStatus[] DeviceStatus()
|
|
519
358
|
{
|
|
520
|
-
var
|
|
521
|
-
|
|
359
|
+
var native = new NativeClient.DeviceStatusNative[NumDevices];
|
|
360
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
361
|
+
var code = NativeClient.autd3_client_device_status(Handle, native, (UIntPtr)native.Length, err, (UIntPtr)err.Length);
|
|
362
|
+
if (code != 0)
|
|
522
363
|
{
|
|
523
|
-
throw
|
|
364
|
+
throw Autd3Exception.FromNative(code, err);
|
|
524
365
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
public BusStats BusStats()
|
|
529
|
-
{
|
|
530
|
-
var stats = NativeClient.autd3_client_bus_stats(Handle);
|
|
531
|
-
if (stats == IntPtr.Zero)
|
|
366
|
+
var status = new DeviceStatus[native.Length];
|
|
367
|
+
for (var i = 0; i < native.Length; i++)
|
|
532
368
|
{
|
|
533
|
-
|
|
369
|
+
status[i] = new DeviceStatus(native[i]);
|
|
534
370
|
}
|
|
535
|
-
return
|
|
371
|
+
return status;
|
|
536
372
|
}
|
|
537
373
|
|
|
538
374
|
public int NumDevices => (int)NativeClient.autd3_client_num_devices(Handle);
|
|
@@ -550,32 +386,41 @@ namespace AUTD3
|
|
|
550
386
|
return SysTime.FromNanos(ns);
|
|
551
387
|
}
|
|
552
388
|
|
|
553
|
-
public
|
|
389
|
+
public TimeSpan AckTimeout
|
|
554
390
|
{
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
391
|
+
get
|
|
392
|
+
{
|
|
393
|
+
OptionNative.Apply("ackTimeout", NativeClient.autd3_client_ack_timeout(Handle, out var ns));
|
|
394
|
+
return OptionNative.FromNanos(ns);
|
|
395
|
+
}
|
|
396
|
+
set => OptionNative.Apply("ackTimeout", NativeClient.autd3_client_set_ack_timeout(Handle, OptionNative.RequiredNanos("ackTimeout", value)));
|
|
558
397
|
}
|
|
559
398
|
|
|
560
|
-
public
|
|
399
|
+
public TimeSpan LostTimeout
|
|
561
400
|
{
|
|
562
|
-
|
|
563
|
-
{
|
|
564
|
-
throw new ArgumentNullException(nameof(command));
|
|
565
|
-
}
|
|
566
|
-
var op = Command.CreateOp(command, _geometry);
|
|
567
|
-
IntPtr stream;
|
|
568
|
-
try
|
|
401
|
+
get
|
|
569
402
|
{
|
|
570
|
-
|
|
571
|
-
|
|
403
|
+
OptionNative.Apply("lostTimeout", NativeClient.autd3_client_lost_timeout(Handle, out var ns));
|
|
404
|
+
return OptionNative.FromNanos(ns);
|
|
572
405
|
}
|
|
573
|
-
|
|
406
|
+
set => OptionNative.Apply("lostTimeout", NativeClient.autd3_client_set_lost_timeout(Handle, OptionNative.RequiredNanos("lostTimeout", value)));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public void SendHeartbeat()
|
|
410
|
+
{
|
|
411
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
412
|
+
var code = NativeClient.autd3_client_send_heartbeat(Handle, err, (UIntPtr)err.Length);
|
|
413
|
+
if (code != 0)
|
|
574
414
|
{
|
|
575
|
-
|
|
576
|
-
throw;
|
|
415
|
+
throw Autd3Exception.FromNative(code, err);
|
|
577
416
|
}
|
|
578
|
-
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
public async Task SendAsync(ICommand command)
|
|
420
|
+
{
|
|
421
|
+
using var frames = Frames.Encode(_geometry, command);
|
|
422
|
+
await AsyncOps.InvokeAsync((cb, ud) =>
|
|
423
|
+
NativeClient.autd3_client_send_checked(Handle, frames.Handle, cb, ud)).ConfigureAwait(false);
|
|
579
424
|
}
|
|
580
425
|
|
|
581
426
|
public async Task<ResponseFuture> SendFrameAsync(Frame frame)
|
|
@@ -585,6 +430,14 @@ namespace AUTD3
|
|
|
585
430
|
return new ResponseFuture(token);
|
|
586
431
|
}
|
|
587
432
|
|
|
433
|
+
public async Task<ResponseFuture> SendFrameAsync(Frame frame, ExecAt execAt)
|
|
434
|
+
{
|
|
435
|
+
var exec = execAt.ToNative();
|
|
436
|
+
var token = await AsyncOps.InvokeAsync((cb, ud) =>
|
|
437
|
+
NativeClient.autd3_client_send_at(Handle, frame.Frames.Handle, frame.Index, exec, cb, ud)).ConfigureAwait(false);
|
|
438
|
+
return new ResponseFuture(token);
|
|
439
|
+
}
|
|
440
|
+
|
|
588
441
|
public async Task<IReadOnlyList<FirmwareVersion>> ReadFirmwareVersionAsync()
|
|
589
442
|
{
|
|
590
443
|
var array = await AsyncOps.InvokeAsync((cb, ud) =>
|
|
@@ -664,30 +517,24 @@ namespace AUTD3
|
|
|
664
517
|
}
|
|
665
518
|
}
|
|
666
519
|
|
|
667
|
-
public
|
|
668
|
-
AsyncOps.InvokeAsync((cb, ud) => NativeClient.autd3_client_silent_stop(Handle, cb, ud));
|
|
669
|
-
|
|
670
|
-
public Task CloseAsync() =>
|
|
671
|
-
AsyncOps.InvokeAsync((cb, ud) => NativeClient.autd3_client_close(Handle, cb, ud));
|
|
672
|
-
|
|
673
|
-
public void Dispose()
|
|
520
|
+
public void Close()
|
|
674
521
|
{
|
|
675
|
-
if (_handle.IsClosed)
|
|
676
|
-
{
|
|
677
|
-
return;
|
|
678
|
-
}
|
|
679
522
|
try
|
|
680
523
|
{
|
|
681
|
-
|
|
524
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
525
|
+
var code = NativeClient.autd3_client_close(Handle, err, (UIntPtr)err.Length);
|
|
526
|
+
if (code != 0)
|
|
527
|
+
{
|
|
528
|
+
throw Autd3Exception.FromNative(code, err);
|
|
529
|
+
}
|
|
682
530
|
}
|
|
683
531
|
finally
|
|
684
532
|
{
|
|
685
|
-
|
|
686
|
-
_geometry.Dispose();
|
|
533
|
+
_closed = true;
|
|
687
534
|
}
|
|
688
535
|
}
|
|
689
536
|
|
|
690
|
-
public
|
|
537
|
+
public void Dispose()
|
|
691
538
|
{
|
|
692
539
|
if (_handle.IsClosed)
|
|
693
540
|
{
|
|
@@ -695,7 +542,13 @@ namespace AUTD3
|
|
|
695
542
|
}
|
|
696
543
|
try
|
|
697
544
|
{
|
|
698
|
-
|
|
545
|
+
if (!_closed)
|
|
546
|
+
{
|
|
547
|
+
Close();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
catch (Autd3Exception)
|
|
551
|
+
{
|
|
699
552
|
}
|
|
700
553
|
finally
|
|
701
554
|
{
|