Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX30101Test.cs Source File

MAX30101Test.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.Threading;
00038 using System.Windows.Forms;
00039 using System.Diagnostics;
00040 using NUnit.Framework;
00041 using Moq;
00042 
00043 using RPCSupport;
00044 using RPCSupport.Devices;
00045 
00046 namespace RPCSupportTest
00047 {
00048     //[TestFixture, RequiresThread]
00049     [TestFixture]
00050     [Property("Class", "MAX30101")]
00051     class MAX30101Test
00052     {
00053         RPCClient rpcClient;
00054         MAX30101 max30101;
00055 
00056         int[] avg = new int[] { 1, 2, 4, 8, 16, 32 };
00057         int[] sr = new int[] { 50, 100, 200, 400 };
00058 
00059         double minFactor = 0.75;
00060         double maxFactor = 1;
00061         int timeSleep = 10000;
00062 
00063         [TestFixtureSetUp]
00064         public void Init()
00065         {
00066             rpcClient = new RPCClient(RPCClient.ePipeline.eSerialWrap);
00067             rpcClient.InitPipeline();
00068             rpcClient.Connect(ComPort.Port);
00069             //rpcClient.Pipeline.Discard();
00070             max30101 = rpcClient.Init_MAX30101(0xAE);
00071             //rpcClient.streaming.Init(rpcClient.Pipeline);
00072 
00073             //rpcClient.Version();
00074         }
00075 
00076         [TestFixtureTearDown]
00077         public void Dispose()
00078         {
00079             rpcClient.Disconnect();
00080             rpcClient.streaming.Stop();
00081             Thread.Sleep(100);
00082         }
00083 
00084         [TestCase(0, 0)]
00085         [TestCase(0, 1)]
00086         [TestCase(0, 2)]
00087         [TestCase(0, 3)]
00088         [TestCase(1, 0)]
00089         [TestCase(1, 1)]
00090         [TestCase(1, 2)]
00091         [TestCase(1, 3)]
00092         [TestCase(2, 0)]
00093         [TestCase(2, 1)]
00094         [TestCase(2, 2)]
00095         [TestCase(2, 3)]
00096         //[TestCase(3, 0)]
00097         [TestCase(3, 1)]
00098         [TestCase(3, 2)]
00099         [TestCase(3, 3)]
00100         //[TestCase(4, 0)]
00101         //[TestCase(4, 1)]
00102         [TestCase(4, 2)]
00103         [TestCase(4, 3)]
00104         //[TestCase(5, 0)]
00105         //[TestCase(5, 1)]
00106         //[TestCase(5, 2)]
00107         [TestCase(5, 3)]
00108         public void HRModeTest(byte sampleAverage, byte sampleRate)
00109         {
00110             HRModeTest(sampleAverage, sampleRate, 3000);
00111         }
00112 
00113         [TestCase(3, 0, 4000)]
00114         [TestCase(4, 0, 8000)]
00115         [TestCase(4, 1, 4000)]
00116         [TestCase(5, 0, 12000)]
00117         [TestCase(5, 1, 8000)]
00118         [TestCase(5, 2, 4000)]
00119         public void HRModeTest(byte sampleAverage, byte sampleRate, int sleepMilliSecond)
00120         {
00121             Mock<IPlotView> plotView;
00122             plotView = new Mock<IPlotView>();
00123             StreamHelper streamHelper = new StreamHelper(rpcClient, plotView.Object);
00124 
00125             rpcClient.MAX30101.HRmode_init(0x0f, sampleAverage, sampleRate, 3, 0x33, (byte)(0 + 4));
00126             Thread.Sleep(sleepMilliSecond);
00127             rpcClient.MAX30101.HRmode_stop();
00128 
00129             Application.DoEvents();
00130 
00131             plotView.Verify(p => p.Display(It.IsAny<int[]>()), Times.AtLeast(1));
00132         }
00133 
00134         [TestCase(0, 0)]
00135         [TestCase(0, 1)]
00136         [TestCase(0, 2)]
00137         [TestCase(0, 3)]
00138         [TestCase(1, 0)]
00139         [TestCase(1, 1)]
00140         [TestCase(1, 2)]
00141         [TestCase(1, 3)]
00142         [TestCase(2, 0)]
00143         [TestCase(2, 1)]
00144         [TestCase(2, 2)]
00145         [TestCase(2, 3)]
00146         //[TestCase(3, 0)]
00147         [TestCase(3, 1)]
00148         [TestCase(3, 2)]
00149         [TestCase(3, 3)]
00150         //[TestCase(4, 0)]
00151         //[TestCase(4, 1)]
00152         [TestCase(4, 2)]
00153         [TestCase(4, 3)]
00154         //[TestCase(5, 0)]
00155         //[TestCase(5, 1)]
00156         //[TestCase(5, 2)]
00157         [TestCase(5, 3)]
00158         public void SpO2ModeTest(byte sampleAverage, byte sampleRate)
00159         {
00160             SpO2ModeTest(sampleAverage, sampleRate, 3000);
00161         }
00162 
00163         [TestCase(3, 0, 4000)]
00164         [TestCase(4, 0, 8000)]
00165         [TestCase(4, 1, 4000)]
00166         [TestCase(5, 0, 12000)]
00167         [TestCase(5, 1, 8000)]
00168         [TestCase(5, 2, 4000)]
00169         public void SpO2ModeTest(byte sampleAverage, byte sampleRate, int sleepMillisecond)
00170         {
00171             Mock<IPlotView> plotView = new Mock<IPlotView>();
00172             StreamHelper streamHelper = new StreamHelper(rpcClient, plotView.Object);
00173 
00174             rpcClient.MAX30101.SpO2mode_init(0x0f, sampleAverage, sampleRate, 3, 0x33, 0x33, (byte)(sampleRate + 4));
00175             Thread.Sleep(sleepMillisecond);
00176             rpcClient.MAX30101.SpO2mode_stop();
00177 
00178             Application.DoEvents();
00179 
00180             plotView.Verify(p => p.Display(It.IsAny<int[]>()), Times.AtLeast(1));
00181         }
00182 
00183 
00184         [TestCase(0, 0)]
00185         [TestCase(0, 1)]
00186         [TestCase(0, 2)]
00187         [TestCase(0, 3)]
00188         [TestCase(1, 0)]
00189         [TestCase(1, 1)]
00190         [TestCase(1, 2)]
00191         [TestCase(1, 3)]
00192         [TestCase(2, 0)]
00193         [TestCase(2, 1)]
00194         [TestCase(2, 2)]
00195         [TestCase(2, 3)]
00196         //[TestCase(3,0)]
00197         [TestCase(3, 1)]
00198         [TestCase(3, 2)]
00199         [TestCase(3, 3)]
00200         //[TestCase(4, 0)]
00201         //[TestCase(4, 1)]
00202         [TestCase(4, 2)]
00203         [TestCase(4, 3)]
00204         //[TestCase(5, 0)]
00205         //[TestCase(5, 1)]
00206         //[TestCase(5, 2)]
00207         [TestCase(5, 3)]
00208         public void MultiModeTest(byte sampleAverage, byte sampleRate)
00209         {
00210             MultiModeTest(sampleAverage, sampleRate, 3000);
00211         }
00212 
00213         [TestCase(3, 0, 4000)]
00214         [TestCase(4, 0, 8000)]
00215         [TestCase(4, 1, 4000)]
00216         [TestCase(5, 0, 12000)]
00217         [TestCase(5, 1, 8000)]
00218         [TestCase(5, 2, 4000)]
00219         public void MultiModeTest(byte sampleAverage, byte sampleRate, int sleepMilliSecond)
00220         {
00221                         Mock<IPlotView> plotView = new Mock<IPlotView>();
00222             StreamHelper streamHelper = new StreamHelper(rpcClient, plotView.Object);
00223 
00224             rpcClient.MAX30101.Multimode_init(0x0f, sampleAverage, sampleRate, 0, 0x33, 0x33, 0x33, 1, 2, 3, 0, (byte)(sampleRate + 4));
00225             Thread.Sleep(sleepMilliSecond);
00226             rpcClient.MAX30101.Multimode_stop();
00227 
00228             Application.DoEvents();
00229 
00230             plotView.Verify(p => p.Display(It.IsAny<int[]>()), Times.AtLeast(1));
00231         }
00232 
00233         [TestCase(0, 0)]
00234         [TestCase(0, 1)]
00235         [TestCase(0, 2)]
00236         [TestCase(0, 3)]
00237         [TestCase(1, 0)]
00238         [TestCase(1, 1)]
00239         [TestCase(1, 2)]
00240         [TestCase(1, 3)]
00241         [TestCase(2, 0)]
00242         [TestCase(2, 1)]
00243         [TestCase(2, 2)]
00244         [TestCase(2, 3)]
00245         [TestCase(3, 0)]
00246         [TestCase(3, 1)]
00247         [TestCase(3, 2)]
00248         [TestCase(3, 3)]
00249         //[TestCase(4, 0)]
00250         [TestCase(4, 1)]
00251         [TestCase(4, 2)]
00252         [TestCase(4, 3)]
00253         //[TestCase(5, 0)]
00254         //[TestCase(5, 1)]
00255         [TestCase(5, 2)]
00256         [TestCase(5, 3)]
00257         public void HRModePointsTest(byte sampleAverage, byte sampleRate)
00258         {
00259             Stopwatch sw = new Stopwatch();
00260             PlotView plotView = new PlotView();
00261             StreamHelper streamHelper = new StreamHelper(rpcClient, plotView);
00262 
00263             rpcClient.MAX30101.HRmode_init(0x0f, sampleAverage, sampleRate, 3, 0x33, (byte)(0 + 4));
00264             sw.Start();
00265             Thread.Sleep(timeSleep);
00266             rpcClient.MAX30101.HRmode_stop();
00267             sw.Stop();
00268 
00269             Application.DoEvents();
00270 
00271             Console.WriteLine("Points: " + plotView.Points + "Time: " + sw.ElapsedMilliseconds / 1000.0);
00272             Assert.That(plotView.Points, Is.GreaterThan(minFactor * sw.ElapsedMilliseconds / 1000 * sr[sampleRate] / avg[sampleAverage]));
00273             Assert.That(plotView.Points, Is.LessThan(maxFactor * sw.ElapsedMilliseconds / 1000 * sr[sampleRate] / avg[sampleAverage]));
00274         }
00275 
00276         [TestCase(0, 0)]
00277         [TestCase(0, 1)]
00278         [TestCase(0, 2)]
00279         [TestCase(0, 3)]
00280         [TestCase(1, 0)]
00281         [TestCase(1, 1)]
00282         [TestCase(1, 2)]
00283         [TestCase(1, 3)]
00284         [TestCase(2, 0)]
00285         [TestCase(2, 1)]
00286         [TestCase(2, 2)]
00287         [TestCase(2, 3)]
00288         [TestCase(3, 0)]
00289         [TestCase(3, 1)]
00290         [TestCase(3, 2)]
00291         [TestCase(3, 3)]
00292         //[TestCase(4, 0)]
00293         [TestCase(4, 1)]
00294         [TestCase(4, 2)]
00295         [TestCase(4, 3)]
00296         //[TestCase(5, 0)]
00297         //[TestCase(5, 1)]
00298         [TestCase(5, 2)]
00299         [TestCase(5, 3)]
00300         public void SpO2ModePointsTest(byte sampleAverage, byte sampleRate)
00301         {
00302             //ManualResetEvent eventRasied = new ManualResetEvent(false);
00303             Stopwatch sw = new Stopwatch();
00304             PlotView plotView = new PlotView();
00305             StreamHelper streamHelper = new StreamHelper(rpcClient, plotView);
00306 
00307             //rpcClient.streaming.PartialArrayIntAvailable += (sender, e) => { eventRasied.Set(); };
00308 
00309             rpcClient.MAX30101.SpO2mode_init(0x0f, sampleAverage, sampleRate, 3, 0x33, 0x33, (byte)(sampleRate + 4));
00310             sw.Start();
00311             Thread.Sleep(timeSleep);
00312             rpcClient.MAX30101.SpO2mode_stop();
00313             sw.Stop();
00314 
00315             Application.DoEvents();
00316 
00317             Console.WriteLine("Points: " + plotView.Points + "Time: " + sw.ElapsedMilliseconds / 1000.0);
00318             Assert.That(plotView.Points, Is.GreaterThan(minFactor * sw.ElapsedMilliseconds / 1000 * sr[sampleRate] / avg[sampleAverage]));
00319             Assert.That(plotView.Points, Is.LessThan(maxFactor * sw.ElapsedMilliseconds / 1000 * sr[sampleRate] / avg[sampleAverage]));
00320             //Assert.IsTrue(eventRasied.WaitOne(10000));
00321         }
00322 
00323         [TestCase(0, 0)]
00324         [TestCase(0, 1)]
00325         [TestCase(0, 2)]
00326         [TestCase(0, 3)]
00327         [TestCase(1, 0)]
00328         [TestCase(1, 1)]
00329         [TestCase(1, 2)]
00330         [TestCase(1, 3)]
00331         [TestCase(2, 0)]
00332         [TestCase(2, 1)]
00333         [TestCase(2, 2)]
00334         [TestCase(2, 3)]
00335         [TestCase(3, 0)]
00336         [TestCase(3, 1)]
00337         [TestCase(3, 2)]
00338         [TestCase(3, 3)]
00339         //[TestCase(4, 0)]
00340         [TestCase(4, 1)]
00341         [TestCase(4, 2)]
00342         [TestCase(4, 3)]
00343         //[TestCase(5, 0)]
00344         //[TestCase(5, 1)]
00345         [TestCase(5, 2)]
00346         [TestCase(5, 3)]
00347         public void MultiModePointsTest(byte sampleAverage, byte sampleRate)
00348         {
00349             Stopwatch sw = new Stopwatch();
00350             PlotView plotView = new PlotView();
00351             StreamHelper streamHelper = new StreamHelper(rpcClient, plotView);
00352 
00353             rpcClient.MAX30101.Multimode_init(0x0f, sampleAverage, sampleRate, 0, 0x33, 0x33, 0x33, 1, 2, 3, 0, (byte)(sampleRate + 4));
00354             sw.Start();
00355             Thread.Sleep(timeSleep);
00356             rpcClient.MAX30101.Multimode_stop();
00357             sw.Stop();
00358 
00359             Application.DoEvents();
00360 
00361             Console.WriteLine("Points: " + plotView.Points + "Time: " + sw.ElapsedMilliseconds / 1000.0);
00362             Assert.That(plotView.Points, Is.GreaterThan(minFactor * sw.ElapsedMilliseconds / 1000 * sr[sampleRate] / avg[sampleAverage]));
00363             Assert.That(plotView.Points, Is.LessThan(maxFactor * sw.ElapsedMilliseconds / 1000 * sr[sampleRate] / avg[sampleAverage]));
00364         }
00365     }
00366 }