Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

BMAG/BMAG.cpp

Committer:
MAA
Date:
2017-03-23
Revision:
8:d6287c33b54a
Child:
14:400ecb93c6a2

File content as of revision 8:d6287c33b54a:

#include "BMAG.h"

BMAG::BMAG(){
    lastMagTime.resize(25);
    lastMagNT.resize(25);
    lastMagSq.resize(25);    
    
};

void BMAG::parseBMAGString(string str){
    string tmpmagStr = "";
    
    //get first mag string column
    tmpmagStr.assign(getColumn(str, 0));
    

    setMagTimeStr(tmpmagStr);
    tmpmagStr = ""; 
    
    //get second mag string column
    tmpmagStr.assign(getColumn(str, 1)); 
    setMagNTStr(tmpmagStr);
    
    tmpmagStr = ""; 
    
     //get third mag string column
    tmpmagStr.assign(getColumn(str, 2));        
    
    setMagSqStr(tmpmagStr);
    
    
};

void BMAG::setMagTimeStr(string magT){
    lastMagTime.assign(magT);  
};


void BMAG::setMagNTStr(string magNT){
    lastMagNT.assign(magNT);  
};


void BMAG::setMagSqStr(string magSq){
    lastMagSq.assign(magSq);  
};

 
string BMAG::getMagTimeStr(void){
    return lastMagTime;     
};

string BMAG::getMagNTStr(void){
    return lastMagNT;
};

string BMAG::getMagSq(void){
    return lastMagSq;  
};

string BMAG::getColumn(string str, char n){
    
    char count = 0;
    string tmpStr = "";
    tmpStr.resize(40);
    char indexcnt = 0;
    
    
    for(int i = 0; i < str.size(); i++){
        if(count == n && (str[i] != '\r') || count == n && (str[i] != '\n')){
            tmpStr[indexcnt] = str[i];
            indexcnt += 1;    
        }
        
        if(str[i] == '\r' || str[i] == ' '){
            count += 1;    
        }
        
        if(count > n){
            break;    
        }        
    }
    
    return tmpStr;
        
};