-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,815 additions
and
268 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
BLE_FTMS_IndoorBike_Unity/Assets/Scenes.meta → ...ike_Unity/Assets/BLE_FTMS_IndoorBike.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
BLE_FTMS_IndoorBike_Unity/Assets/BLE_FTMS_IndoorBike/BleApi.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading; | ||
using UnityEngine; | ||
|
||
|
||
public class BleApi | ||
{ | ||
// dll calls | ||
public enum ScanStatus { PROCESSING, AVAILABLE, FINISHED }; | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
public struct DeviceUpdate | ||
{ | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)] | ||
public string id; | ||
[MarshalAs(UnmanagedType.I1)] | ||
public bool isConnectable; | ||
[MarshalAs(UnmanagedType.I1)] | ||
public bool isConnectableUpdated; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)] | ||
public string name; | ||
[MarshalAs(UnmanagedType.I1)] | ||
public bool nameUpdated; | ||
} | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "StartDeviceScan")] | ||
public static extern void StartDeviceScan(); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "PollDevice")] | ||
public static extern ScanStatus PollDevice(ref DeviceUpdate device, bool block); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "StopDeviceScan")] | ||
public static extern void StopDeviceScan(); | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
public struct Service | ||
{ | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)] | ||
public string uuid; | ||
}; | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "ScanServices", CharSet = CharSet.Unicode)] | ||
public static extern void ScanServices(string deviceId); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "PollService")] | ||
public static extern ScanStatus PollService(out Service service, bool block); | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
public struct Characteristic | ||
{ | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)] | ||
public string uuid; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)] | ||
public string userDescription; | ||
}; | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "ScanCharacteristics", CharSet = CharSet.Unicode)] | ||
public static extern void ScanCharacteristics(string deviceId, string serviceId); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "PollCharacteristic")] | ||
public static extern ScanStatus PollCharacteristic(out Characteristic characteristic, bool block); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "SubscribeCharacteristic_Read", CharSet = CharSet.Unicode)] | ||
public static extern bool SubscribeCharacteristic_Read(string deviceId, string serviceId, string characteristicId, bool block); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "SubscribeCharacteristic_Write", CharSet = CharSet.Unicode)] | ||
public static extern bool SubscribeCharacteristic_Write(string deviceId, string serviceId, string characteristicId, bool block); | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
public struct BLEData | ||
{ | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] | ||
public byte[] buf; | ||
[MarshalAs(UnmanagedType.I2)] | ||
public short size; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] | ||
public string deviceId; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] | ||
public string serviceUuid; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] | ||
public string characteristicUuid; | ||
}; | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "PollData")] | ||
public static extern bool PollData(out BLEData data, bool block); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "SendData")] | ||
public static extern bool SendData(in BLEData data, bool block); | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "Quit")] | ||
public static extern void Quit(); | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
public struct ErrorMessage | ||
{ | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] | ||
public string msg; | ||
}; | ||
|
||
[DllImport("BleWinrtDll.dll", EntryPoint = "GetError")] | ||
public static extern void GetError(out ErrorMessage buf); | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
BLE_FTMS_IndoorBike_Unity/Assets/BLE_FTMS_IndoorBike/BleApi.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
BLE_FTMS_IndoorBike_Unity/Assets/BLE_FTMS_IndoorBike/BleWinrtDll.dll.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.