Skip to content

Commit 7346958

Browse files
authored
feat: 702 ephys link 2.0 support (#703)
* Remove Ephys Link for v2 * Switch to Ephys Link v2.0.0 * Ignore EphysLink from StreamingAssets * Let movement work * Copilot loop
1 parent b95dd9d commit 7346958

File tree

17 files changed

+1114
-1019
lines changed

17 files changed

+1114
-1019
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,4 @@ Library/com.unity.addressables/AddressablesBuildTEP.json
175175
Assets/AddressableAssetsData/link.xml
176176
Assets/AddressableAssetsData/link.xml.meta
177177

178-
Assets/StreamingAssets/EphysLink-v1.3.3
178+
Assets/StreamingAssets/EphysLink-*

Assets/Prefabs/UI/SettingsMenu/Menus/EphysLinkMenu.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6203,7 +6203,7 @@ PrefabInstance:
62036203
objectReference: {fileID: 0}
62046204
- target: {fileID: 5109513604156068580, guid: b5c9c741a0d4edd4c9948dba78e58d2b, type: 3}
62056205
propertyPath: m_Text
6206-
value: 8081
6206+
value: 3000
62076207
objectReference: {fileID: 0}
62086208
- target: {fileID: 5109513604156068580, guid: b5c9c741a0d4edd4c9948dba78e58d2b, type: 3}
62096209
propertyPath: m_ContentType

Assets/Scripts/EphysLink/CommunicationManager.cs

Lines changed: 35 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class CommunicationManager : MonoBehaviour
2020

2121
#region Properties
2222

23-
private static readonly int[] EPHYS_LINK_MIN_VERSION = { 1, 3, 0 };
23+
private static readonly int[] EPHYS_LINK_MIN_VERSION = { 2, 0, 0 };
2424

2525
public static readonly string EPHYS_LINK_MIN_VERSION_STRING =
2626
$"≥ v{string.Join(".", EPHYS_LINK_MIN_VERSION)}";
@@ -55,6 +55,7 @@ private void Awake()
5555
#endregion
5656

5757
#region Connection Handler
58+
5859
public void ServerSettingsLoaded()
5960
{
6061
// Automatically connect if the server credentials are possible
@@ -283,6 +284,7 @@ public void VerifyVersion(Action onSuccess, Action onFailure)
283284
.TakeWhile(numbers => numbers.Length > 0)
284285
.Select(nonEmpty => int.Parse(new string(nonEmpty)))
285286
.ToArray();
287+
print(versionNumbers[0]+"."+versionNumbers[1]+"."+versionNumbers[2]);
286288

287289
// Fail if major version mismatch (breaking changes).
288290
if (versionNumbers[0] != EPHYS_LINK_MIN_VERSION[0])
@@ -292,7 +294,7 @@ public void VerifyVersion(Action onSuccess, Action onFailure)
292294
}
293295

294296
// Fail if minor version is too small (missing features).
295-
if (versionNumbers[1] < EPHYS_LINK_MIN_VERSION[0])
297+
if (versionNumbers[1] < EPHYS_LINK_MIN_VERSION[1])
296298
{
297299
onFailure.Invoke();
298300
return;
@@ -337,6 +339,24 @@ private void GetVersion(Action<string> onSuccessCallback, Action onErrorCallback
337339
.Emit("get_version");
338340
}
339341

342+
/// <summary>
343+
/// Get the platform type.
344+
/// </summary>
345+
/// <param name="onSuccessCallback">Callback function to handle incoming platform type info.</param>
346+
/// <param name="onErrorCallback">Callback function to handle errors.</param>
347+
public void GetPlatformType(Action<string> onSuccessCallback, Action onErrorCallback = null)
348+
{
349+
_connectionManager
350+
.Socket.ExpectAcknowledgement<string>(data =>
351+
{
352+
if (DataKnownAndNotEmpty(data))
353+
onSuccessCallback?.Invoke(data);
354+
else
355+
onErrorCallback?.Invoke();
356+
})
357+
.Emit("get_platform_type");
358+
}
359+
340360
/// <summary>
341361
/// Get manipulators event sender.
342362
/// </summary>
@@ -368,60 +388,12 @@ public void GetManipulators(
368388
}
369389

370390
/// <summary>
371-
/// Register a manipulator with the server.
372-
/// </summary>
373-
/// <param name="manipulatorId">The ID of the manipulator to register</param>
374-
/// <param name="onSuccessCallback">Callback function to handle a successful registration</param>
375-
/// <param name="onErrorCallback">Callback function to handle errors</param>
376-
public void RegisterManipulator(
377-
string manipulatorId,
378-
Action onSuccessCallback = null,
379-
Action<string> onErrorCallback = null
380-
)
381-
{
382-
_connectionManager
383-
.Socket.ExpectAcknowledgement<string>(error =>
384-
{
385-
if (string.IsNullOrEmpty(error))
386-
onSuccessCallback?.Invoke();
387-
else
388-
onErrorCallback?.Invoke($"register_manipulators invalid response: {error}");
389-
})
390-
.Emit("register_manipulator", manipulatorId);
391-
}
392-
393-
/// <summary>
394-
/// Unregister a manipulator with the server.
395-
/// </summary>
396-
/// <param name="manipulatorId">The ID of the manipulator to unregister</param>
397-
/// <param name="onSuccessCallback">Callback function to handle a successful un-registration</param>
398-
/// <param name="onErrorCallback">Callback function to handle errors</param>
399-
public void UnregisterManipulator(
400-
string manipulatorId,
401-
Action onSuccessCallback = null,
402-
Action<string> onErrorCallback = null
403-
)
404-
{
405-
_connectionManager
406-
.Socket.ExpectAcknowledgement<string>(error =>
407-
{
408-
if (string.IsNullOrEmpty(error))
409-
onSuccessCallback?.Invoke();
410-
else
411-
onErrorCallback?.Invoke(
412-
$"unregister_manipulator invalid response: {error}"
413-
);
414-
})
415-
.Emit("unregister_manipulator", manipulatorId);
416-
}
417-
418-
/// <summary>
419-
/// Request the current position of a manipulator.
391+
/// Request the current position of a manipulator (mm).
420392
/// </summary>
421393
/// <param name="manipulatorId">ID of the manipulator to get the position of</param>
422394
/// <param name="onSuccessCallback">Callback function to pass manipulator position to</param>
423395
/// <param name="onErrorCallback">Callback function to handle errors</param>
424-
public void GetPos(
396+
public void GetPosition(
425397
string manipulatorId,
426398
Action<Vector4> onSuccessCallback,
427399
Action<string> onErrorCallback = null
@@ -444,7 +416,7 @@ public void GetPos(
444416
onErrorCallback?.Invoke($"get_pos invalid response: {data}");
445417
}
446418
})
447-
.Emit("get_pos", manipulatorId);
419+
.Emit("get_position", manipulatorId);
448420
}
449421

450422
/// <summary>
@@ -510,8 +482,8 @@ public void GetShankCount(
510482
/// <param name="request">Goto position request object</param>
511483
/// <param name="onSuccessCallback">Callback function to handle successful manipulator movement</param>
512484
/// <param name="onErrorCallback">Callback function to handle errors</param>
513-
public void GotoPos(
514-
GotoPositionRequest request,
485+
public void SetPosition(
486+
SetPositionRequest request,
515487
Action<Vector4> onSuccessCallback,
516488
Action<string> onErrorCallback = null
517489
)
@@ -532,7 +504,7 @@ public void GotoPos(
532504
onErrorCallback?.Invoke($"goto_pos invalid response: {data}");
533505
}
534506
})
535-
.Emit("goto_pos", ToJson(request));
507+
.Emit("set_position", ToJson(request));
536508
}
537509

