Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void updateSpdCadEvent(object sender, EventArgs e)
        {
            spdStream evtFrom = (spdStream)sender;

            // set the wheelSize from this sender ...
            evtFrom.wheelSize = wheelSize;
            speed             = evtFrom.spdInst;
            cad       = evtFrom.cadInst;
            hasSpdCad = true;

            TCXDistanceCount += evtFrom.publicSpdCnt;

            if (ptrSPwr >= 0)
            {
                if (speed >= 0)
                {
                    qSPDQue.Enqueue(speed);
                }
                if (qSPDQue.Count > 4)
                {
                    qSPDQue.Dequeue();
                }

                hasPwr    = false;
                instPower = speedPowerCalcs.getSpower(ptrSPwr, qSPDQue.Average());


                if (_TCXDataTimer.Enabled)
                {
                    powerPoints pp = new powerPoints();
                    pp.instPwr = instPower;
                    pp.time    = DateTime.Now;
                    qPWRQue.Enqueue(pp);

                    /*
                     * This was using time filtering, going to try doing this with segment averages
                     *
                     *
                     *             while (qPWRQue.Peek().time < DateTime.Now.Subtract(TimeSpan.FromSeconds((double)avgPowerTime)))
                     *                 qPWRQue.Dequeue();
                     */
                    avgPower = 0;
                    if (qPWRQue.Count > 0)
                    {
                        avgPower = (int)qPWRQue.Average(s => s.instPwr);
                    }
                }
                return;
            }
        }
Exemplo n.º 3
0
        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
            { }
        }