homologation gros robot et test avec les ack de la carte a tout faire

Fork of CRAC-Strat_2017_HOMOLOGATION_PETIT_ROBOT by CRAC Team

Revision:
4:88431b537477
Parent:
2:8d8e2cf798a3
Child:
5:dcd817534b57
--- a/Strategie/Strategie.cpp	Sun Apr 17 08:31:59 2016 +0000
+++ b/Strategie/Strategie.cpp	Sun Apr 17 14:03:03 2016 +0000
@@ -1,6 +1,6 @@
 #include "Strategie.h"
 
-E_stratGameEtat     gameEtat  = ETAT_GAME_INIT;//ETAT_CHECK_CARTE_SCREEN;
+E_stratGameEtat     gameEtat  = ETAT_CONFIG;//ETAT_CHECK_CARTE_SCREEN;
 E_stratGameEtat     lastEtat  = ETAT_CHECK_CARTE_SCREEN;
 unsigned char screenChecktry = 0;
 Timer cartesCheker;//Le timer pour le timeout de la vérification des cartes
@@ -23,7 +23,10 @@
 
 unsigned char InversStrat = 1;//Si à 1, indique que l'on part de l'autre cote de la table(inversion des Y)
 
-
+/****************************************************************************************/
+/* FUNCTION NAME: chronometre_ISR                                                       */
+/* DESCRIPTION  : Interruption à la fin des 90s du match                                */
+/****************************************************************************************/
 void chronometre_ISR (void)
 {
     SendRawId(ASSERVISSEMENT_STOP);//On stope les moteurs
@@ -37,6 +40,10 @@
     while(1);//On bloque la programme dans l'interruption
 }
 
+/****************************************************************************************/
+/* FUNCTION NAME: automate_process                                                      */
+/* DESCRIPTION  : Automate de gestion de la stratégie du robot                          */
+/****************************************************************************************/
 void automate_process(void)
 {
     static struct S_Instruction instruction;
@@ -167,7 +174,7 @@
         break;
         case ETAT_GAME_INIT:
             //On charge la liste des instructions
-            strcpy(cheminFileStart,"/local/test.txt");//On ouvre le fichier test.txt
+            //strcpy(cheminFileStart,"/local/test.txt");//On ouvre le fichier test.txt
             loadAllInstruction();//Mise en cache de toute les instructions
             gameEtat = ETAT_GAME_WAIT_FOR_JACK;
             SendRawId(ECRAN_ACK_START_MATCH);
@@ -396,10 +403,14 @@
     }
 }
 
+/****************************************************************************************/
+/* FUNCTION NAME: canProcessRx                                                          */
+/* DESCRIPTION  : Fonction de traitement des messages CAN                               */
+/****************************************************************************************/
 void canProcessRx(void)
 {
     static signed char FIFO_occupation=0,FIFO_max_occupation=0;
-
+    CANMessage msgTx=CANMessage();
     FIFO_occupation=FIFO_ecriture-FIFO_lecture;
     if(FIFO_occupation<0)
         FIFO_occupation=FIFO_occupation+SIZE_FIFO;
@@ -408,11 +419,7 @@
     if(FIFO_occupation!=0) {
         
         switch(msgRxBuffer[FIFO_lecture].id) {
-            case ASSERVISSEMENT_STOP:
-                
-            break;
-            
-            case DEBUG_FAKE_JAKE:
+            case DEBUG_FAKE_JAKE://Permet de lancer le match à distance
                 if(gameEtat == ETAT_GAME_WAIT_FOR_JACK) {
                     gameEtat = ETAT_GAME_START;
                 }
@@ -465,16 +472,35 @@
                 AX12_notifyCANEnd(((unsigned short)(msgRxBuffer[FIFO_lecture].data[0])));
             break;
             case ECRAN_CHOICE_COLOR://Choix de la couleur
-                if(gameEtat == ETAT_CONFIG) {
+                if(gameEtat == ETAT_CONFIG) {//C'est bon on a le droit de modifier les config
                     if(msgRxBuffer[FIFO_lecture].data[0] == 0)
                         InversStrat = 0;//Pas d'inversion de la couleur
                     else
                         InversStrat = 1;//Inversion de la couleur
+                        
+                    msgTx.id=ECRAN_ACK_COLOR; // tx ack de la couleur
+                    msgTx.len=1;
+                    msgTx.format=CANStandard;
+                    msgTx.type=CANData;
+                    // couleur sur 1 octet
+                    msgTx.data[0]=msgRxBuffer[FIFO_lecture].data[0];
+                    can1.write(msgTx);
                 }
             break;
             case ECRAN_CHOICE_STRAT://Choix du fichier de stratégie à utiliser
-                if(gameEtat == ETAT_CONFIG) {
-                    
+                if(gameEtat == ETAT_CONFIG) {//C'est bon on a le droit de modifier les config
+                    msgTx.id=ECRAN_ACK_STRAT; // tx ack de la couleur
+                    msgTx.len=1;
+                    msgTx.format=CANStandard;
+                    msgTx.type=CANData;
+                    if(SelectStrategy(msgRxBuffer[FIFO_lecture].data[0])) {
+                        // id de la stratégie sur 1 octet
+                        msgTx.data[0]=msgRxBuffer[FIFO_lecture].data[0];
+                    } else {
+                        //erreur sur 1 octet
+                        msgTx.data[0]=0;
+                    }
+                    can1.write(msgTx);
                 }
             break;
         }