/// <summary>
 /// Constructor to setup some prequisites. The serial code of the Ergometer is needed to setup the connection.
 /// </summary>
 /// <param name="ergometerSerialLastFiveNumbers"></param>
 public BLEconnect(System.String ergometerSerialLastFiveNumbers)
 {
     this.ergometerSerialLastFiveNumbers = ergometerSerialLastFiveNumbers;
     bLESimulator = new BLESimulator(ergometerSerialLastFiveNumbers);
     init(ergometerSerialLastFiveNumbers);
     this.dataHandler = new BLEDataHandler(ergometerSerialLastFiveNumbers);
 }
示例#2
0
 /// <summary>
 /// Constructor to setup some prequisites. The serial code of the Ergometer is needed to setup the connection.
 /// </summary>
 /// <param name="ergometerSerialLastFiveNumbers"></param>
 public BLEConnect(string ergometerSerialLastFiveNumbers, IClient iClient, ISim iSim, string patientName, string patientNumber)
 {
     this.ergometerSerialLastFiveNumbers = ergometerSerialLastFiveNumbers;
     this.bLESimulator = new BLESimulator(ergometerSerialLastFiveNumbers);
     this.dataHandler  = new BLEDataHandler(ergometerSerialLastFiveNumbers, patientName, patientNumber);
     this.iClient      = iClient;
     this.iSim         = iSim;
 }
        /// <summary>
        /// Decode data for the heart rate monitor. In this case the only useful value is byte[1], so far the success data transfer rate has been 100%. Therefor the checksum is not used at the moment.
        /// </summary>
        /// <param name="rawData"></param>
        /// <param name="bLEDataHandler"></param>
        public static void Decrypt(byte[] rawData, BLEDataHandler bLEDataHandler)
        {
            ;
            //byte[] checksum = { rawData[rawData.Length - 1] };
            //bool isCorrect = CheckXorValue(rawData, checksum);

            int heartRate = rawData[1];

            bLEDataHandler.SetHeartrate(heartRate);
        }
        /// <summary>
        /// Run the simulator with a data transfer time of 4Hz, just like the real protocol.
        /// </summary>

        public void RunSimulator()
        {
            BLEDataHandler bLEDataHandler = new BLEDataHandler(ergoID);
            int            i    = 0;
            List <byte[]>  data = new List <byte[]>();

            while (true)
            {
                data = ReadData(ApplicationSettings.GetReadWritePath(ergoID), WriteOption.Ergo);
                System.Threading.Thread.Sleep(250);
                BLEDecoderErgo.Decrypt(data[i], bLEDataHandler);
                if (i >= data.Count - 1)
                {
                    i = 0;
                }
                i++;
            }
        }
        /// <summary>
        /// Decodes the data for all data pages. Hence, when you add a DataPage, also add it here!
        /// </summary>
        /// <param name="rawData"></param>
        /// <param name="bLEDataHandler"></param>
        public static void Decrypt(byte[] rawData, BLEDataHandler bLEDataHandler)
        {
            int messageLength = rawData[1];

            byte[] message    = rawData.Skip(4).Take(messageLength).ToArray();
            int    pageNumber = message[0];

            byte[] checksum  = rawData.Skip(4).Skip(messageLength).ToArray();
            bool   isCorrect = CheckXorValue(rawData, checksum);

            if (isCorrect)
            {
                if (pageNumber == 16)
                {
                    // decode page 16
                    double elapsedTime      = message[2] * 0.25; //seconds
                    int    distanceTraveled = message[3];        //metres
                    byte   speedLSB         = message[4];
                    byte   speedMSB         = message[5];
                    int    heartRate        = message[6];                                  // bpm
                    double speed            = ((speedMSB << 8) | speedLSB) / 1000.0 * 3.6; //kmph

                    double[] data = { elapsedTime, distanceTraveled, speed, heartRate };
                    bLEDataHandler.addBLEDataForDataPage16(data);
                }
                else if (pageNumber == 25)
                {
                    // decode page 25
                    int  updateEventCount    = message[1]; //count
                    int  instanteousCadence  = message[2]; //rpm
                    byte accumulatedPowerLSB = message[3];
                    byte accumulatedPowerMSB = message[4];
                    byte instanteousPowerLSB = message[5];
                    byte instanteousPowerMSB = message[6];

                    int accumulatedPower = (accumulatedPowerMSB << 8) | accumulatedPowerLSB;                               //watt
                    int instanteousPower = (((instanteousPowerMSB | 0b11110000) ^ 0b11110000) << 8) | instanteousPowerLSB; //watt

                    double[] data = { updateEventCount, instanteousCadence, accumulatedPower, instanteousPower };
                    bLEDataHandler.addBLEDataForDataPage25(data);
                }
                bLEDataHandler.printLastData();
            }
        }
示例#6
0
        /// <summary>
        /// Run the simulator with a data transfer time of 4Hz, just like the real protocol.
        /// </summary>

        public void RunSimulator()
        {
            this.bLEDataHandler = new BLEDataHandler(this._ergoID, this._patientName, this._patientNumber);
            int           i    = 0;
            List <byte[]> data = new List <byte[]>();

            while (true)
            {
                data = this.ReadData(ApplicationSettings.GetReadWritePath(this._ergoID), WriteOption.Ergo);
                BLEDecoderErgo.Decrypt(data[i], this.bLEDataHandler);
                string toSend = this.bLEDataHandler.ReadLastData();                 // Data that should be send to the client.
                this._iClient.Write(toSend);
                if (i >= data.Count - 1)
                {
                    i = 0;
                }

                i++;
                System.Threading.Thread.Sleep(250);
            }
        }
 /// <summary>
 /// The Decrypt method should be implemented, so a specific byte[] data can be decoded.
 /// </summary>
 /// <param name="rawData"></param>
 /// <param name="bLEDataHandler"></param>
 public static void Decrypt(byte[] rawData, BLEDataHandler bLEDataHandler)
 {
 }