![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
commit
Dependencies: MPU6050_SIM5320_TEST
Fork of MPU_SDCARD by
DataLogger/DataLogger.cpp
- Committer:
- suads
- Date:
- 2017-11-10
- Revision:
- 1:75966605a6a3
File content as of revision 1:75966605a6a3:
#include <stdio.h> #include "log.h" #include "DataLogger.h" using namespace std; template<class T> void DataLogger<T>::savelog(T templog) { Log nule(0,0,0,0); uint16_t del=position(); if (_index < (DATASIZE - 1)) { _index++; _datalist[_index] = templog; } else { _index = DATASIZE-del; for (int k = 0; k<(DATASIZE-del) && _index!=-1; k++) _datalist[k]=_datalist[del+k]; for (int k = 0; k<DATASIZE; k++){ if(k>=(DATASIZE-del)) _datalist[k]=nule; } _datalist[DATASIZE-del]=templog; } } template<class T> void DataLogger<T>::print() { //Log *p; //p=getfirst(); //cout<<"dirst"<<(*p).getTime()<<endl; printf("\nPrint\n"); for (int i = 0; i < DATASIZE; i++) { printf("Date %d ", _datalist[i].getDate()); printf("Time %d ", _datalist[i].getTime()); printf("Fsm %d ", _datalist[i].getFsmtype()); printf("Event %d\n", _datalist[i].getEvent()); } } template<class T> uint8_t DataLogger<T>::position() { int k=0; int datum=_datalist[0].getDate(); for (int i = 0; i < DATASIZE; i++) { if(_datalist[i].getDate()==datum) k++; } return k; } template<class T> uint16_t DataLogger<T>::getsize() { return sizeof(_datalist) / 4; } template<class T> T* DataLogger<T>::getfirst(){ return _datalist; } template<class T> T* DataLogger<T>::getlast(){ int i=0; for(i;i<DATASIZE;i++){ if(_datalist[i].getDate()==0) break; } return (_datalist+i-1); } template<class T> uint16_t DataLogger<T>::getnumberOfDays(){ uint16_t countDays=1; Log *p1=getfirst(); Log *p2; p2=getLastStop(); uint16_t currentDate=(*p1).getDate(); if((*p2).getDate()==currentDate && (*p2).getDate()!=0) countDays; // cout<<"last stop "<<(*p1).getTime()<<endl; while(p1!=p2){ // cout<<"d "<<(*p1).getDate()<<endl; if((*p1).getDate() != currentDate){ countDays++; currentDate=(*p1).getDate(); } p1++; } // for(int i=0;i<DATASIZE;i++){ // if(_datalist[i].getDate() != _datalist[i+1].getDate()) // countDays++; // } // cout<<"dani "<<countDays<<endl; return countDays; } template<class T> T* DataLogger<T>::getLastStop(){ //cout<<"getlaststop"<<endl; int i=DATASIZE-1; for(i; i>=0; i--) if (_datalist[i].getDate()!=0 && _datalist[i].getEvent()==0) { //cout<<"i "<<i<<" "<<_datalist[i].getTime()<<"Event "<<_datalist[i].getEvent()<<endl; break; } return (_datalist+i); } template class DataLogger<Log>;