Darien Figueroa / Mbed OS Final_Program

Dependencies:   USBDevice

Committer:
darienf
Date:
Sun May 02 23:09:04 2021 +0000
Revision:
5:bc128a16232f
Parent:
3:36de8b9e4b1a
This is the program that was last used, that has the working temperature and some comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darienf 3:36de8b9e4b1a 1 /*******************************************************************************
darienf 3:36de8b9e4b1a 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
darienf 3:36de8b9e4b1a 3 *
darienf 3:36de8b9e4b1a 4 * This software is protected by copyright laws of the United States and
darienf 3:36de8b9e4b1a 5 * of foreign countries. This material may also be protected by patent laws
darienf 3:36de8b9e4b1a 6 * and technology transfer regulations of the United States and of foreign
darienf 3:36de8b9e4b1a 7 * countries. This software is furnished under a license agreement and/or a
darienf 3:36de8b9e4b1a 8 * nondisclosure agreement and may only be used or reproduced in accordance
darienf 3:36de8b9e4b1a 9 * with the terms of those agreements. Dissemination of this information to
darienf 3:36de8b9e4b1a 10 * any party or parties not specified in the license agreement and/or
darienf 3:36de8b9e4b1a 11 * nondisclosure agreement is expressly prohibited.
darienf 3:36de8b9e4b1a 12 *
darienf 3:36de8b9e4b1a 13 * The above copyright notice and this permission notice shall be included
darienf 3:36de8b9e4b1a 14 * in all copies or substantial portions of the Software.
darienf 3:36de8b9e4b1a 15 *
darienf 3:36de8b9e4b1a 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 3:36de8b9e4b1a 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 3:36de8b9e4b1a 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 3:36de8b9e4b1a 19 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 3:36de8b9e4b1a 20 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 3:36de8b9e4b1a 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 3:36de8b9e4b1a 22 * OTHER DEALINGS IN THE SOFTWARE.
darienf 3:36de8b9e4b1a 23 *
darienf 3:36de8b9e4b1a 24 * Except as contained in this notice, the name of Maxim Integrated
darienf 3:36de8b9e4b1a 25 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 3:36de8b9e4b1a 26 * Products, Inc. Branding Policy.
darienf 3:36de8b9e4b1a 27 *
darienf 3:36de8b9e4b1a 28 * The mere transfer of this software does not imply any licenses
darienf 3:36de8b9e4b1a 29 * of trade secrets, proprietary technology, copyrights, patents,
darienf 3:36de8b9e4b1a 30 * trademarks, maskwork rights, or any other form of intellectual
darienf 3:36de8b9e4b1a 31 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 3:36de8b9e4b1a 32 * ownership rights.
darienf 3:36de8b9e4b1a 33 *******************************************************************************
darienf 3:36de8b9e4b1a 34 */
darienf 3:36de8b9e4b1a 35
darienf 3:36de8b9e4b1a 36 using System;
darienf 3:36de8b9e4b1a 37 using System.Collections.Generic;
darienf 3:36de8b9e4b1a 38 using System.Linq;
darienf 3:36de8b9e4b1a 39 using System.Text;
darienf 3:36de8b9e4b1a 40
darienf 3:36de8b9e4b1a 41 using HealthSensorPlatform.View;
darienf 3:36de8b9e4b1a 42 using HealthSensorPlatform.Model;
darienf 3:36de8b9e4b1a 43 using HealthSensorPlatform.CustomControls;
darienf 3:36de8b9e4b1a 44
darienf 3:36de8b9e4b1a 45 using RPCSupport;
darienf 3:36de8b9e4b1a 46 using RPCSupport.Streaming;
darienf 3:36de8b9e4b1a 47
darienf 3:36de8b9e4b1a 48 namespace HealthSensorPlatform.Presenter
darienf 3:36de8b9e4b1a 49 {
darienf 3:36de8b9e4b1a 50 public class RawFileLogPresenter
darienf 3:36de8b9e4b1a 51 {
darienf 3:36de8b9e4b1a 52 IRawFileLogView ecgLog;
darienf 3:36de8b9e4b1a 53 IRawFileLogView bioZLog;
darienf 3:36de8b9e4b1a 54 IRawFileLogView rToRLog;
darienf 3:36de8b9e4b1a 55 IRawFileLogView paceLog;
darienf 3:36de8b9e4b1a 56 IFormView formView;
darienf 3:36de8b9e4b1a 57 IEcgView ecgView;
darienf 3:36de8b9e4b1a 58
darienf 3:36de8b9e4b1a 59 bool fileLog = false; // user enabled file logging
darienf 3:36de8b9e4b1a 60 bool streaming = false; // streaming data or flash log data, only save data from streaming
darienf 3:36de8b9e4b1a 61 //bool flashLog = false;
darienf 3:36de8b9e4b1a 62
darienf 3:36de8b9e4b1a 63 IDataLoggingView dataLogView;
darienf 3:36de8b9e4b1a 64
darienf 3:36de8b9e4b1a 65 PaceData paceData;
darienf 3:36de8b9e4b1a 66
darienf 3:36de8b9e4b1a 67 RToRCalculator rToRCalculator;
darienf 3:36de8b9e4b1a 68 bool rToRFirst = true; // received first RR value for offset correction
darienf 3:36de8b9e4b1a 69
darienf 3:36de8b9e4b1a 70 //bool ecgLeadOff; // DC Lead off data for ECG or BioZ Channel
darienf 3:36de8b9e4b1a 71 DCLeadOff leadOff; // lead off status bits
darienf 3:36de8b9e4b1a 72 ACLeadOff acLeadOff; // bioz lead off status bits
darienf 3:36de8b9e4b1a 73
darienf 3:36de8b9e4b1a 74 int count = 0;
darienf 3:36de8b9e4b1a 75 int bioZCount = 0;
darienf 3:36de8b9e4b1a 76 //int ppgCount = 0;
darienf 3:36de8b9e4b1a 77 //int accelCount = 0;
darienf 3:36de8b9e4b1a 78
darienf 3:36de8b9e4b1a 79 string logFileDirectory = null;
darienf 3:36de8b9e4b1a 80
darienf 3:36de8b9e4b1a 81 View.FileLogView.FileLogHeader fileLogHeader = new View.FileLogView.FileLogHeader();
darienf 3:36de8b9e4b1a 82
darienf 3:36de8b9e4b1a 83 public RawFileLogPresenter(IRawFileLogView ecg, IRawFileLogView bioZ, IRawFileLogView rToR, IRawFileLogView pace, IFormView formView, RPCClient rpcClient, IEcgView ecgView, IDataLoggingView dataLogView)
darienf 3:36de8b9e4b1a 84 {
darienf 3:36de8b9e4b1a 85 this.ecgLog = ecg;
darienf 3:36de8b9e4b1a 86 this.bioZLog = bioZ;
darienf 3:36de8b9e4b1a 87 this.rToRLog = rToR;
darienf 3:36de8b9e4b1a 88 this.paceLog = pace;
darienf 3:36de8b9e4b1a 89 this.formView = formView;
darienf 3:36de8b9e4b1a 90 this.ecgView = ecgView;
darienf 3:36de8b9e4b1a 91
darienf 3:36de8b9e4b1a 92 this.dataLogView = dataLogView;
darienf 3:36de8b9e4b1a 93
darienf 3:36de8b9e4b1a 94 formView.FileLogEnable += new EventHandler<EnableEventArgs>(OnLogFileEnable);
darienf 3:36de8b9e4b1a 95 ecgView.StreamingStartStop += new EventHandler<StreamingStartStopEventArgs>(OnStreamStart);
darienf 3:36de8b9e4b1a 96 //dataLogView.LogDownloadStart += new EventHandler<EventArgs>(OnLogDownloadStart);
darienf 3:36de8b9e4b1a 97 rpcClient.streaming.PartialArrayIntAvailable += new EventHandler<PartialArrayIntAvailableEventArgs>(OnStreamData);
darienf 3:36de8b9e4b1a 98 }
darienf 3:36de8b9e4b1a 99
darienf 3:36de8b9e4b1a 100 public void OnLogFileEnable(object sender, EnableEventArgs e)
darienf 3:36de8b9e4b1a 101 {
darienf 3:36de8b9e4b1a 102 fileLog = e.Enable;
darienf 3:36de8b9e4b1a 103
darienf 3:36de8b9e4b1a 104 if (e.Enable)
darienf 3:36de8b9e4b1a 105 {
darienf 3:36de8b9e4b1a 106 bool result = false;
darienf 3:36de8b9e4b1a 107 IRawFileLogView log = ecgLog;
darienf 3:36de8b9e4b1a 108 string filePrefixName = String.Empty;
darienf 3:36de8b9e4b1a 109
darienf 3:36de8b9e4b1a 110 switch(e.Stream)
darienf 3:36de8b9e4b1a 111 {
darienf 3:36de8b9e4b1a 112 case StreamType.Ecg:
darienf 3:36de8b9e4b1a 113 log = ecgLog;
darienf 3:36de8b9e4b1a 114 filePrefixName = "hsp-ecg";
darienf 3:36de8b9e4b1a 115 break;
darienf 3:36de8b9e4b1a 116 case StreamType.RToR:
darienf 3:36de8b9e4b1a 117 log = rToRLog;
darienf 3:36de8b9e4b1a 118 filePrefixName = "hsp-rtor";
darienf 3:36de8b9e4b1a 119 break;
darienf 3:36de8b9e4b1a 120 case StreamType.Pace:
darienf 3:36de8b9e4b1a 121 log = paceLog;
darienf 3:36de8b9e4b1a 122 filePrefixName = "hsp-pace";
darienf 3:36de8b9e4b1a 123 break;
darienf 3:36de8b9e4b1a 124 case StreamType.BioZ:
darienf 3:36de8b9e4b1a 125 log = bioZLog;
darienf 3:36de8b9e4b1a 126 filePrefixName = "hsp-bioz";
darienf 3:36de8b9e4b1a 127 break;
darienf 3:36de8b9e4b1a 128 }
darienf 3:36de8b9e4b1a 129
darienf 3:36de8b9e4b1a 130 if (logFileDirectory != null) // Set starting directory to be the same as the last
darienf 3:36de8b9e4b1a 131 log.FileDirectory = logFileDirectory;
darienf 3:36de8b9e4b1a 132
darienf 3:36de8b9e4b1a 133 result = log.SelectCSVFile(filePrefixName);
darienf 3:36de8b9e4b1a 134 log.Enable = result;
darienf 3:36de8b9e4b1a 135
darienf 3:36de8b9e4b1a 136 if (result) // Save directory if success
darienf 3:36de8b9e4b1a 137 logFileDirectory = log.FileDirectory;
darienf 3:36de8b9e4b1a 138
darienf 3:36de8b9e4b1a 139 formView.LogFileItem(e.Stream, result);
darienf 3:36de8b9e4b1a 140 }
darienf 3:36de8b9e4b1a 141 else
darienf 3:36de8b9e4b1a 142 {
darienf 3:36de8b9e4b1a 143 switch (e.Stream)
darienf 3:36de8b9e4b1a 144 {
darienf 3:36de8b9e4b1a 145 case StreamType.Ecg:
darienf 3:36de8b9e4b1a 146 ecgLog.Enable = false;
darienf 3:36de8b9e4b1a 147 break;
darienf 3:36de8b9e4b1a 148 case StreamType.RToR:
darienf 3:36de8b9e4b1a 149 rToRLog.Enable = false;
darienf 3:36de8b9e4b1a 150 break;
darienf 3:36de8b9e4b1a 151 case StreamType.Pace:
darienf 3:36de8b9e4b1a 152 paceLog.Enable = false;
darienf 3:36de8b9e4b1a 153 break;
darienf 3:36de8b9e4b1a 154 case StreamType.BioZ:
darienf 3:36de8b9e4b1a 155 bioZLog.Enable = false;
darienf 3:36de8b9e4b1a 156 break;
darienf 3:36de8b9e4b1a 157 }
darienf 3:36de8b9e4b1a 158
darienf 3:36de8b9e4b1a 159 formView.LogFileItem(e.Stream, false);
darienf 3:36de8b9e4b1a 160 }
darienf 3:36de8b9e4b1a 161 }
darienf 3:36de8b9e4b1a 162
darienf 3:36de8b9e4b1a 163 public void OnStreamStart(object sender, StreamingStartStopEventArgs e)
darienf 3:36de8b9e4b1a 164 {
darienf 3:36de8b9e4b1a 165 streaming = e.state;
darienf 3:36de8b9e4b1a 166 count = 0;
darienf 3:36de8b9e4b1a 167 bioZCount = 0;
darienf 3:36de8b9e4b1a 168
darienf 3:36de8b9e4b1a 169 if (e.state)
darienf 3:36de8b9e4b1a 170 {
darienf 3:36de8b9e4b1a 171 leadOff = new DCLeadOff { NegativeHigh = false, NegativeLow = false, PostiveHigh = false, PostiveLow = false };
darienf 3:36de8b9e4b1a 172 acLeadOff = new ACLeadOff { BioZOverRange = false, BioZUnderRange = false };
darienf 3:36de8b9e4b1a 173
darienf 3:36de8b9e4b1a 174 if (ecgLog != null && ecgLog.Enable && ecgView.EnableECG)
darienf 3:36de8b9e4b1a 175 {
darienf 3:36de8b9e4b1a 176 //ecgLog.WriteLine("% " + ecgView.HspSetting.EcgSettingString()); // TODO: What is the requirement for headers
darienf 3:36de8b9e4b1a 177 ecgLog.WriteLine(fileLogHeader.Ecg);
darienf 3:36de8b9e4b1a 178 }
darienf 3:36de8b9e4b1a 179
darienf 3:36de8b9e4b1a 180 if (bioZLog != null && bioZLog.Enable && ecgView.EnableBioZ)
darienf 3:36de8b9e4b1a 181 {
darienf 3:36de8b9e4b1a 182 //ecgLog.WriteLine("% " + ecgView.HspSetting.BioZSettingString());
darienf 3:36de8b9e4b1a 183 bioZLog.WriteLine(fileLogHeader.BioZ);
darienf 3:36de8b9e4b1a 184 }
darienf 3:36de8b9e4b1a 185
darienf 3:36de8b9e4b1a 186 if (rToRLog != null && rToRLog.Enable && ecgView.EnableRToR)
darienf 3:36de8b9e4b1a 187 {
darienf 3:36de8b9e4b1a 188 rToRLog.WriteLine(fileLogHeader.RToR);
darienf 3:36de8b9e4b1a 189 rToRCalculator = new RToRCalculator(ecgView.MasterClockField, ecgView.EcgArgs.Rate, ecgView.EcgArgs.Dlpf, ecgView.RToRArgs.Wndw);
darienf 3:36de8b9e4b1a 190 }
darienf 3:36de8b9e4b1a 191
darienf 3:36de8b9e4b1a 192 if (paceLog != null && paceLog.Enable && ecgView.EnablePace)
darienf 3:36de8b9e4b1a 193 {
darienf 3:36de8b9e4b1a 194 paceLog.WriteLine(fileLogHeader.Pace);
darienf 3:36de8b9e4b1a 195 }
darienf 3:36de8b9e4b1a 196 }
darienf 3:36de8b9e4b1a 197 else
darienf 3:36de8b9e4b1a 198 {
darienf 3:36de8b9e4b1a 199 if (ecgLog != null)
darienf 3:36de8b9e4b1a 200 ecgLog.Enable = false;
darienf 3:36de8b9e4b1a 201
darienf 3:36de8b9e4b1a 202 if (bioZLog != null)
darienf 3:36de8b9e4b1a 203 bioZLog.Enable = false;
darienf 3:36de8b9e4b1a 204
darienf 3:36de8b9e4b1a 205 if (rToRLog != null)
darienf 3:36de8b9e4b1a 206 rToRLog.Enable = false;
darienf 3:36de8b9e4b1a 207
darienf 3:36de8b9e4b1a 208 if (paceLog != null)
darienf 3:36de8b9e4b1a 209 paceLog.Enable = false;
darienf 3:36de8b9e4b1a 210 }
darienf 3:36de8b9e4b1a 211 }
darienf 3:36de8b9e4b1a 212
darienf 3:36de8b9e4b1a 213 void fileLogStop()
darienf 3:36de8b9e4b1a 214 {
darienf 3:36de8b9e4b1a 215 fileLog = false;
darienf 3:36de8b9e4b1a 216 stop();
darienf 3:36de8b9e4b1a 217
darienf 3:36de8b9e4b1a 218 }
darienf 3:36de8b9e4b1a 219
darienf 3:36de8b9e4b1a 220 void stop()
darienf 3:36de8b9e4b1a 221 {
darienf 3:36de8b9e4b1a 222 if (ecgLog != null && ecgLog.Enable)
darienf 3:36de8b9e4b1a 223 ecgLog.Enable = false;
darienf 3:36de8b9e4b1a 224
darienf 3:36de8b9e4b1a 225 if (rToRLog != null && rToRLog.Enable)
darienf 3:36de8b9e4b1a 226 rToRLog.Enable = false;
darienf 3:36de8b9e4b1a 227
darienf 3:36de8b9e4b1a 228 if (paceLog != null && paceLog.Enable)
darienf 3:36de8b9e4b1a 229 paceLog.Enable = false;
darienf 3:36de8b9e4b1a 230
darienf 3:36de8b9e4b1a 231 if (bioZLog != null && bioZLog.Enable)
darienf 3:36de8b9e4b1a 232 bioZLog.Enable = false;
darienf 3:36de8b9e4b1a 233
darienf 3:36de8b9e4b1a 234 formView.LogFileItem(StreamType.Ecg, false);
darienf 3:36de8b9e4b1a 235 formView.LogFileItem(StreamType.RToR, false);
darienf 3:36de8b9e4b1a 236 formView.LogFileItem(StreamType.Pace, false);
darienf 3:36de8b9e4b1a 237 formView.LogFileItem(StreamType.BioZ, false);
darienf 3:36de8b9e4b1a 238 }
darienf 3:36de8b9e4b1a 239
darienf 3:36de8b9e4b1a 240 private void OnStreamData(object sender, PartialArrayIntAvailableEventArgs e)
darienf 3:36de8b9e4b1a 241 {
darienf 3:36de8b9e4b1a 242 if (streaming)
darienf 3:36de8b9e4b1a 243 {
darienf 3:36de8b9e4b1a 244 switch (e.reportID)
darienf 3:36de8b9e4b1a 245 {
darienf 3:36de8b9e4b1a 246 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_ECG:
darienf 3:36de8b9e4b1a 247 if (ecgLog.Enable)
darienf 3:36de8b9e4b1a 248 ProcessEcg(e.array1);
darienf 3:36de8b9e4b1a 249 break;
darienf 3:36de8b9e4b1a 250 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_BIOZ:
darienf 3:36de8b9e4b1a 251 if (bioZLog.Enable)
darienf 3:36de8b9e4b1a 252 ProcessBioZ(e.array1);
darienf 3:36de8b9e4b1a 253 break;
darienf 3:36de8b9e4b1a 254 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_PACE:
darienf 3:36de8b9e4b1a 255 if (paceLog.Enable)
darienf 3:36de8b9e4b1a 256 paceData = new PaceData(e.array1);
darienf 3:36de8b9e4b1a 257 break;
darienf 3:36de8b9e4b1a 258 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_RTOR:
darienf 3:36de8b9e4b1a 259 if (rToRLog.Enable)
darienf 3:36de8b9e4b1a 260 ProcessRToR(e.array1[0]);
darienf 3:36de8b9e4b1a 261 break;
darienf 3:36de8b9e4b1a 262 case PartialArrayIntAvailableEventArgs.PACKET_END_OF_STREAM:
darienf 3:36de8b9e4b1a 263 fileLogStop();
darienf 3:36de8b9e4b1a 264 break;
darienf 3:36de8b9e4b1a 265 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_LEADOFF_DC:
darienf 3:36de8b9e4b1a 266 ProcessLeadOff(e.array1[0]);
darienf 3:36de8b9e4b1a 267 break;
darienf 3:36de8b9e4b1a 268 case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_LEADOFF_AC:
darienf 3:36de8b9e4b1a 269 ProcessACLeadOff(e.array1[0]);
darienf 3:36de8b9e4b1a 270 break;
darienf 3:36de8b9e4b1a 271 }
darienf 3:36de8b9e4b1a 272 }
darienf 3:36de8b9e4b1a 273 }
darienf 3:36de8b9e4b1a 274
darienf 3:36de8b9e4b1a 275 void ProcessBioZ(int[] rawData)
darienf 3:36de8b9e4b1a 276 {
darienf 3:36de8b9e4b1a 277 BioZFifo[] bioZFifo;
darienf 3:36de8b9e4b1a 278 double sampleRate = ecgView.SampleRateBioZ;
darienf 3:36de8b9e4b1a 279 double[] time = new double[rawData.Length];
darienf 3:36de8b9e4b1a 280
darienf 3:36de8b9e4b1a 281 bioZFifo = ConvertBioZ(rawData);
darienf 3:36de8b9e4b1a 282
darienf 3:36de8b9e4b1a 283 for (int i = 0; i < time.Length; i++)
darienf 3:36de8b9e4b1a 284 {
darienf 3:36de8b9e4b1a 285 time[i] = bioZCount / sampleRate;
darienf 3:36de8b9e4b1a 286 bioZCount++;
darienf 3:36de8b9e4b1a 287 }
darienf 3:36de8b9e4b1a 288
darienf 3:36de8b9e4b1a 289 if (ecgView.EnableDCLeadOff == false && ecgView.EnableBioZOverUnderRange == true)
darienf 3:36de8b9e4b1a 290 bioZLog.DisplayBioZ(time, bioZFifo, acLeadOff);
darienf 3:36de8b9e4b1a 291 else if (ecgView.EnableDCLeadOff == true && ecgView.EnableEcgDCLeadOff == false && ecgView.EnableBioZOverUnderRange == false) // && ecgLeadOff == false)
darienf 3:36de8b9e4b1a 292 bioZLog.DisplayBioZ(time, bioZFifo, leadOff);
darienf 3:36de8b9e4b1a 293 else if (ecgView.EnableDCLeadOff == true && ecgView.EnableEcgDCLeadOff == false && ecgView.EnableBioZOverUnderRange == true)
darienf 3:36de8b9e4b1a 294 bioZLog.DisplayBioZ(time, bioZFifo, leadOff, acLeadOff);
darienf 3:36de8b9e4b1a 295 else if ((ecgView.EnableDCLeadOff == false && ecgView.EnableBioZOverUnderRange == false) ||
darienf 3:36de8b9e4b1a 296 ecgView.EnableEcgDCLeadOff == true && ecgView.EnableEcgDCLeadOff == true && ecgView.EnableBioZOverUnderRange == false)
darienf 3:36de8b9e4b1a 297 bioZLog.DisplayBioZ(time, bioZFifo);
darienf 3:36de8b9e4b1a 298 }
darienf 3:36de8b9e4b1a 299
darienf 3:36de8b9e4b1a 300 public BioZFifo[] ConvertBioZ(int[] data)
darienf 3:36de8b9e4b1a 301 {
darienf 3:36de8b9e4b1a 302 BioZFifo[] impedance = new BioZFifo[data.Length];
darienf 3:36de8b9e4b1a 303 EcgView.ChartInfo chartInfo = ecgView.BioZInfo;
darienf 3:36de8b9e4b1a 304 int dataShift;
darienf 3:36de8b9e4b1a 305
darienf 3:36de8b9e4b1a 306 for (int i = 0; i < data.Length; i++)
darienf 3:36de8b9e4b1a 307 {
darienf 3:36de8b9e4b1a 308 dataShift = data[i] >> chartInfo.Shift;
darienf 3:36de8b9e4b1a 309
darienf 3:36de8b9e4b1a 310 // Two's Complement Conversions
darienf 3:36de8b9e4b1a 311 if (dataShift > chartInfo.Threshold)
darienf 3:36de8b9e4b1a 312 {
darienf 3:36de8b9e4b1a 313 dataShift -= chartInfo.Offset;
darienf 3:36de8b9e4b1a 314 }
darienf 3:36de8b9e4b1a 315
darienf 3:36de8b9e4b1a 316 // 1.9734 = 1/2^19 * 1e-6
darienf 3:36de8b9e4b1a 317 impedance[i].Data = dataShift * 1.9073486328125 /
darienf 3:36de8b9e4b1a 318 (chartInfo.Gain * ((chartInfo.CurrentGenerator == 0) ? 1 : chartInfo.CurrentGenerator));
darienf 3:36de8b9e4b1a 319 impedance[i].Code = data[i];
darienf 3:36de8b9e4b1a 320 impedance[i].BioZData = dataShift;
darienf 3:36de8b9e4b1a 321 impedance[i].BTag = data[i] & 0x07;
darienf 3:36de8b9e4b1a 322 }
darienf 3:36de8b9e4b1a 323
darienf 3:36de8b9e4b1a 324 return impedance;
darienf 3:36de8b9e4b1a 325 }
darienf 3:36de8b9e4b1a 326
darienf 3:36de8b9e4b1a 327 void ProcessEcg(int[] rawData)
darienf 3:36de8b9e4b1a 328 {
darienf 3:36de8b9e4b1a 329 EcgFifo[] ecgFifo;
darienf 3:36de8b9e4b1a 330 double ecgRate = ecgView.SampleRateEcg;
darienf 3:36de8b9e4b1a 331 double[] ecgVoltage = new double[rawData.Length];
darienf 3:36de8b9e4b1a 332 double[] timeSecond = new double[rawData.Length];
darienf 3:36de8b9e4b1a 333
darienf 3:36de8b9e4b1a 334 ecgFifo = ConvertEcg(rawData);
darienf 3:36de8b9e4b1a 335
darienf 3:36de8b9e4b1a 336 for (int i = 0; i < ecgFifo.Length; i++ )
darienf 3:36de8b9e4b1a 337 {
darienf 3:36de8b9e4b1a 338 timeSecond[i] = count / ecgRate;
darienf 3:36de8b9e4b1a 339
darienf 3:36de8b9e4b1a 340 // Look for Pace Events
darienf 3:36de8b9e4b1a 341 if (paceLog.Enable)
darienf 3:36de8b9e4b1a 342 {
darienf 3:36de8b9e4b1a 343 //for (int j = 0; j < ecgFifo.Length; j++)
darienf 3:36de8b9e4b1a 344 //{
darienf 3:36de8b9e4b1a 345 if (ecgFifo[i].PTag != 7)
darienf 3:36de8b9e4b1a 346 {
darienf 3:36de8b9e4b1a 347 PaceData.PaceRegister paceRegister = paceData.PaceGroup(ecgFifo[i].PTag);
darienf 3:36de8b9e4b1a 348 List<double> timeMillsecondPace = new List<double>();
darienf 3:36de8b9e4b1a 349 List<PaceData.PaceEdge> paceEdges = new List<PaceData.PaceEdge>();
darienf 3:36de8b9e4b1a 350
darienf 3:36de8b9e4b1a 351 for (int k = 0; k < 6; k++)
darienf 3:36de8b9e4b1a 352 {
darienf 3:36de8b9e4b1a 353 PaceData.PaceEdge edge = paceRegister.Edge[k];
darienf 3:36de8b9e4b1a 354
darienf 3:36de8b9e4b1a 355 timeMillsecondPace.Add(count / ecgRate + ConvertPace(edge.Data));
darienf 3:36de8b9e4b1a 356 paceEdges.Add(edge);
darienf 3:36de8b9e4b1a 357
darienf 3:36de8b9e4b1a 358 if (edge.Last == true)
darienf 3:36de8b9e4b1a 359 break;
darienf 3:36de8b9e4b1a 360 }
darienf 3:36de8b9e4b1a 361
darienf 3:36de8b9e4b1a 362 paceLog.DisplayPace(timeMillsecondPace.ToArray(), paceEdges.ToArray());
darienf 3:36de8b9e4b1a 363 System.Diagnostics.Debug.Print("ECG PTag = " + ecgFifo[i].PTag);
darienf 3:36de8b9e4b1a 364 }
darienf 3:36de8b9e4b1a 365 //}
darienf 3:36de8b9e4b1a 366 }
darienf 3:36de8b9e4b1a 367
darienf 3:36de8b9e4b1a 368 count++;
darienf 3:36de8b9e4b1a 369 }
darienf 3:36de8b9e4b1a 370
darienf 3:36de8b9e4b1a 371 if (ecgView.EnableDCLeadOff && ecgView.EnableEcgDCLeadOff)
darienf 3:36de8b9e4b1a 372 ecgLog.DisplayEcg(timeSecond, ecgFifo, leadOff);
darienf 3:36de8b9e4b1a 373 else
darienf 3:36de8b9e4b1a 374 ecgLog.DisplayEcg(timeSecond, ecgFifo);
darienf 3:36de8b9e4b1a 375
darienf 3:36de8b9e4b1a 376 }
darienf 3:36de8b9e4b1a 377
darienf 3:36de8b9e4b1a 378 public EcgFifo[] ConvertEcg(int[] data)
darienf 3:36de8b9e4b1a 379 {
darienf 3:36de8b9e4b1a 380 EcgFifo[] voltage = new EcgFifo[data.Length];
darienf 3:36de8b9e4b1a 381 EcgView.ChartInfo chartInfo = ecgView.EcgInfo;
darienf 3:36de8b9e4b1a 382 int dataShift;
darienf 3:36de8b9e4b1a 383
darienf 3:36de8b9e4b1a 384 for (int i = 0; i < data.Length; i++)
darienf 3:36de8b9e4b1a 385 {
darienf 3:36de8b9e4b1a 386 dataShift = data[i] >> chartInfo.Shift;
darienf 3:36de8b9e4b1a 387
darienf 3:36de8b9e4b1a 388 // Two's Complement Conversions
darienf 3:36de8b9e4b1a 389 if (dataShift > chartInfo.Threshold)
darienf 3:36de8b9e4b1a 390 {
darienf 3:36de8b9e4b1a 391 dataShift -= chartInfo.Offset;
darienf 3:36de8b9e4b1a 392 }
darienf 3:36de8b9e4b1a 393
darienf 3:36de8b9e4b1a 394 voltage[i].Data = 1000 * 7.62939453125e-6 * dataShift / chartInfo.Gain;
darienf 3:36de8b9e4b1a 395 voltage[i].EcgData = dataShift;
darienf 3:36de8b9e4b1a 396 voltage[i].Code = data[i];
darienf 3:36de8b9e4b1a 397 voltage[i].PTag = data[i] & 0x07;
darienf 3:36de8b9e4b1a 398 voltage[i].ETag = (data[i] >> 3) & 0x07;
darienf 3:36de8b9e4b1a 399 }
darienf 3:36de8b9e4b1a 400
darienf 3:36de8b9e4b1a 401 return voltage;
darienf 3:36de8b9e4b1a 402 }
darienf 3:36de8b9e4b1a 403
darienf 3:36de8b9e4b1a 404 public double ConvertRToR(int data)
darienf 3:36de8b9e4b1a 405 {
darienf 3:36de8b9e4b1a 406 return ecgView.TimeResolution * 1000 * data * 512;
darienf 3:36de8b9e4b1a 407 }
darienf 3:36de8b9e4b1a 408
darienf 3:36de8b9e4b1a 409 public double ConvertPace(int data)
darienf 3:36de8b9e4b1a 410 {
darienf 3:36de8b9e4b1a 411 return data * ecgView.TimeResolution;
darienf 3:36de8b9e4b1a 412 }
darienf 3:36de8b9e4b1a 413
darienf 3:36de8b9e4b1a 414 public string PaceRegisterGroupToString(PaceData.PaceRegister paceRegister)
darienf 3:36de8b9e4b1a 415 {
darienf 3:36de8b9e4b1a 416 StringBuilder paceRegisterLogBuilder = new StringBuilder();
darienf 3:36de8b9e4b1a 417 for (int j = 0; j < 6; j++)
darienf 3:36de8b9e4b1a 418 {
darienf 3:36de8b9e4b1a 419 paceRegisterLogBuilder.Append(paceRegister.Edge[j].Data / (2 * ecgView.MasterClockFrequency));
darienf 3:36de8b9e4b1a 420 paceRegisterLogBuilder.Append(", ");
darienf 3:36de8b9e4b1a 421 paceRegisterLogBuilder.Append(paceRegister.Edge[j].Polarity ? 'R' : 'F');
darienf 3:36de8b9e4b1a 422 paceRegisterLogBuilder.Append(", ");
darienf 3:36de8b9e4b1a 423 paceRegisterLogBuilder.Append(paceRegister.Edge[j].Last ? 'Y' : 'N');
darienf 3:36de8b9e4b1a 424 paceRegisterLogBuilder.Append(", ");
darienf 3:36de8b9e4b1a 425 }
darienf 3:36de8b9e4b1a 426
darienf 3:36de8b9e4b1a 427 return paceRegisterLogBuilder.ToString();
darienf 3:36de8b9e4b1a 428 }
darienf 3:36de8b9e4b1a 429
darienf 3:36de8b9e4b1a 430 void ProcessLeadOff(int data)
darienf 3:36de8b9e4b1a 431 {
darienf 3:36de8b9e4b1a 432 /*
darienf 3:36de8b9e4b1a 433 if (bitShiftMask(data, 8)) // ECG lead off
darienf 3:36de8b9e4b1a 434 ecgLeadOff = true;
darienf 3:36de8b9e4b1a 435 else if (bitShiftMask(data, 9)) // BioZ lead off
darienf 3:36de8b9e4b1a 436 ecgLeadOff = false;
darienf 3:36de8b9e4b1a 437 */
darienf 3:36de8b9e4b1a 438
darienf 3:36de8b9e4b1a 439 leadOff = new DCLeadOff()
darienf 3:36de8b9e4b1a 440 {
darienf 3:36de8b9e4b1a 441 PostiveHigh = bitShiftMask(data, 3),
darienf 3:36de8b9e4b1a 442 PostiveLow = bitShiftMask(data, 2),
darienf 3:36de8b9e4b1a 443 NegativeHigh = bitShiftMask(data, 1),
darienf 3:36de8b9e4b1a 444 NegativeLow = bitShiftMask(data, 0)
darienf 3:36de8b9e4b1a 445 };
darienf 3:36de8b9e4b1a 446
darienf 3:36de8b9e4b1a 447 }
darienf 3:36de8b9e4b1a 448
darienf 3:36de8b9e4b1a 449 void ProcessACLeadOff(int data)
darienf 3:36de8b9e4b1a 450 {
darienf 3:36de8b9e4b1a 451 acLeadOff = new ACLeadOff()
darienf 3:36de8b9e4b1a 452 {
darienf 3:36de8b9e4b1a 453 BioZUnderRange = bitShiftMask(data, 1),
darienf 3:36de8b9e4b1a 454 BioZOverRange = bitShiftMask(data, 0),
darienf 3:36de8b9e4b1a 455 };
darienf 3:36de8b9e4b1a 456 }
darienf 3:36de8b9e4b1a 457
darienf 3:36de8b9e4b1a 458 private static bool bitShiftMask(int data, int index)
darienf 3:36de8b9e4b1a 459 {
darienf 3:36de8b9e4b1a 460 int state;
darienf 3:36de8b9e4b1a 461 int mask = 1 << index;
darienf 3:36de8b9e4b1a 462 state = ((data & mask) == mask) ? 1 : 0;
darienf 3:36de8b9e4b1a 463 return state == 1;
darienf 3:36de8b9e4b1a 464 }
darienf 3:36de8b9e4b1a 465
darienf 3:36de8b9e4b1a 466 void ProcessRToR(int data)
darienf 3:36de8b9e4b1a 467 {
darienf 3:36de8b9e4b1a 468 if (rToRFirst)
darienf 3:36de8b9e4b1a 469 {
darienf 3:36de8b9e4b1a 470 rToRLog.DisplayRToR(data, rToRCalculator.Corrected(data, true) / 1000);
darienf 3:36de8b9e4b1a 471 rToRFirst = false;
darienf 3:36de8b9e4b1a 472 }
darienf 3:36de8b9e4b1a 473 else
darienf 3:36de8b9e4b1a 474 rToRLog.DisplayRToR(data, rToRCalculator.Corrected(data, false) / 1000);
darienf 3:36de8b9e4b1a 475 }
darienf 3:36de8b9e4b1a 476 }
darienf 3:36de8b9e4b1a 477 }