prog robocup equip2

Dependencies:   nRF24L01P MX12 BSP_B-L475E-IOT01

Files at this revision

API Documentation at this revision

Comitter:
chedozeauclement
Date:
Fri Apr 23 09:08:02 2021 +0000
Parent:
0:7b8f377e2077
Commit message:
Prog comm/mvt;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Apr 23 07:51:03 2021 +0000
+++ b/main.cpp	Fri Apr 23 09:08:02 2021 +0000
@@ -9,8 +9,9 @@
 #include "stm32l475e_iot01_magneto.h"
 #include "Projet.h"
 #include "nRF24L01P.h"
+#include "string.h"
 
-Serial pc(USBTX, USBRX); // tx, rx
+static UnbufferedSerial pc(USBTX, USBRX,115200); // tx, rx
 
 nRF24L01P my_nrf24l01p(D11, D12, D13, D9, D10, D8);    // mosi, miso, sck, csn, ce, irq
 
@@ -24,7 +25,7 @@
     
 // Nombre de caractères transmis à chaque envoi
 #define TRANSFER_SIZE   24
-
+    char texte[100];
     char txData[TRANSFER_SIZE]= {};
     char rxData[TRANSFER_SIZE+1]= {};
     char caractere_recu=0;
@@ -46,18 +47,34 @@
     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
     my_nrf24l01p.setRfOutputPower(-6);
     
-    pc.printf("DISCO\r\n");
-    pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
-    pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
-    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
-    pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
-    pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
+    
+    sprintf(texte,"DISCO\r\n");
+    pc.write(texte,strlen(texte));
+    
+    sprintf(texte,"nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency());
+    pc.write(texte,strlen(texte));
+    
+    sprintf(texte,"nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
+    pc.write(texte,strlen(texte));
+    
+    sprintf(texte,"nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate()  );
+    pc.write(texte,strlen(texte));
+    
+    sprintf(texte,"nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
+    pc.write(texte,strlen(texte));
+    
+    sprintf(texte,"nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress()  );
+    pc.write(texte,strlen(texte));
 
 
     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();
-    pc.printf("Pret a recevoir, led2 ON\n\r");
+  
+
+    sprintf(texte,"Pret a recevoir, led2 ON\n\r" );
+    pc.write(texte,strlen(texte));
+
     myled2=!myled2;
 
     while(1) {
@@ -70,23 +87,44 @@
         if ( statut_nrF != 0) {
             
             myled2 = !myled2;
-            pc.printf( "Reception\n\r");
+            
+            sprintf(texte,"Reception\n\r");
+            pc.write(texte,strlen(texte));
  
             rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, TRANSFER_SIZE );
             
             //Traitement donnees--------------------------------
             
             if(sscanf(rxData, "%d,%d,%d,%d,%d,%d,%d",&id_robot,&vx,&vy,&angle_robot,&vangulaire,&v_tir,&cmd_rouleau)==7){ // lecture et parsing de la chaîne
-            pc.printf("Valeur de id_robot : %d \r\n",id_robot);
-            pc.printf("Valeur de vx : %d \r\n",vx);
-            pc.printf("Valeur de vy : %d \r\n",vy);
-            pc.printf("Valeur de angle_robot : %d \r\n",angle_robot);
-            pc.printf("Valeur de vangulaire : %d \r\n",vangulaire);
-            pc.printf("Valeur de v_tir : %d \r\n",v_tir); 
-            pc.printf("Valeur de commande_rouleau : %d \r\n",cmd_rouleau); 
+            
+            
+            sprintf(texte,"Valeur de id_robot : %d \r\n",id_robot);
+            pc.write(texte,strlen(texte));
+            
+            sprintf(texte,"Valeur de vx : %d \r\n",vx);
+            pc.write(texte,strlen(texte));
+            
+            sprintf(texte,"Valeur de vy : %d \r\n",vy);
+            pc.write(texte,strlen(texte));
+            
+            sprintf(texte,"Valeur de angle_robot : %d \r\n",angle_robot);
+            pc.write(texte,strlen(texte));
+
+            sprintf(texte,"Valeur de vangulaire : %d \r\n",vangulaire);
+            pc.write(texte,strlen(texte));
+
+            sprintf(texte,"Valeur de v_tir : %d \r\n",v_tir);
+            pc.write(texte,strlen(texte));
+
+            sprintf(texte,"Valeur de cmd_rouleau : %d \r\n",cmd_rouleau);
+            pc.write(texte,strlen(texte));
+            
+            
             }
             
-            else {pc.printf(rxData);}
+            else {sprintf(texte,rxData);
+            pc.write(texte,strlen(texte));}
+            
             
             consigneData[0] = id_robot;
             consigneData[1] = vx;
@@ -95,10 +133,14 @@
             consigneData[4] = vangulaire;
             consigneData[5] = v_tir;
             consigneData[6] = cmd_rouleau;
-            
+
 
-            pc.printf(rxData);
-            pc.printf( "   Taille %d\r\n",rxDataCnt);
+            sprintf(texte,rxData);
+            pc.write(texte,strlen(texte));
+
+            sprintf(texte,"   Taille %d\r\n",rxDataCnt);
+            pc.write(texte,strlen(texte));
+            
 
         led = 1;
         cmd_inverse(vx,vy,vangulaire,angle_robot,&mx);