init

Dependencies:   MPU6050 PinDetect circular_buffer

Committer:
OsmanKameric
Date:
Tue Nov 07 16:35:14 2017 +0000
Revision:
0:b416214256cd
FIRST

Who changed what in which revision?

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