using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bluetoolth
{
public class Utility
{
//服务
public static String UUID_SERVER = "0000ff12-0000-1000-8000-00805f9b34fb";
//间隔
public static String UUID_Interval = "0000ff04-0000-1000-8000-00805f9b34fb";
//写 WriteWithoutResponse
public static string UUID_Write = "0000ff01-0000-1000-8000-00805f9b34fb";
//读 Notify
public static string UUID_Read = "0000ff02-0000-1000-8000-00805f9b34fb";
//名字 Read Write
public static String UUID_Name = "0000ff06-0000-1000-8000-00805f9b34fb";
public static Guid UUID_CONFIG_DESCRIPTOR = Guid.Parse("00002902-0000-1000-8000-00805f9b34fb");
public static Guid UUID_HEART_RATE_MEASUREMENT = Guid
.Parse("00002a37-0000-1000-8000-00805f9b34fb");
///
/// CRC校验
///
///
///
///
public static ushort CRC(byte[] data, int length)
{
ushort tempCrcResult = 0xffff;
for (int i = 0; i < length; i++)
{
tempCrcResult = (ushort)(tempCrcResult ^ data[i]);
for (int j = 0; j < 8; j++)
{
if ((tempCrcResult & 0x0001) == 1)
tempCrcResult = (ushort)((tempCrcResult >> 1) ^ 0xa001);
else tempCrcResult = (ushort)(tempCrcResult >> 1);
}
}
return (tempCrcResult = (ushort)(((tempCrcResult & 0xff) << 8) | (tempCrcResult >> 8)));
}
}
}