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.
quick_queue.cpp@10:c4629b6c42f8, 2017-10-15 (annotated)
- Committer:
- Cheroukee
- Date:
- Sun Oct 15 23:13:18 2017 +0000
- Revision:
- 10:c4629b6c42f8
- Child:
- 11:1d277e7e272d
Added quick queue module, fixed data reception to fill in message structure
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Cheroukee | 10:c4629b6c42f8 | 1 | |
| Cheroukee | 10:c4629b6c42f8 | 2 | #include "quick_queue.h" |
| Cheroukee | 10:c4629b6c42f8 | 3 | #include "mbed.h" |
| Cheroukee | 10:c4629b6c42f8 | 4 | |
| Cheroukee | 10:c4629b6c42f8 | 5 | radio_message_t out_messages[MESSAGE_BUFFER_SIZE];// = { 0, 0, 0, 0, "0", 0, 0}; |
| Cheroukee | 10:c4629b6c42f8 | 6 | int out_output_index = 0; |
| Cheroukee | 10:c4629b6c42f8 | 7 | int out_input_index = 0; |
| Cheroukee | 10:c4629b6c42f8 | 8 | |
| Cheroukee | 10:c4629b6c42f8 | 9 | radio_message_t in_messages[MESSAGE_BUFFER_SIZE];// = { 0, 0, 0, 0, "0", 0, 0}; |
| Cheroukee | 10:c4629b6c42f8 | 10 | int in_output_index = 0; |
| Cheroukee | 10:c4629b6c42f8 | 11 | int in_input_index = 0; |
| Cheroukee | 10:c4629b6c42f8 | 12 | |
| Cheroukee | 10:c4629b6c42f8 | 13 | // Utilise pour aller chercher une pointeur vers un message a remplir pour l'envoi |
| Cheroukee | 10:c4629b6c42f8 | 14 | radio_message_t* get_new_out_message(){ |
| Cheroukee | 10:c4629b6c42f8 | 15 | if ((out_input_index + 1) % MESSAGE_BUFFER_SIZE != out_output_index) |
| Cheroukee | 10:c4629b6c42f8 | 16 | { |
| Cheroukee | 10:c4629b6c42f8 | 17 | return &(out_messages[(out_input_index + 1) % MESSAGE_BUFFER_SIZE]); |
| Cheroukee | 10:c4629b6c42f8 | 18 | //return true; |
| Cheroukee | 10:c4629b6c42f8 | 19 | } |
| Cheroukee | 10:c4629b6c42f8 | 20 | return NULL; |
| Cheroukee | 10:c4629b6c42f8 | 21 | } |
| Cheroukee | 10:c4629b6c42f8 | 22 | |
| Cheroukee | 10:c4629b6c42f8 | 23 | // Inique que le message courant est pret a etre envouye |
| Cheroukee | 10:c4629b6c42f8 | 24 | bool new_out_message_ready(){ |
| Cheroukee | 10:c4629b6c42f8 | 25 | if ((out_input_index + 1) % MESSAGE_BUFFER_SIZE != out_output_index) |
| Cheroukee | 10:c4629b6c42f8 | 26 | { |
| Cheroukee | 10:c4629b6c42f8 | 27 | out_input_index = (out_input_index + 1) % MESSAGE_BUFFER_SIZE; |
| Cheroukee | 10:c4629b6c42f8 | 28 | return true; |
| Cheroukee | 10:c4629b6c42f8 | 29 | } |
| Cheroukee | 10:c4629b6c42f8 | 30 | return false; |
| Cheroukee | 10:c4629b6c42f8 | 31 | } |
| Cheroukee | 10:c4629b6c42f8 | 32 | |
| Cheroukee | 10:c4629b6c42f8 | 33 | // Utilise pour aller chercher le plus vieux message en sortie |
| Cheroukee | 10:c4629b6c42f8 | 34 | radio_message_t* get_last_out_message(){ |
| Cheroukee | 10:c4629b6c42f8 | 35 | if (out_output_index != out_input_index) |
| Cheroukee | 10:c4629b6c42f8 | 36 | { |
| Cheroukee | 10:c4629b6c42f8 | 37 | return &(out_messages[(out_output_index + 1) % MESSAGE_BUFFER_SIZE]); |
| Cheroukee | 10:c4629b6c42f8 | 38 | //return true; |
| Cheroukee | 10:c4629b6c42f8 | 39 | } |
| Cheroukee | 10:c4629b6c42f8 | 40 | return NULL; |
| Cheroukee | 10:c4629b6c42f8 | 41 | } |
| Cheroukee | 10:c4629b6c42f8 | 42 | |
| Cheroukee | 10:c4629b6c42f8 | 43 | // Indique que le message a ete envoye |
| Cheroukee | 10:c4629b6c42f8 | 44 | bool last_out_message_read(){ |
| Cheroukee | 10:c4629b6c42f8 | 45 | if (out_output_index != out_input_index) |
| Cheroukee | 10:c4629b6c42f8 | 46 | { |
| Cheroukee | 10:c4629b6c42f8 | 47 | out_output_index = (out_output_index + 1) % MESSAGE_BUFFER_SIZE; |
| Cheroukee | 10:c4629b6c42f8 | 48 | return true; |
| Cheroukee | 10:c4629b6c42f8 | 49 | } |
| Cheroukee | 10:c4629b6c42f8 | 50 | return false; |
| Cheroukee | 10:c4629b6c42f8 | 51 | } |
| Cheroukee | 10:c4629b6c42f8 | 52 | |
| Cheroukee | 10:c4629b6c42f8 | 53 | // Utilise pour aller recuperer un nouveau message a remplir pour la reception |
| Cheroukee | 10:c4629b6c42f8 | 54 | radio_message_t* get_new_in_message(){ |
| Cheroukee | 10:c4629b6c42f8 | 55 | if ((in_input_index + 1) % MESSAGE_BUFFER_SIZE != in_output_index) |
| Cheroukee | 10:c4629b6c42f8 | 56 | { |
| Cheroukee | 10:c4629b6c42f8 | 57 | return &(in_messages[(in_input_index + 1) % MESSAGE_BUFFER_SIZE]); |
| Cheroukee | 10:c4629b6c42f8 | 58 | //return true; |
| Cheroukee | 10:c4629b6c42f8 | 59 | } |
| Cheroukee | 10:c4629b6c42f8 | 60 | return NULL; |
| Cheroukee | 10:c4629b6c42f8 | 61 | } |
| Cheroukee | 10:c4629b6c42f8 | 62 | |
| Cheroukee | 10:c4629b6c42f8 | 63 | // Indique qu'un nouveau message est pret en entree |
| Cheroukee | 10:c4629b6c42f8 | 64 | bool new_in_message_ready(){ |
| Cheroukee | 10:c4629b6c42f8 | 65 | if ((in_input_index + 1) % MESSAGE_BUFFER_SIZE != in_output_index) |
| Cheroukee | 10:c4629b6c42f8 | 66 | { |
| Cheroukee | 10:c4629b6c42f8 | 67 | in_input_index = (in_input_index + 1) % MESSAGE_BUFFER_SIZE; |
| Cheroukee | 10:c4629b6c42f8 | 68 | return true; |
| Cheroukee | 10:c4629b6c42f8 | 69 | } |
| Cheroukee | 10:c4629b6c42f8 | 70 | return false; |
| Cheroukee | 10:c4629b6c42f8 | 71 | } |
| Cheroukee | 10:c4629b6c42f8 | 72 | |
| Cheroukee | 10:c4629b6c42f8 | 73 | // Utilise pour aller chercher le dernier message pret |
| Cheroukee | 10:c4629b6c42f8 | 74 | radio_message_t* get_last_in_message(){ |
| Cheroukee | 10:c4629b6c42f8 | 75 | if (in_output_index != in_input_index) |
| Cheroukee | 10:c4629b6c42f8 | 76 | { |
| Cheroukee | 10:c4629b6c42f8 | 77 | return &(in_messages[(in_output_index + 1) % MESSAGE_BUFFER_SIZE]); |
| Cheroukee | 10:c4629b6c42f8 | 78 | //return true; |
| Cheroukee | 10:c4629b6c42f8 | 79 | } |
| Cheroukee | 10:c4629b6c42f8 | 80 | return NULL; |
| Cheroukee | 10:c4629b6c42f8 | 81 | } |
| Cheroukee | 10:c4629b6c42f8 | 82 | |
| Cheroukee | 10:c4629b6c42f8 | 83 | // Indique que le dernier message a bien ete lu |
| Cheroukee | 10:c4629b6c42f8 | 84 | bool last_in_message_read(){ |
| Cheroukee | 10:c4629b6c42f8 | 85 | if (in_output_index != in_input_index) |
| Cheroukee | 10:c4629b6c42f8 | 86 | { |
| Cheroukee | 10:c4629b6c42f8 | 87 | in_output_index = (in_output_index + 1) % MESSAGE_BUFFER_SIZE; |
| Cheroukee | 10:c4629b6c42f8 | 88 | return true; |
| Cheroukee | 10:c4629b6c42f8 | 89 | } |
| Cheroukee | 10:c4629b6c42f8 | 90 | return false; |
| Cheroukee | 10:c4629b6c42f8 | 91 | } |