heart modes, send, receive
Dependencies: Terminal TextLCD mbed-rtos mbed
Fork of Heartnew by
heart.cpp@7:46aeded22784, 2015-12-02 (annotated)
- Committer:
- sanjeet25
- Date:
- Wed Dec 02 05:39:01 2015 +0000
- Revision:
- 7:46aeded22784
- Parent:
- 6:cc4fcc38b9f0
heartwork
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sanjeet25 | 0:a307f0abfd4d | 1 | #include "mbed.h" |
sanjeet25 | 0:a307f0abfd4d | 2 | #include "rtos.h" |
sanjeet25 | 7:46aeded22784 | 3 | #include "Terminal.h" |
sanjeet25 | 0:a307f0abfd4d | 4 | |
sanjeet25 | 7:46aeded22784 | 5 | DigitalOut led1(LED1); //asense |
sanjeet25 | 7:46aeded22784 | 6 | DigitalOut led2(LED2); //vsense |
sanjeet25 | 7:46aeded22784 | 7 | DigitalOut led3(LED3); //apace |
sanjeet25 | 7:46aeded22784 | 8 | DigitalOut led4(LED4); //vpace |
sanjeet25 | 7:46aeded22784 | 9 | DigitalOut aSense(p23); |
sanjeet25 | 7:46aeded22784 | 10 | DigitalOut vSense(p24); |
sanjeet25 | 7:46aeded22784 | 11 | InterruptIn APace(p25); |
sanjeet25 | 7:46aeded22784 | 12 | InterruptIn VPace(p26); |
sanjeet25 | 0:a307f0abfd4d | 13 | |
sanjeet25 | 7:46aeded22784 | 14 | Terminal console(USBTX, USBRX); |
sanjeet25 | 2:fc2f41386ee4 | 15 | |
sanjeet25 | 7:46aeded22784 | 16 | int heartRate, avgHeartRate, observationInterval, rateCoefficient, observationRate, waitCount, senseWaitTime, testCase, changeModeTo; |
sanjeet25 | 7:46aeded22784 | 17 | int heartMode; //0 - Normal, 1 - Manual, 2 - Test |
sanjeet25 | 7:46aeded22784 | 18 | bool observationChange, digitOneReceived, paceReceived, synchDone, testOn, testResult[10]={false}, digitTwoReceived, changeMode, receivedVPace; |
sanjeet25 | 7:46aeded22784 | 19 | char ch; |
sanjeet25 | 7:46aeded22784 | 20 | char modeString[10]; |
sanjeet25 | 0:a307f0abfd4d | 21 | |
sanjeet25 | 7:46aeded22784 | 22 | const int nLRI=1500, nAVI = 60, nPVARP = 150, nURI = 600, nVRP = 100; //timing constraints for Normal Mode of the Pacemaker |
sanjeet25 | 7:46aeded22784 | 23 | const int delta=20; |
sanjeet25 | 7:46aeded22784 | 24 | |
sanjeet25 | 7:46aeded22784 | 25 | osMutexId displayMutex; |
sanjeet25 | 7:46aeded22784 | 26 | osMutexDef (displayMutex); |
sanjeet25 | 7:46aeded22784 | 27 | osMutexId observationChangeMutex; |
sanjeet25 | 7:46aeded22784 | 28 | osMutexDef(obserationChangeMutex); |
sanjeet25 | 7:46aeded22784 | 29 | osMutexId heartRateMutex; |
sanjeet25 | 7:46aeded22784 | 30 | osMutexDef (heartRateMuex); |
sanjeet25 | 0:a307f0abfd4d | 31 | |
sanjeet25 | 7:46aeded22784 | 32 | Thread *SerialThreadPTR; |
sanjeet25 | 7:46aeded22784 | 33 | Thread *HeartSensePTR; |
sanjeet25 | 7:46aeded22784 | 34 | Thread *TestModePTR; |
sanjeet25 | 7:46aeded22784 | 35 | Thread *TestDisplayPTR; |
sanjeet25 | 7:46aeded22784 | 36 | RtosTimer *KeyTimeOutTimer; |
sanjeet25 | 7:46aeded22784 | 37 | RtosTimer *SenseWaitTimer; |
sanjeet25 | 7:46aeded22784 | 38 | //testCode |
sanjeet25 | 7:46aeded22784 | 39 | Timer t; |
sanjeet25 | 0:a307f0abfd4d | 40 | |
sanjeet25 | 7:46aeded22784 | 41 | void resetDisplay() |
sanjeet25 | 7:46aeded22784 | 42 | { |
sanjeet25 | 7:46aeded22784 | 43 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 44 | console.cls(); |
sanjeet25 | 7:46aeded22784 | 45 | console.locate(30, 6); |
sanjeet25 | 7:46aeded22784 | 46 | console.printf("Heart Display"); |
sanjeet25 | 7:46aeded22784 | 47 | console.locate(30, 10); |
sanjeet25 | 7:46aeded22784 | 48 | console.printf("Heart Rate : %04d bpm", avgHeartRate); |
sanjeet25 | 7:46aeded22784 | 49 | console.locate(30, 12); |
sanjeet25 | 7:46aeded22784 | 50 | console.printf("Observation Interval : %02d seconds", observationInterval/1000); |
sanjeet25 | 7:46aeded22784 | 51 | console.locate(30, 14); |
sanjeet25 | 7:46aeded22784 | 52 | console.printf("Mode : %s", modeString); |
sanjeet25 | 7:46aeded22784 | 53 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 54 | } |
sanjeet25 | 4:a64a0fea5266 | 55 | |
sanjeet25 | 7:46aeded22784 | 56 | void updateDisplay() |
sanjeet25 | 7:46aeded22784 | 57 | { |
sanjeet25 | 7:46aeded22784 | 58 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 59 | console.locate(44, 10); |
sanjeet25 | 7:46aeded22784 | 60 | console.printf("%04d", avgHeartRate); |
sanjeet25 | 7:46aeded22784 | 61 | console.locate(54, 12); |
sanjeet25 | 7:46aeded22784 | 62 | console.printf("%02d", observationInterval/1000); |
sanjeet25 | 7:46aeded22784 | 63 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 64 | } |
sanjeet25 | 2:fc2f41386ee4 | 65 | |
sanjeet25 | 2:fc2f41386ee4 | 66 | |
sanjeet25 | 7:46aeded22784 | 67 | void heartSense(const void *args) |
sanjeet25 | 0:a307f0abfd4d | 68 | { |
sanjeet25 | 7:46aeded22784 | 69 | while(1) |
sanjeet25 | 7:46aeded22784 | 70 | { |
sanjeet25 | 7:46aeded22784 | 71 | if(heartMode>0) |
sanjeet25 | 7:46aeded22784 | 72 | { |
sanjeet25 | 7:46aeded22784 | 73 | Thread::signal_wait(0x02); |
sanjeet25 | 7:46aeded22784 | 74 | } |
sanjeet25 | 7:46aeded22784 | 75 | //Thread::wait(500); //chnage this |
sanjeet25 | 7:46aeded22784 | 76 | senseWaitTime=50+(rand()%2000); |
sanjeet25 | 7:46aeded22784 | 77 | SenseWaitTimer->start(senseWaitTime); |
sanjeet25 | 7:46aeded22784 | 78 | Thread::signal_wait(0x03); |
sanjeet25 | 7:46aeded22784 | 79 | if(rand()%2==0) |
sanjeet25 | 7:46aeded22784 | 80 | { |
sanjeet25 | 7:46aeded22784 | 81 | led1=1; |
sanjeet25 | 7:46aeded22784 | 82 | aSense=1; |
sanjeet25 | 7:46aeded22784 | 83 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 84 | aSense=0; |
sanjeet25 | 7:46aeded22784 | 85 | led1=0; |
sanjeet25 | 7:46aeded22784 | 86 | } |
sanjeet25 | 7:46aeded22784 | 87 | else |
sanjeet25 | 7:46aeded22784 | 88 | { |
sanjeet25 | 7:46aeded22784 | 89 | led2=1; |
sanjeet25 | 7:46aeded22784 | 90 | vSense=1; |
sanjeet25 | 7:46aeded22784 | 91 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 92 | vSense=0; |
sanjeet25 | 7:46aeded22784 | 93 | led2=0; |
sanjeet25 | 7:46aeded22784 | 94 | osMutexWait(heartRateMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 95 | heartRate++; |
sanjeet25 | 7:46aeded22784 | 96 | osMutexRelease(heartRateMutex); |
sanjeet25 | 7:46aeded22784 | 97 | |
sanjeet25 | 3:b702a21b2990 | 98 | } |
sanjeet25 | 3:b702a21b2990 | 99 | } |
sanjeet25 | 0:a307f0abfd4d | 100 | } |
sanjeet25 | 0:a307f0abfd4d | 101 | |
sanjeet25 | 7:46aeded22784 | 102 | void display(const void *args) |
sanjeet25 | 0:a307f0abfd4d | 103 | { |
sanjeet25 | 7:46aeded22784 | 104 | while(1) |
sanjeet25 | 7:46aeded22784 | 105 | { |
sanjeet25 | 7:46aeded22784 | 106 | Thread::wait(observationInterval); |
sanjeet25 | 7:46aeded22784 | 107 | if(heartMode!=2) |
sanjeet25 | 7:46aeded22784 | 108 | { |
sanjeet25 | 7:46aeded22784 | 109 | waitCount++; |
sanjeet25 | 7:46aeded22784 | 110 | if(!observationChange) |
sanjeet25 | 7:46aeded22784 | 111 | { |
sanjeet25 | 7:46aeded22784 | 112 | avgHeartRate=heartRate*rateCoefficient/waitCount; |
sanjeet25 | 7:46aeded22784 | 113 | osMutexWait(heartRateMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 114 | heartRate=0; |
sanjeet25 | 7:46aeded22784 | 115 | osMutexRelease(heartRateMutex); |
sanjeet25 | 7:46aeded22784 | 116 | if(observationRate!=(observationInterval/1000)) |
sanjeet25 | 7:46aeded22784 | 117 | { |
sanjeet25 | 7:46aeded22784 | 118 | resetDisplay(); |
sanjeet25 | 7:46aeded22784 | 119 | //update observationrate after the current interval stats are displayed |
sanjeet25 | 7:46aeded22784 | 120 | observationInterval=observationRate*1000; |
sanjeet25 | 7:46aeded22784 | 121 | rateCoefficient=(60000/observationInterval); |
sanjeet25 | 7:46aeded22784 | 122 | } |
sanjeet25 | 7:46aeded22784 | 123 | else |
sanjeet25 | 7:46aeded22784 | 124 | { |
sanjeet25 | 7:46aeded22784 | 125 | updateDisplay(); |
sanjeet25 | 7:46aeded22784 | 126 | } |
sanjeet25 | 7:46aeded22784 | 127 | waitCount=0; |
sanjeet25 | 7:46aeded22784 | 128 | } |
sanjeet25 | 0:a307f0abfd4d | 129 | } |
sanjeet25 | 0:a307f0abfd4d | 130 | } |
sanjeet25 | 0:a307f0abfd4d | 131 | } |
sanjeet25 | 0:a307f0abfd4d | 132 | |
sanjeet25 | 7:46aeded22784 | 133 | void senseWait(const void *args) |
sanjeet25 | 7:46aeded22784 | 134 | { |
sanjeet25 | 7:46aeded22784 | 135 | (*HeartSensePTR).signal_set(0x03); |
sanjeet25 | 7:46aeded22784 | 136 | } |
sanjeet25 | 7:46aeded22784 | 137 | |
sanjeet25 | 7:46aeded22784 | 138 | void keyTimeOut(const void *args) |
sanjeet25 | 0:a307f0abfd4d | 139 | { |
sanjeet25 | 7:46aeded22784 | 140 | if(digitOneReceived) |
sanjeet25 | 7:46aeded22784 | 141 | { |
sanjeet25 | 7:46aeded22784 | 142 | observationChange=false; |
sanjeet25 | 0:a307f0abfd4d | 143 | } |
sanjeet25 | 7:46aeded22784 | 144 | else |
sanjeet25 | 7:46aeded22784 | 145 | { |
sanjeet25 | 7:46aeded22784 | 146 | observationChange=false; |
sanjeet25 | 7:46aeded22784 | 147 | } |
sanjeet25 | 7:46aeded22784 | 148 | resetDisplay(); |
sanjeet25 | 0:a307f0abfd4d | 149 | } |
sanjeet25 | 7:46aeded22784 | 150 | |
sanjeet25 | 7:46aeded22784 | 151 | void testMode(const void *args) |
sanjeet25 | 0:a307f0abfd4d | 152 | { |
sanjeet25 | 7:46aeded22784 | 153 | while(1) |
sanjeet25 | 7:46aeded22784 | 154 | { |
sanjeet25 | 7:46aeded22784 | 155 | if(heartMode!=2) |
sanjeet25 | 7:46aeded22784 | 156 | { |
sanjeet25 | 7:46aeded22784 | 157 | Thread::signal_wait(0x04); |
sanjeet25 | 7:46aeded22784 | 158 | } |
sanjeet25 | 7:46aeded22784 | 159 | else |
sanjeet25 | 7:46aeded22784 | 160 | { |
sanjeet25 | 7:46aeded22784 | 161 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 162 | console.cls(); |
sanjeet25 | 7:46aeded22784 | 163 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 164 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 165 | //TestCase 1 - Asense at PVARP+; No Vpace within URI-PVARP (detected within URI-PVARP+delta) |
sanjeet25 | 7:46aeded22784 | 166 | testCase=0; |
sanjeet25 | 7:46aeded22784 | 167 | testResult[testCase]=true; |
sanjeet25 | 7:46aeded22784 | 168 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 169 | console.locate(20,testCase); |
sanjeet25 | 7:46aeded22784 | 170 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 171 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 172 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 173 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 174 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 175 | t.start(); |
sanjeet25 | 7:46aeded22784 | 176 | Thread::wait(nPVARP); |
sanjeet25 | 7:46aeded22784 | 177 | led1=1; |
sanjeet25 | 7:46aeded22784 | 178 | aSense=1; |
sanjeet25 | 7:46aeded22784 | 179 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 180 | aSense=0; |
sanjeet25 | 7:46aeded22784 | 181 | led1=0; |
sanjeet25 | 7:46aeded22784 | 182 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 183 | console.printf("AS : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 184 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 185 | testOn=true; |
sanjeet25 | 7:46aeded22784 | 186 | Thread::wait(nURI-nPVARP-delta); |
sanjeet25 | 7:46aeded22784 | 187 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 188 | if(testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 189 | { |
sanjeet25 | 7:46aeded22784 | 190 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 191 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 192 | console.printf("test %d pass",testCase+1); |
sanjeet25 | 7:46aeded22784 | 193 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 194 | } |
sanjeet25 | 7:46aeded22784 | 195 | else |
sanjeet25 | 7:46aeded22784 | 196 | { |
sanjeet25 | 7:46aeded22784 | 197 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 198 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 199 | console.printf("test %d fail",testCase+1); |
sanjeet25 | 7:46aeded22784 | 200 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 201 | } |
sanjeet25 | 6:cc4fcc38b9f0 | 202 | |
sanjeet25 | 7:46aeded22784 | 203 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 204 | //TestCase 2 - Asense at URI+; Vpace within AVI+delta |
sanjeet25 | 7:46aeded22784 | 205 | testCase=1; |
sanjeet25 | 7:46aeded22784 | 206 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 207 | console.locate(20,testCase); |
sanjeet25 | 7:46aeded22784 | 208 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 209 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 210 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 211 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 212 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 213 | Thread::wait(nURI); |
sanjeet25 | 7:46aeded22784 | 214 | led1=1; |
sanjeet25 | 7:46aeded22784 | 215 | aSense=1; |
sanjeet25 | 7:46aeded22784 | 216 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 217 | aSense=0; |
sanjeet25 | 7:46aeded22784 | 218 | led1=0; |
sanjeet25 | 7:46aeded22784 | 219 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 220 | console.printf("AS : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 221 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 222 | testOn=true; |
sanjeet25 | 7:46aeded22784 | 223 | Thread::wait(nAVI+delta); |
sanjeet25 | 7:46aeded22784 | 224 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 225 | if(testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 226 | { |
sanjeet25 | 7:46aeded22784 | 227 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 228 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 229 | console.printf("test %d pass",testCase+1); |
sanjeet25 | 7:46aeded22784 | 230 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 231 | } |
sanjeet25 | 7:46aeded22784 | 232 | else |
sanjeet25 | 7:46aeded22784 | 233 | { |
sanjeet25 | 7:46aeded22784 | 234 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 235 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 236 | console.printf("test %d fail",testCase+1); |
sanjeet25 | 7:46aeded22784 | 237 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 238 | } |
sanjeet25 | 7:46aeded22784 | 239 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 240 | //TestCase 3 - Asense at URI+; Vsense at AVI-; No pace detected; run this 4 times |
sanjeet25 | 7:46aeded22784 | 241 | testCase=2; |
sanjeet25 | 7:46aeded22784 | 242 | testResult[testCase]=true; |
sanjeet25 | 7:46aeded22784 | 243 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 244 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 245 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 246 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 247 | Thread::wait(nURI); |
sanjeet25 | 7:46aeded22784 | 248 | testOn=true; |
sanjeet25 | 7:46aeded22784 | 249 | for(int i=0;i<5;i++) |
sanjeet25 | 7:46aeded22784 | 250 | { |
sanjeet25 | 7:46aeded22784 | 251 | /*osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 252 | console.locate(20,testCase); |
sanjeet25 | 7:46aeded22784 | 253 | osMutexRelease(displayMutex);*/ |
sanjeet25 | 7:46aeded22784 | 254 | led1=1; |
sanjeet25 | 7:46aeded22784 | 255 | aSense=1; |
sanjeet25 | 7:46aeded22784 | 256 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 257 | aSense=0; |
sanjeet25 | 7:46aeded22784 | 258 | led1=0; |
sanjeet25 | 7:46aeded22784 | 259 | /*osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 260 | console.printf("AS : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 261 | osMutexRelease(displayMutex);*/ |
sanjeet25 | 7:46aeded22784 | 262 | Thread::wait(nAVI-delta); |
sanjeet25 | 7:46aeded22784 | 263 | led2=1; |
sanjeet25 | 7:46aeded22784 | 264 | vSense=1; |
sanjeet25 | 7:46aeded22784 | 265 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 266 | vSense=0; |
sanjeet25 | 7:46aeded22784 | 267 | led2=0; |
sanjeet25 | 7:46aeded22784 | 268 | /*osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 269 | console.printf("VS : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 270 | osMutexRelease(displayMutex);*/ |
sanjeet25 | 7:46aeded22784 | 271 | Thread::wait(nLRI-nAVI-delta); |
sanjeet25 | 7:46aeded22784 | 272 | } |
sanjeet25 | 7:46aeded22784 | 273 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 274 | if(testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 275 | { |
sanjeet25 | 7:46aeded22784 | 276 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 277 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 278 | console.printf("test %d pass",testCase+1); |
sanjeet25 | 7:46aeded22784 | 279 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 280 | } |
sanjeet25 | 7:46aeded22784 | 281 | else |
sanjeet25 | 7:46aeded22784 | 282 | { |
sanjeet25 | 7:46aeded22784 | 283 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 284 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 285 | console.printf("test %d fail",testCase+1); |
sanjeet25 | 7:46aeded22784 | 286 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 287 | } |
sanjeet25 | 7:46aeded22784 | 288 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 289 | //TestCase 4 - No sensing;Only pacing; |
sanjeet25 | 7:46aeded22784 | 290 | testCase=3; |
sanjeet25 | 7:46aeded22784 | 291 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 292 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 293 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 294 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 295 | testOn=true; |
sanjeet25 | 7:46aeded22784 | 296 | for(int i=0;i<1;i++) |
sanjeet25 | 7:46aeded22784 | 297 | { |
sanjeet25 | 7:46aeded22784 | 298 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 299 | console.locate(20,testCase); |
sanjeet25 | 7:46aeded22784 | 300 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 301 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 302 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 303 | Thread::wait(nLRI-nAVI+delta); |
sanjeet25 | 7:46aeded22784 | 304 | if(!testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 305 | { |
sanjeet25 | 7:46aeded22784 | 306 | console.printf("Here"); |
sanjeet25 | 7:46aeded22784 | 307 | break; |
sanjeet25 | 7:46aeded22784 | 308 | } |
sanjeet25 | 7:46aeded22784 | 309 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 310 | Thread::wait(nAVI); |
sanjeet25 | 7:46aeded22784 | 311 | if(!testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 312 | { |
sanjeet25 | 7:46aeded22784 | 313 | console.printf("There"); |
sanjeet25 | 7:46aeded22784 | 314 | break; |
sanjeet25 | 7:46aeded22784 | 315 | } |
sanjeet25 | 7:46aeded22784 | 316 | } |
sanjeet25 | 7:46aeded22784 | 317 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 318 | if(testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 319 | { |
sanjeet25 | 7:46aeded22784 | 320 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 321 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 322 | console.printf("test %d pass",testCase+1); |
sanjeet25 | 7:46aeded22784 | 323 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 324 | } |
sanjeet25 | 7:46aeded22784 | 325 | else |
sanjeet25 | 7:46aeded22784 | 326 | { |
sanjeet25 | 7:46aeded22784 | 327 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 328 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 329 | console.printf("test %d fail",testCase+1); |
sanjeet25 | 7:46aeded22784 | 330 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 331 | } |
sanjeet25 | 7:46aeded22784 | 332 | |
sanjeet25 | 7:46aeded22784 | 333 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 334 | //TestCase 5 - Vsense at VRP+; APace at LRI-AVI+delta |
sanjeet25 | 7:46aeded22784 | 335 | testCase=4; |
sanjeet25 | 7:46aeded22784 | 336 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 337 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 338 | console.locate(20,testCase); |
sanjeet25 | 7:46aeded22784 | 339 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 340 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 341 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 342 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 343 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 344 | Thread::wait(nPVARP); |
sanjeet25 | 7:46aeded22784 | 345 | led2=1; |
sanjeet25 | 7:46aeded22784 | 346 | vSense=1; |
sanjeet25 | 7:46aeded22784 | 347 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 348 | vSense=0; |
sanjeet25 | 7:46aeded22784 | 349 | led2=0; |
sanjeet25 | 7:46aeded22784 | 350 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 351 | console.printf("VS : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 352 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 353 | testOn=true; |
sanjeet25 | 7:46aeded22784 | 354 | Thread::wait(nLRI-nAVI+delta); |
sanjeet25 | 7:46aeded22784 | 355 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 356 | if(testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 357 | { |
sanjeet25 | 7:46aeded22784 | 358 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 359 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 360 | console.printf("test %d pass",testCase+1); |
sanjeet25 | 7:46aeded22784 | 361 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 362 | } |
sanjeet25 | 7:46aeded22784 | 363 | else |
sanjeet25 | 7:46aeded22784 | 364 | { |
sanjeet25 | 7:46aeded22784 | 365 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 366 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 367 | console.printf("test %d fail",testCase+1); |
sanjeet25 | 7:46aeded22784 | 368 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 369 | } |
sanjeet25 | 6:cc4fcc38b9f0 | 370 | |
sanjeet25 | 7:46aeded22784 | 371 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 372 | //TestCase 6 - Asense at VRP+ (within PVARP); A pace should come at LRI-AVI+delta and no VPace should come |
sanjeet25 | 7:46aeded22784 | 373 | testCase=5; |
sanjeet25 | 7:46aeded22784 | 374 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 375 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 376 | console.locate(20,testCase); |
sanjeet25 | 7:46aeded22784 | 377 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 378 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 379 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 380 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 381 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 382 | Thread::wait(nVRP); |
sanjeet25 | 7:46aeded22784 | 383 | led1=1; |
sanjeet25 | 7:46aeded22784 | 384 | aSense=1; |
sanjeet25 | 7:46aeded22784 | 385 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 386 | aSense=0; |
sanjeet25 | 7:46aeded22784 | 387 | led1=0; |
sanjeet25 | 7:46aeded22784 | 388 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 389 | console.printf("AS : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 390 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 391 | testOn=true; |
sanjeet25 | 7:46aeded22784 | 392 | Thread::wait(nLRI-nAVI-nVRP+delta); |
sanjeet25 | 7:46aeded22784 | 393 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 394 | if(testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 395 | { |
sanjeet25 | 7:46aeded22784 | 396 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 397 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 398 | console.printf("test %d pass",testCase+1); |
sanjeet25 | 7:46aeded22784 | 399 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 400 | } |
sanjeet25 | 7:46aeded22784 | 401 | else |
sanjeet25 | 7:46aeded22784 | 402 | { |
sanjeet25 | 7:46aeded22784 | 403 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 404 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 405 | console.printf("test %d fail",testCase+1); |
sanjeet25 | 7:46aeded22784 | 406 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 407 | } |
sanjeet25 | 7:46aeded22784 | 408 | |
sanjeet25 | 7:46aeded22784 | 409 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 410 | //TestCase 7 - Vsense at VRP-; Asense should come at LRI-AVI+delta; Asense does not come after that, which would happen if Vsense was accepted |
sanjeet25 | 7:46aeded22784 | 411 | testCase=6; |
sanjeet25 | 7:46aeded22784 | 412 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 413 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 414 | console.locate(20,testCase); |
sanjeet25 | 7:46aeded22784 | 415 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 416 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 417 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 418 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 419 | t.reset(); |
sanjeet25 | 7:46aeded22784 | 420 | Thread::wait(nVRP-delta-10); //give vSense within VRP |
sanjeet25 | 7:46aeded22784 | 421 | led2=1; |
sanjeet25 | 7:46aeded22784 | 422 | vSense=1; |
sanjeet25 | 7:46aeded22784 | 423 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 424 | vSense=0; |
sanjeet25 | 7:46aeded22784 | 425 | led2=0; |
sanjeet25 | 7:46aeded22784 | 426 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 427 | console.printf("VS : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 428 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 429 | testOn=true; |
sanjeet25 | 7:46aeded22784 | 430 | Thread::wait(nLRI-nAVI-nVRP+(2*delta)+10); |
sanjeet25 | 7:46aeded22784 | 431 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 432 | if(testResult[testCase]) |
sanjeet25 | 7:46aeded22784 | 433 | { |
sanjeet25 | 7:46aeded22784 | 434 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 435 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 436 | console.printf("test %d pass",testCase+1); |
sanjeet25 | 7:46aeded22784 | 437 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 438 | } |
sanjeet25 | 7:46aeded22784 | 439 | else |
sanjeet25 | 7:46aeded22784 | 440 | { |
sanjeet25 | 7:46aeded22784 | 441 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 442 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 443 | console.printf("test %d fail",testCase+1); |
sanjeet25 | 7:46aeded22784 | 444 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 445 | } |
sanjeet25 | 7:46aeded22784 | 446 | t.stop(); |
sanjeet25 | 7:46aeded22784 | 447 | //synch with PM |
sanjeet25 | 7:46aeded22784 | 448 | //TestCase 8 - Alarm High case; generate Asense and Vsense at very high rate |
sanjeet25 | 7:46aeded22784 | 449 | testCase=7; |
sanjeet25 | 7:46aeded22784 | 450 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 451 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 452 | console.locate(0,testCase); |
sanjeet25 | 7:46aeded22784 | 453 | console.printf("Alarm High"); |
sanjeet25 | 7:46aeded22784 | 454 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 455 | synchDone=false; |
sanjeet25 | 7:46aeded22784 | 456 | Thread::signal_wait(0x05); |
sanjeet25 | 7:46aeded22784 | 457 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 458 | for(int i=0;i<5000;i++) |
sanjeet25 | 7:46aeded22784 | 459 | { |
sanjeet25 | 7:46aeded22784 | 460 | led1=1; |
sanjeet25 | 7:46aeded22784 | 461 | aSense=1; |
sanjeet25 | 7:46aeded22784 | 462 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 463 | aSense=0; |
sanjeet25 | 7:46aeded22784 | 464 | led1=0; |
sanjeet25 | 7:46aeded22784 | 465 | led2=1; |
sanjeet25 | 7:46aeded22784 | 466 | vSense=1; |
sanjeet25 | 7:46aeded22784 | 467 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 468 | vSense=0; |
sanjeet25 | 7:46aeded22784 | 469 | led2=0; |
sanjeet25 | 7:46aeded22784 | 470 | } |
sanjeet25 | 7:46aeded22784 | 471 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 472 | console.locate(0,testCase+1); |
sanjeet25 | 7:46aeded22784 | 473 | console.printf("Testing Complete"); |
sanjeet25 | 7:46aeded22784 | 474 | osMutexRelease(displayMutex); |
sanjeet25 | 6:cc4fcc38b9f0 | 475 | |
sanjeet25 | 0:a307f0abfd4d | 476 | } |
sanjeet25 | 7:46aeded22784 | 477 | if(changeMode) |
sanjeet25 | 7:46aeded22784 | 478 | { |
sanjeet25 | 7:46aeded22784 | 479 | changeMode=false; |
sanjeet25 | 7:46aeded22784 | 480 | if(changeModeTo==0) |
sanjeet25 | 7:46aeded22784 | 481 | { |
sanjeet25 | 7:46aeded22784 | 482 | heartMode=0; |
sanjeet25 | 7:46aeded22784 | 483 | strcpy(modeString,"Random"); |
sanjeet25 | 7:46aeded22784 | 484 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 485 | console.cls(); |
sanjeet25 | 7:46aeded22784 | 486 | console.locate(30, 10); |
sanjeet25 | 7:46aeded22784 | 487 | console.printf("Heart Rate : %03d bpm", avgHeartRate); |
sanjeet25 | 7:46aeded22784 | 488 | console.locate(30, 12); |
sanjeet25 | 7:46aeded22784 | 489 | console.printf("Observation Interval : %02d seconds", observationInterval/1000); |
sanjeet25 | 7:46aeded22784 | 490 | console.locate(30, 14); |
sanjeet25 | 7:46aeded22784 | 491 | console.printf("Mode : %s", modeString); |
sanjeet25 | 7:46aeded22784 | 492 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 493 | (*HeartSensePTR).signal_set(0x02); |
sanjeet25 | 3:b702a21b2990 | 494 | } |
sanjeet25 | 7:46aeded22784 | 495 | else |
sanjeet25 | 7:46aeded22784 | 496 | { |
sanjeet25 | 7:46aeded22784 | 497 | heartMode=1; |
sanjeet25 | 7:46aeded22784 | 498 | strcpy(modeString,"Manual"); |
sanjeet25 | 7:46aeded22784 | 499 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 500 | console.cls(); |
sanjeet25 | 7:46aeded22784 | 501 | console.locate(30, 10); |
sanjeet25 | 7:46aeded22784 | 502 | console.printf("Heart Rate : %03d bpm", avgHeartRate); |
sanjeet25 | 7:46aeded22784 | 503 | console.locate(30, 12); |
sanjeet25 | 7:46aeded22784 | 504 | console.printf("Observation Interval : %02d seconds", observationInterval/1000); |
sanjeet25 | 7:46aeded22784 | 505 | console.locate(30, 14); |
sanjeet25 | 7:46aeded22784 | 506 | console.printf("Mode : %s", modeString); |
sanjeet25 | 7:46aeded22784 | 507 | osMutexRelease(displayMutex); |
sanjeet25 | 3:b702a21b2990 | 508 | } |
sanjeet25 | 7:46aeded22784 | 509 | |
sanjeet25 | 3:b702a21b2990 | 510 | } |
sanjeet25 | 3:b702a21b2990 | 511 | } |
sanjeet25 | 3:b702a21b2990 | 512 | } |
sanjeet25 | 3:b702a21b2990 | 513 | |
sanjeet25 | 7:46aeded22784 | 514 | void aPace() |
sanjeet25 | 4:a64a0fea5266 | 515 | { |
sanjeet25 | 7:46aeded22784 | 516 | if(heartMode==0) |
sanjeet25 | 7:46aeded22784 | 517 | { |
sanjeet25 | 7:46aeded22784 | 518 | SenseWaitTimer->start(50+(rand()%2000)); //TODO move this |
sanjeet25 | 7:46aeded22784 | 519 | } |
sanjeet25 | 7:46aeded22784 | 520 | led3=1; |
sanjeet25 | 7:46aeded22784 | 521 | wait(0.01); |
sanjeet25 | 7:46aeded22784 | 522 | led3=0; |
sanjeet25 | 7:46aeded22784 | 523 | if(heartMode==2 && testOn) |
sanjeet25 | 7:46aeded22784 | 524 | { |
sanjeet25 | 7:46aeded22784 | 525 | receivedVPace=false; |
sanjeet25 | 7:46aeded22784 | 526 | (*TestDisplayPTR).signal_set(0x06); |
sanjeet25 | 7:46aeded22784 | 527 | if(testCase==2) |
sanjeet25 | 7:46aeded22784 | 528 | { |
sanjeet25 | 7:46aeded22784 | 529 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 530 | } |
sanjeet25 | 7:46aeded22784 | 531 | else if(testCase==3 || testCase==4 || testCase==5 || testCase==6) |
sanjeet25 | 7:46aeded22784 | 532 | { |
sanjeet25 | 7:46aeded22784 | 533 | testResult[testCase]=true; |
sanjeet25 | 7:46aeded22784 | 534 | } |
sanjeet25 | 7:46aeded22784 | 535 | } |
sanjeet25 | 7:46aeded22784 | 536 | } |
sanjeet25 | 5:8e3b9032ddfc | 537 | |
sanjeet25 | 7:46aeded22784 | 538 | void vPace() |
sanjeet25 | 7:46aeded22784 | 539 | { |
sanjeet25 | 7:46aeded22784 | 540 | if(heartMode==0) |
sanjeet25 | 7:46aeded22784 | 541 | { |
sanjeet25 | 7:46aeded22784 | 542 | SenseWaitTimer->start(50+(rand()%2000)); //TODO move this |
sanjeet25 | 7:46aeded22784 | 543 | } |
sanjeet25 | 7:46aeded22784 | 544 | led4=1; |
sanjeet25 | 7:46aeded22784 | 545 | wait(0.01); |
sanjeet25 | 7:46aeded22784 | 546 | led4=0; |
sanjeet25 | 7:46aeded22784 | 547 | osMutexWait(heartRateMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 548 | heartRate++; |
sanjeet25 | 7:46aeded22784 | 549 | osMutexRelease(heartRateMutex); |
sanjeet25 | 7:46aeded22784 | 550 | if(heartMode==2 && !synchDone) |
sanjeet25 | 7:46aeded22784 | 551 | { |
sanjeet25 | 7:46aeded22784 | 552 | (*TestModePTR).signal_set(0x05); |
sanjeet25 | 7:46aeded22784 | 553 | } |
sanjeet25 | 7:46aeded22784 | 554 | if(heartMode==2 && testOn) |
sanjeet25 | 7:46aeded22784 | 555 | { |
sanjeet25 | 7:46aeded22784 | 556 | receivedVPace=true; |
sanjeet25 | 7:46aeded22784 | 557 | (*TestDisplayPTR).signal_set(0x06); |
sanjeet25 | 7:46aeded22784 | 558 | if(testCase==0 || testCase==2 || testCase==5 || testCase==6) |
sanjeet25 | 7:46aeded22784 | 559 | { |
sanjeet25 | 7:46aeded22784 | 560 | testResult[testCase]=false; |
sanjeet25 | 7:46aeded22784 | 561 | } |
sanjeet25 | 7:46aeded22784 | 562 | else if(testCase==1 || testCase==3) |
sanjeet25 | 7:46aeded22784 | 563 | { |
sanjeet25 | 7:46aeded22784 | 564 | testResult[testCase]=true; |
sanjeet25 | 7:46aeded22784 | 565 | } |
sanjeet25 | 3:b702a21b2990 | 566 | } |
sanjeet25 | 4:a64a0fea5266 | 567 | } |
sanjeet25 | 4:a64a0fea5266 | 568 | |
sanjeet25 | 7:46aeded22784 | 569 | void testDisplay(const void *args) |
sanjeet25 | 7:46aeded22784 | 570 | { |
sanjeet25 | 7:46aeded22784 | 571 | while(1) |
sanjeet25 | 7:46aeded22784 | 572 | { |
sanjeet25 | 7:46aeded22784 | 573 | Thread::signal_wait(0x06); |
sanjeet25 | 7:46aeded22784 | 574 | if(receivedVPace) |
sanjeet25 | 7:46aeded22784 | 575 | { |
sanjeet25 | 7:46aeded22784 | 576 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 577 | console.printf("VP : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 578 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 579 | } |
sanjeet25 | 7:46aeded22784 | 580 | else |
sanjeet25 | 7:46aeded22784 | 581 | { |
sanjeet25 | 7:46aeded22784 | 582 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 583 | console.printf("AP : %d ",t.read_ms()); |
sanjeet25 | 7:46aeded22784 | 584 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 585 | } |
sanjeet25 | 7:46aeded22784 | 586 | } |
sanjeet25 | 7:46aeded22784 | 587 | } |
sanjeet25 | 7:46aeded22784 | 588 | |
sanjeet25 | 7:46aeded22784 | 589 | |
sanjeet25 | 7:46aeded22784 | 590 | void serialThread(const void *args) |
sanjeet25 | 7:46aeded22784 | 591 | { |
sanjeet25 | 7:46aeded22784 | 592 | while(1) |
sanjeet25 | 7:46aeded22784 | 593 | { |
sanjeet25 | 7:46aeded22784 | 594 | Thread::signal_wait(0x01); |
sanjeet25 | 7:46aeded22784 | 595 | if((((ch=='a')||(ch=='A')) && heartMode==1) && !observationChange) |
sanjeet25 | 7:46aeded22784 | 596 | { |
sanjeet25 | 7:46aeded22784 | 597 | //fire A Signal |
sanjeet25 | 7:46aeded22784 | 598 | led1=1; |
sanjeet25 | 7:46aeded22784 | 599 | aSense=1; |
sanjeet25 | 7:46aeded22784 | 600 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 601 | led1=0; |
sanjeet25 | 7:46aeded22784 | 602 | aSense=0; |
sanjeet25 | 7:46aeded22784 | 603 | } |
sanjeet25 | 7:46aeded22784 | 604 | else if((((ch=='v')||(ch=='V')) && heartMode==1) && !observationChange) |
sanjeet25 | 7:46aeded22784 | 605 | { |
sanjeet25 | 7:46aeded22784 | 606 | //fire V Signal |
sanjeet25 | 7:46aeded22784 | 607 | led2=1; |
sanjeet25 | 7:46aeded22784 | 608 | vSense=1; |
sanjeet25 | 7:46aeded22784 | 609 | Thread::wait(1); |
sanjeet25 | 7:46aeded22784 | 610 | vSense=0; |
sanjeet25 | 7:46aeded22784 | 611 | led2=0; |
sanjeet25 | 7:46aeded22784 | 612 | osMutexWait(heartRateMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 613 | heartRate++; |
sanjeet25 | 7:46aeded22784 | 614 | osMutexRelease(heartRateMutex); |
sanjeet25 | 7:46aeded22784 | 615 | } |
sanjeet25 | 7:46aeded22784 | 616 | else if(((((ch=='r')||(ch=='R'))&& heartMode!=0) && !observationChange) && !changeMode) |
sanjeet25 | 7:46aeded22784 | 617 | { |
sanjeet25 | 7:46aeded22784 | 618 | if(heartMode==2) |
sanjeet25 | 7:46aeded22784 | 619 | { |
sanjeet25 | 7:46aeded22784 | 620 | changeMode=true; |
sanjeet25 | 7:46aeded22784 | 621 | changeModeTo=0; |
sanjeet25 | 7:46aeded22784 | 622 | console.locate(30, 14); |
sanjeet25 | 7:46aeded22784 | 623 | console.printf("Mode : %s (Pending - Random)", modeString); |
sanjeet25 | 7:46aeded22784 | 624 | } |
sanjeet25 | 7:46aeded22784 | 625 | else |
sanjeet25 | 7:46aeded22784 | 626 | { |
sanjeet25 | 7:46aeded22784 | 627 | heartMode=0; |
sanjeet25 | 7:46aeded22784 | 628 | strcpy(modeString,"Random"); |
sanjeet25 | 7:46aeded22784 | 629 | resetDisplay(); |
sanjeet25 | 7:46aeded22784 | 630 | (*HeartSensePTR).signal_set(0x02); |
sanjeet25 | 7:46aeded22784 | 631 | } |
sanjeet25 | 7:46aeded22784 | 632 | } |
sanjeet25 | 7:46aeded22784 | 633 | else if(((((ch=='m')||(ch=='M')) && heartMode!=1) && !observationChange) && !changeMode) |
sanjeet25 | 7:46aeded22784 | 634 | { |
sanjeet25 | 7:46aeded22784 | 635 | if(heartMode==2) |
sanjeet25 | 7:46aeded22784 | 636 | { |
sanjeet25 | 7:46aeded22784 | 637 | changeMode=true; |
sanjeet25 | 7:46aeded22784 | 638 | changeModeTo=1; |
sanjeet25 | 7:46aeded22784 | 639 | console.locate(30, 14); |
sanjeet25 | 7:46aeded22784 | 640 | console.printf("Mode : %s (Pending - Manual)", modeString); |
sanjeet25 | 7:46aeded22784 | 641 | } |
sanjeet25 | 7:46aeded22784 | 642 | else |
sanjeet25 | 7:46aeded22784 | 643 | { |
sanjeet25 | 7:46aeded22784 | 644 | heartMode=1; |
sanjeet25 | 7:46aeded22784 | 645 | strcpy(modeString,"Manual"); |
sanjeet25 | 7:46aeded22784 | 646 | resetDisplay(); |
sanjeet25 | 7:46aeded22784 | 647 | } |
sanjeet25 | 7:46aeded22784 | 648 | } |
sanjeet25 | 7:46aeded22784 | 649 | else if((((ch=='t')||(ch=='T')) && heartMode!=2) && !observationChange) |
sanjeet25 | 7:46aeded22784 | 650 | { |
sanjeet25 | 7:46aeded22784 | 651 | heartMode=2; //spawn Test Thread |
sanjeet25 | 7:46aeded22784 | 652 | strcpy(modeString,"Test"); |
sanjeet25 | 7:46aeded22784 | 653 | resetDisplay(); |
sanjeet25 | 7:46aeded22784 | 654 | (*TestModePTR).signal_set(0x04); |
sanjeet25 | 7:46aeded22784 | 655 | } |
sanjeet25 | 7:46aeded22784 | 656 | else if((((ch=='o')||(ch=='O')) && !observationChange) && heartMode!=2) |
sanjeet25 | 7:46aeded22784 | 657 | { |
sanjeet25 | 7:46aeded22784 | 658 | observationChange=true; |
sanjeet25 | 7:46aeded22784 | 659 | digitOneReceived=false; |
sanjeet25 | 7:46aeded22784 | 660 | digitTwoReceived=false; |
sanjeet25 | 7:46aeded22784 | 661 | //spawn a timer for 3 seconds |
sanjeet25 | 7:46aeded22784 | 662 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 663 | console.locate(29, 16); |
sanjeet25 | 7:46aeded22784 | 664 | console.printf("Observation Interval change : -- seconds"); |
sanjeet25 | 7:46aeded22784 | 665 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 666 | KeyTimeOutTimer=new RtosTimer(keyTimeOut, osTimerOnce, (void *)0); |
sanjeet25 | 7:46aeded22784 | 667 | KeyTimeOutTimer->start(3000); |
sanjeet25 | 7:46aeded22784 | 668 | } |
sanjeet25 | 7:46aeded22784 | 669 | else if((observationChange) && ((ch>=48) && (ch<=57)) && !digitTwoReceived) |
sanjeet25 | 7:46aeded22784 | 670 | { |
sanjeet25 | 7:46aeded22784 | 671 | if(!digitOneReceived) |
sanjeet25 | 7:46aeded22784 | 672 | { |
sanjeet25 | 7:46aeded22784 | 673 | KeyTimeOutTimer->start(3000); //key time out is 3 seconds |
sanjeet25 | 7:46aeded22784 | 674 | osMutexWait(observationChangeMutex, osWaitForever); //mutex to be released either on time out or if 2 digits are received |
sanjeet25 | 7:46aeded22784 | 675 | observationRate=ch-'0'; |
sanjeet25 | 7:46aeded22784 | 676 | osMutexRelease(observationChangeMutex); |
sanjeet25 | 7:46aeded22784 | 677 | digitOneReceived=true; |
sanjeet25 | 7:46aeded22784 | 678 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 679 | console.locate(60, 16); |
sanjeet25 | 7:46aeded22784 | 680 | console.printf("%02d", observationRate); |
sanjeet25 | 7:46aeded22784 | 681 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 682 | } |
sanjeet25 | 7:46aeded22784 | 683 | else |
sanjeet25 | 7:46aeded22784 | 684 | { |
sanjeet25 | 7:46aeded22784 | 685 | KeyTimeOutTimer->stop(); |
sanjeet25 | 7:46aeded22784 | 686 | digitTwoReceived=true; |
sanjeet25 | 7:46aeded22784 | 687 | osMutexWait(observationChangeMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 688 | observationRate=(observationRate*10)+(ch-'0'); |
sanjeet25 | 7:46aeded22784 | 689 | osMutexRelease(observationChangeMutex); |
sanjeet25 | 7:46aeded22784 | 690 | observationChange=false; |
sanjeet25 | 7:46aeded22784 | 691 | osMutexWait(displayMutex, osWaitForever); |
sanjeet25 | 7:46aeded22784 | 692 | console.locate(60, 16); |
sanjeet25 | 7:46aeded22784 | 693 | console.printf("%02d", observationRate); |
sanjeet25 | 7:46aeded22784 | 694 | osMutexRelease(displayMutex); |
sanjeet25 | 7:46aeded22784 | 695 | } |
sanjeet25 | 7:46aeded22784 | 696 | } |
sanjeet25 | 7:46aeded22784 | 697 | } |
sanjeet25 | 7:46aeded22784 | 698 | } |
sanjeet25 | 7:46aeded22784 | 699 | |
sanjeet25 | 7:46aeded22784 | 700 | // Interupt Routine to read in data from serial port and call the serial thread |
sanjeet25 | 7:46aeded22784 | 701 | void Rx_interrupt() |
sanjeet25 | 7:46aeded22784 | 702 | { |
sanjeet25 | 7:46aeded22784 | 703 | if(console.readable()) |
sanjeet25 | 7:46aeded22784 | 704 | { |
sanjeet25 | 7:46aeded22784 | 705 | ch=LPC_UART0->RBR; //read uart buffer data and clear the interrupt flag |
sanjeet25 | 7:46aeded22784 | 706 | (*SerialThreadPTR).signal_set(0x01); //initiate the serial thread to change the state of the timer |
sanjeet25 | 7:46aeded22784 | 707 | } |
sanjeet25 | 7:46aeded22784 | 708 | |
sanjeet25 | 7:46aeded22784 | 709 | } |
sanjeet25 | 3:b702a21b2990 | 710 | |
sanjeet25 | 3:b702a21b2990 | 711 | |
sanjeet25 | 7:46aeded22784 | 712 | int main() |
sanjeet25 | 6:cc4fcc38b9f0 | 713 | { |
sanjeet25 | 7:46aeded22784 | 714 | console.attach(&Rx_interrupt, Serial::RxIrq); //attach a uart interrupt for uart |
sanjeet25 | 7:46aeded22784 | 715 | console.cls(); |
sanjeet25 | 7:46aeded22784 | 716 | console.locate(30, 6); |
sanjeet25 | 7:46aeded22784 | 717 | console.printf("Heart Display"); |
sanjeet25 | 7:46aeded22784 | 718 | console.locate(30, 10); |
sanjeet25 | 7:46aeded22784 | 719 | console.printf("Heart Rate : ---- bpm"); |
sanjeet25 | 7:46aeded22784 | 720 | console.locate(30, 12); |
sanjeet25 | 7:46aeded22784 | 721 | console.printf("Observation Interval : -- seconds"); |
sanjeet25 | 7:46aeded22784 | 722 | console.locate(30, 14); |
sanjeet25 | 7:46aeded22784 | 723 | console.printf("Mode : Random "); |
sanjeet25 | 7:46aeded22784 | 724 | |
sanjeet25 | 7:46aeded22784 | 725 | //initialize variables |
sanjeet25 | 7:46aeded22784 | 726 | heartMode=0; |
sanjeet25 | 7:46aeded22784 | 727 | heartRate=0; |
sanjeet25 | 7:46aeded22784 | 728 | avgHeartRate=0; |
sanjeet25 | 7:46aeded22784 | 729 | waitCount=0; |
sanjeet25 | 7:46aeded22784 | 730 | observationInterval=5000; |
sanjeet25 | 7:46aeded22784 | 731 | rateCoefficient=(60000/observationInterval); |
sanjeet25 | 7:46aeded22784 | 732 | observationChange=false; |
sanjeet25 | 7:46aeded22784 | 733 | observationRate=5; |
sanjeet25 | 7:46aeded22784 | 734 | digitOneReceived=false; |
sanjeet25 | 7:46aeded22784 | 735 | strcpy(modeString,"Random"); |
sanjeet25 | 7:46aeded22784 | 736 | synchDone=true; |
sanjeet25 | 7:46aeded22784 | 737 | testCase=0; |
sanjeet25 | 7:46aeded22784 | 738 | testOn=false; |
sanjeet25 | 7:46aeded22784 | 739 | digitTwoReceived=false; |
sanjeet25 | 7:46aeded22784 | 740 | changeMode=false; |
sanjeet25 | 7:46aeded22784 | 741 | changeModeTo=0; |
sanjeet25 | 7:46aeded22784 | 742 | receivedVPace=false; |
sanjeet25 | 7:46aeded22784 | 743 | |
sanjeet25 | 7:46aeded22784 | 744 | SenseWaitTimer=new RtosTimer(senseWait, osTimerOnce, (void *)0); |
sanjeet25 | 7:46aeded22784 | 745 | Thread SerialThread(serialThread); |
sanjeet25 | 7:46aeded22784 | 746 | SerialThreadPTR=&SerialThread; |
sanjeet25 | 7:46aeded22784 | 747 | SerialThread.set_priority(osPriorityRealtime); |
sanjeet25 | 7:46aeded22784 | 748 | Thread HeartSense(heartSense); |
sanjeet25 | 7:46aeded22784 | 749 | HeartSensePTR=&HeartSense; |
sanjeet25 | 7:46aeded22784 | 750 | HeartSense.set_priority(osPriorityHigh); |
sanjeet25 | 7:46aeded22784 | 751 | Thread Display(display); |
sanjeet25 | 7:46aeded22784 | 752 | Display.set_priority(osPriorityAboveNormal); |
sanjeet25 | 7:46aeded22784 | 753 | Thread TestMode(testMode); |
sanjeet25 | 7:46aeded22784 | 754 | TestModePTR=&TestMode; |
sanjeet25 | 7:46aeded22784 | 755 | TestMode.set_priority(osPriorityAboveNormal); |
sanjeet25 | 7:46aeded22784 | 756 | Thread TestDisplay(testDisplay); |
sanjeet25 | 7:46aeded22784 | 757 | TestDisplayPTR=&TestDisplay; |
sanjeet25 | 7:46aeded22784 | 758 | TestDisplay.set_priority(osPriorityHigh); |
sanjeet25 | 7:46aeded22784 | 759 | APace.fall(&aPace); |
sanjeet25 | 7:46aeded22784 | 760 | VPace.fall(&vPace); |
sanjeet25 | 7:46aeded22784 | 761 | |
sanjeet25 | 7:46aeded22784 | 762 | while(1); |
sanjeet25 | 0:a307f0abfd4d | 763 | } |