public override void Decode(byte[] payload) { if (payload[6] != _lastCount) { // It's new data SensorPayload p = new SensorPayload(); // Decode the time p.Type = "hrm"; p.Data.Add("ticks",BitConverter.ToUInt16(payload, 4)); p.Data.Add("bpm", payload[7]); OnSensorMessage(p); _lastCount = payload[6]; } }
public override void Decode(byte[] payload) { SensorPayload pSpCd = new SensorPayload(); pSpCd.Type = "spcd"; ushort pedalTicks = BitConverter.ToUInt16(payload, 0); ushort pedalRotations = BitConverter.ToUInt16(payload, 2); ushort wheelTicks = BitConverter.ToUInt16(payload, 4); ushort wheelRotations = BitConverter.ToUInt16(payload, 6); pSpCd.Data.Add("pedalTicks", pedalTicks); pSpCd.Data.Add("pedalRotations", pedalRotations); pSpCd.Data.Add("wheelTicks", wheelTicks); pSpCd.Data.Add("wheelRotations", wheelRotations); OnSensorMessage(pSpCd); }
public override void Decode(byte[] payload) { if (payload[0] == 0x10 && payload[1] != _lastCount) { // It's new data SensorPayload p = new SensorPayload(); // Decode the time p.Type = "pwr"; ushort cnt = payload[1]; ushort pwr = BitConverter.ToUInt16(payload, 4); System.Diagnostics.Debug.WriteLine("cnt:" + cnt + " pwr:" + pwr); p.Data.Add("cnt", cnt); p.Data.Add("pwr", pwr); OnSensorMessage(p); _lastCount = payload[1]; } }
protected void OnSensorMessage(SensorPayload p) { SensorMessageHandler handler = SensorMessage; if (handler != null) handler(this, p); }
private void SensorMessageReceived(object sender, SensorPayload p) { // what is it? _datumLock.EnterWriteLock(); try { // Set the lease _outputDatum.ls = _Lease.LeaseId; _outputDatum.userId = _Lease.UserId; switch (p.Type) { case "hrm": _outputDatum.h = p.Data["bpm"]; _outputDatum.ht = OverflowSubtract(p.Data["ticks"], _lastBpmTick); _lastBpmTick = p.Data["ticks"]; break; case "spcd": _outputDatum.p = OverflowSubtract(p.Data["pedalRotations"], _lastPedalRotation); _outputDatum.pt = OverflowSubtract(p.Data["pedalTicks"], _lastPedalTick); _outputDatum.w = OverflowSubtract(p.Data["wheelRotations"], _lastWheelRotation); _outputDatum.wt = OverflowSubtract(p.Data["wheelTicks"], _lastWheelTick); _lastPedalRotation = p.Data["pedalRotations"]; _lastPedalTick = p.Data["pedalTicks"]; _lastWheelRotation = p.Data["wheelRotations"]; _lastWheelTick = p.Data["wheelTicks"]; break; case "pwr": _outputDatum.e = OverflowSubtract(p.Data["pwr"], _lastPower); _outputDatum.ec = OverflowSubtractByte(p.Data["cnt"],_lastPowerCount); _lastPower = p.Data["pwr"]; _lastPowerCount = p.Data["cnt"]; break; default: break; } } finally { _datumLock.ExitWriteLock(); } }