jhuh

Dependents:   robot_final

Bluetooth_HC05_LE_TRAME.cpp

Committer:
aure
Date:
2017-03-15
Revision:
0:092ac281a013
Child:
1:7cc085e87bb0

File content as of revision 0:092ac281a013:

#include "Bluetooth_HC05_LE_TRAME.h"
#include "mbed.h"
#include "m3pi.h"

//#define BAUDS 38400
#define BAUDS 9600           //constante bauds 9600
#define nb_caractere_max 10
#define TX p13
#define RX p14

m3pi mmm;

Serial seriale(TX,RX,MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);


Bluetooth_HC05_LE_TRAME::Bluetooth_HC05_LE_TRAME()
{
   
   seriale.baud(BAUDS);
    seriale.format(8,SerialBase::None,1);
    this->flush='t';   
    this->resetBuffer();
    
}
Bluetooth_HC05_LE_TRAME::~Bluetooth_HC05_LE_TRAME()
{
        
        
}
    
void Bluetooth_HC05_LE_TRAME::envoyer(char* envoi)
{
         seriale.puts(envoi);
         wait(1);
}
         
char* Bluetooth_HC05_LE_TRAME::recevoir(int longueur)          //1 ere tentative
{
         char* recu=NULL;
         
         if (seriale.readable()) {
       
         
                int i=0;
                 int compteur=0;
                 char buffer[20];
                
                 ///////////////////////////////////////////////OK rematrre apres
               while(seriale.readable()==1)
                {
                      for(i=0;i<longueur;i++)
                    {
                     buffer[compteur]=seriale.getc();
                      compteur++;
                    }
                }
                
                char buffer_copie[compteur];
                
                for(i=0;i<compteur;i++)
                buffer_copie[i]=buffer[i];
                
                //recu=buffer;
                
                strcpy(recu,buffer_copie);
                
               
                  }
                  else
                  {
                      recu="0";
                }    
                  this->resetBuffer();
                  
                 return(recu); 
                 
                        
}

/////////////////////////////////

void Bluetooth_HC05_LE_TRAME::resetBuffer()
{
    while(seriale.readable())
    {
    this->flush = seriale.getc();  
    }
    
}