Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DataLogPresenter.cs Source File

DataLogPresenter.cs

00001 /*******************************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
00003 * 
00004 * This software is protected by copyright laws of the United States and
00005 * of foreign countries. This material may also be protected by patent laws
00006 * and technology transfer regulations of the United States and of foreign
00007 * countries. This software is furnished under a license agreement and/or a
00008 * nondisclosure agreement and may only be used or reproduced in accordance
00009 * with the terms of those agreements. Dissemination of this information to
00010 * any party or parties not specified in the license agreement and/or
00011 * nondisclosure agreement is expressly prohibited.
00012 *
00013 * The above copyright notice and this permission notice shall be included
00014 * in all copies or substantial portions of the Software.
00015 *
00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00022 * OTHER DEALINGS IN THE SOFTWARE.
00023 *
00024 * Except as contained in this notice, the name of Maxim Integrated
00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00026 * Products, Inc. Branding Policy.
00027 *
00028 * The mere transfer of this software does not imply any licenses
00029 * of trade secrets, proprietary technology, copyrights, patents,
00030 * trademarks, maskwork rights, or any other form of intellectual
00031 * property whatsoever. Maxim Integrated Products, Inc. retains all
00032 * ownership rights.
00033 *******************************************************************************
00034 */
00035 
00036 using System;
00037 using System.Collections.Generic;
00038 using System.Linq;
00039 using System.Text;
00040 
00041 using RPCSupport.Streaming;
00042 using HealthSensorPlatform.Model;
00043 using HealthSensorPlatform.View;
00044 using HealthSensorPlatform.CustomControls;
00045 
00046 namespace HealthSensorPlatform.Presenter
00047 {
00048     class DataLogPresenter
00049     {
00050         IDataLogModel model;
00051         DataLoggingView view;
00052         IRawFileLogView temperatureLog1;
00053         IRawFileLogView temperatureLog2;
00054         IRawFileLogView pressureLog;
00055 
00056         IRawFileLogView accelerometerLog;
00057         IRawFileLogView opticalLog;
00058 
00059         IRawFileLogView ecgLog;
00060         IRawFileLogView bioZLog;
00061         IRawFileLogView paceLog;
00062         IRawFileLogView rToRLog;
00063 
00064         IFormView formView;
00065 
00066         StatusForm statusForm;
00067 
00068         EcgView ecgView; // Needed to obtain some state information, should be decoupled later and use from data log model
00069         OpticalView opticalView;
00070 
00071         int count = 0;
00072         int bioZCount = 0;
00073         int ppgCount = 0;
00074         int accelCount = 0;
00075         PaceData paceData;
00076         RToRCalculator rToRCalculator;
00077         bool rToRFirst = true;
00078 
00079         string logFileDirectory = null;
00080 
00081         View.FileLogView.FileLogHeader fileLogHeader = new View.FileLogView.FileLogHeader();
00082 
00083         public DataLogPresenter(IFormView formView, EcgView ecgView, OpticalView opticalView, IDataLogModel model, DataLoggingView view, 
00084             IRawFileLogView temperatureLog1, IRawFileLogView temperatureLog2, IRawFileLogView pressureLog, 
00085             IRawFileLogView accelerometerLog, IRawFileLogView opticalLog, 
00086             IRawFileLogView ecgLog, IRawFileLogView bioZLog, IRawFileLogView paceLog, IRawFileLogView rToRLog)
00087         {
00088             this.model = model;
00089             this.view = view;
00090 
00091             this.formView = formView;
00092             this.ecgView = ecgView;
00093             this.opticalView = opticalView;
00094 
00095             this.temperatureLog1 = temperatureLog1;
00096             this.temperatureLog2 = temperatureLog2;
00097             this.pressureLog = pressureLog;
00098 
00099             this.accelerometerLog = accelerometerLog;
00100             this.opticalLog = opticalLog;
00101 
00102             this.ecgLog = ecgLog;
00103             this.bioZLog = bioZLog;
00104             this.paceLog = paceLog;
00105             this.rToRLog = rToRLog;
00106 
00107             view.LogDownloadStart += new EventHandler<EventArgs>(OnLogDownloadStart);
00108             view.MissionWrite += new EventHandler<EventArgs>(OnMissionWrite);
00109             view.MissionRead += new EventHandler<EventArgs>(OnMissionRead);
00110             view.MissionErase += new EventHandler<EventArgs>(OnMissionErase);
00111             model.LogData += new EventHandler<PartialArrayIntAvailableEventArgs>(OnLogData);
00112         }
00113         
00114         public void ProcessTemperature1(int[] data)
00115         {
00116             double[] calcTemp;
00117 
00118             calcTemp = CalculateTemperature(data);
00119             temperatureLog1.DisplayTemperature(data, calcTemp);
00120         }
00121 
00122         public void ProcessTemperature2(int[] data)
00123         {
00124             double[] calcTemp;
00125 
00126             calcTemp = CalculateTemperature(data);
00127             temperatureLog2.DisplayTemperature(data, calcTemp);
00128         }
00129 
00130         public double[] CalculateTemperature(int[] data)
00131         {
00132             double[] calcTemp = new double[data.Length];
00133             int rawCode;
00134 
00135             for (int i = 0; i < data.Length; i++ )
00136             {
00137                 rawCode = data[i];
00138 
00139                 if (rawCode > 0x7fff)
00140                     rawCode -= 0x10000;
00141 
00142                 calcTemp[i] = rawCode / Math.Pow(2, 8);
00143             }
00144 
00145             return calcTemp;
00146         }
00147 
00148         public void ProcessPressure(int[] data)
00149         {
00150             int[] rawTemp = new int[data.Length/2];
00151             int[] rawPress = new int[data.Length/2];
00152             double[] calcTemp, calcPress;
00153             
00154             for (int i = 0, j = 0; i < data.Length; i = i + 2, j++)
00155             {
00156                 rawTemp[j] = data[i];
00157                 rawPress[j] = data[i + 1];
00158             }
00159 
00160             var result = CalculatePressure(rawTemp, rawPress);
00161             calcTemp = result.Item1;
00162             calcPress = result.Item2;
00163             
00164             pressureLog.DisplayPressure(rawTemp, calcTemp, rawPress, calcPress);
00165         }
00166 
00167         public Tuple<double[], double[]> CalculatePressure(int[] temperature, int[] pressure)
00168         {
00169             double[] calcTemp = new double[temperature.Length];
00170             double[] calcPress = new double[pressure.Length];
00171 
00172             for (int i = 0; i < temperature.Length; i++ )
00173             {
00174                 calcTemp[i] = temperature[i] / 10.0;
00175             }
00176 
00177             for (int i = 0; i < pressure.Length; i++ )
00178             {
00179                 calcPress[i] = pressure[i] / 10;
00180             }
00181 
00182             return new Tuple<double[],double[]>(calcTemp, calcPress);
00183         }
00184 
00185         private void OnLogDownloadStart(object sender, EventArgs e)
00186         {
00187 
00188             if (view.Connected)
00189             {
00190                 count = 0;
00191                 bioZCount = 0;
00192                 ppgCount = 0;
00193                 accelCount = 0;
00194 
00195                 missionRead();
00196 
00197                 if (model.MissionSettings.Enable)
00198                 {
00199 
00200                     if (selectFile())
00201                     {
00202                         string missionString;
00203                         StringBuilder sb = new StringBuilder();
00204                         foreach (string str in model.MissionString())
00205                         {
00206                             sb.Append("% ");
00207                             sb.Append(str);
00208                             sb.Append(Environment.NewLine);
00209                         }
00210                         missionString = sb.ToString().Trim(Environment.NewLine.ToCharArray());
00211 
00212 
00213                         if (temperatureLog1 != null && temperatureLog1.Enable)
00214                         {
00215                             temperatureLog1.WriteLine(missionString);
00216                             temperatureLog1.WriteLine(fileLogHeader.Temperature1);
00217                         }
00218 
00219                         if (temperatureLog2 != null && temperatureLog2.Enable)
00220                         {
00221                             temperatureLog2.WriteLine(missionString);
00222                             temperatureLog2.WriteLine(fileLogHeader.Temperature2);
00223                         }
00224 
00225                         if (pressureLog != null && pressureLog.Enable)
00226                         {
00227                             pressureLog.WriteLine(missionString);
00228                             pressureLog.WriteLine(fileLogHeader.Pressure);
00229                         }
00230 
00231                         if (accelerometerLog != null && accelerometerLog.Enable)
00232                         {
00233                             accelerometerLog.WriteLine(missionString);
00234                             accelerometerLog.WriteLine(fileLogHeader.Accelerometer);
00235                         }
00236 
00237                         if (opticalLog != null && opticalLog.Enable)
00238                         {
00239                             opticalLog.WriteLine(missionString);
00240                             opticalLog.WriteLine(fileLogHeader.Optical);
00241                         }
00242 
00243                         if (ecgLog != null && ecgLog.Enable)
00244                         {
00245                             ecgLog.WriteLine(missionString);
00246                             ecgLog.WriteLine(fileLogHeader.Ecg);
00247                         }
00248 
00249                         if (bioZLog != null && bioZLog.Enable)
00250                         {
00251                             bioZLog.WriteLine(missionString);
00252                             bioZLog.WriteLine(fileLogHeader.BioZ);
00253                         }
00254 
00255                         if (rToRLog != null && rToRLog.Enable && ecgLog.Enable)
00256                         {
00257                             rToRLog.WriteLine(missionString);
00258                             rToRCalculator = new RToRCalculator(ecgView.MasterClockField, view.EcgArgs.Rate, view.EcgArgs.Dlpf, view.RToRArgs.Wndw);
00259                             rToRLog.WriteLine(fileLogHeader.RToR);
00260                         }
00261                         else if (rToRLog != null && rToRLog.Enable)
00262                         {
00263                             rToRLog.WriteLine(missionString);
00264                             rToRCalculator = null;
00265                             rToRLog.WriteLine(fileLogHeader.RToR);
00266                         }
00267 
00268                         if (paceLog != null && paceLog.Enable)
00269                         {
00270                             paceLog.WriteLine(missionString);
00271                             paceLog.WriteLine(fileLogHeader.Pace);
00272                         }
00273 
00274                         statusForm = new StatusForm();
00275                         statusForm.Text = "Flash Download";
00276                         statusForm.Message = "Please wait while your data is saved to your file.";
00277                         statusForm.Show();
00278 
00279                         model.Start();
00280                     }
00281                 }
00282             }
00283         }
00284 
00285         private void LogDownloadStop()
00286         {
00287             if (temperatureLog1 != null && temperatureLog1.Enable)
00288                 temperatureLog1.Enable = false;
00289 
00290             if (temperatureLog2 != null && temperatureLog2.Enable)
00291                 temperatureLog2.Enable = false;
00292 
00293             if (pressureLog != null && pressureLog.Enable)
00294                 pressureLog.Enable = false;
00295 
00296             if (accelerometerLog != null && accelerometerLog.Enable)
00297                 accelerometerLog.Enable = false;
00298 
00299             if (opticalLog != null && opticalLog.Enable)
00300                 opticalLog.Enable = false;
00301 
00302             if (ecgLog != null && ecgLog.Enable)
00303                 ecgLog.Enable = false;
00304 
00305             if (bioZLog != null && bioZLog.Enable)
00306                 bioZLog.Enable = false;
00307 
00308             if (rToRLog != null && rToRLog.Enable)
00309                 rToRLog.Enable = false;
00310 
00311             if (paceLog != null && paceLog.Enable)
00312                 paceLog.Enable = false;
00313 
00314             formView.MessageInfo("File save complete");
00315             statusForm.Hide();
00316         }
00317 
00318         private void OnLogData(object sender, PartialArrayIntAvailableEventArgs e)
00319         {
00320             switch(e.reportID)
00321             {
00322                 case PartialArrayIntAvailableEventArgs.PACKET_BMP280_PRESSURE:
00323                     if (pressureLog != null && pressureLog.Enable)
00324                         ProcessPressure(e.array1);
00325                     break;
00326                 case PartialArrayIntAvailableEventArgs.PACKET_MAX31725_TEMP1:
00327                     if (temperatureLog1 != null && temperatureLog1.Enable)
00328                         ProcessTemperature1(e.array1);
00329                     break;
00330                 case PartialArrayIntAvailableEventArgs.PACKET_MAX31725_TEMP2:
00331                     if (temperatureLog2 != null && temperatureLog2.Enable)
00332                         ProcessTemperature2(e.array1);
00333                     break;
00334 
00335                 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_ECG:
00336                     if (ecgLog != null && ecgLog.Enable)
00337                         ProcessEcg(e.array1);
00338                     break;
00339                 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_BIOZ:
00340                     if (bioZLog != null && bioZLog.Enable)
00341                         ProcessBioZ(e.array1);
00342                     break;
00343                 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_PACE:
00344                     if (paceLog != null && paceLog.Enable)
00345                         paceData = new PaceData(e.array1);
00346                     break;
00347                 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_RTOR:
00348                     if (rToRLog != null && rToRLog.Enable)
00349                         ProcessRToR(e.array1[0]);
00350                     break;
00351 
00352                 case PartialArrayIntAvailableEventArgs.PACKET_LIS2DH:
00353                 case PartialArrayIntAvailableEventArgs.PACKET_LSM6DS3_ACCEL:
00354                     if (accelerometerLog != null && accelerometerLog.Enable)
00355                         ProcessAccelerometer(e.array1, e.array2, e.array3);
00356                     break;
00357                 case PartialArrayIntAvailableEventArgs.PACKET_END_OF_STREAM:
00358                     LogDownloadStop();
00359                     break;
00360             }
00361 
00362             if ((e.reportID & 0xF0) == PartialArrayIntAvailableEventArgs.PACKET_MAX30101)
00363             {
00364                 if (opticalLog != null && opticalLog.Enable)
00365                     ProcessOptical(e.array1, e.array2, e.array3);
00366 
00367             }
00368         }
00369 
00370         private void OnMissionWrite(object sender, EventArgs e)
00371         {
00372             if (view.Connected)
00373             {
00374                 if (view.EnableAccelerometer || view.EnableBioz || view.EnableEcg || view.EnableOpticalHR 
00375                     || view.EnableOpticalMulti || view.EnableOpticalSpO2 || view.EnablePace 
00376                     || view.EnablePressure || view.EnableRToR || view.EnableTemperature1 || view.EnableTemperature2)
00377                 {
00378                     if (view.ValidateGuiElements())
00379                     {
00380                         statusForm = new StatusForm();
00381                         statusForm.Message = "Please wait while your flash log is cleared and new parameters are written. Do not unplug the USB connection or press start button on the board until write is complete.";
00382                         statusForm.Show();
00383                         formView.MessageInfo("Writing in progress...");
00384                         model.MissionErase();
00385                         model.EraseWrittenSectors();
00386                         model.MissionStartDefinition();
00387                         view.ProcessGuiElements();
00388                         //rpcClient.DataLogging.Test();
00389                         model.MissionWrite();
00390                         statusForm.Hide();
00391                         formView.MessageInfo("Write parameters complete");
00392                     }
00393                     else
00394                         formView.MessageInfo("Incorrect logging parameters");
00395                 }
00396                 else
00397                 {
00398                     formView.MessageInfo("No devices selected");
00399                 }
00400             }
00401         }
00402 
00403         private void OnMissionRead(object sender, EventArgs e)
00404         {
00405             if (view.Connected)
00406             {
00407                 missionRead();
00408             }
00409         }
00410 
00411         private void OnMissionErase(object sender, EventArgs e)
00412         {
00413             if (view.Connected)
00414             {
00415                 model.MissionErase();
00416 
00417                 formView.MessageInfo("Erase parameters complete");
00418             }
00419         }
00420 
00421         private void OnLogFileEnable(object sender, EnableEventArgs e)
00422         {
00423             // Not used
00424         }
00425 
00426         private bool selectFile()
00427         {
00428             bool result = false;
00429 
00430             Mission settings = model.MissionSettings;
00431 
00432             if (settings.EnableEcg)
00433                 result |= selectLogFileName(ecgLog, "hsp-log-ecg");
00434 
00435             if (settings.EnablePace)
00436                 result |= selectLogFileName(paceLog, "hsp-log-pace");
00437 
00438             if (settings.EnableBioZ)
00439                 result |= selectLogFileName(bioZLog, "hsp-log-bioz");
00440 
00441             if (settings.EnableRToR)
00442                 result |= selectLogFileName(rToRLog, "hsp-log-rtor");
00443 
00444             if (settings.EnableOpticalHR || settings.EnableOpticalMulti || settings.EnableOpticalSpO2)
00445                 result |= selectLogFileName(opticalLog, "hsp-log-optical");
00446 
00447             if (settings.EnableTemperature1)
00448                 result |= selectLogFileName(temperatureLog1, "hsp-log-temperature1");
00449 
00450             if (settings.EnableTemperature2)
00451                 result |= selectLogFileName(temperatureLog2, "hsp-log-temperature2");
00452 
00453             if (settings.EnablePressure)
00454                 result |= selectLogFileName(pressureLog, "hsp-log-barometer");
00455 
00456             if (settings.EnableAccelerometer)
00457                 result |= selectLogFileName(accelerometerLog, "hsp-log-accelerometer");
00458 
00459             return result;
00460         }
00461 
00462         bool selectLogFileName(IRawFileLogView log, string name)
00463         {
00464             bool result;
00465 
00466             if (logFileDirectory != null)
00467                 log.FileDirectory = logFileDirectory;
00468 
00469             result = log.SelectCSVFile(name);
00470             log.Enable = result;
00471 
00472             if (result)
00473                 logFileDirectory = log.FileDirectory;
00474 
00475             return result;
00476         }
00477 
00478         private void missionRead()
00479         {
00480             model.MissionRead();
00481             view.UpdateGuiElements(model.MissionSettings);
00482             if (model.MissionSettings.Enable)
00483                 formView.MessageInfo("Read complete");
00484             else
00485                 formView.MessageInfo("No parameters defined");
00486         }
00487 
00488         void ProcessBioZ(int[] rawData)
00489         {
00490             BioZFifo[] bioZFifo;
00491             double[] time = new double[rawData.Length];
00492             double sampleRate = ecgView.SampleRateBioZ;
00493 
00494             bioZFifo = ConvertBioZ(rawData);
00495 
00496             for (int i = 0; i < time.Length; i++ )
00497             {
00498                 time[i] = bioZCount / (double)sampleRate;
00499                 bioZCount++;
00500             }
00501 
00502             bioZLog.DisplayBioZ(time, bioZFifo);
00503         }
00504 
00505         public BioZFifo[] ConvertBioZ(int[] data)
00506         {
00507             BioZFifo[] impedance = new BioZFifo[data.Length];
00508             //EcgView.ChartInfo chartInfo = BioZInfo();
00509             EcgView.ChartInfo chartInfo = ecgView.BioZInfo;
00510 
00511             int dataShift;
00512 
00513             for (int i = 0; i < data.Length; i++)
00514             {
00515                 dataShift = data[i] >> chartInfo.Shift;
00516 
00517                 // Two's Complement Conversions
00518                 if (dataShift > chartInfo.Threshold)
00519                 {
00520                     dataShift -= chartInfo.Offset;
00521                 }
00522 
00523                 // 1.9734 = 1/2^19 * 1e-6
00524                 impedance[i].Data = dataShift * 1.9073486328125 /
00525                     (chartInfo.Gain * ((chartInfo.CurrentGenerator == 0) ? 1 : chartInfo.CurrentGenerator));
00526                 impedance[i].Code = data[i];
00527                 impedance[i].BioZData = dataShift;
00528                 impedance[i].BTag = data[i] & 0x07;
00529             }
00530 
00531             return impedance;
00532         }
00533 
00534         public EcgView.ChartInfo BioZInfo()
00535         {
00536             EcgView.ChartInfo info = new EcgView.ChartInfo();
00537             int[] currentGen = new int[] {1, 8, 16, 32, 48, 64, 80, 96};
00538             int[] gain = new int[] {20, 40, 80, 160};
00539 
00540             info.Shift = 4;
00541             info.Offset = 0x100000;
00542             info.Threshold = 0x100000;
00543             info.Gain = gain[model.MissionSettings.BioZArgs[10]];
00544             info.CurrentGenerator = currentGen[model.MissionSettings.BioZArgs[15]];
00545 
00546             return info;
00547         }
00548 
00549         void ProcessEcg(int[] rawData)
00550         {
00551             EcgFifo[] ecgFifo;
00552             double[] ecgVoltage = new double[rawData.Length];
00553             double[] timeSecond = new double[rawData.Length];
00554             double ecgRate = ecgView.SampleRateEcg;
00555 
00556             ecgFifo = ConvertEcg(rawData);
00557 
00558             for (int i = 0; i < ecgFifo.Length; i++)
00559             {
00560                 timeSecond[i] = count / ecgRate;
00561 
00562                 // Look for Pace Events
00563                 if (paceLog.Enable)
00564                 {
00565                     //for (int j = 0; j < ecgFifo.Length; j++)
00566                     //{
00567                     if (ecgFifo[i].PTag != 7)
00568                     {
00569                         PaceData.PaceRegister paceRegister = paceData.PaceGroup(ecgFifo[i].PTag);
00570                         List<double> timeMillsecondPace = new List<double>();
00571                         List<PaceData.PaceEdge> paceEdges = new List<PaceData.PaceEdge>();
00572 
00573                         for (int k = 0; k < 6; k++)
00574                         {
00575                             PaceData.PaceEdge edge = paceRegister.Edge[k];
00576 
00577                             timeMillsecondPace.Add(count / ecgRate + ConvertPace(edge.Data));
00578                             paceEdges.Add(edge);
00579 
00580                             if (edge.Last == true)
00581                                 break;
00582                         }
00583 
00584                         paceLog.DisplayPace(timeMillsecondPace.ToArray(), paceEdges.ToArray());
00585                         System.Diagnostics.Debug.Print("ECG PTag = " + ecgFifo[i].PTag);
00586                     }
00587                     //}
00588                 }
00589 
00590                 count++;
00591             }
00592 
00593             ecgLog.DisplayEcg(timeSecond, ecgFifo);
00594 
00595         }
00596 
00597         public EcgFifo[] ConvertEcg(int[] data)
00598         {
00599             EcgFifo[] voltage = new EcgFifo[data.Length];
00600             //EcgView.ChartInfo chartInfo = EcgInfo();
00601             EcgView.ChartInfo chartInfo = ecgView.EcgInfo;
00602 
00603             int dataShift;
00604 
00605             for (int i = 0; i < data.Length; i++)
00606             {
00607                 dataShift = data[i] >> chartInfo.Shift;
00608 
00609                 // Two's Complement Conversions
00610                 if (dataShift > chartInfo.Threshold)
00611                 {
00612                     dataShift -= chartInfo.Offset;
00613                 }
00614 
00615                 voltage[i].Data = 1000 * 7.62939453125e-6 * dataShift / chartInfo.Gain;
00616                 voltage[i].EcgData = dataShift;
00617                 voltage[i].Code = data[i];
00618                 voltage[i].PTag = data[i] & 0x07;
00619                 voltage[i].ETag = (data[i] >> 3) & 0x07;
00620             }
00621 
00622             return voltage;
00623         }
00624 
00625         public EcgView.ChartInfo EcgInfo()
00626         {
00627             EcgView.ChartInfo info = new EcgView.ChartInfo();
00628             int[] gain = new int[] {20, 40, 80, 160};
00629 
00630             info.Shift = 6;
00631             info.Threshold = 0x1ffff;
00632             info.Offset = 0x40000;
00633 
00634             info.Gain = gain[model.MissionSettings.EcgArgs[10]];
00635 
00636             return info;
00637         }
00638 
00639         public double ConvertRToR(int data)
00640         {
00641             return ecgView.TimeResolution * 1000 * data * 512;
00642         }
00643 
00644         public double ConvertPace(int data)
00645         {
00646             return data * ecgView.TimeResolution;
00647         }
00648 
00649         public string PaceRegisterGroupToString(PaceData.PaceRegister paceRegister)
00650         {
00651             StringBuilder paceRegisterLogBuilder = new StringBuilder();
00652             for (int j = 0; j < 6; j++)
00653             {
00654                 paceRegisterLogBuilder.Append(paceRegister.Edge[j].Data / (2 * ecgView.MasterClockFrequency));
00655                 paceRegisterLogBuilder.Append(", ");
00656                 paceRegisterLogBuilder.Append(paceRegister.Edge[j].Polarity ? 'R' : 'F');
00657                 paceRegisterLogBuilder.Append(", ");
00658                 paceRegisterLogBuilder.Append(paceRegister.Edge[j].Last ? 'Y' : 'N');
00659                 paceRegisterLogBuilder.Append(", ");
00660             }
00661 
00662             return paceRegisterLogBuilder.ToString();
00663         }
00664 
00665         void ProcessRToR(int data)
00666         {
00667             if (rToRCalculator != null)
00668             {
00669                 if (rToRFirst)
00670                 {
00671                     rToRLog.DisplayRToR(data, rToRCalculator.Corrected(data, true) / 1000);
00672                     rToRFirst = false;
00673                 }
00674                 else
00675                     rToRLog.DisplayRToR(data, rToRCalculator.Corrected(data, false) / 1000);
00676             }
00677             else
00678             {
00679                 rToRLog.DisplayRToR(data, 0);
00680             }
00681         }
00682 
00683         public void ProcessOptical(int[] red, int[] ir, int[] green)
00684         {
00685             int sampleRate = opticalView.OpticalSampleRate;
00686             double[] time = new double[red.Length];
00687 
00688             for (int i = 0; i < time.Length; i++ )
00689             {
00690                 time[i] = ppgCount / (double)sampleRate;
00691                 ppgCount++;
00692             }
00693 
00694             opticalLog.DisplayPpg(time, new int[][] { red, ir, green });
00695         }
00696 
00697         public void ProcessAccelerometer(int[] x, int[] y, int[] z)
00698         {
00699             int sampleRate = view.AccelSampleRate;
00700             double[] time = new double[x.Length];
00701 
00702             for (int i = 0; i < time.Length; i++)
00703             {
00704                 time[i] = accelCount / (double)sampleRate;
00705                 accelCount++;
00706             }
00707 
00708             accelerometerLog.DisplayXYZ(time, new int[][] { x, y, z });
00709         }
00710     }
00711 }