538510
/// <summary>
@@ -541,8 +513,8 @@ public void GotoPos(
541513
/// <param name="request">Drive to depth request</param>
542514
/// <param name="onSuccessCallback">Callback function to handle successful manipulator movement</param>
543515
/// <param name="onErrorCallback">Callback function to handle errors</param>
544-
public void DriveToDepth(
545-
DriveToDepthRequest request,
516+
public void SetDepth(
517+
SetDepthRequest request,
546518
Action<float> onSuccessCallback,
547519
Action<string> onErrorCallback
548520
)
@@ -552,7 +524,7 @@ Action<string> onErrorCallback
552524
{
553525
if (DataKnownAndNotEmpty(data))
554526
{
555-
var parsedData = ParseJson<DriveToDepthResponse>(data);
527+
var parsedData = ParseJson<SetDepthResponse>(data);
556528
if (string.IsNullOrEmpty(parsedData.Error))
557529
onSuccessCallback?.Invoke(parsedData.Depth);
558530
else
@@ -563,7 +535,7 @@ Action<string> onErrorCallback
563535
onErrorCallback?.Invoke($"drive_to_depth invalid response: {data}");
564536
}
565537
})
566-
.Emit("drive_to_depth", ToJson(request));
538+
.Emit("set_depth", ToJson(request));
567539
}
568540

