Skip to content

Commit 4728494

Browse files
committed
add support for endpoint_ref property type
1 parent 985bc43 commit 4728494

21 files changed

+1656
-984
lines changed

Demo.ReadSetProperties/Program.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77
using System.Windows.Forms;
8-
using ODriveClientlibrary.DeviceSchema;
8+
using ODriveClientLibrary.DeviceSchema;
99
using ODriveClientLibrary;
1010

1111
class Program
@@ -26,24 +26,27 @@ static async Task MyAsyncFunc()
2626
throw new Exception("Could not find any suitable devices to connect to");
2727
}
2828

29+
30+
2931
using (var oDrive = new Device(foundDevice, DeviceSchema.SchemaChecksum))
3032
{
3133
bool connectSuccess = false;
3234
try
3335
{
34-
connectSuccess = await oDrive.Connect(true);
36+
connectSuccess = await oDrive.Connect();
3537
}
3638
catch (Exception ex)
3739
{
3840
System.Diagnostics.Debugger.Break();
3941
}
4042

41-
var download = await oDrive.DownloadSchema();
43+
// var download = await oDrive.DownloadSchema();
4244

4345

4446
while (!Console.KeyAvailable)
4547
{
46-
Console.WriteLine(await oDrive.GetProperty(schema.VbusVoltage));
48+
var x = await oDrive.GetProperty(schema.Config.Gpio1PwmMapping.Endpoint);
49+
Console.WriteLine($"{x.EndpointID}, {x.JsonCRC}");
4750
//await oDrive.SetProperty(schema.Motor0.Config.CalibrationCurrent, 1);
4851
//await oDrive.GetExecutionDelegate(schema.SaveConfiguration)();
4952
Application.DoEvents();

ODriveClientLibrary.Common/IDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public interface IDevice
88
Task<T> GetProperty<T>(IReadablePropertyMember<T> readablePropertyMember);
99
Task SetProperty<T>(IWriteablePropertyMember<T> writeablePropertyMember, T newValue);
1010
T GetExecutionDelegate<T>(IExecutableMember<T> executableMember);
11-
Task<bool> Connect(bool skipChecksumValidation = false);
11+
Task<bool> Connect(ushort? schemaChecksum = null);
1212
bool Disconnect();
1313
Task<string> DownloadSchema(CancellationToken cancellationToken = default(CancellationToken), bool setSchemaChecksum = true);
1414
Task InvokeEndpoint(ushort endpointID, CancellationToken cancellationToken = default(CancellationToken));

ODriveClientLibrary.Common/ODriveClientLibrary.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Compile Include="IReadablePropertyMember.cs" />
4646
<Compile Include="IWriteablePropertyMember.cs" />
4747
<Compile Include="Properties\AssemblyInfo.cs" />
48+
<Compile Include="Types\EndpointReference.cs" />
4849
</ItemGroup>
4950
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5051
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace ODriveClientLibrary.Common.Types
2+
{
3+
using System.Runtime.InteropServices;
4+
5+
[StructLayout(LayoutKind.Explicit, Size = 4)]
6+
public struct EndpointReference
7+
{
8+
[FieldOffset(0)]
9+
private readonly ushort endpointID;
10+
public ushort EndpointID => endpointID;
11+
12+
[FieldOffset(2)]
13+
private readonly ushort jsonCRC;
14+
public ushort JsonCRC => jsonCRC;
15+
16+
public EndpointReference(ushort endpointID, ushort jsonCRC)
17+
{
18+
this.endpointID = endpointID;
19+
this.jsonCRC = jsonCRC;
20+
}
21+
}
22+
}

ODriveClientLibrary.DeviceGenerator/DeviceSchema/DeviceEnums.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public enum DataType
4646
[Description("ulong")]
4747
[DevicePropertyType("uint64", typeof(ulong))]
4848
UInt64,
49+
[Description("Common.Types.EndpointReference")]
50+
[DevicePropertyType("endpoint_ref", typeof(Common.Types.EndpointReference))]
51+
EndpointReference,
4952
[Description("DeviceFunction")]
5053
[DevicePropertyType("function", typeof(DeviceFunction))]
5154
Function,

ODriveClientLibrary.DeviceGenerator/Generator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static GenerationResult GenerateFromString(string schemaJson)
2222

2323
var codeClasses = SchemaParser.Parse(schemaJson);
2424

25-
var namespaceDeclaration = NamespaceDeclaration(ParseName("ODriveClientlibrary.DeviceSchema"))
25+
var namespaceDeclaration = NamespaceDeclaration(ParseName("ODriveClientLibrary.DeviceSchema"))
2626
.AddUsings(
2727
UsingDirective(ParseName("System")),
2828
UsingDirective(ParseName("System.Threading.Tasks")),
@@ -101,7 +101,7 @@ public static GenerationResult GenerateFromDevice(string serialNumber = null)
101101

102102
using (var oDrive = new Device(foundDeviceInfo, 1))
103103
{
104-
var connectResult = oDrive.Connect(true).Result;
104+
var connectResult = oDrive.Connect().Result;
105105
var schemaJson = oDrive.DownloadSchema().Result;
106106
return GenerateFromString(schemaJson);
107107
}

0 commit comments

Comments
 (0)