Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BLE_API X_NUCLEO_IDB0XA1 MODSERIAL
LOGGER.cpp
00001 #include "LOGGER.h" 00002 #include <stdio.h> 00003 #include <cmath> 00004 #include <cstdlib> 00005 #include "Event.h" 00006 #define BUFFER_LENGTH 32 00007 00008 static event *Ev = event::Instance(); 00009 00010 Logger* Logger::_instance = NULL; 00011 00012 Logger::Logger() 00013 { 00014 serial = new MODSERIAL(SERIAL_TX, SERIAL_RX, BUFFER_LENGTH); //32 bitd long 00015 serial->attach(&rxCallback, MODSERIAL::RxIrq); 00016 buffer_index = 0 ; 00017 buffer = new std::queue<char>; 00018 new_event=false; 00019 event_detected = false; 00020 } 00021 void Logger::rxCallback(MODSERIAL_IRQ_INFO *q) 00022 { 00023 char c =serial->getc(); 00024 if(event_detected) { 00025 if(c != FIN_TRAME) { 00026 if(buffer_index < MAX_SIZE_BUFFER) { 00027 buffer_index++; 00028 buffer.push(c); 00029 } 00030 else { // une erreur c'est produite et ont n'a pas recu la fin du message 00031 flush_buffer(); 00032 log("Logger::rxCallback Erreur dépassement de la taille maximale du buffer sans recevoire la fin de la trame"); 00033 event_detected = false; 00034 } 00035 } 00036 else { 00037 //on a recu la fin de la trame et ont vas reseter et envoyer le message aux gestoinaire d'event 00038 Ev->give_buffer(&buffer); 00039 event_detected = false; 00040 flush_buffer(); 00041 log("Logger::rxCallback On a transferet un buffer au gestionaire d'event aprés reception de signalement de la fin de trame"); 00042 } 00043 } 00044 else { //event hesn't been detected yet 00045 if(c == DEBUT_TRAME ) { 00046 event_detected =true; 00047 log("Logger::rxCallback Debut de trame detecter, ont flush le buffer par precausion "); 00048 flush_buffer(); 00049 } 00050 else { 00051 log("Logger::rxCallback Incoherant message pas de debut de trame detecter, recu : "); 00052 log(c); 00053 } 00054 00055 } 00056 } 00057 00058 Logger* Logger::Instance() 00059 { 00060 if (_instance == NULL) _instance = new Logger(); 00061 return _instance; 00062 } 00063 00064 void Logger::log(std::string s) 00065 { 00066 this->serial->printf((s).c_str()); 00067 this->serial->printf(" "); 00068 } 00069 00070 void Logger::logn(std::string s) 00071 { 00072 this->log((s+"\n\r").c_str()); 00073 } 00074 00075 void Logger::log(double f) 00076 { 00077 this->serial->printf("%f",f); 00078 this->log(""); 00079 } 00080 00081 void Logger::logn(double f) 00082 { 00083 this->log(f); 00084 this->logn(""); 00085 } 00086 00087 void Logger::log(int i) 00088 { 00089 this->serial->printf("%d",i); 00090 this->log(""); 00091 } 00092 00093 void Logger::logn(int i) 00094 { 00095 this->log(i); 00096 this->logn(""); 00097 } 00098 00099 void Logger::log(long i) 00100 { 00101 this->serial->printf("%ld",i); 00102 this->log(""); 00103 } 00104 00105 void Logger::logn(long i) 00106 { 00107 this->log(i); 00108 this->logn(""); 00109 } 00110 string Logger::log_itos(int i) 00111 { 00112 float v= (float) i; 00113 char *c =(char*) malloc(sizeof(char)*((int)log10(v)+1)); 00114 sprintf(c,"%d",i); 00115 return string(c); 00116 } 00117 int Logger::get_buffer_index() 00118 { 00119 return buffer_index; 00120 } 00121 void Logger::flush_buffer() 00122 { 00123 if(buffer_index>0) { 00124 buffer= new std::queue<char>; 00125 buffer_index=0; 00126 } else log("Logger::flush_buffer Erreur le buffer est déjà vide"); 00127 } 00128 }
Generated on Thu Jul 14 2022 17:21:51 by
1.7.2