private async Task SendOrThrow(UplinkMessage msg) { var status = await _bluetera.SendMessage(msg); if (!status) { throw new BlueteraException($"Operation failed."); } }
private static async Task <bool> StopImu() { UplinkMessage stopImuMsg = new UplinkMessage() { Imu = new ImuCommand() { Stop = true } }; return(await device.SendMessage(stopImuMsg)); }
private async Task StopImu() { UplinkMessage msg = new UplinkMessage() { Imu = new ImuCommand() { Stop = true } }; await SendOrThrow(msg); }
private static async Task <bool> SendEcho() { UplinkMessage msg = new UplinkMessage() { Echo = new EchoPayload() { Value = 9 } }; return(await device.SendMessage(msg)); }
private async Task StartImu() { UplinkMessage msg = new UplinkMessage() { Imu = new ImuCommand { Start = new ImuStart() { DataTypes = (uint)(ImuDataType.Accelerometer | ImuDataType.Quaternion), // ImuDataType are enum flags - logically 'OR' to combine several types Odr = _odr, // Output Data Rate [Hz] - see note (1) at the end of this file before changing this value AccFsr = 4, // Acceleromenter Full Scale Range [g] GyroFsr = 500 // Gyroscope Full Scale Range [deg/sec] } } }; await SendOrThrow(msg); }
public async Task <bool> SendMessage(UplinkMessage msg) { var stream = new MemoryStream(); msg.WriteDelimitedTo(stream); if (stream.Position > 0) { byte[] buf = stream.ToArray(); GattCommunicationStatus status = await _busRxChar.WriteValueAsync(stream.ToArray().AsBuffer()); return((status == GattCommunicationStatus.Success) ? true : false); } else { throw new ArgumentException("Invalid UplinkMessage"); } }
private static async Task <bool> StartImu() { UplinkMessage msg = new UplinkMessage() { Imu = new ImuCommand { Start = new ImuStart() { DataTypes = (uint)ImuDataType.Quaternion, // ImuDataType are enum flags - logically 'OR' to combine several types Odr = 50, // Output Data Rate [Hz] AccFsr = 4, // Acceleromenter Full Scale Range [g] GyroFsr = 500 // Gyroscope Full Scale Range [deg/sec] } } }; return(await device.SendMessage(msg)); }
public Task <bool> SendMessage(UplinkMessage msg) { var stream = new MemoryStream(); msg.WriteDelimitedTo(stream); if (stream.Position > 0) { byte[] buf = stream.ToArray(); return(Task.Factory.StartNew(() => { NativeSdkWrapper.StatusCode status = NativeSdkWrapper.Write(Address, buf, (ushort)buf.Length); return (status == NativeSdkWrapper.StatusCode.Success); })); } else { throw new ArgumentException("Invalid UplinkMessage"); } }