Skip to content

Commit

Permalink
unity project
Browse files Browse the repository at this point in the history
  • Loading branch information
frakw committed Jul 12, 2022
1 parent 3921ab7 commit 5be082e
Show file tree
Hide file tree
Showing 13 changed files with 1,815 additions and 268 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions BLE_FTMS_IndoorBike_Unity/Assets/BLE_FTMS_IndoorBike/BleApi.cs
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);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5be082e

Please sign in to comment.