private void ReceivingData(Stream mStream)
        {
            try
            {
                byte[] received = new byte[1024];
                mStream.Read(received, 0, received.Length);
                string s = Encoding.UTF8.GetString(received, 0, received.Length);

                string[] phoneData = s.Split(',');
                string   time      = mts.DoubleToTimeString(mts.GetTime() - startTime);
                if (phoneData.Count() == 14)
                {
                    PhoneData pData = new PhoneData(time, int.Parse(phoneData[0]), double.Parse(phoneData[1]),
                                                    double.Parse(phoneData[2]), double.Parse(phoneData[3]), double.Parse(phoneData[4]),
                                                    double.Parse(phoneData[5]), double.Parse(phoneData[6]), double.Parse(phoneData[7]),
                                                    double.Parse(phoneData[8]), double.Parse(phoneData[9]), phoneData[10],
                                                    phoneData[11], double.Parse(phoneData[12]), double.Parse(phoneData[13]));
                    updateData(pData);
                }
                else if (phoneData.Count() == 7)
                {
                    //updateTouchData(new Tuple<double, string[]>(mts.GetTime() - startTime, phoneData));

                    TouchData data = new TouchData(phoneData[0], phoneData[1], phoneData[2], phoneData[3], phoneData[4], phoneData[5], phoneData[6]);
                    UpdateTouchData(data);
                    Debug.WriteLine("touch: " + s);
                }



                //Debug.WriteLine("received : " + s);
            }
            catch (IOException e)
            {
                connected = false;
            }
        }
        public void HandleEvent(object sender, EventArgs args)
        {
            CustomEventArgs eventArgs = (CustomEventArgs)args;
            int             indicator = eventArgs.getIndicator();

            switch (indicator)
            {
            case (int)ShimmerBluetooth.ShimmerIdentifier.MSG_IDENTIFIER_STATE_CHANGE:
                int state = (int)eventArgs.getObject();
                if (state == (int)ShimmerBluetooth.SHIMMER_STATE_CONNECTED)
                {
                    updateMessage("device connected");
                }
                else if (state == (int)ShimmerBluetooth.SHIMMER_STATE_CONNECTING)
                {
                    updateMessage("connecting shimmer device");
                }
                else if (state == (int)ShimmerBluetooth.SHIMMER_STATE_NONE)
                {
                    updateMessage("device disconnected");
                }
                else if (state == (int)ShimmerBluetooth.SHIMMER_STATE_STREAMING)
                {
                    updateMessage("Streaming");
                }
                break;

            case (int)ShimmerBluetooth.ShimmerIdentifier.MSG_IDENTIFIER_NOTIFICATION_MESSAGE:
                break;

            case (int)ShimmerBluetooth.ShimmerIdentifier.MSG_IDENTIFIER_DATA_PACKET:
                ObjectCluster objectCluster = (ObjectCluster)eventArgs.getObject();

                if (FirstTime)
                {
                    IndexAccelX = objectCluster.GetIndex(Shimmer3Configuration.SignalNames.LOW_NOISE_ACCELEROMETER_X, ShimmerConfiguration.SignalFormats.CAL);
                    IndexAccelY = objectCluster.GetIndex(Shimmer3Configuration.SignalNames.LOW_NOISE_ACCELEROMETER_Y, ShimmerConfiguration.SignalFormats.CAL);
                    IndexAccelZ = objectCluster.GetIndex(Shimmer3Configuration.SignalNames.LOW_NOISE_ACCELEROMETER_Z, ShimmerConfiguration.SignalFormats.CAL);
                    IndexGSR    = objectCluster.GetIndex(Shimmer3Configuration.SignalNames.GSR, ShimmerConfiguration.SignalFormats.CAL);
                    IndexPPG    = objectCluster.GetIndex(Shimmer3Configuration.SignalNames.INTERNAL_ADC_A13, ShimmerConfiguration.SignalFormats.CAL);
                    FirstTime   = false;
                }

                // List<string> s= objectCluster.GetNames();
                // foreach (string st in s) {
                //      Debug.WriteLine(st);
                //  }
                SensorData datax   = objectCluster.GetData(IndexAccelX);
                SensorData datay   = objectCluster.GetData(IndexAccelY);
                SensorData dataz   = objectCluster.GetData(IndexAccelZ);
                SensorData dataGSR = objectCluster.GetData(IndexGSR);
                SensorData dataPPG = objectCluster.GetData(IndexPPG);
                //TimeSpan time = stopwatch.Elapsed;

                //double time = DateTime.Now.ToOADate();
                double time = mts.GetTime() - startTime;

                ShimmerData dataObj = new ShimmerData(mts.DoubleToTimeString(time), dataGSR.Data, dataPPG.Data, datax.Data, datay.Data, dataz.Data);
                //Debug.WriteLine(dataObj.Time);

                updateData(dataObj);
                break;
            }
        }