APP4 S5

Dependencies:   mbed-rtos mbed

Committer:
Cheroukee
Date:
Sun Oct 22 20:20:42 2017 +0000
Revision:
13:b44c1f678aff
Parent:
12:e21604b50719
Needs testing, added CRC calculations and adapted queue code to work with radio

Who changed what in which revision?

UserRevisionLine numberNew 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 12:e21604b50719 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 12:e21604b50719 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 11:1d277e7e272d 48 for (int i = 0; i < MAX_MESSAGE_LENGTH; i++)
Cheroukee 11:1d277e7e272d 49 {
Cheroukee 11:1d277e7e272d 50 out_messages[out_output_index].data[i] = 0;
Cheroukee 11:1d277e7e272d 51 }
Cheroukee 10:c4629b6c42f8 52 return true;
Cheroukee 10:c4629b6c42f8 53 }
Cheroukee 10:c4629b6c42f8 54 return false;
Cheroukee 10:c4629b6c42f8 55 }
Cheroukee 10:c4629b6c42f8 56
Cheroukee 10:c4629b6c42f8 57 // Utilise pour aller recuperer un nouveau message a remplir pour la reception
Cheroukee 10:c4629b6c42f8 58 radio_message_t* get_new_in_message(){
Cheroukee 12:e21604b50719 59 if (((in_input_index + 1) % MESSAGE_BUFFER_SIZE) != in_output_index)
Cheroukee 10:c4629b6c42f8 60 {
Cheroukee 10:c4629b6c42f8 61 return &(in_messages[(in_input_index + 1) % MESSAGE_BUFFER_SIZE]);
Cheroukee 10:c4629b6c42f8 62 //return true;
Cheroukee 10:c4629b6c42f8 63 }
Cheroukee 10:c4629b6c42f8 64 return NULL;
Cheroukee 10:c4629b6c42f8 65 }
Cheroukee 10:c4629b6c42f8 66
Cheroukee 10:c4629b6c42f8 67 // Indique qu'un nouveau message est pret en entree
Cheroukee 10:c4629b6c42f8 68 bool new_in_message_ready(){
Cheroukee 12:e21604b50719 69 if (((in_input_index + 1) % MESSAGE_BUFFER_SIZE) != in_output_index)
Cheroukee 10:c4629b6c42f8 70 {
Cheroukee 10:c4629b6c42f8 71 in_input_index = (in_input_index + 1) % MESSAGE_BUFFER_SIZE;
Cheroukee 10:c4629b6c42f8 72 return true;
Cheroukee 10:c4629b6c42f8 73 }
Cheroukee 10:c4629b6c42f8 74 return false;
Cheroukee 10:c4629b6c42f8 75 }
Cheroukee 10:c4629b6c42f8 76
Cheroukee 10:c4629b6c42f8 77 // Utilise pour aller chercher le dernier message pret
Cheroukee 10:c4629b6c42f8 78 radio_message_t* get_last_in_message(){
Cheroukee 10:c4629b6c42f8 79 if (in_output_index != in_input_index)
Cheroukee 10:c4629b6c42f8 80 {
Cheroukee 10:c4629b6c42f8 81 return &(in_messages[(in_output_index + 1) % MESSAGE_BUFFER_SIZE]);
Cheroukee 10:c4629b6c42f8 82 //return true;
Cheroukee 10:c4629b6c42f8 83 }
Cheroukee 10:c4629b6c42f8 84 return NULL;
Cheroukee 10:c4629b6c42f8 85 }
Cheroukee 10:c4629b6c42f8 86
Cheroukee 10:c4629b6c42f8 87 // Indique que le dernier message a bien ete lu
Cheroukee 10:c4629b6c42f8 88 bool last_in_message_read(){
Cheroukee 10:c4629b6c42f8 89 if (in_output_index != in_input_index)
Cheroukee 10:c4629b6c42f8 90 {
Cheroukee 10:c4629b6c42f8 91 in_output_index = (in_output_index + 1) % MESSAGE_BUFFER_SIZE;
Cheroukee 11:1d277e7e272d 92 for (int i = 0; i < MAX_MESSAGE_LENGTH; i++)
Cheroukee 11:1d277e7e272d 93 {
Cheroukee 11:1d277e7e272d 94 in_messages[in_output_index].data[i] = 0;
Cheroukee 11:1d277e7e272d 95 }
Cheroukee 10:c4629b6c42f8 96 return true;
Cheroukee 10:c4629b6c42f8 97 }
Cheroukee 10:c4629b6c42f8 98 return false;
Cheroukee 12:e21604b50719 99 }
Cheroukee 12:e21604b50719 100
Cheroukee 12:e21604b50719 101
Cheroukee 12:e21604b50719 102 int get_input_out_index()
Cheroukee 12:e21604b50719 103 {
Cheroukee 12:e21604b50719 104 return in_output_index;
Cheroukee 12:e21604b50719 105 }
Cheroukee 12:e21604b50719 106
Cheroukee 12:e21604b50719 107 int get_input_in_index()
Cheroukee 12:e21604b50719 108 {
Cheroukee 12:e21604b50719 109 return in_input_index;
Cheroukee 10:c4629b6c42f8 110 }