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
COM/LOGGER.cpp
- Committer:
- Essenceia
- Date:
- 2016-08-18
- Revision:
- 2:ca6d8d1f77d4
- Parent:
- 1:8bab9152933e
- Child:
- 3:13bd725bd47b
File content as of revision 2:ca6d8d1f77d4:
#include "LOGGER.h"
#include <stdio.h>
#include <cmath>
#include <cstdlib>
#define BUFFER_LENGTH 32
Logger* Logger::_instance = NULL;
Logger::Logger() {
serial = new MODSERIAL(SERIAL_TX, SERIAL_RX, BUFFER_LENGTH); //32 bitd long
serial->attach(&rxCallback, MODSERIAL::RxIrq);
buffer_index = 0 ;
buffer = new std::queue<char>;
}
void Logger::rxCallback(MODSERIAL_IRQ_INFO *q) {
char c =serial->getc();
if(c>='0'&&c<='9')
{
if(buffer_index < 32 )
else{ buffer_index = 0;
buffer= new std::queue<char>;
}
// il nous reste de la place dans le buffer
buffer_index++;
buffer.push(c);
}
}
}
Logger* Logger::Instance() {
if (_instance == NULL) _instance = new Logger();
return _instance;
}
void Logger::log(std::string s) {
this->serial->printf((s).c_str());
this->serial->printf(" ");
}
void Logger::logn(std::string s){
this->log((s+"\n\r").c_str());
}
void Logger::log(double f) {
this->serial->printf("%f",f);
this->log("");
}
void Logger::logn(double f){
this->log(f);
this->logn("");
}
void Logger::log(int i) {
this->serial->printf("%d",i);
this->log("");
}
void Logger::logn(int i){
this->log(i);
this->logn("");
}
void Logger::log(long i) {
this->serial->printf("%ld",i);
this->log("");
}
void Logger::logn(long i){
this->log(i);
this->logn("");
}
string Logger::log_itos(int i)
{
float v= (float) i;
char *c =(char*) malloc(sizeof(char)*((int)log10(v)+1));
sprintf(c,"%d",i);
return string(c);
}
int Logger::get_buffer_index()
{return buffer_index;
}
void Logger::flush_buffer()
{
if(buffer_index>0)
{
buffer= new std::queue<char>;
buffer_index=0;
}
else log("Logger::flush_buffer Erreur le buffer est déjà vide");
}
}