569541
/// <summary>
@@ -573,7 +545,7 @@ Action<string> onErrorCallback
573545
/// <param name="onSuccessCallback">Callback function to handle setting inside_brain state successfully</param>
574546
/// <param name="onErrorCallback">Callback function to handle errors</param>
575547
public void SetInsideBrain(
576-
InsideBrainRequest request,
548+
SetInsideBrainRequest request,
577549
Action<bool> onSuccessCallback,
578550
Action<string> onErrorCallback = null
579551
)
@@ -597,89 +569,11 @@ public void SetInsideBrain(
597569
.Emit("set_inside_brain", ToJson(request));
598570
}
599571

600-
/// <summary>
601-
/// Request a manipulator to be calibrated.
602-
/// </summary>
603-
/// <param name="manipulatorId">ID of the manipulator to be calibrated</param>
604-
/// <param name="onSuccessCallback">Callback function to handle a successful calibration</param>
605-
/// <param name="onErrorCallback">Callback function to handle an unsuccessful calibration</param>
606-
public void Calibrate(
607-
string manipulatorId,
608-
Action onSuccessCallback,
609-
Action<string> onErrorCallback = null
610-
)
611-
{
612-
_connectionManager
613-
.Socket.ExpectAcknowledgement<string>(error =>
614-
{
615-
if (error == "")
616-
onSuccessCallback?.Invoke();
617-
else
618-
onErrorCallback?.Invoke(error);
619-
})
620-
.Emit("calibrate", manipulatorId);
621-
}
622-
623-
/// <summary>
624-
/// Bypass calibration requirement of a manipulator.
625-
/// </summary>
626-
/// <remarks>This method should only be used for testing and NEVER in production</remarks>
627-
/// <param name="manipulatorId">ID of the manipulator to bypass calibration</param>
628-
/// <param name="onSuccessCallback">Callback function to handle a successful calibration bypass</param>
629-
/// <param name="onErrorCallback">Callback function to handle errors</param>
630-
public void BypassCalibration(
631-
string manipulatorId,
632-
Action onSuccessCallback,
633-
Action<string> onErrorCallback = null
634-
)
635-
{
636-
_connectionManager
637-
.Socket.ExpectAcknowledgement<string>(error =>
638-
{
639-
if (error == "")
640-
onSuccessCallback?.Invoke();
641-
else
642-
onErrorCallback?.Invoke(error);
643-
})
644-
.Emit("bypass_calibration", manipulatorId);
645-
}
646-
647-
/// <summary>
648-
/// Request a write lease for a manipulator.
649-
/// </summary>
650-
/// <param name="request"></param>
651-
/// <param name="onSuccessCallback">Callback function to handle successfully setting can_write state</param>
652-
/// <param name="onErrorCallback">Callback function to handle errors</param>
653-
public void SetCanWrite(
654-
CanWriteRequest request,
655-
Action<bool> onSuccessCallback,
656-
Action<string> onErrorCallback = null
657-
)
658-
{
659-
_connectionManager
660-
.Socket.ExpectAcknowledgement<string>(data =>
661-
{
662-
if (DataKnownAndNotEmpty(data))
663-
{
664-
var parsedData = ParseJson<BooleanStateResponse>(data);
665-
if (string.IsNullOrEmpty(parsedData.Error))
666-
onSuccessCallback?.Invoke(parsedData.State);
667-
else
668-
onErrorCallback?.Invoke(parsedData.Error);
669-
}
670-
else
671-
{
672-
onErrorCallback?.Invoke($"set_can_write invalid response: {data}");
673-
}
674-
})
675-
.Emit("set_can_write", ToJson(request));
676-
}
677-
678572
/// <summary>
679573
/// Request all movement to stop.
680574
/// </summary>
681575
/// <param name="callback">Callback function to handle stop result</param>
682-
public void Stop(Action<bool> callback)
576+
public void Stop(Action<string> callback)
683577
{
684578
_connectionManager.Socket.ExpectAcknowledgement(callback).Emit("stop");
685579
}
@@ -705,4 +599,4 @@ private static string ToJson<T>(T data)
705599

706600
#endregion
707601
}
708-
}
602+
}

0 commit comments

Comments
 (0)