Skip to content

Commit fb78bd2

Browse files
authored
chore: Updated to new 2.0 API (#763)
1 parent 507b54f commit fb78bd2

File tree

4 files changed

+130
-125
lines changed

4 files changed

+130
-125
lines changed

Assets/Scripts/EphysLink/CommunicationManager.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Globalization;
33
using System.IO;
44
using System.Linq;
5+
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
56
using BestHTTP.SocketIO3;
67
using UnityEngine;
78

@@ -351,30 +352,33 @@ private async Awaitable<string> GetVersion()
351352
}
352353

353354
/// <summary>
354-
/// Get the platform type.
355+
/// Get the platform info.
355356
/// </summary>
356-
/// <param name="onSuccessCallback">Callback function to handle incoming platform type info.</param>
357+
/// <param name="onSuccessCallback">Callback function to handle incoming platform info.</param>
357358
/// <param name="onErrorCallback">Callback function to handle errors.</param>
358-
public void GetPlatformType(Action<string> onSuccessCallback, Action onErrorCallback = null)
359+
public void GetPlatformInfo(Action<PlatformInfo> onSuccessCallback, Action onErrorCallback = null)
359360
{
360361
_connectionManager
361362
.Socket.ExpectAcknowledgement<string>(data =>
362363
{
363364
if (DataKnownAndNotEmpty(data))
364-
onSuccessCallback?.Invoke(data);
365+
{
366+
var parsedData = ParseJson<PlatformInfo>(data);
367+
onSuccessCallback?.Invoke(parsedData);
368+
}
365369
else
366370
onErrorCallback?.Invoke();
367371
})
368-
.Emit("get_platform_type");
372+
.Emit("get_platform_info");
369373
}
370374

371375
/// <summary>
372-
/// Get the platform type.
376+
/// Get the platform info.
373377
/// </summary>
374-
/// <returns>Platform type.</returns>
375-
public async Awaitable<string> GetPlatformType()
378+
/// <returns>Platform info.</returns>
379+
public async Awaitable<PlatformInfo> GetPlatformInfo()
376380
{
377-
return await EmitAndGetStringResponse<object>("get_platform_type", null);
381+
return await EmitAndGetResponse<PlatformInfo, object>("get_platform_info", null);
378382
}
379383

380384
/// <summary>
@@ -867,4 +871,4 @@ private static string ToJson<T>(T data)
867871

868872
#endregion
869873
}
870-
}
874+
}

Assets/Scripts/EphysLink/EphysLinkModels.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using UnityEngine;
21
using System;
2+
using UnityEngine;
33

44
[Serializable]
55
public struct AngularResponse
@@ -39,7 +39,16 @@ public struct EphysLinkOptions
3939
public int MpmPort;
4040
public string Serial;
4141

42-
public EphysLinkOptions(bool background, bool ignoreUpdates, string type, bool debug, bool useProxy, string proxyAddress, int mpmPort, string serial)
42+
public EphysLinkOptions(
43+
bool background,
44+
bool ignoreUpdates,
45+
string type,
46+
bool debug,
47+
bool useProxy,
48+
string proxyAddress,
49+
int mpmPort,
50+
string serial
51+
)
4352
{
4453
Background = background;
4554
IgnoreUpdates = ignoreUpdates;
@@ -52,24 +61,35 @@ public EphysLinkOptions(bool background, bool ignoreUpdates, string type, bool d
5261
}
5362
}
5463

55-
5664
[Serializable]
5765
public struct GetManipulatorsResponse
5866
{
5967
public string[] Manipulators;
60-
public int NumAxes;
61-
public Vector4 Dimensions;
6268
public string Error;
6369

64-
public GetManipulatorsResponse(string[] manipulators, int numAxes, Vector4 dimensions, string error)
70+
public GetManipulatorsResponse(string[] manipulators, string error)
6571
{
6672
Manipulators = manipulators;
67-
NumAxes = numAxes;
68-
Dimensions = dimensions;
6973
Error = error;
7074
}
7175
}
7276

77+
[Serializable]
78+
public struct PlatformInfo
79+
{
80+
public string Name;
81+
public string CliName;
82+
public int AxesCount;
83+
public Vector4 Dimensions;
84+
85+
public PlatformInfo(string name, string cliName, int axesCount, Vector4 dimensions)
86+
{
87+
Name = name;
88+
CliName = cliName;
89+
AxesCount = axesCount;
90+
Dimensions = dimensions;
91+
}
92+
}
7393

7494
[Serializable]
7595
public struct PositionalResponse
@@ -125,7 +145,6 @@ public SetInsideBrainRequest(string manipulatorId, bool inside)
125145
}
126146
}
127147

128-
129148
[Serializable]
130149
public struct SetPositionRequest
131150
{
@@ -152,5 +171,4 @@ public ShankCountResponse(int shankCount, string error)
152171
ShankCount = shankCount;
153172
Error = error;
154173
}
155-
}
156-
174+
}

Assets/Scripts/Pinpoint/Probes/ManipulatorBehaviorController/ManipulatorBehaviorController.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,13 @@ private void OnDisable()
141141
/// <param name="calibrated">Whether this manipulator has been calibrated.</param>
142142
public async void Initialize(string manipulatorID, bool calibrated)
143143
{
144-
// Get manipulator information
145-
var manipulatorResponse = await CommunicationManager.Instance.GetManipulators();
146-
if (CommunicationManager.HasError(manipulatorResponse.Error))
147-
return;
148-
149-
// Shortcut exit if we have an invalid manipulator ID
150-
if (!manipulatorResponse.Manipulators.Contains(manipulatorID))
151-
return;
144+
// Get platform information
145+
var platformInfoResponse = await CommunicationManager.Instance.GetPlatformInfo();
152146

153147
// Set manipulator ID, number of axes, and dimensions
154148
ManipulatorID = manipulatorID;
155-
NumAxes = manipulatorResponse.NumAxes;
156-
Dimensions = manipulatorResponse.Dimensions;
149+
NumAxes = platformInfoResponse.AxesCount;
150+
Dimensions = platformInfoResponse.Dimensions;
157151

158152
// Update transform and space
159153
UpdateSpaceAndTransform();

0 commit comments

Comments
 (0)