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