Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PaceData.cs Source File

PaceData.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 namespace HealthSensorPlatform.Model
00042 {
00043     /// <summary>
00044     /// Store and parse all the Pace burst read data
00045     /// </summary>
00046     public class PaceData 
00047     {
00048         private PaceRegister[] Group = new PaceRegister[6];
00049 
00050         /// <summary>
00051         /// Raw pace data from HSP firmware
00052         /// </summary>
00053         /// <param name="rawData"></param>
00054         public PaceData(int[] rawData)
00055         {
00056             if (rawData.Length == 18)
00057             {
00058                 for (int i = 0; i < 6; i++)
00059                 {
00060                     Group[i] = new PaceRegister(new int[] { rawData[3 * i + 0], rawData[3 * i + 1], rawData[3 * i + 2] });
00061                 }
00062             }
00063             else
00064             {
00065                 throw new InvalidOperationException("Pace register group expects array length of 18.");
00066             }
00067         }
00068 
00069         /// <summary>
00070         /// Calculate the time between first pace event and last event
00071         /// </summary>
00072         /// <param name="group"></param>
00073         /// <returns>Time count unit difference. To obtain the time value multiply the count by PACE_RES = 1/FPACE</returns>
00074         public int PaceLength(int group)
00075         {
00076             int start = 0, stop = 0;
00077             int sign = 1;
00078 
00079             start = Group[group].Edge[0].Data;
00080             sign = Group[group].Edge[0].Polarity == true ? 1 : -1;
00081 
00082             foreach (PaceEdge time in Group[group].Edge)
00083             {
00084                 if (time.Last == true)
00085                 {
00086                     stop = time.Data;
00087                     break;
00088                 }
00089             }
00090 
00091             return sign * (stop - start);
00092         }
00093 
00094         public PaceRegister PaceGroup(int group)
00095         {
00096             return Group[group];
00097         }
00098 
00099         public string GroupToString(int group)
00100         {
00101             StringBuilder sb = new StringBuilder();
00102 
00103             foreach (PaceEdge pe in Group[group].Edge)
00104             {
00105                 sb.Append(pe.Data);
00106                 sb.Append(", ");
00107                 sb.Append(pe.Polarity ? 'R' : 'F');
00108                 sb.Append(", ");
00109                 sb.Append(pe.Last ? 'Y' : 'N');
00110                 sb.Append(", ");
00111             }
00112 
00113             return sb.ToString();
00114         }
00115 
00116         public static string GroupEmptyString()
00117         {
00118             return "0, R, Y, 0, R, Y, 0, R, Y, 0, R, Y, 0, R, Y, 0, R, Y";
00119         }
00120 
00121 
00122         ///// Inner classes of PaceData ////
00123 
00124         /// <summary>
00125         /// Pace edge information
00126         /// </summary>
00127         public class PaceEdge
00128         {
00129             public int Data;
00130             public bool Polarity;
00131             public bool Last;
00132 
00133             public PaceEdge(int data)
00134             {
00135                 Data = data >> 2;
00136                 Polarity = ((data & 0x02) >> 1) == 1 ? true : false;
00137                 Last = ((data & 0x01) >> 0) == 1 ? true : false;
00138             }
00139         }
00140 
00141         /// <summary>
00142         /// Pace register information, each pace register contains up to 6 pace edge events
00143         /// </summary>
00144         public class PaceRegister
00145         {
00146             private PaceEdge[] Bytes = new PaceEdge[6];
00147 
00148             public PaceEdge[] Edge
00149             {
00150                 get { return Bytes; }
00151             }
00152 
00153             public PaceRegister(int[] groupData)
00154             {
00155                 if (groupData.Length == 3)
00156                 {
00157                     for (int i = 0; i < 3; i++)
00158                     {
00159                         Bytes[2 * i] = new PaceEdge(groupData[i] >> 12);
00160                         Bytes[2 * i + 1] = new PaceEdge(groupData[i] & 0xFFF);
00161                     }
00162                 }
00163             }
00164         }
00165     }
00166 }