Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RawFileLogView.cs Source File

RawFileLogView.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 Maxim.Utility;
00042 using HealthSensorPlatform.Model;
00043 
00044 namespace HealthSensorPlatform.View
00045 {
00046     class RawFileLogView : FileLog, IRawFileLogView
00047     {
00048         /* Fields */
00049         private bool enable = false;
00050         //private double sampleRate = 0;
00051         //private int count = 0;
00052 
00053         /* Constructors */
00054 
00055         /* Events */
00056         public new event EventHandler<Maxim.Global.ErrorEventArgs> Error;
00057 
00058         /* Properties */
00059         public bool Enable
00060         {
00061             get
00062             {
00063                 return enable;
00064             }
00065             set
00066             {
00067                 enable = value;
00068                 if (enable == false)
00069                     Close();
00070             }
00071         }
00072 
00073         /* Methods */
00074         public void StreamStartStop()
00075         {
00076         }
00077 
00078         public void DisplayEcg(double[] time, EcgFifo[] ecgData)
00079         {
00080             DisplayEcg(time, ecgData, null);
00081         }
00082 
00083         public void DisplayEcg(double[] time, EcgFifo[] ecgData, DCLeadOff leadOff)
00084         {
00085             StringBuilder sb = new StringBuilder();
00086 
00087             for (int i = 0; i < ecgData.Length; i++)
00088             {
00089                 sb.Append(time[i]);
00090                 sb.Append(", ");
00091                 sb.Append(ecgData[i].EcgData);
00092                 sb.Append(", ");
00093                 sb.Append(ecgData[i].ETag);
00094                 sb.Append(", ");
00095                 sb.Append(ecgData[i].PTag);
00096                 sb.Append(", ");
00097                 sb.Append(ecgData[i].Data);
00098                 sb.Append(", ");
00099 
00100                 if (leadOff != null)
00101                 {
00102                     sb.Append(leadOff.PostiveHigh ? 1 : 0); 
00103                     sb.Append(", ");
00104                     sb.Append(leadOff.PostiveLow ? 1 : 0); 
00105                     sb.Append(", ");
00106                     sb.Append(leadOff.NegativeHigh ? 1 : 0);
00107                     sb.Append(", ");
00108                     sb.Append(leadOff.NegativeLow ? 1 : 0);
00109                 }
00110 
00111 
00112                 if (i != ecgData.Length - 1)
00113                     sb.Append(Environment.NewLine);
00114             }
00115 
00116             WriteLine(sb.ToString());
00117 
00118         }
00119 
00120         public void DisplayBioZ(double[] time, BioZFifo[] bioZData)
00121         {
00122             DisplayBioZ(time, bioZData, null, null);
00123         }
00124 
00125         public void DisplayBioZ(double[] time, BioZFifo[] bioZData, DCLeadOff leadOff)
00126         {
00127             DisplayBioZ(time, bioZData, leadOff, null);
00128         }
00129 
00130         public void DisplayBioZ(double[] time, BioZFifo[] bioZData, ACLeadOff acLeadOff)
00131         {
00132             DisplayBioZ(time, bioZData, null, acLeadOff);
00133         }
00134 
00135         public void DisplayBioZ(double[] time, BioZFifo[] bioZData, DCLeadOff leadOff, ACLeadOff acLeadOff)
00136         {
00137              StringBuilder sb = new StringBuilder();
00138 
00139             for (int i = 0; i < bioZData.Length; i++)
00140             {
00141                 sb.Append(time[i]);
00142                 sb.Append(", ");
00143                 sb.Append(bioZData[i].BioZData);
00144                 sb.Append(", ");
00145                 sb.Append(bioZData[i].BTag);
00146                 sb.Append(", ");
00147                 sb.Append(bioZData[i].Data);
00148                 sb.Append(", ");
00149 
00150                 if (leadOff != null)
00151                 {
00152                     sb.Append(leadOff.PostiveHigh ? 1 : 0);
00153                     sb.Append(", ");
00154                     sb.Append(leadOff.PostiveLow ? 1 : 0);
00155                     sb.Append(", ");
00156                     sb.Append(leadOff.NegativeHigh ? 1 : 0);
00157                     sb.Append(", ");
00158                     sb.Append(leadOff.NegativeLow ? 1 : 0);
00159                     sb.Append(", ");
00160                 }
00161                 else
00162                     sb.Append(", , , ,");
00163 
00164                 if (acLeadOff != null)
00165                 {
00166                     sb.Append(acLeadOff.BioZOverRange ? 1 : 0);
00167                     sb.Append(", ");
00168                     sb.Append(acLeadOff.BioZUnderRange ? 1 : 0);
00169                     sb.Append(", ");
00170                 }
00171 
00172                 if (i != bioZData.Length - 1)
00173                     sb.Append(Environment.NewLine);
00174             }
00175 
00176             WriteLine(sb.ToString());
00177 
00178         }
00179 
00180         public void DisplayRToR(int rToRData, double rToRCorrectedSeconds)
00181         {
00182             StringBuilder sb = new StringBuilder();
00183 
00184             sb.Append(rToRData);
00185             sb.Append(", ");
00186             sb.Append(rToRCorrectedSeconds);
00187 
00188             WriteLine(sb.ToString());
00189         }
00190 
00191         public void DisplayPace(double[] time, PaceData.PaceEdge[] paceData)
00192         {
00193             StringBuilder sb = new StringBuilder();
00194 
00195             for (int i = 0; i < time.Length; i++)
00196             {
00197                 sb.Append(time[i]);
00198                 sb.Append(", ");
00199                 sb.Append(paceData[i].Data);
00200                 sb.Append(", ");
00201                 sb.Append(paceData[i].Polarity ? 'R' : 'F');
00202                 sb.Append(", ");
00203                 sb.Append(paceData[i].Last ? '1' : '0');
00204 
00205                 if (i != time.Length - 1)
00206                     sb.Append(Environment.NewLine);
00207 
00208             }
00209 
00210             WriteLine(sb.ToString());
00211         }
00212 
00213         public void DisplayPressure(int[] hexTemperature, double[] temperature, int[] hexPressure, double[] pressure)
00214         {
00215             StringBuilder sb = new StringBuilder();
00216 
00217             for (int i = 0; i < hexTemperature.Length; i++)
00218             {
00219                 sb.Append(hexTemperature[i]);
00220                 sb.Append(", ");
00221                 sb.Append(temperature[i]);
00222                 sb.Append(", ");
00223                 sb.Append(hexPressure[i]);
00224                 sb.Append(", ");
00225                 sb.Append(pressure[i]);
00226                 sb.Append(", ");
00227 
00228                 if (i != hexTemperature.Length - 1)
00229                     sb.Append(Environment.NewLine);
00230             }
00231 
00232             WriteLine(sb.ToString());
00233         }
00234 
00235         public void DisplayTemperature(int[] hex, double[] temperature)
00236         {
00237             StringBuilder sb = new StringBuilder();
00238 
00239             for (int i = 0; i < hex.Length; i++)
00240             {
00241                 sb.Append(hex[i]);
00242                 sb.Append(", ");
00243                 sb.Append(temperature[i].ToString("F3"));
00244 
00245                 if (i != hex.Length - 1)
00246                     sb.Append(Environment.NewLine);
00247             }
00248 
00249             WriteLine(sb.ToString());
00250         }
00251 
00252         public void DisplayPpg(double[] time, int[][] data)
00253         {
00254             StringBuilder strBuilder = new StringBuilder();
00255 
00256             int channelCount = 0;
00257 
00258             int[] data1 = data[0];
00259             int[] data2 = data[1];
00260             int[] data3 = data[2];
00261             //int[] data4 = data[3];
00262 
00263             //if (data4.Length != 0)
00264             //    channelCount = 4;
00265             if (data3.Length != 0)
00266                 channelCount = 3;
00267             else if (data2.Length != 0)
00268                 channelCount = 2;
00269             else if (data1.Length != 0)
00270                 channelCount = 1;
00271 
00272             for (int i = 0; i < data1.Length; i++)
00273             {
00274                 strBuilder.Append(time[i]);
00275                 strBuilder.Append(",");
00276                 for (int j = 0; j < channelCount; j++)
00277                 {
00278                     //strBuilder.Append(data[j][i] & 0x7FFFF); // Data Code
00279                     //strBuilder.Append(",");
00280                     //strBuilder.Append(data[j][i] >> 19); // DAC code
00281                     //strBuilder.Append(data[j][i] & 0x7FFFF); // Data Code
00282                     strBuilder.Append(data[j][i]);
00283                     strBuilder.Append(",");
00284                 }
00285                 WriteLine(strBuilder.ToString());
00286                 strBuilder.Clear();
00287             }
00288         }
00289 
00290         public void DisplayPpg(int[][] data)
00291         {
00292             long time = DateTime.Now.Ticks;
00293             long startTime = DateTime.Now.Ticks;
00294             string timeStr;
00295             StringBuilder strBuilder = new StringBuilder();
00296 
00297             int channelCount = 0;
00298 
00299             //string datetime = string.Format("{0:HH-mm-ss.fff}", DateTime.Now) + ", "; 
00300             timeStr = ((time - startTime) / 10000000.0).ToString() + ", ";
00301 
00302             int[] data1 = data[0];
00303             int[] data2 = data[1];
00304             int[] data3 = data[2];
00305             //int[] data4 = data[3];
00306 
00307             //if (data4.Length != 0)
00308             //    channelCount = 4;
00309             if (data3.Length != 0)
00310                 channelCount = 3;
00311             else if (data2.Length != 0)
00312                 channelCount = 2;
00313             else if (data1.Length != 0)
00314                 channelCount = 1;
00315 
00316             for (int i = 0; i < data1.Length; i++)
00317             {
00318                 strBuilder.Append(timeStr);
00319                 for (int j = 0; j < channelCount; j++)
00320                 {
00321                     //strBuilder.Append(data[j][i] & 0x7FFFF); // Data Code
00322                     //strBuilder.Append(",");
00323                     //strBuilder.Append(data[j][i] >> 19); // DAC code
00324                     //strBuilder.Append(data[j][i] & 0x7FFFF); // Data Code
00325                     strBuilder.Append(data[j][i]);
00326                     strBuilder.Append(",");
00327                 }
00328                 WriteLine(strBuilder.ToString());
00329                 strBuilder.Clear();
00330             }
00331 
00332         }
00333 
00334         public void DisplayXYZ(double[] time, int[][] data)
00335         {
00336             StringBuilder strBuilder = new StringBuilder();
00337 
00338             int[] data1 = data[0];
00339             int[] data2 = data[1];
00340             int[] data3 = data[2];
00341             //int[] data4 = data[3];
00342 
00343             for (int i = 0; i < data3.Length; i++)
00344             {
00345                 strBuilder.Append(time[i]);
00346                 strBuilder.Append(",");
00347                 strBuilder.Append(data[0][i]);
00348                 strBuilder.Append(",");
00349                 strBuilder.Append(data[1][i]);
00350                 strBuilder.Append(",");
00351                 strBuilder.Append(data[2][i]);
00352 
00353                 WriteLine(strBuilder.ToString());
00354                 strBuilder.Clear();
00355             }
00356         }
00357 
00358         public void DisplayXYZ(int[][] data)
00359         {
00360             long time = DateTime.Now.Ticks;
00361             long startTime = DateTime.Now.Ticks;
00362             string timeStr;
00363             StringBuilder strBuilder = new StringBuilder();
00364 
00365             //string datetime = string.Format("{0:HH-mm-ss.fff}", DateTime.Now) + ", "; 
00366             timeStr = ((time - startTime) / 10000000.0).ToString() + ", ";
00367 
00368             int[] data1 = data[0];
00369             int[] data2 = data[1];
00370             int[] data3 = data[2];
00371             //int[] data4 = data[3];
00372 
00373             for (int i = 0; i < data3.Length; i++)
00374             {
00375                 strBuilder.Append(time);
00376                 strBuilder.Append(data[0][i]);
00377                 strBuilder.Append(",");
00378                 strBuilder.Append(data[1][i]);
00379                 strBuilder.Append(",");
00380                 strBuilder.Append(data[2][i]);
00381 
00382                 WriteLine(strBuilder.ToString());
00383                 strBuilder.Clear();
00384             }
00385         }
00386     }
00387 }