com.shinolab.autd3-sdk.core 0.9.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/AssemblyInfo.cs +0 -4
- package/Command.cs +1 -1
- package/Config.cs +59 -34
- package/Coords.cs +4 -0
- package/Geometry.cs +50 -25
- package/IsExternalInit.cs +6 -0
- package/IsExternalInit.cs.meta +11 -0
- package/Native.cs +68 -65
- package/Plugins/linux-x64/libautd3_core.so +0 -0
- package/Plugins/osx-arm64/libautd3_core.dylib +0 -0
- package/Plugins/win-x64/autd3_core.dll +0 -0
- package/SamplingConfig.cs +39 -91
- package/THIRD-PARTY-LICENSES.md +58 -244
- package/Types.cs +164 -110
- package/Units.cs +105 -61
- package/package.json +1 -1
package/AssemblyInfo.cs
CHANGED
|
@@ -4,8 +4,4 @@ using System.Runtime.CompilerServices;
|
|
|
4
4
|
[assembly: InternalsVisibleTo("AUTD3.Pattern")]
|
|
5
5
|
[assembly: InternalsVisibleTo("AUTD3.Pattern.Holo")]
|
|
6
6
|
[assembly: InternalsVisibleTo("AUTD3.Modulation")]
|
|
7
|
-
[assembly: InternalsVisibleTo("AUTD3.Link.Echocat")]
|
|
8
|
-
[assembly: InternalsVisibleTo("AUTD3.Link.Remote")]
|
|
9
|
-
[assembly: InternalsVisibleTo("AUTD3.Link.TwinCAT")]
|
|
10
|
-
[assembly: InternalsVisibleTo("AUTD3.Link.Nop")]
|
|
11
7
|
[assembly: InternalsVisibleTo("AUTD3.Tests")]
|
package/Command.cs
CHANGED
package/Config.cs
CHANGED
|
@@ -10,72 +10,97 @@ namespace AUTD3
|
|
|
10
10
|
I3 = 3,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
public readonly struct LoopBehavior
|
|
13
|
+
public readonly struct LoopBehavior : IEquatable<LoopBehavior>
|
|
14
14
|
{
|
|
15
|
-
|
|
15
|
+
private readonly ushort _count;
|
|
16
16
|
|
|
17
|
-
private LoopBehavior(ushort
|
|
17
|
+
private LoopBehavior(ushort count)
|
|
18
18
|
{
|
|
19
|
-
|
|
19
|
+
_count = count;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
public
|
|
22
|
+
public ushort Rep => _count == 0 ? (ushort)0xFFFF : (ushort)(_count - 1);
|
|
23
23
|
|
|
24
|
-
public static LoopBehavior
|
|
24
|
+
public static LoopBehavior Infinite => default;
|
|
25
|
+
|
|
26
|
+
public static LoopBehavior Once => new LoopBehavior(1);
|
|
25
27
|
|
|
26
28
|
public static LoopBehavior Finite(ushort count)
|
|
27
29
|
{
|
|
28
30
|
if (count == 0)
|
|
29
31
|
{
|
|
30
|
-
throw new Autd3Exception("loop count must be >= 1");
|
|
32
|
+
throw new Autd3Exception("loop count must be >= 1", Autd3ErrorCode.InvalidArgument);
|
|
31
33
|
}
|
|
32
|
-
return new LoopBehavior(
|
|
34
|
+
return new LoopBehavior(count);
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
public bool Equals(LoopBehavior other) => _count == other._count;
|
|
38
|
+
|
|
39
|
+
public override bool Equals(object? obj) => obj is LoopBehavior other && Equals(other);
|
|
40
|
+
|
|
41
|
+
public override int GetHashCode() => _count;
|
|
42
|
+
|
|
43
|
+
public static bool operator ==(LoopBehavior left, LoopBehavior right) => left.Equals(right);
|
|
44
|
+
|
|
45
|
+
public static bool operator !=(LoopBehavior left, LoopBehavior right) => !left.Equals(right);
|
|
34
46
|
}
|
|
35
47
|
|
|
36
|
-
public readonly struct TransitionMode
|
|
48
|
+
public readonly struct TransitionMode : IEquatable<TransitionMode>
|
|
37
49
|
{
|
|
38
|
-
|
|
50
|
+
private const byte ImmediateMode = 0xFF;
|
|
51
|
+
|
|
52
|
+
private readonly byte _modeFromImmediate;
|
|
53
|
+
|
|
54
|
+
internal byte Mode => (byte)(_modeFromImmediate ^ ImmediateMode);
|
|
39
55
|
internal ulong Value { get; }
|
|
40
|
-
internal uint MarginNs { get; }
|
|
41
56
|
|
|
42
|
-
private TransitionMode(byte mode, ulong value
|
|
57
|
+
private TransitionMode(byte mode, ulong value)
|
|
43
58
|
{
|
|
44
|
-
|
|
59
|
+
_modeFromImmediate = (byte)(mode ^ ImmediateMode);
|
|
45
60
|
Value = value;
|
|
46
|
-
MarginNs = marginNs;
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
public static TransitionMode SyncIdx => new TransitionMode(0x00, 0);
|
|
50
64
|
|
|
51
|
-
public static TransitionMode SysTime(
|
|
52
|
-
{
|
|
53
|
-
if (margin is not { } m) return new TransitionMode(0x01, sysTime.SysTime);
|
|
54
|
-
var nanos = (double)m.Ticks * 100.0;
|
|
55
|
-
if (nanos < 0.0 || nanos > uint.MaxValue)
|
|
56
|
-
{
|
|
57
|
-
throw new Autd3Exception("transition margin is out of range (0..=4294967295 ns)");
|
|
58
|
-
}
|
|
59
|
-
return new TransitionMode(0x01, sysTime.SysTime, (uint)nanos);
|
|
60
|
-
}
|
|
65
|
+
public static TransitionMode SysTime(SysTime sysTime) => new TransitionMode(0x01, sysTime.Nanos);
|
|
61
66
|
|
|
62
67
|
public static TransitionMode Gpio(GpioIn gpio) => new TransitionMode(0x02, (byte)gpio);
|
|
63
68
|
|
|
64
69
|
public static TransitionMode Ext => new TransitionMode(0xF0, 0);
|
|
65
70
|
|
|
66
|
-
public static TransitionMode
|
|
71
|
+
public static TransitionMode Immediate => new TransitionMode(ImmediateMode, 0);
|
|
72
|
+
|
|
73
|
+
public bool Equals(TransitionMode other) => _modeFromImmediate == other._modeFromImmediate && Value == other.Value;
|
|
74
|
+
|
|
75
|
+
public override bool Equals(object? obj) => obj is TransitionMode other && Equals(other);
|
|
67
76
|
|
|
68
|
-
public
|
|
77
|
+
public override int GetHashCode() => HashCode.Combine(_modeFromImmediate, Value);
|
|
78
|
+
|
|
79
|
+
public static bool operator ==(TransitionMode left, TransitionMode right) => left.Equals(right);
|
|
80
|
+
|
|
81
|
+
public static bool operator !=(TransitionMode left, TransitionMode right) => !left.Equals(right);
|
|
69
82
|
}
|
|
70
83
|
|
|
71
|
-
public enum
|
|
84
|
+
public enum FpgaBusWait : byte
|
|
72
85
|
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
Cycles3 = 0,
|
|
87
|
+
Cycles2 = 1,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
internal static class FpgaBusWaitNative
|
|
91
|
+
{
|
|
92
|
+
internal static byte ToCycles(FpgaBusWait wait) => wait switch
|
|
93
|
+
{
|
|
94
|
+
FpgaBusWait.Cycles2 => 2,
|
|
95
|
+
FpgaBusWait.Cycles3 => 3,
|
|
96
|
+
_ => 0,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
internal static FpgaBusWait FromCycles(byte cycles) => cycles switch
|
|
100
|
+
{
|
|
101
|
+
2 => FpgaBusWait.Cycles2,
|
|
102
|
+
3 => FpgaBusWait.Cycles3,
|
|
103
|
+
_ => throw new Autd3Exception($"unknown fpga bus wait {cycles}"),
|
|
104
|
+
};
|
|
80
105
|
}
|
|
81
106
|
}
|
package/Coords.cs
CHANGED
|
@@ -23,6 +23,8 @@ namespace AUTD3
|
|
|
23
23
|
internal static Quaternion FromRotation(SnQuaternion q) => new Quaternion(-q.X, -q.Y, q.Z, q.W);
|
|
24
24
|
|
|
25
25
|
internal static Quaternion IdentityRotation => Quaternion.identity;
|
|
26
|
+
|
|
27
|
+
internal static Vector3 FromLengths(Length x, Length y, Length z) => new Vector3(x.M, y.M, z.M);
|
|
26
28
|
#else
|
|
27
29
|
internal static SnVector3 Point(Vector3 v) => v;
|
|
28
30
|
|
|
@@ -37,6 +39,8 @@ namespace AUTD3
|
|
|
37
39
|
internal static Quaternion FromRotation(SnQuaternion q) => q;
|
|
38
40
|
|
|
39
41
|
internal static Quaternion IdentityRotation => Quaternion.Identity;
|
|
42
|
+
|
|
43
|
+
internal static Vector3 FromLengths(Length x, Length y, Length z) => new Vector3(x.Mm, y.Mm, z.Mm);
|
|
40
44
|
#endif
|
|
41
45
|
|
|
42
46
|
internal static float[] PointArray(Vector3 v)
|
package/Geometry.cs
CHANGED
|
@@ -18,10 +18,11 @@ namespace AUTD3
|
|
|
18
18
|
{
|
|
19
19
|
native[i] = devices[i].ToNative();
|
|
20
20
|
}
|
|
21
|
-
var
|
|
21
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
22
|
+
var handle = NativeCore.autd3_core_geometry_new(native, (UIntPtr)native.Length, err, (UIntPtr)err.Length);
|
|
22
23
|
if (handle == IntPtr.Zero)
|
|
23
24
|
{
|
|
24
|
-
throw new Autd3Exception(
|
|
25
|
+
throw new Autd3Exception(NativeUtil.Utf8(err), Autd3ErrorCode.InvalidArgument);
|
|
25
26
|
}
|
|
26
27
|
_handle = new GeometryHandle(handle);
|
|
27
28
|
}
|
|
@@ -31,13 +32,23 @@ namespace AUTD3
|
|
|
31
32
|
_handle = handle;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
internal Geometry Clone()
|
|
36
|
+
{
|
|
37
|
+
var handle = NativeCore.autd3_core_geometry_clone(Handle);
|
|
38
|
+
if (handle == IntPtr.Zero)
|
|
39
|
+
{
|
|
40
|
+
throw new Autd3Exception("failed to clone geometry");
|
|
41
|
+
}
|
|
42
|
+
return new Geometry(new GeometryHandle(handle));
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
public static Geometry FromJson(string json)
|
|
35
46
|
{
|
|
36
47
|
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
37
48
|
var handle = NativeCore.autd3_core_geometry_from_json(json, err, (UIntPtr)err.Length);
|
|
38
49
|
if (handle == IntPtr.Zero)
|
|
39
50
|
{
|
|
40
|
-
throw new Autd3Exception(NativeUtil.Utf8(err));
|
|
51
|
+
throw new Autd3Exception(NativeUtil.Utf8(err), Autd3ErrorCode.InvalidArgument);
|
|
41
52
|
}
|
|
42
53
|
return new Geometry(new GeometryHandle(handle));
|
|
43
54
|
}
|
|
@@ -66,6 +77,17 @@ namespace AUTD3
|
|
|
66
77
|
|
|
67
78
|
public bool IsEmpty => NumDevices == 0;
|
|
68
79
|
|
|
80
|
+
public bool[][] OutputMaskBuffer()
|
|
81
|
+
{
|
|
82
|
+
var masks = new bool[NumDevices][];
|
|
83
|
+
for (var dev = 0; dev < masks.Length; dev++)
|
|
84
|
+
{
|
|
85
|
+
masks[dev] = new bool[this[dev].NumTransducers];
|
|
86
|
+
Array.Fill(masks[dev], true);
|
|
87
|
+
}
|
|
88
|
+
return masks;
|
|
89
|
+
}
|
|
90
|
+
|
|
69
91
|
public Vector3 Center
|
|
70
92
|
{
|
|
71
93
|
get
|
|
@@ -76,14 +98,24 @@ namespace AUTD3
|
|
|
76
98
|
}
|
|
77
99
|
}
|
|
78
100
|
|
|
79
|
-
public Device this[int dev]
|
|
101
|
+
public Device this[int dev]
|
|
102
|
+
{
|
|
103
|
+
get
|
|
104
|
+
{
|
|
105
|
+
if (dev < 0 || dev >= NumDevices)
|
|
106
|
+
{
|
|
107
|
+
throw new ArgumentOutOfRangeException(nameof(dev));
|
|
108
|
+
}
|
|
109
|
+
return new Device(Handle, (UIntPtr)dev);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
80
112
|
|
|
81
113
|
public IEnumerator<Device> GetEnumerator()
|
|
82
114
|
{
|
|
83
115
|
var count = NumDevices;
|
|
84
116
|
for (var i = 0; i < count; i++)
|
|
85
117
|
{
|
|
86
|
-
yield return
|
|
118
|
+
yield return new Device(Handle, (UIntPtr)i);
|
|
87
119
|
}
|
|
88
120
|
}
|
|
89
121
|
|
|
@@ -103,10 +135,6 @@ namespace AUTD3
|
|
|
103
135
|
_dev = dev;
|
|
104
136
|
}
|
|
105
137
|
|
|
106
|
-
internal GeometryHandle GeometryHandle => _geometry;
|
|
107
|
-
|
|
108
|
-
internal UIntPtr DeviceIndex => _dev;
|
|
109
|
-
|
|
110
138
|
public int Idx => (int)NativeCore.autd3_core_device_idx(_geometry, _dev);
|
|
111
139
|
|
|
112
140
|
public int NumTransducers => (int)NativeCore.autd3_core_device_num_transducers(_geometry, _dev);
|
|
@@ -147,36 +175,33 @@ namespace AUTD3
|
|
|
147
175
|
return Coords.FromPointArray(xyz);
|
|
148
176
|
}
|
|
149
177
|
|
|
150
|
-
public Vector3 Direction(int tr)
|
|
151
|
-
{
|
|
152
|
-
var xyz = new float[3];
|
|
153
|
-
if (NativeCore.autd3_core_transducer_direction(_geometry, _dev, (UIntPtr)tr, xyz) != 0)
|
|
154
|
-
throw new ArgumentOutOfRangeException(nameof(tr));
|
|
155
|
-
return Coords.FromDirArray(xyz);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
178
|
public Vector3[] Positions
|
|
159
179
|
{
|
|
160
180
|
get
|
|
161
181
|
{
|
|
162
182
|
var n = NumTransducers;
|
|
183
|
+
var flat = new float[n * 3];
|
|
184
|
+
if (NativeCore.autd3_core_device_positions(_geometry, _dev, flat, (UIntPtr)flat.Length) != 0)
|
|
185
|
+
{
|
|
186
|
+
throw new Autd3Exception("failed to read the transducer positions");
|
|
187
|
+
}
|
|
163
188
|
var result = new Vector3[n];
|
|
164
189
|
for (var i = 0; i < n; i++)
|
|
165
|
-
|
|
190
|
+
{
|
|
191
|
+
result[i] = Coords.FromPoint(new System.Numerics.Vector3(flat[i * 3], flat[i * 3 + 1], flat[i * 3 + 2]));
|
|
192
|
+
}
|
|
166
193
|
return result;
|
|
167
194
|
}
|
|
168
195
|
}
|
|
169
196
|
|
|
170
|
-
public Vector3
|
|
197
|
+
public Vector3 ToLocal(Vector3 point)
|
|
171
198
|
{
|
|
172
|
-
|
|
199
|
+
var xyz = new float[3];
|
|
200
|
+
if (NativeCore.autd3_core_device_to_local(_geometry, _dev, Coords.PointArray(point), xyz) != 0)
|
|
173
201
|
{
|
|
174
|
-
|
|
175
|
-
var result = new Vector3[n];
|
|
176
|
-
for (var i = 0; i < n; i++)
|
|
177
|
-
result[i] = Direction(i);
|
|
178
|
-
return result;
|
|
202
|
+
throw new Autd3Exception("failed to convert the point to the device frame");
|
|
179
203
|
}
|
|
204
|
+
return Coords.FromPointArray(xyz);
|
|
180
205
|
}
|
|
181
206
|
|
|
182
207
|
private Vector3 DeviceDirection(Action<GeometryHandle, UIntPtr, float[]> native)
|
package/Native.cs
CHANGED
|
@@ -21,7 +21,7 @@ namespace AUTD3
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
24
|
-
internal static extern IntPtr autd3_core_geometry_new(Autd3Device[] devices, UIntPtr len);
|
|
24
|
+
internal static extern IntPtr autd3_core_geometry_new(Autd3Device[] devices, UIntPtr len, byte[] outErr, UIntPtr outErrLen);
|
|
25
25
|
|
|
26
26
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
27
27
|
internal static extern IntPtr autd3_core_geometry_from_json([MarshalAs(UnmanagedType.LPUTF8Str)] string json, byte[] outErr, UIntPtr outErrLen);
|
|
@@ -66,46 +66,88 @@ namespace AUTD3
|
|
|
66
66
|
internal static extern int autd3_core_transducer_position(GeometryHandle geometry, UIntPtr dev, UIntPtr tr, [Out] float[] outXyz);
|
|
67
67
|
|
|
68
68
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
69
|
-
internal static extern
|
|
69
|
+
internal static extern IntPtr autd3_core_geometry_clone(GeometryHandle geometry);
|
|
70
70
|
|
|
71
71
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
72
72
|
internal static extern void autd3_core_geometry_free(IntPtr geometry);
|
|
73
73
|
|
|
74
74
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
75
|
-
internal static extern
|
|
75
|
+
internal static extern int autd3_core_device_positions(GeometryHandle geometry, UIntPtr dev, [Out] float[] dst, UIntPtr len);
|
|
76
76
|
|
|
77
77
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
78
|
-
internal static extern
|
|
78
|
+
internal static extern int autd3_core_device_to_local(GeometryHandle geometry, UIntPtr dev, float[] point, [Out] float[] outXyz);
|
|
79
79
|
|
|
80
80
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
81
|
-
internal static extern
|
|
81
|
+
internal static extern byte autd3_core_phase_from_rad(float radian);
|
|
82
82
|
|
|
83
83
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
84
|
-
internal static extern
|
|
84
|
+
internal static extern ulong autd3_core_params_ultrasound_period_ns();
|
|
85
85
|
|
|
86
86
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
87
|
-
internal static extern
|
|
87
|
+
internal static extern uint autd3_core_params_ultrasound_freq_hz();
|
|
88
88
|
|
|
89
89
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
90
|
-
internal static extern
|
|
90
|
+
internal static extern UIntPtr autd3_core_params_mod_buffer_samples();
|
|
91
91
|
|
|
92
92
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
93
|
-
internal static extern
|
|
93
|
+
internal static extern UIntPtr autd3_core_params_buffer_size_min();
|
|
94
94
|
|
|
95
95
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
96
|
-
internal static extern
|
|
96
|
+
internal static extern UIntPtr autd3_core_params_emission_max_indices();
|
|
97
97
|
|
|
98
98
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
99
|
-
internal static extern
|
|
99
|
+
internal static extern byte autd3_core_params_num_foci_max();
|
|
100
100
|
|
|
101
101
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
102
|
-
internal static extern
|
|
102
|
+
internal static extern ushort autd3_core_params_pulse_width_period();
|
|
103
|
+
|
|
104
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
105
|
+
internal static extern UIntPtr autd3_core_params_max_inflight();
|
|
106
|
+
|
|
107
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
108
|
+
internal static extern UIntPtr autd3_core_params_max_devices();
|
|
109
|
+
|
|
110
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
111
|
+
internal static extern ushort autd3_core_params_port();
|
|
112
|
+
|
|
113
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
114
|
+
internal static extern float autd3_core_params_rotation_norm_tolerance();
|
|
115
|
+
|
|
116
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
117
|
+
internal static extern UIntPtr autd3_core_params_num_transducers();
|
|
118
|
+
|
|
119
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
120
|
+
internal static extern uint autd3_core_params_grid_x();
|
|
121
|
+
|
|
122
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
123
|
+
internal static extern uint autd3_core_params_grid_y();
|
|
124
|
+
|
|
125
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
126
|
+
internal static extern float autd3_core_params_pitch_mm();
|
|
127
|
+
|
|
128
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
129
|
+
internal static extern float autd3_core_params_device_width_mm();
|
|
130
|
+
|
|
131
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
132
|
+
internal static extern float autd3_core_params_device_height_mm();
|
|
133
|
+
|
|
134
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
135
|
+
internal static extern ushort autd3_core_sampling_config_freq_4k();
|
|
136
|
+
|
|
137
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
138
|
+
internal static extern ushort autd3_core_sampling_config_freq_40k();
|
|
139
|
+
|
|
140
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
141
|
+
internal static extern int autd3_core_sampling_config_from_freq(float hz, out ushort @out, byte[] outErr, UIntPtr outErrLen);
|
|
142
|
+
|
|
143
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
144
|
+
internal static extern int autd3_core_sampling_config_from_period(ulong nanos, out ushort @out, byte[] outErr, UIntPtr outErrLen);
|
|
103
145
|
}
|
|
104
146
|
|
|
105
147
|
internal static class NativeAbi
|
|
106
148
|
{
|
|
107
149
|
internal const ushort Major = 0;
|
|
108
|
-
internal const ushort Minor =
|
|
150
|
+
internal const ushort Minor = 13;
|
|
109
151
|
internal const ushort Patch = 0;
|
|
110
152
|
|
|
111
153
|
internal const int ErrorBufferLength = 1024;
|
|
@@ -124,71 +166,32 @@ namespace AUTD3
|
|
|
124
166
|
}
|
|
125
167
|
}
|
|
126
168
|
|
|
127
|
-
internal static class
|
|
169
|
+
internal static class OptionNative
|
|
128
170
|
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
133
|
-
internal delegate int GetDurationFn(IntPtr option, out ulong ns);
|
|
134
|
-
|
|
135
|
-
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
136
|
-
internal delegate int SetOptionalDurationFn(IntPtr option, [MarshalAs(UnmanagedType.I1)] bool hasValue, ulong ns);
|
|
137
|
-
|
|
138
|
-
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
139
|
-
internal delegate int GetOptionalDurationFn(IntPtr option, [MarshalAs(UnmanagedType.I1)] out bool hasValue, out ulong ns);
|
|
140
|
-
|
|
141
|
-
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
142
|
-
internal delegate IntPtr OpenFn(IntPtr option, byte[] outErr, UIntPtr outErrLen);
|
|
171
|
+
internal static Autd3Exception OutOfRange(string field) =>
|
|
172
|
+
new Autd3Exception($"`{field}` is out of the range the native library accepts", Autd3ErrorCode.InvalidArgument);
|
|
143
173
|
|
|
144
174
|
internal static void Apply(string field, int code)
|
|
145
175
|
{
|
|
146
176
|
if (code != 0)
|
|
147
177
|
{
|
|
148
|
-
throw
|
|
178
|
+
throw OutOfRange(field);
|
|
149
179
|
}
|
|
150
180
|
}
|
|
151
181
|
|
|
152
|
-
internal static
|
|
153
|
-
|
|
154
|
-
if (value is { } v)
|
|
155
|
-
{
|
|
156
|
-
Apply(field, set(option, ToNanos(v)));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
182
|
+
internal static ulong RequiredNanos(string field, TimeSpan value) =>
|
|
183
|
+
value < TimeSpan.Zero ? throw OutOfRange(field) : ToNanos(value);
|
|
159
184
|
|
|
160
|
-
internal static
|
|
161
|
-
|
|
162
|
-
Apply(field, set(option, value.HasValue, value.HasValue ? ToNanos(value.Value) : 0UL));
|
|
163
|
-
}
|
|
185
|
+
internal static ulong OptionalNanos(string field, TimeSpan? value) =>
|
|
186
|
+
value is { } duration ? RequiredNanos(field, duration) : 0;
|
|
164
187
|
|
|
165
|
-
internal static TimeSpan
|
|
166
|
-
|
|
167
|
-
Apply("preset", get(option, out var ns));
|
|
168
|
-
return FromNanos(ns);
|
|
169
|
-
}
|
|
188
|
+
internal static TimeSpan? FromOptionalNanos(byte hasValue, ulong ns) =>
|
|
189
|
+
hasValue != 0 ? FromNanos(ns) : (TimeSpan?)null;
|
|
170
190
|
|
|
171
|
-
internal static
|
|
172
|
-
{
|
|
173
|
-
Apply("preset", get(option, out var hasValue, out var ns));
|
|
174
|
-
return hasValue ? FromNanos(ns) : (TimeSpan?)null;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
internal static IntPtr TakeOpener(string link, IntPtr option, OpenFn open)
|
|
178
|
-
{
|
|
179
|
-
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
180
|
-
var opener = open(option, err, (UIntPtr)err.Length);
|
|
181
|
-
if (opener == IntPtr.Zero)
|
|
182
|
-
{
|
|
183
|
-
var reason = NativeUtil.Utf8(err);
|
|
184
|
-
throw new Autd3Exception(reason.Length == 0
|
|
185
|
-
? $"failed to create {link} link"
|
|
186
|
-
: $"failed to create {link} link: {reason}");
|
|
187
|
-
}
|
|
188
|
-
return opener;
|
|
189
|
-
}
|
|
191
|
+
internal static byte Flag(bool value) => (byte)(value ? 1 : 0);
|
|
190
192
|
|
|
191
|
-
internal static ulong ToNanos(TimeSpan value) =>
|
|
193
|
+
internal static ulong ToNanos(TimeSpan value) =>
|
|
194
|
+
(ulong)value.Ticks > ulong.MaxValue / 100UL ? ulong.MaxValue : (ulong)value.Ticks * 100UL;
|
|
192
195
|
|
|
193
196
|
internal static TimeSpan FromNanos(ulong ns) => TimeSpan.FromTicks((long)(ns / 100));
|
|
194
197
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|