This is the latest working repository used in our demo video for the Maxim to display temperature readings on Bluetooth
hspguisourcev301/HspGuiSourceV301/HSPGui/Model/DataLogModel.cs@5:bc128a16232f, 2021-05-02 (annotated)
- 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?
User | Revision | Line number | New 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 RPCSupport; |
darienf | 3:36de8b9e4b1a | 42 | using RPCSupport.Streaming; |
darienf | 3:36de8b9e4b1a | 43 | using RPCSupport.DataLogging; |
darienf | 3:36de8b9e4b1a | 44 | |
darienf | 3:36de8b9e4b1a | 45 | namespace HealthSensorPlatform.Model |
darienf | 3:36de8b9e4b1a | 46 | { |
darienf | 3:36de8b9e4b1a | 47 | class DataLogModel : IDataLogModel |
darienf | 3:36de8b9e4b1a | 48 | { |
darienf | 3:36de8b9e4b1a | 49 | RPCClient rpcClient; |
darienf | 3:36de8b9e4b1a | 50 | StreamDataLog streamDataLog; |
darienf | 3:36de8b9e4b1a | 51 | EventHandler<PartialArrayIntAvailableEventArgs> onStreamDataHandler; |
darienf | 3:36de8b9e4b1a | 52 | |
darienf | 3:36de8b9e4b1a | 53 | Mission missionSettings; |
darienf | 3:36de8b9e4b1a | 54 | |
darienf | 3:36de8b9e4b1a | 55 | public DataLogModel(RPCClient rpcClient) |
darienf | 3:36de8b9e4b1a | 56 | { |
darienf | 3:36de8b9e4b1a | 57 | this.rpcClient = rpcClient; |
darienf | 3:36de8b9e4b1a | 58 | } |
darienf | 3:36de8b9e4b1a | 59 | |
darienf | 3:36de8b9e4b1a | 60 | public Mission MissionSettings |
darienf | 3:36de8b9e4b1a | 61 | { |
darienf | 3:36de8b9e4b1a | 62 | get |
darienf | 3:36de8b9e4b1a | 63 | { |
darienf | 3:36de8b9e4b1a | 64 | return missionSettings; |
darienf | 3:36de8b9e4b1a | 65 | } |
darienf | 3:36de8b9e4b1a | 66 | } |
darienf | 3:36de8b9e4b1a | 67 | |
darienf | 3:36de8b9e4b1a | 68 | public event EventHandler<EventArgs> LogStreamDone; |
darienf | 3:36de8b9e4b1a | 69 | public event EventHandler<PartialArrayIntAvailableEventArgs> LogData; |
darienf | 3:36de8b9e4b1a | 70 | |
darienf | 3:36de8b9e4b1a | 71 | public void Start() |
darienf | 3:36de8b9e4b1a | 72 | { |
darienf | 3:36de8b9e4b1a | 73 | onStreamDataHandler = new EventHandler<PartialArrayIntAvailableEventArgs>(OnStreamData); |
darienf | 3:36de8b9e4b1a | 74 | rpcClient.streaming.PartialArrayIntAvailable += onStreamDataHandler; |
darienf | 3:36de8b9e4b1a | 75 | streamDataLog = new StreamDataLog(rpcClient); |
darienf | 3:36de8b9e4b1a | 76 | |
darienf | 3:36de8b9e4b1a | 77 | streamDataLog.Start(); |
darienf | 3:36de8b9e4b1a | 78 | } |
darienf | 3:36de8b9e4b1a | 79 | |
darienf | 3:36de8b9e4b1a | 80 | public void EraseWrittenSectors() |
darienf | 3:36de8b9e4b1a | 81 | { |
darienf | 3:36de8b9e4b1a | 82 | ((SerialWrapPipeline)rpcClient.Pipeline).ReadTimeout = 180000; |
darienf | 3:36de8b9e4b1a | 83 | rpcClient.DataLogging.EraseWrittenSectors(); |
darienf | 3:36de8b9e4b1a | 84 | ((SerialWrapPipeline)rpcClient.Pipeline).ReadTimeout = 1000; |
darienf | 3:36de8b9e4b1a | 85 | } |
darienf | 3:36de8b9e4b1a | 86 | |
darienf | 3:36de8b9e4b1a | 87 | public void MissionStartDefinition() |
darienf | 3:36de8b9e4b1a | 88 | { |
darienf | 3:36de8b9e4b1a | 89 | rpcClient.DataLogging.MissionStartDefinition(); |
darienf | 3:36de8b9e4b1a | 90 | } |
darienf | 3:36de8b9e4b1a | 91 | |
darienf | 3:36de8b9e4b1a | 92 | public void MissionWrite() |
darienf | 3:36de8b9e4b1a | 93 | { |
darienf | 3:36de8b9e4b1a | 94 | rpcClient.DataLogging.MissionWrite(); |
darienf | 3:36de8b9e4b1a | 95 | } |
darienf | 3:36de8b9e4b1a | 96 | |
darienf | 3:36de8b9e4b1a | 97 | public void MissionErase() |
darienf | 3:36de8b9e4b1a | 98 | { |
darienf | 3:36de8b9e4b1a | 99 | rpcClient.DataLogging.EraseMission(); |
darienf | 3:36de8b9e4b1a | 100 | } |
darienf | 3:36de8b9e4b1a | 101 | |
darienf | 3:36de8b9e4b1a | 102 | public void MissionRead() |
darienf | 3:36de8b9e4b1a | 103 | { |
darienf | 3:36de8b9e4b1a | 104 | rpcClient.DataLogging.MissionRead(); |
darienf | 3:36de8b9e4b1a | 105 | |
darienf | 3:36de8b9e4b1a | 106 | missionSettings = new Mission(); |
darienf | 3:36de8b9e4b1a | 107 | // pre cmd |
darienf | 3:36de8b9e4b1a | 108 | missionSettings.PreCommand = rpcClient.DataLogging.PreCommand.cmdString; |
darienf | 3:36de8b9e4b1a | 109 | // ecg |
darienf | 3:36de8b9e4b1a | 110 | missionSettings.EnableEcg = rpcClient.DataLogging.MAX30001_Ecg.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 111 | if (missionSettings.EnableEcg) |
darienf | 3:36de8b9e4b1a | 112 | missionSettings.EcgArgs = rpcClient.DataLogging.MAX30001_Ecg.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 113 | // pace |
darienf | 3:36de8b9e4b1a | 114 | missionSettings.EnablePace = rpcClient.DataLogging.MAX30001_Pace.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 115 | if (missionSettings.EnablePace) |
darienf | 3:36de8b9e4b1a | 116 | missionSettings.PaceArgs = rpcClient.DataLogging.MAX30001_Pace.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 117 | // bioz |
darienf | 3:36de8b9e4b1a | 118 | missionSettings.EnableBioZ = rpcClient.DataLogging.MAX30001_Bioz.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 119 | if (missionSettings.EnableBioZ) |
darienf | 3:36de8b9e4b1a | 120 | missionSettings.BioZArgs = rpcClient.DataLogging.MAX30001_Bioz.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 121 | // RtoR |
darienf | 3:36de8b9e4b1a | 122 | missionSettings.EnableRToR = rpcClient.DataLogging.MAX30001_RtoR.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 123 | if (missionSettings.EnableRToR) |
darienf | 3:36de8b9e4b1a | 124 | missionSettings.RToRArgs = rpcClient.DataLogging.MAX30001_RtoR.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 125 | // Rbias, FMSTR |
darienf | 3:36de8b9e4b1a | 126 | //missionSettings.EnableRBias = rpcClient.DataLogging.MAX30001_Rbias.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 127 | missionSettings.EnableRBias = missionSettings.EnableRBias | missionSettings.EnableEcg | missionSettings.EnableBioZ | missionSettings.EnableRToR | missionSettings.EnablePace; |
darienf | 3:36de8b9e4b1a | 128 | if (missionSettings.EnableRBias) |
darienf | 3:36de8b9e4b1a | 129 | missionSettings.RBiasArgs = rpcClient.DataLogging.MAX30001_Rbias_Fmstr.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 130 | // SpO2 |
darienf | 3:36de8b9e4b1a | 131 | missionSettings.EnableOpticalSpO2 = rpcClient.DataLogging.MAX30101_SpO2.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 132 | if (missionSettings.EnableOpticalSpO2) |
darienf | 3:36de8b9e4b1a | 133 | missionSettings.SpO2HRModeArgs = rpcClient.DataLogging.MAX30101_SpO2.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 134 | // HR |
darienf | 3:36de8b9e4b1a | 135 | missionSettings.EnableOpticalHR = rpcClient.DataLogging.MAX30101_HR.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 136 | if (missionSettings.EnableOpticalHR) |
darienf | 3:36de8b9e4b1a | 137 | missionSettings.HRModeArgs = rpcClient.DataLogging.MAX30101_HR.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 138 | // Multi |
darienf | 3:36de8b9e4b1a | 139 | missionSettings.EnableOpticalMulti = rpcClient.DataLogging.MAX30101_Multi.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 140 | if (missionSettings.EnableOpticalMulti) |
darienf | 3:36de8b9e4b1a | 141 | missionSettings.MultiModeArgs = rpcClient.DataLogging.MAX30101_Multi.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 142 | |
darienf | 3:36de8b9e4b1a | 143 | // Temp1 |
darienf | 3:36de8b9e4b1a | 144 | missionSettings.EnableTemperature1 = rpcClient.DataLogging.MAX31725_1.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 145 | if (missionSettings.EnableTemperature1) |
darienf | 3:36de8b9e4b1a | 146 | missionSettings.Temperature1Parameters = rpcClient.DataLogging.MAX31725_1.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 147 | // Temp2 |
darienf | 3:36de8b9e4b1a | 148 | missionSettings.EnableTemperature2 = rpcClient.DataLogging.MAX31725_2.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 149 | if (missionSettings.EnableTemperature2) |
darienf | 3:36de8b9e4b1a | 150 | missionSettings.Temperature2Parameters = rpcClient.DataLogging.MAX31725_2.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 151 | // Accel |
darienf | 3:36de8b9e4b1a | 152 | missionSettings.EnableAccelerometer = rpcClient.DataLogging.LIS2DH.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 153 | if (missionSettings.EnableAccelerometer) |
darienf | 3:36de8b9e4b1a | 154 | missionSettings.AccelerometerParameters = rpcClient.DataLogging.LIS2DH.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 155 | // Pressure |
darienf | 3:36de8b9e4b1a | 156 | missionSettings.EnablePressure = rpcClient.DataLogging.BMP280.IsExistsInDeviceMission(); |
darienf | 3:36de8b9e4b1a | 157 | if (missionSettings.EnablePressure) |
darienf | 3:36de8b9e4b1a | 158 | missionSettings.PressureParameters = rpcClient.DataLogging.BMP280.ToIntArray(); |
darienf | 3:36de8b9e4b1a | 159 | |
darienf | 3:36de8b9e4b1a | 160 | |
darienf | 3:36de8b9e4b1a | 161 | // post cmd |
darienf | 3:36de8b9e4b1a | 162 | missionSettings.PostCommand = rpcClient.DataLogging.PostCommand.cmdString; |
darienf | 3:36de8b9e4b1a | 163 | |
darienf | 3:36de8b9e4b1a | 164 | } |
darienf | 3:36de8b9e4b1a | 165 | |
darienf | 3:36de8b9e4b1a | 166 | public string[] MissionString() |
darienf | 3:36de8b9e4b1a | 167 | { |
darienf | 3:36de8b9e4b1a | 168 | string[] missionStrings = rpcClient.DataLogging.MissionStrings(); |
darienf | 3:36de8b9e4b1a | 169 | |
darienf | 3:36de8b9e4b1a | 170 | List<string> stringList = new List<string>(missionStrings); |
darienf | 3:36de8b9e4b1a | 171 | |
darienf | 3:36de8b9e4b1a | 172 | if (stringList[0] == "null") |
darienf | 3:36de8b9e4b1a | 173 | stringList.RemoveAt(0); |
darienf | 3:36de8b9e4b1a | 174 | |
darienf | 3:36de8b9e4b1a | 175 | if (stringList.Count > 0 && stringList[stringList.Count - 1] == "null") |
darienf | 3:36de8b9e4b1a | 176 | { |
darienf | 3:36de8b9e4b1a | 177 | stringList.RemoveAt(stringList.Count - 1); |
darienf | 3:36de8b9e4b1a | 178 | } |
darienf | 3:36de8b9e4b1a | 179 | |
darienf | 3:36de8b9e4b1a | 180 | return stringList.ToArray(); |
darienf | 3:36de8b9e4b1a | 181 | } |
darienf | 3:36de8b9e4b1a | 182 | |
darienf | 3:36de8b9e4b1a | 183 | public void OnStreamData(object sender, PartialArrayIntAvailableEventArgs e) |
darienf | 3:36de8b9e4b1a | 184 | { |
darienf | 3:36de8b9e4b1a | 185 | if (e.reportID == PartialArrayIntAvailableEventArgs.PACKET_END_OF_STREAM) |
darienf | 3:36de8b9e4b1a | 186 | { |
darienf | 3:36de8b9e4b1a | 187 | if (LogStreamDone != null) |
darienf | 3:36de8b9e4b1a | 188 | LogStreamDone(this, e); |
darienf | 3:36de8b9e4b1a | 189 | |
darienf | 3:36de8b9e4b1a | 190 | rpcClient.streaming.PartialArrayIntAvailable -= onStreamDataHandler; |
darienf | 3:36de8b9e4b1a | 191 | |
darienf | 3:36de8b9e4b1a | 192 | } |
darienf | 3:36de8b9e4b1a | 193 | |
darienf | 3:36de8b9e4b1a | 194 | if (LogData != null) |
darienf | 3:36de8b9e4b1a | 195 | LogData(this, e); |
darienf | 3:36de8b9e4b1a | 196 | } |
darienf | 3:36de8b9e4b1a | 197 | } |
darienf | 3:36de8b9e4b1a | 198 | |
darienf | 3:36de8b9e4b1a | 199 | public class Mission |
darienf | 3:36de8b9e4b1a | 200 | { |
darienf | 3:36de8b9e4b1a | 201 | public string PreCommand; |
darienf | 3:36de8b9e4b1a | 202 | public bool EnableEcg; |
darienf | 3:36de8b9e4b1a | 203 | public int[] EcgArgs; |
darienf | 3:36de8b9e4b1a | 204 | |
darienf | 3:36de8b9e4b1a | 205 | public bool EnablePace; |
darienf | 3:36de8b9e4b1a | 206 | public int[] PaceArgs; |
darienf | 3:36de8b9e4b1a | 207 | |
darienf | 3:36de8b9e4b1a | 208 | public bool EnableBioZ; |
darienf | 3:36de8b9e4b1a | 209 | public int[] BioZArgs; |
darienf | 3:36de8b9e4b1a | 210 | |
darienf | 3:36de8b9e4b1a | 211 | public bool EnableRToR; |
darienf | 3:36de8b9e4b1a | 212 | public int[] RToRArgs; |
darienf | 3:36de8b9e4b1a | 213 | |
darienf | 3:36de8b9e4b1a | 214 | public bool EnableRBias; |
darienf | 3:36de8b9e4b1a | 215 | public int[] RBiasArgs; |
darienf | 3:36de8b9e4b1a | 216 | |
darienf | 3:36de8b9e4b1a | 217 | public bool EnableOpticalSpO2; |
darienf | 3:36de8b9e4b1a | 218 | public int[] SpO2HRModeArgs; |
darienf | 3:36de8b9e4b1a | 219 | |
darienf | 3:36de8b9e4b1a | 220 | public bool EnableOpticalHR; |
darienf | 3:36de8b9e4b1a | 221 | public int[] HRModeArgs; |
darienf | 3:36de8b9e4b1a | 222 | |
darienf | 3:36de8b9e4b1a | 223 | public bool EnableOpticalMulti; |
darienf | 3:36de8b9e4b1a | 224 | public int[] MultiModeArgs; |
darienf | 3:36de8b9e4b1a | 225 | |
darienf | 3:36de8b9e4b1a | 226 | public bool EnableTemperature1; |
darienf | 3:36de8b9e4b1a | 227 | public int[] Temperature1Parameters; |
darienf | 3:36de8b9e4b1a | 228 | |
darienf | 3:36de8b9e4b1a | 229 | public bool EnableTemperature2; |
darienf | 3:36de8b9e4b1a | 230 | public int[] Temperature2Parameters; |
darienf | 3:36de8b9e4b1a | 231 | |
darienf | 3:36de8b9e4b1a | 232 | public bool EnablePressure; |
darienf | 3:36de8b9e4b1a | 233 | public int[] PressureParameters; |
darienf | 3:36de8b9e4b1a | 234 | |
darienf | 3:36de8b9e4b1a | 235 | public bool EnableAccelerometer; |
darienf | 3:36de8b9e4b1a | 236 | public int[] AccelerometerParameters; |
darienf | 3:36de8b9e4b1a | 237 | |
darienf | 3:36de8b9e4b1a | 238 | public string PostCommand; |
darienf | 3:36de8b9e4b1a | 239 | |
darienf | 3:36de8b9e4b1a | 240 | public bool Enable |
darienf | 3:36de8b9e4b1a | 241 | { |
darienf | 3:36de8b9e4b1a | 242 | get |
darienf | 3:36de8b9e4b1a | 243 | { |
darienf | 3:36de8b9e4b1a | 244 | return EnableEcg | EnablePace | EnableBioZ | EnableRToR | EnableRBias |
darienf | 3:36de8b9e4b1a | 245 | | EnableOpticalSpO2 | EnableOpticalHR | EnableOpticalMulti |
darienf | 3:36de8b9e4b1a | 246 | | EnableTemperature1 | EnableTemperature2 | EnablePressure | EnableAccelerometer; |
darienf | 3:36de8b9e4b1a | 247 | } |
darienf | 3:36de8b9e4b1a | 248 | } |
darienf | 3:36de8b9e4b1a | 249 | } |
darienf | 3:36de8b9e4b1a | 250 | } |