![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
commit
Dependencies: MPU6050_SIM5320_TEST
Fork of MPU_SDCARD by
Log/log.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 | #include <stdio.h> |
suads | 1:75966605a6a3 | 2 | #include <stdlib.h> |
suads | 1:75966605a6a3 | 3 | #include <stdint.h> |
suads | 1:75966605a6a3 | 4 | |
suads | 1:75966605a6a3 | 5 | // #include <string> |
suads | 1:75966605a6a3 | 6 | // #include <typeinfo> |
suads | 1:75966605a6a3 | 7 | |
suads | 1:75966605a6a3 | 8 | #include "log.h" |
suads | 1:75966605a6a3 | 9 | |
suads | 1:75966605a6a3 | 10 | Log::Log(uint16_t ttime, uint8_t fsmtype, uint8_t event,uint16_t date) |
suads | 1:75966605a6a3 | 11 | { |
suads | 1:75966605a6a3 | 12 | uint16_t h=ttime/100; |
suads | 1:75966605a6a3 | 13 | uint16_t m=ttime%100; |
suads | 1:75966605a6a3 | 14 | uint16_t data=fsmtype<<12|event<<11; |
suads | 1:75966605a6a3 | 15 | h=h<<6; |
suads | 1:75966605a6a3 | 16 | _date=date; |
suads | 1:75966605a6a3 | 17 | _data=data|h|m; |
suads | 1:75966605a6a3 | 18 | } |
suads | 1:75966605a6a3 | 19 | |
suads | 1:75966605a6a3 | 20 | Log::Log(){_data=0;} |
suads | 1:75966605a6a3 | 21 | |
suads | 1:75966605a6a3 | 22 | uint16_t Log::getsize() |
suads | 1:75966605a6a3 | 23 | { |
suads | 1:75966605a6a3 | 24 | return sizeof(_data); |
suads | 1:75966605a6a3 | 25 | } |
suads | 1:75966605a6a3 | 26 | uint16_t Log::getDate() const |
suads | 1:75966605a6a3 | 27 | { |
suads | 1:75966605a6a3 | 28 | return _date; |
suads | 1:75966605a6a3 | 29 | } |
suads | 1:75966605a6a3 | 30 | |
suads | 1:75966605a6a3 | 31 | bool Log::getFsmtype() const |
suads | 1:75966605a6a3 | 32 | { |
suads | 1:75966605a6a3 | 33 | return (_data & (1 << 12))!=0; |
suads | 1:75966605a6a3 | 34 | } |
suads | 1:75966605a6a3 | 35 | |
suads | 1:75966605a6a3 | 36 | bool Log::getEvent() const |
suads | 1:75966605a6a3 | 37 | { |
suads | 1:75966605a6a3 | 38 | return (_data & (1 << 11))!=0; |
suads | 1:75966605a6a3 | 39 | } |
suads | 1:75966605a6a3 | 40 | |
suads | 1:75966605a6a3 | 41 | uint16_t Log::getTime() const |
suads | 1:75966605a6a3 | 42 | { |
suads | 1:75966605a6a3 | 43 | char temp[6]; |
suads | 1:75966605a6a3 | 44 | //string z; |
suads | 1:75966605a6a3 | 45 | uint16_t x = (_data & 0x7c0)>>6; |
suads | 1:75966605a6a3 | 46 | uint16_t y = (_data & 0x3F); |
suads | 1:75966605a6a3 | 47 | //cout<<x<<" "<<y<<endl; |
suads | 1:75966605a6a3 | 48 | if(y<=9) |
suads | 1:75966605a6a3 | 49 | sprintf(temp, "%d0%d", x,y); |
suads | 1:75966605a6a3 | 50 | //z=to_string(x)+"0"+to_string(y); |
suads | 1:75966605a6a3 | 51 | else |
suads | 1:75966605a6a3 | 52 | sprintf(temp, "%d%d", x,y); |
suads | 1:75966605a6a3 | 53 | //z =to_string(x)+to_string(y); |
suads | 1:75966605a6a3 | 54 | temp[6]='\0'; |
suads | 1:75966605a6a3 | 55 | //std::string z(temp); |
suads | 1:75966605a6a3 | 56 | //cout<<"temp "<<temp<<endl; |
suads | 1:75966605a6a3 | 57 | return atoi(temp); |
suads | 1:75966605a6a3 | 58 | } |
suads | 1:75966605a6a3 | 59 | |
suads | 1:75966605a6a3 | 60 | Log& Log::operator =(const Log &a){ // b.operator=(a); |
suads | 1:75966605a6a3 | 61 | |
suads | 1:75966605a6a3 | 62 | uint16_t date=a.getDate(); |
suads | 1:75966605a6a3 | 63 | _date=date; |
suads | 1:75966605a6a3 | 64 | uint16_t h=a.getTime()/100; |
suads | 1:75966605a6a3 | 65 | uint16_t m=a.getTime()%100; |
suads | 1:75966605a6a3 | 66 | uint16_t data=((a.getFsmtype())<<12)|((a.getEvent())<<11); |
suads | 1:75966605a6a3 | 67 | h=h<<6; |
suads | 1:75966605a6a3 | 68 | _data=data|h|m; |
suads | 1:75966605a6a3 | 69 | return *this; |
suads | 1:75966605a6a3 | 70 | } |
suads | 1:75966605a6a3 | 71 | |
suads | 1:75966605a6a3 | 72 | void Log::setLog(uint16_t ttime, uint8_t fsmtype, uint8_t event,uint16_t date) |
suads | 1:75966605a6a3 | 73 | { |
suads | 1:75966605a6a3 | 74 | uint16_t h=ttime/100; |
suads | 1:75966605a6a3 | 75 | uint16_t m=ttime%100; |
suads | 1:75966605a6a3 | 76 | uint16_t data=fsmtype<<12|event<<11; |
suads | 1:75966605a6a3 | 77 | h=h<<6; |
suads | 1:75966605a6a3 | 78 | _data=data|h|m; |
suads | 1:75966605a6a3 | 79 | _date=date; |
suads | 1:75966605a6a3 | 80 | } |
suads | 1:75966605a6a3 | 81 |