PROJ515 / Mbed OS ELEC-351-GROUP-E-CW

Dependencies:   BMP280

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Logging.cpp Source File

Logging.cpp

00001 #include "Logging.h"
00002 #include <string>
00003 
00004 using namespace std;
00005 Mail<uint32_t,32> ActivityLog;  //Mail Queue passes logging data
00006 bool logging = false;           //Are we logging or not
00007 
00008 void LogEvent(uint32_t eventCode)
00009 {
00010     if (logging) {  //Only do if logging is enabled
00011         uint32_t* Status = ActivityLog.alloc(); //Allocate space in mailbox
00012         *Status = eventCode;    //Move data into memory
00013         ActivityLog.put(Status);//data is in queue 
00014     }
00015 }
00016 
00017 string CheckLoggingQueue(void)
00018 {
00019     string returnString = "";
00020     if (logging) {  //Only do if logging is enabled
00021         osEvent evt = ActivityLog.get(5000);    //Get the object from mailbox. This blocks until there is data. Timeout after 5 secconds
00022         if (evt.status == osEventMail) {
00023             //Does it have content? If not, there is no mail.
00024             uint32_t* mail = (uint32_t*)evt.value.p;    //Extract the value passed
00025             //Convert int value to string
00026             char intStr[4]; //Has to be done in two steps because of known to_string bug stackoverflow.com/questions/12975341
00027             sprintf(intStr, "%d", *mail);
00028             string mailAsString = string(intStr);
00029             ActivityLog.free(mail);     //Now we can release the space in the mailbox
00030             returnString = "Data Logged:\n\r" + mailAsString;
00031             return returnString;
00032         } else {  
00033             //There wasn't any data            
00034             string returnString = "ERROR: There wasn't any data";
00035         }
00036     }
00037     return returnString;
00038 }