public override T Value <T>() { var type = typeof(T); if (type == typeof(LowHighG)) { Func <byte, byte, bool> CheckHighG = (axis, value) => { byte mask = (byte)(0x1 << axis); return((value & mask) == mask); }; byte highFirst = (byte)((bytes[0] & 0x1c) >> 2); LowHighG casted = new LowHighG( (bytes[0] & 0x1) == 0x1, (bytes[0] & 0x2) == 0x2, CheckHighG(0, highFirst), CheckHighG(1, highFirst), CheckHighG(2, highFirst), (bytes[0] & 0x20) == 0x20 ? Sign.Negative : Sign.Positive); return((T)Convert.ChangeType(casted, type)); } return(base.Value <T>()); }
public async Task HandleLowResponse() { LowHighG actual = null, expected = new LowHighG(false, true, false, false, false, Data.Sign.Positive); await accelerometer.LowAndHighG.AddRouteAsync(source => source.Stream(data => actual = data.Value <LowHighG>())); platform.sendMockResponse(new byte[] { 0x03, 0x08, 0x02 }); Assert.That(actual, Is.EqualTo(expected)); }
public async Task HandleHighResponse(LowHighG expected, byte[] response) { LowHighG actual = null; await accelerometer.LowAndHighG.AddRouteAsync(source => source.Stream(data => actual = data.Value <LowHighG>())); platform.sendMockResponse(response); Assert.That(actual, Is.EqualTo(expected)); }