update code
Dependencies: X_NUCLEO_IKS01A1 mbed-rtos mbed
main.cpp@4:2c73682f05b5, 2016-05-03 (annotated)
- Committer:
- snmatteo
- Date:
- Tue May 03 14:48:13 2016 +0000
- Revision:
- 4:2c73682f05b5
- Parent:
- 3:f61ae69ed662
- Child:
- 6:397db5c5ad11
Fixed some thread errors and a few warnings.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
acarter2 | 0:4a8b751dbe7c | 1 | #include <stdlib.h> |
acarter2 | 1:4cd93767691a | 2 | //#include <pthread.h> |
acarter2 | 1:4cd93767691a | 3 | //#include <semaphore.h> |
acarter2 | 0:4a8b751dbe7c | 4 | #include "buffer.h" |
acarter2 | 0:4a8b751dbe7c | 5 | #include "mbed.h" |
acarter2 | 0:4a8b751dbe7c | 6 | //#include "string.h" |
acarter2 | 0:4a8b751dbe7c | 7 | #include <stdio.h> |
acarter2 | 0:4a8b751dbe7c | 8 | #include <ctype.h> |
acarter2 | 0:4a8b751dbe7c | 9 | #include "x_nucleo_iks01a1.h" |
acarter2 | 0:4a8b751dbe7c | 10 | #include "rtos.h" |
acarter2 | 0:4a8b751dbe7c | 11 | |
acarter2 | 0:4a8b751dbe7c | 12 | #define RAND_DIVISOR 100000000 |
acarter2 | 0:4a8b751dbe7c | 13 | #define TRUE 1 |
acarter2 | 0:4a8b751dbe7c | 14 | |
snmatteo | 4:2c73682f05b5 | 15 | void thread1(const void *); |
snmatteo | 4:2c73682f05b5 | 16 | |
acarter2 | 0:4a8b751dbe7c | 17 | //setting out variables |
acarter2 | 0:4a8b751dbe7c | 18 | |
acarter2 | 0:4a8b751dbe7c | 19 | /** |
acarter2 | 0:4a8b751dbe7c | 20 | / this is setting up the connection from the board |
acarter2 | 0:4a8b751dbe7c | 21 | **/ |
acarter2 | 0:4a8b751dbe7c | 22 | |
acarter2 | 0:4a8b751dbe7c | 23 | static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15); |
acarter2 | 0:4a8b751dbe7c | 24 | static HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor; |
acarter2 | 0:4a8b751dbe7c | 25 | static PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor; |
acarter2 | 0:4a8b751dbe7c | 26 | static TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor; |
acarter2 | 3:f61ae69ed662 | 27 | //static TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor; |
acarter2 | 0:4a8b751dbe7c | 28 | |
acarter2 | 1:4cd93767691a | 29 | /* |
acarter2 | 1:4cd93767691a | 30 | / this is will make sure the contant valid of how much data will be sorted or not as this |
acarter2 | 1:4cd93767691a | 31 | /could help when the data range. |
acarter2 | 1:4cd93767691a | 32 | */ |
acarter2 | 1:4cd93767691a | 33 | const int amountOfSample = 150; |
acarter2 | 1:4cd93767691a | 34 | |
acarter2 | 1:4cd93767691a | 35 | const int BUFFER_SIZE = 75; |
acarter2 | 0:4a8b751dbe7c | 36 | |
snmatteo | 4:2c73682f05b5 | 37 | // Mutex lock |
acarter2 | 1:4cd93767691a | 38 | Mutex *bufferLock; |
acarter2 | 0:4a8b751dbe7c | 39 | |
acarter2 | 0:4a8b751dbe7c | 40 | //buffer |
acarter2 | 3:f61ae69ed662 | 41 | char buffer_item[BUFFER_SIZE]; |
acarter2 | 0:4a8b751dbe7c | 42 | |
acarter2 | 0:4a8b751dbe7c | 43 | |
snmatteo | 4:2c73682f05b5 | 44 | |
snmatteo | 4:2c73682f05b5 | 45 | Thread *tid; //thread id |
snmatteo | 4:2c73682f05b5 | 46 | //pthread_attr_t attr; //set of thread attributes |
acarter2 | 0:4a8b751dbe7c | 47 | |
acarter2 | 0:4a8b751dbe7c | 48 | void *producer(void *param); //producer thread |
acarter2 | 0:4a8b751dbe7c | 49 | void *consumer(void *param); //consumer thread |
acarter2 | 0:4a8b751dbe7c | 50 | |
acarter2 | 1:4cd93767691a | 51 | |
acarter2 | 1:4cd93767691a | 52 | |
acarter2 | 3:f61ae69ed662 | 53 | volatile char memorySample[amountOfSample]; |
acarter2 | 0:4a8b751dbe7c | 54 | |
acarter2 | 0:4a8b751dbe7c | 55 | char values[20][20]; |
acarter2 | 0:4a8b751dbe7c | 56 | |
acarter2 | 1:4cd93767691a | 57 | |
acarter2 | 0:4a8b751dbe7c | 58 | |
acarter2 | 0:4a8b751dbe7c | 59 | |
acarter2 | 0:4a8b751dbe7c | 60 | uint8_t id; |
acarter2 | 0:4a8b751dbe7c | 61 | |
acarter2 | 0:4a8b751dbe7c | 62 | |
acarter2 | 0:4a8b751dbe7c | 63 | //class |
acarter2 | 0:4a8b751dbe7c | 64 | |
acarter2 | 0:4a8b751dbe7c | 65 | class KeyLocks { |
acarter2 | 0:4a8b751dbe7c | 66 | |
acarter2 | 0:4a8b751dbe7c | 67 | public: |
acarter2 | 0:4a8b751dbe7c | 68 | int key; |
acarter2 | 0:4a8b751dbe7c | 69 | |
acarter2 | 0:4a8b751dbe7c | 70 | KeyLocks(){ |
acarter2 | 0:4a8b751dbe7c | 71 | |
acarter2 | 0:4a8b751dbe7c | 72 | key = 0; |
acarter2 | 0:4a8b751dbe7c | 73 | |
acarter2 | 0:4a8b751dbe7c | 74 | } |
acarter2 | 0:4a8b751dbe7c | 75 | |
acarter2 | 0:4a8b751dbe7c | 76 | bool unlock(void) |
acarter2 | 0:4a8b751dbe7c | 77 | { |
acarter2 | 0:4a8b751dbe7c | 78 | if(key == 0){ |
acarter2 | 0:4a8b751dbe7c | 79 | |
acarter2 | 0:4a8b751dbe7c | 80 | key = 1; |
acarter2 | 0:4a8b751dbe7c | 81 | return true; |
acarter2 | 0:4a8b751dbe7c | 82 | |
acarter2 | 0:4a8b751dbe7c | 83 | }else{ |
acarter2 | 0:4a8b751dbe7c | 84 | return false; |
acarter2 | 0:4a8b751dbe7c | 85 | |
acarter2 | 0:4a8b751dbe7c | 86 | } |
acarter2 | 0:4a8b751dbe7c | 87 | } |
acarter2 | 0:4a8b751dbe7c | 88 | |
acarter2 | 0:4a8b751dbe7c | 89 | bool lock(void) |
acarter2 | 0:4a8b751dbe7c | 90 | { |
acarter2 | 0:4a8b751dbe7c | 91 | if(key == 1){ |
acarter2 | 0:4a8b751dbe7c | 92 | |
acarter2 | 0:4a8b751dbe7c | 93 | key = 0; |
acarter2 | 0:4a8b751dbe7c | 94 | return true; |
acarter2 | 0:4a8b751dbe7c | 95 | |
acarter2 | 0:4a8b751dbe7c | 96 | }else{ |
acarter2 | 0:4a8b751dbe7c | 97 | return false; |
acarter2 | 0:4a8b751dbe7c | 98 | |
acarter2 | 0:4a8b751dbe7c | 99 | } |
acarter2 | 0:4a8b751dbe7c | 100 | } |
acarter2 | 0:4a8b751dbe7c | 101 | |
acarter2 | 0:4a8b751dbe7c | 102 | }; |
acarter2 | 0:4a8b751dbe7c | 103 | |
acarter2 | 0:4a8b751dbe7c | 104 | class SampleRate : public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 105 | { |
acarter2 | 0:4a8b751dbe7c | 106 | public: |
acarter2 | 0:4a8b751dbe7c | 107 | /* |
acarter2 | 0:4a8b751dbe7c | 108 | /this is going the amount of time which the data sample will be taking and this will have |
acarter2 | 0:4a8b751dbe7c | 109 | /a default stating of every 15 second but can be changed |
acarter2 | 0:4a8b751dbe7c | 110 | */ |
acarter2 | 0:4a8b751dbe7c | 111 | int sampleRate; |
acarter2 | 0:4a8b751dbe7c | 112 | |
acarter2 | 0:4a8b751dbe7c | 113 | SampleRate(){ |
acarter2 | 0:4a8b751dbe7c | 114 | |
acarter2 | 0:4a8b751dbe7c | 115 | sampleRate = 15; |
acarter2 | 0:4a8b751dbe7c | 116 | |
acarter2 | 0:4a8b751dbe7c | 117 | } |
acarter2 | 0:4a8b751dbe7c | 118 | |
acarter2 | 0:4a8b751dbe7c | 119 | int getSampleRate(void) |
acarter2 | 0:4a8b751dbe7c | 120 | { |
acarter2 | 0:4a8b751dbe7c | 121 | return sampleRate; |
acarter2 | 0:4a8b751dbe7c | 122 | } |
acarter2 | 0:4a8b751dbe7c | 123 | void setSampleRate(double newSampleRate){ |
acarter2 | 0:4a8b751dbe7c | 124 | |
acarter2 | 0:4a8b751dbe7c | 125 | sampleRate = newSampleRate; |
acarter2 | 0:4a8b751dbe7c | 126 | |
acarter2 | 0:4a8b751dbe7c | 127 | } |
acarter2 | 0:4a8b751dbe7c | 128 | |
acarter2 | 0:4a8b751dbe7c | 129 | |
acarter2 | 0:4a8b751dbe7c | 130 | |
acarter2 | 0:4a8b751dbe7c | 131 | }; |
acarter2 | 0:4a8b751dbe7c | 132 | |
acarter2 | 0:4a8b751dbe7c | 133 | |
acarter2 | 0:4a8b751dbe7c | 134 | class TakeSample : public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 135 | { |
acarter2 | 0:4a8b751dbe7c | 136 | public: |
acarter2 | 0:4a8b751dbe7c | 137 | /* |
acarter2 | 0:4a8b751dbe7c | 138 | /this is going to take the sample or not as this can change if the person thing it could happen |
acarter2 | 0:4a8b751dbe7c | 139 | /which will see if the data is stored |
acarter2 | 0:4a8b751dbe7c | 140 | */ |
acarter2 | 0:4a8b751dbe7c | 141 | bool takeSample; |
acarter2 | 0:4a8b751dbe7c | 142 | |
acarter2 | 0:4a8b751dbe7c | 143 | TakeSample(){ |
acarter2 | 0:4a8b751dbe7c | 144 | takeSample = true; |
acarter2 | 0:4a8b751dbe7c | 145 | } |
acarter2 | 0:4a8b751dbe7c | 146 | |
acarter2 | 0:4a8b751dbe7c | 147 | int getTakeSample(void) |
acarter2 | 0:4a8b751dbe7c | 148 | { |
acarter2 | 0:4a8b751dbe7c | 149 | return takeSample; |
acarter2 | 0:4a8b751dbe7c | 150 | } |
acarter2 | 0:4a8b751dbe7c | 151 | void setTakeSample(bool newTakeSample){ |
acarter2 | 0:4a8b751dbe7c | 152 | |
acarter2 | 0:4a8b751dbe7c | 153 | takeSample = newTakeSample; |
acarter2 | 0:4a8b751dbe7c | 154 | |
acarter2 | 0:4a8b751dbe7c | 155 | } |
acarter2 | 0:4a8b751dbe7c | 156 | }; |
acarter2 | 0:4a8b751dbe7c | 157 | |
acarter2 | 0:4a8b751dbe7c | 158 | |
acarter2 | 0:4a8b751dbe7c | 159 | |
acarter2 | 0:4a8b751dbe7c | 160 | class SampleTemp: public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 161 | { |
acarter2 | 0:4a8b751dbe7c | 162 | public: |
acarter2 | 0:4a8b751dbe7c | 163 | |
acarter2 | 0:4a8b751dbe7c | 164 | SampleTemp(){} |
acarter2 | 0:4a8b751dbe7c | 165 | float currentTemp; |
acarter2 | 0:4a8b751dbe7c | 166 | /* |
acarter2 | 0:4a8b751dbe7c | 167 | /this is the fuction which will get the humidity for the external devices |
acarter2 | 0:4a8b751dbe7c | 168 | */ |
acarter2 | 0:4a8b751dbe7c | 169 | float getTemp(void) |
acarter2 | 0:4a8b751dbe7c | 170 | { |
acarter2 | 0:4a8b751dbe7c | 171 | temp_sensor1->GetTemperature(¤tTemp); |
acarter2 | 0:4a8b751dbe7c | 172 | return currentTemp; |
acarter2 | 0:4a8b751dbe7c | 173 | } |
acarter2 | 0:4a8b751dbe7c | 174 | }; |
acarter2 | 0:4a8b751dbe7c | 175 | |
acarter2 | 0:4a8b751dbe7c | 176 | class SampleHumitaty: public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 177 | { |
acarter2 | 0:4a8b751dbe7c | 178 | public: |
acarter2 | 0:4a8b751dbe7c | 179 | |
acarter2 | 0:4a8b751dbe7c | 180 | SampleHumitaty(){} |
acarter2 | 0:4a8b751dbe7c | 181 | |
acarter2 | 0:4a8b751dbe7c | 182 | float currentHumitaty; |
acarter2 | 0:4a8b751dbe7c | 183 | /* |
acarter2 | 0:4a8b751dbe7c | 184 | /this is the fuction which will get the humidity for the external devices |
acarter2 | 0:4a8b751dbe7c | 185 | */ |
acarter2 | 0:4a8b751dbe7c | 186 | float getHumidity() |
acarter2 | 0:4a8b751dbe7c | 187 | { |
acarter2 | 0:4a8b751dbe7c | 188 | humidity_sensor->GetHumidity(¤tHumitaty); |
acarter2 | 0:4a8b751dbe7c | 189 | return currentHumitaty; |
acarter2 | 0:4a8b751dbe7c | 190 | |
acarter2 | 0:4a8b751dbe7c | 191 | } |
acarter2 | 0:4a8b751dbe7c | 192 | }; |
acarter2 | 0:4a8b751dbe7c | 193 | |
acarter2 | 0:4a8b751dbe7c | 194 | |
acarter2 | 0:4a8b751dbe7c | 195 | class SamplePressure: public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 196 | |
acarter2 | 0:4a8b751dbe7c | 197 | { |
acarter2 | 0:4a8b751dbe7c | 198 | public: |
acarter2 | 0:4a8b751dbe7c | 199 | |
acarter2 | 0:4a8b751dbe7c | 200 | SamplePressure(){} |
acarter2 | 0:4a8b751dbe7c | 201 | |
acarter2 | 0:4a8b751dbe7c | 202 | float currentPressure; |
acarter2 | 0:4a8b751dbe7c | 203 | /* |
acarter2 | 0:4a8b751dbe7c | 204 | /this is the fuction which will get the pressure for the external devices |
acarter2 | 0:4a8b751dbe7c | 205 | */ |
acarter2 | 0:4a8b751dbe7c | 206 | float getPressure() |
acarter2 | 0:4a8b751dbe7c | 207 | { |
acarter2 | 0:4a8b751dbe7c | 208 | pressure_sensor->GetPressure(¤tPressure); |
acarter2 | 0:4a8b751dbe7c | 209 | return currentPressure; |
acarter2 | 0:4a8b751dbe7c | 210 | } |
acarter2 | 0:4a8b751dbe7c | 211 | }; |
acarter2 | 0:4a8b751dbe7c | 212 | |
acarter2 | 0:4a8b751dbe7c | 213 | class SampleDisplay: public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 214 | { |
acarter2 | 0:4a8b751dbe7c | 215 | public: |
acarter2 | 0:4a8b751dbe7c | 216 | /* |
acarter2 | 0:4a8b751dbe7c | 217 | /this is the variable to see if the data will be display or not after the data being sorted |
acarter2 | 0:4a8b751dbe7c | 218 | /this can change by the user input |
acarter2 | 0:4a8b751dbe7c | 219 | */ |
acarter2 | 0:4a8b751dbe7c | 220 | |
acarter2 | 0:4a8b751dbe7c | 221 | bool display; |
acarter2 | 0:4a8b751dbe7c | 222 | |
acarter2 | 0:4a8b751dbe7c | 223 | SampleDisplay(){ |
acarter2 | 0:4a8b751dbe7c | 224 | display = false; |
acarter2 | 0:4a8b751dbe7c | 225 | } |
acarter2 | 0:4a8b751dbe7c | 226 | |
acarter2 | 0:4a8b751dbe7c | 227 | bool getTakeDisplay(void) |
acarter2 | 0:4a8b751dbe7c | 228 | { |
acarter2 | 0:4a8b751dbe7c | 229 | return display; |
acarter2 | 0:4a8b751dbe7c | 230 | } |
acarter2 | 0:4a8b751dbe7c | 231 | void setDisplay(bool newSampleDisplay){ |
acarter2 | 0:4a8b751dbe7c | 232 | |
acarter2 | 0:4a8b751dbe7c | 233 | display = newSampleDisplay; |
acarter2 | 0:4a8b751dbe7c | 234 | |
acarter2 | 0:4a8b751dbe7c | 235 | } |
acarter2 | 0:4a8b751dbe7c | 236 | }; |
acarter2 | 0:4a8b751dbe7c | 237 | |
acarter2 | 0:4a8b751dbe7c | 238 | |
acarter2 | 0:4a8b751dbe7c | 239 | |
acarter2 | 0:4a8b751dbe7c | 240 | |
acarter2 | 0:4a8b751dbe7c | 241 | class BufferStartPointer: public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 242 | { |
acarter2 | 0:4a8b751dbe7c | 243 | public: |
acarter2 | 0:4a8b751dbe7c | 244 | /* |
acarter2 | 0:4a8b751dbe7c | 245 | /this is the pointer to start of the buffer as this will make the buffer be cycler |
acarter2 | 0:4a8b751dbe7c | 246 | */ |
acarter2 | 0:4a8b751dbe7c | 247 | int bufferStartPointer; |
acarter2 | 0:4a8b751dbe7c | 248 | |
acarter2 | 0:4a8b751dbe7c | 249 | BufferStartPointer(){ |
acarter2 | 0:4a8b751dbe7c | 250 | bufferStartPointer = 0; |
acarter2 | 0:4a8b751dbe7c | 251 | } |
acarter2 | 0:4a8b751dbe7c | 252 | |
acarter2 | 0:4a8b751dbe7c | 253 | int getBufferStartPointer (void) |
acarter2 | 0:4a8b751dbe7c | 254 | { |
acarter2 | 3:f61ae69ed662 | 255 | key = 1; |
acarter2 | 0:4a8b751dbe7c | 256 | return bufferStartPointer; |
acarter2 | 3:f61ae69ed662 | 257 | |
acarter2 | 0:4a8b751dbe7c | 258 | } |
acarter2 | 0:4a8b751dbe7c | 259 | void setBufferStartPointer (int newBufferStartPointer ){ |
acarter2 | 0:4a8b751dbe7c | 260 | |
acarter2 | 0:4a8b751dbe7c | 261 | bufferStartPointer = newBufferStartPointer; |
acarter2 | 0:4a8b751dbe7c | 262 | |
acarter2 | 1:4cd93767691a | 263 | } |
acarter2 | 1:4cd93767691a | 264 | void plusOne(void){ |
acarter2 | 1:4cd93767691a | 265 | if(bufferStartPointer + 1 == BUFFER_SIZE){ |
acarter2 | 1:4cd93767691a | 266 | bufferStartPointer = 0; |
acarter2 | 1:4cd93767691a | 267 | }else{ |
acarter2 | 1:4cd93767691a | 268 | bufferStartPointer = bufferStartPointer + 1; |
acarter2 | 1:4cd93767691a | 269 | } |
acarter2 | 1:4cd93767691a | 270 | } |
acarter2 | 0:4a8b751dbe7c | 271 | }; |
acarter2 | 0:4a8b751dbe7c | 272 | |
acarter2 | 0:4a8b751dbe7c | 273 | |
acarter2 | 0:4a8b751dbe7c | 274 | class BufferEndPointer: public KeyLocks |
acarter2 | 0:4a8b751dbe7c | 275 | { |
acarter2 | 0:4a8b751dbe7c | 276 | public: |
acarter2 | 0:4a8b751dbe7c | 277 | /* |
acarter2 | 0:4a8b751dbe7c | 278 | /this is the pointer to End of the buffer as this will make the buffer be cycler |
acarter2 | 0:4a8b751dbe7c | 279 | */ |
acarter2 | 0:4a8b751dbe7c | 280 | int bufferEndPointer; |
acarter2 | 0:4a8b751dbe7c | 281 | |
acarter2 | 1:4cd93767691a | 282 | |
acarter2 | 0:4a8b751dbe7c | 283 | BufferEndPointer(){ |
acarter2 | 0:4a8b751dbe7c | 284 | bufferEndPointer = 0; |
acarter2 | 0:4a8b751dbe7c | 285 | } |
acarter2 | 0:4a8b751dbe7c | 286 | |
acarter2 | 0:4a8b751dbe7c | 287 | int getBufferEndPointer (void) |
acarter2 | 0:4a8b751dbe7c | 288 | { |
acarter2 | 0:4a8b751dbe7c | 289 | return bufferEndPointer; |
acarter2 | 0:4a8b751dbe7c | 290 | } |
acarter2 | 0:4a8b751dbe7c | 291 | void setBufferEndPointer (int newBufferEndPointer ){ |
acarter2 | 0:4a8b751dbe7c | 292 | |
acarter2 | 0:4a8b751dbe7c | 293 | bufferEndPointer = newBufferEndPointer; |
acarter2 | 0:4a8b751dbe7c | 294 | |
acarter2 | 1:4cd93767691a | 295 | } |
acarter2 | 1:4cd93767691a | 296 | |
acarter2 | 1:4cd93767691a | 297 | void plusOne(void){ |
acarter2 | 1:4cd93767691a | 298 | if(bufferEndPointer + 1 == BUFFER_SIZE){ |
acarter2 | 1:4cd93767691a | 299 | bufferEndPointer = 0; |
acarter2 | 1:4cd93767691a | 300 | }else{ |
acarter2 | 1:4cd93767691a | 301 | bufferEndPointer = bufferEndPointer + 1; |
acarter2 | 1:4cd93767691a | 302 | } |
acarter2 | 1:4cd93767691a | 303 | } |
acarter2 | 1:4cd93767691a | 304 | }; |
acarter2 | 1:4cd93767691a | 305 | |
acarter2 | 1:4cd93767691a | 306 | class BufferSize: public KeyLocks |
acarter2 | 1:4cd93767691a | 307 | { |
acarter2 | 1:4cd93767691a | 308 | |
acarter2 | 1:4cd93767691a | 309 | public: |
acarter2 | 1:4cd93767691a | 310 | int bufferSize; |
acarter2 | 1:4cd93767691a | 311 | Semaphore *EmptyBuffer; |
acarter2 | 1:4cd93767691a | 312 | Semaphore *fullBuffer; |
acarter2 | 1:4cd93767691a | 313 | |
acarter2 | 1:4cd93767691a | 314 | BufferSize(){ |
acarter2 | 1:4cd93767691a | 315 | EmptyBuffer = new Semaphore(0); |
acarter2 | 3:f61ae69ed662 | 316 | fullBuffer = new Semaphore(BUFFER_SIZE); |
acarter2 | 1:4cd93767691a | 317 | bufferSize = 0; |
acarter2 | 1:4cd93767691a | 318 | |
acarter2 | 1:4cd93767691a | 319 | } |
acarter2 | 1:4cd93767691a | 320 | |
acarter2 | 1:4cd93767691a | 321 | void increaseBufferSize(){ |
acarter2 | 1:4cd93767691a | 322 | bufferSize = bufferSize + 1; |
acarter2 | 1:4cd93767691a | 323 | } |
acarter2 | 1:4cd93767691a | 324 | |
acarter2 | 1:4cd93767691a | 325 | void deincreaseBufferSize(){ |
acarter2 | 1:4cd93767691a | 326 | bufferSize = bufferSize - 1; |
acarter2 | 1:4cd93767691a | 327 | } |
acarter2 | 1:4cd93767691a | 328 | |
acarter2 | 1:4cd93767691a | 329 | int getBufferSize(){ |
acarter2 | 1:4cd93767691a | 330 | return bufferSize; |
acarter2 | 1:4cd93767691a | 331 | } |
acarter2 | 1:4cd93767691a | 332 | |
acarter2 | 1:4cd93767691a | 333 | int getEmptyBuffer(){ |
acarter2 | 1:4cd93767691a | 334 | return EmptyBuffer -> wait(); |
acarter2 | 1:4cd93767691a | 335 | } |
acarter2 | 1:4cd93767691a | 336 | |
acarter2 | 1:4cd93767691a | 337 | int getFullBuffer(){ |
acarter2 | 1:4cd93767691a | 338 | return fullBuffer -> wait(); |
acarter2 | 1:4cd93767691a | 339 | } |
acarter2 | 1:4cd93767691a | 340 | |
acarter2 | 1:4cd93767691a | 341 | void releaseEmptyBuffer(){ |
acarter2 | 3:f61ae69ed662 | 342 | EmptyBuffer -> release(); |
acarter2 | 1:4cd93767691a | 343 | } |
acarter2 | 1:4cd93767691a | 344 | |
acarter2 | 1:4cd93767691a | 345 | void releaseFullBuffer(){ |
acarter2 | 3:f61ae69ed662 | 346 | fullBuffer -> release(); |
acarter2 | 1:4cd93767691a | 347 | } |
acarter2 | 1:4cd93767691a | 348 | |
acarter2 | 1:4cd93767691a | 349 | |
acarter2 | 0:4a8b751dbe7c | 350 | }; |
acarter2 | 0:4a8b751dbe7c | 351 | |
acarter2 | 2:c5fb78148ccc | 352 | /**void initialiseBufferData(){ |
acarter2 | 0:4a8b751dbe7c | 353 | //create mutex lock |
acarter2 | 0:4a8b751dbe7c | 354 | pthread_mutex_init(&mutex, NULL); |
acarter2 | 0:4a8b751dbe7c | 355 | |
acarter2 | 0:4a8b751dbe7c | 356 | //create full semaphore and initialise to 0 |
acarter2 | 0:4a8b751dbe7c | 357 | sem_init(&full, 0, 0); |
acarter2 | 0:4a8b751dbe7c | 358 | |
acarter2 | 0:4a8b751dbe7c | 359 | //create empty semaphore and initialise to BUFFER_SIZE |
acarter2 | 0:4a8b751dbe7c | 360 | sem_init(&empty, 0, BUFFER_SIZE); |
acarter2 | 0:4a8b751dbe7c | 361 | |
acarter2 | 0:4a8b751dbe7c | 362 | //get default attributes |
acarter2 | 0:4a8b751dbe7c | 363 | pthread_attr_init(&attr); |
acarter2 | 0:4a8b751dbe7c | 364 | |
acarter2 | 0:4a8b751dbe7c | 365 | //init buffer |
acarter2 | 0:4a8b751dbe7c | 366 | counter = 0; |
acarter2 | 2:c5fb78148ccc | 367 | }**/ |
acarter2 | 0:4a8b751dbe7c | 368 | |
acarter2 | 0:4a8b751dbe7c | 369 | //producer thread |
acarter2 | 3:f61ae69ed662 | 370 | void *producer(char newItem, BufferEndPointer *endPointer, BufferSize *bufferSize){ |
acarter2 | 1:4cd93767691a | 371 | |
acarter2 | 1:4cd93767691a | 372 | while(!bufferSize->lock()){}; |
acarter2 | 0:4a8b751dbe7c | 373 | |
acarter2 | 1:4cd93767691a | 374 | int size = bufferSize -> getBufferSize(); |
acarter2 | 1:4cd93767691a | 375 | |
acarter2 | 1:4cd93767691a | 376 | while(size < BUFFER_SIZE){ |
acarter2 | 0:4a8b751dbe7c | 377 | //sleep for random amount of time |
acarter2 | 0:4a8b751dbe7c | 378 | |
acarter2 | 1:4cd93767691a | 379 | //get the buffer |
acarter2 | 1:4cd93767691a | 380 | bufferLock->lock(); |
acarter2 | 1:4cd93767691a | 381 | |
acarter2 | 1:4cd93767691a | 382 | |
acarter2 | 1:4cd93767691a | 383 | while(!endPointer->lock()){}; |
acarter2 | 0:4a8b751dbe7c | 384 | |
acarter2 | 1:4cd93767691a | 385 | endPointer->plusOne(); |
acarter2 | 3:f61ae69ed662 | 386 | const int bufferIndex = endPointer->getBufferEndPointer(); |
acarter2 | 3:f61ae69ed662 | 387 | buffer_item[bufferIndex] = newItem; |
acarter2 | 1:4cd93767691a | 388 | endPointer->unlock(); |
acarter2 | 1:4cd93767691a | 389 | bufferLock->unlock(); |
acarter2 | 1:4cd93767691a | 390 | while(!bufferSize->lock()){}; |
acarter2 | 1:4cd93767691a | 391 | bufferSize ->increaseBufferSize(); |
acarter2 | 1:4cd93767691a | 392 | size = bufferSize -> getBufferSize(); |
acarter2 | 1:4cd93767691a | 393 | |
acarter2 | 1:4cd93767691a | 394 | |
acarter2 | 0:4a8b751dbe7c | 395 | } |
acarter2 | 0:4a8b751dbe7c | 396 | } |
acarter2 | 0:4a8b751dbe7c | 397 | |
acarter2 | 0:4a8b751dbe7c | 398 | //consumer thread |
acarter2 | 2:c5fb78148ccc | 399 | void *consumer(BufferStartPointer *startPointer, BufferSize *bufferSize, BufferEndPointer *endPointer) { |
acarter2 | 2:c5fb78148ccc | 400 | |
acarter2 | 2:c5fb78148ccc | 401 | while(!bufferSize->lock()){}; |
acarter2 | 2:c5fb78148ccc | 402 | |
acarter2 | 2:c5fb78148ccc | 403 | int size = bufferSize -> getBufferSize(); |
acarter2 | 2:c5fb78148ccc | 404 | |
acarter2 | 2:c5fb78148ccc | 405 | while(size > 0){ |
acarter2 | 2:c5fb78148ccc | 406 | //sleep for random amount of time |
acarter2 | 2:c5fb78148ccc | 407 | |
acarter2 | 2:c5fb78148ccc | 408 | //get the buffer |
acarter2 | 2:c5fb78148ccc | 409 | bufferLock->lock(); |
acarter2 | 2:c5fb78148ccc | 410 | |
acarter2 | 2:c5fb78148ccc | 411 | while(!endPointer->lock()){}; |
acarter2 | 2:c5fb78148ccc | 412 | |
acarter2 | 3:f61ae69ed662 | 413 | int ramIndex = endPointer->getBufferEndPointer(); |
acarter2 | 2:c5fb78148ccc | 414 | |
acarter2 | 3:f61ae69ed662 | 415 | endPointer -> unlock(); |
acarter2 | 2:c5fb78148ccc | 416 | |
acarter2 | 2:c5fb78148ccc | 417 | while(!startPointer->lock()){}; |
acarter2 | 2:c5fb78148ccc | 418 | |
acarter2 | 2:c5fb78148ccc | 419 | startPointer->plusOne(); |
acarter2 | 3:f61ae69ed662 | 420 | |
acarter2 | 3:f61ae69ed662 | 421 | |
acarter2 | 3:f61ae69ed662 | 422 | memorySample[ramIndex] = buffer_item[startPointer->getBufferStartPointer()]; |
acarter2 | 3:f61ae69ed662 | 423 | |
acarter2 | 3:f61ae69ed662 | 424 | |
acarter2 | 3:f61ae69ed662 | 425 | |
acarter2 | 2:c5fb78148ccc | 426 | startPointer->unlock(); |
acarter2 | 2:c5fb78148ccc | 427 | bufferLock->unlock(); |
acarter2 | 2:c5fb78148ccc | 428 | |
acarter2 | 2:c5fb78148ccc | 429 | |
acarter2 | 2:c5fb78148ccc | 430 | while(!bufferSize->lock()){}; |
acarter2 | 2:c5fb78148ccc | 431 | bufferSize ->deincreaseBufferSize(); |
acarter2 | 2:c5fb78148ccc | 432 | size = bufferSize -> getBufferSize(); |
acarter2 | 2:c5fb78148ccc | 433 | |
acarter2 | 2:c5fb78148ccc | 434 | |
acarter2 | 2:c5fb78148ccc | 435 | } |
acarter2 | 0:4a8b751dbe7c | 436 | |
acarter2 | 1:4cd93767691a | 437 | |
acarter2 | 0:4a8b751dbe7c | 438 | } |
acarter2 | 0:4a8b751dbe7c | 439 | |
acarter2 | 0:4a8b751dbe7c | 440 | //this is setting all the function for the treads in the program |
acarter2 | 0:4a8b751dbe7c | 441 | |
acarter2 | 0:4a8b751dbe7c | 442 | |
acarter2 | 0:4a8b751dbe7c | 443 | /* |
acarter2 | 0:4a8b751dbe7c | 444 | /this is fucntion which the important the updateSample rate |
acarter2 | 0:4a8b751dbe7c | 445 | */ |
acarter2 | 0:4a8b751dbe7c | 446 | void updateSample(SamplePressure* pressure, SampleHumitaty* humitaty, SampleTemp* tempeture) |
acarter2 | 0:4a8b751dbe7c | 447 | { |
acarter2 | 0:4a8b751dbe7c | 448 | while(!pressure->lock()){}; |
acarter2 | 0:4a8b751dbe7c | 449 | |
acarter2 | 0:4a8b751dbe7c | 450 | float currentPressure = pressure->getPressure(); |
acarter2 | 0:4a8b751dbe7c | 451 | pressure->unlock(); |
acarter2 | 0:4a8b751dbe7c | 452 | |
acarter2 | 0:4a8b751dbe7c | 453 | while(!humitaty->lock()){}; |
acarter2 | 0:4a8b751dbe7c | 454 | |
acarter2 | 0:4a8b751dbe7c | 455 | float current= humitaty->getHumidity(); |
acarter2 | 0:4a8b751dbe7c | 456 | humitaty->unlock(); |
acarter2 | 0:4a8b751dbe7c | 457 | |
acarter2 | 0:4a8b751dbe7c | 458 | |
acarter2 | 0:4a8b751dbe7c | 459 | while(!tempeture->lock()){}; |
acarter2 | 0:4a8b751dbe7c | 460 | |
acarter2 | 0:4a8b751dbe7c | 461 | float currentTemp= tempeture->getTemp(); |
acarter2 | 0:4a8b751dbe7c | 462 | tempeture->unlock(); |
acarter2 | 0:4a8b751dbe7c | 463 | |
acarter2 | 0:4a8b751dbe7c | 464 | } |
acarter2 | 0:4a8b751dbe7c | 465 | |
acarter2 | 0:4a8b751dbe7c | 466 | |
acarter2 | 0:4a8b751dbe7c | 467 | void splitString(char inputString[]){ |
acarter2 | 0:4a8b751dbe7c | 468 | int sizeOfArray = 1000; |
acarter2 | 0:4a8b751dbe7c | 469 | char opertaion[sizeOfArray]; |
acarter2 | 0:4a8b751dbe7c | 470 | char data[sizeOfArray]; |
acarter2 | 0:4a8b751dbe7c | 471 | |
acarter2 | 0:4a8b751dbe7c | 472 | for (int i = 0; i < 20; i++){ |
acarter2 | 0:4a8b751dbe7c | 473 | for (int j = 0; i < 20; j++){ |
acarter2 | 0:4a8b751dbe7c | 474 | values[i][j] =' '; |
acarter2 | 0:4a8b751dbe7c | 475 | |
acarter2 | 0:4a8b751dbe7c | 476 | } |
acarter2 | 0:4a8b751dbe7c | 477 | } |
acarter2 | 0:4a8b751dbe7c | 478 | |
acarter2 | 0:4a8b751dbe7c | 479 | for (int i = 0; i < sizeOfArray; i++){ |
acarter2 | 0:4a8b751dbe7c | 480 | |
acarter2 | 0:4a8b751dbe7c | 481 | if(inputString[i] == '<'){ |
acarter2 | 0:4a8b751dbe7c | 482 | for(int j=0; j < i; j++){ |
acarter2 | 0:4a8b751dbe7c | 483 | |
acarter2 | 0:4a8b751dbe7c | 484 | opertaion[j] = inputString[j]; |
acarter2 | 0:4a8b751dbe7c | 485 | |
acarter2 | 0:4a8b751dbe7c | 486 | } |
acarter2 | 0:4a8b751dbe7c | 487 | |
acarter2 | 0:4a8b751dbe7c | 488 | int index = 0; |
acarter2 | 0:4a8b751dbe7c | 489 | |
acarter2 | 0:4a8b751dbe7c | 490 | for(int k=i+1; k < sizeOfArray - 1; k++){ |
acarter2 | 0:4a8b751dbe7c | 491 | |
acarter2 | 0:4a8b751dbe7c | 492 | data[index] = (inputString[k]); |
acarter2 | 0:4a8b751dbe7c | 493 | index++; |
acarter2 | 0:4a8b751dbe7c | 494 | |
acarter2 | 0:4a8b751dbe7c | 495 | } |
acarter2 | 0:4a8b751dbe7c | 496 | |
acarter2 | 0:4a8b751dbe7c | 497 | |
acarter2 | 0:4a8b751dbe7c | 498 | |
acarter2 | 0:4a8b751dbe7c | 499 | for(int y = 0; y < 20; y++){ |
acarter2 | 0:4a8b751dbe7c | 500 | values[0][y] = opertaion[y]; |
acarter2 | 0:4a8b751dbe7c | 501 | } |
acarter2 | 0:4a8b751dbe7c | 502 | |
acarter2 | 0:4a8b751dbe7c | 503 | for(int z = 0;z < 20; z++){ |
acarter2 | 0:4a8b751dbe7c | 504 | values[1][z] = data[z]; |
acarter2 | 0:4a8b751dbe7c | 505 | } |
acarter2 | 0:4a8b751dbe7c | 506 | |
acarter2 | 0:4a8b751dbe7c | 507 | break; |
acarter2 | 0:4a8b751dbe7c | 508 | |
acarter2 | 0:4a8b751dbe7c | 509 | } |
acarter2 | 0:4a8b751dbe7c | 510 | } |
acarter2 | 0:4a8b751dbe7c | 511 | } |
acarter2 | 0:4a8b751dbe7c | 512 | |
acarter2 | 3:f61ae69ed662 | 513 | static char *printDouble(char* str, double v, int decimalDigits=2) |
acarter2 | 3:f61ae69ed662 | 514 | { |
acarter2 | 3:f61ae69ed662 | 515 | int i = 1; |
acarter2 | 3:f61ae69ed662 | 516 | int intPart, fractPart; |
acarter2 | 3:f61ae69ed662 | 517 | int len; |
acarter2 | 3:f61ae69ed662 | 518 | char *ptr; |
acarter2 | 3:f61ae69ed662 | 519 | |
acarter2 | 3:f61ae69ed662 | 520 | /* prepare decimal digits multiplicator */ |
acarter2 | 3:f61ae69ed662 | 521 | for (;decimalDigits!=0; i*=10, decimalDigits--); |
acarter2 | 3:f61ae69ed662 | 522 | |
acarter2 | 3:f61ae69ed662 | 523 | /* calculate integer & fractinal parts */ |
acarter2 | 3:f61ae69ed662 | 524 | intPart = (int)v; |
acarter2 | 3:f61ae69ed662 | 525 | fractPart = (int)((v-(double)(int)v)*i); |
acarter2 | 3:f61ae69ed662 | 526 | |
acarter2 | 3:f61ae69ed662 | 527 | /* fill in integer part */ |
acarter2 | 3:f61ae69ed662 | 528 | sprintf(str, "%i.", intPart); |
acarter2 | 3:f61ae69ed662 | 529 | |
acarter2 | 3:f61ae69ed662 | 530 | /* prepare fill in of fractional part */ |
acarter2 | 3:f61ae69ed662 | 531 | len = strlen(str); |
acarter2 | 3:f61ae69ed662 | 532 | ptr = &str[len]; |
acarter2 | 3:f61ae69ed662 | 533 | |
acarter2 | 3:f61ae69ed662 | 534 | /* fill in leading fractional zeros */ |
acarter2 | 3:f61ae69ed662 | 535 | for (i/=10;i>1; i/=10, ptr++) { |
acarter2 | 3:f61ae69ed662 | 536 | if(fractPart >= i) break; |
acarter2 | 3:f61ae69ed662 | 537 | *ptr = '0'; |
acarter2 | 3:f61ae69ed662 | 538 | } |
acarter2 | 3:f61ae69ed662 | 539 | |
acarter2 | 3:f61ae69ed662 | 540 | /* fill in (rest of) fractional part */ |
acarter2 | 3:f61ae69ed662 | 541 | sprintf(ptr, "%i", fractPart); |
acarter2 | 3:f61ae69ed662 | 542 | |
acarter2 | 3:f61ae69ed662 | 543 | return str; |
acarter2 | 3:f61ae69ed662 | 544 | } |
acarter2 | 3:f61ae69ed662 | 545 | |
acarter2 | 0:4a8b751dbe7c | 546 | /* |
acarter2 | 0:4a8b751dbe7c | 547 | /this is going to sort the string to see the opertion which will picked the opertion which |
acarter2 | 0:4a8b751dbe7c | 548 | /need the be carried out and the put the data in to the tread to then which the tread will |
acarter2 | 0:4a8b751dbe7c | 549 | /do it operation |
acarter2 | 0:4a8b751dbe7c | 550 | */ |
acarter2 | 0:4a8b751dbe7c | 551 | void sortString(char inputString[]) |
acarter2 | 0:4a8b751dbe7c | 552 | { |
acarter2 | 0:4a8b751dbe7c | 553 | |
acarter2 | 0:4a8b751dbe7c | 554 | //if("DELETE" == values[0]){ |
acarter2 | 0:4a8b751dbe7c | 555 | |
acarter2 | 0:4a8b751dbe7c | 556 | //printCurrentRecord(values[]); |
acarter2 | 0:4a8b751dbe7c | 557 | |
acarter2 | 0:4a8b751dbe7c | 558 | //} |
acarter2 | 0:4a8b751dbe7c | 559 | |
acarter2 | 0:4a8b751dbe7c | 560 | //https://developer.mbed.org/teams/Students-Plymouth-University-UK-SoCEM/ |
acarter2 | 0:4a8b751dbe7c | 561 | |
acarter2 | 0:4a8b751dbe7c | 562 | } |
acarter2 | 0:4a8b751dbe7c | 563 | |
acarter2 | 0:4a8b751dbe7c | 564 | |
acarter2 | 0:4a8b751dbe7c | 565 | |
acarter2 | 0:4a8b751dbe7c | 566 | |
acarter2 | 0:4a8b751dbe7c | 567 | /* |
acarter2 | 0:4a8b751dbe7c | 568 | /this is function that will written to the memory of the from the buffer so that will be fast |
acarter2 | 0:4a8b751dbe7c | 569 | / and did not lose anydata |
acarter2 | 0:4a8b751dbe7c | 570 | */ |
acarter2 | 0:4a8b751dbe7c | 571 | void writtenToMemory(const void* arg ) |
acarter2 | 0:4a8b751dbe7c | 572 | { |
acarter2 | 0:4a8b751dbe7c | 573 | |
acarter2 | 0:4a8b751dbe7c | 574 | } |
acarter2 | 0:4a8b751dbe7c | 575 | |
acarter2 | 0:4a8b751dbe7c | 576 | |
acarter2 | 0:4a8b751dbe7c | 577 | /* |
acarter2 | 0:4a8b751dbe7c | 578 | /this is he deleteRecords which will move the buffer regard so that the bufferent will over |
acarter2 | 0:4a8b751dbe7c | 579 | /write to the old data in the fifo buffer |
acarter2 | 0:4a8b751dbe7c | 580 | */ |
acarter2 | 0:4a8b751dbe7c | 581 | void deleteRecord(const void* arg ) |
acarter2 | 0:4a8b751dbe7c | 582 | { |
acarter2 | 0:4a8b751dbe7c | 583 | |
acarter2 | 0:4a8b751dbe7c | 584 | } |
acarter2 | 0:4a8b751dbe7c | 585 | |
acarter2 | 0:4a8b751dbe7c | 586 | |
acarter2 | 0:4a8b751dbe7c | 587 | /* |
acarter2 | 0:4a8b751dbe7c | 588 | /read Record is the most reason data which which is store in the data |
acarter2 | 0:4a8b751dbe7c | 589 | */ |
acarter2 | 0:4a8b751dbe7c | 590 | void readRecord(const void* arg ) |
acarter2 | 0:4a8b751dbe7c | 591 | { |
acarter2 | 0:4a8b751dbe7c | 592 | |
acarter2 | 0:4a8b751dbe7c | 593 | } |
acarter2 | 0:4a8b751dbe7c | 594 | |
acarter2 | 0:4a8b751dbe7c | 595 | |
acarter2 | 0:4a8b751dbe7c | 596 | /* |
acarter2 | 0:4a8b751dbe7c | 597 | /read Record is the selected data which be passed in as a a string |
acarter2 | 0:4a8b751dbe7c | 598 | */ |
acarter2 | 3:f61ae69ed662 | 599 | void printCurrentRecord(char displayString, int length) |
acarter2 | 3:f61ae69ed662 | 600 | { |
acarter2 | 3:f61ae69ed662 | 601 | printf("%c\n", displayString); |
acarter2 | 0:4a8b751dbe7c | 602 | |
acarter2 | 0:4a8b751dbe7c | 603 | |
acarter2 | 0:4a8b751dbe7c | 604 | } |
acarter2 | 0:4a8b751dbe7c | 605 | |
acarter2 | 0:4a8b751dbe7c | 606 | void deleteAll(BufferStartPointer* bufferStart, BufferEndPointer* bufferEnd){ |
acarter2 | 0:4a8b751dbe7c | 607 | |
acarter2 | 0:4a8b751dbe7c | 608 | while(bufferStart -> lock()){} |
acarter2 | 0:4a8b751dbe7c | 609 | bufferStart -> setBufferStartPointer(0); |
acarter2 | 0:4a8b751dbe7c | 610 | bufferStart -> unlock(); |
acarter2 | 0:4a8b751dbe7c | 611 | |
acarter2 | 0:4a8b751dbe7c | 612 | while(bufferEnd -> lock()){}; |
acarter2 | 0:4a8b751dbe7c | 613 | bufferEnd -> setBufferEndPointer(0); |
acarter2 | 0:4a8b751dbe7c | 614 | bufferEnd -> unlock(); |
acarter2 | 0:4a8b751dbe7c | 615 | |
acarter2 | 0:4a8b751dbe7c | 616 | |
acarter2 | 0:4a8b751dbe7c | 617 | // need the ram memory |
acarter2 | 0:4a8b751dbe7c | 618 | |
acarter2 | 0:4a8b751dbe7c | 619 | |
acarter2 | 0:4a8b751dbe7c | 620 | |
acarter2 | 0:4a8b751dbe7c | 621 | |
acarter2 | 0:4a8b751dbe7c | 622 | |
acarter2 | 0:4a8b751dbe7c | 623 | } |
acarter2 | 0:4a8b751dbe7c | 624 | |
acarter2 | 0:4a8b751dbe7c | 625 | /* |
acarter2 | 0:4a8b751dbe7c | 626 | /this is the fuction which update the the sample rate so the int to |
acarter2 | 0:4a8b751dbe7c | 627 | /update the value whoch might hange |
acarter2 | 0:4a8b751dbe7c | 628 | */ |
acarter2 | 0:4a8b751dbe7c | 629 | void updateSampleRate(double newSampleRate, SampleRate* sampleRate) |
acarter2 | 0:4a8b751dbe7c | 630 | { |
acarter2 | 0:4a8b751dbe7c | 631 | while(!sampleRate -> lock()){}; |
acarter2 | 3:f61ae69ed662 | 632 | char outputString = 'OUT OF RANGE'; |
acarter2 | 3:f61ae69ed662 | 633 | |
snmatteo | 4:2c73682f05b5 | 634 | if(newSampleRate >= 0.1 && newSampleRate <= 60.0){ |
acarter2 | 3:f61ae69ed662 | 635 | sampleRate -> setSampleRate(newSampleRate); |
acarter2 | 3:f61ae69ed662 | 636 | char decimel; |
acarter2 | 3:f61ae69ed662 | 637 | printDouble(&decimel, newSampleRate, 2); |
acarter2 | 3:f61ae69ed662 | 638 | |
snmatteo | 4:2c73682f05b5 | 639 | outputString = 'UPDATE<' + decimel + '>'; |
acarter2 | 3:f61ae69ed662 | 640 | } |
acarter2 | 0:4a8b751dbe7c | 641 | sampleRate -> unlock(); |
acarter2 | 0:4a8b751dbe7c | 642 | |
acarter2 | 0:4a8b751dbe7c | 643 | } |
acarter2 | 0:4a8b751dbe7c | 644 | |
acarter2 | 0:4a8b751dbe7c | 645 | /*/ |
acarter2 | 0:4a8b751dbe7c | 646 | /this is update the the log so see if the log if the the sample rate |
acarter2 | 0:4a8b751dbe7c | 647 | ozr not |
acarter2 | 0:4a8b751dbe7c | 648 | */ |
acarter2 | 3:f61ae69ed662 | 649 | void updateLog(char logType, TakeSample *takeSample) |
acarter2 | 0:4a8b751dbe7c | 650 | { |
acarter2 | 3:f61ae69ed662 | 651 | char output = ' '; |
acarter2 | 3:f61ae69ed662 | 652 | |
acarter2 | 3:f61ae69ed662 | 653 | while(takeSample -> lock()){}; |
acarter2 | 0:4a8b751dbe7c | 654 | |
acarter2 | 3:f61ae69ed662 | 655 | |
acarter2 | 3:f61ae69ed662 | 656 | if(logType == 'NO'){ |
acarter2 | 3:f61ae69ed662 | 657 | takeSample -> setTakeSample(false); |
acarter2 | 3:f61ae69ed662 | 658 | output ='Log<ON>'; |
acarter2 | 3:f61ae69ed662 | 659 | |
acarter2 | 0:4a8b751dbe7c | 660 | |
acarter2 | 0:4a8b751dbe7c | 661 | } |
acarter2 | 0:4a8b751dbe7c | 662 | |
acarter2 | 3:f61ae69ed662 | 663 | if(logType == 'YES' ){ |
acarter2 | 3:f61ae69ed662 | 664 | takeSample -> setTakeSample(true); |
acarter2 | 3:f61ae69ed662 | 665 | output ='Log<OFF>'; |
acarter2 | 3:f61ae69ed662 | 666 | |
acarter2 | 3:f61ae69ed662 | 667 | |
acarter2 | 0:4a8b751dbe7c | 668 | } |
acarter2 | 0:4a8b751dbe7c | 669 | takeSample -> unlock(); |
acarter2 | 0:4a8b751dbe7c | 670 | |
acarter2 | 0:4a8b751dbe7c | 671 | //need output tread |
acarter2 | 0:4a8b751dbe7c | 672 | |
acarter2 | 0:4a8b751dbe7c | 673 | } |
acarter2 | 0:4a8b751dbe7c | 674 | |
acarter2 | 0:4a8b751dbe7c | 675 | /* |
acarter2 | 0:4a8b751dbe7c | 676 | /tthis is update th date which the system will go from and with change |
acarter2 | 0:4a8b751dbe7c | 677 | / the date so that the records are set with the date. |
acarter2 | 0:4a8b751dbe7c | 678 | */ |
acarter2 | 0:4a8b751dbe7c | 679 | void updateDate(char newDate[]) |
acarter2 | 0:4a8b751dbe7c | 680 | { |
acarter2 | 0:4a8b751dbe7c | 681 | |
acarter2 | 0:4a8b751dbe7c | 682 | } |
acarter2 | 0:4a8b751dbe7c | 683 | |
acarter2 | 0:4a8b751dbe7c | 684 | /* |
acarter2 | 0:4a8b751dbe7c | 685 | /tthis is update th time which the system will go from and with change |
acarter2 | 0:4a8b751dbe7c | 686 | / the time so that the records are set with the date. |
acarter2 | 0:4a8b751dbe7c | 687 | */ |
acarter2 | 0:4a8b751dbe7c | 688 | void updateTime(char newTime[]) |
acarter2 | 0:4a8b751dbe7c | 689 | { |
acarter2 | 0:4a8b751dbe7c | 690 | |
acarter2 | 0:4a8b751dbe7c | 691 | } |
acarter2 | 0:4a8b751dbe7c | 692 | |
acarter2 | 3:f61ae69ed662 | 693 | void updateDisplayState(SampleDisplay* sampleDisplay, char displayString){ |
acarter2 | 0:4a8b751dbe7c | 694 | |
acarter2 | 3:f61ae69ed662 | 695 | char output = ' '; |
acarter2 | 0:4a8b751dbe7c | 696 | |
acarter2 | 0:4a8b751dbe7c | 697 | while(!sampleDisplay -> lock()){}; |
acarter2 | 3:f61ae69ed662 | 698 | if(displayString == 'NO'){ |
acarter2 | 3:f61ae69ed662 | 699 | sampleDisplay -> setDisplay(false); |
acarter2 | 3:f61ae69ed662 | 700 | output = 'SAMPLING<ON>'; |
acarter2 | 0:4a8b751dbe7c | 701 | |
acarter2 | 0:4a8b751dbe7c | 702 | } |
acarter2 | 0:4a8b751dbe7c | 703 | |
acarter2 | 3:f61ae69ed662 | 704 | if(displayString == 'YES'){ |
acarter2 | 3:f61ae69ed662 | 705 | sampleDisplay -> setDisplay(true); |
acarter2 | 3:f61ae69ed662 | 706 | output = 'SAMPLING<OFF>'; |
acarter2 | 3:f61ae69ed662 | 707 | |
acarter2 | 3:f61ae69ed662 | 708 | |
acarter2 | 0:4a8b751dbe7c | 709 | } |
acarter2 | 0:4a8b751dbe7c | 710 | sampleDisplay -> unlock(); |
acarter2 | 0:4a8b751dbe7c | 711 | |
acarter2 | 0:4a8b751dbe7c | 712 | } |
acarter2 | 0:4a8b751dbe7c | 713 | |
acarter2 | 0:4a8b751dbe7c | 714 | void readInput(){ |
acarter2 | 0:4a8b751dbe7c | 715 | |
acarter2 | 0:4a8b751dbe7c | 716 | char ch; |
acarter2 | 0:4a8b751dbe7c | 717 | char input[100]; |
acarter2 | 3:f61ae69ed662 | 718 | int place = 0; |
acarter2 | 0:4a8b751dbe7c | 719 | do |
acarter2 | 0:4a8b751dbe7c | 720 | { |
acarter2 | 0:4a8b751dbe7c | 721 | ch = getchar(); |
acarter2 | 0:4a8b751dbe7c | 722 | if(ch != EOF || ch != '\n'|| ch != ' '){ |
acarter2 | 3:f61ae69ed662 | 723 | input[place] = ch; |
acarter2 | 3:f61ae69ed662 | 724 | place++; |
acarter2 | 0:4a8b751dbe7c | 725 | } |
acarter2 | 0:4a8b751dbe7c | 726 | |
acarter2 | 0:4a8b751dbe7c | 727 | }while( ch != '\n' || ch != EOF); |
acarter2 | 0:4a8b751dbe7c | 728 | |
acarter2 | 3:f61ae69ed662 | 729 | if(place> 1){ |
acarter2 | 0:4a8b751dbe7c | 730 | |
acarter2 | 0:4a8b751dbe7c | 731 | //Thread stringMutipluation; |
acarter2 | 0:4a8b751dbe7c | 732 | |
acarter2 | 0:4a8b751dbe7c | 733 | //stringMutipluation =7 new Thread(sortString); |
acarter2 | 0:4a8b751dbe7c | 734 | |
acarter2 | 0:4a8b751dbe7c | 735 | |
acarter2 | 0:4a8b751dbe7c | 736 | } |
acarter2 | 0:4a8b751dbe7c | 737 | } |
acarter2 | 0:4a8b751dbe7c | 738 | |
acarter2 | 0:4a8b751dbe7c | 739 | |
acarter2 | 0:4a8b751dbe7c | 740 | // setting up gobal treads to be uses in the program |
acarter2 | 0:4a8b751dbe7c | 741 | //Thread producter(); |
acarter2 | 0:4a8b751dbe7c | 742 | //Thread customer; |
acarter2 | 0:4a8b751dbe7c | 743 | //Thread tempTread; |
acarter2 | 0:4a8b751dbe7c | 744 | //Thread humTread; |
acarter2 | 0:4a8b751dbe7c | 745 | //Thread pressTread(; |
acarter2 | 0:4a8b751dbe7c | 746 | //Thread displayTread; |
acarter2 | 0:4a8b751dbe7c | 747 | //Thread sampleTread; |
snmatteo | 4:2c73682f05b5 | 748 | Thread *inputTread; |
acarter2 | 0:4a8b751dbe7c | 749 | Thread deleteRecordTread(deleteRecord); |
acarter2 | 0:4a8b751dbe7c | 750 | //Thread setDateTread; |
acarter2 | 0:4a8b751dbe7c | 751 | //Thread setTimeTread; |
acarter2 | 0:4a8b751dbe7c | 752 | //Thread dsiplaySelectedRecord; |
acarter2 | 0:4a8b751dbe7c | 753 | //Thread updateTakeDisplay; |
acarter2 | 0:4a8b751dbe7c | 754 | //Thread updateTreadTiming; |
acarter2 | 0:4a8b751dbe7c | 755 | //Thread stringMutipluation; |
acarter2 | 0:4a8b751dbe7c | 756 | |
acarter2 | 0:4a8b751dbe7c | 757 | |
acarter2 | 0:4a8b751dbe7c | 758 | PwmOut mypwm(PWM_OUT); |
acarter2 | 0:4a8b751dbe7c | 759 | |
acarter2 | 0:4a8b751dbe7c | 760 | DigitalOut myled(LED1); |
acarter2 | 0:4a8b751dbe7c | 761 | |
acarter2 | 0:4a8b751dbe7c | 762 | int main() { |
acarter2 | 3:f61ae69ed662 | 763 | |
snmatteo | 4:2c73682f05b5 | 764 | tid = new Thread(&thread1); |
acarter2 | 0:4a8b751dbe7c | 765 | SampleRate sampleRate = SampleRate(); |
acarter2 | 0:4a8b751dbe7c | 766 | TakeSample takeSample = TakeSample(); |
acarter2 | 0:4a8b751dbe7c | 767 | SampleTemp sampleTemp = SampleTemp(); |
acarter2 | 0:4a8b751dbe7c | 768 | SampleHumitaty sampleHumitaty = SampleHumitaty(); |
acarter2 | 0:4a8b751dbe7c | 769 | SamplePressure samplePressure = SamplePressure(); |
acarter2 | 0:4a8b751dbe7c | 770 | SampleDisplay sampleDisplay = SampleDisplay(); |
acarter2 | 0:4a8b751dbe7c | 771 | BufferStartPointer bufferStartPointer = BufferStartPointer(); |
acarter2 | 0:4a8b751dbe7c | 772 | BufferEndPointer bufferEndPointer = BufferEndPointer(); |
acarter2 | 1:4cd93767691a | 773 | bufferLock = new Mutex(); |
acarter2 | 0:4a8b751dbe7c | 774 | |
acarter2 | 0:4a8b751dbe7c | 775 | |
acarter2 | 0:4a8b751dbe7c | 776 | while(1) { |
acarter2 | 0:4a8b751dbe7c | 777 | |
acarter2 | 0:4a8b751dbe7c | 778 | readInput(); |
acarter2 | 0:4a8b751dbe7c | 779 | |
acarter2 | 0:4a8b751dbe7c | 780 | |
acarter2 | 0:4a8b751dbe7c | 781 | myled = !myled; |
acarter2 | 0:4a8b751dbe7c | 782 | wait(1); |
acarter2 | 0:4a8b751dbe7c | 783 | } |
acarter2 | 0:4a8b751dbe7c | 784 | } |
acarter2 | 0:4a8b751dbe7c | 785 |