Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EcgTest.cs Source File

EcgTest.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 NUnit.Framework;
00038 using HealthSensorPlatform.CustomControls;
00039 using RPCSupport.Streaming;
00040 using System.Windows.Forms;
00041 using System.Collections.Generic;
00042 using System.Linq;
00043 using System.Text;
00044 using System.Threading.Tasks;
00045 
00046 using HealthSensorPlatform.Presenter;
00047 
00048 namespace EcgViewTest
00049 {
00050     [TestFixture]
00051     public partial class EcgTest
00052     {
00053         /*
00054         [Test]
00055         public void CalculationTest()
00056         {
00057             double[] result;
00058 
00059             Form form = new Form();
00060             EcgView ecgView = new EcgView();
00061             int[] ecgData = new int[] { 0, 1000 << 6, 226759, 159111, 8388544, 8388608};
00062 
00063             form.Controls.Add(ecgView);
00064             result = ecgView.UpdateChart(EcgView.StreamDataType.Ecg, ecgData);
00065 
00066             // millivolts
00067             Assert.AreEqual(0, result[0], 1e-3);
00068             Assert.AreEqual(0.38147, result[1], 1e-3);
00069             Assert.AreEqual(1.351547, result[2], 1e-3);
00070             Assert.AreEqual(0.948334, result[3], 1e-2);
00071             Assert.AreEqual(49.99962, result[4], 1e-2);
00072             Assert.AreEqual(-50, result[5], 1e-2);
00073         }
00074 
00075         [Test]
00076         public void CalculationTest1()
00077         {
00078             double[] result;
00079 
00080             Form form = new Form();
00081             EcgView ecgView = new EcgView();
00082             int[] ecgData = new int[] { 226759, 159111, 8388544, 8388608 };
00083 
00084             form.Controls.Add(ecgView);
00085             result = ecgView.UpdateChart(EcgView.StreamDataType.Ecg, ecgData);
00086 
00087             // milliovolts
00088             Assert.AreEqual(1.351547, result[0], 1e-3);
00089 
00090         }
00091         */
00092 
00093         [Test]
00094         public void EcgCalculationTest()
00095         {
00096             EcgView ecgView = new EcgView();
00097             StreamPresenter sp = new StreamPresenter(ecgView);
00098             double[] result;
00099             int[] ecgData = new int[] { 0 | 7, 1000 << 6 | 7, 226759, 159119 | 7, 8388547 | 7, 8388607 | 7 };
00100 
00101             result = sp.ProcessEcg(ecgData);
00102 
00103             // millivolts
00104             Assert.AreEqual(0, result[0], 1e-3);
00105             Assert.AreEqual(ecgEquation(ecgData[1] >> 6), result[1], 1e-3);
00106             Assert.AreEqual(ecgEquation(ecgData[2] >> 6), result[2], 1e-3);
00107             Assert.AreEqual(ecgEquation(ecgData[3] >> 6), result[3], 1e-2);
00108             Assert.AreEqual(ecgEquation(ecgData[4] >> 6), result[4], 1e-2);
00109             Assert.AreEqual(ecgEquation(ecgData[5] >> 6), result[5], 1e-2);
00110         }
00111 
00112         double ecgEquation(double data)
00113         {
00114             return 1000 * 7.62939453125e-6 * data / 20;
00115         }
00116 
00117         /*
00118 
00119         [TestCase(0x80, 60)]
00120         [TestCase(0xff, 30.118)]
00121         [TestCase(0x01, 7680)]
00122         [TestCase(0xaa, 45.176)]
00123         public void RToRCalculationTest(int rToR, double bpm)
00124         {
00125             double result;
00126 
00127             EcgView ecgView = new EcgView();
00128             InitArgs.EcgInitStart ecgInit = new InitArgs.EcgInitStart();
00129 
00130             ecgView.ecgArgs = ecgInit;
00131 
00132             result = ecgView.RToRBeatsPerMinute(rToR);
00133 
00134             Assert.AreEqual(bpm, result, 1e-2);
00135         }
00136 
00137         [TestCase(0x80, 58.594)]
00138         [TestCase(0xff, 29.412)]
00139         [TestCase(0x01, 7500)]
00140         [TestCase(0xaa, 44.1176)]
00141         public void RToRCalculationTest1(int rToR, double bpm)
00142         {
00143             double result;
00144 
00145             EcgView ecgView = new EcgView();
00146             InitArgs.EcgInitStart ecgInit = new InitArgs.EcgInitStart();
00147 
00148             ecgView.ecgArgs = ecgInit;
00149 
00150             ecgView.FrequencyMasterField = 1;
00151 
00152             result = ecgView.RToRBeatsPerMinute(rToR);
00153 
00154             Assert.AreEqual(bpm, result, 1e-2);
00155         }
00156 
00157         [TestCase(0x80, 58.594)]
00158         [TestCase(0xff, 29.412)]
00159         [TestCase(0x01, 7500)]
00160         [TestCase(0xaa, 44.1176)]
00161         public void RToRCalculationTest2(int rToR, double bpm)
00162         {
00163             double result;
00164 
00165             EcgView ecgView = new EcgView();
00166             InitArgs.EcgInitStart ecgInit = new InitArgs.EcgInitStart();
00167 
00168             ecgView.ecgArgs = ecgInit;
00169 
00170             ecgView.FrequencyMasterField = 2;
00171 
00172             result = ecgView.RToRBeatsPerMinute(rToR);
00173 
00174             Assert.AreEqual(bpm, result, 1e-2);
00175         }
00176 
00177         [TestCase(0x80, 58.535)]
00178         [TestCase(0xff, 29.382)]
00179         [TestCase(0x01, 7492.5)]
00180         [TestCase(0xaa, 44.0735)]
00181         public void RToRCalculationTest3(int rToR, double bpm)
00182         {
00183             double result;
00184 
00185             EcgView ecgView = new EcgView();
00186             InitArgs.EcgInitStart ecgInit = new InitArgs.EcgInitStart();
00187 
00188             ecgView.ecgArgs = ecgInit;
00189 
00190             ecgView.FrequencyMasterField = 3;
00191 
00192             result = ecgView.RToRBeatsPerMinute(rToR);
00193 
00194             Assert.AreEqual(bpm, result, 1e-2);
00195         }
00196         */
00197     }
00198 }