repo time
Dependencies: mbed MAX14720 MAX30205 USBDevice
HspGuiSourceV301/HSPGui/Presenter/DataLogPresenter.cs@20:6d2af70c92ab, 2021-04-06 (annotated)
- Committer:
- darienf
- Date:
- Tue Apr 06 06:41:40 2021 +0000
- Revision:
- 20:6d2af70c92ab
another repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
darienf | 20:6d2af70c92ab | 1 | /******************************************************************************* |
darienf | 20:6d2af70c92ab | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved. |
darienf | 20:6d2af70c92ab | 3 | * |
darienf | 20:6d2af70c92ab | 4 | * This software is protected by copyright laws of the United States and |
darienf | 20:6d2af70c92ab | 5 | * of foreign countries. This material may also be protected by patent laws |
darienf | 20:6d2af70c92ab | 6 | * and technology transfer regulations of the United States and of foreign |
darienf | 20:6d2af70c92ab | 7 | * countries. This software is furnished under a license agreement and/or a |
darienf | 20:6d2af70c92ab | 8 | * nondisclosure agreement and may only be used or reproduced in accordance |
darienf | 20:6d2af70c92ab | 9 | * with the terms of those agreements. Dissemination of this information to |
darienf | 20:6d2af70c92ab | 10 | * any party or parties not specified in the license agreement and/or |
darienf | 20:6d2af70c92ab | 11 | * nondisclosure agreement is expressly prohibited. |
darienf | 20:6d2af70c92ab | 12 | * |
darienf | 20:6d2af70c92ab | 13 | * The above copyright notice and this permission notice shall be included |
darienf | 20:6d2af70c92ab | 14 | * in all copies or substantial portions of the Software. |
darienf | 20:6d2af70c92ab | 15 | * |
darienf | 20:6d2af70c92ab | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
darienf | 20:6d2af70c92ab | 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
darienf | 20:6d2af70c92ab | 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
darienf | 20:6d2af70c92ab | 19 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
darienf | 20:6d2af70c92ab | 20 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
darienf | 20:6d2af70c92ab | 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
darienf | 20:6d2af70c92ab | 22 | * OTHER DEALINGS IN THE SOFTWARE. |
darienf | 20:6d2af70c92ab | 23 | * |
darienf | 20:6d2af70c92ab | 24 | * Except as contained in this notice, the name of Maxim Integrated |
darienf | 20:6d2af70c92ab | 25 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
darienf | 20:6d2af70c92ab | 26 | * Products, Inc. Branding Policy. |
darienf | 20:6d2af70c92ab | 27 | * |
darienf | 20:6d2af70c92ab | 28 | * The mere transfer of this software does not imply any licenses |
darienf | 20:6d2af70c92ab | 29 | * of trade secrets, proprietary technology, copyrights, patents, |
darienf | 20:6d2af70c92ab | 30 | * trademarks, maskwork rights, or any other form of intellectual |
darienf | 20:6d2af70c92ab | 31 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
darienf | 20:6d2af70c92ab | 32 | * ownership rights. |
darienf | 20:6d2af70c92ab | 33 | ******************************************************************************* |
darienf | 20:6d2af70c92ab | 34 | */ |
darienf | 20:6d2af70c92ab | 35 | |
darienf | 20:6d2af70c92ab | 36 | using System; |
darienf | 20:6d2af70c92ab | 37 | using System.Collections.Generic; |
darienf | 20:6d2af70c92ab | 38 | using System.Linq; |
darienf | 20:6d2af70c92ab | 39 | using System.Text; |
darienf | 20:6d2af70c92ab | 40 | |
darienf | 20:6d2af70c92ab | 41 | using RPCSupport.Streaming; |
darienf | 20:6d2af70c92ab | 42 | using HealthSensorPlatform.Model; |
darienf | 20:6d2af70c92ab | 43 | using HealthSensorPlatform.View; |
darienf | 20:6d2af70c92ab | 44 | using HealthSensorPlatform.CustomControls; |
darienf | 20:6d2af70c92ab | 45 | |
darienf | 20:6d2af70c92ab | 46 | namespace HealthSensorPlatform.Presenter |
darienf | 20:6d2af70c92ab | 47 | { |
darienf | 20:6d2af70c92ab | 48 | class DataLogPresenter |
darienf | 20:6d2af70c92ab | 49 | { |
darienf | 20:6d2af70c92ab | 50 | IDataLogModel model; |
darienf | 20:6d2af70c92ab | 51 | DataLoggingView view; |
darienf | 20:6d2af70c92ab | 52 | IRawFileLogView temperatureLog1; |
darienf | 20:6d2af70c92ab | 53 | IRawFileLogView temperatureLog2; |
darienf | 20:6d2af70c92ab | 54 | IRawFileLogView pressureLog; |
darienf | 20:6d2af70c92ab | 55 | |
darienf | 20:6d2af70c92ab | 56 | IRawFileLogView accelerometerLog; |
darienf | 20:6d2af70c92ab | 57 | IRawFileLogView opticalLog; |
darienf | 20:6d2af70c92ab | 58 | |
darienf | 20:6d2af70c92ab | 59 | IRawFileLogView ecgLog; |
darienf | 20:6d2af70c92ab | 60 | IRawFileLogView bioZLog; |
darienf | 20:6d2af70c92ab | 61 | IRawFileLogView paceLog; |
darienf | 20:6d2af70c92ab | 62 | IRawFileLogView rToRLog; |
darienf | 20:6d2af70c92ab | 63 | |
darienf | 20:6d2af70c92ab | 64 | IFormView formView; |
darienf | 20:6d2af70c92ab | 65 | |
darienf | 20:6d2af70c92ab | 66 | StatusForm statusForm; |
darienf | 20:6d2af70c92ab | 67 | |
darienf | 20:6d2af70c92ab | 68 | EcgView ecgView; // Needed to obtain some state information, should be decoupled later and use from data log model |
darienf | 20:6d2af70c92ab | 69 | OpticalView opticalView; |
darienf | 20:6d2af70c92ab | 70 | |
darienf | 20:6d2af70c92ab | 71 | int count = 0; |
darienf | 20:6d2af70c92ab | 72 | int bioZCount = 0; |
darienf | 20:6d2af70c92ab | 73 | int ppgCount = 0; |
darienf | 20:6d2af70c92ab | 74 | int accelCount = 0; |
darienf | 20:6d2af70c92ab | 75 | PaceData paceData; |
darienf | 20:6d2af70c92ab | 76 | RToRCalculator rToRCalculator; |
darienf | 20:6d2af70c92ab | 77 | bool rToRFirst = true; |
darienf | 20:6d2af70c92ab | 78 | |
darienf | 20:6d2af70c92ab | 79 | string logFileDirectory = null; |
darienf | 20:6d2af70c92ab | 80 | |
darienf | 20:6d2af70c92ab | 81 | View.FileLogView.FileLogHeader fileLogHeader = new View.FileLogView.FileLogHeader(); |
darienf | 20:6d2af70c92ab | 82 | |
darienf | 20:6d2af70c92ab | 83 | public DataLogPresenter(IFormView formView, EcgView ecgView, OpticalView opticalView, IDataLogModel model, DataLoggingView view, |
darienf | 20:6d2af70c92ab | 84 | IRawFileLogView temperatureLog1, IRawFileLogView temperatureLog2, IRawFileLogView pressureLog, |
darienf | 20:6d2af70c92ab | 85 | IRawFileLogView accelerometerLog, IRawFileLogView opticalLog, |
darienf | 20:6d2af70c92ab | 86 | IRawFileLogView ecgLog, IRawFileLogView bioZLog, IRawFileLogView paceLog, IRawFileLogView rToRLog) |
darienf | 20:6d2af70c92ab | 87 | { |
darienf | 20:6d2af70c92ab | 88 | this.model = model; |
darienf | 20:6d2af70c92ab | 89 | this.view = view; |
darienf | 20:6d2af70c92ab | 90 | |
darienf | 20:6d2af70c92ab | 91 | this.formView = formView; |
darienf | 20:6d2af70c92ab | 92 | this.ecgView = ecgView; |
darienf | 20:6d2af70c92ab | 93 | this.opticalView = opticalView; |
darienf | 20:6d2af70c92ab | 94 | |
darienf | 20:6d2af70c92ab | 95 | this.temperatureLog1 = temperatureLog1; |
darienf | 20:6d2af70c92ab | 96 | this.temperatureLog2 = temperatureLog2; |
darienf | 20:6d2af70c92ab | 97 | this.pressureLog = pressureLog; |
darienf | 20:6d2af70c92ab | 98 | |
darienf | 20:6d2af70c92ab | 99 | this.accelerometerLog = accelerometerLog; |
darienf | 20:6d2af70c92ab | 100 | this.opticalLog = opticalLog; |
darienf | 20:6d2af70c92ab | 101 | |
darienf | 20:6d2af70c92ab | 102 | this.ecgLog = ecgLog; |
darienf | 20:6d2af70c92ab | 103 | this.bioZLog = bioZLog; |
darienf | 20:6d2af70c92ab | 104 | this.paceLog = paceLog; |
darienf | 20:6d2af70c92ab | 105 | this.rToRLog = rToRLog; |
darienf | 20:6d2af70c92ab | 106 | |
darienf | 20:6d2af70c92ab | 107 | view.LogDownloadStart += new EventHandler<EventArgs>(OnLogDownloadStart); |
darienf | 20:6d2af70c92ab | 108 | view.MissionWrite += new EventHandler<EventArgs>(OnMissionWrite); |
darienf | 20:6d2af70c92ab | 109 | view.MissionRead += new EventHandler<EventArgs>(OnMissionRead); |
darienf | 20:6d2af70c92ab | 110 | view.MissionErase += new EventHandler<EventArgs>(OnMissionErase); |
darienf | 20:6d2af70c92ab | 111 | model.LogData += new EventHandler<PartialArrayIntAvailableEventArgs>(OnLogData); |
darienf | 20:6d2af70c92ab | 112 | } |
darienf | 20:6d2af70c92ab | 113 | |
darienf | 20:6d2af70c92ab | 114 | public void ProcessTemperature1(int[] data) |
darienf | 20:6d2af70c92ab | 115 | { |
darienf | 20:6d2af70c92ab | 116 | double[] calcTemp; |
darienf | 20:6d2af70c92ab | 117 | |
darienf | 20:6d2af70c92ab | 118 | calcTemp = CalculateTemperature(data); |
darienf | 20:6d2af70c92ab | 119 | temperatureLog1.DisplayTemperature(data, calcTemp); |
darienf | 20:6d2af70c92ab | 120 | } |
darienf | 20:6d2af70c92ab | 121 | |
darienf | 20:6d2af70c92ab | 122 | public void ProcessTemperature2(int[] data) |
darienf | 20:6d2af70c92ab | 123 | { |
darienf | 20:6d2af70c92ab | 124 | double[] calcTemp; |
darienf | 20:6d2af70c92ab | 125 | |
darienf | 20:6d2af70c92ab | 126 | calcTemp = CalculateTemperature(data); |
darienf | 20:6d2af70c92ab | 127 | temperatureLog2.DisplayTemperature(data, calcTemp); |
darienf | 20:6d2af70c92ab | 128 | } |
darienf | 20:6d2af70c92ab | 129 | |
darienf | 20:6d2af70c92ab | 130 | public double[] CalculateTemperature(int[] data) |
darienf | 20:6d2af70c92ab | 131 | { |
darienf | 20:6d2af70c92ab | 132 | double[] calcTemp = new double[data.Length]; |
darienf | 20:6d2af70c92ab | 133 | int rawCode; |
darienf | 20:6d2af70c92ab | 134 | |
darienf | 20:6d2af70c92ab | 135 | for (int i = 0; i < data.Length; i++ ) |
darienf | 20:6d2af70c92ab | 136 | { |
darienf | 20:6d2af70c92ab | 137 | rawCode = data[i]; |
darienf | 20:6d2af70c92ab | 138 | |
darienf | 20:6d2af70c92ab | 139 | if (rawCode > 0x7fff) |
darienf | 20:6d2af70c92ab | 140 | rawCode -= 0x10000; |
darienf | 20:6d2af70c92ab | 141 | |
darienf | 20:6d2af70c92ab | 142 | calcTemp[i] = rawCode / Math.Pow(2, 8); |
darienf | 20:6d2af70c92ab | 143 | } |
darienf | 20:6d2af70c92ab | 144 | |
darienf | 20:6d2af70c92ab | 145 | return calcTemp; |
darienf | 20:6d2af70c92ab | 146 | } |
darienf | 20:6d2af70c92ab | 147 | |
darienf | 20:6d2af70c92ab | 148 | public void ProcessPressure(int[] data) |
darienf | 20:6d2af70c92ab | 149 | { |
darienf | 20:6d2af70c92ab | 150 | int[] rawTemp = new int[data.Length/2]; |
darienf | 20:6d2af70c92ab | 151 | int[] rawPress = new int[data.Length/2]; |
darienf | 20:6d2af70c92ab | 152 | double[] calcTemp, calcPress; |
darienf | 20:6d2af70c92ab | 153 | |
darienf | 20:6d2af70c92ab | 154 | for (int i = 0, j = 0; i < data.Length; i = i + 2, j++) |
darienf | 20:6d2af70c92ab | 155 | { |
darienf | 20:6d2af70c92ab | 156 | rawTemp[j] = data[i]; |
darienf | 20:6d2af70c92ab | 157 | rawPress[j] = data[i + 1]; |
darienf | 20:6d2af70c92ab | 158 | } |
darienf | 20:6d2af70c92ab | 159 | |
darienf | 20:6d2af70c92ab | 160 | var result = CalculatePressure(rawTemp, rawPress); |
darienf | 20:6d2af70c92ab | 161 | calcTemp = result.Item1; |
darienf | 20:6d2af70c92ab | 162 | calcPress = result.Item2; |
darienf | 20:6d2af70c92ab | 163 | |
darienf | 20:6d2af70c92ab | 164 | pressureLog.DisplayPressure(rawTemp, calcTemp, rawPress, calcPress); |
darienf | 20:6d2af70c92ab | 165 | } |
darienf | 20:6d2af70c92ab | 166 | |
darienf | 20:6d2af70c92ab | 167 | public Tuple<double[], double[]> CalculatePressure(int[] temperature, int[] pressure) |
darienf | 20:6d2af70c92ab | 168 | { |
darienf | 20:6d2af70c92ab | 169 | double[] calcTemp = new double[temperature.Length]; |
darienf | 20:6d2af70c92ab | 170 | double[] calcPress = new double[pressure.Length]; |
darienf | 20:6d2af70c92ab | 171 | |
darienf | 20:6d2af70c92ab | 172 | for (int i = 0; i < temperature.Length; i++ ) |
darienf | 20:6d2af70c92ab | 173 | { |
darienf | 20:6d2af70c92ab | 174 | calcTemp[i] = temperature[i] / 10.0; |
darienf | 20:6d2af70c92ab | 175 | } |
darienf | 20:6d2af70c92ab | 176 | |
darienf | 20:6d2af70c92ab | 177 | for (int i = 0; i < pressure.Length; i++ ) |
darienf | 20:6d2af70c92ab | 178 | { |
darienf | 20:6d2af70c92ab | 179 | calcPress[i] = pressure[i] / 10; |
darienf | 20:6d2af70c92ab | 180 | } |
darienf | 20:6d2af70c92ab | 181 | |
darienf | 20:6d2af70c92ab | 182 | return new Tuple<double[],double[]>(calcTemp, calcPress); |
darienf | 20:6d2af70c92ab | 183 | } |
darienf | 20:6d2af70c92ab | 184 | |
darienf | 20:6d2af70c92ab | 185 | private void OnLogDownloadStart(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 186 | { |
darienf | 20:6d2af70c92ab | 187 | |
darienf | 20:6d2af70c92ab | 188 | if (view.Connected) |
darienf | 20:6d2af70c92ab | 189 | { |
darienf | 20:6d2af70c92ab | 190 | count = 0; |
darienf | 20:6d2af70c92ab | 191 | bioZCount = 0; |
darienf | 20:6d2af70c92ab | 192 | ppgCount = 0; |
darienf | 20:6d2af70c92ab | 193 | accelCount = 0; |
darienf | 20:6d2af70c92ab | 194 | |
darienf | 20:6d2af70c92ab | 195 | missionRead(); |
darienf | 20:6d2af70c92ab | 196 | |
darienf | 20:6d2af70c92ab | 197 | if (model.MissionSettings.Enable) |
darienf | 20:6d2af70c92ab | 198 | { |
darienf | 20:6d2af70c92ab | 199 | |
darienf | 20:6d2af70c92ab | 200 | if (selectFile()) |
darienf | 20:6d2af70c92ab | 201 | { |
darienf | 20:6d2af70c92ab | 202 | string missionString; |
darienf | 20:6d2af70c92ab | 203 | StringBuilder sb = new StringBuilder(); |
darienf | 20:6d2af70c92ab | 204 | foreach (string str in model.MissionString()) |
darienf | 20:6d2af70c92ab | 205 | { |
darienf | 20:6d2af70c92ab | 206 | sb.Append("% "); |
darienf | 20:6d2af70c92ab | 207 | sb.Append(str); |
darienf | 20:6d2af70c92ab | 208 | sb.Append(Environment.NewLine); |
darienf | 20:6d2af70c92ab | 209 | } |
darienf | 20:6d2af70c92ab | 210 | missionString = sb.ToString().Trim(Environment.NewLine.ToCharArray()); |
darienf | 20:6d2af70c92ab | 211 | |
darienf | 20:6d2af70c92ab | 212 | |
darienf | 20:6d2af70c92ab | 213 | if (temperatureLog1 != null && temperatureLog1.Enable) |
darienf | 20:6d2af70c92ab | 214 | { |
darienf | 20:6d2af70c92ab | 215 | temperatureLog1.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 216 | temperatureLog1.WriteLine(fileLogHeader.Temperature1); |
darienf | 20:6d2af70c92ab | 217 | } |
darienf | 20:6d2af70c92ab | 218 | |
darienf | 20:6d2af70c92ab | 219 | if (temperatureLog2 != null && temperatureLog2.Enable) |
darienf | 20:6d2af70c92ab | 220 | { |
darienf | 20:6d2af70c92ab | 221 | temperatureLog2.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 222 | temperatureLog2.WriteLine(fileLogHeader.Temperature2); |
darienf | 20:6d2af70c92ab | 223 | } |
darienf | 20:6d2af70c92ab | 224 | |
darienf | 20:6d2af70c92ab | 225 | if (pressureLog != null && pressureLog.Enable) |
darienf | 20:6d2af70c92ab | 226 | { |
darienf | 20:6d2af70c92ab | 227 | pressureLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 228 | pressureLog.WriteLine(fileLogHeader.Pressure); |
darienf | 20:6d2af70c92ab | 229 | } |
darienf | 20:6d2af70c92ab | 230 | |
darienf | 20:6d2af70c92ab | 231 | if (accelerometerLog != null && accelerometerLog.Enable) |
darienf | 20:6d2af70c92ab | 232 | { |
darienf | 20:6d2af70c92ab | 233 | accelerometerLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 234 | accelerometerLog.WriteLine(fileLogHeader.Accelerometer); |
darienf | 20:6d2af70c92ab | 235 | } |
darienf | 20:6d2af70c92ab | 236 | |
darienf | 20:6d2af70c92ab | 237 | if (opticalLog != null && opticalLog.Enable) |
darienf | 20:6d2af70c92ab | 238 | { |
darienf | 20:6d2af70c92ab | 239 | opticalLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 240 | opticalLog.WriteLine(fileLogHeader.Optical); |
darienf | 20:6d2af70c92ab | 241 | } |
darienf | 20:6d2af70c92ab | 242 | |
darienf | 20:6d2af70c92ab | 243 | if (ecgLog != null && ecgLog.Enable) |
darienf | 20:6d2af70c92ab | 244 | { |
darienf | 20:6d2af70c92ab | 245 | ecgLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 246 | ecgLog.WriteLine(fileLogHeader.Ecg); |
darienf | 20:6d2af70c92ab | 247 | } |
darienf | 20:6d2af70c92ab | 248 | |
darienf | 20:6d2af70c92ab | 249 | if (bioZLog != null && bioZLog.Enable) |
darienf | 20:6d2af70c92ab | 250 | { |
darienf | 20:6d2af70c92ab | 251 | bioZLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 252 | bioZLog.WriteLine(fileLogHeader.BioZ); |
darienf | 20:6d2af70c92ab | 253 | } |
darienf | 20:6d2af70c92ab | 254 | |
darienf | 20:6d2af70c92ab | 255 | if (rToRLog != null && rToRLog.Enable && ecgLog.Enable) |
darienf | 20:6d2af70c92ab | 256 | { |
darienf | 20:6d2af70c92ab | 257 | rToRLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 258 | rToRCalculator = new RToRCalculator(ecgView.MasterClockField, view.EcgArgs.Rate, view.EcgArgs.Dlpf, view.RToRArgs.Wndw); |
darienf | 20:6d2af70c92ab | 259 | rToRLog.WriteLine(fileLogHeader.RToR); |
darienf | 20:6d2af70c92ab | 260 | } |
darienf | 20:6d2af70c92ab | 261 | else if (rToRLog != null && rToRLog.Enable) |
darienf | 20:6d2af70c92ab | 262 | { |
darienf | 20:6d2af70c92ab | 263 | rToRLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 264 | rToRCalculator = null; |
darienf | 20:6d2af70c92ab | 265 | rToRLog.WriteLine(fileLogHeader.RToR); |
darienf | 20:6d2af70c92ab | 266 | } |
darienf | 20:6d2af70c92ab | 267 | |
darienf | 20:6d2af70c92ab | 268 | if (paceLog != null && paceLog.Enable) |
darienf | 20:6d2af70c92ab | 269 | { |
darienf | 20:6d2af70c92ab | 270 | paceLog.WriteLine(missionString); |
darienf | 20:6d2af70c92ab | 271 | paceLog.WriteLine(fileLogHeader.Pace); |
darienf | 20:6d2af70c92ab | 272 | } |
darienf | 20:6d2af70c92ab | 273 | |
darienf | 20:6d2af70c92ab | 274 | statusForm = new StatusForm(); |
darienf | 20:6d2af70c92ab | 275 | statusForm.Text = "Flash Download"; |
darienf | 20:6d2af70c92ab | 276 | statusForm.Message = "Please wait while your data is saved to your file."; |
darienf | 20:6d2af70c92ab | 277 | statusForm.Show(); |
darienf | 20:6d2af70c92ab | 278 | |
darienf | 20:6d2af70c92ab | 279 | model.Start(); |
darienf | 20:6d2af70c92ab | 280 | } |
darienf | 20:6d2af70c92ab | 281 | } |
darienf | 20:6d2af70c92ab | 282 | } |
darienf | 20:6d2af70c92ab | 283 | } |
darienf | 20:6d2af70c92ab | 284 | |
darienf | 20:6d2af70c92ab | 285 | private void LogDownloadStop() |
darienf | 20:6d2af70c92ab | 286 | { |
darienf | 20:6d2af70c92ab | 287 | if (temperatureLog1 != null && temperatureLog1.Enable) |
darienf | 20:6d2af70c92ab | 288 | temperatureLog1.Enable = false; |
darienf | 20:6d2af70c92ab | 289 | |
darienf | 20:6d2af70c92ab | 290 | if (temperatureLog2 != null && temperatureLog2.Enable) |
darienf | 20:6d2af70c92ab | 291 | temperatureLog2.Enable = false; |
darienf | 20:6d2af70c92ab | 292 | |
darienf | 20:6d2af70c92ab | 293 | if (pressureLog != null && pressureLog.Enable) |
darienf | 20:6d2af70c92ab | 294 | pressureLog.Enable = false; |
darienf | 20:6d2af70c92ab | 295 | |
darienf | 20:6d2af70c92ab | 296 | if (accelerometerLog != null && accelerometerLog.Enable) |
darienf | 20:6d2af70c92ab | 297 | accelerometerLog.Enable = false; |
darienf | 20:6d2af70c92ab | 298 | |
darienf | 20:6d2af70c92ab | 299 | if (opticalLog != null && opticalLog.Enable) |
darienf | 20:6d2af70c92ab | 300 | opticalLog.Enable = false; |
darienf | 20:6d2af70c92ab | 301 | |
darienf | 20:6d2af70c92ab | 302 | if (ecgLog != null && ecgLog.Enable) |
darienf | 20:6d2af70c92ab | 303 | ecgLog.Enable = false; |
darienf | 20:6d2af70c92ab | 304 | |
darienf | 20:6d2af70c92ab | 305 | if (bioZLog != null && bioZLog.Enable) |
darienf | 20:6d2af70c92ab | 306 | bioZLog.Enable = false; |
darienf | 20:6d2af70c92ab | 307 | |
darienf | 20:6d2af70c92ab | 308 | if (rToRLog != null && rToRLog.Enable) |
darienf | 20:6d2af70c92ab | 309 | rToRLog.Enable = false; |
darienf | 20:6d2af70c92ab | 310 | |
darienf | 20:6d2af70c92ab | 311 | if (paceLog != null && paceLog.Enable) |
darienf | 20:6d2af70c92ab | 312 | paceLog.Enable = false; |
darienf | 20:6d2af70c92ab | 313 | |
darienf | 20:6d2af70c92ab | 314 | formView.MessageInfo("File save complete"); |
darienf | 20:6d2af70c92ab | 315 | statusForm.Hide(); |
darienf | 20:6d2af70c92ab | 316 | } |
darienf | 20:6d2af70c92ab | 317 | |
darienf | 20:6d2af70c92ab | 318 | private void OnLogData(object sender, PartialArrayIntAvailableEventArgs e) |
darienf | 20:6d2af70c92ab | 319 | { |
darienf | 20:6d2af70c92ab | 320 | switch(e.reportID) |
darienf | 20:6d2af70c92ab | 321 | { |
darienf | 20:6d2af70c92ab | 322 | case PartialArrayIntAvailableEventArgs.PACKET_BMP280_PRESSURE: |
darienf | 20:6d2af70c92ab | 323 | if (pressureLog != null && pressureLog.Enable) |
darienf | 20:6d2af70c92ab | 324 | ProcessPressure(e.array1); |
darienf | 20:6d2af70c92ab | 325 | break; |
darienf | 20:6d2af70c92ab | 326 | case PartialArrayIntAvailableEventArgs.PACKET_MAX31725_TEMP1: |
darienf | 20:6d2af70c92ab | 327 | if (temperatureLog1 != null && temperatureLog1.Enable) |
darienf | 20:6d2af70c92ab | 328 | ProcessTemperature1(e.array1); |
darienf | 20:6d2af70c92ab | 329 | break; |
darienf | 20:6d2af70c92ab | 330 | case PartialArrayIntAvailableEventArgs.PACKET_MAX31725_TEMP2: |
darienf | 20:6d2af70c92ab | 331 | if (temperatureLog2 != null && temperatureLog2.Enable) |
darienf | 20:6d2af70c92ab | 332 | ProcessTemperature2(e.array1); |
darienf | 20:6d2af70c92ab | 333 | break; |
darienf | 20:6d2af70c92ab | 334 | |
darienf | 20:6d2af70c92ab | 335 | case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_ECG: |
darienf | 20:6d2af70c92ab | 336 | if (ecgLog != null && ecgLog.Enable) |
darienf | 20:6d2af70c92ab | 337 | ProcessEcg(e.array1); |
darienf | 20:6d2af70c92ab | 338 | break; |
darienf | 20:6d2af70c92ab | 339 | case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_BIOZ: |
darienf | 20:6d2af70c92ab | 340 | if (bioZLog != null && bioZLog.Enable) |
darienf | 20:6d2af70c92ab | 341 | ProcessBioZ(e.array1); |
darienf | 20:6d2af70c92ab | 342 | break; |
darienf | 20:6d2af70c92ab | 343 | case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_PACE: |
darienf | 20:6d2af70c92ab | 344 | if (paceLog != null && paceLog.Enable) |
darienf | 20:6d2af70c92ab | 345 | paceData = new PaceData(e.array1); |
darienf | 20:6d2af70c92ab | 346 | break; |
darienf | 20:6d2af70c92ab | 347 | case PartialArrayIntAvailableEventArgs.PACKET_MAX30001_RTOR: |
darienf | 20:6d2af70c92ab | 348 | if (rToRLog != null && rToRLog.Enable) |
darienf | 20:6d2af70c92ab | 349 | ProcessRToR(e.array1[0]); |
darienf | 20:6d2af70c92ab | 350 | break; |
darienf | 20:6d2af70c92ab | 351 | |
darienf | 20:6d2af70c92ab | 352 | case PartialArrayIntAvailableEventArgs.PACKET_LIS2DH: |
darienf | 20:6d2af70c92ab | 353 | case PartialArrayIntAvailableEventArgs.PACKET_LSM6DS3_ACCEL: |
darienf | 20:6d2af70c92ab | 354 | if (accelerometerLog != null && accelerometerLog.Enable) |
darienf | 20:6d2af70c92ab | 355 | ProcessAccelerometer(e.array1, e.array2, e.array3); |
darienf | 20:6d2af70c92ab | 356 | break; |
darienf | 20:6d2af70c92ab | 357 | case PartialArrayIntAvailableEventArgs.PACKET_END_OF_STREAM: |
darienf | 20:6d2af70c92ab | 358 | LogDownloadStop(); |
darienf | 20:6d2af70c92ab | 359 | break; |
darienf | 20:6d2af70c92ab | 360 | } |
darienf | 20:6d2af70c92ab | 361 | |
darienf | 20:6d2af70c92ab | 362 | if ((e.reportID & 0xF0) == PartialArrayIntAvailableEventArgs.PACKET_MAX30101) |
darienf | 20:6d2af70c92ab | 363 | { |
darienf | 20:6d2af70c92ab | 364 | if (opticalLog != null && opticalLog.Enable) |
darienf | 20:6d2af70c92ab | 365 | ProcessOptical(e.array1, e.array2, e.array3); |
darienf | 20:6d2af70c92ab | 366 | |
darienf | 20:6d2af70c92ab | 367 | } |
darienf | 20:6d2af70c92ab | 368 | } |
darienf | 20:6d2af70c92ab | 369 | |
darienf | 20:6d2af70c92ab | 370 | private void OnMissionWrite(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 371 | { |
darienf | 20:6d2af70c92ab | 372 | if (view.Connected) |
darienf | 20:6d2af70c92ab | 373 | { |
darienf | 20:6d2af70c92ab | 374 | if (view.EnableAccelerometer || view.EnableBioz || view.EnableEcg || view.EnableOpticalHR |
darienf | 20:6d2af70c92ab | 375 | || view.EnableOpticalMulti || view.EnableOpticalSpO2 || view.EnablePace |
darienf | 20:6d2af70c92ab | 376 | || view.EnablePressure || view.EnableRToR || view.EnableTemperature1 || view.EnableTemperature2) |
darienf | 20:6d2af70c92ab | 377 | { |
darienf | 20:6d2af70c92ab | 378 | if (view.ValidateGuiElements()) |
darienf | 20:6d2af70c92ab | 379 | { |
darienf | 20:6d2af70c92ab | 380 | statusForm = new StatusForm(); |
darienf | 20:6d2af70c92ab | 381 | statusForm.Message = "Please wait while your flash log is cleared and new parameters are written. Do not unplug the USB connection or press start button on the board until write is complete."; |
darienf | 20:6d2af70c92ab | 382 | statusForm.Show(); |
darienf | 20:6d2af70c92ab | 383 | formView.MessageInfo("Writing in progress..."); |
darienf | 20:6d2af70c92ab | 384 | model.MissionErase(); |
darienf | 20:6d2af70c92ab | 385 | model.EraseWrittenSectors(); |
darienf | 20:6d2af70c92ab | 386 | model.MissionStartDefinition(); |
darienf | 20:6d2af70c92ab | 387 | view.ProcessGuiElements(); |
darienf | 20:6d2af70c92ab | 388 | //rpcClient.DataLogging.Test(); |
darienf | 20:6d2af70c92ab | 389 | model.MissionWrite(); |
darienf | 20:6d2af70c92ab | 390 | statusForm.Hide(); |
darienf | 20:6d2af70c92ab | 391 | formView.MessageInfo("Write parameters complete"); |
darienf | 20:6d2af70c92ab | 392 | } |
darienf | 20:6d2af70c92ab | 393 | else |
darienf | 20:6d2af70c92ab | 394 | formView.MessageInfo("Incorrect logging parameters"); |
darienf | 20:6d2af70c92ab | 395 | } |
darienf | 20:6d2af70c92ab | 396 | else |
darienf | 20:6d2af70c92ab | 397 | { |
darienf | 20:6d2af70c92ab | 398 | formView.MessageInfo("No devices selected"); |
darienf | 20:6d2af70c92ab | 399 | } |
darienf | 20:6d2af70c92ab | 400 | } |
darienf | 20:6d2af70c92ab | 401 | } |
darienf | 20:6d2af70c92ab | 402 | |
darienf | 20:6d2af70c92ab | 403 | private void OnMissionRead(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 404 | { |
darienf | 20:6d2af70c92ab | 405 | if (view.Connected) |
darienf | 20:6d2af70c92ab | 406 | { |
darienf | 20:6d2af70c92ab | 407 | missionRead(); |
darienf | 20:6d2af70c92ab | 408 | } |
darienf | 20:6d2af70c92ab | 409 | } |
darienf | 20:6d2af70c92ab | 410 | |
darienf | 20:6d2af70c92ab | 411 | private void OnMissionErase(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 412 | { |
darienf | 20:6d2af70c92ab | 413 | if (view.Connected) |
darienf | 20:6d2af70c92ab | 414 | { |
darienf | 20:6d2af70c92ab | 415 | model.MissionErase(); |
darienf | 20:6d2af70c92ab | 416 | |
darienf | 20:6d2af70c92ab | 417 | formView.MessageInfo("Erase parameters complete"); |
darienf | 20:6d2af70c92ab | 418 | } |
darienf | 20:6d2af70c92ab | 419 | } |
darienf | 20:6d2af70c92ab | 420 | |
darienf | 20:6d2af70c92ab | 421 | private void OnLogFileEnable(object sender, EnableEventArgs e) |
darienf | 20:6d2af70c92ab | 422 | { |
darienf | 20:6d2af70c92ab | 423 | // Not used |
darienf | 20:6d2af70c92ab | 424 | } |
darienf | 20:6d2af70c92ab | 425 | |
darienf | 20:6d2af70c92ab | 426 | private bool selectFile() |
darienf | 20:6d2af70c92ab | 427 | { |
darienf | 20:6d2af70c92ab | 428 | bool result = false; |
darienf | 20:6d2af70c92ab | 429 | |
darienf | 20:6d2af70c92ab | 430 | Mission settings = model.MissionSettings; |
darienf | 20:6d2af70c92ab | 431 | |
darienf | 20:6d2af70c92ab | 432 | if (settings.EnableEcg) |
darienf | 20:6d2af70c92ab | 433 | result |= selectLogFileName(ecgLog, "hsp-log-ecg"); |
darienf | 20:6d2af70c92ab | 434 | |
darienf | 20:6d2af70c92ab | 435 | if (settings.EnablePace) |
darienf | 20:6d2af70c92ab | 436 | result |= selectLogFileName(paceLog, "hsp-log-pace"); |
darienf | 20:6d2af70c92ab | 437 | |
darienf | 20:6d2af70c92ab | 438 | if (settings.EnableBioZ) |
darienf | 20:6d2af70c92ab | 439 | result |= selectLogFileName(bioZLog, "hsp-log-bioz"); |
darienf | 20:6d2af70c92ab | 440 | |
darienf | 20:6d2af70c92ab | 441 | if (settings.EnableRToR) |
darienf | 20:6d2af70c92ab | 442 | result |= selectLogFileName(rToRLog, "hsp-log-rtor"); |
darienf | 20:6d2af70c92ab | 443 | |
darienf | 20:6d2af70c92ab | 444 | if (settings.EnableOpticalHR || settings.EnableOpticalMulti || settings.EnableOpticalSpO2) |
darienf | 20:6d2af70c92ab | 445 | result |= selectLogFileName(opticalLog, "hsp-log-optical"); |
darienf | 20:6d2af70c92ab | 446 | |
darienf | 20:6d2af70c92ab | 447 | if (settings.EnableTemperature1) |
darienf | 20:6d2af70c92ab | 448 | result |= selectLogFileName(temperatureLog1, "hsp-log-temperature1"); |
darienf | 20:6d2af70c92ab | 449 | |
darienf | 20:6d2af70c92ab | 450 | if (settings.EnableTemperature2) |
darienf | 20:6d2af70c92ab | 451 | result |= selectLogFileName(temperatureLog2, "hsp-log-temperature2"); |
darienf | 20:6d2af70c92ab | 452 | |
darienf | 20:6d2af70c92ab | 453 | if (settings.EnablePressure) |
darienf | 20:6d2af70c92ab | 454 | result |= selectLogFileName(pressureLog, "hsp-log-barometer"); |
darienf | 20:6d2af70c92ab | 455 | |
darienf | 20:6d2af70c92ab | 456 | if (settings.EnableAccelerometer) |
darienf | 20:6d2af70c92ab | 457 | result |= selectLogFileName(accelerometerLog, "hsp-log-accelerometer"); |
darienf | 20:6d2af70c92ab | 458 | |
darienf | 20:6d2af70c92ab | 459 | return result; |
darienf | 20:6d2af70c92ab | 460 | } |
darienf | 20:6d2af70c92ab | 461 | |
darienf | 20:6d2af70c92ab | 462 | bool selectLogFileName(IRawFileLogView log, string name) |
darienf | 20:6d2af70c92ab | 463 | { |
darienf | 20:6d2af70c92ab | 464 | bool result; |
darienf | 20:6d2af70c92ab | 465 | |
darienf | 20:6d2af70c92ab | 466 | if (logFileDirectory != null) |
darienf | 20:6d2af70c92ab | 467 | log.FileDirectory = logFileDirectory; |
darienf | 20:6d2af70c92ab | 468 | |
darienf | 20:6d2af70c92ab | 469 | result = log.SelectCSVFile(name); |
darienf | 20:6d2af70c92ab | 470 | log.Enable = result; |
darienf | 20:6d2af70c92ab | 471 | |
darienf | 20:6d2af70c92ab | 472 | if (result) |
darienf | 20:6d2af70c92ab | 473 | logFileDirectory = log.FileDirectory; |
darienf | 20:6d2af70c92ab | 474 | |
darienf | 20:6d2af70c92ab | 475 | return result; |
darienf | 20:6d2af70c92ab | 476 | } |
darienf | 20:6d2af70c92ab | 477 | |
darienf | 20:6d2af70c92ab | 478 | private void missionRead() |
darienf | 20:6d2af70c92ab | 479 | { |
darienf | 20:6d2af70c92ab | 480 | model.MissionRead(); |
darienf | 20:6d2af70c92ab | 481 | view.UpdateGuiElements(model.MissionSettings); |
darienf | 20:6d2af70c92ab | 482 | if (model.MissionSettings.Enable) |
darienf | 20:6d2af70c92ab | 483 | formView.MessageInfo("Read complete"); |
darienf | 20:6d2af70c92ab | 484 | else |
darienf | 20:6d2af70c92ab | 485 | formView.MessageInfo("No parameters defined"); |
darienf | 20:6d2af70c92ab | 486 | } |
darienf | 20:6d2af70c92ab | 487 | |
darienf | 20:6d2af70c92ab | 488 | void ProcessBioZ(int[] rawData) |
darienf | 20:6d2af70c92ab | 489 | { |
darienf | 20:6d2af70c92ab | 490 | BioZFifo[] bioZFifo; |
darienf | 20:6d2af70c92ab | 491 | double[] time = new double[rawData.Length]; |
darienf | 20:6d2af70c92ab | 492 | double sampleRate = ecgView.SampleRateBioZ; |
darienf | 20:6d2af70c92ab | 493 | |
darienf | 20:6d2af70c92ab | 494 | bioZFifo = ConvertBioZ(rawData); |
darienf | 20:6d2af70c92ab | 495 | |
darienf | 20:6d2af70c92ab | 496 | for (int i = 0; i < time.Length; i++ ) |
darienf | 20:6d2af70c92ab | 497 | { |
darienf | 20:6d2af70c92ab | 498 | time[i] = bioZCount / (double)sampleRate; |
darienf | 20:6d2af70c92ab | 499 | bioZCount++; |
darienf | 20:6d2af70c92ab | 500 | } |
darienf | 20:6d2af70c92ab | 501 | |
darienf | 20:6d2af70c92ab | 502 | bioZLog.DisplayBioZ(time, bioZFifo); |
darienf | 20:6d2af70c92ab | 503 | } |
darienf | 20:6d2af70c92ab | 504 | |
darienf | 20:6d2af70c92ab | 505 | public BioZFifo[] ConvertBioZ(int[] data) |
darienf | 20:6d2af70c92ab | 506 | { |
darienf | 20:6d2af70c92ab | 507 | BioZFifo[] impedance = new BioZFifo[data.Length]; |
darienf | 20:6d2af70c92ab | 508 | //EcgView.ChartInfo chartInfo = BioZInfo(); |
darienf | 20:6d2af70c92ab | 509 | EcgView.ChartInfo chartInfo = ecgView.BioZInfo; |
darienf | 20:6d2af70c92ab | 510 | |
darienf | 20:6d2af70c92ab | 511 | int dataShift; |
darienf | 20:6d2af70c92ab | 512 | |
darienf | 20:6d2af70c92ab | 513 | for (int i = 0; i < data.Length; i++) |
darienf | 20:6d2af70c92ab | 514 | { |
darienf | 20:6d2af70c92ab | 515 | dataShift = data[i] >> chartInfo.Shift; |
darienf | 20:6d2af70c92ab | 516 | |
darienf | 20:6d2af70c92ab | 517 | // Two's Complement Conversions |
darienf | 20:6d2af70c92ab | 518 | if (dataShift > chartInfo.Threshold) |
darienf | 20:6d2af70c92ab | 519 | { |
darienf | 20:6d2af70c92ab | 520 | dataShift -= chartInfo.Offset; |
darienf | 20:6d2af70c92ab | 521 | } |
darienf | 20:6d2af70c92ab | 522 | |
darienf | 20:6d2af70c92ab | 523 | // 1.9734 = 1/2^19 * 1e-6 |
darienf | 20:6d2af70c92ab | 524 | impedance[i].Data = dataShift * 1.9073486328125 / |
darienf | 20:6d2af70c92ab | 525 | (chartInfo.Gain * ((chartInfo.CurrentGenerator == 0) ? 1 : chartInfo.CurrentGenerator)); |
darienf | 20:6d2af70c92ab | 526 | impedance[i].Code = data[i]; |
darienf | 20:6d2af70c92ab | 527 | impedance[i].BioZData = dataShift; |
darienf | 20:6d2af70c92ab | 528 | impedance[i].BTag = data[i] & 0x07; |
darienf | 20:6d2af70c92ab | 529 | } |
darienf | 20:6d2af70c92ab | 530 | |
darienf | 20:6d2af70c92ab | 531 | return impedance; |
darienf | 20:6d2af70c92ab | 532 | } |
darienf | 20:6d2af70c92ab | 533 | |
darienf | 20:6d2af70c92ab | 534 | public EcgView.ChartInfo BioZInfo() |
darienf | 20:6d2af70c92ab | 535 | { |
darienf | 20:6d2af70c92ab | 536 | EcgView.ChartInfo info = new EcgView.ChartInfo(); |
darienf | 20:6d2af70c92ab | 537 | int[] currentGen = new int[] {1, 8, 16, 32, 48, 64, 80, 96}; |
darienf | 20:6d2af70c92ab | 538 | int[] gain = new int[] {20, 40, 80, 160}; |
darienf | 20:6d2af70c92ab | 539 | |
darienf | 20:6d2af70c92ab | 540 | info.Shift = 4; |
darienf | 20:6d2af70c92ab | 541 | info.Offset = 0x100000; |
darienf | 20:6d2af70c92ab | 542 | info.Threshold = 0x100000; |
darienf | 20:6d2af70c92ab | 543 | info.Gain = gain[model.MissionSettings.BioZArgs[10]]; |
darienf | 20:6d2af70c92ab | 544 | info.CurrentGenerator = currentGen[model.MissionSettings.BioZArgs[15]]; |
darienf | 20:6d2af70c92ab | 545 | |
darienf | 20:6d2af70c92ab | 546 | return info; |
darienf | 20:6d2af70c92ab | 547 | } |
darienf | 20:6d2af70c92ab | 548 | |
darienf | 20:6d2af70c92ab | 549 | void ProcessEcg(int[] rawData) |
darienf | 20:6d2af70c92ab | 550 | { |
darienf | 20:6d2af70c92ab | 551 | EcgFifo[] ecgFifo; |
darienf | 20:6d2af70c92ab | 552 | double[] ecgVoltage = new double[rawData.Length]; |
darienf | 20:6d2af70c92ab | 553 | double[] timeSecond = new double[rawData.Length]; |
darienf | 20:6d2af70c92ab | 554 | double ecgRate = ecgView.SampleRateEcg; |
darienf | 20:6d2af70c92ab | 555 | |
darienf | 20:6d2af70c92ab | 556 | ecgFifo = ConvertEcg(rawData); |
darienf | 20:6d2af70c92ab | 557 | |
darienf | 20:6d2af70c92ab | 558 | for (int i = 0; i < ecgFifo.Length; i++) |
darienf | 20:6d2af70c92ab | 559 | { |
darienf | 20:6d2af70c92ab | 560 | timeSecond[i] = count / ecgRate; |
darienf | 20:6d2af70c92ab | 561 | |
darienf | 20:6d2af70c92ab | 562 | // Look for Pace Events |
darienf | 20:6d2af70c92ab | 563 | if (paceLog.Enable) |
darienf | 20:6d2af70c92ab | 564 | { |
darienf | 20:6d2af70c92ab | 565 | //for (int j = 0; j < ecgFifo.Length; j++) |
darienf | 20:6d2af70c92ab | 566 | //{ |
darienf | 20:6d2af70c92ab | 567 | if (ecgFifo[i].PTag != 7) |
darienf | 20:6d2af70c92ab | 568 | { |
darienf | 20:6d2af70c92ab | 569 | PaceData.PaceRegister paceRegister = paceData.PaceGroup(ecgFifo[i].PTag); |
darienf | 20:6d2af70c92ab | 570 | List<double> timeMillsecondPace = new List<double>(); |
darienf | 20:6d2af70c92ab | 571 | List<PaceData.PaceEdge> paceEdges = new List<PaceData.PaceEdge>(); |
darienf | 20:6d2af70c92ab | 572 | |
darienf | 20:6d2af70c92ab | 573 | for (int k = 0; k < 6; k++) |
darienf | 20:6d2af70c92ab | 574 | { |
darienf | 20:6d2af70c92ab | 575 | PaceData.PaceEdge edge = paceRegister.Edge[k]; |
darienf | 20:6d2af70c92ab | 576 | |
darienf | 20:6d2af70c92ab | 577 | timeMillsecondPace.Add(count / ecgRate + ConvertPace(edge.Data)); |
darienf | 20:6d2af70c92ab | 578 | paceEdges.Add(edge); |
darienf | 20:6d2af70c92ab | 579 | |
darienf | 20:6d2af70c92ab | 580 | if (edge.Last == true) |
darienf | 20:6d2af70c92ab | 581 | break; |
darienf | 20:6d2af70c92ab | 582 | } |
darienf | 20:6d2af70c92ab | 583 | |
darienf | 20:6d2af70c92ab | 584 | paceLog.DisplayPace(timeMillsecondPace.ToArray(), paceEdges.ToArray()); |
darienf | 20:6d2af70c92ab | 585 | System.Diagnostics.Debug.Print("ECG PTag = " + ecgFifo[i].PTag); |
darienf | 20:6d2af70c92ab | 586 | } |
darienf | 20:6d2af70c92ab | 587 | //} |
darienf | 20:6d2af70c92ab | 588 | } |
darienf | 20:6d2af70c92ab | 589 | |
darienf | 20:6d2af70c92ab | 590 | count++; |
darienf | 20:6d2af70c92ab | 591 | } |
darienf | 20:6d2af70c92ab | 592 | |
darienf | 20:6d2af70c92ab | 593 | ecgLog.DisplayEcg(timeSecond, ecgFifo); |
darienf | 20:6d2af70c92ab | 594 | |
darienf | 20:6d2af70c92ab | 595 | } |
darienf | 20:6d2af70c92ab | 596 | |
darienf | 20:6d2af70c92ab | 597 | public EcgFifo[] ConvertEcg(int[] data) |
darienf | 20:6d2af70c92ab | 598 | { |
darienf | 20:6d2af70c92ab | 599 | EcgFifo[] voltage = new EcgFifo[data.Length]; |
darienf | 20:6d2af70c92ab | 600 | //EcgView.ChartInfo chartInfo = EcgInfo(); |
darienf | 20:6d2af70c92ab | 601 | EcgView.ChartInfo chartInfo = ecgView.EcgInfo; |
darienf | 20:6d2af70c92ab | 602 | |
darienf | 20:6d2af70c92ab | 603 | int dataShift; |
darienf | 20:6d2af70c92ab | 604 | |
darienf | 20:6d2af70c92ab | 605 | for (int i = 0; i < data.Length; i++) |
darienf | 20:6d2af70c92ab | 606 | { |
darienf | 20:6d2af70c92ab | 607 | dataShift = data[i] >> chartInfo.Shift; |
darienf | 20:6d2af70c92ab | 608 | |
darienf | 20:6d2af70c92ab | 609 | // Two's Complement Conversions |
darienf | 20:6d2af70c92ab | 610 | if (dataShift > chartInfo.Threshold) |
darienf | 20:6d2af70c92ab | 611 | { |
darienf | 20:6d2af70c92ab | 612 | dataShift -= chartInfo.Offset; |
darienf | 20:6d2af70c92ab | 613 | } |
darienf | 20:6d2af70c92ab | 614 | |
darienf | 20:6d2af70c92ab | 615 | voltage[i].Data = 1000 * 7.62939453125e-6 * dataShift / chartInfo.Gain; |
darienf | 20:6d2af70c92ab | 616 | voltage[i].EcgData = dataShift; |
darienf | 20:6d2af70c92ab | 617 | voltage[i].Code = data[i]; |
darienf | 20:6d2af70c92ab | 618 | voltage[i].PTag = data[i] & 0x07; |
darienf | 20:6d2af70c92ab | 619 | voltage[i].ETag = (data[i] >> 3) & 0x07; |
darienf | 20:6d2af70c92ab | 620 | } |
darienf | 20:6d2af70c92ab | 621 | |
darienf | 20:6d2af70c92ab | 622 | return voltage; |
darienf | 20:6d2af70c92ab | 623 | } |
darienf | 20:6d2af70c92ab | 624 | |
darienf | 20:6d2af70c92ab | 625 | public EcgView.ChartInfo EcgInfo() |
darienf | 20:6d2af70c92ab | 626 | { |
darienf | 20:6d2af70c92ab | 627 | EcgView.ChartInfo info = new EcgView.ChartInfo(); |
darienf | 20:6d2af70c92ab | 628 | int[] gain = new int[] {20, 40, 80, 160}; |
darienf | 20:6d2af70c92ab | 629 | |
darienf | 20:6d2af70c92ab | 630 | info.Shift = 6; |
darienf | 20:6d2af70c92ab | 631 | info.Threshold = 0x1ffff; |
darienf | 20:6d2af70c92ab | 632 | info.Offset = 0x40000; |
darienf | 20:6d2af70c92ab | 633 | |
darienf | 20:6d2af70c92ab | 634 | info.Gain = gain[model.MissionSettings.EcgArgs[10]]; |
darienf | 20:6d2af70c92ab | 635 | |
darienf | 20:6d2af70c92ab | 636 | return info; |
darienf | 20:6d2af70c92ab | 637 | } |
darienf | 20:6d2af70c92ab | 638 | |
darienf | 20:6d2af70c92ab | 639 | public double ConvertRToR(int data) |
darienf | 20:6d2af70c92ab | 640 | { |
darienf | 20:6d2af70c92ab | 641 | return ecgView.TimeResolution * 1000 * data * 512; |
darienf | 20:6d2af70c92ab | 642 | } |
darienf | 20:6d2af70c92ab | 643 | |
darienf | 20:6d2af70c92ab | 644 | public double ConvertPace(int data) |
darienf | 20:6d2af70c92ab | 645 | { |
darienf | 20:6d2af70c92ab | 646 | return data * ecgView.TimeResolution; |
darienf | 20:6d2af70c92ab | 647 | } |
darienf | 20:6d2af70c92ab | 648 | |
darienf | 20:6d2af70c92ab | 649 | public string PaceRegisterGroupToString(PaceData.PaceRegister paceRegister) |
darienf | 20:6d2af70c92ab | 650 | { |
darienf | 20:6d2af70c92ab | 651 | StringBuilder paceRegisterLogBuilder = new StringBuilder(); |
darienf | 20:6d2af70c92ab | 652 | for (int j = 0; j < 6; j++) |
darienf | 20:6d2af70c92ab | 653 | { |
darienf | 20:6d2af70c92ab | 654 | paceRegisterLogBuilder.Append(paceRegister.Edge[j].Data / (2 * ecgView.MasterClockFrequency)); |
darienf | 20:6d2af70c92ab | 655 | paceRegisterLogBuilder.Append(", "); |
darienf | 20:6d2af70c92ab | 656 | paceRegisterLogBuilder.Append(paceRegister.Edge[j].Polarity ? 'R' : 'F'); |
darienf | 20:6d2af70c92ab | 657 | paceRegisterLogBuilder.Append(", "); |
darienf | 20:6d2af70c92ab | 658 | paceRegisterLogBuilder.Append(paceRegister.Edge[j].Last ? 'Y' : 'N'); |
darienf | 20:6d2af70c92ab | 659 | paceRegisterLogBuilder.Append(", "); |
darienf | 20:6d2af70c92ab | 660 | } |
darienf | 20:6d2af70c92ab | 661 | |
darienf | 20:6d2af70c92ab | 662 | return paceRegisterLogBuilder.ToString(); |
darienf | 20:6d2af70c92ab | 663 | } |
darienf | 20:6d2af70c92ab | 664 | |
darienf | 20:6d2af70c92ab | 665 | void ProcessRToR(int data) |
darienf | 20:6d2af70c92ab | 666 | { |
darienf | 20:6d2af70c92ab | 667 | if (rToRCalculator != null) |
darienf | 20:6d2af70c92ab | 668 | { |
darienf | 20:6d2af70c92ab | 669 | if (rToRFirst) |
darienf | 20:6d2af70c92ab | 670 | { |
darienf | 20:6d2af70c92ab | 671 | rToRLog.DisplayRToR(data, rToRCalculator.Corrected(data, true) / 1000); |
darienf | 20:6d2af70c92ab | 672 | rToRFirst = false; |
darienf | 20:6d2af70c92ab | 673 | } |
darienf | 20:6d2af70c92ab | 674 | else |
darienf | 20:6d2af70c92ab | 675 | rToRLog.DisplayRToR(data, rToRCalculator.Corrected(data, false) / 1000); |
darienf | 20:6d2af70c92ab | 676 | } |
darienf | 20:6d2af70c92ab | 677 | else |
darienf | 20:6d2af70c92ab | 678 | { |
darienf | 20:6d2af70c92ab | 679 | rToRLog.DisplayRToR(data, 0); |
darienf | 20:6d2af70c92ab | 680 | } |
darienf | 20:6d2af70c92ab | 681 | } |
darienf | 20:6d2af70c92ab | 682 | |
darienf | 20:6d2af70c92ab | 683 | public void ProcessOptical(int[] red, int[] ir, int[] green) |
darienf | 20:6d2af70c92ab | 684 | { |
darienf | 20:6d2af70c92ab | 685 | int sampleRate = opticalView.OpticalSampleRate; |
darienf | 20:6d2af70c92ab | 686 | double[] time = new double[red.Length]; |
darienf | 20:6d2af70c92ab | 687 | |
darienf | 20:6d2af70c92ab | 688 | for (int i = 0; i < time.Length; i++ ) |
darienf | 20:6d2af70c92ab | 689 | { |
darienf | 20:6d2af70c92ab | 690 | time[i] = ppgCount / (double)sampleRate; |
darienf | 20:6d2af70c92ab | 691 | ppgCount++; |
darienf | 20:6d2af70c92ab | 692 | } |
darienf | 20:6d2af70c92ab | 693 | |
darienf | 20:6d2af70c92ab | 694 | opticalLog.DisplayPpg(time, new int[][] { red, ir, green }); |
darienf | 20:6d2af70c92ab | 695 | } |
darienf | 20:6d2af70c92ab | 696 | |
darienf | 20:6d2af70c92ab | 697 | public void ProcessAccelerometer(int[] x, int[] y, int[] z) |
darienf | 20:6d2af70c92ab | 698 | { |
darienf | 20:6d2af70c92ab | 699 | int sampleRate = view.AccelSampleRate; |
darienf | 20:6d2af70c92ab | 700 | double[] time = new double[x.Length]; |
darienf | 20:6d2af70c92ab | 701 | |
darienf | 20:6d2af70c92ab | 702 | for (int i = 0; i < time.Length; i++) |
darienf | 20:6d2af70c92ab | 703 | { |
darienf | 20:6d2af70c92ab | 704 | time[i] = accelCount / (double)sampleRate; |
darienf | 20:6d2af70c92ab | 705 | accelCount++; |
darienf | 20:6d2af70c92ab | 706 | } |
darienf | 20:6d2af70c92ab | 707 | |
darienf | 20:6d2af70c92ab | 708 | accelerometerLog.DisplayXYZ(time, new int[][] { x, y, z }); |
darienf | 20:6d2af70c92ab | 709 | } |
darienf | 20:6d2af70c92ab | 710 | } |
darienf | 20:6d2af70c92ab | 711 | } |