![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
commit
Dependencies: MPU6050_SIM5320_TEST
Fork of MPU_SDCARD by
DataLogger/DataLogger.cpp@1:75966605a6a3, 2017-11-10 (annotated)
- Committer:
- suads
- Date:
- Fri Nov 10 15:35:26 2017 +0000
- Revision:
- 1:75966605a6a3
mbed cli
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suads | 1:75966605a6a3 | 1 | |
suads | 1:75966605a6a3 | 2 | #include <stdio.h> |
suads | 1:75966605a6a3 | 3 | |
suads | 1:75966605a6a3 | 4 | |
suads | 1:75966605a6a3 | 5 | #include "log.h" |
suads | 1:75966605a6a3 | 6 | #include "DataLogger.h" |
suads | 1:75966605a6a3 | 7 | |
suads | 1:75966605a6a3 | 8 | using namespace std; |
suads | 1:75966605a6a3 | 9 | |
suads | 1:75966605a6a3 | 10 | |
suads | 1:75966605a6a3 | 11 | |
suads | 1:75966605a6a3 | 12 | template<class T> |
suads | 1:75966605a6a3 | 13 | void DataLogger<T>::savelog(T templog) |
suads | 1:75966605a6a3 | 14 | { |
suads | 1:75966605a6a3 | 15 | Log nule(0,0,0,0); |
suads | 1:75966605a6a3 | 16 | uint16_t del=position(); |
suads | 1:75966605a6a3 | 17 | |
suads | 1:75966605a6a3 | 18 | if (_index < (DATASIZE - 1)) { |
suads | 1:75966605a6a3 | 19 | _index++; |
suads | 1:75966605a6a3 | 20 | _datalist[_index] = templog; |
suads | 1:75966605a6a3 | 21 | |
suads | 1:75966605a6a3 | 22 | } |
suads | 1:75966605a6a3 | 23 | else { |
suads | 1:75966605a6a3 | 24 | _index = DATASIZE-del; |
suads | 1:75966605a6a3 | 25 | |
suads | 1:75966605a6a3 | 26 | for (int k = 0; k<(DATASIZE-del) && _index!=-1; k++) |
suads | 1:75966605a6a3 | 27 | _datalist[k]=_datalist[del+k]; |
suads | 1:75966605a6a3 | 28 | |
suads | 1:75966605a6a3 | 29 | for (int k = 0; k<DATASIZE; k++){ |
suads | 1:75966605a6a3 | 30 | if(k>=(DATASIZE-del)) |
suads | 1:75966605a6a3 | 31 | _datalist[k]=nule; |
suads | 1:75966605a6a3 | 32 | } |
suads | 1:75966605a6a3 | 33 | |
suads | 1:75966605a6a3 | 34 | _datalist[DATASIZE-del]=templog; |
suads | 1:75966605a6a3 | 35 | |
suads | 1:75966605a6a3 | 36 | } |
suads | 1:75966605a6a3 | 37 | |
suads | 1:75966605a6a3 | 38 | } |
suads | 1:75966605a6a3 | 39 | |
suads | 1:75966605a6a3 | 40 | template<class T> |
suads | 1:75966605a6a3 | 41 | void DataLogger<T>::print() |
suads | 1:75966605a6a3 | 42 | { |
suads | 1:75966605a6a3 | 43 | //Log *p; |
suads | 1:75966605a6a3 | 44 | //p=getfirst(); |
suads | 1:75966605a6a3 | 45 | //cout<<"dirst"<<(*p).getTime()<<endl; |
suads | 1:75966605a6a3 | 46 | |
suads | 1:75966605a6a3 | 47 | printf("\nPrint\n"); |
suads | 1:75966605a6a3 | 48 | for (int i = 0; i < DATASIZE; i++) { |
suads | 1:75966605a6a3 | 49 | printf("Date %d ", _datalist[i].getDate()); |
suads | 1:75966605a6a3 | 50 | printf("Time %d ", _datalist[i].getTime()); |
suads | 1:75966605a6a3 | 51 | printf("Fsm %d ", _datalist[i].getFsmtype()); |
suads | 1:75966605a6a3 | 52 | printf("Event %d\n", _datalist[i].getEvent()); |
suads | 1:75966605a6a3 | 53 | |
suads | 1:75966605a6a3 | 54 | } |
suads | 1:75966605a6a3 | 55 | } |
suads | 1:75966605a6a3 | 56 | |
suads | 1:75966605a6a3 | 57 | template<class T> |
suads | 1:75966605a6a3 | 58 | uint8_t DataLogger<T>::position() |
suads | 1:75966605a6a3 | 59 | { |
suads | 1:75966605a6a3 | 60 | int k=0; |
suads | 1:75966605a6a3 | 61 | int datum=_datalist[0].getDate(); |
suads | 1:75966605a6a3 | 62 | for (int i = 0; i < DATASIZE; i++) { |
suads | 1:75966605a6a3 | 63 | if(_datalist[i].getDate()==datum) |
suads | 1:75966605a6a3 | 64 | k++; |
suads | 1:75966605a6a3 | 65 | } |
suads | 1:75966605a6a3 | 66 | return k; |
suads | 1:75966605a6a3 | 67 | } |
suads | 1:75966605a6a3 | 68 | |
suads | 1:75966605a6a3 | 69 | |
suads | 1:75966605a6a3 | 70 | |
suads | 1:75966605a6a3 | 71 | |
suads | 1:75966605a6a3 | 72 | template<class T> |
suads | 1:75966605a6a3 | 73 | uint16_t DataLogger<T>::getsize() |
suads | 1:75966605a6a3 | 74 | { |
suads | 1:75966605a6a3 | 75 | |
suads | 1:75966605a6a3 | 76 | return sizeof(_datalist) / 4; |
suads | 1:75966605a6a3 | 77 | } |
suads | 1:75966605a6a3 | 78 | |
suads | 1:75966605a6a3 | 79 | template<class T> |
suads | 1:75966605a6a3 | 80 | T* DataLogger<T>::getfirst(){ |
suads | 1:75966605a6a3 | 81 | |
suads | 1:75966605a6a3 | 82 | return _datalist; |
suads | 1:75966605a6a3 | 83 | |
suads | 1:75966605a6a3 | 84 | } |
suads | 1:75966605a6a3 | 85 | |
suads | 1:75966605a6a3 | 86 | template<class T> |
suads | 1:75966605a6a3 | 87 | T* DataLogger<T>::getlast(){ |
suads | 1:75966605a6a3 | 88 | int i=0; |
suads | 1:75966605a6a3 | 89 | for(i;i<DATASIZE;i++){ |
suads | 1:75966605a6a3 | 90 | if(_datalist[i].getDate()==0) |
suads | 1:75966605a6a3 | 91 | break; |
suads | 1:75966605a6a3 | 92 | |
suads | 1:75966605a6a3 | 93 | } |
suads | 1:75966605a6a3 | 94 | return (_datalist+i-1); |
suads | 1:75966605a6a3 | 95 | } |
suads | 1:75966605a6a3 | 96 | |
suads | 1:75966605a6a3 | 97 | template<class T> |
suads | 1:75966605a6a3 | 98 | uint16_t DataLogger<T>::getnumberOfDays(){ |
suads | 1:75966605a6a3 | 99 | uint16_t countDays=1; |
suads | 1:75966605a6a3 | 100 | Log *p1=getfirst(); |
suads | 1:75966605a6a3 | 101 | Log *p2; |
suads | 1:75966605a6a3 | 102 | p2=getLastStop(); |
suads | 1:75966605a6a3 | 103 | uint16_t currentDate=(*p1).getDate(); |
suads | 1:75966605a6a3 | 104 | |
suads | 1:75966605a6a3 | 105 | if((*p2).getDate()==currentDate && (*p2).getDate()!=0) |
suads | 1:75966605a6a3 | 106 | countDays; |
suads | 1:75966605a6a3 | 107 | |
suads | 1:75966605a6a3 | 108 | // cout<<"last stop "<<(*p1).getTime()<<endl; |
suads | 1:75966605a6a3 | 109 | |
suads | 1:75966605a6a3 | 110 | |
suads | 1:75966605a6a3 | 111 | while(p1!=p2){ |
suads | 1:75966605a6a3 | 112 | // cout<<"d "<<(*p1).getDate()<<endl; |
suads | 1:75966605a6a3 | 113 | if((*p1).getDate() != currentDate){ |
suads | 1:75966605a6a3 | 114 | countDays++; |
suads | 1:75966605a6a3 | 115 | currentDate=(*p1).getDate(); |
suads | 1:75966605a6a3 | 116 | } |
suads | 1:75966605a6a3 | 117 | p1++; |
suads | 1:75966605a6a3 | 118 | } |
suads | 1:75966605a6a3 | 119 | |
suads | 1:75966605a6a3 | 120 | // for(int i=0;i<DATASIZE;i++){ |
suads | 1:75966605a6a3 | 121 | // if(_datalist[i].getDate() != _datalist[i+1].getDate()) |
suads | 1:75966605a6a3 | 122 | // countDays++; |
suads | 1:75966605a6a3 | 123 | |
suads | 1:75966605a6a3 | 124 | // } |
suads | 1:75966605a6a3 | 125 | // cout<<"dani "<<countDays<<endl; |
suads | 1:75966605a6a3 | 126 | |
suads | 1:75966605a6a3 | 127 | return countDays; |
suads | 1:75966605a6a3 | 128 | } |
suads | 1:75966605a6a3 | 129 | |
suads | 1:75966605a6a3 | 130 | |
suads | 1:75966605a6a3 | 131 | template<class T> |
suads | 1:75966605a6a3 | 132 | T* DataLogger<T>::getLastStop(){ |
suads | 1:75966605a6a3 | 133 | |
suads | 1:75966605a6a3 | 134 | //cout<<"getlaststop"<<endl; |
suads | 1:75966605a6a3 | 135 | |
suads | 1:75966605a6a3 | 136 | int i=DATASIZE-1; |
suads | 1:75966605a6a3 | 137 | |
suads | 1:75966605a6a3 | 138 | for(i; i>=0; i--) |
suads | 1:75966605a6a3 | 139 | if (_datalist[i].getDate()!=0 && _datalist[i].getEvent()==0) |
suads | 1:75966605a6a3 | 140 | { |
suads | 1:75966605a6a3 | 141 | //cout<<"i "<<i<<" "<<_datalist[i].getTime()<<"Event "<<_datalist[i].getEvent()<<endl; |
suads | 1:75966605a6a3 | 142 | break; |
suads | 1:75966605a6a3 | 143 | |
suads | 1:75966605a6a3 | 144 | } |
suads | 1:75966605a6a3 | 145 | |
suads | 1:75966605a6a3 | 146 | return (_datalist+i); |
suads | 1:75966605a6a3 | 147 | } |
suads | 1:75966605a6a3 | 148 | |
suads | 1:75966605a6a3 | 149 | |
suads | 1:75966605a6a3 | 150 | |
suads | 1:75966605a6a3 | 151 | |
suads | 1:75966605a6a3 | 152 | |
suads | 1:75966605a6a3 | 153 | template class DataLogger<Log>; |
suads | 1:75966605a6a3 | 154 | |
suads | 1:75966605a6a3 | 155 |