SkyTEM BMAG / Mbed 2 deprecated BMAGThrRev

Dependencies:   mbed WDT MODSERIAL BME280

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ErrorHandler.cpp Source File

ErrorHandler.cpp

00001 #include "ErrorHandler.h"
00002 
00003 
00004 //! ErrorHandler, default constructor
00005 ErrorHandler::ErrorHandler(){
00006     errorStr1.assign("        ");
00007     errorStr2.assign("        ");
00008     currentState  = NONE;
00009     setMagTimePrompted = false;
00010     memset(tmparr,'\0',10);
00011     magPromptCounter = 0;   
00012 };
00013 
00014 
00015 //! ErrorHandler, constructor taking a few inputs
00016 /*!
00017     This constuctor takes a few inputs, to enable more functionality
00018     
00019     \param batteryvoltage A string pointer, enabling the class to access the current battery voltage string
00020     \param fix A bool pointer, pointing to a boolean flag with gps fix status
00021     \param bmag A BMAG object pointer, enabling the access to mag data directly from this class
00022     \param gps An NMEA object pointer to a gps in this case 
00023 */
00024 ErrorHandler::ErrorHandler(string * batteryvoltage, bool * fix, BMAG * bmag, NMEA * gps){
00025     errorStr1.assign("        ");
00026     errorStr2.assign("        ");
00027     currentState  = NONE;
00028     memset(tmparr,'\0',10);
00029     fixptr = fix;
00030     batteryvoltageptr = batteryvoltage;
00031     bmagptr = bmag;
00032     gpsPtr = gps;
00033     setMagTimePrompted = false;
00034     magPromptCounter = 0;       
00035 };
00036 
00037 //! getLine1 is an error string getter method
00038 /*!
00039     This method returns the first row of input used in a display
00040     
00041     \return errorStr1 a string containing the first display row 
00042     
00043 */
00044 string ErrorHandler::getLine1(void){
00045     return errorStr1;
00046 };
00047 
00048 //! getLine2 is an error string getter method
00049 /*!
00050     This method returns the second row of input used in a display
00051     
00052     \return errorStr2 a string containing the second display row 
00053     
00054 */
00055 string ErrorHandler::getLine2(void){
00056     return errorStr2;
00057 };
00058 
00059 
00060 //! setErrorState is a error state setter method.
00061 /*!
00062     Used to set the current errorstate, and changing the display texts accordingly
00063     
00064     \param es The errorstate needed of type ErrorState  
00065 */
00066 void ErrorHandler::setErrorState(ErrorState es){
00067    
00068    this->currentState = es;    
00069     
00070     switch(currentState){
00071         
00072         case(NONE):
00073             errorStr1.assign("        ");
00074             errorStr2.assign("        ");
00075             break;
00076             
00077         case(NO_GPS):
00078             errorStr1.assign("GPS Data");
00079             errorStr2.assign("!Missing");
00080             break;            
00081         
00082         case(NO_FIX):
00083             errorStr1.assign("SetClock");
00084             errorStr2.assign("!on mag ");
00085             
00086             if(magPromptCounter <= 30){
00087                 magPromptCounter += 1;
00088             }
00089             if(magPromptCounter > 30){
00090                 setMagTimePrompted = true;      
00091             }                  
00092             break;
00093         
00094         case(NO_MAG_DATA):
00095             memset(tmparr,'\0',15);
00096             sprintf(tmparr, "%s", gpsPtr->getCurrentTime().c_str());
00097             errorStr1.assign("!MagData");
00098             
00099             if(*fixptr){
00100                 errorStr2.assign(tmparr);
00101             }
00102             if(!(*fixptr)){
00103                 errorStr2.assign("!NoFix  ");
00104             }                     
00105             break;
00106         
00107         case(DISPLAY_VBAT_FIX):
00108             memset(tmparr,'\0',15);
00109             sprintf(tmparr, "VB: %s", *(batteryvoltageptr));
00110             errorStr1.assign(tmparr);
00111             
00112             if(*fixptr){
00113                 errorStr2.assign("FIX: OK ");    
00114             }
00115             
00116             if(!(*fixptr)){
00117                 errorStr2.assign("FIX:NONE");                
00118             }
00119             break;
00120             
00121         case(DISPLAY_MAG_MEASUREMENT):
00122             //memset(tmparr,'\0',15);
00123             errorStr1.assign("BMAG    ");  
00124             //errorStr1[2] = bmagptr->getMagSq()[0];
00125             //errorStr1[3] = bmagptr->getMagSq()[1];
00126             
00127             //sprintf(tmparr, "%s",bmagptr->getMagNTStr().c_str());
00128             errorStr2.assign("Working ");
00129             break;
00130             
00131         case(BATTERY_LOW):
00132             errorStr1.assign("Battery ");
00133             errorStr2.assign("!Low    ");
00134             break;
00135                 
00136         case(GPS_OVERRIDE_NEEDED):
00137             errorStr1.assign("!GPS    ");
00138             errorStr2.assign("Override");
00139             break;
00140         
00141         default:
00142             break;
00143     }    
00144 };
00145 
00146 
00147 //! getMagTimePromtStatus is a prompt status flag getter method
00148 /*!
00149     Returns the status of the setMagTimePrompted flag, indicating if a "please set the clock on bmag" prompt has been shown on display.
00150     
00151     \return setMagTimePrompted A bool indicating if user has been prompted to set time on mag or not.
00152 */
00153 bool ErrorHandler::getMagTimePromtStatus(void){
00154     return this->setMagTimePrompted;  
00155 };
00156 
00157 //! getErrorState is a method returning the current errorstate
00158 /*!
00159     Returns the current errorstate
00160     
00161     \return currentState The current ErrorState
00162 */
00163 ErrorState ErrorHandler::getErrorState(void){
00164   return   this->currentState;
00165 };