com.shinolab.autd3-sdk.core 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/Config.cs CHANGED
@@ -76,5 +76,6 @@ namespace AUTD3
76
76
  DispatchError = 0x03,
77
77
  Processed = 0x04,
78
78
  Failsafe = 0x05,
79
+ SyncResync = 0x06,
79
80
  }
80
81
  }
package/Geometry.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.Numerics;
@@ -7,7 +8,9 @@ namespace AUTD3
7
8
  {
8
9
  public sealed class Geometry : IDisposable, IEnumerable<Device>
9
10
  {
10
- internal IntPtr Handle { get; private set; }
11
+ private IntPtr _handle;
12
+
13
+ internal IntPtr Handle => _handle;
11
14
 
12
15
  public Geometry(IReadOnlyList<Autd3> devices)
13
16
  {
@@ -21,7 +24,7 @@ namespace AUTD3
21
24
  {
22
25
  throw new Autd3Exception("failed to create geometry");
23
26
  }
24
- Handle = handle;
27
+ _handle = handle;
25
28
  }
26
29
 
27
30
  public int NumDevices => (int)NativeCore.autd3_core_geometry_num_devices(Handle);
@@ -55,19 +58,20 @@ namespace AUTD3
55
58
 
56
59
  public void Dispose()
57
60
  {
58
- if (Handle != IntPtr.Zero)
61
+ var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
62
+ if (handle != IntPtr.Zero)
59
63
  {
60
- NativeCore.autd3_core_geometry_free(Handle);
61
- Handle = IntPtr.Zero;
64
+ NativeCore.autd3_core_geometry_free(handle);
62
65
  }
63
66
  GC.SuppressFinalize(this);
64
67
  }
65
68
 
66
69
  ~Geometry()
67
70
  {
68
- if (Handle != IntPtr.Zero)
71
+ var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
72
+ if (handle != IntPtr.Zero)
69
73
  {
70
- NativeCore.autd3_core_geometry_free(Handle);
74
+ NativeCore.autd3_core_geometry_free(handle);
71
75
  }
72
76
  }
73
77
  }
package/Native.cs CHANGED
@@ -8,6 +8,11 @@ namespace AUTD3
8
8
  {
9
9
  private const string Lib = "autd3_core";
10
10
 
11
+ static NativeCore() => NativeAbi.Verify(Lib, autd3_abi_version());
12
+
13
+ [DllImport(Lib)]
14
+ private static extern uint autd3_abi_version();
15
+
11
16
  [StructLayout(LayoutKind.Sequential)]
12
17
  internal struct Autd3Device
13
18
  {
@@ -88,6 +93,91 @@ namespace AUTD3
88
93
  internal static extern void autd3_core_sampling_config_free(IntPtr config);
89
94
  }
90
95
 
96
+ internal static class NativeAbi
97
+ {
98
+ internal const ushort Major = 1;
99
+ internal const ushort Minor = 0;
100
+
101
+ internal const int ErrorBufferLength = 1024;
102
+
103
+ internal static void Verify(string library, uint actual)
104
+ {
105
+ var expected = ((uint)Major << 16) | Minor;
106
+ if (actual == expected)
107
+ {
108
+ return;
109
+ }
110
+ throw new Autd3Exception(
111
+ $"native library '{library}' reports C ABI version {actual >> 16}.{actual & 0xFFFF}, " +
112
+ $"but this binding requires {Major}.{Minor}. " +
113
+ "The managed package and the native library are from different releases.");
114
+ }
115
+ }
116
+
117
+ internal static class LinkOptionNative
118
+ {
119
+ internal delegate int SetDurationFn(IntPtr option, ulong ns);
120
+
121
+ internal delegate int GetDurationFn(IntPtr option, out ulong ns);
122
+
123
+ internal delegate int SetOptionalDurationFn(IntPtr option, [MarshalAs(UnmanagedType.I1)] bool hasValue, ulong ns);
124
+
125
+ internal delegate int GetOptionalDurationFn(IntPtr option, [MarshalAs(UnmanagedType.I1)] out bool hasValue, out ulong ns);
126
+
127
+ internal delegate IntPtr OpenFn(IntPtr option, byte[] outErr, UIntPtr outErrLen);
128
+
129
+ internal static void Apply(string field, int code)
130
+ {
131
+ if (code != 0)
132
+ {
133
+ throw new Autd3Exception($"`{field}` is out of the range the native library accepts");
134
+ }
135
+ }
136
+
137
+ internal static void SetDuration(IntPtr option, string field, TimeSpan? value, SetDurationFn set)
138
+ {
139
+ if (value is { } v)
140
+ {
141
+ Apply(field, set(option, ToNanos(v)));
142
+ }
143
+ }
144
+
145
+ internal static void SetOptionalDuration(IntPtr option, string field, TimeSpan? value, SetOptionalDurationFn set)
146
+ {
147
+ Apply(field, set(option, value.HasValue, value.HasValue ? ToNanos(value.Value) : 0UL));
148
+ }
149
+
150
+ internal static TimeSpan GetDuration(IntPtr option, GetDurationFn get)
151
+ {
152
+ Apply("preset", get(option, out var ns));
153
+ return FromNanos(ns);
154
+ }
155
+
156
+ internal static TimeSpan? GetOptionalDuration(IntPtr option, GetOptionalDurationFn get)
157
+ {
158
+ Apply("preset", get(option, out var hasValue, out var ns));
159
+ return hasValue ? FromNanos(ns) : (TimeSpan?)null;
160
+ }
161
+
162
+ internal static IntPtr TakeOpener(string link, IntPtr option, OpenFn open)
163
+ {
164
+ var err = new byte[NativeAbi.ErrorBufferLength];
165
+ var opener = open(option, err, (UIntPtr)err.Length);
166
+ if (opener == IntPtr.Zero)
167
+ {
168
+ var reason = NativeUtil.Utf8(err);
169
+ throw new Autd3Exception(reason.Length == 0
170
+ ? $"failed to create {link} link"
171
+ : $"failed to create {link} link: {reason}");
172
+ }
173
+ return opener;
174
+ }
175
+
176
+ internal static ulong ToNanos(TimeSpan value) => (ulong)value.Ticks * 100UL;
177
+
178
+ internal static TimeSpan FromNanos(ulong ns) => TimeSpan.FromTicks((long)(ns / 100));
179
+ }
180
+
91
181
  internal static class NativeUtil
92
182
  {
93
183
  internal static string Utf8(byte[] buffer)
Binary file
Binary file
@@ -854,10 +854,40 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
854
854
 
855
855
  Used by:
856
856
 
857
- - autd3-ffi-abi 0.5.0 — https://github.com/shinolab/autd3-sdk
858
- - autd3-ffi-core 0.5.0 — https://github.com/shinolab/autd3-sdk
859
- - autd3-rs-core 0.5.0 — https://github.com/shinolab/autd3-sdk
860
- - autd3-cpu-wire 0.4.0 — https://github.com/shinolab/autd3-sdk
857
+ - autd3-rs-core 0.6.0 — https://github.com/shinolab/autd3-sdk
858
+ - autd3-cpu-wire 0.6.0 — https://github.com/shinolab/autd3-sdk
859
+
860
+ ```
861
+ MIT License
862
+
863
+ Copyright (c) 2026 Shun Suzuki
864
+
865
+ Permission is hereby granted, free of charge, to any person obtaining a copy
866
+ of this software and associated documentation files (the "Software"), to deal
867
+ in the Software without restriction, including without limitation the rights
868
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
869
+ copies of the Software, and to permit persons to whom the Software is
870
+ furnished to do so, subject to the following conditions:
871
+
872
+ The above copyright notice and this permission notice shall be included in all
873
+ copies or substantial portions of the Software.
874
+
875
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
876
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
877
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
878
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
879
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
880
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
881
+ SOFTWARE.
882
+
883
+ ```
884
+
885
+ ## MIT License
886
+
887
+ Used by:
888
+
889
+ - autd3-ffi-abi 0.6.0 — https://github.com/shinolab/autd3-sdk
890
+ - autd3-ffi-core 0.6.0 — https://github.com/shinolab/autd3-sdk
861
891
  - chrono 0.4.45 — https://github.com/chronotope/chrono
862
892
  - wide 1.5.0 — https://github.com/Lokathor/wide
863
893
  - 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.core"
7
7
  },
8
- "version": "0.5.0",
8
+ "version": "0.6.0",
9
9
  "displayName": "AUTD3 Core",
10
10
  "description": "AUTD3 core types, geometry and units (Unity binding).",
11
11
  "unity": "6000.0",