IniSat Modèle 1 Version 2 TP 5 : Station Sol Exo 1 : Enregistrement GPS sur carte SD Exo 2 : Mise en place d'un protocole de communication avec la station sol

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Giamarchi
Date:
Tue May 31 13:38:23 2022 +0000
Parent:
0:278eba15d90b
Commit message:
MAJ

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
gps.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
user.h Show annotated file Show diff for this revision Revisions of this file
--- a/SDFileSystem.lib	Wed Jul 07 11:39:10 2021 +0000
+++ b/SDFileSystem.lib	Tue May 31 13:38:23 2022 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/UniverSpace-IniSat-072021/code/SDFileSystem/#777349234283
+https://os.mbed.com/teams/UniverSpace-IniSat-072021/code/SDFileSystem/#fed70466472d
--- a/gps.h	Wed Jul 07 11:39:10 2021 +0000
+++ b/gps.h	Tue May 31 13:38:23 2022 +0000
@@ -117,23 +117,31 @@
 }
 
 void Envoi_GPS(void) {
+
     if(gps.fixe) {
-//        pc.printf("GPS: %s\n\r",buffer);
-//            pc.printf("hms : %s\n",gps.horaire);
-        pc.printf("lat : %fN\n",gps.latitude);
-        pc.printf("long: %fE\n",gps.longitude);
+        pc.printf("hms : %s\n",gps.horaire);
+        pc.printf("lat : %f N\n",gps.latitude);
+        pc.printf("long: %f E\n",gps.longitude);
         pc.printf("alt : %d m\n",gps.altitude);
-            
-/*        if (cmd[0] == 'E') {      // lancer l'enregistrement    
-            FILE *fp = fopen("/sd/gps_data.txt", "a");
-        }
-//        fprintf(fp, "%.6f, %.6f, \n",gps.latitude,gps.longitude);
-        
-        
-        if (cmd[0] == 'S') {      // stopper l'enregistrement    
-            fclose(fp);
-        }*/
     }
+    else
+        pc.printf("GPS: %s\n",buffer);
+}
+
+void XBee_Envoi_GPS(void) {
+    
+    if(gps.fixe) {
+        xbee.printf("H%s\n",gps.horaire);
+        xbee.printf("lat : %fN\n",gps.latitude);
+        xbee.printf("long: %fE\n",gps.longitude);
+        xbee.printf("#A%d\n",gps.altitude);
+              
+        FILE *fp = fopen("/sd/gps_data.txt", "a");
+        fprintf(fp, "%.6f, %.6f, \n",gps.latitude,gps.longitude);   
+        fclose(fp);
+    }
+    else
+        xbee.printf("GPS: %s\n\r",buffer);
 }
 //==============================================================================
 // Sélection de la trame GGA - Système de positionnement global des données fixées
--- a/main.cpp	Wed Jul 07 11:39:10 2021 +0000
+++ b/main.cpp	Tue May 31 13:38:23 2022 +0000
@@ -38,6 +38,7 @@
     Init_Soft_UART();
 //    thread_sleep_for(1000);
     xb_ptr = 0;
+    cmd[0] = 'P';           // Controle montant par PC
 // Setup a serial interrupt function to receive data
     xbee.attach(&Rx_interrupt, Serial::RxIrq);
     __enable_irq();
@@ -68,8 +69,8 @@
     if(fp == NULL) {
         error("Erreur : fichier non accessible en ecriture\n");
     }
-    pc.printf("Fichier cree!\r\n");
-    xbee.printf("Liaison Sol\r\n");
+    pc.printf("Carte SD Ok!\r\n");
+    xbee.printf("Station Sol par XBee Ok!\r\n");
 
 //  Write text in file    
  //   fprintf(fp, "Hello World, greats from Inisat!");
@@ -123,13 +124,23 @@
 //  Mode Radio :    Transmission de données
 //                  Mise en forme pour affichage
             case 3:
-                Envoi_GPS();
-                Envoi_Mes_Bat();
-//                Envoi_Mes_SP();
-//                Envoi_Mes_Temp();
-                
-//                thread_sleep_for(1000);
-//                wait_ms(1000);
+                switch (cmd[0]) {     // Commn
+                    case 'P': {         // Commande montante filaire
+                        Envoi_GPS();
+                        Envoi_Mes_Bat();
+//                      Envoi_Mes_SP();
+                        Envoi_Mes_Temp();
+                        break; }
+                    case 'X':           // Commande montante sans fil par XBee
+                        XBee_Envoi_GPS();
+                        XBee_Envoi_Mes_Bat();
+//                        XBee_Envoi_Mes_SP();
+                        XBee_Envoi_Mes_Temp();
+                        break;
+                    default:
+                        cmd[0] = 'P';
+                        break;
+                }
                 etat = 1;
                 break;
 /******************************************************************************/
@@ -186,6 +197,7 @@
             {
                 cmd[0] = xb_buf[1];
                 xbee.printf("#%c\r\n",cmd[0]+0x20);       // Acquittement
+                param[0] = xb_buf[2];
             }
 //                xb_ok = 1;                      // Trame disponible pour décodage
 //                pc.printf("%s\n\r",buffer);     // Echo  
--- a/user.h	Wed Jul 07 11:39:10 2021 +0000
+++ b/user.h	Tue May 31 13:38:23 2022 +0000
@@ -73,7 +73,11 @@
 void Envoi_Mes_Bat(void) {
     
     pc.printf("BAT: %.2f V\n",mes_bat);     // Format pour Terminal (Putty)
-//    pc.printf("B%.2f\n",mes_bat);          // Format pour Serial Data Plotter
+}
+
+void XBee_Envoi_Mes_Bat(void) {
+    
+    xbee.printf("#B%d\n",(uint16_t)(mes_bat*100));          // Format pour Supervision sans fil par XBee
 }
 /******************************************************************************/
 //  Mesure des courants des 2 panneaux solaires
@@ -116,7 +120,11 @@
 void Envoi_Mes_Temp(void) {
     
     pc.printf("Temp: %.1f degC\r\n",mes_temp);          // Mesure directe
-//    pc.printf("%.1f\n",mes_temp);          // Supervision -> Format pour Serial Data Plotter
+}
+
+void XBee_Envoi_Mes_Temp(void) {
+    
+    xbee.printf("#T%d\n",(uint16_t)(mes_temp*10));          // Supervision -> par XBee
 }
 /******************************************************************************/