Correction de problèmes dans la gestion du tampon tournant

This commit is contained in:
Samuel 2025-09-20 10:29:29 +02:00
parent a069a4e8d0
commit 83fa26be6d
3 changed files with 20 additions and 15 deletions

View File

@ -1,5 +1,5 @@
#include "pico/error.h"
#include "pico/stdio.h"
#include <stdio.h>
#include "communication.h"
#include "messagerie.h"
@ -63,7 +63,12 @@ void communication_reception_message(){
// Parce que c'est plus simple à traiter
index_chaine_recue = 0;
index_tampon = com_reception_buffer.index_tampon_lecture;
while(index_tampon != com_reception_buffer.index_tampon_ecriture){
if(index_tampon != com_reception_buffer.index_tampon_ecriture){
while(index_tampon != com_reception_buffer.index_tampon_ecriture){
chaîne_octets_reçus[index_chaine_recue] = com_reception_buffer.tampon[index_tampon];
index_chaine_recue++;
increment_index(&index_tampon);
}
chaîne_octets_reçus[index_chaine_recue] = com_reception_buffer.tampon[index_tampon];
index_chaine_recue++;
increment_index(&index_tampon);
@ -80,10 +85,7 @@ void communication_reception_message(){
if(i+3 < index_chaine_recue){
message.taille_donnees = chaîne_octets_reçus[i+3];
}
for(int z=0; z<=4 + message.taille_donnees; z++ ){
printf("%d ", chaîne_octets_reçus[i+z]);
}
printf("\n");
index_fin_message = i+4 + message.taille_donnees;
if(index_fin_message < index_chaine_recue){
if(chaîne_octets_reçus[index_fin_message] == 0){

19
main.c
View File

@ -6,9 +6,12 @@
#include "pico/stdlib.h"
#include <stdio.h>
#include <string.h>
#include <pico/stdio.h>
#include "communication.h"
#include "messagerie.h"
void stdio_usb_out_chars(const char *buf, int length);
#define NB_MORCEAUX 100
@ -78,6 +81,7 @@ void main(void)
int nb_ech = 10;
int taille_morceau = 60;
stdio_init_all();
sleep_ms(5000);
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
gpio_put(PICO_DEFAULT_LED_PIN, 0);
@ -86,6 +90,7 @@ void main(void)
communication_init();
while(1){
if(get_absolute_time() - temps_message_detection > MESSAGE_TIMEOUT_US){
@ -93,21 +98,19 @@ void main(void)
temps_message_detection = get_absolute_time();
}
start_time_us = get_absolute_time();
//envoie_donnees(message_binaire, 10);
current_time_us = get_absolute_time();
//printf(">temps:%lld\n", current_time_us - start_time_us);
start_time_us = get_absolute_time();
communication_reception_message();
while(messagerie_message_disponible()){
printf("Message disponible\n");
message = messagerie_get_message();
if(message.type == 'r'){
if(message.id_carte == 'D'){
temps_message_detection = get_absolute_time();
if(message.donnees[1] > 0 && message.donnees[1] < 30){
if(message.donnees[0] > 0 && message.donnees[0] < 30){
printf(">LED ON\n");
gpio_put(PICO_DEFAULT_LED_PIN, 1);
}else{
printf(">LED OFF\n");
gpio_put(PICO_DEFAULT_LED_PIN, 0);
}
}
@ -115,9 +118,8 @@ void main(void)
}
current_time_us = get_absolute_time();
putchar('\n');
printf(">temps:%lld\n", current_time_us - start_time_us);
sleep_ms(50);
//sleep_ms(50);
}
}
@ -140,3 +142,4 @@ absolute_time_t envoie_nb_char(int nb_char) {
chaine_envoie[nb_char] = 'a';
return current_time_us - start_time_us;
}