Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Serie.cpp
00001 #include "Serie.h" 00002 00003 //INSTANCIATION DES INSTANCES GLOBALES ET EXTERNES 00004 Serial xbee(XBEE_PIN_TX,XBEE_PIN_RX); 00005 00006 //INSTANCES GLOBALES ET INTERNES 00007 char commande[TAILLE_COMMANDE]; 00008 int curseur; 00009 bool wait_com; 00010 00011 00012 /* LA COMMANDE POUR PAPI BROSSARD 00013 reception d'un chaine :"Cam:23521/4521/451/.../6532/\n" 00014 Utilisation du split java avec pour delimiteur / et : 00015 String s="27/03/2008"; 00016 String str[]=s.split("/"); 00017 00018 On peut eventuellement utilisé la classe Scanner de JAVA*/ 00019 void envoyerCamera() 00020 { 00021 xbee.printf("Cam:"); 00022 for(int i=0;i<128;i++) { 00023 xbee.printf("%u/",valeurs[i]); 00024 } 00025 xbee.printf("\n"); 00026 } 00027 00028 typedef enum IdVar IdVar; 00029 enum Idvar {CAM1,TASSERV,VPROP,}; 00030 00031 //Si quelqu'un trouve pourquoi un parametre de type enumeration n'est pas accepte par le compilo 00032 /*void getVar(IdVar id) { 00033 switch(id) { 00034 case CAM1 : 00035 envoyerCamera(); 00036 break; 00037 00038 } 00039 }*/ 00040 00041 void getVar(int id) { 00042 switch(id) { 00043 case CAM1 : 00044 envoyerCamera(); 00045 break; 00046 } 00047 } 00048 void help() { 00049 } 00050 00051 void traiter(char commande[]) { 00052 switch(commande[0]) { 00053 case 'G': 00054 getVar(commande[1]); 00055 00056 break; 00057 00058 case 'S': 00059 int t; 00060 sscanf(commande, "S%d\n",t); 00061 //setTIntegration(t); 00062 00063 break; 00064 case 'D': 00065 float t; 00066 char a,b; 00067 sscanf(commande,"%c%c%f\n",&a,&b,&t); 00068 00069 switch(commande[2]) { 00070 case 'P': 00071 propulsion.setDKp(t); 00072 break; 00073 case 'I': 00074 propulsion.setDKi(t); 00075 break; 00076 case 'D': 00077 propulsion.setDKd(t); 00078 break; 00079 } 00080 break; 00081 case 'L': 00082 float w; 00083 char a,b; 00084 sscanf(commande,"%c%c%f\n",&a,&b,&w); 00085 00086 switch(commande[2]) { 00087 case 'P': 00088 propulsion.setGKp(w); 00089 break; 00090 case 'I': 00091 propulsion.setGKi(w); 00092 break; 00093 case 'D': 00094 propulsion.setGKd(w); 00095 break; 00096 } 00097 break; 00098 00099 case 'C': 00100 setDirection(((float)commande[1])/(2000*256.0f)); 00101 float a1 = (float)commande[1]/(2000*256.0f); 00102 float a2 = (commande[2]-128.0f)/128.0f; 00103 float a3 = (commande[3]-128.0f)/128.0f; 00104 //setPuissanceMoteurs((commande[2]-128.0f)/(128.0f),(commande[3]-128.0f)/(128.0f)); 00105 xbee.printf("Commande (C)ontrol reconnue\n"); 00106 xbee.printf(" C:%s dir(int):%d M1(int):%d M2(int):%d\n",commande[0],commande[1],commande[2],commande[3]); 00107 xbee.printf(" Valeur: Dir(float)%f\n",direction.read()); 00108 xbee.printf("%f %f %f\n\n\n",a1,a2,a3); 00109 00110 break; 00111 00112 default: 00113 xbee.printf("Commande non reconnue\n"); 00114 break; 00115 } 00116 xbee.printf(" Commande(ASCII) : %s\n",commande); 00117 } 00118 00119 void callbackSerie() { 00120 int donne; 00121 00122 while(xbee.readable()) 00123 { 00124 donne = xbee.getc(); 00125 00126 if(wait_com) { 00127 /*On ecoute la commande*/ 00128 00129 if(donne == '\n') { 00130 /*Fin de la commande*/ 00131 if(curseur != 0) { 00132 commande[curseur] = '\n'; 00133 traiter(commande); 00134 } 00135 wait_com = false; 00136 } else { 00137 if(curseur >= TAILLE_COMMANDE) { 00138 xbee.printf("Xbee Freescale: Buffer overflown"); 00139 wait_com = false; 00140 } else { 00141 commande[curseur] = donne; 00142 curseur++; 00143 } 00144 } 00145 00146 } else { 00147 /*On attends le symbole START pour prendre commande*/ 00148 if(donne == 'S') { 00149 wait_com = true; 00150 curseur = 0; 00151 } 00152 } 00153 } 00154 } 00155 00156 00157 void initSerie() { 00158 for(int i=0 ; i< TAILLE_COMMANDE ; i++) { 00159 commande[i] = 0; 00160 } 00161 xbee.baud(XBEE_SPEED); 00162 xbee.printf("Xbee Freescale: Hello...\n"); 00163 xbee.attach(&callbackSerie); 00164 curseur = 0; 00165 wait_com = false; 00166 }
Generated on Wed Jul 13 2022 20:35:19 by
1.7.2