char inByte = 0; // incoming serial byte const int rtsPin = 16; const int ctsPin = 17; #include char ChaineEmission[]="\r\nLe caractere envoye est "; #define FIFOSIZE 32 char FifoBuffer[FIFOSIZE]; //////////////////////////////////////////// struct charFifo{ char * data ; unsigned int fifo_size ; unsigned int write_index ; unsigned int read_index ; unsigned int nb_token_available ; }; struct charFifo myFifo; // la variable FIFO à utiliser //////////////////////////////////////////// void char_fifo_init(struct charFifo * pf, char * buf, unsigned int f_size){ pf -> data = buf ; pf -> fifo_size = f_size ; pf -> write_index = 0 ; pf -> read_index = 0 ; pf -> nb_token_available = 0 ; } //////////////////////////////////////////// char write_char_fifo(struct charFifo * pf, const char token){ if(pf->nb_token_available >= pf->fifo_size) return 0 ; pf->data[pf->write_index] = token ; pf->write_index = pf->write_index + 1; if(pf->write_index >= pf->fifo_size) pf->write_index = 0 ; pf->nb_token_available = pf->nb_token_available + 1 ; return 1 ; } //////////////////////////////////////////// char read_char_fifo(struct charFifo * pf, char * ptr_token){ if(pf->nb_token_available == 0) return 0; *ptr_token = pf->data[pf->read_index] ; pf->read_index = pf->read_index + 1; if(pf->read_index >= pf->fifo_size) pf->read_index = 0 ; pf->nb_token_available = pf->nb_token_available -1 ; return 1 ; } //////////////////////////////////////////// char peek_char_fifo(struct charFifo * pf, char * ptr_token){ if(pf->nb_token_available == 0) return 0 ; *ptr_token = pf->data[pf->read_index] ; return 1 ; } //////////////////////////////////////////// SoftwareSerial mySerial(5, 6); // uart soft avec les broches RX,TX // http://arduino.cc/en/Reference/softwareSerial //////////////////////////////////////////// void setup() { pinMode(rtsPin, OUTPUT); pinMode(ctsPin, INPUT); Serial.begin(115200); // start serial port at 115200 bps: Serial.print("Bonjour"); mySerial.begin(1200); // set the data rate for the SoftwareSerial port mySerial.println("Hello, world?"); char_fifo_init(&myFifo,FifoBuffer, FIFOSIZE); //initialisation de la FIFO digitalWrite(rtsPin, 1); //éteind la led RTS } //////////////////////////////////////////// void RemplirFifo(char c) { //écrire tous les caractères de la chaine ChaineEmission + le caractère c et mettre RTS à 0 si débordement de la FIFO //à implémenter } //////////////////////////////////////////// void loop() { int i; //réception du nouveau caractère if (Serial.available() != 0) { //à compléter } //vidage de la FIFO if(read_char_fifo(&myFifo,&inByte)==1) { //à compléter } }