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: X_NUCLEO_IKS01A1-f255a2c75ecb mbed-rtos mbed
userMethods.cpp
00001 #include "userMethods.h" 00002 #include "sensor.h" 00003 #include <cstring> 00004 #include <ctime> 00005 #include <stdexcept> 00006 #include <vector> 00007 00008 //FIFO buffer 00009 vector<log_data> * logVector; 00010 int * UserMethods::n; 00011 ExpansionBoard * UserMethods::e; 00012 bool UserMethods::flag; 00013 Mail<log_data, QUEUESIZE> * logMail; 00014 00015 // Method that processes the ReadAll command 00016 void UserMethods::readAllData(const void*) 00017 { 00018 printf("Chegei"); 00019 vector<log_data> vector = *logVector; 00020 00021 if(flag) printf("Entered in readAllData"); 00022 00023 char buffer[32]; 00024 00025 //.csv header 00026 if(flag) printf("Sample_Date,HTS221_Temp,LPS25H_Press,HTS221_Hum\n\r"); 00027 00028 for(int i = 0; i < vector.size(); i++) 00029 //TODO Add time here and read n 00030 //.csv friendly format for logging 00031 printf("%s,%7s°C,%smbar,%s%%\n\r", ctime(&vector[i].date), ExpansionBoard::printDouble(buffer, vector[i].tempCelsius, 2), 00032 ExpansionBoard::printDouble(buffer, vector[i].pressure, 2), ExpansionBoard::printDouble(buffer, vector[i].humidity, 2)); 00033 00034 Thread::wait(1000); 00035 } 00036 00037 // Method to proccess Read <n> command 00038 void UserMethods::readNData(const void*) 00039 { 00040 vector<log_data> vector = *logVector; 00041 int num = *n; 00042 00043 if(flag) printf("Sample_Date,HTS221_Temp,LPS25H_Press,HTS221_Hum\n\r"); 00044 00045 char buffer[32]; 00046 for(int i = vector.size()-num-1; i < vector.size(); i++) 00047 printf("%s,%7s°C,%smbar,%s%%\n\r", ctime(&vector[i].date), ExpansionBoard::printDouble(buffer, vector[i].tempCelsius, 2), 00048 ExpansionBoard::printDouble(buffer, vector[i].pressure, 2), ExpansionBoard::printDouble(buffer, vector[i].humidity, 2)); 00049 } 00050 00051 // Method that proccesses the DeleteAll command 00052 int UserMethods::deleteAllData(const void*) 00053 { 00054 vector<log_data> vector = *logVector; 00055 Mail<log_data, QUEUESIZE> mail = *logMail; 00056 int num = vector.size(); 00057 ExpansionBoard sensor = *e; 00058 00059 for(int i = 0; i < vector.size(); i++) { 00060 osEvent evt = mail.get(); 00061 if (evt.status == osEventMail) { 00062 log_data *log = (log_data*)evt.value.p; 00063 mail.free(log); 00064 } 00065 } 00066 00067 vector.clear(); 00068 00069 return num; 00070 } 00071 00072 // Method thar proccesses the Read<n> command 00073 int UserMethods::deleteNData(const void*) 00074 {/* 00075 vector<log_data> vector = *v; 00076 int num = (int)vector.size(); 00077 int nOfRecords = *n; 00078 ExpansionBoard sensor = *e; 00079 00080 if(nOfRecords >= num) { 00081 //nOfRecords = UserMethods::deleteAllData; 00082 return nOfRecords; 00083 } else { 00084 for(int i = 0; i < nOfRecords; i++) { 00085 osEvent evt = sensor.mail_box.get(); 00086 if (evt.status == osEventMail) { 00087 log_data *log = (log_data*)evt.value.p; 00088 sensor.mail_box.free(log); 00089 } 00090 } 00091 //Erases the first n elements 00092 //vector.erase(v.begin(), v.begin() + nOfRecords); 00093 } 00094 00095 return nOfRecords; 00096 */ 00097 return 0; 00098 } 00099 00100 // Constructor of the class 00101 UserMethods::UserMethods(vector<log_data> vector, int num, ExpansionBoard sensor, bool lFlag, Mail<log_data, QUEUESIZE> mail) 00102 { 00103 logVector = &vector; 00104 n = # 00105 e = &sensor; 00106 flag = &lFlag; 00107 }
Generated on Fri Jul 15 2022 17:35:06 by
1.7.2