carte_strategie_2019

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
kyxstark
Date:
Fri May 31 18:04:13 2019 +0000
Revision:
85:c46c39d879a9
Parent:
61:4046a91e1b0e
tests_bt;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sitkah 29:41e02746041d 1 #include "mbed.h"
antbig 0:ad97421fb1fb 2 #include "global.h"
Sitkah 29:41e02746041d 3 #include <CAN.h>
Sitkah 29:41e02746041d 4
Sitkah 29:41e02746041d 5 CAN can1(PB_8,PB_9); // Rx&Tx pour le CAN
Sitkah 29:41e02746041d 6 CAN can2(PB_5, PB_13);
Sitkah 30:a1e37af4bbde 7
Sitkah 31:833fc481b002 8 void bluetooth_init(void);
Sitkah 30:a1e37af4bbde 9 DigitalIn choix_robot(PG_12);
Sitkah 29:41e02746041d 10 CANMessage msgRxBuffer[SIZE_FIFO];
Sitkah 29:41e02746041d 11 unsigned char FIFO_ecriture;
Sitkah 29:41e02746041d 12 char strat_sd[10][SIZE+8];
Sitkah 29:41e02746041d 13 char PATH[10][SIZE+8];
Sitkah 29:41e02746041d 14
kyxstark 85:c46c39d879a9 15 //Serial rn42_pr(PG_14, PG_9);
Sitkah 31:833fc481b002 16 //Serial rn42(PA_1,PA_2);
Sitkah 31:833fc481b002 17 Serial rn42_Tx(PA_2,NC);
Sitkah 31:833fc481b002 18 Serial rn42_Rx(NC,PA_1);
Sitkah 31:833fc481b002 19
kyxstark 85:c46c39d879a9 20 Serial serialNC(NC,NC);
kyxstark 85:c46c39d879a9 21 Serial rn42Dessus(PG_14,PG_9);
kyxstark 85:c46c39d879a9 22 Serial rn42Dessous(PA_2,PA_1);
kyxstark 85:c46c39d879a9 23
kyxstark 85:c46c39d879a9 24
kyxstark 85:c46c39d879a9 25
Sitkah 30:a1e37af4bbde 26 Serial pc(USBTX,USBRX);
kyxstark 85:c46c39d879a9 27
kyxstark 85:c46c39d879a9 28
kyxstark 85:c46c39d879a9 29
kyxstark 85:c46c39d879a9 30 #ifdef PETI_ROB
Sitkah 31:833fc481b002 31 LiaisonBluetooth liaison_Rx(&rn42_Rx,&pc);
Sitkah 31:833fc481b002 32 LiaisonBluetooth liaison_Tx(&rn42_Tx,&pc);
kyxstark 85:c46c39d879a9 33 //LiaisonBluetooth liaison_pr(&rn42Dessus,&pc);
kyxstark 85:c46c39d879a9 34 LiaisonBluetooth liaisonRob(&rn42Dessus,&pc);
kyxstark 85:c46c39d879a9 35 #endif
kyxstark 85:c46c39d879a9 36 #ifdef GROS_ROB
kyxstark 85:c46c39d879a9 37 LiaisonBluetooth liaisonRob(&rn42Dessous,&pc);
kyxstark 85:c46c39d879a9 38 #endif
antbig 0:ad97421fb1fb 39
Sitkah 29:41e02746041d 40 char cheminFileStart[SIZE+8]; //Le chemin du fichier de strat, utiliser strcpy(cheminFileStart,"/local/strat.txt");
Sitkah 29:41e02746041d 41 struct S_Instruction strat_instructions[SIZE_BUFFER_FILE]; //La liste des instruction chargé en mémoire
Sitkah 29:41e02746041d 42 unsigned char nb_instructions; //Le nombre d'instruction dans le fichier de strategie
Sitkah 29:41e02746041d 43 unsigned char actual_instruction;//La ligne de l'instruction en cours d'execution
Sitkah 29:41e02746041d 44
Sitkah 30:a1e37af4bbde 45
antbig 0:ad97421fb1fb 46
Sitkah 29:41e02746041d 47 unsigned char InversStrat = 1;//Si à 1, indique que l'on part de l'autre cote de la table(inversion des Y)
Sitkah 29:41e02746041d 48
Sitkah 29:41e02746041d 49
Sitkah 29:41e02746041d 50 unsigned short waitingAckID=0;//L'id du ack attendu
Sitkah 29:41e02746041d 51 unsigned short waitingAckFrom=0;//La provenance du ack attendu
Artiom 50:a5361ffeefc8 52 unsigned short waitingId=0;
Sitkah 29:41e02746041d 53 char modeTelemetre; // Si à 1, indique que l'on attend une reponse du telemetre
antbig 0:ad97421fb1fb 54
antbig 0:ad97421fb1fb 55 DigitalOut led1(LED1);//Led d'indication de problème, si elle clignote, c'est pas bon
antbig 1:116040d14164 56 DigitalOut led2(LED2);//Led d'indication de problème, si elle clignote, c'est pas bon
antbig 8:0edc7dfb7f7e 57 DigitalOut led3(LED3);//Led d'indication de problème, si elle clignote, c'est pas bon
antbig 8:0edc7dfb7f7e 58 DigitalOut led4(LED4);//Led d'indication de problème, si elle clignote, c'est pas bon
antbig 0:ad97421fb1fb 59
antbig 0:ad97421fb1fb 60 /****************************************************************************************/
antbig 0:ad97421fb1fb 61 /* FUNCTION NAME: canRx_ISR */
antbig 0:ad97421fb1fb 62 /* DESCRIPTION : Interruption en réception sur le CAN */
antbig 0:ad97421fb1fb 63 /****************************************************************************************/
antbig 0:ad97421fb1fb 64 void canRx_ISR (void)
antbig 0:ad97421fb1fb 65 {
Sitkah 30:a1e37af4bbde 66 if (can2.read(msgRxBuffer[FIFO_ecriture])) {
Sitkah 29:41e02746041d 67 //if(msgRxBuffer[FIFO_ecriture].id==RESET_STRAT) mbed_reset();
Sitkah 29:41e02746041d 68 /*else*/ FIFO_ecriture=(FIFO_ecriture+1)%SIZE_FIFO;
Sitkah 36:6dd30780bd8e 69 //canProcessRx();
antbig 0:ad97421fb1fb 70 }
antbig 0:ad97421fb1fb 71 }
antbig 0:ad97421fb1fb 72
antbig 0:ad97421fb1fb 73
Sitkah 29:41e02746041d 74
Sitkah 29:41e02746041d 75
antbig 0:ad97421fb1fb 76 /**********************************************************************************/
antbig 0:ad97421fb1fb 77 /* FUNCTION NAME: main */
antbig 0:ad97421fb1fb 78 /* DESCRIPTION : Fonction principal du programme */
antbig 0:ad97421fb1fb 79 /**********************************************************************************/
antbig 0:ad97421fb1fb 80 int main() {
antbig 0:ad97421fb1fb 81 can1.frequency(1000000); // fréquence de travail 1Mbit/s
Sitkah 30:a1e37af4bbde 82 can2.attach(&canRx_ISR); // création de l'interrupt attachée à la réception sur le CAN
Sitkah 29:41e02746041d 83 can2.frequency(1000000);
antbig 12:14729d584500 84 #ifdef ROBOT_BIG
Sitkah 30:a1e37af4bbde 85 lcd.DisplayStringAt(0, 0,(uint8_t *)"Initialisation gros robot", LEFT_MODE);
antbig 12:14729d584500 86 #else
Sitkah 30:a1e37af4bbde 87 lcd.DisplayStringAt(0, 0,(uint8_t *)"Initialisation petit robot", LEFT_MODE);
antbig 12:14729d584500 88 #endif
ClementBreteau 18:cc5fec34ed9c 89 led1 = 1;
Sitkah 31:833fc481b002 90 bluetooth_init();
Sitkah 38:76f886a1c8e6 91 lecture_fichier(); //bloquant si pas de carte SD
ClementBreteau 18:cc5fec34ed9c 92 led1 = 0;
Sitkah 38:76f886a1c8e6 93 wait_ms(2000);//Attente pour que toutes les cartes se lancent et surtout le CANBlue
antbig 0:ad97421fb1fb 94 while(true) {
Sitkah 29:41e02746041d 95 automate_etat_ihm();
antbig 9:d0042422d95a 96 automate_process();//Boucle dans l'automate principal
Sitkah 36:6dd30780bd8e 97 canProcessRx();
antbig 0:ad97421fb1fb 98 }
antbig 0:ad97421fb1fb 99 }
Sitkah 31:833fc481b002 100
Sitkah 31:833fc481b002 101 void bluetooth_init(void){
Sitkah 31:833fc481b002 102 rn42_Tx.baud(115200);
Sitkah 31:833fc481b002 103 rn42_Rx.baud(115200);
kyxstark 85:c46c39d879a9 104 rn42Dessus.baud(115200);
kyxstark 85:c46c39d879a9 105 rn42Dessous.baud(115200);
Sitkah 31:833fc481b002 106 pc.baud(115200);
Sitkah 31:833fc481b002 107 pc.printf("ok1");
Sitkah 42:657b6a573e11 108 /*while(1){ // sert au paramètrage des module RN42
Sitkah 31:833fc481b002 109 while(pc.readable()){
Sitkah 31:833fc481b002 110 rn42_Tx.putc(pc.getc());
Sitkah 31:833fc481b002 111
Sitkah 31:833fc481b002 112 }
Sitkah 31:833fc481b002 113 while(rn42_Rx.readable()){
Sitkah 31:833fc481b002 114 pc.putc(rn42_Rx.getc());
Sitkah 31:833fc481b002 115 }
Sitkah 31:833fc481b002 116 }*/
Sitkah 31:833fc481b002 117 }