Ejemplo n.º 1
0
 public void PopAndWrite(Queue <DataProfile> q)
 {
     while (q.Count != 0)
     {
         DataProfile data = q.Dequeue();
         _fileManagementModel.WriteToFile(data).Wait();
     }
 }
Ejemplo n.º 2
0
        public void DataUpdate(byte[] data, DataType type, DeviceType senderDeviceType)
        {
            List <Collection <DataProfile> > dataCollection = new List <Collection <DataProfile> >();

            dataCollection.Add(new Collection <DataProfile>());
            if (senderDeviceType == DeviceType.Master)
            {
                if (type == DataType.temp)
                {
                    var raw  = data[0] << 8 | data[1];
                    var temp = raw * 0.00390625;
                    temp       = (int)(temp * 10);
                    temp       = temp * .1;
                    MasterTemp = temp;
                    Debug.WriteLine("Master Temperature" + MasterTemp + "\t Time: " + DateTime.Now);
                    dataCollection[0].Add(new DataProfile(DataType.chest_temp, DataTime[DataType.chest_temp]++, temp));
                    //DataTime[DataType.masterTemp]++; DataTime[DataType.slaveTemp]++;
                }
                else if (type == DataType.scg)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        dataCollection[0].Add(new DataProfile(type, DataTime[type]++, (UInt16)(data[6 * i + 1] << 8 | data[6 * i])));
                        dataCollection[0].Add(new DataProfile(type, DataTime[type]++, (UInt16)(data[6 * i + 3] << 8 | data[6 * i + 2])));
                        dataCollection[0].Add(new DataProfile(type, DataTime[type]++, (UInt16)(data[6 * i + 5] << 8 | data[6 * i + 4])));
                    }
                }
                else if (type == DataType.ecg)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        dataCollection[0].Add(new DataProfile(type, DataTime[type]++, (UInt16)(data[2 * i + 1] | data[2 * i] << 8)));
                    }
                }
                else
                {
                    Debug.WriteLine("data leak");
                }
            }
            else if (senderDeviceType == DeviceType.Slave)
            {
                if (type == DataType.temp)
                {
                    var raw  = data[0] << 8 | data[1];
                    var temp = raw * 0.00390625;
                    temp      = (int)(temp * 10);
                    temp      = temp * .1;
                    SlaveTemp = temp;
                    Debug.WriteLine("Slave Temperature" + SlaveTemp + "\t Time: " + DateTime.Now);
                    dataCollection[0].Add(new DataProfile(DataType.foot_temp, DataTime[DataType.foot_temp]++, (UInt16)temp));
                    //DataTime[DataType.masterTemp]++; DataTime[DataType.slaveTemp]++;
                }
                else if (type == DataType.ppg)
                {
                    dataCollection.Add(new Collection <DataProfile>());
                    for (int i = 0; i < 5; i++)
                    {
                        var reddata = new DataProfile(DataType.red, DataTime[DataType.red]++, (UInt16)((data[4 * i + 1] << 8) | data[4 * i]));
                        var irdata  = new DataProfile(DataType.ir, DataTime[DataType.ir]++, (UInt16)((data[4 * i + 3] << 8) | data[4 * i + 2]));
                        dataCollection[0].Add(reddata);
                        dataCollection[1].Add(irdata);
                    }
                }
                else
                {
                    Debug.WriteLine("data leak");
                }
            }
            else
            {
                Debug.WriteLine("Data Leak: " + type);
            }

            //static int Maximum = 500;
            //Update user interface.
            //MvxObservableCollection<BleDataReceived> newDataCollection = new MvxObservableCollection<BleDataReceived>();
            foreach (var collection in dataCollection)
            {
                if (collection.Count > 0)
                {
                    Collection <DataProfile> newDataCollection = null;
                    DataType specificType = DataType.None;
                    foreach (var dat in collection)
                    {
                        string typeToString = "DataType." + dat.Type.ToString();
                        if (newDataCollection == null)
                        {
                            //newDataCollection = new MvxObservableCollection<BleDataReceived>(DataListString[typeToString]);
                            newDataCollection = DataCollection[typeToString];

                            specificType = dat.Type;
                        }
                        if ((dat.Index % BluetoothModel.SamplingRate[dat.Type] == 0))
                        {
                            if (dat.Index % BluetoothModel.DataPoints[dat.Type] == 0)
                            {
                                newDataCollection.Clear();
                                for (uint i = DataTime[specificType]; i < BluetoothModel.DataPoints[dat.Type]; i++)
                                {
                                    newDataCollection.Add(new DataProfile(type, i, double.NaN));
                                }
                            }
                            newDataCollection.Add(dat);
                        }
                        DataCollection[typeToString] = newDataCollection;
                    }
                }
                else
                {
                    Debug.WriteLine("UI: " + type);
                }
            }
            foreach (var collection in dataCollection)
            {
                EnqueueData(collection);
            }
        }