
trabalho
Dependencies: X_NUCLEO_IKS01A1 mbed-rtos mbed
Fork of HelloWorld_IKS01A1 by
Revision 31:eb7320bd1d37, committed 2016-05-09
- Comitter:
- Jacinta
- Date:
- Mon May 09 20:03:21 2016 +0000
- Parent:
- 30:673e342f1932
- Child:
- 32:6e0266e7f205
- Commit message:
- Well..worked in the READ, READAll and around some errors. I?m getting some strange errors as well stating that "log_data" as already been defined, probably changing the name will solve this
Changed in this revision
--- a/buffer.cpp Mon May 09 12:51:37 2016 +0000 +++ b/buffer.cpp Mon May 09 20:03:21 2016 +0000 @@ -8,7 +8,7 @@ // It is thread-safe and often used to buffer data across threads #define BUFFERSIZE 100 - +/* typedef struct { uint8_t id; float tempCelsius; @@ -74,4 +74,5 @@ spaceAvailable = new Semaphore(BUFFERSIZE); samplesInBuffer = new Semaphore(0); } -}; \ No newline at end of file +}; +*/ \ No newline at end of file
--- a/expansionBoard.cpp Mon May 09 12:51:37 2016 +0000 +++ b/expansionBoard.cpp Mon May 09 20:03:21 2016 +0000 @@ -19,10 +19,10 @@ static Ticker ticker; void readData(); - class ExpansionBoard { public: float T; + int count; private: /* Helper function for printing floats & doubles */ @@ -56,7 +56,7 @@ char buffer1[32], buffer2[32]; int32_t axes[3]; - log_data* log_d = mail_box.alloc(); + log_data *log_d = mail_box.alloc(); //TODO Too small!? log_d->id = rand() % 255; @@ -93,18 +93,20 @@ //Send pointer to the queue osStatus stat = mail_box.put(log_d); + count++; // Check for resource error if (stat == osErrorResource) { printf("mail_box->put() Error %4Xh", stat); //Error, free up memory block mail_box.free(log_d); + count--; return; } } public: - ExpansionBoard() { + ExpansionBoard() : count(0) { /* Retrieve the composing elements of the expansion board */ uint8_t id; humidity_sensor->ReadID(&id); @@ -120,7 +122,6 @@ //TODO For now it just spits out the data //but data must be passed to the FIFO ticker.attach(this, &ExpansionBoard::readData, T); - //flipper.attach(&flip, 2.0); } void stopSampling() { ticker.detach(); } }; \ No newline at end of file
--- a/mailBox.cpp Mon May 09 12:51:37 2016 +0000 +++ b/mailBox.cpp Mon May 09 20:03:21 2016 +0000 @@ -13,6 +13,6 @@ int32_t gyroscope[3]; int32_t magnetometer[3]; char* date; - } log_data; + }log_data; Mail<log_data, QUEUESIZE> mail_box; \ No newline at end of file
--- a/main.cpp Mon May 09 12:51:37 2016 +0000 +++ b/main.cpp Mon May 09 20:03:21 2016 +0000 @@ -17,7 +17,8 @@ #include <stdexcept> ExpansionBoard e; -Thread *t; +struct tm t; +//Thread *t; void getData(const void*){ while(true){ @@ -135,10 +136,12 @@ } else if(strcmp("LOGGING", command)==0) { scanf("%s", arg); - if (strcmp("ON", arg)==0) - startLogging(); + if (strcmp("ON", arg)==0){ + //startLogging(); + printf("LOGGING ON"); + } else if (strcmp("OFF", arg)==0){ - stopLogging(); + //stopLogging(); printf("LOGGING OFF"); } else printf("The argument is invalid");
--- a/userInteractions.cpp Mon May 09 12:51:37 2016 +0000 +++ b/userInteractions.cpp Mon May 09 20:03:21 2016 +0000 @@ -1,68 +1,66 @@ -#include "buffer.cpp" +#include "mailBox.cpp" +#include "expansionBoard.cpp" struct tm t; class UserMethods { - Buffer buffer; public: int readAll() { - //Check if there are samples - int32_t Nsamples = samplesInBuffer->wait(); - - Buffer::log_data log; - int count = buffer.newestIndex; - int nOfRecords = 0; + ExpansionBoard logs; + int nOfRecords = logs.count; - while(count >= buffer.oldestIndex){ - log = buffer[count]; - - printf("Record %i \nDate: %s, Temp Celcius: %s, Temp Farenheit: %s, Humidity: %s, - "Pressure: , Accelerometer: %s, Gyroscope: %s, Magnetometer: %s\n\n", log->id, - log->date, log->tempCelcius, log->tempFarenheit, log->humidity, - log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); + while(nOfRecords > 0) { + osEvent evt = mail_box.get(); - count--; - nOfRecords++; + if (evt.status == osEventMail) { + log_data* log = (log_data*)evt.value.p; + printf("Record %d \nDate: %s, Temp Celcius: %f, Temp Farenheit: %f, Humidity: %f, " + "Pressure: %f, Accelerometer: %d, Gyroscope: %d, Magnetometer: %d\n\n", log->id, + log->date, log->tempCelsius, log->tempFarenheit, log->humidity, + log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); + + nOfRecords--; + } } - return nOfRecords; + return logs.count; } int deleteAll() { - int n = mail.count; - mail.recv_thread(n); + int n; //int numRecords; return n; } int readN(int n) { - //Check if there are samples - int32_t Nsamples = samplesInBuffer->wait(); - - Buffer::log_data log; - int count = buffer.newestIndex; + ExpansionBoard logs; int nOfRecords = 0; - - while(count >= n){ - log = buffer[count]; - - printf("Record %i \nDate: %s, Temp Celcius: %s, Temp Farenheit: %s, Humidity: %s, - "Pressure: , Accelerometer: %s, Gyroscope: %s, Magnetometer: %s\n\n", log->id, - log->date, log->tempCelcius, log->tempFarenheit, log->humidity, - log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); - count--; - nOfRecords++; + if(logs.count < n) { + nOfRecords = readAll(); + } else { + while(nOfRecords < n) { + osEvent evt = mail_box.get(); + + if (evt.status == osEventMail) { + log_data* log = (log_data*)evt.value.p; + printf("Record %d \nDate: %s, Temp Celcius: %f, Temp Farenheit: %f, Humidity: %f, " + "Pressure: %f, Accelerometer: %d, Gyroscope: %d, Magnetometer: %d\n\n", log->id, + log->date, log->tempCelsius, log->tempFarenheit, log->humidity, + log->pressure, log->accelerometer, log->gyroscope, log->magnetometer); + + nOfRecords--; + } + } } return nOfRecords; } int deleteN(int n) { - mail.recv_thread(n); - //int numRecords; + return n; }