APP4 S5

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers quick_queue.cpp Source File

quick_queue.cpp

00001 
00002 #include "quick_queue.h"
00003 #include "mbed.h"
00004 
00005 radio_message_t out_messages[MESSAGE_BUFFER_SIZE];// = { 0, 0, 0, 0, "0", 0, 0};
00006 int out_output_index = 0;
00007 int out_input_index = 0;
00008 
00009 radio_message_t in_messages[MESSAGE_BUFFER_SIZE];// =  { 0, 0, 0, 0, "0", 0, 0};
00010 int in_output_index = 0;
00011 int in_input_index = 0;
00012 
00013 // Utilise pour aller chercher une pointeur vers un message a remplir pour l'envoi
00014 radio_message_t* get_new_out_message(){
00015     if (((out_input_index + 1) % MESSAGE_BUFFER_SIZE) != out_output_index) 
00016     {
00017         return &(out_messages[(out_input_index + 1) % MESSAGE_BUFFER_SIZE]);
00018         //return true;
00019     }
00020     return NULL;
00021 }
00022 
00023 // Inique que le message courant est pret a etre envouye
00024 bool new_out_message_ready(){
00025     if (((out_input_index + 1) % MESSAGE_BUFFER_SIZE) != out_output_index) 
00026     {
00027         out_input_index = (out_input_index + 1) %  MESSAGE_BUFFER_SIZE;
00028         return true;
00029     }
00030     return false;
00031 }
00032 
00033 // Utilise pour aller chercher le plus vieux message en sortie
00034 radio_message_t* get_last_out_message(){
00035     if (out_output_index != out_input_index) 
00036     {
00037         return &(out_messages[(out_output_index + 1) % MESSAGE_BUFFER_SIZE]);
00038         //return true;
00039     }
00040     return NULL;
00041 }
00042 
00043 // Indique que le message a ete envoye
00044 bool last_out_message_read(){
00045     if (out_output_index != out_input_index) 
00046     {
00047         out_output_index = (out_output_index + 1) % MESSAGE_BUFFER_SIZE;
00048         for (int i = 0; i < MAX_MESSAGE_LENGTH; i++)
00049         {
00050             out_messages[out_output_index].data[i] = 0;
00051         }
00052         return true;
00053     }
00054     return false;
00055 }
00056 
00057 // Utilise pour aller recuperer un nouveau message a remplir pour la reception
00058 radio_message_t* get_new_in_message(){
00059     if (((in_input_index + 1) % MESSAGE_BUFFER_SIZE) != in_output_index) 
00060     {
00061         return &(in_messages[(in_input_index + 1) % MESSAGE_BUFFER_SIZE]);
00062         //return true;
00063     }
00064     return NULL;
00065 }
00066 
00067 // Indique qu'un nouveau message est pret en entree
00068 bool new_in_message_ready(){
00069     if (((in_input_index + 1) % MESSAGE_BUFFER_SIZE) != in_output_index) 
00070     {
00071         in_input_index = (in_input_index + 1) %  MESSAGE_BUFFER_SIZE;
00072         return true;
00073     }
00074     return false;
00075 }
00076 
00077 // Utilise pour aller chercher le dernier message pret
00078 radio_message_t* get_last_in_message(){
00079     if (in_output_index != in_input_index) 
00080     {
00081         return &(in_messages[(in_output_index + 1) % MESSAGE_BUFFER_SIZE]);
00082         //return true;
00083     }
00084     return NULL;
00085 }
00086 
00087 // Indique que le dernier message a bien ete lu
00088 bool last_in_message_read(){
00089     if (in_output_index != in_input_index) 
00090     {
00091         in_output_index = (in_output_index + 1) % MESSAGE_BUFFER_SIZE;
00092         for (int i = 0; i < MAX_MESSAGE_LENGTH; i++)
00093         {
00094             in_messages[in_output_index].data[i] = 0;
00095         }
00096         return true;
00097     }
00098     return false;
00099 }
00100 
00101 
00102 int get_input_out_index()
00103 {
00104     return in_output_index;
00105 }
00106 
00107 int get_input_in_index()
00108 {
00109     return in_input_index;
00110 }