public int addStream(ushort sAddress, byte type) { //called from user Handler to add a Stream from XML file definition byte[] address = BitConverter.GetBytes(sAddress); byte[] uIdBytes = new byte[4]; uIdBytes[0] = 128; //80h uIdBytes[1] = address[0]; //80h uIdBytes[2] = address[1]; //80h uIdBytes[3] = type; //0Bh for Power Sensor uint uId = BitConverter.ToUInt32(uIdBytes, 0); switch (type) { case (byte)sensorTypes.Power: // power for (int i = 0; i < pwrStreams.Count; i++) { if (pwrStreams[i].uniqueID == uId) { return(i); } } powerStream ds = new powerStream(sAddress, (byte)sensorTypes.Power, uId); pwrStreams.Add(ds); ds.timeoutEvent += new TimeoutHandler(heartBeatLost); return(pwrStreams.Count - 1); case (byte)sensorTypes.HeartRate: for (int i = 0; i < hbStreams.Count; i++) { if (hbStreams[i].uniqueID == uId) { return(i); } } hbStream hbds = new hbStream(sAddress, (byte)sensorTypes.HeartRate, uId); hbStreams.Add(hbds); hbds.timeoutEvent += new TimeoutHandler(heartBeatLost); return(hbStreams.Count - 1); case (byte)sensorTypes.SpeedCadence: for (int i = 0; i < spdStreams.Count; i++) { if (spdStreams[i].uniqueID == uId) { return(i); } } spdStream spdds = new spdStream(sAddress, (byte)sensorTypes.SpeedCadence, uId); spdStreams.Add(spdds); spdds.timeoutEvent += new TimeoutHandler(heartBeatLost); return(spdStreams.Count - 1); default: return(-1); } }
public void updatePwrEvent(object sender, EventArgs e) { powerStream evtFrom = (powerStream)sender; if (ptrSPwr >= 0) { hasPwr = false; return; } powerPoints pp = new powerPoints(); pp.instPwr = evtFrom.powerInst; pp.time = DateTime.Now; if (avgPowerTime > 0) { qPWRSmoothQue.Enqueue(pp); while (qPWRSmoothQue.Peek().time < DateTime.Now.Subtract(TimeSpan.FromSeconds((double)avgPowerTime))) { qPWRSmoothQue.Dequeue(); } } if (qPWRQue.Count > 0 && avgPowerTime > 0) { instPower = (int)qPWRSmoothQue.Average(s => s.instPwr); } else { instPower = evtFrom.powerInst; } if (_TCXDataTimer.Enabled) { qPWRQue.Enqueue(pp); avgPower = 0; if (qPWRQue.Count > 0) { avgPower = (int)qPWRQue.Average(s => s.instPwr); } } hasPwr = true; }
public void handleAntData(object sender, antEventArgs data) { try { UInt32 id = BitConverter.ToUInt32(data.data, pUID); switch (data.data[pTYPE]) { case (byte)sensorTypes.Power: // pwrStreams.Any( foreach (powerStream ds in pwrStreams) { if (ds.uniqueID == id) { ds.parseData(data.data); id = 0; break; } } if (id != 0) { powerStream ds = new powerStream(data.data); //App.Current.Dispatcher.Invoke((Action)(() => //{ pwrStreams.Add(ds); //})); ds.timeoutEvent += new TimeoutHandler(heartBeatLost); } break; case (byte)sensorTypes.HeartRate: foreach (hbStream ds in hbStreams) { if (ds.uniqueID == id) { ds.parseData(data.data); id = 0; break; } } if (id != 0) { hbStream ds = new hbStream(data.data); //App.Current.Dispatcher.Invoke((Action)(() => //{ hbStreams.Add(ds); //})); ds.timeoutEvent += new TimeoutHandler(heartBeatLost); } break; case (byte)sensorTypes.SpeedCadence: foreach (spdStream ds in spdStreams) { if (ds.uniqueID == id) { ds.parseData(data.data); id = 0; break; } } if (id != 0) { spdStream ds = new spdStream(data.data); //App.Current.Dispatcher.Invoke((Action)(() => //{ spdStreams.Add(ds); //})); ds.timeoutEvent += new TimeoutHandler(heartBeatLost); } break; } } catch { } }