Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: sd-driver_compatible_with_MAX32630FTHR
Fork of CircularBufferSDCardLib by
Revision 2:c2cfb0ebc3bd, committed 2018-04-04
- Comitter:
- DVLevine
- Date:
- Wed Apr 04 16:17:34 2018 -0400
- Parent:
- 1:45627bbdeb69
- Child:
- 3:df8fb1b5d868
- Commit message:
- Completed first round. Now need to bug check
Changed in this revision
--- a/dataRecorder.cpp Tue Apr 03 22:41:46 2018 -0400
+++ b/dataRecorder.cpp Wed Apr 04 16:17:34 2018 -0400
@@ -13,102 +13,79 @@
/* PUBLIC METHODS */
-int DataRecorder::getQuantityStored(){
+int DataRecorder::getDataQuantity(){
return m_data_quantity;
}
+int DataRecorder::getTimeStampQuantity(){
+ return m_time_quantity;
+}
+
uint16_t DataRecorder::popLastDataPoint(){
- return m_buf_data.pop();
+ m_data_quantity--;
+ if (m_data_quantity<0){
+ m_data_quantity=0;
+ }
+ if(!m_buf_data.empty()){
+ return m_buf_data.pop();
+ }else{
+ return (uint16_t)0;
+ }
+
}
uint32_t DataRecorder::popLastTimeStamp(){
- return m_buf_timestamp.pop();
+ m_time_quantity--;
+ if (m_time_quantity<0){
+ m_time_quantity=0;
+ }
+
+ if(!m_buf_time.empty()){
+ return m_buf_time.pop();
+ }else{
+ return (uint16_t)0;
+ }
+
}
void DataRecorder::logDistancePoint(uint16_t value){
+ m_data_quantity++;
+ if (m_data_quantity>BUF_SIZE){
+ m_data_quantity=BUF_SIZE;
+ }
m_buf_data.push(value);
-
}
void DataRecorder::logTimeStamp(uint32_t value){
+ m_time_quantity++;
+ if (m_time_quantity>BUF_SIZE){
+ m_time_quantity=BUF_SIZE;
+ }
m_buf_timestamp.push(value);
}
+
/** Save logged data to SD card **/
void DataRecorder::saveLoggedData(string filename){
//iterate over buffer and use the sd card commands
-
+ int indexArr[m_data_quantity];
+ for (int i = indexArr.size-1; i >=0 ; i--){
+ indexArr[i] = i;
+ }
+
+ uint32_t timeArr[m_time_quantity];
+ uint16_t* allDataArr[m_data_quantity];
-
+ for (int i = 0; i < allDataArr.size; i++){
+ uint16_t dataEntry[1];
+ dataEntry[1] = popLastDataPoint();
+ allDataArr[i] = dataEntry;
+ }
+
+ m_saveBuddy->fullWriteProcedure(filename,indexArr,timeArr,allDataArr);
}
//saves buffer to sd card and clears it
void DataRecorder::saveLoggedDataAndClearBuffer(string filename){
saveLoggedData(filename);
// then eraseBuffers();
}
-
-
-/* PRIVATE METHODS */
-
-
-
-//private buffer load in method
-void DataRecorder::pushEleToBuffer(uint16_t inputVal){
- buf_distance.push(inputVal);
- // while (!buf.full()) {
- // buf.push(inputVal);
- // }
-
-}
-
-uint8_t* DataRecorder::getDistanceBlock(){
- return blockDistance;
-}
-
-int DataRecorder::getDistanceDataLength(){
- return blockDistance_Index;
-};
-
-
-//writes input value to buffer
-void DataRecorder::LogDistancePoint(uint16_t value){
- buf_distance.push(value);
- savePoint(value);
-}
-
-void DataRecorder::savePoint(uint16_t value){
- string yo = SSTR(value);
- int n = yo.length();
- // declaring character array
- char char_array[n+1];
-
- // copying the contents of the
- // string to char array
- strcpy(char_array, yo.c_str());
-
-
- int counter = 0;
-
- for (int i=blockDistance_Index; i<blockDistance_Index+n; i++){
- blockDistance[i] = char_array[counter];
- //printf("%i\n",i);
- //printf("%c\n",blockDistance[i]);
- counter++;
- }
-
- blockDistance_Index = blockDistance_Index+n;
-
- //add separator
- blockDistance[blockDistance_Index] = ' ';
- blockDistance_Index++;
-
- //buf.push(char_array[i]);
- //buf_distance
-}
-
-
-void DataRecorder::savePoint(uint16_t value);
-
-
-
-void DataRecorder::pushEleToBuffer(uint16_t);
--- a/dataRecorder.h Tue Apr 03 22:41:46 2018 -0400
+++ b/dataRecorder.h Wed Apr 04 16:17:34 2018 -0400
@@ -8,7 +8,7 @@
#define SSTR( x ) static_cast< std::ostringstream & >(( std::ostringstream() << std::dec << x ) ).str()
// Define circular buffer size
-#define BUF_SIZE 150
+#define BUF_SIZE 350
/** Data Recorder is a class that stores data measurements in a ring buffer.
@@ -39,7 +39,6 @@
private:
void savePoint(uint16_t value);
- void pushEleToBuffer(uint16_t);
// input values are converted to char arrays
// iterate over char array to add values to buffer
// buffer contents it turned into a uint8_t array and written to
@@ -51,6 +50,7 @@
// Count for buffers
int m_data_quantity;
+ int m_time_quantity;
/* SD Card Interface Object */
SDCardReader* m_saveBuddy;
--- a/main.cpp Tue Apr 03 22:41:46 2018 -0400
+++ b/main.cpp Wed Apr 04 16:17:34 2018 -0400
@@ -30,12 +30,9 @@
boba->LogDistancePoint(d);
boba->LogDistancePoint(e);
- uint8_t* dooba = boba->getDistanceBlock();
- int distanco = boba->getDistanceDataLength();
-
- int ere = soba.writeBlock(dooba,distanco);
//printf("ERE IS %i \n",ere);
-
+
+ boba->saveLoggedDataAndClearBuffer("SUPERDATAYO.txt");
led1 = !led1;
--- a/sdCardReader.h Tue Apr 03 22:41:46 2018 -0400
+++ b/sdCardReader.h Wed Apr 04 16:17:34 2018 -0400
@@ -32,7 +32,6 @@
void write_uint16_t(uint16_t data, bool endline, FILE* fileToUse);
void write_uint32_t(uint32_t data, bool endline, FILE* fileToUse);
-
// Define file system
FATFileSystem m_fs("fs");
};
